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.

252440 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 ValueTreeSetPropertyAction : public UndoableAction
  12593. {
  12594. public:
  12595. ValueTreeSetPropertyAction (const ValueTree::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. ~ValueTreeSetPropertyAction() {}
  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 ValueTree::SharedObjectPtr target;
  12628. const var::identifier name;
  12629. const var newValue;
  12630. var oldValue;
  12631. const bool isAddingNewProperty, isDeletingProperty;
  12632. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12633. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12634. };
  12635. class ValueTreeChildChangeAction : public UndoableAction
  12636. {
  12637. public:
  12638. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12639. const ValueTree::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. ~ValueTreeChildChangeAction() {}
  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 ValueTree::SharedObjectPtr target, child;
  12677. const int childIndex;
  12678. const bool isDeleting;
  12679. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12680. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12681. };
  12682. ValueTree::SharedObject::SharedObject (const String& type_)
  12683. : type (type_), parent (0)
  12684. {
  12685. }
  12686. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12687. : type (other.type), properties (other.properties), parent (0)
  12688. {
  12689. for (int i = 0; i < other.children.size(); ++i)
  12690. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12691. }
  12692. ValueTree::SharedObject::~SharedObject()
  12693. {
  12694. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12695. for (int i = children.size(); --i >= 0;)
  12696. {
  12697. const SharedObjectPtr c (children.getUnchecked(i));
  12698. c->parent = 0;
  12699. children.remove (i);
  12700. c->sendParentChangeMessage();
  12701. }
  12702. }
  12703. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12704. {
  12705. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12706. {
  12707. ValueTree* const v = valueTreesWithListeners[i];
  12708. if (v != 0)
  12709. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12710. }
  12711. }
  12712. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12713. {
  12714. ValueTree tree (this);
  12715. ValueTree::SharedObject* t = this;
  12716. while (t != 0)
  12717. {
  12718. t->sendPropertyChangeMessage (tree, property);
  12719. t = t->parent;
  12720. }
  12721. }
  12722. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12723. {
  12724. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12725. {
  12726. ValueTree* const v = valueTreesWithListeners[i];
  12727. if (v != 0)
  12728. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12729. }
  12730. }
  12731. void ValueTree::SharedObject::sendChildChangeMessage()
  12732. {
  12733. ValueTree tree (this);
  12734. ValueTree::SharedObject* t = this;
  12735. while (t != 0)
  12736. {
  12737. t->sendChildChangeMessage (tree);
  12738. t = t->parent;
  12739. }
  12740. }
  12741. void ValueTree::SharedObject::sendParentChangeMessage()
  12742. {
  12743. ValueTree tree (this);
  12744. int i;
  12745. for (i = children.size(); --i >= 0;)
  12746. {
  12747. SharedObject* const t = children[i];
  12748. if (t != 0)
  12749. t->sendParentChangeMessage();
  12750. }
  12751. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12752. {
  12753. ValueTree* const v = valueTreesWithListeners[i];
  12754. if (v != 0)
  12755. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12756. }
  12757. }
  12758. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12759. {
  12760. return properties [name];
  12761. }
  12762. const var ValueTree::SharedObject::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12763. {
  12764. return properties.getWithDefault (name, defaultReturnValue);
  12765. }
  12766. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12767. {
  12768. if (undoManager == 0)
  12769. {
  12770. if (properties.set (name, newValue))
  12771. sendPropertyChangeMessage (name);
  12772. }
  12773. else
  12774. {
  12775. var* const existingValue = properties.getItem (name);
  12776. if (existingValue != 0)
  12777. {
  12778. if (*existingValue != newValue)
  12779. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12780. }
  12781. else
  12782. {
  12783. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12784. }
  12785. }
  12786. }
  12787. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12788. {
  12789. return properties.contains (name);
  12790. }
  12791. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12792. {
  12793. if (undoManager == 0)
  12794. {
  12795. if (properties.remove (name))
  12796. sendPropertyChangeMessage (name);
  12797. }
  12798. else
  12799. {
  12800. if (properties.contains (name))
  12801. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12802. }
  12803. }
  12804. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12805. {
  12806. if (undoManager == 0)
  12807. {
  12808. while (properties.size() > 0)
  12809. {
  12810. const var::identifier name (properties.getName (properties.size() - 1));
  12811. properties.remove (name);
  12812. sendPropertyChangeMessage (name);
  12813. }
  12814. }
  12815. else
  12816. {
  12817. for (int i = properties.size(); --i >= 0;)
  12818. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12819. }
  12820. }
  12821. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12822. {
  12823. for (int i = 0; i < children.size(); ++i)
  12824. if (children.getUnchecked(i)->type == typeToMatch)
  12825. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12826. return ValueTree::invalid;
  12827. }
  12828. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12829. {
  12830. for (int i = 0; i < children.size(); ++i)
  12831. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12832. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12833. return ValueTree::invalid;
  12834. }
  12835. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12836. {
  12837. const SharedObject* p = parent;
  12838. while (p != 0)
  12839. {
  12840. if (p == possibleParent)
  12841. return true;
  12842. p = p->parent;
  12843. }
  12844. return false;
  12845. }
  12846. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12847. {
  12848. if (child != 0 && child->parent != this)
  12849. {
  12850. if (child != this && ! isAChildOf (child))
  12851. {
  12852. // You should always make sure that a child is removed from its previous parent before
  12853. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12854. // undomanager should be used when removing it from its current parent..
  12855. jassert (child->parent == 0);
  12856. if (child->parent != 0)
  12857. {
  12858. jassert (child->parent->children.indexOf (child) >= 0);
  12859. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12860. }
  12861. if (undoManager == 0)
  12862. {
  12863. children.insert (index, child);
  12864. child->parent = this;
  12865. sendChildChangeMessage();
  12866. child->sendParentChangeMessage();
  12867. }
  12868. else
  12869. {
  12870. if (index < 0)
  12871. index = children.size();
  12872. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12873. }
  12874. }
  12875. else
  12876. {
  12877. // You're attempting to create a recursive loop! A node
  12878. // can't be a child of one of its own children!
  12879. jassertfalse
  12880. }
  12881. }
  12882. }
  12883. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12884. {
  12885. const SharedObjectPtr child (children [childIndex]);
  12886. if (child != 0)
  12887. {
  12888. if (undoManager == 0)
  12889. {
  12890. children.remove (childIndex);
  12891. child->parent = 0;
  12892. sendChildChangeMessage();
  12893. child->sendParentChangeMessage();
  12894. }
  12895. else
  12896. {
  12897. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12898. }
  12899. }
  12900. }
  12901. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12902. {
  12903. while (children.size() > 0)
  12904. removeChild (children.size() - 1, undoManager);
  12905. }
  12906. ValueTree::ValueTree() throw()
  12907. : object (0)
  12908. {
  12909. }
  12910. const ValueTree ValueTree::invalid;
  12911. ValueTree::ValueTree (const String& type_)
  12912. : object (new ValueTree::SharedObject (type_))
  12913. {
  12914. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12915. }
  12916. ValueTree::ValueTree (SharedObject* const object_)
  12917. : object (object_)
  12918. {
  12919. }
  12920. ValueTree::ValueTree (const ValueTree& other)
  12921. : object (other.object)
  12922. {
  12923. }
  12924. ValueTree& ValueTree::operator= (const ValueTree& other)
  12925. {
  12926. if (listeners.size() > 0)
  12927. {
  12928. if (object != 0)
  12929. object->valueTreesWithListeners.removeValue (this);
  12930. if (other.object != 0)
  12931. other.object->valueTreesWithListeners.add (this);
  12932. }
  12933. object = other.object;
  12934. return *this;
  12935. }
  12936. ValueTree::~ValueTree()
  12937. {
  12938. if (listeners.size() > 0 && object != 0)
  12939. object->valueTreesWithListeners.removeValue (this);
  12940. }
  12941. bool ValueTree::operator== (const ValueTree& other) const
  12942. {
  12943. return object == other.object;
  12944. }
  12945. bool ValueTree::operator!= (const ValueTree& other) const
  12946. {
  12947. return object != other.object;
  12948. }
  12949. ValueTree ValueTree::createCopy() const
  12950. {
  12951. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  12952. }
  12953. bool ValueTree::hasType (const String& typeName) const
  12954. {
  12955. return object != 0 && object->type == typeName;
  12956. }
  12957. const String ValueTree::getType() const
  12958. {
  12959. return object != 0 ? object->type : String::empty;
  12960. }
  12961. ValueTree ValueTree::getParent() const
  12962. {
  12963. return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
  12964. }
  12965. const var& ValueTree::operator[] (const var::identifier& name) const
  12966. {
  12967. return object == 0 ? var::null : object->getProperty (name);
  12968. }
  12969. const var& ValueTree::getProperty (const var::identifier& name) const
  12970. {
  12971. return object == 0 ? var::null : object->getProperty (name);
  12972. }
  12973. const var ValueTree::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12974. {
  12975. return object == 0 ? defaultReturnValue : object->getProperty (name, defaultReturnValue);
  12976. }
  12977. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12978. {
  12979. jassert (name.name.isNotEmpty());
  12980. if (object != 0 && name.name.isNotEmpty())
  12981. object->setProperty (name, newValue, undoManager);
  12982. }
  12983. bool ValueTree::hasProperty (const var::identifier& name) const
  12984. {
  12985. return object != 0 && object->hasProperty (name);
  12986. }
  12987. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12988. {
  12989. if (object != 0)
  12990. object->removeProperty (name, undoManager);
  12991. }
  12992. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  12993. {
  12994. if (object != 0)
  12995. object->removeAllProperties (undoManager);
  12996. }
  12997. int ValueTree::getNumProperties() const
  12998. {
  12999. return object == 0 ? 0 : object->properties.size();
  13000. }
  13001. const var::identifier ValueTree::getPropertyName (const int index) const
  13002. {
  13003. return object == 0 ? var::identifier()
  13004. : object->properties.getName (index);
  13005. }
  13006. class ValueTreePropertyValueSource : public Value::ValueSource,
  13007. public ValueTree::Listener
  13008. {
  13009. public:
  13010. ValueTreePropertyValueSource (const ValueTree& tree_,
  13011. const var::identifier& property_,
  13012. UndoManager* const undoManager_)
  13013. : tree (tree_),
  13014. property (property_),
  13015. undoManager (undoManager_)
  13016. {
  13017. tree.addListener (this);
  13018. }
  13019. ~ValueTreePropertyValueSource()
  13020. {
  13021. tree.removeListener (this);
  13022. }
  13023. const var getValue() const
  13024. {
  13025. return tree [property];
  13026. }
  13027. void setValue (const var& newValue)
  13028. {
  13029. tree.setProperty (property, newValue, undoManager);
  13030. }
  13031. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13032. {
  13033. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13034. sendChangeMessage (false);
  13035. }
  13036. void valueTreeChildrenChanged (ValueTree&) {}
  13037. void valueTreeParentChanged (ValueTree&) {}
  13038. private:
  13039. ValueTree tree;
  13040. const var::identifier property;
  13041. UndoManager* const undoManager;
  13042. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13043. };
  13044. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13045. {
  13046. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13047. }
  13048. int ValueTree::getNumChildren() const
  13049. {
  13050. return object == 0 ? 0 : object->children.size();
  13051. }
  13052. ValueTree ValueTree::getChild (int index) const
  13053. {
  13054. return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
  13055. }
  13056. ValueTree ValueTree::getChildWithName (const String& type) const
  13057. {
  13058. return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
  13059. }
  13060. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13061. {
  13062. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
  13063. }
  13064. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13065. {
  13066. return object != 0 && object->isAChildOf (possibleParent.object);
  13067. }
  13068. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13069. {
  13070. if (object != 0)
  13071. object->addChild (child.object, index, undoManager);
  13072. }
  13073. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13074. {
  13075. if (object != 0)
  13076. object->removeChild (childIndex, undoManager);
  13077. }
  13078. void ValueTree::removeChild (const ValueTree& child, UndoManager* const undoManager)
  13079. {
  13080. if (object != 0)
  13081. object->removeChild (object->children.indexOf (child.object), undoManager);
  13082. }
  13083. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13084. {
  13085. if (object != 0)
  13086. object->removeAllChildren (undoManager);
  13087. }
  13088. void ValueTree::addListener (Listener* listener)
  13089. {
  13090. if (listener != 0)
  13091. {
  13092. if (listeners.size() == 0 && object != 0)
  13093. object->valueTreesWithListeners.add (this);
  13094. listeners.add (listener);
  13095. }
  13096. }
  13097. void ValueTree::removeListener (Listener* listener)
  13098. {
  13099. listeners.remove (listener);
  13100. if (listeners.size() == 0 && object != 0)
  13101. object->valueTreesWithListeners.removeValue (this);
  13102. }
  13103. XmlElement* ValueTree::SharedObject::createXml() const
  13104. {
  13105. XmlElement* xml = new XmlElement (type);
  13106. int i;
  13107. for (i = 0; i < properties.size(); ++i)
  13108. {
  13109. var::identifier name (properties.getName(i));
  13110. const var& v = properties [name];
  13111. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13112. xml->setAttribute (name.name, v.toString());
  13113. }
  13114. for (i = 0; i < children.size(); ++i)
  13115. xml->addChildElement (children.getUnchecked(i)->createXml());
  13116. return xml;
  13117. }
  13118. XmlElement* ValueTree::createXml() const
  13119. {
  13120. return object != 0 ? object->createXml() : 0;
  13121. }
  13122. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13123. {
  13124. ValueTree v (xml.getTagName());
  13125. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13126. for (int i = 0; i < numAtts; ++i)
  13127. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13128. forEachXmlChildElement (xml, e)
  13129. {
  13130. v.addChild (fromXml (*e), -1, 0);
  13131. }
  13132. return v;
  13133. }
  13134. void ValueTree::writeToStream (OutputStream& output)
  13135. {
  13136. output.writeString (getType());
  13137. const int numProps = getNumProperties();
  13138. output.writeCompressedInt (numProps);
  13139. int i;
  13140. for (i = 0; i < numProps; ++i)
  13141. {
  13142. const var::identifier name (getPropertyName(i));
  13143. output.writeString (name.name);
  13144. getProperty(name).writeToStream (output);
  13145. }
  13146. const int numChildren = getNumChildren();
  13147. output.writeCompressedInt (numChildren);
  13148. for (i = 0; i < numChildren; ++i)
  13149. getChild (i).writeToStream (output);
  13150. }
  13151. ValueTree ValueTree::readFromStream (InputStream& input)
  13152. {
  13153. String type (input.readString());
  13154. if (type.isEmpty())
  13155. return ValueTree::invalid;
  13156. ValueTree v (type);
  13157. const int numProps = input.readCompressedInt();
  13158. if (numProps < 0)
  13159. {
  13160. jassertfalse // trying to read corrupted data!
  13161. return v;
  13162. }
  13163. int i;
  13164. for (i = 0; i < numProps; ++i)
  13165. {
  13166. const String name (input.readString());
  13167. jassert (name.isNotEmpty());
  13168. const var value (var::readFromStream (input));
  13169. v.setProperty (name, value, 0);
  13170. }
  13171. const int numChildren = input.readCompressedInt();
  13172. for (i = 0; i < numChildren; ++i)
  13173. v.addChild (readFromStream (input), -1, 0);
  13174. return v;
  13175. }
  13176. END_JUCE_NAMESPACE
  13177. /*** End of inlined file: juce_ValueTree.cpp ***/
  13178. /*** Start of inlined file: juce_Value.cpp ***/
  13179. BEGIN_JUCE_NAMESPACE
  13180. Value::ValueSource::ValueSource()
  13181. {
  13182. }
  13183. Value::ValueSource::~ValueSource()
  13184. {
  13185. }
  13186. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13187. {
  13188. if (synchronous)
  13189. {
  13190. for (int i = valuesWithListeners.size(); --i >= 0;)
  13191. {
  13192. Value* const v = valuesWithListeners[i];
  13193. if (v != 0)
  13194. v->callListeners();
  13195. }
  13196. }
  13197. else
  13198. {
  13199. triggerAsyncUpdate();
  13200. }
  13201. }
  13202. void Value::ValueSource::handleAsyncUpdate()
  13203. {
  13204. sendChangeMessage (true);
  13205. }
  13206. class SimpleValueSource : public Value::ValueSource
  13207. {
  13208. public:
  13209. SimpleValueSource()
  13210. {
  13211. }
  13212. SimpleValueSource (const var& initialValue)
  13213. : value (initialValue)
  13214. {
  13215. }
  13216. ~SimpleValueSource()
  13217. {
  13218. }
  13219. const var getValue() const
  13220. {
  13221. return value;
  13222. }
  13223. void setValue (const var& newValue)
  13224. {
  13225. if (newValue != value)
  13226. {
  13227. value = newValue;
  13228. sendChangeMessage (false);
  13229. }
  13230. }
  13231. private:
  13232. var value;
  13233. SimpleValueSource (const SimpleValueSource&);
  13234. SimpleValueSource& operator= (const SimpleValueSource&);
  13235. };
  13236. Value::Value()
  13237. : value (new SimpleValueSource())
  13238. {
  13239. }
  13240. Value::Value (ValueSource* const value_)
  13241. : value (value_)
  13242. {
  13243. jassert (value_ != 0);
  13244. }
  13245. Value::Value (const var& initialValue)
  13246. : value (new SimpleValueSource (initialValue))
  13247. {
  13248. }
  13249. Value::Value (const Value& other)
  13250. : value (other.value)
  13251. {
  13252. }
  13253. Value& Value::operator= (const Value& other)
  13254. {
  13255. value = other.value;
  13256. return *this;
  13257. }
  13258. Value::~Value()
  13259. {
  13260. if (listeners.size() > 0)
  13261. value->valuesWithListeners.removeValue (this);
  13262. }
  13263. const var Value::getValue() const
  13264. {
  13265. return value->getValue();
  13266. }
  13267. Value::operator const var() const
  13268. {
  13269. return getValue();
  13270. }
  13271. void Value::setValue (const var& newValue)
  13272. {
  13273. value->setValue (newValue);
  13274. }
  13275. const String Value::toString() const
  13276. {
  13277. return value->getValue().toString();
  13278. }
  13279. Value& Value::operator= (const var& newValue)
  13280. {
  13281. value->setValue (newValue);
  13282. return *this;
  13283. }
  13284. void Value::referTo (const Value& valueToReferTo)
  13285. {
  13286. if (valueToReferTo.value != value)
  13287. {
  13288. if (listeners.size() > 0)
  13289. {
  13290. value->valuesWithListeners.removeValue (this);
  13291. valueToReferTo.value->valuesWithListeners.add (this);
  13292. }
  13293. value = valueToReferTo.value;
  13294. callListeners();
  13295. }
  13296. }
  13297. bool Value::refersToSameSourceAs (const Value& other) const
  13298. {
  13299. return value == other.value;
  13300. }
  13301. bool Value::operator== (const Value& other) const
  13302. {
  13303. return value == other.value || value->getValue() == other.getValue();
  13304. }
  13305. bool Value::operator!= (const Value& other) const
  13306. {
  13307. return value != other.value && value->getValue() != other.getValue();
  13308. }
  13309. void Value::addListener (Listener* const listener)
  13310. {
  13311. if (listener != 0)
  13312. {
  13313. if (listeners.size() == 0)
  13314. value->valuesWithListeners.add (this);
  13315. listeners.add (listener);
  13316. }
  13317. }
  13318. void Value::removeListener (Listener* const listener)
  13319. {
  13320. listeners.remove (listener);
  13321. if (listeners.size() == 0)
  13322. value->valuesWithListeners.removeValue (this);
  13323. }
  13324. void Value::callListeners()
  13325. {
  13326. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13327. listeners.call (&Listener::valueChanged, v);
  13328. }
  13329. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13330. {
  13331. return stream << value.toString();
  13332. }
  13333. END_JUCE_NAMESPACE
  13334. /*** End of inlined file: juce_Value.cpp ***/
  13335. /*** Start of inlined file: juce_Application.cpp ***/
  13336. #if JUCE_MSVC
  13337. #pragma warning (push)
  13338. #pragma warning (disable: 4245 4514 4100)
  13339. #include <crtdbg.h>
  13340. #pragma warning (pop)
  13341. #endif
  13342. BEGIN_JUCE_NAMESPACE
  13343. void juce_setCurrentThreadName (const String& name);
  13344. static JUCEApplication* appInstance = 0;
  13345. JUCEApplication::JUCEApplication()
  13346. : appReturnValue (0),
  13347. stillInitialising (true)
  13348. {
  13349. }
  13350. JUCEApplication::~JUCEApplication()
  13351. {
  13352. if (appLock != 0)
  13353. {
  13354. appLock->exit();
  13355. appLock = 0;
  13356. }
  13357. }
  13358. JUCEApplication* JUCEApplication::getInstance() throw()
  13359. {
  13360. return appInstance;
  13361. }
  13362. bool JUCEApplication::isInitialising() const throw()
  13363. {
  13364. return stillInitialising;
  13365. }
  13366. const String JUCEApplication::getApplicationVersion()
  13367. {
  13368. return String::empty;
  13369. }
  13370. bool JUCEApplication::moreThanOneInstanceAllowed()
  13371. {
  13372. return true;
  13373. }
  13374. void JUCEApplication::anotherInstanceStarted (const String&)
  13375. {
  13376. }
  13377. void JUCEApplication::systemRequestedQuit()
  13378. {
  13379. quit();
  13380. }
  13381. void JUCEApplication::quit()
  13382. {
  13383. MessageManager::getInstance()->stopDispatchLoop();
  13384. }
  13385. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13386. {
  13387. appReturnValue = newReturnValue;
  13388. }
  13389. void JUCEApplication::unhandledException (const std::exception*,
  13390. const String&,
  13391. const int)
  13392. {
  13393. jassertfalse
  13394. }
  13395. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13396. const char* const sourceFile,
  13397. const int lineNumber)
  13398. {
  13399. if (appInstance != 0)
  13400. appInstance->unhandledException (e, sourceFile, lineNumber);
  13401. }
  13402. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13403. {
  13404. return 0;
  13405. }
  13406. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13407. {
  13408. commands.add (StandardApplicationCommandIDs::quit);
  13409. }
  13410. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13411. {
  13412. if (commandID == StandardApplicationCommandIDs::quit)
  13413. {
  13414. result.setInfo (TRANS("Quit"),
  13415. TRANS("Quits the application"),
  13416. "Application",
  13417. 0);
  13418. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13419. }
  13420. }
  13421. bool JUCEApplication::perform (const InvocationInfo& info)
  13422. {
  13423. if (info.commandID == StandardApplicationCommandIDs::quit)
  13424. {
  13425. systemRequestedQuit();
  13426. return true;
  13427. }
  13428. return false;
  13429. }
  13430. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13431. {
  13432. if (! app->initialiseApp (commandLine))
  13433. return 0;
  13434. // now loop until a quit message is received..
  13435. JUCE_TRY
  13436. {
  13437. MessageManager::getInstance()->runDispatchLoop();
  13438. }
  13439. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13440. catch (const std::exception& e)
  13441. {
  13442. app->unhandledException (&e, __FILE__, __LINE__);
  13443. }
  13444. catch (...)
  13445. {
  13446. app->unhandledException (0, __FILE__, __LINE__);
  13447. }
  13448. #endif
  13449. return shutdownAppAndClearUp();
  13450. }
  13451. bool JUCEApplication::initialiseApp (String& commandLine)
  13452. {
  13453. jassert (appInstance == 0);
  13454. appInstance = this;
  13455. commandLineParameters = commandLine.trim();
  13456. commandLine = String::empty;
  13457. initialiseJuce_GUI();
  13458. #if ! JUCE_IPHONE
  13459. jassert (appLock == 0); // initialiseApp must only be called once!
  13460. if (! moreThanOneInstanceAllowed())
  13461. {
  13462. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13463. if (! appLock->enter(0))
  13464. {
  13465. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13466. delete appInstance;
  13467. appInstance = 0;
  13468. DBG ("Another instance is running - quitting...");
  13469. return false;
  13470. }
  13471. }
  13472. #endif
  13473. // let the app do its setting-up..
  13474. initialise (commandLineParameters);
  13475. // register for broadcast new app messages
  13476. MessageManager::getInstance()->registerBroadcastListener (this);
  13477. stillInitialising = false;
  13478. return true;
  13479. }
  13480. int JUCEApplication::shutdownAppAndClearUp()
  13481. {
  13482. jassert (appInstance != 0);
  13483. ScopedPointer<JUCEApplication> app (appInstance);
  13484. int returnValue = 0;
  13485. MessageManager::getInstance()->deregisterBroadcastListener (static_cast <JUCEApplication*> (app));
  13486. static bool reentrancyCheck = false;
  13487. if (! reentrancyCheck)
  13488. {
  13489. reentrancyCheck = true;
  13490. JUCE_TRY
  13491. {
  13492. // give the app a chance to clean up..
  13493. app->shutdown();
  13494. }
  13495. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13496. catch (const std::exception& e)
  13497. {
  13498. app->unhandledException (&e, __FILE__, __LINE__);
  13499. }
  13500. catch (...)
  13501. {
  13502. app->unhandledException (0, __FILE__, __LINE__);
  13503. }
  13504. #endif
  13505. JUCE_TRY
  13506. {
  13507. shutdownJuce_GUI();
  13508. returnValue = app->getApplicationReturnValue();
  13509. appInstance = 0;
  13510. app = 0;
  13511. }
  13512. JUCE_CATCH_ALL_ASSERT
  13513. reentrancyCheck = false;
  13514. }
  13515. return returnValue;
  13516. }
  13517. #if JUCE_IPHONE
  13518. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13519. #endif
  13520. #if ! JUCE_WINDOWS
  13521. extern const char* juce_Argv0;
  13522. #endif
  13523. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13524. {
  13525. #if ! JUCE_WINDOWS
  13526. juce_Argv0 = argv[0];
  13527. #endif
  13528. #if JUCE_IPHONE
  13529. const ScopedAutoReleasePool pool;
  13530. return juce_IPhoneMain (argc, argv, newApp);
  13531. #else
  13532. #if JUCE_MAC
  13533. const ScopedAutoReleasePool pool;
  13534. #endif
  13535. String cmd;
  13536. for (int i = 1; i < argc; ++i)
  13537. cmd << argv[i] << ' ';
  13538. return JUCEApplication::main (cmd, newApp);
  13539. #endif
  13540. }
  13541. void JUCEApplication::actionListenerCallback (const String& message)
  13542. {
  13543. if (message.startsWith (getApplicationName() + "/"))
  13544. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13545. }
  13546. static bool juceInitialisedGUI = false;
  13547. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13548. {
  13549. if (! juceInitialisedGUI)
  13550. {
  13551. #if JUCE_MAC || JUCE_IPHONE
  13552. const ScopedAutoReleasePool pool;
  13553. #endif
  13554. juceInitialisedGUI = true;
  13555. initialiseJuce_NonGUI();
  13556. MessageManager::getInstance();
  13557. LookAndFeel::setDefaultLookAndFeel (0);
  13558. juce_setCurrentThreadName ("Juce Message Thread");
  13559. #if JUCE_WINDOWS && JUCE_DEBUG
  13560. // This section is just for catching people who mess up their project settings and
  13561. // turn RTTI off..
  13562. try
  13563. {
  13564. TextButton tb (String::empty);
  13565. Component* c = &tb;
  13566. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13567. c = dynamic_cast <Button*> (c);
  13568. }
  13569. catch (...)
  13570. {
  13571. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13572. // got as far as this catch statement, then why haven't you got exception catching
  13573. // turned on in the debugger???
  13574. jassertfalse
  13575. }
  13576. #endif
  13577. }
  13578. }
  13579. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13580. {
  13581. if (juceInitialisedGUI)
  13582. {
  13583. #if JUCE_MAC
  13584. const ScopedAutoReleasePool pool;
  13585. #endif
  13586. {
  13587. DeletedAtShutdown::deleteAll();
  13588. LookAndFeel::clearDefaultLookAndFeel();
  13589. }
  13590. delete MessageManager::getInstance();
  13591. shutdownJuce_NonGUI();
  13592. juceInitialisedGUI = false;
  13593. }
  13594. }
  13595. END_JUCE_NAMESPACE
  13596. /*** End of inlined file: juce_Application.cpp ***/
  13597. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13598. BEGIN_JUCE_NAMESPACE
  13599. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13600. : commandID (commandID_),
  13601. flags (0)
  13602. {
  13603. }
  13604. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13605. const String& description_,
  13606. const String& categoryName_,
  13607. const int flags_) throw()
  13608. {
  13609. shortName = shortName_;
  13610. description = description_;
  13611. categoryName = categoryName_;
  13612. flags = flags_;
  13613. }
  13614. void ApplicationCommandInfo::setActive (const bool b) throw()
  13615. {
  13616. if (b)
  13617. flags &= ~isDisabled;
  13618. else
  13619. flags |= isDisabled;
  13620. }
  13621. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13622. {
  13623. if (b)
  13624. flags |= isTicked;
  13625. else
  13626. flags &= ~isTicked;
  13627. }
  13628. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13629. {
  13630. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13631. }
  13632. END_JUCE_NAMESPACE
  13633. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13634. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13635. BEGIN_JUCE_NAMESPACE
  13636. ApplicationCommandManager::ApplicationCommandManager()
  13637. : firstTarget (0)
  13638. {
  13639. keyMappings = new KeyPressMappingSet (this);
  13640. Desktop::getInstance().addFocusChangeListener (this);
  13641. }
  13642. ApplicationCommandManager::~ApplicationCommandManager()
  13643. {
  13644. Desktop::getInstance().removeFocusChangeListener (this);
  13645. keyMappings = 0;
  13646. }
  13647. void ApplicationCommandManager::clearCommands()
  13648. {
  13649. commands.clear();
  13650. keyMappings->clearAllKeyPresses();
  13651. triggerAsyncUpdate();
  13652. }
  13653. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13654. {
  13655. // zero isn't a valid command ID!
  13656. jassert (newCommand.commandID != 0);
  13657. // the name isn't optional!
  13658. jassert (newCommand.shortName.isNotEmpty());
  13659. if (getCommandForID (newCommand.commandID) == 0)
  13660. {
  13661. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13662. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13663. commands.add (newInfo);
  13664. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13665. triggerAsyncUpdate();
  13666. }
  13667. else
  13668. {
  13669. // trying to re-register the same command with different parameters?
  13670. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13671. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13672. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13673. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13674. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13675. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13676. }
  13677. }
  13678. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13679. {
  13680. if (target != 0)
  13681. {
  13682. Array <CommandID> commandIDs;
  13683. target->getAllCommands (commandIDs);
  13684. for (int i = 0; i < commandIDs.size(); ++i)
  13685. {
  13686. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13687. target->getCommandInfo (info.commandID, info);
  13688. registerCommand (info);
  13689. }
  13690. }
  13691. }
  13692. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13693. {
  13694. for (int i = commands.size(); --i >= 0;)
  13695. {
  13696. if (commands.getUnchecked (i)->commandID == commandID)
  13697. {
  13698. commands.remove (i);
  13699. triggerAsyncUpdate();
  13700. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13701. for (int j = keys.size(); --j >= 0;)
  13702. keyMappings->removeKeyPress (keys.getReference (j));
  13703. }
  13704. }
  13705. }
  13706. void ApplicationCommandManager::commandStatusChanged()
  13707. {
  13708. triggerAsyncUpdate();
  13709. }
  13710. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13711. {
  13712. for (int i = commands.size(); --i >= 0;)
  13713. if (commands.getUnchecked(i)->commandID == commandID)
  13714. return commands.getUnchecked(i);
  13715. return 0;
  13716. }
  13717. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13718. {
  13719. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13720. return (ci != 0) ? ci->shortName : String::empty;
  13721. }
  13722. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13723. {
  13724. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13725. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13726. : String::empty;
  13727. }
  13728. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13729. {
  13730. StringArray s;
  13731. for (int i = 0; i < commands.size(); ++i)
  13732. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13733. return s;
  13734. }
  13735. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13736. {
  13737. Array <CommandID> results;
  13738. for (int i = 0; i < commands.size(); ++i)
  13739. if (commands.getUnchecked(i)->categoryName == categoryName)
  13740. results.add (commands.getUnchecked(i)->commandID);
  13741. return results;
  13742. }
  13743. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13744. {
  13745. ApplicationCommandTarget::InvocationInfo info (commandID);
  13746. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13747. return invoke (info, asynchronously);
  13748. }
  13749. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13750. {
  13751. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13752. // manager first..
  13753. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13754. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13755. if (target == 0)
  13756. return false;
  13757. ApplicationCommandInfo commandInfo (0);
  13758. target->getCommandInfo (info_.commandID, commandInfo);
  13759. ApplicationCommandTarget::InvocationInfo info (info_);
  13760. info.commandFlags = commandInfo.flags;
  13761. sendListenerInvokeCallback (info);
  13762. const bool ok = target->invoke (info, asynchronously);
  13763. commandStatusChanged();
  13764. return ok;
  13765. }
  13766. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13767. {
  13768. return firstTarget != 0 ? firstTarget
  13769. : findDefaultComponentTarget();
  13770. }
  13771. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13772. {
  13773. firstTarget = newTarget;
  13774. }
  13775. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13776. ApplicationCommandInfo& upToDateInfo)
  13777. {
  13778. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13779. if (target == 0)
  13780. target = JUCEApplication::getInstance();
  13781. if (target != 0)
  13782. target = target->getTargetForCommand (commandID);
  13783. if (target != 0)
  13784. target->getCommandInfo (commandID, upToDateInfo);
  13785. return target;
  13786. }
  13787. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13788. {
  13789. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13790. if (target == 0 && c != 0)
  13791. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13792. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13793. return target;
  13794. }
  13795. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13796. {
  13797. Component* c = Component::getCurrentlyFocusedComponent();
  13798. if (c == 0)
  13799. {
  13800. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13801. if (activeWindow != 0)
  13802. {
  13803. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13804. if (c == 0)
  13805. c = activeWindow;
  13806. }
  13807. }
  13808. if (c == 0 && Process::isForegroundProcess())
  13809. {
  13810. // getting a bit desperate now - try all desktop comps..
  13811. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13812. {
  13813. ApplicationCommandTarget* const target
  13814. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13815. ->getPeer()->getLastFocusedSubcomponent());
  13816. if (target != 0)
  13817. return target;
  13818. }
  13819. }
  13820. if (c != 0)
  13821. {
  13822. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13823. // if we're focused on a ResizableWindow, chances are that it's the content
  13824. // component that really should get the event. And if not, the event will
  13825. // still be passed up to the top level window anyway, so let's send it to the
  13826. // content comp.
  13827. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13828. c = resizableWindow->getContentComponent();
  13829. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13830. if (target != 0)
  13831. return target;
  13832. }
  13833. return JUCEApplication::getInstance();
  13834. }
  13835. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13836. {
  13837. listeners.add (listener);
  13838. }
  13839. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13840. {
  13841. listeners.remove (listener);
  13842. }
  13843. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13844. {
  13845. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13846. }
  13847. void ApplicationCommandManager::handleAsyncUpdate()
  13848. {
  13849. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13850. }
  13851. void ApplicationCommandManager::globalFocusChanged (Component*)
  13852. {
  13853. commandStatusChanged();
  13854. }
  13855. END_JUCE_NAMESPACE
  13856. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13857. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13858. BEGIN_JUCE_NAMESPACE
  13859. ApplicationCommandTarget::ApplicationCommandTarget()
  13860. {
  13861. }
  13862. ApplicationCommandTarget::~ApplicationCommandTarget()
  13863. {
  13864. messageInvoker = 0;
  13865. }
  13866. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13867. {
  13868. if (isCommandActive (info.commandID))
  13869. {
  13870. if (async)
  13871. {
  13872. if (messageInvoker == 0)
  13873. messageInvoker = new CommandTargetMessageInvoker (this);
  13874. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13875. return true;
  13876. }
  13877. else
  13878. {
  13879. const bool success = perform (info);
  13880. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13881. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13882. // returns the command's info.
  13883. return success;
  13884. }
  13885. }
  13886. return false;
  13887. }
  13888. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13889. {
  13890. Component* c = dynamic_cast <Component*> (this);
  13891. if (c != 0)
  13892. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13893. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13894. return 0;
  13895. }
  13896. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13897. {
  13898. ApplicationCommandTarget* target = this;
  13899. int depth = 0;
  13900. while (target != 0)
  13901. {
  13902. Array <CommandID> commandIDs;
  13903. target->getAllCommands (commandIDs);
  13904. if (commandIDs.contains (commandID))
  13905. return target;
  13906. target = target->getNextCommandTarget();
  13907. ++depth;
  13908. jassert (depth < 100); // could be a recursive command chain??
  13909. jassert (target != this); // definitely a recursive command chain!
  13910. if (depth > 100 || target == this)
  13911. break;
  13912. }
  13913. if (target == 0)
  13914. {
  13915. target = JUCEApplication::getInstance();
  13916. if (target != 0)
  13917. {
  13918. Array <CommandID> commandIDs;
  13919. target->getAllCommands (commandIDs);
  13920. if (commandIDs.contains (commandID))
  13921. return target;
  13922. }
  13923. }
  13924. return 0;
  13925. }
  13926. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13927. {
  13928. ApplicationCommandInfo info (commandID);
  13929. info.flags = ApplicationCommandInfo::isDisabled;
  13930. getCommandInfo (commandID, info);
  13931. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13932. }
  13933. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13934. {
  13935. ApplicationCommandTarget* target = this;
  13936. int depth = 0;
  13937. while (target != 0)
  13938. {
  13939. if (target->tryToInvoke (info, async))
  13940. return true;
  13941. target = target->getNextCommandTarget();
  13942. ++depth;
  13943. jassert (depth < 100); // could be a recursive command chain??
  13944. jassert (target != this); // definitely a recursive command chain!
  13945. if (depth > 100 || target == this)
  13946. break;
  13947. }
  13948. if (target == 0)
  13949. {
  13950. target = JUCEApplication::getInstance();
  13951. if (target != 0)
  13952. return target->tryToInvoke (info, async);
  13953. }
  13954. return false;
  13955. }
  13956. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13957. {
  13958. ApplicationCommandTarget::InvocationInfo info (commandID);
  13959. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13960. return invoke (info, asynchronously);
  13961. }
  13962. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  13963. : commandID (commandID_),
  13964. commandFlags (0),
  13965. invocationMethod (direct),
  13966. originatingComponent (0),
  13967. isKeyDown (false),
  13968. millisecsSinceKeyPressed (0)
  13969. {
  13970. }
  13971. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  13972. : owner (owner_)
  13973. {
  13974. }
  13975. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  13976. {
  13977. }
  13978. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  13979. {
  13980. const ScopedPointer <InvocationInfo> info (static_cast <InvocationInfo*> (message.pointerParameter));
  13981. owner->tryToInvoke (*info, false);
  13982. }
  13983. END_JUCE_NAMESPACE
  13984. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13985. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  13986. BEGIN_JUCE_NAMESPACE
  13987. juce_ImplementSingleton (ApplicationProperties)
  13988. ApplicationProperties::ApplicationProperties() throw()
  13989. : msBeforeSaving (3000),
  13990. options (PropertiesFile::storeAsBinary),
  13991. commonSettingsAreReadOnly (0)
  13992. {
  13993. }
  13994. ApplicationProperties::~ApplicationProperties()
  13995. {
  13996. closeFiles();
  13997. clearSingletonInstance();
  13998. }
  13999. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14000. const String& fileNameSuffix,
  14001. const String& folderName_,
  14002. const int millisecondsBeforeSaving,
  14003. const int propertiesFileOptions) throw()
  14004. {
  14005. appName = applicationName;
  14006. fileSuffix = fileNameSuffix;
  14007. folderName = folderName_;
  14008. msBeforeSaving = millisecondsBeforeSaving;
  14009. options = propertiesFileOptions;
  14010. }
  14011. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14012. const bool testCommonSettings,
  14013. const bool showWarningDialogOnFailure)
  14014. {
  14015. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14016. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14017. if (! (userOk && commonOk))
  14018. {
  14019. if (showWarningDialogOnFailure)
  14020. {
  14021. String filenames;
  14022. if (userProps != 0 && ! userOk)
  14023. filenames << '\n' << userProps->getFile().getFullPathName();
  14024. if (commonProps != 0 && ! commonOk)
  14025. filenames << '\n' << commonProps->getFile().getFullPathName();
  14026. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14027. appName + TRANS(" - Unable to save settings"),
  14028. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14029. + appName + TRANS(" needs to be able to write to the following files:\n")
  14030. + filenames
  14031. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14032. }
  14033. return false;
  14034. }
  14035. return true;
  14036. }
  14037. void ApplicationProperties::openFiles() throw()
  14038. {
  14039. // You need to call setStorageParameters() before trying to get hold of the
  14040. // properties!
  14041. jassert (appName.isNotEmpty());
  14042. if (appName.isNotEmpty())
  14043. {
  14044. if (userProps == 0)
  14045. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14046. false, msBeforeSaving, options);
  14047. if (commonProps == 0)
  14048. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14049. true, msBeforeSaving, options);
  14050. userProps->setFallbackPropertySet (commonProps);
  14051. }
  14052. }
  14053. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14054. {
  14055. if (userProps == 0)
  14056. openFiles();
  14057. return userProps;
  14058. }
  14059. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14060. {
  14061. if (commonProps == 0)
  14062. openFiles();
  14063. if (returnUserPropsIfReadOnly)
  14064. {
  14065. if (commonSettingsAreReadOnly == 0)
  14066. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14067. if (commonSettingsAreReadOnly > 0)
  14068. return userProps;
  14069. }
  14070. return commonProps;
  14071. }
  14072. bool ApplicationProperties::saveIfNeeded()
  14073. {
  14074. return (userProps == 0 || userProps->saveIfNeeded())
  14075. && (commonProps == 0 || commonProps->saveIfNeeded());
  14076. }
  14077. void ApplicationProperties::closeFiles()
  14078. {
  14079. userProps = 0;
  14080. commonProps = 0;
  14081. }
  14082. END_JUCE_NAMESPACE
  14083. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14084. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14085. BEGIN_JUCE_NAMESPACE
  14086. static VoidArray objectsToDelete;
  14087. static CriticalSection lock;
  14088. DeletedAtShutdown::DeletedAtShutdown()
  14089. {
  14090. const ScopedLock sl (lock);
  14091. objectsToDelete.add (this);
  14092. }
  14093. DeletedAtShutdown::~DeletedAtShutdown()
  14094. {
  14095. const ScopedLock sl (lock);
  14096. objectsToDelete.removeValue (this);
  14097. }
  14098. void DeletedAtShutdown::deleteAll()
  14099. {
  14100. // make a local copy of the array, so it can't get into a loop if something
  14101. // creates another DeletedAtShutdown object during its destructor.
  14102. VoidArray localCopy;
  14103. {
  14104. const ScopedLock sl (lock);
  14105. localCopy = objectsToDelete;
  14106. }
  14107. for (int i = localCopy.size(); --i >= 0;)
  14108. {
  14109. JUCE_TRY
  14110. {
  14111. DeletedAtShutdown* deletee = static_cast <DeletedAtShutdown*> (localCopy.getUnchecked(i));
  14112. // double-check that it's not already been deleted during another object's destructor.
  14113. {
  14114. const ScopedLock sl (lock);
  14115. if (! objectsToDelete.contains (deletee))
  14116. deletee = 0;
  14117. }
  14118. delete deletee;
  14119. }
  14120. JUCE_CATCH_EXCEPTION
  14121. }
  14122. // if no objects got re-created during shutdown, this should have been emptied by their
  14123. // destructors
  14124. jassert (objectsToDelete.size() == 0);
  14125. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14126. }
  14127. END_JUCE_NAMESPACE
  14128. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14129. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14130. BEGIN_JUCE_NAMESPACE
  14131. namespace PropertyFileConstants
  14132. {
  14133. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14134. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14135. static const char* const fileTag = "PROPERTIES";
  14136. static const char* const valueTag = "VALUE";
  14137. static const char* const nameAttribute = "name";
  14138. static const char* const valueAttribute = "val";
  14139. }
  14140. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving,
  14141. const int options_, InterProcessLock* const processLock_)
  14142. : PropertySet (ignoreCaseOfKeyNames),
  14143. file (f),
  14144. timerInterval (millisecondsBeforeSaving),
  14145. options (options_),
  14146. loadedOk (false),
  14147. needsWriting (false),
  14148. processLock (processLock_)
  14149. {
  14150. // You need to correctly specify just one storage format for the file
  14151. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14152. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14153. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14154. ProcessScopedLock pl (createProcessLock());
  14155. if (pl != 0 && ! pl->isLocked())
  14156. return; // locking failure..
  14157. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14158. if (fileStream != 0)
  14159. {
  14160. int magicNumber = fileStream->readInt();
  14161. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14162. {
  14163. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14164. magicNumber = PropertyFileConstants::magicNumber;
  14165. }
  14166. if (magicNumber == PropertyFileConstants::magicNumber)
  14167. {
  14168. loadedOk = true;
  14169. BufferedInputStream in (fileStream.release(), 2048, true);
  14170. int numValues = in.readInt();
  14171. while (--numValues >= 0 && ! in.isExhausted())
  14172. {
  14173. const String key (in.readString());
  14174. const String value (in.readString());
  14175. jassert (key.isNotEmpty());
  14176. if (key.isNotEmpty())
  14177. getAllProperties().set (key, value);
  14178. }
  14179. }
  14180. else
  14181. {
  14182. // Not a binary props file - let's see if it's XML..
  14183. fileStream = 0;
  14184. XmlDocument parser (f);
  14185. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14186. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14187. {
  14188. doc = parser.getDocumentElement();
  14189. if (doc != 0)
  14190. {
  14191. loadedOk = true;
  14192. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14193. {
  14194. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14195. if (name.isNotEmpty())
  14196. {
  14197. getAllProperties().set (name,
  14198. e->getFirstChildElement() != 0
  14199. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14200. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14201. }
  14202. }
  14203. }
  14204. else
  14205. {
  14206. // must be a pretty broken XML file we're trying to parse here,
  14207. // or a sign that this object needs an InterProcessLock,
  14208. // or just a failure reading the file. This last reason is why
  14209. // we don't jassertfalse here.
  14210. }
  14211. }
  14212. }
  14213. }
  14214. else
  14215. {
  14216. loadedOk = ! f.exists();
  14217. }
  14218. }
  14219. PropertiesFile::~PropertiesFile()
  14220. {
  14221. if (! saveIfNeeded())
  14222. jassertfalse;
  14223. }
  14224. InterProcessLock::ScopedLockType* PropertiesFile::createProcessLock() const
  14225. {
  14226. return processLock != 0 ? new InterProcessLock::ScopedLockType (*processLock) : 0;
  14227. }
  14228. bool PropertiesFile::saveIfNeeded()
  14229. {
  14230. const ScopedLock sl (getLock());
  14231. return (! needsWriting) || save();
  14232. }
  14233. bool PropertiesFile::needsToBeSaved() const
  14234. {
  14235. const ScopedLock sl (getLock());
  14236. return needsWriting;
  14237. }
  14238. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14239. {
  14240. const ScopedLock sl (getLock());
  14241. needsWriting = needsToBeSaved;
  14242. }
  14243. bool PropertiesFile::save()
  14244. {
  14245. const ScopedLock sl (getLock());
  14246. stopTimer();
  14247. if (file == File::nonexistent
  14248. || file.isDirectory()
  14249. || ! file.getParentDirectory().createDirectory())
  14250. return false;
  14251. if ((options & storeAsXML) != 0)
  14252. {
  14253. XmlElement doc (PropertyFileConstants::fileTag);
  14254. for (int i = 0; i < getAllProperties().size(); ++i)
  14255. {
  14256. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14257. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14258. // if the value seems to contain xml, store it as such..
  14259. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14260. XmlElement* const childElement = xmlContent.getDocumentElement();
  14261. if (childElement != 0)
  14262. e->addChildElement (childElement);
  14263. else
  14264. e->setAttribute (PropertyFileConstants::valueAttribute,
  14265. getAllProperties().getAllValues() [i]);
  14266. }
  14267. ProcessScopedLock pl (createProcessLock());
  14268. if (pl != 0 && ! pl->isLocked())
  14269. return false; // locking failure..
  14270. if (doc.writeToFile (file, String::empty))
  14271. {
  14272. needsWriting = false;
  14273. return true;
  14274. }
  14275. }
  14276. else
  14277. {
  14278. ProcessScopedLock pl (createProcessLock());
  14279. if (pl != 0 && ! pl->isLocked())
  14280. return false; // locking failure..
  14281. TemporaryFile tempFile (file);
  14282. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14283. if (out != 0)
  14284. {
  14285. if ((options & storeAsCompressedBinary) != 0)
  14286. {
  14287. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14288. out->flush();
  14289. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14290. }
  14291. else
  14292. {
  14293. // have you set up the storage option flags correctly?
  14294. jassert ((options & storeAsBinary) != 0);
  14295. out->writeInt (PropertyFileConstants::magicNumber);
  14296. }
  14297. const int numProperties = getAllProperties().size();
  14298. out->writeInt (numProperties);
  14299. for (int i = 0; i < numProperties; ++i)
  14300. {
  14301. out->writeString (getAllProperties().getAllKeys() [i]);
  14302. out->writeString (getAllProperties().getAllValues() [i]);
  14303. }
  14304. out = 0;
  14305. if (tempFile.overwriteTargetFileWithTemporary())
  14306. {
  14307. needsWriting = false;
  14308. return true;
  14309. }
  14310. }
  14311. }
  14312. return false;
  14313. }
  14314. void PropertiesFile::timerCallback()
  14315. {
  14316. saveIfNeeded();
  14317. }
  14318. void PropertiesFile::propertyChanged()
  14319. {
  14320. sendChangeMessage (this);
  14321. needsWriting = true;
  14322. if (timerInterval > 0)
  14323. startTimer (timerInterval);
  14324. else if (timerInterval == 0)
  14325. saveIfNeeded();
  14326. }
  14327. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14328. const String& fileNameSuffix,
  14329. const String& folderName,
  14330. const bool commonToAllUsers)
  14331. {
  14332. // mustn't have illegal characters in this name..
  14333. jassert (applicationName == File::createLegalFileName (applicationName));
  14334. #if JUCE_MAC || JUCE_IPHONE
  14335. File dir (commonToAllUsers ? "/Library/Preferences"
  14336. : "~/Library/Preferences");
  14337. if (folderName.isNotEmpty())
  14338. dir = dir.getChildFile (folderName);
  14339. #endif
  14340. #ifdef JUCE_LINUX
  14341. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14342. + (folderName.isNotEmpty() ? folderName
  14343. : ("." + applicationName)));
  14344. #endif
  14345. #if JUCE_WIN32
  14346. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14347. : File::userApplicationDataDirectory));
  14348. if (dir == File::nonexistent)
  14349. return File::nonexistent;
  14350. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14351. : applicationName);
  14352. #endif
  14353. return dir.getChildFile (applicationName)
  14354. .withFileExtension (fileNameSuffix);
  14355. }
  14356. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14357. const String& fileNameSuffix,
  14358. const String& folderName,
  14359. const bool commonToAllUsers,
  14360. const int millisecondsBeforeSaving,
  14361. const int propertiesFileOptions,
  14362. InterProcessLock* processLock_)
  14363. {
  14364. const File file (getDefaultAppSettingsFile (applicationName,
  14365. fileNameSuffix,
  14366. folderName,
  14367. commonToAllUsers));
  14368. jassert (file != File::nonexistent);
  14369. if (file == File::nonexistent)
  14370. return 0;
  14371. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions,processLock_);
  14372. }
  14373. END_JUCE_NAMESPACE
  14374. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14375. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14376. BEGIN_JUCE_NAMESPACE
  14377. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14378. const String& fileWildcard_,
  14379. const String& openFileDialogTitle_,
  14380. const String& saveFileDialogTitle_)
  14381. : changedSinceSave (false),
  14382. fileExtension (fileExtension_),
  14383. fileWildcard (fileWildcard_),
  14384. openFileDialogTitle (openFileDialogTitle_),
  14385. saveFileDialogTitle (saveFileDialogTitle_)
  14386. {
  14387. }
  14388. FileBasedDocument::~FileBasedDocument()
  14389. {
  14390. }
  14391. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14392. {
  14393. if (changedSinceSave != hasChanged)
  14394. {
  14395. changedSinceSave = hasChanged;
  14396. sendChangeMessage (this);
  14397. }
  14398. }
  14399. void FileBasedDocument::changed()
  14400. {
  14401. changedSinceSave = true;
  14402. sendChangeMessage (this);
  14403. }
  14404. void FileBasedDocument::setFile (const File& newFile)
  14405. {
  14406. if (documentFile != newFile)
  14407. {
  14408. documentFile = newFile;
  14409. changed();
  14410. }
  14411. }
  14412. bool FileBasedDocument::loadFrom (const File& newFile,
  14413. const bool showMessageOnFailure)
  14414. {
  14415. MouseCursor::showWaitCursor();
  14416. const File oldFile (documentFile);
  14417. documentFile = newFile;
  14418. String error;
  14419. if (newFile.existsAsFile())
  14420. {
  14421. error = loadDocument (newFile);
  14422. if (error.isEmpty())
  14423. {
  14424. setChangedFlag (false);
  14425. MouseCursor::hideWaitCursor();
  14426. setLastDocumentOpened (newFile);
  14427. return true;
  14428. }
  14429. }
  14430. else
  14431. {
  14432. error = "The file doesn't exist";
  14433. }
  14434. documentFile = oldFile;
  14435. MouseCursor::hideWaitCursor();
  14436. if (showMessageOnFailure)
  14437. {
  14438. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14439. TRANS("Failed to open file..."),
  14440. TRANS("There was an error while trying to load the file:\n\n")
  14441. + newFile.getFullPathName()
  14442. + "\n\n"
  14443. + error);
  14444. }
  14445. return false;
  14446. }
  14447. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14448. {
  14449. FileChooser fc (openFileDialogTitle,
  14450. getLastDocumentOpened(),
  14451. fileWildcard);
  14452. if (fc.browseForFileToOpen())
  14453. return loadFrom (fc.getResult(), showMessageOnFailure);
  14454. return false;
  14455. }
  14456. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14457. const bool showMessageOnFailure)
  14458. {
  14459. return saveAs (documentFile,
  14460. false,
  14461. askUserForFileIfNotSpecified,
  14462. showMessageOnFailure);
  14463. }
  14464. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14465. const bool warnAboutOverwritingExistingFiles,
  14466. const bool askUserForFileIfNotSpecified,
  14467. const bool showMessageOnFailure)
  14468. {
  14469. if (newFile == File::nonexistent)
  14470. {
  14471. if (askUserForFileIfNotSpecified)
  14472. {
  14473. return saveAsInteractive (true);
  14474. }
  14475. else
  14476. {
  14477. // can't save to an unspecified file
  14478. jassertfalse
  14479. return failedToWriteToFile;
  14480. }
  14481. }
  14482. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14483. {
  14484. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14485. TRANS("File already exists"),
  14486. TRANS("There's already a file called:\n\n")
  14487. + newFile.getFullPathName()
  14488. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14489. TRANS("overwrite"),
  14490. TRANS("cancel")))
  14491. {
  14492. return userCancelledSave;
  14493. }
  14494. }
  14495. MouseCursor::showWaitCursor();
  14496. const File oldFile (documentFile);
  14497. documentFile = newFile;
  14498. String error (saveDocument (newFile));
  14499. if (error.isEmpty())
  14500. {
  14501. setChangedFlag (false);
  14502. MouseCursor::hideWaitCursor();
  14503. return savedOk;
  14504. }
  14505. documentFile = oldFile;
  14506. MouseCursor::hideWaitCursor();
  14507. if (showMessageOnFailure)
  14508. {
  14509. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14510. TRANS("Error writing to file..."),
  14511. TRANS("An error occurred while trying to save \"")
  14512. + getDocumentTitle()
  14513. + TRANS("\" to the file:\n\n")
  14514. + newFile.getFullPathName()
  14515. + "\n\n"
  14516. + error);
  14517. }
  14518. return failedToWriteToFile;
  14519. }
  14520. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14521. {
  14522. if (! hasChangedSinceSaved())
  14523. return savedOk;
  14524. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14525. TRANS("Closing document..."),
  14526. TRANS("Do you want to save the changes to \"")
  14527. + getDocumentTitle() + "\"?",
  14528. TRANS("save"),
  14529. TRANS("discard changes"),
  14530. TRANS("cancel"));
  14531. if (r == 1)
  14532. {
  14533. // save changes
  14534. return save (true, true);
  14535. }
  14536. else if (r == 2)
  14537. {
  14538. // discard changes
  14539. return savedOk;
  14540. }
  14541. return userCancelledSave;
  14542. }
  14543. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14544. {
  14545. File f;
  14546. if (documentFile.existsAsFile())
  14547. f = documentFile;
  14548. else
  14549. f = getLastDocumentOpened();
  14550. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14551. if (legalFilename.isEmpty())
  14552. legalFilename = "unnamed";
  14553. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14554. f = f.getSiblingFile (legalFilename);
  14555. else
  14556. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14557. f = f.withFileExtension (fileExtension)
  14558. .getNonexistentSibling (true);
  14559. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14560. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14561. {
  14562. setLastDocumentOpened (fc.getResult());
  14563. File chosen (fc.getResult());
  14564. if (chosen.getFileExtension().isEmpty())
  14565. {
  14566. chosen = chosen.withFileExtension (fileExtension);
  14567. if (chosen.exists())
  14568. {
  14569. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14570. TRANS("File already exists"),
  14571. TRANS("There's already a file called:")
  14572. + "\n\n" + chosen.getFullPathName()
  14573. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14574. TRANS("overwrite"),
  14575. TRANS("cancel")))
  14576. {
  14577. return userCancelledSave;
  14578. }
  14579. }
  14580. }
  14581. return saveAs (chosen, false, false, true);
  14582. }
  14583. return userCancelledSave;
  14584. }
  14585. END_JUCE_NAMESPACE
  14586. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14587. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14588. BEGIN_JUCE_NAMESPACE
  14589. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14590. : maxNumberOfItems (10)
  14591. {
  14592. }
  14593. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14594. {
  14595. }
  14596. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14597. {
  14598. maxNumberOfItems = jmax (1, newMaxNumber);
  14599. while (getNumFiles() > maxNumberOfItems)
  14600. files.remove (getNumFiles() - 1);
  14601. }
  14602. int RecentlyOpenedFilesList::getNumFiles() const
  14603. {
  14604. return files.size();
  14605. }
  14606. const File RecentlyOpenedFilesList::getFile (const int index) const
  14607. {
  14608. return File (files [index]);
  14609. }
  14610. void RecentlyOpenedFilesList::clear()
  14611. {
  14612. files.clear();
  14613. }
  14614. void RecentlyOpenedFilesList::addFile (const File& file)
  14615. {
  14616. const String path (file.getFullPathName());
  14617. files.removeString (path, true);
  14618. files.insert (0, path);
  14619. setMaxNumberOfItems (maxNumberOfItems);
  14620. }
  14621. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14622. {
  14623. for (int i = getNumFiles(); --i >= 0;)
  14624. if (! getFile(i).exists())
  14625. files.remove (i);
  14626. }
  14627. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14628. const int baseItemId,
  14629. const bool showFullPaths,
  14630. const bool dontAddNonExistentFiles,
  14631. const File** filesToAvoid)
  14632. {
  14633. int num = 0;
  14634. for (int i = 0; i < getNumFiles(); ++i)
  14635. {
  14636. const File f (getFile(i));
  14637. if ((! dontAddNonExistentFiles) || f.exists())
  14638. {
  14639. bool needsAvoiding = false;
  14640. if (filesToAvoid != 0)
  14641. {
  14642. const File** avoid = filesToAvoid;
  14643. while (*avoid != 0)
  14644. {
  14645. if (f == **avoid)
  14646. {
  14647. needsAvoiding = true;
  14648. break;
  14649. }
  14650. ++avoid;
  14651. }
  14652. }
  14653. if (! needsAvoiding)
  14654. {
  14655. menuToAddTo.addItem (baseItemId + i,
  14656. showFullPaths ? f.getFullPathName()
  14657. : f.getFileName());
  14658. ++num;
  14659. }
  14660. }
  14661. }
  14662. return num;
  14663. }
  14664. const String RecentlyOpenedFilesList::toString() const
  14665. {
  14666. return files.joinIntoString ("\n");
  14667. }
  14668. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14669. {
  14670. clear();
  14671. files.addLines (stringifiedVersion);
  14672. setMaxNumberOfItems (maxNumberOfItems);
  14673. }
  14674. END_JUCE_NAMESPACE
  14675. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14676. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14677. BEGIN_JUCE_NAMESPACE
  14678. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14679. const int minimumTransactions)
  14680. : totalUnitsStored (0),
  14681. nextIndex (0),
  14682. newTransaction (true),
  14683. reentrancyCheck (false)
  14684. {
  14685. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14686. minimumTransactions);
  14687. }
  14688. UndoManager::~UndoManager()
  14689. {
  14690. clearUndoHistory();
  14691. }
  14692. void UndoManager::clearUndoHistory()
  14693. {
  14694. transactions.clear();
  14695. transactionNames.clear();
  14696. totalUnitsStored = 0;
  14697. nextIndex = 0;
  14698. sendChangeMessage (this);
  14699. }
  14700. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14701. {
  14702. return totalUnitsStored;
  14703. }
  14704. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14705. const int minimumTransactions)
  14706. {
  14707. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14708. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14709. }
  14710. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14711. {
  14712. if (command != 0)
  14713. {
  14714. if (actionName.isNotEmpty())
  14715. currentTransactionName = actionName;
  14716. if (reentrancyCheck)
  14717. {
  14718. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14719. // undo() methods, or else these actions won't actually get done.
  14720. return false;
  14721. }
  14722. else
  14723. {
  14724. bool success = false;
  14725. JUCE_TRY
  14726. {
  14727. success = command->perform();
  14728. }
  14729. JUCE_CATCH_EXCEPTION
  14730. jassert (success);
  14731. if (success)
  14732. {
  14733. if (nextIndex > 0 && ! newTransaction)
  14734. {
  14735. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14736. jassert (commandSet != 0);
  14737. if (commandSet == 0)
  14738. return false;
  14739. commandSet->add (command);
  14740. }
  14741. else
  14742. {
  14743. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14744. commandSet->add (command);
  14745. transactions.insert (nextIndex, commandSet);
  14746. transactionNames.insert (nextIndex, currentTransactionName);
  14747. ++nextIndex;
  14748. }
  14749. totalUnitsStored += command->getSizeInUnits();
  14750. newTransaction = false;
  14751. }
  14752. while (nextIndex < transactions.size())
  14753. {
  14754. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14755. for (int i = lastSet->size(); --i >= 0;)
  14756. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14757. transactions.removeLast();
  14758. transactionNames.remove (transactionNames.size() - 1);
  14759. }
  14760. while (nextIndex > 0
  14761. && totalUnitsStored > maxNumUnitsToKeep
  14762. && transactions.size() > minimumTransactionsToKeep)
  14763. {
  14764. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14765. for (int i = firstSet->size(); --i >= 0;)
  14766. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14767. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14768. transactions.remove (0);
  14769. transactionNames.remove (0);
  14770. --nextIndex;
  14771. }
  14772. sendChangeMessage (this);
  14773. return success;
  14774. }
  14775. }
  14776. return false;
  14777. }
  14778. void UndoManager::beginNewTransaction (const String& actionName)
  14779. {
  14780. newTransaction = true;
  14781. currentTransactionName = actionName;
  14782. }
  14783. void UndoManager::setCurrentTransactionName (const String& newName)
  14784. {
  14785. currentTransactionName = newName;
  14786. }
  14787. bool UndoManager::canUndo() const
  14788. {
  14789. return nextIndex > 0;
  14790. }
  14791. bool UndoManager::canRedo() const
  14792. {
  14793. return nextIndex < transactions.size();
  14794. }
  14795. const String UndoManager::getUndoDescription() const
  14796. {
  14797. return transactionNames [nextIndex - 1];
  14798. }
  14799. const String UndoManager::getRedoDescription() const
  14800. {
  14801. return transactionNames [nextIndex];
  14802. }
  14803. bool UndoManager::undo()
  14804. {
  14805. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14806. if (commandSet == 0)
  14807. return false;
  14808. reentrancyCheck = true;
  14809. bool failed = false;
  14810. for (int i = commandSet->size(); --i >= 0;)
  14811. {
  14812. if (! commandSet->getUnchecked(i)->undo())
  14813. {
  14814. jassertfalse
  14815. failed = true;
  14816. break;
  14817. }
  14818. }
  14819. reentrancyCheck = false;
  14820. if (failed)
  14821. {
  14822. clearUndoHistory();
  14823. }
  14824. else
  14825. {
  14826. --nextIndex;
  14827. }
  14828. beginNewTransaction();
  14829. sendChangeMessage (this);
  14830. return true;
  14831. }
  14832. bool UndoManager::redo()
  14833. {
  14834. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14835. if (commandSet == 0)
  14836. return false;
  14837. reentrancyCheck = true;
  14838. bool failed = false;
  14839. for (int i = 0; i < commandSet->size(); ++i)
  14840. {
  14841. if (! commandSet->getUnchecked(i)->perform())
  14842. {
  14843. jassertfalse
  14844. failed = true;
  14845. break;
  14846. }
  14847. }
  14848. reentrancyCheck = false;
  14849. if (failed)
  14850. {
  14851. clearUndoHistory();
  14852. }
  14853. else
  14854. {
  14855. ++nextIndex;
  14856. }
  14857. beginNewTransaction();
  14858. sendChangeMessage (this);
  14859. return true;
  14860. }
  14861. bool UndoManager::undoCurrentTransactionOnly()
  14862. {
  14863. return newTransaction ? false
  14864. : undo();
  14865. }
  14866. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14867. {
  14868. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14869. if (commandSet != 0 && ! newTransaction)
  14870. {
  14871. for (int i = 0; i < commandSet->size(); ++i)
  14872. actionsFound.add (commandSet->getUnchecked(i));
  14873. }
  14874. }
  14875. int UndoManager::getNumActionsInCurrentTransaction() const
  14876. {
  14877. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14878. if (commandSet != 0 && ! newTransaction)
  14879. return commandSet->size();
  14880. return 0;
  14881. }
  14882. END_JUCE_NAMESPACE
  14883. /*** End of inlined file: juce_UndoManager.cpp ***/
  14884. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14885. BEGIN_JUCE_NAMESPACE
  14886. static const char* const aiffFormatName = "AIFF file";
  14887. static const juce_wchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14888. class AiffAudioFormatReader : public AudioFormatReader
  14889. {
  14890. public:
  14891. int bytesPerFrame;
  14892. int64 dataChunkStart;
  14893. bool littleEndian;
  14894. AiffAudioFormatReader (InputStream* in)
  14895. : AudioFormatReader (in, TRANS (aiffFormatName))
  14896. {
  14897. if (input->readInt() == chunkName ("FORM"))
  14898. {
  14899. const int len = input->readIntBigEndian();
  14900. const int64 end = input->getPosition() + len;
  14901. const int nextType = input->readInt();
  14902. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14903. {
  14904. bool hasGotVer = false;
  14905. bool hasGotData = false;
  14906. bool hasGotType = false;
  14907. while (input->getPosition() < end)
  14908. {
  14909. const int type = input->readInt();
  14910. const uint32 length = (uint32) input->readIntBigEndian();
  14911. const int64 chunkEnd = input->getPosition() + length;
  14912. if (type == chunkName ("FVER"))
  14913. {
  14914. hasGotVer = true;
  14915. const int ver = input->readIntBigEndian();
  14916. if (ver != 0 && ver != (int)0xa2805140)
  14917. break;
  14918. }
  14919. else if (type == chunkName ("COMM"))
  14920. {
  14921. hasGotType = true;
  14922. numChannels = (unsigned int)input->readShortBigEndian();
  14923. lengthInSamples = input->readIntBigEndian();
  14924. bitsPerSample = input->readShortBigEndian();
  14925. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14926. unsigned char sampleRateBytes[10];
  14927. input->read (sampleRateBytes, 10);
  14928. const int byte0 = sampleRateBytes[0];
  14929. if ((byte0 & 0x80) != 0
  14930. || byte0 <= 0x3F || byte0 > 0x40
  14931. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14932. break;
  14933. unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
  14934. sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
  14935. sampleRate = (int) sampRate;
  14936. if (length <= 18)
  14937. {
  14938. // some types don't have a chunk large enough to include a compression
  14939. // type, so assume it's just big-endian pcm
  14940. littleEndian = false;
  14941. }
  14942. else
  14943. {
  14944. const int compType = input->readInt();
  14945. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14946. {
  14947. littleEndian = false;
  14948. }
  14949. else if (compType == chunkName ("sowt"))
  14950. {
  14951. littleEndian = true;
  14952. }
  14953. else
  14954. {
  14955. sampleRate = 0;
  14956. break;
  14957. }
  14958. }
  14959. }
  14960. else if (type == chunkName ("SSND"))
  14961. {
  14962. hasGotData = true;
  14963. const int offset = input->readIntBigEndian();
  14964. dataChunkStart = input->getPosition() + 4 + offset;
  14965. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  14966. }
  14967. else if ((hasGotVer && hasGotData && hasGotType)
  14968. || chunkEnd < input->getPosition()
  14969. || input->isExhausted())
  14970. {
  14971. break;
  14972. }
  14973. input->setPosition (chunkEnd);
  14974. }
  14975. }
  14976. }
  14977. }
  14978. ~AiffAudioFormatReader()
  14979. {
  14980. }
  14981. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  14982. int64 startSampleInFile, int numSamples)
  14983. {
  14984. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  14985. if (samplesAvailable < numSamples)
  14986. {
  14987. for (int i = numDestChannels; --i >= 0;)
  14988. if (destSamples[i] != 0)
  14989. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  14990. numSamples = (int) samplesAvailable;
  14991. }
  14992. if (numSamples <= 0)
  14993. return true;
  14994. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  14995. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  14996. char tempBuffer [tempBufSize];
  14997. while (numSamples > 0)
  14998. {
  14999. int* left = destSamples[0];
  15000. if (left != 0)
  15001. left += startOffsetInDestBuffer;
  15002. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15003. if (right != 0)
  15004. right += startOffsetInDestBuffer;
  15005. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15006. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15007. if (bytesRead < numThisTime * bytesPerFrame)
  15008. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15009. if (bitsPerSample == 16)
  15010. {
  15011. if (littleEndian)
  15012. {
  15013. const short* src = reinterpret_cast <const short*> (tempBuffer);
  15014. if (numChannels > 1)
  15015. {
  15016. if (left == 0)
  15017. {
  15018. for (int i = numThisTime; --i >= 0;)
  15019. {
  15020. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15021. ++src;
  15022. }
  15023. }
  15024. else if (right == 0)
  15025. {
  15026. for (int i = numThisTime; --i >= 0;)
  15027. {
  15028. ++src;
  15029. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15030. }
  15031. }
  15032. else
  15033. {
  15034. for (int i = numThisTime; --i >= 0;)
  15035. {
  15036. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15037. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15038. }
  15039. }
  15040. }
  15041. else
  15042. {
  15043. for (int i = numThisTime; --i >= 0;)
  15044. {
  15045. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15046. }
  15047. }
  15048. }
  15049. else
  15050. {
  15051. const char* src = tempBuffer;
  15052. if (numChannels > 1)
  15053. {
  15054. if (left == 0)
  15055. {
  15056. for (int i = numThisTime; --i >= 0;)
  15057. {
  15058. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15059. src += 4;
  15060. }
  15061. }
  15062. else if (right == 0)
  15063. {
  15064. for (int i = numThisTime; --i >= 0;)
  15065. {
  15066. src += 2;
  15067. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15068. src += 2;
  15069. }
  15070. }
  15071. else
  15072. {
  15073. for (int i = numThisTime; --i >= 0;)
  15074. {
  15075. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15076. src += 2;
  15077. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15078. src += 2;
  15079. }
  15080. }
  15081. }
  15082. else
  15083. {
  15084. for (int i = numThisTime; --i >= 0;)
  15085. {
  15086. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15087. src += 2;
  15088. }
  15089. }
  15090. }
  15091. }
  15092. else if (bitsPerSample == 24)
  15093. {
  15094. const char* src = (const char*)tempBuffer;
  15095. if (littleEndian)
  15096. {
  15097. if (numChannels > 1)
  15098. {
  15099. if (left == 0)
  15100. {
  15101. for (int i = numThisTime; --i >= 0;)
  15102. {
  15103. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15104. src += 6;
  15105. }
  15106. }
  15107. else if (right == 0)
  15108. {
  15109. for (int i = numThisTime; --i >= 0;)
  15110. {
  15111. src += 3;
  15112. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15113. src += 3;
  15114. }
  15115. }
  15116. else
  15117. {
  15118. for (int i = numThisTime; --i >= 0;)
  15119. {
  15120. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15121. src += 3;
  15122. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15123. src += 3;
  15124. }
  15125. }
  15126. }
  15127. else
  15128. {
  15129. for (int i = numThisTime; --i >= 0;)
  15130. {
  15131. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15132. src += 3;
  15133. }
  15134. }
  15135. }
  15136. else
  15137. {
  15138. if (numChannels > 1)
  15139. {
  15140. if (left == 0)
  15141. {
  15142. for (int i = numThisTime; --i >= 0;)
  15143. {
  15144. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15145. src += 6;
  15146. }
  15147. }
  15148. else if (right == 0)
  15149. {
  15150. for (int i = numThisTime; --i >= 0;)
  15151. {
  15152. src += 3;
  15153. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15154. src += 3;
  15155. }
  15156. }
  15157. else
  15158. {
  15159. for (int i = numThisTime; --i >= 0;)
  15160. {
  15161. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15162. src += 3;
  15163. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15164. src += 3;
  15165. }
  15166. }
  15167. }
  15168. else
  15169. {
  15170. for (int i = numThisTime; --i >= 0;)
  15171. {
  15172. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15173. src += 3;
  15174. }
  15175. }
  15176. }
  15177. }
  15178. else if (bitsPerSample == 32)
  15179. {
  15180. const unsigned int* src = reinterpret_cast <const unsigned int*> (tempBuffer);
  15181. unsigned int* l = reinterpret_cast <unsigned int*> (left);
  15182. unsigned int* r = reinterpret_cast <unsigned int*> (right);
  15183. if (littleEndian)
  15184. {
  15185. if (numChannels > 1)
  15186. {
  15187. if (l == 0)
  15188. {
  15189. for (int i = numThisTime; --i >= 0;)
  15190. {
  15191. ++src;
  15192. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15193. }
  15194. }
  15195. else if (r == 0)
  15196. {
  15197. for (int i = numThisTime; --i >= 0;)
  15198. {
  15199. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15200. ++src;
  15201. }
  15202. }
  15203. else
  15204. {
  15205. for (int i = numThisTime; --i >= 0;)
  15206. {
  15207. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15208. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15209. }
  15210. }
  15211. }
  15212. else
  15213. {
  15214. for (int i = numThisTime; --i >= 0;)
  15215. {
  15216. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15217. }
  15218. }
  15219. }
  15220. else
  15221. {
  15222. if (numChannels > 1)
  15223. {
  15224. if (l == 0)
  15225. {
  15226. for (int i = numThisTime; --i >= 0;)
  15227. {
  15228. ++src;
  15229. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15230. }
  15231. }
  15232. else if (r == 0)
  15233. {
  15234. for (int i = numThisTime; --i >= 0;)
  15235. {
  15236. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15237. ++src;
  15238. }
  15239. }
  15240. else
  15241. {
  15242. for (int i = numThisTime; --i >= 0;)
  15243. {
  15244. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15245. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15246. }
  15247. }
  15248. }
  15249. else
  15250. {
  15251. for (int i = numThisTime; --i >= 0;)
  15252. {
  15253. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15254. }
  15255. }
  15256. }
  15257. left = reinterpret_cast <int*> (l);
  15258. right = reinterpret_cast <int*> (r);
  15259. }
  15260. else if (bitsPerSample == 8)
  15261. {
  15262. const char* src = tempBuffer;
  15263. if (numChannels > 1)
  15264. {
  15265. if (left == 0)
  15266. {
  15267. for (int i = numThisTime; --i >= 0;)
  15268. {
  15269. *right++ = ((int) *src++) << 24;
  15270. ++src;
  15271. }
  15272. }
  15273. else if (right == 0)
  15274. {
  15275. for (int i = numThisTime; --i >= 0;)
  15276. {
  15277. ++src;
  15278. *left++ = ((int) *src++) << 24;
  15279. }
  15280. }
  15281. else
  15282. {
  15283. for (int i = numThisTime; --i >= 0;)
  15284. {
  15285. *left++ = ((int) *src++) << 24;
  15286. *right++ = ((int) *src++) << 24;
  15287. }
  15288. }
  15289. }
  15290. else
  15291. {
  15292. for (int i = numThisTime; --i >= 0;)
  15293. {
  15294. *left++ = ((int) *src++) << 24;
  15295. }
  15296. }
  15297. }
  15298. startOffsetInDestBuffer += numThisTime;
  15299. numSamples -= numThisTime;
  15300. }
  15301. if (numSamples > 0)
  15302. {
  15303. for (int i = numDestChannels; --i >= 0;)
  15304. if (destSamples[i] != 0)
  15305. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15306. sizeof (int) * numSamples);
  15307. }
  15308. return true;
  15309. }
  15310. juce_UseDebuggingNewOperator
  15311. private:
  15312. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15313. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15314. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15315. };
  15316. class AiffAudioFormatWriter : public AudioFormatWriter
  15317. {
  15318. MemoryBlock tempBlock;
  15319. uint32 lengthInSamples, bytesWritten;
  15320. int64 headerPosition;
  15321. bool writeFailed;
  15322. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15323. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15324. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15325. void writeHeader()
  15326. {
  15327. const bool couldSeekOk = output->setPosition (headerPosition);
  15328. (void) couldSeekOk;
  15329. // if this fails, you've given it an output stream that can't seek! It needs
  15330. // to be able to seek back to write the header
  15331. jassert (couldSeekOk);
  15332. const int headerLen = 54;
  15333. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15334. audioBytes += (audioBytes & 1);
  15335. output->writeInt (chunkName ("FORM"));
  15336. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15337. output->writeInt (chunkName ("AIFF"));
  15338. output->writeInt (chunkName ("COMM"));
  15339. output->writeIntBigEndian (18);
  15340. output->writeShortBigEndian ((short) numChannels);
  15341. output->writeIntBigEndian (lengthInSamples);
  15342. output->writeShortBigEndian ((short) bitsPerSample);
  15343. uint8 sampleRateBytes[10];
  15344. zeromem (sampleRateBytes, 10);
  15345. if (sampleRate <= 1)
  15346. {
  15347. sampleRateBytes[0] = 0x3f;
  15348. sampleRateBytes[1] = 0xff;
  15349. sampleRateBytes[2] = 0x80;
  15350. }
  15351. else
  15352. {
  15353. int mask = 0x40000000;
  15354. sampleRateBytes[0] = 0x40;
  15355. if (sampleRate >= mask)
  15356. {
  15357. jassertfalse
  15358. sampleRateBytes[1] = 0x1d;
  15359. }
  15360. else
  15361. {
  15362. int n = (int) sampleRate;
  15363. int i;
  15364. for (i = 0; i <= 32 ; ++i)
  15365. {
  15366. if ((n & mask) != 0)
  15367. break;
  15368. mask >>= 1;
  15369. }
  15370. n = n << (i + 1);
  15371. sampleRateBytes[1] = (uint8) (29 - i);
  15372. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15373. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15374. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15375. sampleRateBytes[5] = (uint8) (n & 0xff);
  15376. }
  15377. }
  15378. output->write (sampleRateBytes, 10);
  15379. output->writeInt (chunkName ("SSND"));
  15380. output->writeIntBigEndian (audioBytes + 8);
  15381. output->writeInt (0);
  15382. output->writeInt (0);
  15383. jassert (output->getPosition() == headerLen);
  15384. }
  15385. public:
  15386. AiffAudioFormatWriter (OutputStream* out,
  15387. const double sampleRate_,
  15388. const unsigned int chans,
  15389. const int bits)
  15390. : AudioFormatWriter (out,
  15391. TRANS (aiffFormatName),
  15392. sampleRate_,
  15393. chans,
  15394. bits),
  15395. lengthInSamples (0),
  15396. bytesWritten (0),
  15397. writeFailed (false)
  15398. {
  15399. headerPosition = out->getPosition();
  15400. writeHeader();
  15401. }
  15402. ~AiffAudioFormatWriter()
  15403. {
  15404. if ((bytesWritten & 1) != 0)
  15405. output->writeByte (0);
  15406. writeHeader();
  15407. }
  15408. bool write (const int** data, int numSamples)
  15409. {
  15410. if (writeFailed)
  15411. return false;
  15412. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15413. tempBlock.ensureSize (bytes, false);
  15414. char* buffer = static_cast <char*> (tempBlock.getData());
  15415. const int* left = data[0];
  15416. const int* right = data[1];
  15417. if (right == 0)
  15418. right = left;
  15419. if (bitsPerSample == 16)
  15420. {
  15421. short* b = reinterpret_cast <short*> (buffer);
  15422. if (numChannels > 1)
  15423. {
  15424. for (int i = numSamples; --i >= 0;)
  15425. {
  15426. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15427. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15428. }
  15429. }
  15430. else
  15431. {
  15432. for (int i = numSamples; --i >= 0;)
  15433. {
  15434. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15435. }
  15436. }
  15437. }
  15438. else if (bitsPerSample == 24)
  15439. {
  15440. char* b = buffer;
  15441. if (numChannels > 1)
  15442. {
  15443. for (int i = numSamples; --i >= 0;)
  15444. {
  15445. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15446. b += 3;
  15447. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15448. b += 3;
  15449. }
  15450. }
  15451. else
  15452. {
  15453. for (int i = numSamples; --i >= 0;)
  15454. {
  15455. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15456. b += 3;
  15457. }
  15458. }
  15459. }
  15460. else if (bitsPerSample == 32)
  15461. {
  15462. uint32* b = reinterpret_cast <uint32*> (buffer);
  15463. if (numChannels > 1)
  15464. {
  15465. for (int i = numSamples; --i >= 0;)
  15466. {
  15467. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15468. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15469. }
  15470. }
  15471. else
  15472. {
  15473. for (int i = numSamples; --i >= 0;)
  15474. {
  15475. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15476. }
  15477. }
  15478. }
  15479. else if (bitsPerSample == 8)
  15480. {
  15481. char* b = buffer;
  15482. if (numChannels > 1)
  15483. {
  15484. for (int i = numSamples; --i >= 0;)
  15485. {
  15486. *b++ = (char) (*left++ >> 24);
  15487. *b++ = (char) (*right++ >> 24);
  15488. }
  15489. }
  15490. else
  15491. {
  15492. for (int i = numSamples; --i >= 0;)
  15493. {
  15494. *b++ = (char) (*left++ >> 24);
  15495. }
  15496. }
  15497. }
  15498. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15499. || ! output->write (buffer, bytes))
  15500. {
  15501. // failed to write to disk, so let's try writing the header.
  15502. // If it's just run out of disk space, then if it does manage
  15503. // to write the header, we'll still have a useable file..
  15504. writeHeader();
  15505. writeFailed = true;
  15506. return false;
  15507. }
  15508. else
  15509. {
  15510. bytesWritten += bytes;
  15511. lengthInSamples += numSamples;
  15512. return true;
  15513. }
  15514. }
  15515. juce_UseDebuggingNewOperator
  15516. };
  15517. AiffAudioFormat::AiffAudioFormat()
  15518. : AudioFormat (TRANS (aiffFormatName), (const juce_wchar**) aiffExtensions)
  15519. {
  15520. }
  15521. AiffAudioFormat::~AiffAudioFormat()
  15522. {
  15523. }
  15524. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15525. {
  15526. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15527. return Array <int> (rates);
  15528. }
  15529. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15530. {
  15531. const int depths[] = { 8, 16, 24, 0 };
  15532. return Array <int> (depths);
  15533. }
  15534. bool AiffAudioFormat::canDoStereo()
  15535. {
  15536. return true;
  15537. }
  15538. bool AiffAudioFormat::canDoMono()
  15539. {
  15540. return true;
  15541. }
  15542. #if JUCE_MAC
  15543. bool AiffAudioFormat::canHandleFile (const File& f)
  15544. {
  15545. if (AudioFormat::canHandleFile (f))
  15546. return true;
  15547. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15548. return type == 'AIFF' || type == 'AIFC'
  15549. || type == 'aiff' || type == 'aifc';
  15550. }
  15551. #endif
  15552. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15553. const bool deleteStreamIfOpeningFails)
  15554. {
  15555. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15556. if (w->sampleRate != 0)
  15557. return w.release();
  15558. if (! deleteStreamIfOpeningFails)
  15559. w->input = 0;
  15560. return 0;
  15561. }
  15562. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15563. double sampleRate,
  15564. unsigned int chans,
  15565. int bitsPerSample,
  15566. const StringPairArray& /*metadataValues*/,
  15567. int /*qualityOptionIndex*/)
  15568. {
  15569. if (getPossibleBitDepths().contains (bitsPerSample))
  15570. {
  15571. return new AiffAudioFormatWriter (out,
  15572. sampleRate,
  15573. chans,
  15574. bitsPerSample);
  15575. }
  15576. return 0;
  15577. }
  15578. END_JUCE_NAMESPACE
  15579. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15580. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15581. BEGIN_JUCE_NAMESPACE
  15582. #if JUCE_MAC && JUCE_USE_CDREADER
  15583. // Mac version doesn't need any native code because it's all done with files..
  15584. // Windows + Linux versions are in the platform-dependent code sections.
  15585. static void findCDs (Array<File>& cds)
  15586. {
  15587. File volumes ("/Volumes");
  15588. volumes.findChildFiles (cds, File::findDirectories, false);
  15589. for (int i = cds.size(); --i >= 0;)
  15590. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15591. cds.remove (i);
  15592. }
  15593. const StringArray AudioCDReader::getAvailableCDNames()
  15594. {
  15595. Array<File> cds;
  15596. findCDs (cds);
  15597. StringArray names;
  15598. for (int i = 0; i < cds.size(); ++i)
  15599. names.add (cds.getReference(i).getFileName());
  15600. return names;
  15601. }
  15602. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15603. {
  15604. Array<File> cds;
  15605. findCDs (cds);
  15606. if (cds[index] != File::nonexistent)
  15607. return new AudioCDReader (cds[index]);
  15608. else
  15609. return 0;
  15610. }
  15611. AudioCDReader::AudioCDReader (const File& volume)
  15612. : AudioFormatReader (0, "CD Audio"),
  15613. volumeDir (volume),
  15614. currentReaderTrack (-1),
  15615. reader (0)
  15616. {
  15617. sampleRate = 44100.0;
  15618. bitsPerSample = 16;
  15619. numChannels = 2;
  15620. usesFloatingPointData = false;
  15621. refreshTrackLengths();
  15622. }
  15623. AudioCDReader::~AudioCDReader()
  15624. {
  15625. }
  15626. static int getTrackNumber (const File& file)
  15627. {
  15628. return file.getFileName()
  15629. .initialSectionContainingOnly ("0123456789")
  15630. .getIntValue();
  15631. }
  15632. int AudioCDReader::compareElements (const File& first, const File& second)
  15633. {
  15634. const int firstTrack = getTrackNumber (first);
  15635. const int secondTrack = getTrackNumber (second);
  15636. jassert (firstTrack > 0 && secondTrack > 0);
  15637. return firstTrack - secondTrack;
  15638. }
  15639. void AudioCDReader::refreshTrackLengths()
  15640. {
  15641. tracks.clear();
  15642. trackStartSamples.clear();
  15643. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15644. tracks.sort (*this);
  15645. AiffAudioFormat format;
  15646. int sample = 0;
  15647. for (int i = 0; i < tracks.size(); ++i)
  15648. {
  15649. trackStartSamples.add (sample);
  15650. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15651. if (in != 0)
  15652. {
  15653. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15654. if (r != 0)
  15655. sample += (int) r->lengthInSamples;
  15656. }
  15657. }
  15658. trackStartSamples.add (sample);
  15659. lengthInSamples = sample;
  15660. }
  15661. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15662. int64 startSampleInFile, int numSamples)
  15663. {
  15664. while (numSamples > 0)
  15665. {
  15666. int track = -1;
  15667. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15668. {
  15669. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15670. {
  15671. track = i;
  15672. break;
  15673. }
  15674. }
  15675. if (track < 0)
  15676. return false;
  15677. if (track != currentReaderTrack)
  15678. {
  15679. reader = 0;
  15680. FileInputStream* const in = tracks [track].createInputStream();
  15681. if (in != 0)
  15682. {
  15683. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15684. AiffAudioFormat format;
  15685. reader = format.createReaderFor (bin, true);
  15686. if (reader == 0)
  15687. currentReaderTrack = -1;
  15688. else
  15689. currentReaderTrack = track;
  15690. }
  15691. }
  15692. if (reader == 0)
  15693. return false;
  15694. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15695. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15696. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15697. numSamples -= numAvailable;
  15698. startSampleInFile += numAvailable;
  15699. }
  15700. return true;
  15701. }
  15702. bool AudioCDReader::isCDStillPresent() const
  15703. {
  15704. return volumeDir.exists();
  15705. }
  15706. int AudioCDReader::getNumTracks() const
  15707. {
  15708. return tracks.size();
  15709. }
  15710. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15711. {
  15712. return trackStartSamples [trackNum];
  15713. }
  15714. bool AudioCDReader::isTrackAudio (int trackNum) const
  15715. {
  15716. return tracks [trackNum] != File::nonexistent;
  15717. }
  15718. void AudioCDReader::enableIndexScanning (bool b)
  15719. {
  15720. // any way to do this on a Mac??
  15721. }
  15722. int AudioCDReader::getLastIndex() const
  15723. {
  15724. return 0;
  15725. }
  15726. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15727. {
  15728. return Array <int>();
  15729. }
  15730. int AudioCDReader::getCDDBId()
  15731. {
  15732. return 0; //xxx
  15733. }
  15734. #endif
  15735. END_JUCE_NAMESPACE
  15736. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15737. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15738. BEGIN_JUCE_NAMESPACE
  15739. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15740. const String& formatName_)
  15741. : sampleRate (0),
  15742. bitsPerSample (0),
  15743. lengthInSamples (0),
  15744. numChannels (0),
  15745. usesFloatingPointData (false),
  15746. input (in),
  15747. formatName (formatName_)
  15748. {
  15749. }
  15750. AudioFormatReader::~AudioFormatReader()
  15751. {
  15752. delete input;
  15753. }
  15754. bool AudioFormatReader::read (int** destSamples,
  15755. int numDestChannels,
  15756. int64 startSampleInSource,
  15757. int numSamplesToRead,
  15758. const bool fillLeftoverChannelsWithCopies)
  15759. {
  15760. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15761. int startOffsetInDestBuffer = 0;
  15762. if (startSampleInSource < 0)
  15763. {
  15764. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15765. for (int i = numDestChannels; --i >= 0;)
  15766. if (destSamples[i] != 0)
  15767. zeromem (destSamples[i], sizeof (int) * silence);
  15768. startOffsetInDestBuffer += silence;
  15769. numSamplesToRead -= silence;
  15770. startSampleInSource = 0;
  15771. }
  15772. if (numSamplesToRead <= 0)
  15773. return true;
  15774. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15775. startSampleInSource, numSamplesToRead))
  15776. return false;
  15777. if (numDestChannels > (int) numChannels)
  15778. {
  15779. if (fillLeftoverChannelsWithCopies)
  15780. {
  15781. int* lastFullChannel = destSamples[0];
  15782. for (int i = numDestChannels; --i > 0;)
  15783. {
  15784. if (destSamples[i] != 0)
  15785. {
  15786. lastFullChannel = destSamples[i];
  15787. break;
  15788. }
  15789. }
  15790. if (lastFullChannel != 0)
  15791. for (int i = numChannels; i < numDestChannels; ++i)
  15792. if (destSamples[i] != 0)
  15793. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15794. }
  15795. else
  15796. {
  15797. for (int i = numChannels; i < numDestChannels; ++i)
  15798. if (destSamples[i] != 0)
  15799. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15800. }
  15801. }
  15802. return true;
  15803. }
  15804. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15805. {
  15806. float mn = buffer[0];
  15807. float mx = mn;
  15808. for (int i = 1; i < num; ++i)
  15809. {
  15810. const float s = buffer[i];
  15811. if (s > mx) mx = s;
  15812. if (s < mn) mn = s;
  15813. }
  15814. maxVal = mx;
  15815. minVal = mn;
  15816. }
  15817. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15818. int64 numSamples,
  15819. float& lowestLeft, float& highestLeft,
  15820. float& lowestRight, float& highestRight)
  15821. {
  15822. if (numSamples <= 0)
  15823. {
  15824. lowestLeft = 0;
  15825. lowestRight = 0;
  15826. highestLeft = 0;
  15827. highestRight = 0;
  15828. return;
  15829. }
  15830. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15831. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15832. int* tempBuffer[3];
  15833. tempBuffer[0] = (int*) tempSpace.getData();
  15834. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15835. tempBuffer[2] = 0;
  15836. if (usesFloatingPointData)
  15837. {
  15838. float lmin = 1.0e6f;
  15839. float lmax = -lmin;
  15840. float rmin = lmin;
  15841. float rmax = lmax;
  15842. while (numSamples > 0)
  15843. {
  15844. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15845. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15846. numSamples -= numToDo;
  15847. startSampleInFile += numToDo;
  15848. float bufmin, bufmax;
  15849. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15850. lmin = jmin (lmin, bufmin);
  15851. lmax = jmax (lmax, bufmax);
  15852. if (numChannels > 1)
  15853. {
  15854. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15855. rmin = jmin (rmin, bufmin);
  15856. rmax = jmax (rmax, bufmax);
  15857. }
  15858. }
  15859. if (numChannels <= 1)
  15860. {
  15861. rmax = lmax;
  15862. rmin = lmin;
  15863. }
  15864. lowestLeft = lmin;
  15865. highestLeft = lmax;
  15866. lowestRight = rmin;
  15867. highestRight = rmax;
  15868. }
  15869. else
  15870. {
  15871. int lmax = std::numeric_limits<int>::min();
  15872. int lmin = std::numeric_limits<int>::max();
  15873. int rmax = std::numeric_limits<int>::min();
  15874. int rmin = std::numeric_limits<int>::max();
  15875. while (numSamples > 0)
  15876. {
  15877. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15878. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15879. numSamples -= numToDo;
  15880. startSampleInFile += numToDo;
  15881. for (int j = numChannels; --j >= 0;)
  15882. {
  15883. int bufMax = std::numeric_limits<int>::min();
  15884. int bufMin = std::numeric_limits<int>::max();
  15885. const int* const b = tempBuffer[j];
  15886. for (int i = 0; i < numToDo; ++i)
  15887. {
  15888. const int samp = b[i];
  15889. if (samp < bufMin)
  15890. bufMin = samp;
  15891. if (samp > bufMax)
  15892. bufMax = samp;
  15893. }
  15894. if (j == 0)
  15895. {
  15896. lmax = jmax (lmax, bufMax);
  15897. lmin = jmin (lmin, bufMin);
  15898. }
  15899. else
  15900. {
  15901. rmax = jmax (rmax, bufMax);
  15902. rmin = jmin (rmin, bufMin);
  15903. }
  15904. }
  15905. }
  15906. if (numChannels <= 1)
  15907. {
  15908. rmax = lmax;
  15909. rmin = lmin;
  15910. }
  15911. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15912. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15913. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15914. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15915. }
  15916. }
  15917. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15918. int64 numSamplesToSearch,
  15919. const double magnitudeRangeMinimum,
  15920. const double magnitudeRangeMaximum,
  15921. const int minimumConsecutiveSamples)
  15922. {
  15923. if (numSamplesToSearch == 0)
  15924. return -1;
  15925. const int bufferSize = 4096;
  15926. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15927. int* tempBuffer[3];
  15928. tempBuffer[0] = (int*) tempSpace.getData();
  15929. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15930. tempBuffer[2] = 0;
  15931. int consecutive = 0;
  15932. int64 firstMatchPos = -1;
  15933. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15934. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15935. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15936. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15937. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15938. while (numSamplesToSearch != 0)
  15939. {
  15940. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15941. int64 bufferStart = startSample;
  15942. if (numSamplesToSearch < 0)
  15943. bufferStart -= numThisTime;
  15944. if (bufferStart >= (int) lengthInSamples)
  15945. break;
  15946. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15947. int num = numThisTime;
  15948. while (--num >= 0)
  15949. {
  15950. if (numSamplesToSearch < 0)
  15951. --startSample;
  15952. bool matches = false;
  15953. const int index = (int) (startSample - bufferStart);
  15954. if (usesFloatingPointData)
  15955. {
  15956. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15957. if (sample1 >= magnitudeRangeMinimum
  15958. && sample1 <= magnitudeRangeMaximum)
  15959. {
  15960. matches = true;
  15961. }
  15962. else if (numChannels > 1)
  15963. {
  15964. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  15965. matches = (sample2 >= magnitudeRangeMinimum
  15966. && sample2 <= magnitudeRangeMaximum);
  15967. }
  15968. }
  15969. else
  15970. {
  15971. const int sample1 = abs (tempBuffer[0] [index]);
  15972. if (sample1 >= intMagnitudeRangeMinimum
  15973. && sample1 <= intMagnitudeRangeMaximum)
  15974. {
  15975. matches = true;
  15976. }
  15977. else if (numChannels > 1)
  15978. {
  15979. const int sample2 = abs (tempBuffer[1][index]);
  15980. matches = (sample2 >= intMagnitudeRangeMinimum
  15981. && sample2 <= intMagnitudeRangeMaximum);
  15982. }
  15983. }
  15984. if (matches)
  15985. {
  15986. if (firstMatchPos < 0)
  15987. firstMatchPos = startSample;
  15988. if (++consecutive >= minimumConsecutiveSamples)
  15989. {
  15990. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  15991. return -1;
  15992. return firstMatchPos;
  15993. }
  15994. }
  15995. else
  15996. {
  15997. consecutive = 0;
  15998. firstMatchPos = -1;
  15999. }
  16000. if (numSamplesToSearch > 0)
  16001. ++startSample;
  16002. }
  16003. if (numSamplesToSearch > 0)
  16004. numSamplesToSearch -= numThisTime;
  16005. else
  16006. numSamplesToSearch += numThisTime;
  16007. }
  16008. return -1;
  16009. }
  16010. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16011. const String& formatName_,
  16012. const double rate,
  16013. const unsigned int numChannels_,
  16014. const unsigned int bitsPerSample_)
  16015. : sampleRate (rate),
  16016. numChannels (numChannels_),
  16017. bitsPerSample (bitsPerSample_),
  16018. usesFloatingPointData (false),
  16019. output (out),
  16020. formatName (formatName_)
  16021. {
  16022. }
  16023. AudioFormatWriter::~AudioFormatWriter()
  16024. {
  16025. delete output;
  16026. }
  16027. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16028. int64 startSample,
  16029. int64 numSamplesToRead)
  16030. {
  16031. const int bufferSize = 16384;
  16032. const int maxChans = 128;
  16033. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16034. int* buffers [maxChans];
  16035. for (int i = maxChans; --i >= 0;)
  16036. buffers[i] = 0;
  16037. if (numSamplesToRead < 0)
  16038. numSamplesToRead = reader.lengthInSamples;
  16039. while (numSamplesToRead > 0)
  16040. {
  16041. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16042. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16043. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16044. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16045. return false;
  16046. if (reader.usesFloatingPointData != isFloatingPoint())
  16047. {
  16048. int** bufferChan = buffers;
  16049. while (*bufferChan != 0)
  16050. {
  16051. int* b = *bufferChan++;
  16052. if (isFloatingPoint())
  16053. {
  16054. // int -> float
  16055. const double factor = 1.0 / std::numeric_limits<int>::max();
  16056. for (int i = 0; i < numToDo; ++i)
  16057. ((float*) b)[i] = (float) (factor * b[i]);
  16058. }
  16059. else
  16060. {
  16061. // float -> int
  16062. for (int i = 0; i < numToDo; ++i)
  16063. {
  16064. const double samp = *(const float*) b;
  16065. if (samp <= -1.0)
  16066. *b++ = std::numeric_limits<int>::min();
  16067. else if (samp >= 1.0)
  16068. *b++ = std::numeric_limits<int>::max();
  16069. else
  16070. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16071. }
  16072. }
  16073. }
  16074. }
  16075. if (! write ((const int**) buffers, numToDo))
  16076. return false;
  16077. numSamplesToRead -= numToDo;
  16078. startSample += numToDo;
  16079. }
  16080. return true;
  16081. }
  16082. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16083. int numSamplesToRead,
  16084. const int samplesPerBlock)
  16085. {
  16086. const int maxChans = 128;
  16087. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16088. int* buffers [maxChans];
  16089. while (numSamplesToRead > 0)
  16090. {
  16091. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16092. AudioSourceChannelInfo info;
  16093. info.buffer = &tempBuffer;
  16094. info.startSample = 0;
  16095. info.numSamples = numToDo;
  16096. info.clearActiveBufferRegion();
  16097. source.getNextAudioBlock (info);
  16098. int i;
  16099. for (i = maxChans; --i >= 0;)
  16100. buffers[i] = 0;
  16101. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16102. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16103. if (! isFloatingPoint())
  16104. {
  16105. int** bufferChan = buffers;
  16106. while (*bufferChan != 0)
  16107. {
  16108. int* b = *bufferChan++;
  16109. // float -> int
  16110. for (int j = numToDo; --j >= 0;)
  16111. {
  16112. const double samp = *(const float*) b;
  16113. if (samp <= -1.0)
  16114. *b++ = std::numeric_limits<int>::min();
  16115. else if (samp >= 1.0)
  16116. *b++ = std::numeric_limits<int>::max();
  16117. else
  16118. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16119. }
  16120. }
  16121. }
  16122. if (! write ((const int**) buffers, numToDo))
  16123. return false;
  16124. numSamplesToRead -= numToDo;
  16125. }
  16126. return true;
  16127. }
  16128. AudioFormat::AudioFormat (const String& name,
  16129. const juce_wchar** const extensions)
  16130. : formatName (name),
  16131. fileExtensions (extensions)
  16132. {
  16133. }
  16134. AudioFormat::~AudioFormat()
  16135. {
  16136. }
  16137. const String& AudioFormat::getFormatName() const
  16138. {
  16139. return formatName;
  16140. }
  16141. const StringArray& AudioFormat::getFileExtensions() const
  16142. {
  16143. return fileExtensions;
  16144. }
  16145. bool AudioFormat::canHandleFile (const File& f)
  16146. {
  16147. for (int i = 0; i < fileExtensions.size(); ++i)
  16148. if (f.hasFileExtension (fileExtensions[i]))
  16149. return true;
  16150. return false;
  16151. }
  16152. bool AudioFormat::isCompressed()
  16153. {
  16154. return false;
  16155. }
  16156. const StringArray AudioFormat::getQualityOptions()
  16157. {
  16158. return StringArray();
  16159. }
  16160. END_JUCE_NAMESPACE
  16161. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16162. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16163. BEGIN_JUCE_NAMESPACE
  16164. AudioFormatManager::AudioFormatManager()
  16165. : defaultFormatIndex (0)
  16166. {
  16167. }
  16168. AudioFormatManager::~AudioFormatManager()
  16169. {
  16170. clearFormats();
  16171. clearSingletonInstance();
  16172. }
  16173. juce_ImplementSingleton (AudioFormatManager);
  16174. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16175. const bool makeThisTheDefaultFormat)
  16176. {
  16177. jassert (newFormat != 0);
  16178. if (newFormat != 0)
  16179. {
  16180. #ifdef JUCE_DEBUG
  16181. for (int i = getNumKnownFormats(); --i >= 0;)
  16182. {
  16183. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16184. {
  16185. jassertfalse // trying to add the same format twice!
  16186. }
  16187. }
  16188. #endif
  16189. if (makeThisTheDefaultFormat)
  16190. defaultFormatIndex = knownFormats.size();
  16191. knownFormats.add (newFormat);
  16192. }
  16193. }
  16194. void AudioFormatManager::registerBasicFormats()
  16195. {
  16196. #if JUCE_MAC
  16197. registerFormat (new AiffAudioFormat(), true);
  16198. registerFormat (new WavAudioFormat(), false);
  16199. #else
  16200. registerFormat (new WavAudioFormat(), true);
  16201. registerFormat (new AiffAudioFormat(), false);
  16202. #endif
  16203. #if JUCE_USE_FLAC
  16204. registerFormat (new FlacAudioFormat(), false);
  16205. #endif
  16206. #if JUCE_USE_OGGVORBIS
  16207. registerFormat (new OggVorbisAudioFormat(), false);
  16208. #endif
  16209. }
  16210. void AudioFormatManager::clearFormats()
  16211. {
  16212. for (int i = getNumKnownFormats(); --i >= 0;)
  16213. delete getKnownFormat(i);
  16214. knownFormats.clear();
  16215. defaultFormatIndex = 0;
  16216. }
  16217. int AudioFormatManager::getNumKnownFormats() const
  16218. {
  16219. return knownFormats.size();
  16220. }
  16221. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16222. {
  16223. return (AudioFormat*) knownFormats [index];
  16224. }
  16225. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16226. {
  16227. return getKnownFormat (defaultFormatIndex);
  16228. }
  16229. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16230. {
  16231. String e (fileExtension);
  16232. if (! e.startsWithChar ('.'))
  16233. e = "." + e;
  16234. for (int i = 0; i < getNumKnownFormats(); ++i)
  16235. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16236. return getKnownFormat(i);
  16237. return 0;
  16238. }
  16239. const String AudioFormatManager::getWildcardForAllFormats() const
  16240. {
  16241. StringArray allExtensions;
  16242. int i;
  16243. for (i = 0; i < getNumKnownFormats(); ++i)
  16244. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16245. allExtensions.trim();
  16246. allExtensions.removeEmptyStrings();
  16247. String s;
  16248. for (i = 0; i < allExtensions.size(); ++i)
  16249. {
  16250. s << '*';
  16251. if (! allExtensions[i].startsWithChar ('.'))
  16252. s << '.';
  16253. s << allExtensions[i];
  16254. if (i < allExtensions.size() - 1)
  16255. s << ';';
  16256. }
  16257. return s;
  16258. }
  16259. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16260. {
  16261. // you need to actually register some formats before the manager can
  16262. // use them to open a file!
  16263. jassert (knownFormats.size() > 0);
  16264. for (int i = 0; i < getNumKnownFormats(); ++i)
  16265. {
  16266. AudioFormat* const af = getKnownFormat(i);
  16267. if (af->canHandleFile (file))
  16268. {
  16269. InputStream* const in = file.createInputStream();
  16270. if (in != 0)
  16271. {
  16272. AudioFormatReader* const r = af->createReaderFor (in, true);
  16273. if (r != 0)
  16274. return r;
  16275. }
  16276. }
  16277. }
  16278. return 0;
  16279. }
  16280. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16281. {
  16282. // you need to actually register some formats before the manager can
  16283. // use them to open a file!
  16284. jassert (knownFormats.size() > 0);
  16285. ScopedPointer <InputStream> in (audioFileStream);
  16286. if (in != 0)
  16287. {
  16288. const int64 originalStreamPos = in->getPosition();
  16289. for (int i = 0; i < getNumKnownFormats(); ++i)
  16290. {
  16291. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16292. if (r != 0)
  16293. {
  16294. in.release();
  16295. return r;
  16296. }
  16297. in->setPosition (originalStreamPos);
  16298. // the stream that is passed-in must be capable of being repositioned so
  16299. // that all the formats can have a go at opening it.
  16300. jassert (in->getPosition() == originalStreamPos);
  16301. }
  16302. }
  16303. return 0;
  16304. }
  16305. END_JUCE_NAMESPACE
  16306. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16307. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16308. BEGIN_JUCE_NAMESPACE
  16309. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16310. const int64 startSample_,
  16311. const int64 length_,
  16312. const bool deleteSourceWhenDeleted_)
  16313. : AudioFormatReader (0, source_->getFormatName()),
  16314. source (source_),
  16315. startSample (startSample_),
  16316. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16317. {
  16318. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16319. sampleRate = source->sampleRate;
  16320. bitsPerSample = source->bitsPerSample;
  16321. lengthInSamples = length;
  16322. numChannels = source->numChannels;
  16323. usesFloatingPointData = source->usesFloatingPointData;
  16324. }
  16325. AudioSubsectionReader::~AudioSubsectionReader()
  16326. {
  16327. if (deleteSourceWhenDeleted)
  16328. delete source;
  16329. }
  16330. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16331. int64 startSampleInFile, int numSamples)
  16332. {
  16333. if (startSampleInFile + numSamples > length)
  16334. {
  16335. for (int i = numDestChannels; --i >= 0;)
  16336. if (destSamples[i] != 0)
  16337. zeromem (destSamples[i], sizeof (int) * numSamples);
  16338. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16339. if (numSamples <= 0)
  16340. return true;
  16341. }
  16342. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16343. startSampleInFile + startSample, numSamples);
  16344. }
  16345. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16346. int64 numSamples,
  16347. float& lowestLeft,
  16348. float& highestLeft,
  16349. float& lowestRight,
  16350. float& highestRight)
  16351. {
  16352. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16353. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16354. source->readMaxLevels (startSampleInFile + startSample,
  16355. numSamples,
  16356. lowestLeft,
  16357. highestLeft,
  16358. lowestRight,
  16359. highestRight);
  16360. }
  16361. END_JUCE_NAMESPACE
  16362. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16363. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16364. BEGIN_JUCE_NAMESPACE
  16365. const int timeBeforeDeletingReader = 2000;
  16366. struct AudioThumbnailDataFormat
  16367. {
  16368. char thumbnailMagic[4];
  16369. int samplesPerThumbSample;
  16370. int64 totalSamples; // source samples
  16371. int64 numFinishedSamples; // source samples
  16372. int numThumbnailSamples;
  16373. int numChannels;
  16374. int sampleRate;
  16375. char future[16];
  16376. char data[1];
  16377. void swapEndiannessIfNeeded() throw()
  16378. {
  16379. #if JUCE_BIG_ENDIAN
  16380. flip (samplesPerThumbSample);
  16381. flip (totalSamples);
  16382. flip (numFinishedSamples);
  16383. flip (numThumbnailSamples);
  16384. flip (numChannels);
  16385. flip (sampleRate);
  16386. #endif
  16387. }
  16388. private:
  16389. #if JUCE_BIG_ENDIAN
  16390. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16391. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16392. #endif
  16393. };
  16394. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16395. AudioFormatManager& formatManagerToUse_,
  16396. AudioThumbnailCache& cacheToUse)
  16397. : formatManagerToUse (formatManagerToUse_),
  16398. cache (cacheToUse),
  16399. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16400. {
  16401. clear();
  16402. }
  16403. AudioThumbnail::~AudioThumbnail()
  16404. {
  16405. cache.removeThumbnail (this);
  16406. const ScopedLock sl (readerLock);
  16407. reader = 0;
  16408. }
  16409. void AudioThumbnail::setSource (InputSource* const newSource)
  16410. {
  16411. cache.removeThumbnail (this);
  16412. timerCallback(); // stops the timer and deletes the reader
  16413. source = newSource;
  16414. clear();
  16415. if (newSource != 0
  16416. && ! (cache.loadThumb (*this, newSource->hashCode())
  16417. && isFullyLoaded()))
  16418. {
  16419. {
  16420. const ScopedLock sl (readerLock);
  16421. reader = createReader();
  16422. }
  16423. if (reader != 0)
  16424. {
  16425. initialiseFromAudioFile (*reader);
  16426. cache.addThumbnail (this);
  16427. }
  16428. }
  16429. sendChangeMessage (this);
  16430. }
  16431. bool AudioThumbnail::useTimeSlice()
  16432. {
  16433. const ScopedLock sl (readerLock);
  16434. if (isFullyLoaded())
  16435. {
  16436. if (reader != 0)
  16437. startTimer (timeBeforeDeletingReader);
  16438. cache.removeThumbnail (this);
  16439. return false;
  16440. }
  16441. if (reader == 0)
  16442. reader = createReader();
  16443. if (reader != 0)
  16444. {
  16445. readNextBlockFromAudioFile (*reader);
  16446. stopTimer();
  16447. sendChangeMessage (this);
  16448. const bool justFinished = isFullyLoaded();
  16449. if (justFinished)
  16450. cache.storeThumb (*this, source->hashCode());
  16451. return ! justFinished;
  16452. }
  16453. return false;
  16454. }
  16455. AudioFormatReader* AudioThumbnail::createReader() const
  16456. {
  16457. if (source != 0)
  16458. {
  16459. InputStream* const audioFileStream = source->createInputStream();
  16460. if (audioFileStream != 0)
  16461. return formatManagerToUse.createReaderFor (audioFileStream);
  16462. }
  16463. return 0;
  16464. }
  16465. void AudioThumbnail::timerCallback()
  16466. {
  16467. stopTimer();
  16468. const ScopedLock sl (readerLock);
  16469. reader = 0;
  16470. }
  16471. void AudioThumbnail::clear()
  16472. {
  16473. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16474. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16475. d->thumbnailMagic[0] = 'j';
  16476. d->thumbnailMagic[1] = 'a';
  16477. d->thumbnailMagic[2] = 't';
  16478. d->thumbnailMagic[3] = 'm';
  16479. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16480. d->totalSamples = 0;
  16481. d->numFinishedSamples = 0;
  16482. d->numThumbnailSamples = 0;
  16483. d->numChannels = 0;
  16484. d->sampleRate = 0;
  16485. numSamplesCached = 0;
  16486. cacheNeedsRefilling = true;
  16487. }
  16488. void AudioThumbnail::loadFrom (InputStream& input)
  16489. {
  16490. const ScopedLock sl (readerLock);
  16491. data.setSize (0);
  16492. input.readIntoMemoryBlock (data);
  16493. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16494. d->swapEndiannessIfNeeded();
  16495. if (! (d->thumbnailMagic[0] == 'j'
  16496. && d->thumbnailMagic[1] == 'a'
  16497. && d->thumbnailMagic[2] == 't'
  16498. && d->thumbnailMagic[3] == 'm'))
  16499. {
  16500. clear();
  16501. }
  16502. numSamplesCached = 0;
  16503. cacheNeedsRefilling = true;
  16504. }
  16505. void AudioThumbnail::saveTo (OutputStream& output) const
  16506. {
  16507. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16508. d->swapEndiannessIfNeeded();
  16509. output.write (data.getData(), (int) data.getSize());
  16510. d->swapEndiannessIfNeeded();
  16511. }
  16512. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16513. {
  16514. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16515. d->totalSamples = fileReader.lengthInSamples;
  16516. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16517. d->numFinishedSamples = 0;
  16518. d->sampleRate = roundToInt (fileReader.sampleRate);
  16519. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16520. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16521. d = (AudioThumbnailDataFormat*) data.getData();
  16522. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16523. return d->totalSamples > 0;
  16524. }
  16525. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16526. {
  16527. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16528. if (d->numFinishedSamples < d->totalSamples)
  16529. {
  16530. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16531. generateSection (fileReader,
  16532. d->numFinishedSamples,
  16533. numToDo);
  16534. d->numFinishedSamples += numToDo;
  16535. }
  16536. cacheNeedsRefilling = true;
  16537. return (d->numFinishedSamples < d->totalSamples);
  16538. }
  16539. int AudioThumbnail::getNumChannels() const throw()
  16540. {
  16541. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16542. jassert (d != 0);
  16543. return d->numChannels;
  16544. }
  16545. double AudioThumbnail::getTotalLength() const throw()
  16546. {
  16547. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16548. jassert (d != 0);
  16549. if (d->sampleRate > 0)
  16550. return d->totalSamples / (double)d->sampleRate;
  16551. else
  16552. return 0.0;
  16553. }
  16554. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16555. int64 startSample,
  16556. int numSamples)
  16557. {
  16558. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16559. jassert (d != 0);
  16560. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16561. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16562. char* l = getChannelData (0);
  16563. char* r = getChannelData (1);
  16564. for (int i = firstDataPos; i < lastDataPos; ++i)
  16565. {
  16566. const int sourceStart = i * d->samplesPerThumbSample;
  16567. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16568. float lowestLeft, highestLeft, lowestRight, highestRight;
  16569. fileReader.readMaxLevels (sourceStart,
  16570. sourceEnd - sourceStart,
  16571. lowestLeft,
  16572. highestLeft,
  16573. lowestRight,
  16574. highestRight);
  16575. int n = i * 2;
  16576. if (r != 0)
  16577. {
  16578. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16579. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16580. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16581. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16582. }
  16583. else
  16584. {
  16585. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16586. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16587. }
  16588. }
  16589. }
  16590. char* AudioThumbnail::getChannelData (int channel) const
  16591. {
  16592. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16593. jassert (d != 0);
  16594. if (channel >= 0 && channel < d->numChannels)
  16595. return d->data + (channel * 2 * d->numThumbnailSamples);
  16596. return 0;
  16597. }
  16598. bool AudioThumbnail::isFullyLoaded() const throw()
  16599. {
  16600. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16601. jassert (d != 0);
  16602. return d->numFinishedSamples >= d->totalSamples;
  16603. }
  16604. void AudioThumbnail::refillCache (const int numSamples,
  16605. double startTime,
  16606. const double timePerPixel)
  16607. {
  16608. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16609. jassert (d != 0);
  16610. if (numSamples <= 0
  16611. || timePerPixel <= 0.0
  16612. || d->sampleRate <= 0)
  16613. {
  16614. numSamplesCached = 0;
  16615. cacheNeedsRefilling = true;
  16616. return;
  16617. }
  16618. if (numSamples == numSamplesCached
  16619. && numChannelsCached == d->numChannels
  16620. && startTime == cachedStart
  16621. && timePerPixel == cachedTimePerPixel
  16622. && ! cacheNeedsRefilling)
  16623. {
  16624. return;
  16625. }
  16626. numSamplesCached = numSamples;
  16627. numChannelsCached = d->numChannels;
  16628. cachedStart = startTime;
  16629. cachedTimePerPixel = timePerPixel;
  16630. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16631. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16632. const ScopedLock sl (readerLock);
  16633. cacheNeedsRefilling = false;
  16634. if (needExtraDetail && reader == 0)
  16635. reader = createReader();
  16636. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16637. {
  16638. startTimer (timeBeforeDeletingReader);
  16639. char* cacheData = static_cast <char*> (cachedLevels.getData());
  16640. int sample = roundToInt (startTime * d->sampleRate);
  16641. for (int i = numSamples; --i >= 0;)
  16642. {
  16643. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16644. if (sample >= 0)
  16645. {
  16646. if (sample >= reader->lengthInSamples)
  16647. break;
  16648. float lmin, lmax, rmin, rmax;
  16649. reader->readMaxLevels (sample,
  16650. jmax (1, nextSample - sample),
  16651. lmin, lmax, rmin, rmax);
  16652. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16653. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16654. if (numChannelsCached > 1)
  16655. {
  16656. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16657. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16658. }
  16659. cacheData += 2 * numChannelsCached;
  16660. }
  16661. startTime += timePerPixel;
  16662. sample = nextSample;
  16663. }
  16664. }
  16665. else
  16666. {
  16667. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16668. {
  16669. char* const channelData = getChannelData (channelNum);
  16670. char* cacheData = static_cast <char*> (cachedLevels.getData()) + channelNum * 2;
  16671. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16672. startTime = cachedStart;
  16673. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16674. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16675. for (int i = numSamples; --i >= 0;)
  16676. {
  16677. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16678. if (sample >= 0 && channelData != 0)
  16679. {
  16680. char mx = -128;
  16681. char mn = 127;
  16682. while (sample <= nextSample)
  16683. {
  16684. if (sample >= numFinished)
  16685. break;
  16686. const int n = sample << 1;
  16687. const char sampMin = channelData [n];
  16688. const char sampMax = channelData [n + 1];
  16689. if (sampMin < mn)
  16690. mn = sampMin;
  16691. if (sampMax > mx)
  16692. mx = sampMax;
  16693. ++sample;
  16694. }
  16695. if (mn <= mx)
  16696. {
  16697. cacheData[0] = mn;
  16698. cacheData[1] = mx;
  16699. }
  16700. else
  16701. {
  16702. cacheData[0] = 1;
  16703. cacheData[1] = 0;
  16704. }
  16705. }
  16706. else
  16707. {
  16708. cacheData[0] = 1;
  16709. cacheData[1] = 0;
  16710. }
  16711. cacheData += numChannelsCached * 2;
  16712. startTime += timePerPixel;
  16713. sample = nextSample;
  16714. }
  16715. }
  16716. }
  16717. }
  16718. void AudioThumbnail::drawChannel (Graphics& g,
  16719. int x, int y, int w, int h,
  16720. double startTime,
  16721. double endTime,
  16722. int channelNum,
  16723. const float verticalZoomFactor)
  16724. {
  16725. refillCache (w, startTime, (endTime - startTime) / w);
  16726. if (numSamplesCached >= w
  16727. && channelNum >= 0
  16728. && channelNum < numChannelsCached)
  16729. {
  16730. const float topY = (float) y;
  16731. const float bottomY = topY + h;
  16732. const float midY = topY + h * 0.5f;
  16733. const float vscale = verticalZoomFactor * h / 256.0f;
  16734. const Rectangle<int> clip (g.getClipBounds());
  16735. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16736. w -= skipLeft;
  16737. x += skipLeft;
  16738. const char* cacheData = static_cast <const char*> (cachedLevels.getData())
  16739. + (channelNum << 1)
  16740. + skipLeft * (numChannelsCached << 1);
  16741. while (--w >= 0)
  16742. {
  16743. const char mn = cacheData[0];
  16744. const char mx = cacheData[1];
  16745. cacheData += numChannelsCached << 1;
  16746. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16747. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16748. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16749. ++x;
  16750. if (x >= clip.getRight())
  16751. break;
  16752. }
  16753. }
  16754. }
  16755. END_JUCE_NAMESPACE
  16756. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16757. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16758. BEGIN_JUCE_NAMESPACE
  16759. struct ThumbnailCacheEntry
  16760. {
  16761. int64 hash;
  16762. uint32 lastUsed;
  16763. MemoryBlock data;
  16764. juce_UseDebuggingNewOperator
  16765. };
  16766. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16767. : TimeSliceThread ("thumb cache"),
  16768. maxNumThumbsToStore (maxNumThumbsToStore_)
  16769. {
  16770. startThread (2);
  16771. }
  16772. AudioThumbnailCache::~AudioThumbnailCache()
  16773. {
  16774. }
  16775. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16776. {
  16777. for (int i = thumbs.size(); --i >= 0;)
  16778. {
  16779. if (thumbs[i]->hash == hashCode)
  16780. {
  16781. MemoryInputStream in (thumbs[i]->data, false);
  16782. thumb.loadFrom (in);
  16783. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16784. return true;
  16785. }
  16786. }
  16787. return false;
  16788. }
  16789. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16790. const int64 hashCode)
  16791. {
  16792. MemoryOutputStream out;
  16793. thumb.saveTo (out);
  16794. ThumbnailCacheEntry* te = 0;
  16795. for (int i = thumbs.size(); --i >= 0;)
  16796. {
  16797. if (thumbs[i]->hash == hashCode)
  16798. {
  16799. te = thumbs[i];
  16800. break;
  16801. }
  16802. }
  16803. if (te == 0)
  16804. {
  16805. te = new ThumbnailCacheEntry();
  16806. te->hash = hashCode;
  16807. if (thumbs.size() < maxNumThumbsToStore)
  16808. {
  16809. thumbs.add (te);
  16810. }
  16811. else
  16812. {
  16813. int oldest = 0;
  16814. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16815. int i;
  16816. for (i = thumbs.size(); --i >= 0;)
  16817. if (thumbs[i]->lastUsed < oldestTime)
  16818. oldest = i;
  16819. thumbs.set (i, te);
  16820. }
  16821. }
  16822. te->lastUsed = Time::getMillisecondCounter();
  16823. te->data.setSize (0);
  16824. te->data.append (out.getData(), out.getDataSize());
  16825. }
  16826. void AudioThumbnailCache::clear()
  16827. {
  16828. thumbs.clear();
  16829. }
  16830. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16831. {
  16832. addTimeSliceClient (thumb);
  16833. }
  16834. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16835. {
  16836. removeTimeSliceClient (thumb);
  16837. }
  16838. END_JUCE_NAMESPACE
  16839. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16840. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16841. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16842. #if ! JUCE_WINDOWS
  16843. #include <QuickTime/Movies.h>
  16844. #include <QuickTime/QTML.h>
  16845. #include <QuickTime/QuickTimeComponents.h>
  16846. #include <QuickTime/MediaHandlers.h>
  16847. #include <QuickTime/ImageCodec.h>
  16848. #else
  16849. #if JUCE_MSVC
  16850. #pragma warning (push)
  16851. #pragma warning (disable : 4100)
  16852. #endif
  16853. #include <Movies.h>
  16854. #include <QTML.h>
  16855. #include <QuickTimeComponents.h>
  16856. #include <MediaHandlers.h>
  16857. #include <ImageCodec.h>
  16858. #if JUCE_MSVC
  16859. #pragma warning (pop)
  16860. #endif
  16861. #endif
  16862. BEGIN_JUCE_NAMESPACE
  16863. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16864. static const char* const quickTimeFormatName = "QuickTime file";
  16865. static const juce_wchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16866. class QTAudioReader : public AudioFormatReader
  16867. {
  16868. public:
  16869. QTAudioReader (InputStream* const input_, const int trackNum_)
  16870. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16871. ok (false),
  16872. movie (0),
  16873. trackNum (trackNum_),
  16874. lastSampleRead (0),
  16875. lastThreadId (0),
  16876. extractor (0),
  16877. dataHandle (0)
  16878. {
  16879. bufferList.calloc (256, 1);
  16880. #ifdef WIN32
  16881. if (InitializeQTML (0) != noErr)
  16882. return;
  16883. #endif
  16884. if (EnterMovies() != noErr)
  16885. return;
  16886. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16887. if (! opened)
  16888. return;
  16889. {
  16890. const int numTracks = GetMovieTrackCount (movie);
  16891. int trackCount = 0;
  16892. for (int i = 1; i <= numTracks; ++i)
  16893. {
  16894. track = GetMovieIndTrack (movie, i);
  16895. media = GetTrackMedia (track);
  16896. OSType mediaType;
  16897. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16898. if (mediaType == SoundMediaType
  16899. && trackCount++ == trackNum_)
  16900. {
  16901. ok = true;
  16902. break;
  16903. }
  16904. }
  16905. }
  16906. if (! ok)
  16907. return;
  16908. ok = false;
  16909. lengthInSamples = GetMediaDecodeDuration (media);
  16910. usesFloatingPointData = false;
  16911. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16912. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16913. / GetMediaTimeScale (media);
  16914. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16915. unsigned long output_layout_size;
  16916. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16917. kQTPropertyClass_MovieAudioExtraction_Audio,
  16918. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16919. 0, &output_layout_size, 0);
  16920. if (err != noErr)
  16921. return;
  16922. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16923. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16924. err = MovieAudioExtractionGetProperty (extractor,
  16925. kQTPropertyClass_MovieAudioExtraction_Audio,
  16926. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16927. output_layout_size, qt_audio_channel_layout, 0);
  16928. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16929. err = MovieAudioExtractionSetProperty (extractor,
  16930. kQTPropertyClass_MovieAudioExtraction_Audio,
  16931. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16932. output_layout_size,
  16933. qt_audio_channel_layout);
  16934. err = MovieAudioExtractionGetProperty (extractor,
  16935. kQTPropertyClass_MovieAudioExtraction_Audio,
  16936. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16937. sizeof (inputStreamDesc),
  16938. &inputStreamDesc, 0);
  16939. if (err != noErr)
  16940. return;
  16941. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16942. | kAudioFormatFlagIsPacked
  16943. | kAudioFormatFlagsNativeEndian;
  16944. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16945. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16946. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16947. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16948. err = MovieAudioExtractionSetProperty (extractor,
  16949. kQTPropertyClass_MovieAudioExtraction_Audio,
  16950. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16951. sizeof (inputStreamDesc),
  16952. &inputStreamDesc);
  16953. if (err != noErr)
  16954. return;
  16955. Boolean allChannelsDiscrete = false;
  16956. err = MovieAudioExtractionSetProperty (extractor,
  16957. kQTPropertyClass_MovieAudioExtraction_Movie,
  16958. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16959. sizeof (allChannelsDiscrete),
  16960. &allChannelsDiscrete);
  16961. if (err != noErr)
  16962. return;
  16963. bufferList->mNumberBuffers = 1;
  16964. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  16965. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  16966. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  16967. sampleRate = inputStreamDesc.mSampleRate;
  16968. bitsPerSample = 16;
  16969. numChannels = inputStreamDesc.mChannelsPerFrame;
  16970. detachThread();
  16971. ok = true;
  16972. }
  16973. ~QTAudioReader()
  16974. {
  16975. if (dataHandle != 0)
  16976. DisposeHandle (dataHandle);
  16977. if (extractor != 0)
  16978. {
  16979. MovieAudioExtractionEnd (extractor);
  16980. extractor = 0;
  16981. }
  16982. checkThreadIsAttached();
  16983. DisposeMovie (movie);
  16984. juce_free (bufferList->mBuffers[0].mData);
  16985. #if JUCE_MAC
  16986. ExitMoviesOnThread ();
  16987. #endif
  16988. }
  16989. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16990. int64 startSampleInFile, int numSamples)
  16991. {
  16992. checkThreadIsAttached();
  16993. while (numSamples > 0)
  16994. {
  16995. if (! loadFrame ((int) startSampleInFile))
  16996. return false;
  16997. const int numToDo = jmin (numSamples, samplesPerFrame);
  16998. for (int j = numDestChannels; --j >= 0;)
  16999. {
  17000. if (destSamples[j] != 0)
  17001. {
  17002. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17003. for (int i = 0; i < numToDo; ++i)
  17004. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17005. }
  17006. }
  17007. startOffsetInDestBuffer += numToDo;
  17008. startSampleInFile += numToDo;
  17009. numSamples -= numToDo;
  17010. }
  17011. detachThread();
  17012. return true;
  17013. }
  17014. bool loadFrame (const int sampleNum)
  17015. {
  17016. if (lastSampleRead != sampleNum)
  17017. {
  17018. TimeRecord time;
  17019. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17020. time.base = 0;
  17021. time.value.hi = 0;
  17022. time.value.lo = (UInt32) sampleNum;
  17023. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17024. kQTPropertyClass_MovieAudioExtraction_Movie,
  17025. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17026. sizeof (time), &time);
  17027. if (err != noErr)
  17028. return false;
  17029. }
  17030. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17031. UInt32 outFlags = 0;
  17032. UInt32 actualNumSamples = samplesPerFrame;
  17033. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17034. bufferList, &outFlags);
  17035. lastSampleRead = sampleNum + samplesPerFrame;
  17036. return err == noErr;
  17037. }
  17038. juce_UseDebuggingNewOperator
  17039. bool ok;
  17040. private:
  17041. Movie movie;
  17042. Media media;
  17043. Track track;
  17044. const int trackNum;
  17045. double trackUnitsPerFrame;
  17046. int samplesPerFrame;
  17047. int lastSampleRead;
  17048. Thread::ThreadID lastThreadId;
  17049. MovieAudioExtractionRef extractor;
  17050. AudioStreamBasicDescription inputStreamDesc;
  17051. HeapBlock <AudioBufferList> bufferList;
  17052. Handle dataHandle;
  17053. void checkThreadIsAttached()
  17054. {
  17055. #if JUCE_MAC
  17056. if (Thread::getCurrentThreadId() != lastThreadId)
  17057. EnterMoviesOnThread (0);
  17058. AttachMovieToCurrentThread (movie);
  17059. #endif
  17060. }
  17061. void detachThread()
  17062. {
  17063. #if JUCE_MAC
  17064. DetachMovieFromCurrentThread (movie);
  17065. #endif
  17066. }
  17067. QTAudioReader (const QTAudioReader&);
  17068. QTAudioReader& operator= (const QTAudioReader&);
  17069. };
  17070. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17071. : AudioFormat (TRANS (quickTimeFormatName), (const juce_wchar**) quickTimeExtensions)
  17072. {
  17073. }
  17074. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17075. {
  17076. }
  17077. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17078. {
  17079. return Array<int>();
  17080. }
  17081. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17082. {
  17083. return Array<int>();
  17084. }
  17085. bool QuickTimeAudioFormat::canDoStereo()
  17086. {
  17087. return true;
  17088. }
  17089. bool QuickTimeAudioFormat::canDoMono()
  17090. {
  17091. return true;
  17092. }
  17093. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17094. const bool deleteStreamIfOpeningFails)
  17095. {
  17096. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17097. if (r->ok)
  17098. return r.release();
  17099. if (! deleteStreamIfOpeningFails)
  17100. r->input = 0;
  17101. return 0;
  17102. }
  17103. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17104. double /*sampleRateToUse*/,
  17105. unsigned int /*numberOfChannels*/,
  17106. int /*bitsPerSample*/,
  17107. const StringPairArray& /*metadataValues*/,
  17108. int /*qualityOptionIndex*/)
  17109. {
  17110. jassertfalse // not yet implemented!
  17111. return 0;
  17112. }
  17113. END_JUCE_NAMESPACE
  17114. #endif
  17115. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17116. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17117. BEGIN_JUCE_NAMESPACE
  17118. static const char* const wavFormatName = "WAV file";
  17119. static const juce_wchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17120. const char* const WavAudioFormat::bwavDescription = "bwav description";
  17121. const char* const WavAudioFormat::bwavOriginator = "bwav originator";
  17122. const char* const WavAudioFormat::bwavOriginatorRef = "bwav originator ref";
  17123. const char* const WavAudioFormat::bwavOriginationDate = "bwav origination date";
  17124. const char* const WavAudioFormat::bwavOriginationTime = "bwav origination time";
  17125. const char* const WavAudioFormat::bwavTimeReference = "bwav time reference";
  17126. const char* const WavAudioFormat::bwavCodingHistory = "bwav coding history";
  17127. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17128. const String& originator,
  17129. const String& originatorRef,
  17130. const Time& date,
  17131. const int64 timeReferenceSamples,
  17132. const String& codingHistory)
  17133. {
  17134. StringPairArray m;
  17135. m.set (bwavDescription, description);
  17136. m.set (bwavOriginator, originator);
  17137. m.set (bwavOriginatorRef, originatorRef);
  17138. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17139. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17140. m.set (bwavTimeReference, String (timeReferenceSamples));
  17141. m.set (bwavCodingHistory, codingHistory);
  17142. return m;
  17143. }
  17144. #if JUCE_MSVC
  17145. #pragma pack (push, 1)
  17146. #define PACKED
  17147. #elif JUCE_GCC
  17148. #define PACKED __attribute__((packed))
  17149. #else
  17150. #define PACKED
  17151. #endif
  17152. struct BWAVChunk
  17153. {
  17154. char description [256];
  17155. char originator [32];
  17156. char originatorRef [32];
  17157. char originationDate [10];
  17158. char originationTime [8];
  17159. uint32 timeRefLow;
  17160. uint32 timeRefHigh;
  17161. uint16 version;
  17162. uint8 umid[64];
  17163. uint8 reserved[190];
  17164. char codingHistory[1];
  17165. void copyTo (StringPairArray& values) const
  17166. {
  17167. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17168. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17169. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17170. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17171. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17172. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17173. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17174. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17175. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17176. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17177. }
  17178. static MemoryBlock createFrom (const StringPairArray& values)
  17179. {
  17180. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17181. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17182. data.fillWith (0);
  17183. BWAVChunk* b = (BWAVChunk*) data.getData();
  17184. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17185. // as they get called in the right order..
  17186. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17187. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17188. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17189. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17190. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17191. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17192. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17193. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17194. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17195. if (b->description[0] != 0
  17196. || b->originator[0] != 0
  17197. || b->originationDate[0] != 0
  17198. || b->originationTime[0] != 0
  17199. || b->codingHistory[0] != 0
  17200. || time != 0)
  17201. {
  17202. return data;
  17203. }
  17204. return MemoryBlock();
  17205. }
  17206. } PACKED;
  17207. struct SMPLChunk
  17208. {
  17209. struct SampleLoop
  17210. {
  17211. uint32 identifier;
  17212. uint32 type;
  17213. uint32 start;
  17214. uint32 end;
  17215. uint32 fraction;
  17216. uint32 playCount;
  17217. } PACKED;
  17218. uint32 manufacturer;
  17219. uint32 product;
  17220. uint32 samplePeriod;
  17221. uint32 midiUnityNote;
  17222. uint32 midiPitchFraction;
  17223. uint32 smpteFormat;
  17224. uint32 smpteOffset;
  17225. uint32 numSampleLoops;
  17226. uint32 samplerData;
  17227. SampleLoop loops[1];
  17228. void copyTo (StringPairArray& values, const int totalSize) const
  17229. {
  17230. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17231. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17232. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17233. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17234. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17235. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17236. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17237. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17238. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17239. for (uint32 i = 0; i < numSampleLoops; ++i)
  17240. {
  17241. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17242. break;
  17243. const String prefix ("Loop" + String(i));
  17244. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17245. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17246. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17247. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17248. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17249. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17250. }
  17251. }
  17252. static MemoryBlock createFrom (const StringPairArray& values)
  17253. {
  17254. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17255. if (numLoops <= 0)
  17256. return MemoryBlock();
  17257. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17258. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17259. data.fillWith (0);
  17260. SMPLChunk* s = (SMPLChunk*) data.getData();
  17261. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17262. // as they get called in the right order..
  17263. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17264. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17265. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17266. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17267. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17268. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17269. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17270. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17271. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17272. for (int i = 0; i < numLoops; ++i)
  17273. {
  17274. const String prefix ("Loop" + String(i));
  17275. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17276. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17277. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17278. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17279. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17280. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17281. }
  17282. return data;
  17283. }
  17284. } PACKED;
  17285. struct ExtensibleWavSubFormat
  17286. {
  17287. uint32 data1;
  17288. uint16 data2;
  17289. uint16 data3;
  17290. uint8 data4[8];
  17291. } PACKED;
  17292. #if JUCE_MSVC
  17293. #pragma pack (pop)
  17294. #endif
  17295. #undef PACKED
  17296. class WavAudioFormatReader : public AudioFormatReader
  17297. {
  17298. int bytesPerFrame;
  17299. int64 dataChunkStart, dataLength;
  17300. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17301. WavAudioFormatReader (const WavAudioFormatReader&);
  17302. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17303. public:
  17304. int64 bwavChunkStart, bwavSize;
  17305. WavAudioFormatReader (InputStream* const in)
  17306. : AudioFormatReader (in, TRANS (wavFormatName)),
  17307. dataLength (0),
  17308. bwavChunkStart (0),
  17309. bwavSize (0)
  17310. {
  17311. if (input->readInt() == chunkName ("RIFF"))
  17312. {
  17313. const uint32 len = (uint32) input->readInt();
  17314. const int64 end = input->getPosition() + len;
  17315. bool hasGotType = false;
  17316. bool hasGotData = false;
  17317. if (input->readInt() == chunkName ("WAVE"))
  17318. {
  17319. while (input->getPosition() < end
  17320. && ! input->isExhausted())
  17321. {
  17322. const int chunkType = input->readInt();
  17323. uint32 length = (uint32) input->readInt();
  17324. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17325. if (chunkType == chunkName ("fmt "))
  17326. {
  17327. // read the format chunk
  17328. const unsigned short format = input->readShort();
  17329. const short numChans = input->readShort();
  17330. sampleRate = input->readInt();
  17331. const int bytesPerSec = input->readInt();
  17332. numChannels = numChans;
  17333. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17334. bitsPerSample = 8 * bytesPerFrame / numChans;
  17335. if (format == 3)
  17336. {
  17337. usesFloatingPointData = true;
  17338. }
  17339. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17340. {
  17341. if (length < 40) // too short
  17342. {
  17343. bytesPerFrame = 0;
  17344. }
  17345. else
  17346. {
  17347. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17348. ExtensibleWavSubFormat subFormat;
  17349. subFormat.data1 = input->readInt();
  17350. subFormat.data2 = input->readShort();
  17351. subFormat.data3 = input->readShort();
  17352. input->read (subFormat.data4, sizeof (subFormat.data4));
  17353. const ExtensibleWavSubFormat pcmFormat
  17354. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17355. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17356. {
  17357. const ExtensibleWavSubFormat ambisonicFormat
  17358. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17359. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17360. bytesPerFrame = 0;
  17361. }
  17362. }
  17363. }
  17364. else if (format != 1)
  17365. {
  17366. bytesPerFrame = 0;
  17367. }
  17368. hasGotType = true;
  17369. }
  17370. else if (chunkType == chunkName ("data"))
  17371. {
  17372. // get the data chunk's position
  17373. dataLength = length;
  17374. dataChunkStart = input->getPosition();
  17375. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17376. hasGotData = true;
  17377. }
  17378. else if (chunkType == chunkName ("bext"))
  17379. {
  17380. bwavChunkStart = input->getPosition();
  17381. bwavSize = length;
  17382. // Broadcast-wav extension chunk..
  17383. HeapBlock <BWAVChunk> bwav;
  17384. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17385. input->read (bwav, length);
  17386. bwav->copyTo (metadataValues);
  17387. }
  17388. else if (chunkType == chunkName ("smpl"))
  17389. {
  17390. HeapBlock <SMPLChunk> smpl;
  17391. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17392. input->read (smpl, length);
  17393. smpl->copyTo (metadataValues, length);
  17394. }
  17395. else if (chunkEnd <= input->getPosition())
  17396. {
  17397. break;
  17398. }
  17399. input->setPosition (chunkEnd);
  17400. }
  17401. }
  17402. }
  17403. }
  17404. ~WavAudioFormatReader()
  17405. {
  17406. }
  17407. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17408. int64 startSampleInFile, int numSamples)
  17409. {
  17410. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17411. if (samplesAvailable < numSamples)
  17412. {
  17413. for (int i = numDestChannels; --i >= 0;)
  17414. if (destSamples[i] != 0)
  17415. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17416. numSamples = (int) samplesAvailable;
  17417. }
  17418. if (numSamples <= 0)
  17419. return true;
  17420. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17421. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17422. char tempBuffer [tempBufSize];
  17423. while (numSamples > 0)
  17424. {
  17425. int* left = destSamples[0];
  17426. if (left != 0)
  17427. left += startOffsetInDestBuffer;
  17428. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17429. if (right != 0)
  17430. right += startOffsetInDestBuffer;
  17431. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17432. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17433. if (bytesRead < numThisTime * bytesPerFrame)
  17434. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17435. if (bitsPerSample == 16)
  17436. {
  17437. const short* src = reinterpret_cast <const short*> (tempBuffer);
  17438. if (numChannels > 1)
  17439. {
  17440. if (left == 0)
  17441. {
  17442. for (int i = numThisTime; --i >= 0;)
  17443. {
  17444. ++src;
  17445. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17446. }
  17447. }
  17448. else if (right == 0)
  17449. {
  17450. for (int i = numThisTime; --i >= 0;)
  17451. {
  17452. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17453. ++src;
  17454. }
  17455. }
  17456. else
  17457. {
  17458. for (int i = numThisTime; --i >= 0;)
  17459. {
  17460. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17461. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17462. }
  17463. }
  17464. }
  17465. else
  17466. {
  17467. for (int i = numThisTime; --i >= 0;)
  17468. {
  17469. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17470. }
  17471. }
  17472. }
  17473. else if (bitsPerSample == 24)
  17474. {
  17475. const char* src = tempBuffer;
  17476. if (numChannels > 1)
  17477. {
  17478. if (left == 0)
  17479. {
  17480. for (int i = numThisTime; --i >= 0;)
  17481. {
  17482. src += 3;
  17483. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17484. src += 3;
  17485. }
  17486. }
  17487. else if (right == 0)
  17488. {
  17489. for (int i = numThisTime; --i >= 0;)
  17490. {
  17491. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17492. src += 6;
  17493. }
  17494. }
  17495. else
  17496. {
  17497. for (int i = 0; i < numThisTime; ++i)
  17498. {
  17499. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17500. src += 3;
  17501. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17502. src += 3;
  17503. }
  17504. }
  17505. }
  17506. else
  17507. {
  17508. for (int i = 0; i < numThisTime; ++i)
  17509. {
  17510. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17511. src += 3;
  17512. }
  17513. }
  17514. }
  17515. else if (bitsPerSample == 32)
  17516. {
  17517. const unsigned int* src = (const unsigned int*) tempBuffer;
  17518. unsigned int* l = (unsigned int*) left;
  17519. unsigned int* r = (unsigned int*) right;
  17520. if (numChannels > 1)
  17521. {
  17522. if (l == 0)
  17523. {
  17524. for (int i = numThisTime; --i >= 0;)
  17525. {
  17526. ++src;
  17527. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17528. }
  17529. }
  17530. else if (r == 0)
  17531. {
  17532. for (int i = numThisTime; --i >= 0;)
  17533. {
  17534. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17535. ++src;
  17536. }
  17537. }
  17538. else
  17539. {
  17540. for (int i = numThisTime; --i >= 0;)
  17541. {
  17542. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17543. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17544. }
  17545. }
  17546. }
  17547. else
  17548. {
  17549. for (int i = numThisTime; --i >= 0;)
  17550. {
  17551. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17552. }
  17553. }
  17554. left = (int*)l;
  17555. right = (int*)r;
  17556. }
  17557. else if (bitsPerSample == 8)
  17558. {
  17559. const unsigned char* src = (const unsigned char*) tempBuffer;
  17560. if (numChannels > 1)
  17561. {
  17562. if (left == 0)
  17563. {
  17564. for (int i = numThisTime; --i >= 0;)
  17565. {
  17566. ++src;
  17567. *right++ = ((int) *src++ - 128) << 24;
  17568. }
  17569. }
  17570. else if (right == 0)
  17571. {
  17572. for (int i = numThisTime; --i >= 0;)
  17573. {
  17574. *left++ = ((int) *src++ - 128) << 24;
  17575. ++src;
  17576. }
  17577. }
  17578. else
  17579. {
  17580. for (int i = numThisTime; --i >= 0;)
  17581. {
  17582. *left++ = ((int) *src++ - 128) << 24;
  17583. *right++ = ((int) *src++ - 128) << 24;
  17584. }
  17585. }
  17586. }
  17587. else
  17588. {
  17589. for (int i = numThisTime; --i >= 0;)
  17590. {
  17591. *left++ = ((int)*src++ - 128) << 24;
  17592. }
  17593. }
  17594. }
  17595. startOffsetInDestBuffer += numThisTime;
  17596. numSamples -= numThisTime;
  17597. }
  17598. if (numSamples > 0)
  17599. {
  17600. for (int i = numDestChannels; --i >= 0;)
  17601. if (destSamples[i] != 0)
  17602. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17603. sizeof (int) * numSamples);
  17604. }
  17605. return true;
  17606. }
  17607. juce_UseDebuggingNewOperator
  17608. };
  17609. class WavAudioFormatWriter : public AudioFormatWriter
  17610. {
  17611. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17612. uint32 lengthInSamples, bytesWritten;
  17613. int64 headerPosition;
  17614. bool writeFailed;
  17615. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17616. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17617. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17618. void writeHeader()
  17619. {
  17620. const bool seekedOk = output->setPosition (headerPosition);
  17621. (void) seekedOk;
  17622. // if this fails, you've given it an output stream that can't seek! It needs
  17623. // to be able to seek back to write the header
  17624. jassert (seekedOk);
  17625. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17626. output->writeInt (chunkName ("RIFF"));
  17627. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17628. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17629. output->writeInt (chunkName ("WAVE"));
  17630. output->writeInt (chunkName ("fmt "));
  17631. output->writeInt (16);
  17632. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17633. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17634. output->writeShort ((short) numChannels);
  17635. output->writeInt ((int) sampleRate);
  17636. output->writeInt (bytesPerFrame * (int) sampleRate);
  17637. output->writeShort ((short) bytesPerFrame);
  17638. output->writeShort ((short) bitsPerSample);
  17639. if (bwavChunk.getSize() > 0)
  17640. {
  17641. output->writeInt (chunkName ("bext"));
  17642. output->writeInt ((int) bwavChunk.getSize());
  17643. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17644. }
  17645. if (smplChunk.getSize() > 0)
  17646. {
  17647. output->writeInt (chunkName ("smpl"));
  17648. output->writeInt ((int) smplChunk.getSize());
  17649. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17650. }
  17651. output->writeInt (chunkName ("data"));
  17652. output->writeInt (lengthInSamples * bytesPerFrame);
  17653. usesFloatingPointData = (bitsPerSample == 32);
  17654. }
  17655. public:
  17656. WavAudioFormatWriter (OutputStream* const out,
  17657. const double sampleRate_,
  17658. const unsigned int numChannels_,
  17659. const int bits,
  17660. const StringPairArray& metadataValues)
  17661. : AudioFormatWriter (out,
  17662. TRANS (wavFormatName),
  17663. sampleRate_,
  17664. numChannels_,
  17665. bits),
  17666. lengthInSamples (0),
  17667. bytesWritten (0),
  17668. writeFailed (false)
  17669. {
  17670. if (metadataValues.size() > 0)
  17671. {
  17672. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17673. smplChunk = SMPLChunk::createFrom (metadataValues);
  17674. }
  17675. headerPosition = out->getPosition();
  17676. writeHeader();
  17677. }
  17678. ~WavAudioFormatWriter()
  17679. {
  17680. writeHeader();
  17681. }
  17682. bool write (const int** data, int numSamples)
  17683. {
  17684. if (writeFailed)
  17685. return false;
  17686. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17687. tempBlock.ensureSize (bytes, false);
  17688. char* buffer = static_cast <char*> (tempBlock.getData());
  17689. const int* left = data[0];
  17690. const int* right = data[1];
  17691. if (right == 0)
  17692. right = left;
  17693. if (bitsPerSample == 16)
  17694. {
  17695. short* b = (short*) buffer;
  17696. if (numChannels > 1)
  17697. {
  17698. for (int i = numSamples; --i >= 0;)
  17699. {
  17700. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17701. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17702. }
  17703. }
  17704. else
  17705. {
  17706. for (int i = numSamples; --i >= 0;)
  17707. {
  17708. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17709. }
  17710. }
  17711. }
  17712. else if (bitsPerSample == 24)
  17713. {
  17714. char* b = buffer;
  17715. if (numChannels > 1)
  17716. {
  17717. for (int i = numSamples; --i >= 0;)
  17718. {
  17719. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17720. b += 3;
  17721. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17722. b += 3;
  17723. }
  17724. }
  17725. else
  17726. {
  17727. for (int i = numSamples; --i >= 0;)
  17728. {
  17729. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17730. b += 3;
  17731. }
  17732. }
  17733. }
  17734. else if (bitsPerSample == 32)
  17735. {
  17736. unsigned int* b = (unsigned int*) buffer;
  17737. if (numChannels > 1)
  17738. {
  17739. for (int i = numSamples; --i >= 0;)
  17740. {
  17741. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17742. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17743. }
  17744. }
  17745. else
  17746. {
  17747. for (int i = numSamples; --i >= 0;)
  17748. {
  17749. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17750. }
  17751. }
  17752. }
  17753. else if (bitsPerSample == 8)
  17754. {
  17755. unsigned char* b = (unsigned char*) buffer;
  17756. if (numChannels > 1)
  17757. {
  17758. for (int i = numSamples; --i >= 0;)
  17759. {
  17760. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17761. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17762. }
  17763. }
  17764. else
  17765. {
  17766. for (int i = numSamples; --i >= 0;)
  17767. {
  17768. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17769. }
  17770. }
  17771. }
  17772. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17773. || ! output->write (buffer, bytes))
  17774. {
  17775. // failed to write to disk, so let's try writing the header.
  17776. // If it's just run out of disk space, then if it does manage
  17777. // to write the header, we'll still have a useable file..
  17778. writeHeader();
  17779. writeFailed = true;
  17780. return false;
  17781. }
  17782. else
  17783. {
  17784. bytesWritten += bytes;
  17785. lengthInSamples += numSamples;
  17786. return true;
  17787. }
  17788. }
  17789. juce_UseDebuggingNewOperator
  17790. };
  17791. WavAudioFormat::WavAudioFormat()
  17792. : AudioFormat (TRANS (wavFormatName), (const juce_wchar**) wavExtensions)
  17793. {
  17794. }
  17795. WavAudioFormat::~WavAudioFormat()
  17796. {
  17797. }
  17798. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17799. {
  17800. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17801. return Array <int> (rates);
  17802. }
  17803. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17804. {
  17805. const int depths[] = { 8, 16, 24, 32, 0 };
  17806. return Array <int> (depths);
  17807. }
  17808. bool WavAudioFormat::canDoStereo()
  17809. {
  17810. return true;
  17811. }
  17812. bool WavAudioFormat::canDoMono()
  17813. {
  17814. return true;
  17815. }
  17816. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17817. const bool deleteStreamIfOpeningFails)
  17818. {
  17819. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17820. if (r->sampleRate != 0)
  17821. return r.release();
  17822. if (! deleteStreamIfOpeningFails)
  17823. r->input = 0;
  17824. return 0;
  17825. }
  17826. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17827. double sampleRate,
  17828. unsigned int numChannels,
  17829. int bitsPerSample,
  17830. const StringPairArray& metadataValues,
  17831. int /*qualityOptionIndex*/)
  17832. {
  17833. if (getPossibleBitDepths().contains (bitsPerSample))
  17834. {
  17835. return new WavAudioFormatWriter (out,
  17836. sampleRate,
  17837. numChannels,
  17838. bitsPerSample,
  17839. metadataValues);
  17840. }
  17841. return 0;
  17842. }
  17843. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17844. {
  17845. TemporaryFile tempFile (file);
  17846. WavAudioFormat wav;
  17847. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17848. if (reader != 0)
  17849. {
  17850. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17851. if (outStream != 0)
  17852. {
  17853. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17854. reader->numChannels, reader->bitsPerSample,
  17855. metadata, 0));
  17856. if (writer != 0)
  17857. {
  17858. outStream.release();
  17859. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17860. writer = 0;
  17861. reader = 0;
  17862. return ok && tempFile.overwriteTargetFileWithTemporary();
  17863. }
  17864. }
  17865. }
  17866. return false;
  17867. }
  17868. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17869. {
  17870. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17871. if (reader != 0)
  17872. {
  17873. const int64 bwavPos = reader->bwavChunkStart;
  17874. const int64 bwavSize = reader->bwavSize;
  17875. reader = 0;
  17876. if (bwavSize > 0)
  17877. {
  17878. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17879. if (chunk.getSize() <= (size_t) bwavSize)
  17880. {
  17881. // the new one will fit in the space available, so write it directly..
  17882. const int64 oldSize = wavFile.getSize();
  17883. {
  17884. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17885. out->setPosition (bwavPos);
  17886. out->write (chunk.getData(), (int) chunk.getSize());
  17887. out->setPosition (oldSize);
  17888. }
  17889. jassert (wavFile.getSize() == oldSize);
  17890. return true;
  17891. }
  17892. }
  17893. }
  17894. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17895. }
  17896. END_JUCE_NAMESPACE
  17897. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17898. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17899. BEGIN_JUCE_NAMESPACE
  17900. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17901. const bool deleteReaderWhenThisIsDeleted)
  17902. : reader (reader_),
  17903. deleteReader (deleteReaderWhenThisIsDeleted),
  17904. nextPlayPos (0),
  17905. looping (false)
  17906. {
  17907. jassert (reader != 0);
  17908. }
  17909. AudioFormatReaderSource::~AudioFormatReaderSource()
  17910. {
  17911. releaseResources();
  17912. if (deleteReader)
  17913. delete reader;
  17914. }
  17915. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17916. {
  17917. nextPlayPos = newPosition;
  17918. }
  17919. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17920. {
  17921. looping = shouldLoop;
  17922. }
  17923. int AudioFormatReaderSource::getNextReadPosition() const
  17924. {
  17925. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17926. : nextPlayPos;
  17927. }
  17928. int AudioFormatReaderSource::getTotalLength() const
  17929. {
  17930. return (int) reader->lengthInSamples;
  17931. }
  17932. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17933. double /*sampleRate*/)
  17934. {
  17935. }
  17936. void AudioFormatReaderSource::releaseResources()
  17937. {
  17938. }
  17939. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17940. {
  17941. if (info.numSamples > 0)
  17942. {
  17943. const int start = nextPlayPos;
  17944. if (looping)
  17945. {
  17946. const int newStart = start % (int) reader->lengthInSamples;
  17947. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17948. if (newEnd > newStart)
  17949. {
  17950. info.buffer->readFromAudioReader (reader,
  17951. info.startSample,
  17952. newEnd - newStart,
  17953. newStart,
  17954. true, true);
  17955. }
  17956. else
  17957. {
  17958. const int endSamps = (int) reader->lengthInSamples - newStart;
  17959. info.buffer->readFromAudioReader (reader,
  17960. info.startSample,
  17961. endSamps,
  17962. newStart,
  17963. true, true);
  17964. info.buffer->readFromAudioReader (reader,
  17965. info.startSample + endSamps,
  17966. newEnd,
  17967. 0,
  17968. true, true);
  17969. }
  17970. nextPlayPos = newEnd;
  17971. }
  17972. else
  17973. {
  17974. info.buffer->readFromAudioReader (reader,
  17975. info.startSample,
  17976. info.numSamples,
  17977. start,
  17978. true, true);
  17979. nextPlayPos += info.numSamples;
  17980. }
  17981. }
  17982. }
  17983. END_JUCE_NAMESPACE
  17984. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17985. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  17986. BEGIN_JUCE_NAMESPACE
  17987. AudioSourcePlayer::AudioSourcePlayer()
  17988. : source (0),
  17989. sampleRate (0),
  17990. bufferSize (0),
  17991. tempBuffer (2, 8),
  17992. lastGain (1.0f),
  17993. gain (1.0f)
  17994. {
  17995. }
  17996. AudioSourcePlayer::~AudioSourcePlayer()
  17997. {
  17998. setSource (0);
  17999. }
  18000. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18001. {
  18002. if (source != newSource)
  18003. {
  18004. AudioSource* const oldSource = source;
  18005. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18006. newSource->prepareToPlay (bufferSize, sampleRate);
  18007. {
  18008. const ScopedLock sl (readLock);
  18009. source = newSource;
  18010. }
  18011. if (oldSource != 0)
  18012. oldSource->releaseResources();
  18013. }
  18014. }
  18015. void AudioSourcePlayer::setGain (const float newGain) throw()
  18016. {
  18017. gain = newGain;
  18018. }
  18019. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18020. int totalNumInputChannels,
  18021. float** outputChannelData,
  18022. int totalNumOutputChannels,
  18023. int numSamples)
  18024. {
  18025. // these should have been prepared by audioDeviceAboutToStart()...
  18026. jassert (sampleRate > 0 && bufferSize > 0);
  18027. const ScopedLock sl (readLock);
  18028. if (source != 0)
  18029. {
  18030. AudioSourceChannelInfo info;
  18031. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18032. // messy stuff needed to compact the channels down into an array
  18033. // of non-zero pointers..
  18034. for (i = 0; i < totalNumInputChannels; ++i)
  18035. {
  18036. if (inputChannelData[i] != 0)
  18037. {
  18038. inputChans [numInputs++] = inputChannelData[i];
  18039. if (numInputs >= numElementsInArray (inputChans))
  18040. break;
  18041. }
  18042. }
  18043. for (i = 0; i < totalNumOutputChannels; ++i)
  18044. {
  18045. if (outputChannelData[i] != 0)
  18046. {
  18047. outputChans [numOutputs++] = outputChannelData[i];
  18048. if (numOutputs >= numElementsInArray (outputChans))
  18049. break;
  18050. }
  18051. }
  18052. if (numInputs > numOutputs)
  18053. {
  18054. // if there aren't enough output channels for the number of
  18055. // inputs, we need to create some temporary extra ones (can't
  18056. // use the input data in case it gets written to)
  18057. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18058. false, false, true);
  18059. for (i = 0; i < numOutputs; ++i)
  18060. {
  18061. channels[numActiveChans] = outputChans[i];
  18062. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18063. ++numActiveChans;
  18064. }
  18065. for (i = numOutputs; i < numInputs; ++i)
  18066. {
  18067. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18068. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18069. ++numActiveChans;
  18070. }
  18071. }
  18072. else
  18073. {
  18074. for (i = 0; i < numInputs; ++i)
  18075. {
  18076. channels[numActiveChans] = outputChans[i];
  18077. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18078. ++numActiveChans;
  18079. }
  18080. for (i = numInputs; i < numOutputs; ++i)
  18081. {
  18082. channels[numActiveChans] = outputChans[i];
  18083. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18084. ++numActiveChans;
  18085. }
  18086. }
  18087. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18088. info.buffer = &buffer;
  18089. info.startSample = 0;
  18090. info.numSamples = numSamples;
  18091. source->getNextAudioBlock (info);
  18092. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18093. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18094. lastGain = gain;
  18095. }
  18096. else
  18097. {
  18098. for (int i = 0; i < totalNumOutputChannels; ++i)
  18099. if (outputChannelData[i] != 0)
  18100. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18101. }
  18102. }
  18103. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18104. {
  18105. sampleRate = device->getCurrentSampleRate();
  18106. bufferSize = device->getCurrentBufferSizeSamples();
  18107. zeromem (channels, sizeof (channels));
  18108. if (source != 0)
  18109. source->prepareToPlay (bufferSize, sampleRate);
  18110. }
  18111. void AudioSourcePlayer::audioDeviceStopped()
  18112. {
  18113. if (source != 0)
  18114. source->releaseResources();
  18115. sampleRate = 0.0;
  18116. bufferSize = 0;
  18117. tempBuffer.setSize (2, 8);
  18118. }
  18119. END_JUCE_NAMESPACE
  18120. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18121. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18122. BEGIN_JUCE_NAMESPACE
  18123. AudioTransportSource::AudioTransportSource()
  18124. : source (0),
  18125. resamplerSource (0),
  18126. bufferingSource (0),
  18127. positionableSource (0),
  18128. masterSource (0),
  18129. gain (1.0f),
  18130. lastGain (1.0f),
  18131. playing (false),
  18132. stopped (true),
  18133. sampleRate (44100.0),
  18134. sourceSampleRate (0.0),
  18135. blockSize (128),
  18136. readAheadBufferSize (0),
  18137. isPrepared (false),
  18138. inputStreamEOF (false)
  18139. {
  18140. }
  18141. AudioTransportSource::~AudioTransportSource()
  18142. {
  18143. setSource (0);
  18144. releaseResources();
  18145. }
  18146. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18147. int readAheadBufferSize_,
  18148. double sourceSampleRateToCorrectFor)
  18149. {
  18150. if (source == newSource)
  18151. {
  18152. if (source == 0)
  18153. return;
  18154. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18155. }
  18156. readAheadBufferSize = readAheadBufferSize_;
  18157. sourceSampleRate = sourceSampleRateToCorrectFor;
  18158. ResamplingAudioSource* newResamplerSource = 0;
  18159. BufferingAudioSource* newBufferingSource = 0;
  18160. PositionableAudioSource* newPositionableSource = 0;
  18161. AudioSource* newMasterSource = 0;
  18162. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18163. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18164. AudioSource* oldMasterSource = masterSource;
  18165. if (newSource != 0)
  18166. {
  18167. newPositionableSource = newSource;
  18168. if (readAheadBufferSize_ > 0)
  18169. newPositionableSource = newBufferingSource
  18170. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18171. newPositionableSource->setNextReadPosition (0);
  18172. if (sourceSampleRateToCorrectFor != 0)
  18173. newMasterSource = newResamplerSource
  18174. = new ResamplingAudioSource (newPositionableSource, false);
  18175. else
  18176. newMasterSource = newPositionableSource;
  18177. if (isPrepared)
  18178. {
  18179. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18180. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18181. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18182. }
  18183. }
  18184. {
  18185. const ScopedLock sl (callbackLock);
  18186. source = newSource;
  18187. resamplerSource = newResamplerSource;
  18188. bufferingSource = newBufferingSource;
  18189. masterSource = newMasterSource;
  18190. positionableSource = newPositionableSource;
  18191. playing = false;
  18192. }
  18193. if (oldMasterSource != 0)
  18194. oldMasterSource->releaseResources();
  18195. }
  18196. void AudioTransportSource::start()
  18197. {
  18198. if ((! playing) && masterSource != 0)
  18199. {
  18200. {
  18201. const ScopedLock sl (callbackLock);
  18202. playing = true;
  18203. stopped = false;
  18204. inputStreamEOF = false;
  18205. }
  18206. sendChangeMessage (this);
  18207. }
  18208. }
  18209. void AudioTransportSource::stop()
  18210. {
  18211. if (playing)
  18212. {
  18213. {
  18214. const ScopedLock sl (callbackLock);
  18215. playing = false;
  18216. }
  18217. int n = 500;
  18218. while (--n >= 0 && ! stopped)
  18219. Thread::sleep (2);
  18220. sendChangeMessage (this);
  18221. }
  18222. }
  18223. void AudioTransportSource::setPosition (double newPosition)
  18224. {
  18225. if (sampleRate > 0.0)
  18226. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18227. }
  18228. double AudioTransportSource::getCurrentPosition() const
  18229. {
  18230. if (sampleRate > 0.0)
  18231. return getNextReadPosition() / sampleRate;
  18232. else
  18233. return 0.0;
  18234. }
  18235. void AudioTransportSource::setNextReadPosition (int newPosition)
  18236. {
  18237. if (positionableSource != 0)
  18238. {
  18239. if (sampleRate > 0 && sourceSampleRate > 0)
  18240. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18241. positionableSource->setNextReadPosition (newPosition);
  18242. }
  18243. }
  18244. int AudioTransportSource::getNextReadPosition() const
  18245. {
  18246. if (positionableSource != 0)
  18247. {
  18248. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18249. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18250. }
  18251. return 0;
  18252. }
  18253. int AudioTransportSource::getTotalLength() const
  18254. {
  18255. const ScopedLock sl (callbackLock);
  18256. if (positionableSource != 0)
  18257. {
  18258. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18259. return roundToInt (positionableSource->getTotalLength() * ratio);
  18260. }
  18261. return 0;
  18262. }
  18263. bool AudioTransportSource::isLooping() const
  18264. {
  18265. const ScopedLock sl (callbackLock);
  18266. return positionableSource != 0
  18267. && positionableSource->isLooping();
  18268. }
  18269. void AudioTransportSource::setGain (const float newGain) throw()
  18270. {
  18271. gain = newGain;
  18272. }
  18273. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18274. double sampleRate_)
  18275. {
  18276. const ScopedLock sl (callbackLock);
  18277. sampleRate = sampleRate_;
  18278. blockSize = samplesPerBlockExpected;
  18279. if (masterSource != 0)
  18280. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18281. if (resamplerSource != 0 && sourceSampleRate != 0)
  18282. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18283. isPrepared = true;
  18284. }
  18285. void AudioTransportSource::releaseResources()
  18286. {
  18287. const ScopedLock sl (callbackLock);
  18288. if (masterSource != 0)
  18289. masterSource->releaseResources();
  18290. isPrepared = false;
  18291. }
  18292. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18293. {
  18294. const ScopedLock sl (callbackLock);
  18295. inputStreamEOF = false;
  18296. if (masterSource != 0 && ! stopped)
  18297. {
  18298. masterSource->getNextAudioBlock (info);
  18299. if (! playing)
  18300. {
  18301. // just stopped playing, so fade out the last block..
  18302. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18303. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18304. if (info.numSamples > 256)
  18305. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18306. }
  18307. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18308. && ! positionableSource->isLooping())
  18309. {
  18310. playing = false;
  18311. inputStreamEOF = true;
  18312. sendChangeMessage (this);
  18313. }
  18314. stopped = ! playing;
  18315. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18316. {
  18317. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18318. lastGain, gain);
  18319. }
  18320. }
  18321. else
  18322. {
  18323. info.clearActiveBufferRegion();
  18324. stopped = true;
  18325. }
  18326. lastGain = gain;
  18327. }
  18328. END_JUCE_NAMESPACE
  18329. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18330. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18331. BEGIN_JUCE_NAMESPACE
  18332. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18333. public Thread,
  18334. private Timer
  18335. {
  18336. public:
  18337. SharedBufferingAudioSourceThread()
  18338. : Thread ("Audio Buffer")
  18339. {
  18340. }
  18341. ~SharedBufferingAudioSourceThread()
  18342. {
  18343. stopThread (10000);
  18344. clearSingletonInstance();
  18345. }
  18346. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18347. void addSource (BufferingAudioSource* source)
  18348. {
  18349. const ScopedLock sl (lock);
  18350. if (! sources.contains (source))
  18351. {
  18352. sources.add (source);
  18353. startThread();
  18354. stopTimer();
  18355. }
  18356. notify();
  18357. }
  18358. void removeSource (BufferingAudioSource* source)
  18359. {
  18360. const ScopedLock sl (lock);
  18361. sources.removeValue (source);
  18362. if (sources.size() == 0)
  18363. startTimer (5000);
  18364. }
  18365. private:
  18366. Array <BufferingAudioSource*> sources;
  18367. CriticalSection lock;
  18368. void run()
  18369. {
  18370. while (! threadShouldExit())
  18371. {
  18372. bool busy = false;
  18373. for (int i = sources.size(); --i >= 0;)
  18374. {
  18375. if (threadShouldExit())
  18376. return;
  18377. const ScopedLock sl (lock);
  18378. BufferingAudioSource* const b = sources[i];
  18379. if (b != 0 && b->readNextBufferChunk())
  18380. busy = true;
  18381. }
  18382. if (! busy)
  18383. wait (500);
  18384. }
  18385. }
  18386. void timerCallback()
  18387. {
  18388. stopTimer();
  18389. if (sources.size() == 0)
  18390. deleteInstance();
  18391. }
  18392. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18393. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18394. };
  18395. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18396. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18397. const bool deleteSourceWhenDeleted_,
  18398. int numberOfSamplesToBuffer_)
  18399. : source (source_),
  18400. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18401. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18402. buffer (2, 0),
  18403. bufferValidStart (0),
  18404. bufferValidEnd (0),
  18405. nextPlayPos (0),
  18406. wasSourceLooping (false)
  18407. {
  18408. jassert (source_ != 0);
  18409. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18410. // not using a larger buffer..
  18411. }
  18412. BufferingAudioSource::~BufferingAudioSource()
  18413. {
  18414. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18415. if (thread != 0)
  18416. thread->removeSource (this);
  18417. if (deleteSourceWhenDeleted)
  18418. delete source;
  18419. }
  18420. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18421. {
  18422. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18423. sampleRate = sampleRate_;
  18424. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18425. buffer.clear();
  18426. bufferValidStart = 0;
  18427. bufferValidEnd = 0;
  18428. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18429. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18430. buffer.getNumSamples() / 2))
  18431. {
  18432. SharedBufferingAudioSourceThread::getInstance()->notify();
  18433. Thread::sleep (5);
  18434. }
  18435. }
  18436. void BufferingAudioSource::releaseResources()
  18437. {
  18438. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18439. if (thread != 0)
  18440. thread->removeSource (this);
  18441. buffer.setSize (2, 0);
  18442. source->releaseResources();
  18443. }
  18444. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18445. {
  18446. const ScopedLock sl (bufferStartPosLock);
  18447. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18448. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18449. if (validStart == validEnd)
  18450. {
  18451. // total cache miss
  18452. info.clearActiveBufferRegion();
  18453. }
  18454. else
  18455. {
  18456. if (validStart > 0)
  18457. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18458. if (validEnd < info.numSamples)
  18459. info.buffer->clear (info.startSample + validEnd,
  18460. info.numSamples - validEnd); // partial cache miss at end
  18461. if (validStart < validEnd)
  18462. {
  18463. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18464. {
  18465. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18466. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18467. if (startBufferIndex < endBufferIndex)
  18468. {
  18469. info.buffer->copyFrom (chan, info.startSample + validStart,
  18470. buffer,
  18471. chan, startBufferIndex,
  18472. validEnd - validStart);
  18473. }
  18474. else
  18475. {
  18476. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18477. info.buffer->copyFrom (chan, info.startSample + validStart,
  18478. buffer,
  18479. chan, startBufferIndex,
  18480. initialSize);
  18481. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18482. buffer,
  18483. chan, 0,
  18484. (validEnd - validStart) - initialSize);
  18485. }
  18486. }
  18487. }
  18488. nextPlayPos += info.numSamples;
  18489. if (source->isLooping() && nextPlayPos > 0)
  18490. nextPlayPos %= source->getTotalLength();
  18491. }
  18492. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18493. if (thread != 0)
  18494. thread->notify();
  18495. }
  18496. int BufferingAudioSource::getNextReadPosition() const
  18497. {
  18498. return (source->isLooping() && nextPlayPos > 0)
  18499. ? nextPlayPos % source->getTotalLength()
  18500. : nextPlayPos;
  18501. }
  18502. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18503. {
  18504. const ScopedLock sl (bufferStartPosLock);
  18505. nextPlayPos = newPosition;
  18506. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18507. if (thread != 0)
  18508. thread->notify();
  18509. }
  18510. bool BufferingAudioSource::readNextBufferChunk()
  18511. {
  18512. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18513. {
  18514. const ScopedLock sl (bufferStartPosLock);
  18515. if (wasSourceLooping != isLooping())
  18516. {
  18517. wasSourceLooping = isLooping();
  18518. bufferValidStart = 0;
  18519. bufferValidEnd = 0;
  18520. }
  18521. newBVS = jmax (0, nextPlayPos);
  18522. newBVE = newBVS + buffer.getNumSamples() - 4;
  18523. sectionToReadStart = 0;
  18524. sectionToReadEnd = 0;
  18525. const int maxChunkSize = 2048;
  18526. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18527. {
  18528. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18529. sectionToReadStart = newBVS;
  18530. sectionToReadEnd = newBVE;
  18531. bufferValidStart = 0;
  18532. bufferValidEnd = 0;
  18533. }
  18534. else if (abs (newBVS - bufferValidStart) > 512
  18535. || abs (newBVE - bufferValidEnd) > 512)
  18536. {
  18537. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18538. sectionToReadStart = bufferValidEnd;
  18539. sectionToReadEnd = newBVE;
  18540. bufferValidStart = newBVS;
  18541. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18542. }
  18543. }
  18544. if (sectionToReadStart != sectionToReadEnd)
  18545. {
  18546. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18547. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18548. if (bufferIndexStart < bufferIndexEnd)
  18549. {
  18550. readBufferSection (sectionToReadStart,
  18551. sectionToReadEnd - sectionToReadStart,
  18552. bufferIndexStart);
  18553. }
  18554. else
  18555. {
  18556. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18557. readBufferSection (sectionToReadStart,
  18558. initialSize,
  18559. bufferIndexStart);
  18560. readBufferSection (sectionToReadStart + initialSize,
  18561. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18562. 0);
  18563. }
  18564. const ScopedLock sl2 (bufferStartPosLock);
  18565. bufferValidStart = newBVS;
  18566. bufferValidEnd = newBVE;
  18567. return true;
  18568. }
  18569. else
  18570. {
  18571. return false;
  18572. }
  18573. }
  18574. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18575. {
  18576. if (source->getNextReadPosition() != start)
  18577. source->setNextReadPosition (start);
  18578. AudioSourceChannelInfo info;
  18579. info.buffer = &buffer;
  18580. info.startSample = bufferOffset;
  18581. info.numSamples = length;
  18582. source->getNextAudioBlock (info);
  18583. }
  18584. END_JUCE_NAMESPACE
  18585. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18586. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18587. BEGIN_JUCE_NAMESPACE
  18588. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18589. const bool deleteSourceWhenDeleted_)
  18590. : requiredNumberOfChannels (2),
  18591. source (source_),
  18592. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18593. buffer (2, 16)
  18594. {
  18595. remappedInfo.buffer = &buffer;
  18596. remappedInfo.startSample = 0;
  18597. }
  18598. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18599. {
  18600. if (deleteSourceWhenDeleted)
  18601. delete source;
  18602. }
  18603. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18604. {
  18605. const ScopedLock sl (lock);
  18606. requiredNumberOfChannels = requiredNumberOfChannels_;
  18607. }
  18608. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18609. {
  18610. const ScopedLock sl (lock);
  18611. remappedInputs.clear();
  18612. remappedOutputs.clear();
  18613. }
  18614. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18615. {
  18616. const ScopedLock sl (lock);
  18617. while (remappedInputs.size() < destIndex)
  18618. remappedInputs.add (-1);
  18619. remappedInputs.set (destIndex, sourceIndex);
  18620. }
  18621. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18622. {
  18623. const ScopedLock sl (lock);
  18624. while (remappedOutputs.size() < sourceIndex)
  18625. remappedOutputs.add (-1);
  18626. remappedOutputs.set (sourceIndex, destIndex);
  18627. }
  18628. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18629. {
  18630. const ScopedLock sl (lock);
  18631. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18632. return remappedInputs.getUnchecked (inputChannelIndex);
  18633. return -1;
  18634. }
  18635. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18636. {
  18637. const ScopedLock sl (lock);
  18638. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18639. return remappedOutputs .getUnchecked (outputChannelIndex);
  18640. return -1;
  18641. }
  18642. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18643. {
  18644. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18645. }
  18646. void ChannelRemappingAudioSource::releaseResources()
  18647. {
  18648. source->releaseResources();
  18649. }
  18650. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18651. {
  18652. const ScopedLock sl (lock);
  18653. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18654. const int numChans = bufferToFill.buffer->getNumChannels();
  18655. int i;
  18656. for (i = 0; i < buffer.getNumChannels(); ++i)
  18657. {
  18658. const int remappedChan = getRemappedInputChannel (i);
  18659. if (remappedChan >= 0 && remappedChan < numChans)
  18660. {
  18661. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18662. remappedChan,
  18663. bufferToFill.startSample,
  18664. bufferToFill.numSamples);
  18665. }
  18666. else
  18667. {
  18668. buffer.clear (i, 0, bufferToFill.numSamples);
  18669. }
  18670. }
  18671. remappedInfo.numSamples = bufferToFill.numSamples;
  18672. source->getNextAudioBlock (remappedInfo);
  18673. bufferToFill.clearActiveBufferRegion();
  18674. for (i = 0; i < requiredNumberOfChannels; ++i)
  18675. {
  18676. const int remappedChan = getRemappedOutputChannel (i);
  18677. if (remappedChan >= 0 && remappedChan < numChans)
  18678. {
  18679. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18680. buffer, i, 0, bufferToFill.numSamples);
  18681. }
  18682. }
  18683. }
  18684. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18685. {
  18686. XmlElement* e = new XmlElement ("MAPPINGS");
  18687. String ins, outs;
  18688. int i;
  18689. const ScopedLock sl (lock);
  18690. for (i = 0; i < remappedInputs.size(); ++i)
  18691. ins << remappedInputs.getUnchecked(i) << ' ';
  18692. for (i = 0; i < remappedOutputs.size(); ++i)
  18693. outs << remappedOutputs.getUnchecked(i) << ' ';
  18694. e->setAttribute ("inputs", ins.trimEnd());
  18695. e->setAttribute ("outputs", outs.trimEnd());
  18696. return e;
  18697. }
  18698. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18699. {
  18700. if (e.hasTagName ("MAPPINGS"))
  18701. {
  18702. const ScopedLock sl (lock);
  18703. clearAllMappings();
  18704. StringArray ins, outs;
  18705. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18706. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18707. int i;
  18708. for (i = 0; i < ins.size(); ++i)
  18709. remappedInputs.add (ins[i].getIntValue());
  18710. for (i = 0; i < outs.size(); ++i)
  18711. remappedOutputs.add (outs[i].getIntValue());
  18712. }
  18713. }
  18714. END_JUCE_NAMESPACE
  18715. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18716. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18717. BEGIN_JUCE_NAMESPACE
  18718. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18719. const bool deleteInputWhenDeleted_)
  18720. : input (inputSource),
  18721. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18722. {
  18723. jassert (inputSource != 0);
  18724. for (int i = 2; --i >= 0;)
  18725. iirFilters.add (new IIRFilter());
  18726. }
  18727. IIRFilterAudioSource::~IIRFilterAudioSource()
  18728. {
  18729. if (deleteInputWhenDeleted)
  18730. delete input;
  18731. }
  18732. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18733. {
  18734. for (int i = iirFilters.size(); --i >= 0;)
  18735. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18736. }
  18737. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18738. {
  18739. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18740. for (int i = iirFilters.size(); --i >= 0;)
  18741. iirFilters.getUnchecked(i)->reset();
  18742. }
  18743. void IIRFilterAudioSource::releaseResources()
  18744. {
  18745. input->releaseResources();
  18746. }
  18747. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18748. {
  18749. input->getNextAudioBlock (bufferToFill);
  18750. const int numChannels = bufferToFill.buffer->getNumChannels();
  18751. while (numChannels > iirFilters.size())
  18752. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18753. for (int i = 0; i < numChannels; ++i)
  18754. iirFilters.getUnchecked(i)
  18755. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18756. bufferToFill.numSamples);
  18757. }
  18758. END_JUCE_NAMESPACE
  18759. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18760. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18761. BEGIN_JUCE_NAMESPACE
  18762. MixerAudioSource::MixerAudioSource()
  18763. : tempBuffer (2, 0),
  18764. currentSampleRate (0.0),
  18765. bufferSizeExpected (0)
  18766. {
  18767. }
  18768. MixerAudioSource::~MixerAudioSource()
  18769. {
  18770. removeAllInputs();
  18771. }
  18772. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18773. {
  18774. if (input != 0 && ! inputs.contains (input))
  18775. {
  18776. double localRate;
  18777. int localBufferSize;
  18778. {
  18779. const ScopedLock sl (lock);
  18780. localRate = currentSampleRate;
  18781. localBufferSize = bufferSizeExpected;
  18782. }
  18783. if (localRate != 0.0)
  18784. input->prepareToPlay (localBufferSize, localRate);
  18785. const ScopedLock sl (lock);
  18786. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18787. inputs.add (input);
  18788. }
  18789. }
  18790. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18791. {
  18792. if (input != 0)
  18793. {
  18794. int index;
  18795. {
  18796. const ScopedLock sl (lock);
  18797. index = inputs.indexOf (input);
  18798. if (index >= 0)
  18799. {
  18800. inputsToDelete.shiftBits (index, 1);
  18801. inputs.remove (index);
  18802. }
  18803. }
  18804. if (index >= 0)
  18805. {
  18806. input->releaseResources();
  18807. if (deleteInput)
  18808. delete input;
  18809. }
  18810. }
  18811. }
  18812. void MixerAudioSource::removeAllInputs()
  18813. {
  18814. VoidArray inputsCopy;
  18815. BigInteger inputsToDeleteCopy;
  18816. {
  18817. const ScopedLock sl (lock);
  18818. inputsCopy = inputs;
  18819. inputsToDeleteCopy = inputsToDelete;
  18820. }
  18821. for (int i = inputsCopy.size(); --i >= 0;)
  18822. if (inputsToDeleteCopy[i])
  18823. delete (AudioSource*) inputsCopy[i];
  18824. }
  18825. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18826. {
  18827. tempBuffer.setSize (2, samplesPerBlockExpected);
  18828. const ScopedLock sl (lock);
  18829. currentSampleRate = sampleRate;
  18830. bufferSizeExpected = samplesPerBlockExpected;
  18831. for (int i = inputs.size(); --i >= 0;)
  18832. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18833. sampleRate);
  18834. }
  18835. void MixerAudioSource::releaseResources()
  18836. {
  18837. const ScopedLock sl (lock);
  18838. for (int i = inputs.size(); --i >= 0;)
  18839. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18840. tempBuffer.setSize (2, 0);
  18841. currentSampleRate = 0;
  18842. bufferSizeExpected = 0;
  18843. }
  18844. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18845. {
  18846. const ScopedLock sl (lock);
  18847. if (inputs.size() > 0)
  18848. {
  18849. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18850. if (inputs.size() > 1)
  18851. {
  18852. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18853. info.buffer->getNumSamples());
  18854. AudioSourceChannelInfo info2;
  18855. info2.buffer = &tempBuffer;
  18856. info2.numSamples = info.numSamples;
  18857. info2.startSample = 0;
  18858. for (int i = 1; i < inputs.size(); ++i)
  18859. {
  18860. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18861. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18862. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18863. }
  18864. }
  18865. }
  18866. else
  18867. {
  18868. info.clearActiveBufferRegion();
  18869. }
  18870. }
  18871. END_JUCE_NAMESPACE
  18872. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18873. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18874. BEGIN_JUCE_NAMESPACE
  18875. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18876. const bool deleteInputWhenDeleted_)
  18877. : input (inputSource),
  18878. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18879. ratio (1.0),
  18880. lastRatio (1.0),
  18881. buffer (2, 0),
  18882. sampsInBuffer (0)
  18883. {
  18884. jassert (input != 0);
  18885. }
  18886. ResamplingAudioSource::~ResamplingAudioSource()
  18887. {
  18888. if (deleteInputWhenDeleted)
  18889. delete input;
  18890. }
  18891. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18892. {
  18893. jassert (samplesInPerOutputSample > 0);
  18894. const ScopedLock sl (ratioLock);
  18895. ratio = jmax (0.0, samplesInPerOutputSample);
  18896. }
  18897. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18898. double sampleRate)
  18899. {
  18900. const ScopedLock sl (ratioLock);
  18901. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18902. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18903. buffer.clear();
  18904. sampsInBuffer = 0;
  18905. bufferPos = 0;
  18906. subSampleOffset = 0.0;
  18907. createLowPass (ratio);
  18908. resetFilters();
  18909. }
  18910. void ResamplingAudioSource::releaseResources()
  18911. {
  18912. input->releaseResources();
  18913. buffer.setSize (2, 0);
  18914. }
  18915. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18916. {
  18917. const ScopedLock sl (ratioLock);
  18918. if (lastRatio != ratio)
  18919. {
  18920. createLowPass (ratio);
  18921. lastRatio = ratio;
  18922. }
  18923. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18924. int bufferSize = buffer.getNumSamples();
  18925. if (bufferSize < sampsNeeded + 8)
  18926. {
  18927. bufferPos %= bufferSize;
  18928. bufferSize = sampsNeeded + 32;
  18929. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18930. }
  18931. bufferPos %= bufferSize;
  18932. int endOfBufferPos = bufferPos + sampsInBuffer;
  18933. while (sampsNeeded > sampsInBuffer)
  18934. {
  18935. endOfBufferPos %= bufferSize;
  18936. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18937. bufferSize - endOfBufferPos);
  18938. AudioSourceChannelInfo readInfo;
  18939. readInfo.buffer = &buffer;
  18940. readInfo.numSamples = numToDo;
  18941. readInfo.startSample = endOfBufferPos;
  18942. input->getNextAudioBlock (readInfo);
  18943. if (ratio > 1.0001)
  18944. {
  18945. // for down-sampling, pre-apply the filter..
  18946. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18947. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18948. }
  18949. sampsInBuffer += numToDo;
  18950. endOfBufferPos += numToDo;
  18951. }
  18952. float* dl = info.buffer->getSampleData (0, info.startSample);
  18953. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18954. const float* const bl = buffer.getSampleData (0, 0);
  18955. const float* const br = buffer.getSampleData (1, 0);
  18956. int nextPos = (bufferPos + 1) % bufferSize;
  18957. for (int m = info.numSamples; --m >= 0;)
  18958. {
  18959. const float alpha = (float) subSampleOffset;
  18960. const float invAlpha = 1.0f - alpha;
  18961. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18962. if (dr != 0)
  18963. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  18964. subSampleOffset += ratio;
  18965. jassert (sampsInBuffer > 0);
  18966. while (subSampleOffset >= 1.0)
  18967. {
  18968. if (++bufferPos >= bufferSize)
  18969. bufferPos = 0;
  18970. --sampsInBuffer;
  18971. nextPos = (bufferPos + 1) % bufferSize;
  18972. subSampleOffset -= 1.0;
  18973. }
  18974. }
  18975. if (ratio < 0.9999)
  18976. {
  18977. // for up-sampling, apply the filter after transposing..
  18978. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18979. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  18980. }
  18981. else if (ratio <= 1.0001)
  18982. {
  18983. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  18984. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18985. {
  18986. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  18987. FilterState& fs = filterStates[i];
  18988. if (info.numSamples > 1)
  18989. {
  18990. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  18991. }
  18992. else
  18993. {
  18994. fs.y2 = fs.y1;
  18995. fs.x2 = fs.x1;
  18996. }
  18997. fs.y1 = fs.x1 = *endOfBuffer;
  18998. }
  18999. }
  19000. jassert (sampsInBuffer >= 0);
  19001. }
  19002. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19003. {
  19004. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19005. : 0.5 * frequencyRatio;
  19006. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19007. const double nSquared = n * n;
  19008. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19009. setFilterCoefficients (c1,
  19010. c1 * 2.0f,
  19011. c1,
  19012. 1.0,
  19013. c1 * 2.0 * (1.0 - nSquared),
  19014. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19015. }
  19016. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19017. {
  19018. const double a = 1.0 / c4;
  19019. c1 *= a;
  19020. c2 *= a;
  19021. c3 *= a;
  19022. c5 *= a;
  19023. c6 *= a;
  19024. coefficients[0] = c1;
  19025. coefficients[1] = c2;
  19026. coefficients[2] = c3;
  19027. coefficients[3] = c4;
  19028. coefficients[4] = c5;
  19029. coefficients[5] = c6;
  19030. }
  19031. void ResamplingAudioSource::resetFilters()
  19032. {
  19033. zeromem (filterStates, sizeof (filterStates));
  19034. }
  19035. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19036. {
  19037. while (--num >= 0)
  19038. {
  19039. const double in = *samples;
  19040. double out = coefficients[0] * in
  19041. + coefficients[1] * fs.x1
  19042. + coefficients[2] * fs.x2
  19043. - coefficients[4] * fs.y1
  19044. - coefficients[5] * fs.y2;
  19045. #if JUCE_INTEL
  19046. if (! (out < -1.0e-8 || out > 1.0e-8))
  19047. out = 0;
  19048. #endif
  19049. fs.x2 = fs.x1;
  19050. fs.x1 = in;
  19051. fs.y2 = fs.y1;
  19052. fs.y1 = out;
  19053. *samples++ = (float) out;
  19054. }
  19055. }
  19056. END_JUCE_NAMESPACE
  19057. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19058. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19059. BEGIN_JUCE_NAMESPACE
  19060. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19061. : frequency (1000.0),
  19062. sampleRate (44100.0),
  19063. currentPhase (0.0),
  19064. phasePerSample (0.0),
  19065. amplitude (0.5f)
  19066. {
  19067. }
  19068. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19069. {
  19070. }
  19071. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19072. {
  19073. amplitude = newAmplitude;
  19074. }
  19075. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19076. {
  19077. frequency = newFrequencyHz;
  19078. phasePerSample = 0.0;
  19079. }
  19080. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19081. double sampleRate_)
  19082. {
  19083. currentPhase = 0.0;
  19084. phasePerSample = 0.0;
  19085. sampleRate = sampleRate_;
  19086. }
  19087. void ToneGeneratorAudioSource::releaseResources()
  19088. {
  19089. }
  19090. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19091. {
  19092. if (phasePerSample == 0.0)
  19093. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19094. for (int i = 0; i < info.numSamples; ++i)
  19095. {
  19096. const float sample = amplitude * (float) sin (currentPhase);
  19097. currentPhase += phasePerSample;
  19098. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19099. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19100. }
  19101. }
  19102. END_JUCE_NAMESPACE
  19103. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19104. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19105. BEGIN_JUCE_NAMESPACE
  19106. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19107. : sampleRate (0),
  19108. bufferSize (0),
  19109. useDefaultInputChannels (true),
  19110. useDefaultOutputChannels (true)
  19111. {
  19112. }
  19113. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19114. {
  19115. return outputDeviceName == other.outputDeviceName
  19116. && inputDeviceName == other.inputDeviceName
  19117. && sampleRate == other.sampleRate
  19118. && bufferSize == other.bufferSize
  19119. && inputChannels == other.inputChannels
  19120. && useDefaultInputChannels == other.useDefaultInputChannels
  19121. && outputChannels == other.outputChannels
  19122. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19123. }
  19124. AudioDeviceManager::AudioDeviceManager()
  19125. : currentAudioDevice (0),
  19126. numInputChansNeeded (0),
  19127. numOutputChansNeeded (2),
  19128. listNeedsScanning (true),
  19129. useInputNames (false),
  19130. inputLevelMeasurementEnabledCount (0),
  19131. inputLevel (0),
  19132. tempBuffer (2, 2),
  19133. defaultMidiOutput (0),
  19134. cpuUsageMs (0),
  19135. timeToCpuScale (0)
  19136. {
  19137. callbackHandler.owner = this;
  19138. }
  19139. AudioDeviceManager::~AudioDeviceManager()
  19140. {
  19141. currentAudioDevice = 0;
  19142. defaultMidiOutput = 0;
  19143. }
  19144. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19145. {
  19146. if (availableDeviceTypes.size() == 0)
  19147. {
  19148. createAudioDeviceTypes (availableDeviceTypes);
  19149. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19150. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19151. if (availableDeviceTypes.size() > 0)
  19152. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19153. }
  19154. }
  19155. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19156. {
  19157. scanDevicesIfNeeded();
  19158. return availableDeviceTypes;
  19159. }
  19160. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19161. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19162. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19163. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19164. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19165. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19166. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19167. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19168. {
  19169. (void) list; // (to avoid 'unused param' warnings)
  19170. #if JUCE_WINDOWS
  19171. #if JUCE_WASAPI
  19172. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19173. list.add (juce_createAudioIODeviceType_WASAPI());
  19174. #endif
  19175. #if JUCE_DIRECTSOUND
  19176. list.add (juce_createAudioIODeviceType_DirectSound());
  19177. #endif
  19178. #if JUCE_ASIO
  19179. list.add (juce_createAudioIODeviceType_ASIO());
  19180. #endif
  19181. #endif
  19182. #if JUCE_MAC
  19183. list.add (juce_createAudioIODeviceType_CoreAudio());
  19184. #endif
  19185. #if JUCE_IPHONE
  19186. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19187. #endif
  19188. #if JUCE_LINUX && JUCE_ALSA
  19189. list.add (juce_createAudioIODeviceType_ALSA());
  19190. #endif
  19191. #if JUCE_LINUX && JUCE_JACK
  19192. list.add (juce_createAudioIODeviceType_JACK());
  19193. #endif
  19194. }
  19195. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19196. const int numOutputChannelsNeeded,
  19197. const XmlElement* const e,
  19198. const bool selectDefaultDeviceOnFailure,
  19199. const String& preferredDefaultDeviceName,
  19200. const AudioDeviceSetup* preferredSetupOptions)
  19201. {
  19202. scanDevicesIfNeeded();
  19203. numInputChansNeeded = numInputChannelsNeeded;
  19204. numOutputChansNeeded = numOutputChannelsNeeded;
  19205. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19206. {
  19207. lastExplicitSettings = new XmlElement (*e);
  19208. String error;
  19209. AudioDeviceSetup setup;
  19210. if (preferredSetupOptions != 0)
  19211. setup = *preferredSetupOptions;
  19212. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19213. {
  19214. setup.inputDeviceName = setup.outputDeviceName
  19215. = e->getStringAttribute ("audioDeviceName");
  19216. }
  19217. else
  19218. {
  19219. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19220. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19221. }
  19222. currentDeviceType = e->getStringAttribute ("deviceType");
  19223. if (currentDeviceType.isEmpty())
  19224. {
  19225. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19226. if (type != 0)
  19227. currentDeviceType = type->getTypeName();
  19228. else if (availableDeviceTypes.size() > 0)
  19229. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19230. }
  19231. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19232. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19233. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19234. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19235. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19236. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19237. error = setAudioDeviceSetup (setup, true);
  19238. midiInsFromXml.clear();
  19239. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19240. midiInsFromXml.add (c->getStringAttribute ("name"));
  19241. const StringArray allMidiIns (MidiInput::getDevices());
  19242. for (int i = allMidiIns.size(); --i >= 0;)
  19243. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19244. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19245. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19246. false, preferredDefaultDeviceName);
  19247. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19248. return error;
  19249. }
  19250. else
  19251. {
  19252. AudioDeviceSetup setup;
  19253. if (preferredSetupOptions != 0)
  19254. {
  19255. setup = *preferredSetupOptions;
  19256. }
  19257. else if (preferredDefaultDeviceName.isNotEmpty())
  19258. {
  19259. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19260. {
  19261. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19262. StringArray outs (type->getDeviceNames (false));
  19263. int i;
  19264. for (i = 0; i < outs.size(); ++i)
  19265. {
  19266. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19267. {
  19268. setup.outputDeviceName = outs[i];
  19269. break;
  19270. }
  19271. }
  19272. StringArray ins (type->getDeviceNames (true));
  19273. for (i = 0; i < ins.size(); ++i)
  19274. {
  19275. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19276. {
  19277. setup.inputDeviceName = ins[i];
  19278. break;
  19279. }
  19280. }
  19281. }
  19282. }
  19283. insertDefaultDeviceNames (setup);
  19284. return setAudioDeviceSetup (setup, false);
  19285. }
  19286. }
  19287. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19288. {
  19289. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19290. if (type != 0)
  19291. {
  19292. if (setup.outputDeviceName.isEmpty())
  19293. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19294. if (setup.inputDeviceName.isEmpty())
  19295. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19296. }
  19297. }
  19298. XmlElement* AudioDeviceManager::createStateXml() const
  19299. {
  19300. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19301. }
  19302. void AudioDeviceManager::scanDevicesIfNeeded()
  19303. {
  19304. if (listNeedsScanning)
  19305. {
  19306. listNeedsScanning = false;
  19307. createDeviceTypesIfNeeded();
  19308. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19309. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19310. }
  19311. }
  19312. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19313. {
  19314. scanDevicesIfNeeded();
  19315. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19316. {
  19317. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19318. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19319. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19320. {
  19321. return type;
  19322. }
  19323. }
  19324. return 0;
  19325. }
  19326. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19327. {
  19328. setup = currentSetup;
  19329. }
  19330. void AudioDeviceManager::deleteCurrentDevice()
  19331. {
  19332. currentAudioDevice = 0;
  19333. currentSetup.inputDeviceName = String::empty;
  19334. currentSetup.outputDeviceName = String::empty;
  19335. }
  19336. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19337. const bool treatAsChosenDevice)
  19338. {
  19339. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19340. {
  19341. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19342. && currentDeviceType != type)
  19343. {
  19344. currentDeviceType = type;
  19345. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19346. insertDefaultDeviceNames (s);
  19347. setAudioDeviceSetup (s, treatAsChosenDevice);
  19348. sendChangeMessage (this);
  19349. break;
  19350. }
  19351. }
  19352. }
  19353. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19354. {
  19355. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19356. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19357. return availableDeviceTypes[i];
  19358. return availableDeviceTypes[0];
  19359. }
  19360. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19361. const bool treatAsChosenDevice)
  19362. {
  19363. jassert (&newSetup != &currentSetup); // this will have no effect
  19364. if (newSetup == currentSetup && currentAudioDevice != 0)
  19365. return String::empty;
  19366. if (! (newSetup == currentSetup))
  19367. sendChangeMessage (this);
  19368. stopDevice();
  19369. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19370. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19371. String error;
  19372. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19373. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19374. {
  19375. deleteCurrentDevice();
  19376. if (treatAsChosenDevice)
  19377. updateXml();
  19378. return String::empty;
  19379. }
  19380. if (currentSetup.inputDeviceName != newInputDeviceName
  19381. || currentSetup.outputDeviceName != newOutputDeviceName
  19382. || currentAudioDevice == 0)
  19383. {
  19384. deleteCurrentDevice();
  19385. scanDevicesIfNeeded();
  19386. if (newOutputDeviceName.isNotEmpty()
  19387. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19388. {
  19389. return "No such device: " + newOutputDeviceName;
  19390. }
  19391. if (newInputDeviceName.isNotEmpty()
  19392. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19393. {
  19394. return "No such device: " + newInputDeviceName;
  19395. }
  19396. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19397. if (currentAudioDevice == 0)
  19398. 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!";
  19399. else
  19400. error = currentAudioDevice->getLastError();
  19401. if (error.isNotEmpty())
  19402. {
  19403. deleteCurrentDevice();
  19404. return error;
  19405. }
  19406. if (newSetup.useDefaultInputChannels)
  19407. {
  19408. inputChannels.clear();
  19409. inputChannels.setRange (0, numInputChansNeeded, true);
  19410. }
  19411. if (newSetup.useDefaultOutputChannels)
  19412. {
  19413. outputChannels.clear();
  19414. outputChannels.setRange (0, numOutputChansNeeded, true);
  19415. }
  19416. if (newInputDeviceName.isEmpty())
  19417. inputChannels.clear();
  19418. if (newOutputDeviceName.isEmpty())
  19419. outputChannels.clear();
  19420. }
  19421. if (! newSetup.useDefaultInputChannels)
  19422. inputChannels = newSetup.inputChannels;
  19423. if (! newSetup.useDefaultOutputChannels)
  19424. outputChannels = newSetup.outputChannels;
  19425. currentSetup = newSetup;
  19426. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19427. error = currentAudioDevice->open (inputChannels,
  19428. outputChannels,
  19429. currentSetup.sampleRate,
  19430. currentSetup.bufferSize);
  19431. if (error.isEmpty())
  19432. {
  19433. currentDeviceType = currentAudioDevice->getTypeName();
  19434. currentAudioDevice->start (&callbackHandler);
  19435. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19436. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19437. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19438. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19439. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19440. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19441. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19442. if (treatAsChosenDevice)
  19443. updateXml();
  19444. }
  19445. else
  19446. {
  19447. deleteCurrentDevice();
  19448. }
  19449. return error;
  19450. }
  19451. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19452. {
  19453. jassert (currentAudioDevice != 0);
  19454. if (rate > 0)
  19455. {
  19456. bool ok = false;
  19457. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19458. {
  19459. const double sr = currentAudioDevice->getSampleRate (i);
  19460. if (sr == rate)
  19461. ok = true;
  19462. }
  19463. if (! ok)
  19464. rate = 0;
  19465. }
  19466. if (rate == 0)
  19467. {
  19468. double lowestAbove44 = 0.0;
  19469. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19470. {
  19471. const double sr = currentAudioDevice->getSampleRate (i);
  19472. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19473. lowestAbove44 = sr;
  19474. }
  19475. if (lowestAbove44 == 0.0)
  19476. rate = currentAudioDevice->getSampleRate (0);
  19477. else
  19478. rate = lowestAbove44;
  19479. }
  19480. return rate;
  19481. }
  19482. void AudioDeviceManager::stopDevice()
  19483. {
  19484. if (currentAudioDevice != 0)
  19485. currentAudioDevice->stop();
  19486. testSound = 0;
  19487. }
  19488. void AudioDeviceManager::closeAudioDevice()
  19489. {
  19490. stopDevice();
  19491. currentAudioDevice = 0;
  19492. }
  19493. void AudioDeviceManager::restartLastAudioDevice()
  19494. {
  19495. if (currentAudioDevice == 0)
  19496. {
  19497. if (currentSetup.inputDeviceName.isEmpty()
  19498. && currentSetup.outputDeviceName.isEmpty())
  19499. {
  19500. // This method will only reload the last device that was running
  19501. // before closeAudioDevice() was called - you need to actually open
  19502. // one first, with setAudioDevice().
  19503. jassertfalse
  19504. return;
  19505. }
  19506. AudioDeviceSetup s (currentSetup);
  19507. setAudioDeviceSetup (s, false);
  19508. }
  19509. }
  19510. void AudioDeviceManager::updateXml()
  19511. {
  19512. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19513. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19514. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19515. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19516. if (currentAudioDevice != 0)
  19517. {
  19518. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19519. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19520. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19521. if (! currentSetup.useDefaultInputChannels)
  19522. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19523. if (! currentSetup.useDefaultOutputChannels)
  19524. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19525. }
  19526. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19527. {
  19528. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19529. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19530. }
  19531. if (midiInsFromXml.size() > 0)
  19532. {
  19533. // Add any midi devices that have been enabled before, but which aren't currently
  19534. // open because the device has been disconnected.
  19535. const StringArray availableMidiDevices (MidiInput::getDevices());
  19536. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19537. {
  19538. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19539. {
  19540. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19541. m->setAttribute ("name", midiInsFromXml[i]);
  19542. }
  19543. }
  19544. }
  19545. if (defaultMidiOutputName.isNotEmpty())
  19546. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19547. }
  19548. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19549. {
  19550. {
  19551. const ScopedLock sl (audioCallbackLock);
  19552. if (callbacks.contains (newCallback))
  19553. return;
  19554. }
  19555. if (currentAudioDevice != 0 && newCallback != 0)
  19556. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19557. const ScopedLock sl (audioCallbackLock);
  19558. callbacks.add (newCallback);
  19559. }
  19560. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19561. {
  19562. if (callback != 0)
  19563. {
  19564. bool needsDeinitialising = currentAudioDevice != 0;
  19565. {
  19566. const ScopedLock sl (audioCallbackLock);
  19567. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19568. callbacks.removeValue (callback);
  19569. }
  19570. if (needsDeinitialising)
  19571. callback->audioDeviceStopped();
  19572. }
  19573. }
  19574. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19575. int numInputChannels,
  19576. float** outputChannelData,
  19577. int numOutputChannels,
  19578. int numSamples)
  19579. {
  19580. const ScopedLock sl (audioCallbackLock);
  19581. if (inputLevelMeasurementEnabledCount > 0)
  19582. {
  19583. for (int j = 0; j < numSamples; ++j)
  19584. {
  19585. float s = 0;
  19586. for (int i = 0; i < numInputChannels; ++i)
  19587. s += fabsf (inputChannelData[i][j]);
  19588. s /= numInputChannels;
  19589. const double decayFactor = 0.99992;
  19590. if (s > inputLevel)
  19591. inputLevel = s;
  19592. else if (inputLevel > 0.001f)
  19593. inputLevel *= decayFactor;
  19594. else
  19595. inputLevel = 0;
  19596. }
  19597. }
  19598. if (callbacks.size() > 0)
  19599. {
  19600. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19601. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19602. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19603. outputChannelData, numOutputChannels, numSamples);
  19604. float** const tempChans = tempBuffer.getArrayOfChannels();
  19605. for (int i = callbacks.size(); --i > 0;)
  19606. {
  19607. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19608. tempChans, numOutputChannels, numSamples);
  19609. for (int chan = 0; chan < numOutputChannels; ++chan)
  19610. {
  19611. const float* const src = tempChans [chan];
  19612. float* const dst = outputChannelData [chan];
  19613. if (src != 0 && dst != 0)
  19614. for (int j = 0; j < numSamples; ++j)
  19615. dst[j] += src[j];
  19616. }
  19617. }
  19618. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19619. const double filterAmount = 0.2;
  19620. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19621. }
  19622. else
  19623. {
  19624. for (int i = 0; i < numOutputChannels; ++i)
  19625. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19626. }
  19627. if (testSound != 0)
  19628. {
  19629. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19630. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19631. for (int i = 0; i < numOutputChannels; ++i)
  19632. for (int j = 0; j < numSamps; ++j)
  19633. outputChannelData [i][j] += src[j];
  19634. testSoundPosition += numSamps;
  19635. if (testSoundPosition >= testSound->getNumSamples())
  19636. testSound = 0;
  19637. }
  19638. }
  19639. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19640. {
  19641. cpuUsageMs = 0;
  19642. const double sampleRate = device->getCurrentSampleRate();
  19643. const int blockSize = device->getCurrentBufferSizeSamples();
  19644. if (sampleRate > 0.0 && blockSize > 0)
  19645. {
  19646. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19647. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19648. }
  19649. {
  19650. const ScopedLock sl (audioCallbackLock);
  19651. for (int i = callbacks.size(); --i >= 0;)
  19652. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19653. }
  19654. sendChangeMessage (this);
  19655. }
  19656. void AudioDeviceManager::audioDeviceStoppedInt()
  19657. {
  19658. cpuUsageMs = 0;
  19659. timeToCpuScale = 0;
  19660. sendChangeMessage (this);
  19661. const ScopedLock sl (audioCallbackLock);
  19662. for (int i = callbacks.size(); --i >= 0;)
  19663. callbacks.getUnchecked(i)->audioDeviceStopped();
  19664. }
  19665. double AudioDeviceManager::getCpuUsage() const
  19666. {
  19667. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19668. }
  19669. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19670. const bool enabled)
  19671. {
  19672. if (enabled != isMidiInputEnabled (name))
  19673. {
  19674. if (enabled)
  19675. {
  19676. const int index = MidiInput::getDevices().indexOf (name);
  19677. if (index >= 0)
  19678. {
  19679. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19680. if (min != 0)
  19681. {
  19682. enabledMidiInputs.add (min);
  19683. min->start();
  19684. }
  19685. }
  19686. }
  19687. else
  19688. {
  19689. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19690. if (enabledMidiInputs[i]->getName() == name)
  19691. enabledMidiInputs.remove (i);
  19692. }
  19693. updateXml();
  19694. sendChangeMessage (this);
  19695. }
  19696. }
  19697. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19698. {
  19699. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19700. if (enabledMidiInputs[i]->getName() == name)
  19701. return true;
  19702. return false;
  19703. }
  19704. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19705. MidiInputCallback* callback)
  19706. {
  19707. removeMidiInputCallback (name, callback);
  19708. if (name.isEmpty())
  19709. {
  19710. midiCallbacks.add (callback);
  19711. midiCallbackDevices.add (0);
  19712. }
  19713. else
  19714. {
  19715. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19716. {
  19717. if (enabledMidiInputs[i]->getName() == name)
  19718. {
  19719. const ScopedLock sl (midiCallbackLock);
  19720. midiCallbacks.add (callback);
  19721. midiCallbackDevices.add (enabledMidiInputs[i]);
  19722. break;
  19723. }
  19724. }
  19725. }
  19726. }
  19727. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19728. MidiInputCallback* /*callback*/)
  19729. {
  19730. const ScopedLock sl (midiCallbackLock);
  19731. for (int i = midiCallbacks.size(); --i >= 0;)
  19732. {
  19733. String devName;
  19734. if (midiCallbackDevices.getUnchecked(i) != 0)
  19735. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19736. if (devName == name)
  19737. {
  19738. midiCallbacks.remove (i);
  19739. midiCallbackDevices.remove (i);
  19740. }
  19741. }
  19742. }
  19743. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19744. const MidiMessage& message)
  19745. {
  19746. if (! message.isActiveSense())
  19747. {
  19748. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19749. const ScopedLock sl (midiCallbackLock);
  19750. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19751. {
  19752. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19753. if (md == source || (md == 0 && isDefaultSource))
  19754. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19755. }
  19756. }
  19757. }
  19758. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19759. {
  19760. if (defaultMidiOutputName != deviceName)
  19761. {
  19762. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19763. {
  19764. const ScopedLock sl (audioCallbackLock);
  19765. oldCallbacks = callbacks;
  19766. callbacks.clear();
  19767. }
  19768. if (currentAudioDevice != 0)
  19769. for (int i = oldCallbacks.size(); --i >= 0;)
  19770. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19771. defaultMidiOutput = 0;
  19772. defaultMidiOutputName = deviceName;
  19773. if (deviceName.isNotEmpty())
  19774. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19775. if (currentAudioDevice != 0)
  19776. for (int i = oldCallbacks.size(); --i >= 0;)
  19777. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19778. {
  19779. const ScopedLock sl (audioCallbackLock);
  19780. callbacks = oldCallbacks;
  19781. }
  19782. updateXml();
  19783. sendChangeMessage (this);
  19784. }
  19785. }
  19786. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19787. int numInputChannels,
  19788. float** outputChannelData,
  19789. int numOutputChannels,
  19790. int numSamples)
  19791. {
  19792. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19793. }
  19794. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19795. {
  19796. owner->audioDeviceAboutToStartInt (device);
  19797. }
  19798. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19799. {
  19800. owner->audioDeviceStoppedInt();
  19801. }
  19802. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19803. {
  19804. owner->handleIncomingMidiMessageInt (source, message);
  19805. }
  19806. void AudioDeviceManager::playTestSound()
  19807. {
  19808. { // cunningly nested to swap, unlock and delete in that order.
  19809. ScopedPointer <AudioSampleBuffer> oldSound;
  19810. {
  19811. const ScopedLock sl (audioCallbackLock);
  19812. oldSound = testSound;
  19813. }
  19814. }
  19815. testSoundPosition = 0;
  19816. if (currentAudioDevice != 0)
  19817. {
  19818. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19819. const int soundLength = (int) sampleRate;
  19820. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19821. float* samples = newSound->getSampleData (0);
  19822. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19823. const float amplitude = 0.5f;
  19824. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19825. for (int i = 0; i < soundLength; ++i)
  19826. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19827. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19828. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19829. const ScopedLock sl (audioCallbackLock);
  19830. testSound = newSound;
  19831. }
  19832. }
  19833. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19834. {
  19835. const ScopedLock sl (audioCallbackLock);
  19836. if (enableMeasurement)
  19837. ++inputLevelMeasurementEnabledCount;
  19838. else
  19839. --inputLevelMeasurementEnabledCount;
  19840. inputLevel = 0;
  19841. }
  19842. double AudioDeviceManager::getCurrentInputLevel() const
  19843. {
  19844. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19845. return inputLevel;
  19846. }
  19847. END_JUCE_NAMESPACE
  19848. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19849. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19850. BEGIN_JUCE_NAMESPACE
  19851. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19852. : name (deviceName),
  19853. typeName (typeName_)
  19854. {
  19855. }
  19856. AudioIODevice::~AudioIODevice()
  19857. {
  19858. }
  19859. bool AudioIODevice::hasControlPanel() const
  19860. {
  19861. return false;
  19862. }
  19863. bool AudioIODevice::showControlPanel()
  19864. {
  19865. jassertfalse // this should only be called for devices which return true from
  19866. // their hasControlPanel() method.
  19867. return false;
  19868. }
  19869. END_JUCE_NAMESPACE
  19870. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19871. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19872. BEGIN_JUCE_NAMESPACE
  19873. AudioIODeviceType::AudioIODeviceType (const String& name)
  19874. : typeName (name)
  19875. {
  19876. }
  19877. AudioIODeviceType::~AudioIODeviceType()
  19878. {
  19879. }
  19880. END_JUCE_NAMESPACE
  19881. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19882. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19883. BEGIN_JUCE_NAMESPACE
  19884. MidiOutput::MidiOutput()
  19885. : Thread ("midi out"),
  19886. internal (0),
  19887. firstMessage (0)
  19888. {
  19889. }
  19890. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19891. const double sampleNumber)
  19892. : message (data, len, sampleNumber)
  19893. {
  19894. }
  19895. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19896. const double millisecondCounterToStartAt,
  19897. double samplesPerSecondForBuffer)
  19898. {
  19899. // You've got to call startBackgroundThread() for this to actually work..
  19900. jassert (isThreadRunning());
  19901. // this needs to be a value in the future - RTFM for this method!
  19902. jassert (millisecondCounterToStartAt > 0);
  19903. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19904. MidiBuffer::Iterator i (buffer);
  19905. const uint8* data;
  19906. int len, time;
  19907. while (i.getNextEvent (data, len, time))
  19908. {
  19909. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19910. PendingMessage* const m
  19911. = new PendingMessage (data, len, eventTime);
  19912. const ScopedLock sl (lock);
  19913. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19914. {
  19915. m->next = firstMessage;
  19916. firstMessage = m;
  19917. }
  19918. else
  19919. {
  19920. PendingMessage* mm = firstMessage;
  19921. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19922. mm = mm->next;
  19923. m->next = mm->next;
  19924. mm->next = m;
  19925. }
  19926. }
  19927. notify();
  19928. }
  19929. void MidiOutput::clearAllPendingMessages()
  19930. {
  19931. const ScopedLock sl (lock);
  19932. while (firstMessage != 0)
  19933. {
  19934. PendingMessage* const m = firstMessage;
  19935. firstMessage = firstMessage->next;
  19936. delete m;
  19937. }
  19938. }
  19939. void MidiOutput::startBackgroundThread()
  19940. {
  19941. startThread (9);
  19942. }
  19943. void MidiOutput::stopBackgroundThread()
  19944. {
  19945. stopThread (5000);
  19946. }
  19947. void MidiOutput::run()
  19948. {
  19949. while (! threadShouldExit())
  19950. {
  19951. uint32 now = Time::getMillisecondCounter();
  19952. uint32 eventTime = 0;
  19953. uint32 timeToWait = 500;
  19954. PendingMessage* message;
  19955. {
  19956. const ScopedLock sl (lock);
  19957. message = firstMessage;
  19958. if (message != 0)
  19959. {
  19960. eventTime = roundToInt (message->message.getTimeStamp());
  19961. if (eventTime > now + 20)
  19962. {
  19963. timeToWait = eventTime - (now + 20);
  19964. message = 0;
  19965. }
  19966. else
  19967. {
  19968. firstMessage = message->next;
  19969. }
  19970. }
  19971. }
  19972. if (message != 0)
  19973. {
  19974. if (eventTime > now)
  19975. {
  19976. Time::waitForMillisecondCounter (eventTime);
  19977. if (threadShouldExit())
  19978. break;
  19979. }
  19980. if (eventTime > now - 200)
  19981. sendMessageNow (message->message);
  19982. delete message;
  19983. }
  19984. else
  19985. {
  19986. jassert (timeToWait < 1000 * 30);
  19987. wait (timeToWait);
  19988. }
  19989. }
  19990. clearAllPendingMessages();
  19991. }
  19992. END_JUCE_NAMESPACE
  19993. /*** End of inlined file: juce_MidiOutput.cpp ***/
  19994. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  19995. BEGIN_JUCE_NAMESPACE
  19996. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19997. {
  19998. const double maxVal = (double) 0x7fff;
  19999. char* intData = static_cast <char*> (dest);
  20000. if (dest != (void*) source || destBytesPerSample <= 4)
  20001. {
  20002. for (int i = 0; i < numSamples; ++i)
  20003. {
  20004. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20005. intData += destBytesPerSample;
  20006. }
  20007. }
  20008. else
  20009. {
  20010. intData += destBytesPerSample * numSamples;
  20011. for (int i = numSamples; --i >= 0;)
  20012. {
  20013. intData -= destBytesPerSample;
  20014. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20015. }
  20016. }
  20017. }
  20018. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20019. {
  20020. const double maxVal = (double) 0x7fff;
  20021. char* intData = static_cast <char*> (dest);
  20022. if (dest != (void*) source || destBytesPerSample <= 4)
  20023. {
  20024. for (int i = 0; i < numSamples; ++i)
  20025. {
  20026. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20027. intData += destBytesPerSample;
  20028. }
  20029. }
  20030. else
  20031. {
  20032. intData += destBytesPerSample * numSamples;
  20033. for (int i = numSamples; --i >= 0;)
  20034. {
  20035. intData -= destBytesPerSample;
  20036. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20037. }
  20038. }
  20039. }
  20040. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20041. {
  20042. const double maxVal = (double) 0x7fffff;
  20043. char* intData = static_cast <char*> (dest);
  20044. if (dest != (void*) source || destBytesPerSample <= 4)
  20045. {
  20046. for (int i = 0; i < numSamples; ++i)
  20047. {
  20048. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20049. intData += destBytesPerSample;
  20050. }
  20051. }
  20052. else
  20053. {
  20054. intData += destBytesPerSample * numSamples;
  20055. for (int i = numSamples; --i >= 0;)
  20056. {
  20057. intData -= destBytesPerSample;
  20058. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20059. }
  20060. }
  20061. }
  20062. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20063. {
  20064. const double maxVal = (double) 0x7fffff;
  20065. char* intData = static_cast <char*> (dest);
  20066. if (dest != (void*) source || destBytesPerSample <= 4)
  20067. {
  20068. for (int i = 0; i < numSamples; ++i)
  20069. {
  20070. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20071. intData += destBytesPerSample;
  20072. }
  20073. }
  20074. else
  20075. {
  20076. intData += destBytesPerSample * numSamples;
  20077. for (int i = numSamples; --i >= 0;)
  20078. {
  20079. intData -= destBytesPerSample;
  20080. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20081. }
  20082. }
  20083. }
  20084. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20085. {
  20086. const double maxVal = (double) 0x7fffffff;
  20087. char* intData = static_cast <char*> (dest);
  20088. if (dest != (void*) source || destBytesPerSample <= 4)
  20089. {
  20090. for (int i = 0; i < numSamples; ++i)
  20091. {
  20092. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20093. intData += destBytesPerSample;
  20094. }
  20095. }
  20096. else
  20097. {
  20098. intData += destBytesPerSample * numSamples;
  20099. for (int i = numSamples; --i >= 0;)
  20100. {
  20101. intData -= destBytesPerSample;
  20102. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20103. }
  20104. }
  20105. }
  20106. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20107. {
  20108. const double maxVal = (double) 0x7fffffff;
  20109. char* intData = static_cast <char*> (dest);
  20110. if (dest != (void*) source || destBytesPerSample <= 4)
  20111. {
  20112. for (int i = 0; i < numSamples; ++i)
  20113. {
  20114. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20115. intData += destBytesPerSample;
  20116. }
  20117. }
  20118. else
  20119. {
  20120. intData += destBytesPerSample * numSamples;
  20121. for (int i = numSamples; --i >= 0;)
  20122. {
  20123. intData -= destBytesPerSample;
  20124. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20125. }
  20126. }
  20127. }
  20128. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20129. {
  20130. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20131. char* d = static_cast <char*> (dest);
  20132. for (int i = 0; i < numSamples; ++i)
  20133. {
  20134. *(float*) d = source[i];
  20135. #if JUCE_BIG_ENDIAN
  20136. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20137. #endif
  20138. d += destBytesPerSample;
  20139. }
  20140. }
  20141. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20142. {
  20143. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20144. char* d = static_cast <char*> (dest);
  20145. for (int i = 0; i < numSamples; ++i)
  20146. {
  20147. *(float*) d = source[i];
  20148. #if JUCE_LITTLE_ENDIAN
  20149. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20150. #endif
  20151. d += destBytesPerSample;
  20152. }
  20153. }
  20154. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20155. {
  20156. const float scale = 1.0f / 0x7fff;
  20157. const char* intData = static_cast <const char*> (source);
  20158. if (source != (void*) dest || srcBytesPerSample >= 4)
  20159. {
  20160. for (int i = 0; i < numSamples; ++i)
  20161. {
  20162. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20163. intData += srcBytesPerSample;
  20164. }
  20165. }
  20166. else
  20167. {
  20168. intData += srcBytesPerSample * numSamples;
  20169. for (int i = numSamples; --i >= 0;)
  20170. {
  20171. intData -= srcBytesPerSample;
  20172. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20173. }
  20174. }
  20175. }
  20176. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20177. {
  20178. const float scale = 1.0f / 0x7fff;
  20179. const char* intData = static_cast <const char*> (source);
  20180. if (source != (void*) dest || srcBytesPerSample >= 4)
  20181. {
  20182. for (int i = 0; i < numSamples; ++i)
  20183. {
  20184. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20185. intData += srcBytesPerSample;
  20186. }
  20187. }
  20188. else
  20189. {
  20190. intData += srcBytesPerSample * numSamples;
  20191. for (int i = numSamples; --i >= 0;)
  20192. {
  20193. intData -= srcBytesPerSample;
  20194. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20195. }
  20196. }
  20197. }
  20198. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20199. {
  20200. const float scale = 1.0f / 0x7fffff;
  20201. const char* intData = static_cast <const char*> (source);
  20202. if (source != (void*) dest || srcBytesPerSample >= 4)
  20203. {
  20204. for (int i = 0; i < numSamples; ++i)
  20205. {
  20206. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20207. intData += srcBytesPerSample;
  20208. }
  20209. }
  20210. else
  20211. {
  20212. intData += srcBytesPerSample * numSamples;
  20213. for (int i = numSamples; --i >= 0;)
  20214. {
  20215. intData -= srcBytesPerSample;
  20216. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20217. }
  20218. }
  20219. }
  20220. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20221. {
  20222. const float scale = 1.0f / 0x7fffff;
  20223. const char* intData = static_cast <const char*> (source);
  20224. if (source != (void*) dest || srcBytesPerSample >= 4)
  20225. {
  20226. for (int i = 0; i < numSamples; ++i)
  20227. {
  20228. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20229. intData += srcBytesPerSample;
  20230. }
  20231. }
  20232. else
  20233. {
  20234. intData += srcBytesPerSample * numSamples;
  20235. for (int i = numSamples; --i >= 0;)
  20236. {
  20237. intData -= srcBytesPerSample;
  20238. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20239. }
  20240. }
  20241. }
  20242. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20243. {
  20244. const float scale = 1.0f / 0x7fffffff;
  20245. const char* intData = static_cast <const char*> (source);
  20246. if (source != (void*) dest || srcBytesPerSample >= 4)
  20247. {
  20248. for (int i = 0; i < numSamples; ++i)
  20249. {
  20250. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20251. intData += srcBytesPerSample;
  20252. }
  20253. }
  20254. else
  20255. {
  20256. intData += srcBytesPerSample * numSamples;
  20257. for (int i = numSamples; --i >= 0;)
  20258. {
  20259. intData -= srcBytesPerSample;
  20260. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20261. }
  20262. }
  20263. }
  20264. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20265. {
  20266. const float scale = 1.0f / 0x7fffffff;
  20267. const char* intData = static_cast <const char*> (source);
  20268. if (source != (void*) dest || srcBytesPerSample >= 4)
  20269. {
  20270. for (int i = 0; i < numSamples; ++i)
  20271. {
  20272. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20273. intData += srcBytesPerSample;
  20274. }
  20275. }
  20276. else
  20277. {
  20278. intData += srcBytesPerSample * numSamples;
  20279. for (int i = numSamples; --i >= 0;)
  20280. {
  20281. intData -= srcBytesPerSample;
  20282. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20283. }
  20284. }
  20285. }
  20286. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20287. {
  20288. const char* s = static_cast <const char*> (source);
  20289. for (int i = 0; i < numSamples; ++i)
  20290. {
  20291. dest[i] = *(float*)s;
  20292. #if JUCE_BIG_ENDIAN
  20293. uint32* const d = (uint32*) (dest + i);
  20294. *d = ByteOrder::swap (*d);
  20295. #endif
  20296. s += srcBytesPerSample;
  20297. }
  20298. }
  20299. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20300. {
  20301. const char* s = static_cast <const char*> (source);
  20302. for (int i = 0; i < numSamples; ++i)
  20303. {
  20304. dest[i] = *(float*)s;
  20305. #if JUCE_LITTLE_ENDIAN
  20306. uint32* const d = (uint32*) (dest + i);
  20307. *d = ByteOrder::swap (*d);
  20308. #endif
  20309. s += srcBytesPerSample;
  20310. }
  20311. }
  20312. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20313. const float* const source,
  20314. void* const dest,
  20315. const int numSamples)
  20316. {
  20317. switch (destFormat)
  20318. {
  20319. case int16LE:
  20320. convertFloatToInt16LE (source, dest, numSamples);
  20321. break;
  20322. case int16BE:
  20323. convertFloatToInt16BE (source, dest, numSamples);
  20324. break;
  20325. case int24LE:
  20326. convertFloatToInt24LE (source, dest, numSamples);
  20327. break;
  20328. case int24BE:
  20329. convertFloatToInt24BE (source, dest, numSamples);
  20330. break;
  20331. case int32LE:
  20332. convertFloatToInt32LE (source, dest, numSamples);
  20333. break;
  20334. case int32BE:
  20335. convertFloatToInt32BE (source, dest, numSamples);
  20336. break;
  20337. case float32LE:
  20338. convertFloatToFloat32LE (source, dest, numSamples);
  20339. break;
  20340. case float32BE:
  20341. convertFloatToFloat32BE (source, dest, numSamples);
  20342. break;
  20343. default:
  20344. jassertfalse
  20345. break;
  20346. }
  20347. }
  20348. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20349. const void* const source,
  20350. float* const dest,
  20351. const int numSamples)
  20352. {
  20353. switch (sourceFormat)
  20354. {
  20355. case int16LE:
  20356. convertInt16LEToFloat (source, dest, numSamples);
  20357. break;
  20358. case int16BE:
  20359. convertInt16BEToFloat (source, dest, numSamples);
  20360. break;
  20361. case int24LE:
  20362. convertInt24LEToFloat (source, dest, numSamples);
  20363. break;
  20364. case int24BE:
  20365. convertInt24BEToFloat (source, dest, numSamples);
  20366. break;
  20367. case int32LE:
  20368. convertInt32LEToFloat (source, dest, numSamples);
  20369. break;
  20370. case int32BE:
  20371. convertInt32BEToFloat (source, dest, numSamples);
  20372. break;
  20373. case float32LE:
  20374. convertFloat32LEToFloat (source, dest, numSamples);
  20375. break;
  20376. case float32BE:
  20377. convertFloat32BEToFloat (source, dest, numSamples);
  20378. break;
  20379. default:
  20380. jassertfalse
  20381. break;
  20382. }
  20383. }
  20384. void AudioDataConverters::interleaveSamples (const float** const source,
  20385. float* const dest,
  20386. const int numSamples,
  20387. const int numChannels)
  20388. {
  20389. for (int chan = 0; chan < numChannels; ++chan)
  20390. {
  20391. int i = chan;
  20392. const float* src = source [chan];
  20393. for (int j = 0; j < numSamples; ++j)
  20394. {
  20395. dest [i] = src [j];
  20396. i += numChannels;
  20397. }
  20398. }
  20399. }
  20400. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20401. float** const dest,
  20402. const int numSamples,
  20403. const int numChannels)
  20404. {
  20405. for (int chan = 0; chan < numChannels; ++chan)
  20406. {
  20407. int i = chan;
  20408. float* dst = dest [chan];
  20409. for (int j = 0; j < numSamples; ++j)
  20410. {
  20411. dst [j] = source [i];
  20412. i += numChannels;
  20413. }
  20414. }
  20415. }
  20416. END_JUCE_NAMESPACE
  20417. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20418. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20419. BEGIN_JUCE_NAMESPACE
  20420. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20421. const int numSamples) throw()
  20422. : numChannels (numChannels_),
  20423. size (numSamples)
  20424. {
  20425. jassert (numSamples >= 0);
  20426. jassert (numChannels_ > 0);
  20427. allocateData();
  20428. }
  20429. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20430. : numChannels (other.numChannels),
  20431. size (other.size)
  20432. {
  20433. allocateData();
  20434. const size_t numBytes = size * sizeof (float);
  20435. for (int i = 0; i < numChannels; ++i)
  20436. memcpy (channels[i], other.channels[i], numBytes);
  20437. }
  20438. void AudioSampleBuffer::allocateData()
  20439. {
  20440. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20441. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20442. allocatedData.malloc (allocatedBytes);
  20443. channels = reinterpret_cast <float**> (allocatedData.getData());
  20444. float* chan = (float*) (allocatedData + channelListSize);
  20445. for (int i = 0; i < numChannels; ++i)
  20446. {
  20447. channels[i] = chan;
  20448. chan += size;
  20449. }
  20450. channels [numChannels] = 0;
  20451. }
  20452. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20453. const int numChannels_,
  20454. const int numSamples) throw()
  20455. : numChannels (numChannels_),
  20456. size (numSamples),
  20457. allocatedBytes (0)
  20458. {
  20459. jassert (numChannels_ > 0);
  20460. allocateChannels (dataToReferTo);
  20461. }
  20462. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20463. const int newNumChannels,
  20464. const int newNumSamples) throw()
  20465. {
  20466. jassert (newNumChannels > 0);
  20467. allocatedBytes = 0;
  20468. allocatedData.free();
  20469. numChannels = newNumChannels;
  20470. size = newNumSamples;
  20471. allocateChannels (dataToReferTo);
  20472. }
  20473. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20474. {
  20475. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20476. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20477. {
  20478. channels = static_cast <float**> (preallocatedChannelSpace);
  20479. }
  20480. else
  20481. {
  20482. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20483. channels = reinterpret_cast <float**> (allocatedData.getData());
  20484. }
  20485. for (int i = 0; i < numChannels; ++i)
  20486. {
  20487. // you have to pass in the same number of valid pointers as numChannels
  20488. jassert (dataToReferTo[i] != 0);
  20489. channels[i] = dataToReferTo[i];
  20490. }
  20491. channels [numChannels] = 0;
  20492. }
  20493. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20494. {
  20495. if (this != &other)
  20496. {
  20497. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  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. return *this;
  20503. }
  20504. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20505. {
  20506. }
  20507. void AudioSampleBuffer::setSize (const int newNumChannels,
  20508. const int newNumSamples,
  20509. const bool keepExistingContent,
  20510. const bool clearExtraSpace,
  20511. const bool avoidReallocating) throw()
  20512. {
  20513. jassert (newNumChannels > 0);
  20514. if (newNumSamples != size || newNumChannels != numChannels)
  20515. {
  20516. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20517. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20518. if (keepExistingContent)
  20519. {
  20520. HeapBlock <char> newData;
  20521. newData.allocate (newTotalBytes, clearExtraSpace);
  20522. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20523. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20524. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20525. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20526. for (int i = 0; i < numChansToCopy; ++i)
  20527. {
  20528. memcpy (newChan, channels[i], numBytesToCopy);
  20529. newChannels[i] = newChan;
  20530. newChan += newNumSamples;
  20531. }
  20532. allocatedData.swapWith (newData);
  20533. allocatedBytes = (int) newTotalBytes;
  20534. channels = newChannels;
  20535. }
  20536. else
  20537. {
  20538. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20539. {
  20540. if (clearExtraSpace)
  20541. zeromem (allocatedData, newTotalBytes);
  20542. }
  20543. else
  20544. {
  20545. allocatedBytes = newTotalBytes;
  20546. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20547. channels = reinterpret_cast <float**> (allocatedData.getData());
  20548. }
  20549. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20550. for (int i = 0; i < newNumChannels; ++i)
  20551. {
  20552. channels[i] = chan;
  20553. chan += newNumSamples;
  20554. }
  20555. }
  20556. channels [newNumChannels] = 0;
  20557. size = newNumSamples;
  20558. numChannels = newNumChannels;
  20559. }
  20560. }
  20561. void AudioSampleBuffer::clear() throw()
  20562. {
  20563. for (int i = 0; i < numChannels; ++i)
  20564. zeromem (channels[i], size * sizeof (float));
  20565. }
  20566. void AudioSampleBuffer::clear (const int startSample,
  20567. const int numSamples) throw()
  20568. {
  20569. jassert (startSample >= 0 && startSample + numSamples <= size);
  20570. for (int i = 0; i < numChannels; ++i)
  20571. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20572. }
  20573. void AudioSampleBuffer::clear (const int channel,
  20574. const int startSample,
  20575. const int numSamples) throw()
  20576. {
  20577. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20578. jassert (startSample >= 0 && startSample + numSamples <= size);
  20579. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20580. }
  20581. void AudioSampleBuffer::applyGain (const int channel,
  20582. const int startSample,
  20583. int numSamples,
  20584. const float gain) throw()
  20585. {
  20586. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20587. jassert (startSample >= 0 && startSample + numSamples <= size);
  20588. if (gain != 1.0f)
  20589. {
  20590. float* d = channels [channel] + startSample;
  20591. if (gain == 0.0f)
  20592. {
  20593. zeromem (d, sizeof (float) * numSamples);
  20594. }
  20595. else
  20596. {
  20597. while (--numSamples >= 0)
  20598. *d++ *= gain;
  20599. }
  20600. }
  20601. }
  20602. void AudioSampleBuffer::applyGainRamp (const int channel,
  20603. const int startSample,
  20604. int numSamples,
  20605. float startGain,
  20606. float endGain) throw()
  20607. {
  20608. if (startGain == endGain)
  20609. {
  20610. applyGain (channel, startSample, numSamples, startGain);
  20611. }
  20612. else
  20613. {
  20614. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20615. jassert (startSample >= 0 && startSample + numSamples <= size);
  20616. const float increment = (endGain - startGain) / numSamples;
  20617. float* d = channels [channel] + startSample;
  20618. while (--numSamples >= 0)
  20619. {
  20620. *d++ *= startGain;
  20621. startGain += increment;
  20622. }
  20623. }
  20624. }
  20625. void AudioSampleBuffer::applyGain (const int startSample,
  20626. const int numSamples,
  20627. const float gain) throw()
  20628. {
  20629. for (int i = 0; i < numChannels; ++i)
  20630. applyGain (i, startSample, numSamples, gain);
  20631. }
  20632. void AudioSampleBuffer::addFrom (const int destChannel,
  20633. const int destStartSample,
  20634. const AudioSampleBuffer& source,
  20635. const int sourceChannel,
  20636. const int sourceStartSample,
  20637. int numSamples,
  20638. const float gain) throw()
  20639. {
  20640. jassert (&source != this || sourceChannel != destChannel);
  20641. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20642. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20643. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20644. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20645. if (gain != 0.0f && numSamples > 0)
  20646. {
  20647. float* d = channels [destChannel] + destStartSample;
  20648. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20649. if (gain != 1.0f)
  20650. {
  20651. while (--numSamples >= 0)
  20652. *d++ += gain * *s++;
  20653. }
  20654. else
  20655. {
  20656. while (--numSamples >= 0)
  20657. *d++ += *s++;
  20658. }
  20659. }
  20660. }
  20661. void AudioSampleBuffer::addFrom (const int destChannel,
  20662. const int destStartSample,
  20663. const float* source,
  20664. int numSamples,
  20665. const float gain) throw()
  20666. {
  20667. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20668. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20669. jassert (source != 0);
  20670. if (gain != 0.0f && numSamples > 0)
  20671. {
  20672. float* d = channels [destChannel] + destStartSample;
  20673. if (gain != 1.0f)
  20674. {
  20675. while (--numSamples >= 0)
  20676. *d++ += gain * *source++;
  20677. }
  20678. else
  20679. {
  20680. while (--numSamples >= 0)
  20681. *d++ += *source++;
  20682. }
  20683. }
  20684. }
  20685. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20686. const int destStartSample,
  20687. const float* source,
  20688. int numSamples,
  20689. float startGain,
  20690. const float endGain) throw()
  20691. {
  20692. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20693. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20694. jassert (source != 0);
  20695. if (startGain == endGain)
  20696. {
  20697. addFrom (destChannel,
  20698. destStartSample,
  20699. source,
  20700. numSamples,
  20701. startGain);
  20702. }
  20703. else
  20704. {
  20705. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20706. {
  20707. const float increment = (endGain - startGain) / numSamples;
  20708. float* d = channels [destChannel] + destStartSample;
  20709. while (--numSamples >= 0)
  20710. {
  20711. *d++ += startGain * *source++;
  20712. startGain += increment;
  20713. }
  20714. }
  20715. }
  20716. }
  20717. void AudioSampleBuffer::copyFrom (const int destChannel,
  20718. const int destStartSample,
  20719. const AudioSampleBuffer& source,
  20720. const int sourceChannel,
  20721. const int sourceStartSample,
  20722. int numSamples) throw()
  20723. {
  20724. jassert (&source != this || sourceChannel != destChannel);
  20725. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20726. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20727. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20728. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20729. if (numSamples > 0)
  20730. {
  20731. memcpy (channels [destChannel] + destStartSample,
  20732. source.channels [sourceChannel] + sourceStartSample,
  20733. sizeof (float) * numSamples);
  20734. }
  20735. }
  20736. void AudioSampleBuffer::copyFrom (const int destChannel,
  20737. const int destStartSample,
  20738. const float* source,
  20739. int numSamples) throw()
  20740. {
  20741. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20742. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20743. jassert (source != 0);
  20744. if (numSamples > 0)
  20745. {
  20746. memcpy (channels [destChannel] + destStartSample,
  20747. source,
  20748. sizeof (float) * numSamples);
  20749. }
  20750. }
  20751. void AudioSampleBuffer::copyFrom (const int destChannel,
  20752. const int destStartSample,
  20753. const float* source,
  20754. int numSamples,
  20755. const float gain) throw()
  20756. {
  20757. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20758. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20759. jassert (source != 0);
  20760. if (numSamples > 0)
  20761. {
  20762. float* d = channels [destChannel] + destStartSample;
  20763. if (gain != 1.0f)
  20764. {
  20765. if (gain == 0)
  20766. {
  20767. zeromem (d, sizeof (float) * numSamples);
  20768. }
  20769. else
  20770. {
  20771. while (--numSamples >= 0)
  20772. *d++ = gain * *source++;
  20773. }
  20774. }
  20775. else
  20776. {
  20777. memcpy (d, source, sizeof (float) * numSamples);
  20778. }
  20779. }
  20780. }
  20781. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20782. const int destStartSample,
  20783. const float* source,
  20784. int numSamples,
  20785. float startGain,
  20786. float endGain) throw()
  20787. {
  20788. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20789. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20790. jassert (source != 0);
  20791. if (startGain == endGain)
  20792. {
  20793. copyFrom (destChannel,
  20794. destStartSample,
  20795. source,
  20796. numSamples,
  20797. startGain);
  20798. }
  20799. else
  20800. {
  20801. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20802. {
  20803. const float increment = (endGain - startGain) / numSamples;
  20804. float* d = channels [destChannel] + destStartSample;
  20805. while (--numSamples >= 0)
  20806. {
  20807. *d++ = startGain * *source++;
  20808. startGain += increment;
  20809. }
  20810. }
  20811. }
  20812. }
  20813. void AudioSampleBuffer::findMinMax (const int channel,
  20814. const int startSample,
  20815. int numSamples,
  20816. float& minVal,
  20817. float& maxVal) const throw()
  20818. {
  20819. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20820. jassert (startSample >= 0 && startSample + numSamples <= size);
  20821. if (numSamples <= 0)
  20822. {
  20823. minVal = 0.0f;
  20824. maxVal = 0.0f;
  20825. }
  20826. else
  20827. {
  20828. const float* d = channels [channel] + startSample;
  20829. float mn = *d++;
  20830. float mx = mn;
  20831. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20832. {
  20833. const float samp = *d++;
  20834. if (samp > mx)
  20835. mx = samp;
  20836. if (samp < mn)
  20837. mn = samp;
  20838. }
  20839. maxVal = mx;
  20840. minVal = mn;
  20841. }
  20842. }
  20843. float AudioSampleBuffer::getMagnitude (const int channel,
  20844. const int startSample,
  20845. const int numSamples) const throw()
  20846. {
  20847. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20848. jassert (startSample >= 0 && startSample + numSamples <= size);
  20849. float mn, mx;
  20850. findMinMax (channel, startSample, numSamples, mn, mx);
  20851. return jmax (mn, -mn, mx, -mx);
  20852. }
  20853. float AudioSampleBuffer::getMagnitude (const int startSample,
  20854. const int numSamples) const throw()
  20855. {
  20856. float mag = 0.0f;
  20857. for (int i = 0; i < numChannels; ++i)
  20858. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20859. return mag;
  20860. }
  20861. float AudioSampleBuffer::getRMSLevel (const int channel,
  20862. const int startSample,
  20863. const int numSamples) const throw()
  20864. {
  20865. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20866. jassert (startSample >= 0 && startSample + numSamples <= size);
  20867. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20868. return 0.0f;
  20869. const float* const data = channels [channel] + startSample;
  20870. double sum = 0.0;
  20871. for (int i = 0; i < numSamples; ++i)
  20872. {
  20873. const float sample = data [i];
  20874. sum += sample * sample;
  20875. }
  20876. return (float) sqrt (sum / numSamples);
  20877. }
  20878. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20879. const int startSample,
  20880. const int numSamples,
  20881. const int readerStartSample,
  20882. const bool useLeftChan,
  20883. const bool useRightChan) throw()
  20884. {
  20885. jassert (reader != 0);
  20886. jassert (startSample >= 0 && startSample + numSamples <= size);
  20887. if (numSamples > 0)
  20888. {
  20889. int* chans[3];
  20890. if (useLeftChan == useRightChan)
  20891. {
  20892. chans[0] = (int*) getSampleData (0, startSample);
  20893. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20894. }
  20895. else if (useLeftChan || (reader->numChannels == 1))
  20896. {
  20897. chans[0] = (int*) getSampleData (0, startSample);
  20898. chans[1] = 0;
  20899. }
  20900. else if (useRightChan)
  20901. {
  20902. chans[0] = 0;
  20903. chans[1] = (int*) getSampleData (0, startSample);
  20904. }
  20905. chans[2] = 0;
  20906. reader->read (chans, 2, readerStartSample, numSamples, true);
  20907. if (! reader->usesFloatingPointData)
  20908. {
  20909. for (int j = 0; j < 2; ++j)
  20910. {
  20911. float* const d = reinterpret_cast <float*> (chans[j]);
  20912. if (d != 0)
  20913. {
  20914. const float multiplier = 1.0f / 0x7fffffff;
  20915. for (int i = 0; i < numSamples; ++i)
  20916. d[i] = *(int*)(d + i) * multiplier;
  20917. }
  20918. }
  20919. }
  20920. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20921. {
  20922. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20923. memcpy (getSampleData (1, startSample),
  20924. getSampleData (0, startSample),
  20925. sizeof (float) * numSamples);
  20926. }
  20927. }
  20928. }
  20929. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20930. const int startSample,
  20931. const int numSamples) const throw()
  20932. {
  20933. jassert (startSample >= 0 && startSample + numSamples <= size);
  20934. if (numSamples > 0)
  20935. {
  20936. int* chans [3];
  20937. if (writer->isFloatingPoint())
  20938. {
  20939. chans[0] = (int*) getSampleData (0, startSample);
  20940. if (numChannels > 1)
  20941. chans[1] = (int*) getSampleData (1, startSample);
  20942. else
  20943. chans[1] = 0;
  20944. chans[2] = 0;
  20945. writer->write ((const int**) chans, numSamples);
  20946. }
  20947. else
  20948. {
  20949. HeapBlock <int> tempBuffer (numSamples * 2);
  20950. chans[0] = tempBuffer;
  20951. if (numChannels > 1)
  20952. chans[1] = chans[0] + numSamples;
  20953. else
  20954. chans[1] = 0;
  20955. chans[2] = 0;
  20956. for (int j = 0; j < 2; ++j)
  20957. {
  20958. int* const dest = chans[j];
  20959. if (dest != 0)
  20960. {
  20961. const float* const src = channels [j] + startSample;
  20962. for (int i = 0; i < numSamples; ++i)
  20963. {
  20964. const double samp = src[i];
  20965. if (samp <= -1.0)
  20966. dest[i] = std::numeric_limits<int>::min();
  20967. else if (samp >= 1.0)
  20968. dest[i] = std::numeric_limits<int>::max();
  20969. else
  20970. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  20971. }
  20972. }
  20973. }
  20974. writer->write ((const int**) chans, numSamples);
  20975. }
  20976. }
  20977. }
  20978. END_JUCE_NAMESPACE
  20979. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  20980. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  20981. BEGIN_JUCE_NAMESPACE
  20982. IIRFilter::IIRFilter()
  20983. : active (false)
  20984. {
  20985. reset();
  20986. }
  20987. IIRFilter::IIRFilter (const IIRFilter& other)
  20988. : active (other.active)
  20989. {
  20990. const ScopedLock sl (other.processLock);
  20991. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  20992. reset();
  20993. }
  20994. IIRFilter::~IIRFilter()
  20995. {
  20996. }
  20997. void IIRFilter::reset() throw()
  20998. {
  20999. const ScopedLock sl (processLock);
  21000. x1 = 0;
  21001. x2 = 0;
  21002. y1 = 0;
  21003. y2 = 0;
  21004. }
  21005. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21006. {
  21007. float out = coefficients[0] * in
  21008. + coefficients[1] * x1
  21009. + coefficients[2] * x2
  21010. - coefficients[4] * y1
  21011. - coefficients[5] * y2;
  21012. #if JUCE_INTEL
  21013. if (! (out < -1.0e-8 || out > 1.0e-8))
  21014. out = 0;
  21015. #endif
  21016. x2 = x1;
  21017. x1 = in;
  21018. y2 = y1;
  21019. y1 = out;
  21020. return out;
  21021. }
  21022. void IIRFilter::processSamples (float* const samples,
  21023. const int numSamples) throw()
  21024. {
  21025. const ScopedLock sl (processLock);
  21026. if (active)
  21027. {
  21028. for (int i = 0; i < numSamples; ++i)
  21029. {
  21030. const float in = samples[i];
  21031. float out = coefficients[0] * in
  21032. + coefficients[1] * x1
  21033. + coefficients[2] * x2
  21034. - coefficients[4] * y1
  21035. - coefficients[5] * y2;
  21036. #if JUCE_INTEL
  21037. if (! (out < -1.0e-8 || out > 1.0e-8))
  21038. out = 0;
  21039. #endif
  21040. x2 = x1;
  21041. x1 = in;
  21042. y2 = y1;
  21043. y1 = out;
  21044. samples[i] = out;
  21045. }
  21046. }
  21047. }
  21048. void IIRFilter::makeLowPass (const double sampleRate,
  21049. const double frequency) throw()
  21050. {
  21051. jassert (sampleRate > 0);
  21052. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21053. const double nSquared = n * n;
  21054. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21055. setCoefficients (c1,
  21056. c1 * 2.0f,
  21057. c1,
  21058. 1.0,
  21059. c1 * 2.0 * (1.0 - nSquared),
  21060. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21061. }
  21062. void IIRFilter::makeHighPass (const double sampleRate,
  21063. const double frequency) throw()
  21064. {
  21065. const double n = tan (double_Pi * frequency / sampleRate);
  21066. const double nSquared = n * n;
  21067. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21068. setCoefficients (c1,
  21069. c1 * -2.0f,
  21070. c1,
  21071. 1.0,
  21072. c1 * 2.0 * (nSquared - 1.0),
  21073. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21074. }
  21075. void IIRFilter::makeLowShelf (const double sampleRate,
  21076. const double cutOffFrequency,
  21077. const double Q,
  21078. const float gainFactor) throw()
  21079. {
  21080. jassert (sampleRate > 0);
  21081. jassert (Q > 0);
  21082. const double A = jmax (0.0f, gainFactor);
  21083. const double aminus1 = A - 1.0;
  21084. const double aplus1 = A + 1.0;
  21085. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21086. const double coso = cos (omega);
  21087. const double beta = sin (omega) * sqrt (A) / Q;
  21088. const double aminus1TimesCoso = aminus1 * coso;
  21089. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21090. A * 2.0 * (aminus1 - aplus1 * coso),
  21091. A * (aplus1 - aminus1TimesCoso - beta),
  21092. aplus1 + aminus1TimesCoso + beta,
  21093. -2.0 * (aminus1 + aplus1 * coso),
  21094. aplus1 + aminus1TimesCoso - beta);
  21095. }
  21096. void IIRFilter::makeHighShelf (const double sampleRate,
  21097. const double cutOffFrequency,
  21098. const double Q,
  21099. const float gainFactor) throw()
  21100. {
  21101. jassert (sampleRate > 0);
  21102. jassert (Q > 0);
  21103. const double A = jmax (0.0f, gainFactor);
  21104. const double aminus1 = A - 1.0;
  21105. const double aplus1 = A + 1.0;
  21106. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21107. const double coso = cos (omega);
  21108. const double beta = sin (omega) * sqrt (A) / Q;
  21109. const double aminus1TimesCoso = aminus1 * coso;
  21110. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21111. A * -2.0 * (aminus1 + aplus1 * coso),
  21112. A * (aplus1 + aminus1TimesCoso - beta),
  21113. aplus1 - aminus1TimesCoso + beta,
  21114. 2.0 * (aminus1 - aplus1 * coso),
  21115. aplus1 - aminus1TimesCoso - beta);
  21116. }
  21117. void IIRFilter::makeBandPass (const double sampleRate,
  21118. const double centreFrequency,
  21119. const double Q,
  21120. const float gainFactor) throw()
  21121. {
  21122. jassert (sampleRate > 0);
  21123. jassert (Q > 0);
  21124. const double A = jmax (0.0f, gainFactor);
  21125. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21126. const double alpha = 0.5 * sin (omega) / Q;
  21127. const double c2 = -2.0 * cos (omega);
  21128. const double alphaTimesA = alpha * A;
  21129. const double alphaOverA = alpha / A;
  21130. setCoefficients (1.0 + alphaTimesA,
  21131. c2,
  21132. 1.0 - alphaTimesA,
  21133. 1.0 + alphaOverA,
  21134. c2,
  21135. 1.0 - alphaOverA);
  21136. }
  21137. void IIRFilter::makeInactive() throw()
  21138. {
  21139. const ScopedLock sl (processLock);
  21140. active = false;
  21141. }
  21142. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21143. {
  21144. const ScopedLock sl (processLock);
  21145. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21146. active = other.active;
  21147. }
  21148. void IIRFilter::setCoefficients (double c1,
  21149. double c2,
  21150. double c3,
  21151. double c4,
  21152. double c5,
  21153. double c6) throw()
  21154. {
  21155. const double a = 1.0 / c4;
  21156. c1 *= a;
  21157. c2 *= a;
  21158. c3 *= a;
  21159. c5 *= a;
  21160. c6 *= a;
  21161. const ScopedLock sl (processLock);
  21162. coefficients[0] = (float) c1;
  21163. coefficients[1] = (float) c2;
  21164. coefficients[2] = (float) c3;
  21165. coefficients[3] = (float) c4;
  21166. coefficients[4] = (float) c5;
  21167. coefficients[5] = (float) c6;
  21168. active = true;
  21169. }
  21170. END_JUCE_NAMESPACE
  21171. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21172. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21173. BEGIN_JUCE_NAMESPACE
  21174. MidiBuffer::MidiBuffer() throw()
  21175. : bytesUsed (0)
  21176. {
  21177. }
  21178. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21179. : bytesUsed (0)
  21180. {
  21181. addEvent (message, 0);
  21182. }
  21183. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21184. : data (other.data),
  21185. bytesUsed (other.bytesUsed)
  21186. {
  21187. }
  21188. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21189. {
  21190. bytesUsed = other.bytesUsed;
  21191. data = other.data;
  21192. return *this;
  21193. }
  21194. void MidiBuffer::swapWith (MidiBuffer& other)
  21195. {
  21196. data.swapWith (other.data);
  21197. swapVariables <int> (bytesUsed, other.bytesUsed);
  21198. }
  21199. MidiBuffer::~MidiBuffer() throw()
  21200. {
  21201. }
  21202. inline uint8* MidiBuffer::getData() const throw()
  21203. {
  21204. return static_cast <uint8*> (data.getData());
  21205. }
  21206. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21207. {
  21208. return *static_cast <const int*> (d);
  21209. }
  21210. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21211. {
  21212. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21213. }
  21214. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21215. {
  21216. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21217. }
  21218. void MidiBuffer::clear() throw()
  21219. {
  21220. bytesUsed = 0;
  21221. }
  21222. void MidiBuffer::clear (const int startSample,
  21223. const int numSamples) throw()
  21224. {
  21225. uint8* const start = findEventAfter (getData(), startSample - 1);
  21226. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21227. if (end > start)
  21228. {
  21229. const int bytesToMove = bytesUsed - (int) (end - getData());
  21230. if (bytesToMove > 0)
  21231. memmove (start, end, bytesToMove);
  21232. bytesUsed -= (int) (end - start);
  21233. }
  21234. }
  21235. void MidiBuffer::addEvent (const MidiMessage& m,
  21236. const int sampleNumber) throw()
  21237. {
  21238. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21239. }
  21240. static int findActualEventLength (const uint8* const data,
  21241. const int maxBytes) throw()
  21242. {
  21243. unsigned int byte = (unsigned int) *data;
  21244. int size = 0;
  21245. if (byte == 0xf0 || byte == 0xf7)
  21246. {
  21247. const uint8* d = data + 1;
  21248. while (d < data + maxBytes)
  21249. if (*d++ == 0xf7)
  21250. break;
  21251. size = (int) (d - data);
  21252. }
  21253. else if (byte == 0xff)
  21254. {
  21255. int n;
  21256. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21257. size = jmin (maxBytes, n + 2 + bytesLeft);
  21258. }
  21259. else if (byte >= 0x80)
  21260. {
  21261. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21262. }
  21263. return size;
  21264. }
  21265. void MidiBuffer::addEvent (const uint8* const newData,
  21266. const int maxBytes,
  21267. const int sampleNumber) throw()
  21268. {
  21269. const int numBytes = findActualEventLength (newData, maxBytes);
  21270. if (numBytes > 0)
  21271. {
  21272. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21273. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21274. uint8* d = findEventAfter (getData(), sampleNumber);
  21275. const int bytesToMove = bytesUsed - (int) (d - getData());
  21276. if (bytesToMove > 0)
  21277. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21278. *reinterpret_cast <int*> (d) = sampleNumber;
  21279. d += sizeof (int);
  21280. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21281. d += sizeof (uint16);
  21282. memcpy (d, newData, numBytes);
  21283. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21284. }
  21285. }
  21286. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21287. const int startSample,
  21288. const int numSamples,
  21289. const int sampleDeltaToAdd) throw()
  21290. {
  21291. Iterator i (otherBuffer);
  21292. i.setNextSamplePosition (startSample);
  21293. const uint8* eventData;
  21294. int eventSize, position;
  21295. while (i.getNextEvent (eventData, eventSize, position)
  21296. && (position < startSample + numSamples || numSamples < 0))
  21297. {
  21298. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21299. }
  21300. }
  21301. bool MidiBuffer::isEmpty() const throw()
  21302. {
  21303. return bytesUsed == 0;
  21304. }
  21305. int MidiBuffer::getNumEvents() const throw()
  21306. {
  21307. int n = 0;
  21308. const uint8* d = getData();
  21309. const uint8* const end = d + bytesUsed;
  21310. while (d < end)
  21311. {
  21312. d += getEventTotalSize (d);
  21313. ++n;
  21314. }
  21315. return n;
  21316. }
  21317. int MidiBuffer::getFirstEventTime() const throw()
  21318. {
  21319. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21320. }
  21321. int MidiBuffer::getLastEventTime() const throw()
  21322. {
  21323. if (bytesUsed == 0)
  21324. return 0;
  21325. const uint8* d = getData();
  21326. const uint8* const endData = d + bytesUsed;
  21327. for (;;)
  21328. {
  21329. const uint8* const nextOne = d + getEventTotalSize (d);
  21330. if (nextOne >= endData)
  21331. return getEventTime (d);
  21332. d = nextOne;
  21333. }
  21334. }
  21335. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21336. {
  21337. const uint8* const endData = getData() + bytesUsed;
  21338. while (d < endData && getEventTime (d) <= samplePosition)
  21339. d += getEventTotalSize (d);
  21340. return d;
  21341. }
  21342. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21343. : buffer (buffer_),
  21344. data (buffer_.getData())
  21345. {
  21346. }
  21347. MidiBuffer::Iterator::~Iterator() throw()
  21348. {
  21349. }
  21350. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21351. {
  21352. data = buffer.getData();
  21353. const uint8* dataEnd = data + buffer.bytesUsed;
  21354. while (data < dataEnd && getEventTime (data) < samplePosition)
  21355. data += getEventTotalSize (data);
  21356. }
  21357. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21358. {
  21359. if (data >= buffer.getData() + buffer.bytesUsed)
  21360. return false;
  21361. samplePosition = getEventTime (data);
  21362. numBytes = getEventDataSize (data);
  21363. data += sizeof (int) + sizeof (uint16);
  21364. midiData = data;
  21365. data += numBytes;
  21366. return true;
  21367. }
  21368. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21369. {
  21370. if (data >= buffer.getData() + buffer.bytesUsed)
  21371. return false;
  21372. samplePosition = getEventTime (data);
  21373. const int numBytes = getEventDataSize (data);
  21374. data += sizeof (int) + sizeof (uint16);
  21375. result = MidiMessage (data, numBytes, samplePosition);
  21376. data += numBytes;
  21377. return true;
  21378. }
  21379. END_JUCE_NAMESPACE
  21380. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21381. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21382. BEGIN_JUCE_NAMESPACE
  21383. namespace MidiFileHelpers
  21384. {
  21385. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21386. {
  21387. unsigned int buffer = v & 0x7F;
  21388. while ((v >>= 7) != 0)
  21389. {
  21390. buffer <<= 8;
  21391. buffer |= ((v & 0x7F) | 0x80);
  21392. }
  21393. for (;;)
  21394. {
  21395. out.writeByte ((char) buffer);
  21396. if (buffer & 0x80)
  21397. buffer >>= 8;
  21398. else
  21399. break;
  21400. }
  21401. }
  21402. static bool parseMidiHeader (const uint8* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21403. {
  21404. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21405. data += 4;
  21406. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21407. {
  21408. bool ok = false;
  21409. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21410. {
  21411. for (int i = 0; i < 8; ++i)
  21412. {
  21413. ch = ByteOrder::bigEndianInt (data);
  21414. data += 4;
  21415. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21416. {
  21417. ok = true;
  21418. break;
  21419. }
  21420. }
  21421. }
  21422. if (! ok)
  21423. return false;
  21424. }
  21425. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21426. data += 4;
  21427. fileType = (short) ByteOrder::bigEndianShort (data);
  21428. data += 2;
  21429. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21430. data += 2;
  21431. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21432. data += 2;
  21433. bytesRemaining -= 6;
  21434. data += bytesRemaining;
  21435. return true;
  21436. }
  21437. static double convertTicksToSeconds (const double time,
  21438. const MidiMessageSequence& tempoEvents,
  21439. const int timeFormat)
  21440. {
  21441. if (timeFormat > 0)
  21442. {
  21443. int numer = 4, denom = 4;
  21444. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21445. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21446. double secsPerTick = 0.5 * tickLen;
  21447. const int numEvents = tempoEvents.getNumEvents();
  21448. for (int i = 0; i < numEvents; ++i)
  21449. {
  21450. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21451. if (time <= m.getTimeStamp())
  21452. break;
  21453. if (timeFormat > 0)
  21454. {
  21455. correctedTempoTime = correctedTempoTime
  21456. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21457. }
  21458. else
  21459. {
  21460. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21461. }
  21462. tempoTime = m.getTimeStamp();
  21463. if (m.isTempoMetaEvent())
  21464. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21465. else if (m.isTimeSignatureMetaEvent())
  21466. m.getTimeSignatureInfo (numer, denom);
  21467. while (i + 1 < numEvents)
  21468. {
  21469. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21470. if (m2.getTimeStamp() == tempoTime)
  21471. {
  21472. ++i;
  21473. if (m2.isTempoMetaEvent())
  21474. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21475. else if (m2.isTimeSignatureMetaEvent())
  21476. m2.getTimeSignatureInfo (numer, denom);
  21477. }
  21478. else
  21479. {
  21480. break;
  21481. }
  21482. }
  21483. }
  21484. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21485. }
  21486. else
  21487. {
  21488. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21489. }
  21490. }
  21491. }
  21492. MidiFile::MidiFile()
  21493. : timeFormat ((short) (unsigned short) 0xe728)
  21494. {
  21495. }
  21496. MidiFile::~MidiFile()
  21497. {
  21498. clear();
  21499. }
  21500. void MidiFile::clear()
  21501. {
  21502. tracks.clear();
  21503. }
  21504. int MidiFile::getNumTracks() const throw()
  21505. {
  21506. return tracks.size();
  21507. }
  21508. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21509. {
  21510. return tracks [index];
  21511. }
  21512. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21513. {
  21514. tracks.add (new MidiMessageSequence (trackSequence));
  21515. }
  21516. short MidiFile::getTimeFormat() const throw()
  21517. {
  21518. return timeFormat;
  21519. }
  21520. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21521. {
  21522. timeFormat = (short) ticks;
  21523. }
  21524. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21525. const int subframeResolution) throw()
  21526. {
  21527. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21528. }
  21529. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21530. {
  21531. for (int i = tracks.size(); --i >= 0;)
  21532. {
  21533. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21534. for (int j = 0; j < numEvents; ++j)
  21535. {
  21536. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21537. if (m.isTempoMetaEvent())
  21538. tempoChangeEvents.addEvent (m);
  21539. }
  21540. }
  21541. }
  21542. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21543. {
  21544. for (int i = tracks.size(); --i >= 0;)
  21545. {
  21546. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21547. for (int j = 0; j < numEvents; ++j)
  21548. {
  21549. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21550. if (m.isTimeSignatureMetaEvent())
  21551. timeSigEvents.addEvent (m);
  21552. }
  21553. }
  21554. }
  21555. double MidiFile::getLastTimestamp() const
  21556. {
  21557. double t = 0.0;
  21558. for (int i = tracks.size(); --i >= 0;)
  21559. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21560. return t;
  21561. }
  21562. bool MidiFile::readFrom (InputStream& sourceStream)
  21563. {
  21564. clear();
  21565. MemoryBlock data;
  21566. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21567. // (put a sanity-check on the file size, as midi files are generally small)
  21568. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21569. {
  21570. size_t size = data.getSize();
  21571. const uint8* d = static_cast <const uint8*> (data.getData());
  21572. short fileType, expectedTracks;
  21573. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21574. {
  21575. size -= (int) (d - static_cast <const uint8*> (data.getData()));
  21576. int track = 0;
  21577. while (size > 0 && track < expectedTracks)
  21578. {
  21579. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21580. d += 4;
  21581. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21582. d += 4;
  21583. if (chunkSize <= 0)
  21584. break;
  21585. if (size < 0)
  21586. return false;
  21587. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21588. {
  21589. readNextTrack (d, chunkSize);
  21590. }
  21591. size -= chunkSize + 8;
  21592. d += chunkSize;
  21593. ++track;
  21594. }
  21595. return true;
  21596. }
  21597. }
  21598. return false;
  21599. }
  21600. // a comparator that puts all the note-offs before note-ons that have the same time
  21601. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21602. const MidiMessageSequence::MidiEventHolder* const second)
  21603. {
  21604. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21605. if (diff == 0)
  21606. {
  21607. if (first->message.isNoteOff() && second->message.isNoteOn())
  21608. return -1;
  21609. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21610. return 1;
  21611. else
  21612. return 0;
  21613. }
  21614. else
  21615. {
  21616. return (diff > 0) ? 1 : -1;
  21617. }
  21618. }
  21619. void MidiFile::readNextTrack (const uint8* data, int size)
  21620. {
  21621. double time = 0;
  21622. char lastStatusByte = 0;
  21623. MidiMessageSequence result;
  21624. while (size > 0)
  21625. {
  21626. int bytesUsed;
  21627. const int delay = MidiMessage::readVariableLengthVal (data, bytesUsed);
  21628. data += bytesUsed;
  21629. size -= bytesUsed;
  21630. time += delay;
  21631. int messSize = 0;
  21632. const MidiMessage mm (data, size, messSize, lastStatusByte, time);
  21633. if (messSize <= 0)
  21634. break;
  21635. size -= messSize;
  21636. data += messSize;
  21637. result.addEvent (mm);
  21638. const char firstByte = *(mm.getRawData());
  21639. if ((firstByte & 0xf0) != 0xf0)
  21640. lastStatusByte = firstByte;
  21641. }
  21642. // use a sort that puts all the note-offs before note-ons that have the same time
  21643. result.list.sort (*this, true);
  21644. result.updateMatchedPairs();
  21645. addTrack (result);
  21646. }
  21647. void MidiFile::convertTimestampTicksToSeconds()
  21648. {
  21649. MidiMessageSequence tempoEvents;
  21650. findAllTempoEvents (tempoEvents);
  21651. findAllTimeSigEvents (tempoEvents);
  21652. for (int i = 0; i < tracks.size(); ++i)
  21653. {
  21654. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21655. for (int j = ms.getNumEvents(); --j >= 0;)
  21656. {
  21657. MidiMessage& m = ms.getEventPointer(j)->message;
  21658. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21659. tempoEvents,
  21660. timeFormat));
  21661. }
  21662. }
  21663. }
  21664. bool MidiFile::writeTo (OutputStream& out)
  21665. {
  21666. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21667. out.writeIntBigEndian (6);
  21668. out.writeShortBigEndian (1); // type
  21669. out.writeShortBigEndian ((short) tracks.size());
  21670. out.writeShortBigEndian (timeFormat);
  21671. for (int i = 0; i < tracks.size(); ++i)
  21672. writeTrack (out, i);
  21673. out.flush();
  21674. return true;
  21675. }
  21676. void MidiFile::writeTrack (OutputStream& mainOut,
  21677. const int trackNum)
  21678. {
  21679. MemoryOutputStream out;
  21680. const MidiMessageSequence& ms = *tracks[trackNum];
  21681. int lastTick = 0;
  21682. char lastStatusByte = 0;
  21683. for (int i = 0; i < ms.getNumEvents(); ++i)
  21684. {
  21685. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21686. const int tick = roundToInt (mm.getTimeStamp());
  21687. const int delta = jmax (0, tick - lastTick);
  21688. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21689. lastTick = tick;
  21690. const char statusByte = *(mm.getRawData());
  21691. if ((statusByte == lastStatusByte)
  21692. && ((statusByte & 0xf0) != 0xf0)
  21693. && i > 0
  21694. && mm.getRawDataSize() > 1)
  21695. {
  21696. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21697. }
  21698. else
  21699. {
  21700. out.write (mm.getRawData(), mm.getRawDataSize());
  21701. }
  21702. lastStatusByte = statusByte;
  21703. }
  21704. out.writeByte (0);
  21705. const MidiMessage m (MidiMessage::endOfTrack());
  21706. out.write (m.getRawData(),
  21707. m.getRawDataSize());
  21708. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21709. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21710. mainOut.write (out.getData(), (int) out.getDataSize());
  21711. }
  21712. END_JUCE_NAMESPACE
  21713. /*** End of inlined file: juce_MidiFile.cpp ***/
  21714. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21715. BEGIN_JUCE_NAMESPACE
  21716. MidiKeyboardState::MidiKeyboardState()
  21717. {
  21718. zerostruct (noteStates);
  21719. }
  21720. MidiKeyboardState::~MidiKeyboardState()
  21721. {
  21722. }
  21723. void MidiKeyboardState::reset()
  21724. {
  21725. const ScopedLock sl (lock);
  21726. zerostruct (noteStates);
  21727. eventsToAdd.clear();
  21728. }
  21729. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21730. {
  21731. jassert (midiChannel >= 0 && midiChannel <= 16);
  21732. return ((unsigned int) n) < 128
  21733. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21734. }
  21735. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21736. {
  21737. return ((unsigned int) n) < 128
  21738. && (noteStates[n] & midiChannelMask) != 0;
  21739. }
  21740. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21741. {
  21742. jassert (midiChannel >= 0 && midiChannel <= 16);
  21743. jassert (((unsigned int) midiNoteNumber) < 128);
  21744. const ScopedLock sl (lock);
  21745. if (((unsigned int) midiNoteNumber) < 128)
  21746. {
  21747. const int timeNow = (int) Time::getMillisecondCounter();
  21748. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21749. eventsToAdd.clear (0, timeNow - 500);
  21750. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21751. }
  21752. }
  21753. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21754. {
  21755. if (((unsigned int) midiNoteNumber) < 128)
  21756. {
  21757. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21758. for (int i = listeners.size(); --i >= 0;)
  21759. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21760. }
  21761. }
  21762. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21763. {
  21764. const ScopedLock sl (lock);
  21765. if (isNoteOn (midiChannel, midiNoteNumber))
  21766. {
  21767. const int timeNow = (int) Time::getMillisecondCounter();
  21768. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21769. eventsToAdd.clear (0, timeNow - 500);
  21770. noteOffInternal (midiChannel, midiNoteNumber);
  21771. }
  21772. }
  21773. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21774. {
  21775. if (isNoteOn (midiChannel, midiNoteNumber))
  21776. {
  21777. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21778. for (int i = listeners.size(); --i >= 0;)
  21779. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21780. }
  21781. }
  21782. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21783. {
  21784. const ScopedLock sl (lock);
  21785. if (midiChannel <= 0)
  21786. {
  21787. for (int i = 1; i <= 16; ++i)
  21788. allNotesOff (i);
  21789. }
  21790. else
  21791. {
  21792. for (int i = 0; i < 128; ++i)
  21793. noteOff (midiChannel, i);
  21794. }
  21795. }
  21796. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21797. {
  21798. if (message.isNoteOn())
  21799. {
  21800. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21801. }
  21802. else if (message.isNoteOff())
  21803. {
  21804. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21805. }
  21806. else if (message.isAllNotesOff())
  21807. {
  21808. for (int i = 0; i < 128; ++i)
  21809. noteOffInternal (message.getChannel(), i);
  21810. }
  21811. }
  21812. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21813. const int startSample,
  21814. const int numSamples,
  21815. const bool injectIndirectEvents)
  21816. {
  21817. MidiBuffer::Iterator i (buffer);
  21818. MidiMessage message (0xf4, 0.0);
  21819. int time;
  21820. const ScopedLock sl (lock);
  21821. while (i.getNextEvent (message, time))
  21822. processNextMidiEvent (message);
  21823. if (injectIndirectEvents)
  21824. {
  21825. MidiBuffer::Iterator i2 (eventsToAdd);
  21826. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21827. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21828. while (i2.getNextEvent (message, time))
  21829. {
  21830. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21831. buffer.addEvent (message, startSample + pos);
  21832. }
  21833. }
  21834. eventsToAdd.clear();
  21835. }
  21836. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21837. {
  21838. const ScopedLock sl (lock);
  21839. listeners.addIfNotAlreadyThere (listener);
  21840. }
  21841. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21842. {
  21843. const ScopedLock sl (lock);
  21844. listeners.removeValue (listener);
  21845. }
  21846. END_JUCE_NAMESPACE
  21847. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21848. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21849. BEGIN_JUCE_NAMESPACE
  21850. int MidiMessage::readVariableLengthVal (const uint8* data,
  21851. int& numBytesUsed) throw()
  21852. {
  21853. numBytesUsed = 0;
  21854. int v = 0;
  21855. int i;
  21856. do
  21857. {
  21858. i = (int) *data++;
  21859. if (++numBytesUsed > 6)
  21860. break;
  21861. v = (v << 7) + (i & 0x7f);
  21862. } while (i & 0x80);
  21863. return v;
  21864. }
  21865. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21866. {
  21867. // this method only works for valid starting bytes of a short midi message
  21868. jassert (firstByte >= 0x80
  21869. && firstByte != 0xf0
  21870. && firstByte != 0xf7);
  21871. static const char messageLengths[] =
  21872. {
  21873. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21874. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21875. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21876. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21877. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21878. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21879. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21880. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21881. };
  21882. return messageLengths [firstByte & 0x7f];
  21883. }
  21884. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21885. : timeStamp (t),
  21886. size (dataSize)
  21887. {
  21888. jassert (dataSize > 0);
  21889. if (dataSize <= 4)
  21890. data = static_cast<uint8*> (preallocatedData.asBytes);
  21891. else
  21892. data = static_cast<uint8*> (juce_malloc (dataSize));
  21893. memcpy (data, d, dataSize);
  21894. // check that the length matches the data..
  21895. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21896. }
  21897. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21898. : timeStamp (t),
  21899. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21900. size (1)
  21901. {
  21902. data[0] = (uint8) byte1;
  21903. // check that the length matches the data..
  21904. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21905. }
  21906. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21907. : timeStamp (t),
  21908. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21909. size (2)
  21910. {
  21911. data[0] = (uint8) byte1;
  21912. data[1] = (uint8) byte2;
  21913. // check that the length matches the data..
  21914. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21915. }
  21916. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21917. : timeStamp (t),
  21918. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21919. size (3)
  21920. {
  21921. data[0] = (uint8) byte1;
  21922. data[1] = (uint8) byte2;
  21923. data[2] = (uint8) byte3;
  21924. // check that the length matches the data..
  21925. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21926. }
  21927. MidiMessage::MidiMessage (const MidiMessage& other)
  21928. : timeStamp (other.timeStamp),
  21929. size (other.size)
  21930. {
  21931. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21932. {
  21933. data = static_cast<uint8*> (juce_malloc (size));
  21934. memcpy (data, other.data, size);
  21935. }
  21936. else
  21937. {
  21938. data = static_cast<uint8*> (preallocatedData.asBytes);
  21939. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21940. }
  21941. }
  21942. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  21943. : timeStamp (newTimeStamp),
  21944. size (other.size)
  21945. {
  21946. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21947. {
  21948. data = static_cast<uint8*> (juce_malloc (size));
  21949. memcpy (data, other.data, size);
  21950. }
  21951. else
  21952. {
  21953. data = static_cast<uint8*> (preallocatedData.asBytes);
  21954. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21955. }
  21956. }
  21957. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  21958. : timeStamp (t),
  21959. data (static_cast<uint8*> (preallocatedData.asBytes))
  21960. {
  21961. const uint8* src = static_cast <const uint8*> (src_);
  21962. unsigned int byte = (unsigned int) *src;
  21963. if (byte < 0x80)
  21964. {
  21965. byte = (unsigned int) (uint8) lastStatusByte;
  21966. numBytesUsed = -1;
  21967. }
  21968. else
  21969. {
  21970. numBytesUsed = 0;
  21971. --sz;
  21972. ++src;
  21973. }
  21974. if (byte >= 0x80)
  21975. {
  21976. if (byte == 0xf0)
  21977. {
  21978. const uint8* d = src;
  21979. while (d < src + sz)
  21980. {
  21981. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  21982. {
  21983. if (*d == 0xf7) // include an 0xf7 if we hit one
  21984. ++d;
  21985. break;
  21986. }
  21987. ++d;
  21988. }
  21989. size = 1 + (int) (d - src);
  21990. data = static_cast<uint8*> (juce_malloc (size));
  21991. *data = (uint8) byte;
  21992. memcpy (data + 1, src, size - 1);
  21993. }
  21994. else if (byte == 0xff)
  21995. {
  21996. int n;
  21997. const int bytesLeft = readVariableLengthVal (src + 1, n);
  21998. size = jmin (sz + 1, n + 2 + bytesLeft);
  21999. data = static_cast<uint8*> (juce_malloc (size));
  22000. *data = (uint8) byte;
  22001. memcpy (data + 1, src, size - 1);
  22002. }
  22003. else
  22004. {
  22005. preallocatedData.asInt32 = 0;
  22006. size = getMessageLengthFromFirstByte ((uint8) byte);
  22007. data[0] = (uint8) byte;
  22008. if (size > 1)
  22009. {
  22010. data[1] = src[0];
  22011. if (size > 2)
  22012. data[2] = src[1];
  22013. }
  22014. }
  22015. numBytesUsed += size;
  22016. }
  22017. else
  22018. {
  22019. preallocatedData.asInt32 = 0;
  22020. size = 0;
  22021. }
  22022. }
  22023. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  22024. {
  22025. if (this != &other)
  22026. {
  22027. timeStamp = other.timeStamp;
  22028. size = other.size;
  22029. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22030. juce_free (data);
  22031. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22032. {
  22033. data = static_cast<uint8*> (juce_malloc (size));
  22034. memcpy (data, other.data, size);
  22035. }
  22036. else
  22037. {
  22038. data = static_cast<uint8*> (preallocatedData.asBytes);
  22039. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22040. }
  22041. }
  22042. return *this;
  22043. }
  22044. MidiMessage::~MidiMessage()
  22045. {
  22046. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22047. juce_free (data);
  22048. }
  22049. int MidiMessage::getChannel() const throw()
  22050. {
  22051. if ((data[0] & 0xf0) != 0xf0)
  22052. return (data[0] & 0xf) + 1;
  22053. else
  22054. return 0;
  22055. }
  22056. bool MidiMessage::isForChannel (const int channel) const throw()
  22057. {
  22058. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22059. return ((data[0] & 0xf) == channel - 1)
  22060. && ((data[0] & 0xf0) != 0xf0);
  22061. }
  22062. void MidiMessage::setChannel (const int channel) throw()
  22063. {
  22064. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22065. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22066. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22067. | (uint8)(channel - 1));
  22068. }
  22069. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22070. {
  22071. return ((data[0] & 0xf0) == 0x90)
  22072. && (returnTrueForVelocity0 || data[2] != 0);
  22073. }
  22074. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22075. {
  22076. return ((data[0] & 0xf0) == 0x80)
  22077. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22078. }
  22079. bool MidiMessage::isNoteOnOrOff() const throw()
  22080. {
  22081. const int d = data[0] & 0xf0;
  22082. return (d == 0x90) || (d == 0x80);
  22083. }
  22084. int MidiMessage::getNoteNumber() const throw()
  22085. {
  22086. return data[1];
  22087. }
  22088. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22089. {
  22090. if (isNoteOnOrOff())
  22091. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22092. }
  22093. uint8 MidiMessage::getVelocity() const throw()
  22094. {
  22095. if (isNoteOnOrOff())
  22096. return data[2];
  22097. else
  22098. return 0;
  22099. }
  22100. float MidiMessage::getFloatVelocity() const throw()
  22101. {
  22102. return getVelocity() * (1.0f / 127.0f);
  22103. }
  22104. void MidiMessage::setVelocity (const float newVelocity) throw()
  22105. {
  22106. if (isNoteOnOrOff())
  22107. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22108. }
  22109. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22110. {
  22111. if (isNoteOnOrOff())
  22112. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22113. }
  22114. bool MidiMessage::isAftertouch() const throw()
  22115. {
  22116. return (data[0] & 0xf0) == 0xa0;
  22117. }
  22118. int MidiMessage::getAfterTouchValue() const throw()
  22119. {
  22120. return data[2];
  22121. }
  22122. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22123. const int noteNum,
  22124. const int aftertouchValue) throw()
  22125. {
  22126. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22127. jassert (((unsigned int) noteNum) <= 127);
  22128. jassert (((unsigned int) aftertouchValue) <= 127);
  22129. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22130. noteNum & 0x7f,
  22131. aftertouchValue & 0x7f);
  22132. }
  22133. bool MidiMessage::isChannelPressure() const throw()
  22134. {
  22135. return (data[0] & 0xf0) == 0xd0;
  22136. }
  22137. int MidiMessage::getChannelPressureValue() const throw()
  22138. {
  22139. jassert (isChannelPressure());
  22140. return data[1];
  22141. }
  22142. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22143. const int pressure) throw()
  22144. {
  22145. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22146. jassert (((unsigned int) pressure) <= 127);
  22147. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22148. pressure & 0x7f);
  22149. }
  22150. bool MidiMessage::isProgramChange() const throw()
  22151. {
  22152. return (data[0] & 0xf0) == 0xc0;
  22153. }
  22154. int MidiMessage::getProgramChangeNumber() const throw()
  22155. {
  22156. return data[1];
  22157. }
  22158. const MidiMessage MidiMessage::programChange (const int channel,
  22159. const int programNumber) throw()
  22160. {
  22161. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22162. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22163. programNumber & 0x7f);
  22164. }
  22165. bool MidiMessage::isPitchWheel() const throw()
  22166. {
  22167. return (data[0] & 0xf0) == 0xe0;
  22168. }
  22169. int MidiMessage::getPitchWheelValue() const throw()
  22170. {
  22171. return data[1] | (data[2] << 7);
  22172. }
  22173. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22174. const int position) throw()
  22175. {
  22176. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22177. jassert (((unsigned int) position) <= 0x3fff);
  22178. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22179. position & 127,
  22180. (position >> 7) & 127);
  22181. }
  22182. bool MidiMessage::isController() const throw()
  22183. {
  22184. return (data[0] & 0xf0) == 0xb0;
  22185. }
  22186. int MidiMessage::getControllerNumber() const throw()
  22187. {
  22188. jassert (isController());
  22189. return data[1];
  22190. }
  22191. int MidiMessage::getControllerValue() const throw()
  22192. {
  22193. jassert (isController());
  22194. return data[2];
  22195. }
  22196. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22197. const int controllerType,
  22198. const int value) throw()
  22199. {
  22200. // the channel must be between 1 and 16 inclusive
  22201. jassert (channel > 0 && channel <= 16);
  22202. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22203. controllerType & 127,
  22204. value & 127);
  22205. }
  22206. const MidiMessage MidiMessage::noteOn (const int channel,
  22207. const int noteNumber,
  22208. const float velocity) throw()
  22209. {
  22210. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22211. }
  22212. const MidiMessage MidiMessage::noteOn (const int channel,
  22213. const int noteNumber,
  22214. const uint8 velocity) throw()
  22215. {
  22216. jassert (channel > 0 && channel <= 16);
  22217. jassert (((unsigned int) noteNumber) <= 127);
  22218. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22219. noteNumber & 127,
  22220. jlimit (0, 127, roundToInt (velocity)));
  22221. }
  22222. const MidiMessage MidiMessage::noteOff (const int channel,
  22223. const int noteNumber) throw()
  22224. {
  22225. jassert (channel > 0 && channel <= 16);
  22226. jassert (((unsigned int) noteNumber) <= 127);
  22227. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22228. }
  22229. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22230. {
  22231. jassert (channel > 0 && channel <= 16);
  22232. return controllerEvent (channel, 123, 0);
  22233. }
  22234. bool MidiMessage::isAllNotesOff() const throw()
  22235. {
  22236. return (data[0] & 0xf0) == 0xb0
  22237. && data[1] == 123;
  22238. }
  22239. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22240. {
  22241. return controllerEvent (channel, 120, 0);
  22242. }
  22243. bool MidiMessage::isAllSoundOff() const throw()
  22244. {
  22245. return (data[0] & 0xf0) == 0xb0
  22246. && data[1] == 120;
  22247. }
  22248. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22249. {
  22250. return controllerEvent (channel, 121, 0);
  22251. }
  22252. const MidiMessage MidiMessage::masterVolume (const float volume)
  22253. {
  22254. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22255. uint8 buf[8];
  22256. buf[0] = 0xf0;
  22257. buf[1] = 0x7f;
  22258. buf[2] = 0x7f;
  22259. buf[3] = 0x04;
  22260. buf[4] = 0x01;
  22261. buf[5] = (uint8) (vol & 0x7f);
  22262. buf[6] = (uint8) (vol >> 7);
  22263. buf[7] = 0xf7;
  22264. return MidiMessage (buf, 8);
  22265. }
  22266. bool MidiMessage::isSysEx() const throw()
  22267. {
  22268. return *data == 0xf0;
  22269. }
  22270. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22271. {
  22272. MemoryBlock mm (dataSize + 2);
  22273. uint8* const m = static_cast <uint8*> (mm.getData());
  22274. m[0] = 0xf0;
  22275. memcpy (m + 1, sysexData, dataSize);
  22276. m[dataSize + 1] = 0xf7;
  22277. return MidiMessage (m, dataSize + 2);
  22278. }
  22279. const uint8* MidiMessage::getSysExData() const throw()
  22280. {
  22281. return (isSysEx()) ? getRawData() + 1 : 0;
  22282. }
  22283. int MidiMessage::getSysExDataSize() const throw()
  22284. {
  22285. return (isSysEx()) ? size - 2 : 0;
  22286. }
  22287. bool MidiMessage::isMetaEvent() const throw()
  22288. {
  22289. return *data == 0xff;
  22290. }
  22291. bool MidiMessage::isActiveSense() const throw()
  22292. {
  22293. return *data == 0xfe;
  22294. }
  22295. int MidiMessage::getMetaEventType() const throw()
  22296. {
  22297. if (*data != 0xff)
  22298. return -1;
  22299. else
  22300. return data[1];
  22301. }
  22302. int MidiMessage::getMetaEventLength() const throw()
  22303. {
  22304. if (*data == 0xff)
  22305. {
  22306. int n;
  22307. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22308. }
  22309. return 0;
  22310. }
  22311. const uint8* MidiMessage::getMetaEventData() const throw()
  22312. {
  22313. int n;
  22314. const uint8* d = data + 2;
  22315. readVariableLengthVal (d, n);
  22316. return d + n;
  22317. }
  22318. bool MidiMessage::isTrackMetaEvent() const throw()
  22319. {
  22320. return getMetaEventType() == 0;
  22321. }
  22322. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22323. {
  22324. return getMetaEventType() == 47;
  22325. }
  22326. bool MidiMessage::isTextMetaEvent() const throw()
  22327. {
  22328. const int t = getMetaEventType();
  22329. return t > 0 && t < 16;
  22330. }
  22331. const String MidiMessage::getTextFromTextMetaEvent() const
  22332. {
  22333. return String (reinterpret_cast <const char*> (getMetaEventData()), getMetaEventLength());
  22334. }
  22335. bool MidiMessage::isTrackNameEvent() const throw()
  22336. {
  22337. return (data[1] == 3)
  22338. && (*data == 0xff);
  22339. }
  22340. bool MidiMessage::isTempoMetaEvent() const throw()
  22341. {
  22342. return (data[1] == 81)
  22343. && (*data == 0xff);
  22344. }
  22345. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22346. {
  22347. return (data[1] == 0x20)
  22348. && (*data == 0xff)
  22349. && (data[2] == 1);
  22350. }
  22351. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22352. {
  22353. return data[3] + 1;
  22354. }
  22355. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22356. {
  22357. if (! isTempoMetaEvent())
  22358. return 0.0;
  22359. const uint8* const d = getMetaEventData();
  22360. return (((unsigned int) d[0] << 16)
  22361. | ((unsigned int) d[1] << 8)
  22362. | d[2])
  22363. / 1000000.0;
  22364. }
  22365. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22366. {
  22367. if (timeFormat > 0)
  22368. {
  22369. if (! isTempoMetaEvent())
  22370. return 0.5 / timeFormat;
  22371. return getTempoSecondsPerQuarterNote() / timeFormat;
  22372. }
  22373. else
  22374. {
  22375. const int frameCode = (-timeFormat) >> 8;
  22376. double framesPerSecond;
  22377. switch (frameCode)
  22378. {
  22379. case 24: framesPerSecond = 24.0; break;
  22380. case 25: framesPerSecond = 25.0; break;
  22381. case 29: framesPerSecond = 29.97; break;
  22382. case 30: framesPerSecond = 30.0; break;
  22383. default: framesPerSecond = 30.0; break;
  22384. }
  22385. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22386. }
  22387. }
  22388. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22389. {
  22390. uint8 d[8];
  22391. d[0] = 0xff;
  22392. d[1] = 81;
  22393. d[2] = 3;
  22394. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22395. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22396. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22397. return MidiMessage (d, 6, 0.0);
  22398. }
  22399. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22400. {
  22401. return (data[1] == 0x58)
  22402. && (*data == (uint8) 0xff);
  22403. }
  22404. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22405. {
  22406. if (isTimeSignatureMetaEvent())
  22407. {
  22408. const uint8* const d = getMetaEventData();
  22409. numerator = d[0];
  22410. denominator = 1 << d[1];
  22411. }
  22412. else
  22413. {
  22414. numerator = 4;
  22415. denominator = 4;
  22416. }
  22417. }
  22418. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22419. {
  22420. uint8 d[8];
  22421. d[0] = 0xff;
  22422. d[1] = 0x58;
  22423. d[2] = 0x04;
  22424. d[3] = (uint8) numerator;
  22425. int n = 1;
  22426. int powerOfTwo = 0;
  22427. while (n < denominator)
  22428. {
  22429. n <<= 1;
  22430. ++powerOfTwo;
  22431. }
  22432. d[4] = (uint8) powerOfTwo;
  22433. d[5] = 0x01;
  22434. d[6] = 96;
  22435. return MidiMessage (d, 7, 0.0);
  22436. }
  22437. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22438. {
  22439. uint8 d[8];
  22440. d[0] = 0xff;
  22441. d[1] = 0x20;
  22442. d[2] = 0x01;
  22443. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22444. return MidiMessage (d, 4, 0.0);
  22445. }
  22446. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22447. {
  22448. return getMetaEventType() == 89;
  22449. }
  22450. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22451. {
  22452. return (int) *getMetaEventData();
  22453. }
  22454. const MidiMessage MidiMessage::endOfTrack() throw()
  22455. {
  22456. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22457. }
  22458. bool MidiMessage::isSongPositionPointer() const throw()
  22459. {
  22460. return *data == 0xf2;
  22461. }
  22462. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22463. {
  22464. return data[1] | (data[2] << 7);
  22465. }
  22466. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22467. {
  22468. return MidiMessage (0xf2,
  22469. positionInMidiBeats & 127,
  22470. (positionInMidiBeats >> 7) & 127);
  22471. }
  22472. bool MidiMessage::isMidiStart() const throw()
  22473. {
  22474. return *data == 0xfa;
  22475. }
  22476. const MidiMessage MidiMessage::midiStart() throw()
  22477. {
  22478. return MidiMessage (0xfa);
  22479. }
  22480. bool MidiMessage::isMidiContinue() const throw()
  22481. {
  22482. return *data == 0xfb;
  22483. }
  22484. const MidiMessage MidiMessage::midiContinue() throw()
  22485. {
  22486. return MidiMessage (0xfb);
  22487. }
  22488. bool MidiMessage::isMidiStop() const throw()
  22489. {
  22490. return *data == 0xfc;
  22491. }
  22492. const MidiMessage MidiMessage::midiStop() throw()
  22493. {
  22494. return MidiMessage (0xfc);
  22495. }
  22496. bool MidiMessage::isMidiClock() const throw()
  22497. {
  22498. return *data == 0xf8;
  22499. }
  22500. const MidiMessage MidiMessage::midiClock() throw()
  22501. {
  22502. return MidiMessage (0xf8);
  22503. }
  22504. bool MidiMessage::isQuarterFrame() const throw()
  22505. {
  22506. return *data == 0xf1;
  22507. }
  22508. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22509. {
  22510. return ((int) data[1]) >> 4;
  22511. }
  22512. int MidiMessage::getQuarterFrameValue() const throw()
  22513. {
  22514. return ((int) data[1]) & 0x0f;
  22515. }
  22516. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22517. const int value) throw()
  22518. {
  22519. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22520. }
  22521. bool MidiMessage::isFullFrame() const throw()
  22522. {
  22523. return data[0] == 0xf0
  22524. && data[1] == 0x7f
  22525. && size >= 10
  22526. && data[3] == 0x01
  22527. && data[4] == 0x01;
  22528. }
  22529. void MidiMessage::getFullFrameParameters (int& hours,
  22530. int& minutes,
  22531. int& seconds,
  22532. int& frames,
  22533. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22534. {
  22535. jassert (isFullFrame());
  22536. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22537. hours = data[5] & 0x1f;
  22538. minutes = data[6];
  22539. seconds = data[7];
  22540. frames = data[8];
  22541. }
  22542. const MidiMessage MidiMessage::fullFrame (const int hours,
  22543. const int minutes,
  22544. const int seconds,
  22545. const int frames,
  22546. MidiMessage::SmpteTimecodeType timecodeType)
  22547. {
  22548. uint8 d[10];
  22549. d[0] = 0xf0;
  22550. d[1] = 0x7f;
  22551. d[2] = 0x7f;
  22552. d[3] = 0x01;
  22553. d[4] = 0x01;
  22554. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22555. d[6] = (uint8) minutes;
  22556. d[7] = (uint8) seconds;
  22557. d[8] = (uint8) frames;
  22558. d[9] = 0xf7;
  22559. return MidiMessage (d, 10, 0.0);
  22560. }
  22561. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22562. {
  22563. return data[0] == 0xf0
  22564. && data[1] == 0x7f
  22565. && data[3] == 0x06
  22566. && size > 5;
  22567. }
  22568. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22569. {
  22570. jassert (isMidiMachineControlMessage());
  22571. return (MidiMachineControlCommand) data[4];
  22572. }
  22573. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22574. {
  22575. uint8 d[6];
  22576. d[0] = 0xf0;
  22577. d[1] = 0x7f;
  22578. d[2] = 0x00;
  22579. d[3] = 0x06;
  22580. d[4] = (uint8) command;
  22581. d[5] = 0xf7;
  22582. return MidiMessage (d, 6, 0.0);
  22583. }
  22584. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22585. int& minutes,
  22586. int& seconds,
  22587. int& frames) const throw()
  22588. {
  22589. if (size >= 12
  22590. && data[0] == 0xf0
  22591. && data[1] == 0x7f
  22592. && data[3] == 0x06
  22593. && data[4] == 0x44
  22594. && data[5] == 0x06
  22595. && data[6] == 0x01)
  22596. {
  22597. hours = data[7] % 24; // (that some machines send out hours > 24)
  22598. minutes = data[8];
  22599. seconds = data[9];
  22600. frames = data[10];
  22601. return true;
  22602. }
  22603. return false;
  22604. }
  22605. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22606. int minutes,
  22607. int seconds,
  22608. int frames)
  22609. {
  22610. uint8 d[12];
  22611. d[0] = 0xf0;
  22612. d[1] = 0x7f;
  22613. d[2] = 0x00;
  22614. d[3] = 0x06;
  22615. d[4] = 0x44;
  22616. d[5] = 0x06;
  22617. d[6] = 0x01;
  22618. d[7] = (uint8) hours;
  22619. d[8] = (uint8) minutes;
  22620. d[9] = (uint8) seconds;
  22621. d[10] = (uint8) frames;
  22622. d[11] = 0xf7;
  22623. return MidiMessage (d, 12, 0.0);
  22624. }
  22625. const String MidiMessage::getMidiNoteName (int note,
  22626. bool useSharps,
  22627. bool includeOctaveNumber,
  22628. int octaveNumForMiddleC) throw()
  22629. {
  22630. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22631. "F", "F#", "G", "G#", "A",
  22632. "A#", "B" };
  22633. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22634. "F", "Gb", "G", "Ab", "A",
  22635. "Bb", "B" };
  22636. if (((unsigned int) note) < 128)
  22637. {
  22638. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22639. : flatNoteNames [note % 12]);
  22640. if (includeOctaveNumber)
  22641. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22642. else
  22643. return s;
  22644. }
  22645. return String::empty;
  22646. }
  22647. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22648. {
  22649. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22650. return 440.0 * pow (2.0, noteNumber / 12.0);
  22651. }
  22652. const String MidiMessage::getGMInstrumentName (int n) throw()
  22653. {
  22654. const char *names[] =
  22655. {
  22656. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22657. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22658. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22659. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22660. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22661. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22662. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22663. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22664. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22665. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22666. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22667. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22668. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22669. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22670. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22671. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22672. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22673. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22674. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22675. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22676. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22677. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22678. "Applause", "Gunshot"
  22679. };
  22680. return (((unsigned int) n) < 128) ? names[n]
  22681. : (const char*)0;
  22682. }
  22683. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22684. {
  22685. const char* names[] =
  22686. {
  22687. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22688. "Bass", "Strings", "Ensemble", "Brass",
  22689. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22690. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22691. };
  22692. return (((unsigned int) n) <= 15) ? names[n]
  22693. : (const char*)0;
  22694. }
  22695. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22696. {
  22697. const char* names[] =
  22698. {
  22699. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22700. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22701. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22702. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22703. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22704. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22705. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22706. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22707. "Mute Triangle", "Open Triangle"
  22708. };
  22709. return (n >= 35 && n <= 81) ? names [n - 35]
  22710. : (const char*)0;
  22711. }
  22712. const String MidiMessage::getControllerName (int n) throw()
  22713. {
  22714. const char* names[] =
  22715. {
  22716. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22717. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22718. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22719. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22720. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22721. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22722. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22723. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22724. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22725. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22726. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22727. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22728. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22729. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22730. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22731. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22732. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22733. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22734. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22736. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22737. "Poly Operation"
  22738. };
  22739. return (((unsigned int) n) < 128) ? names[n]
  22740. : (const char*)0;
  22741. }
  22742. END_JUCE_NAMESPACE
  22743. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22744. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22745. BEGIN_JUCE_NAMESPACE
  22746. MidiMessageCollector::MidiMessageCollector()
  22747. : lastCallbackTime (0),
  22748. sampleRate (44100.0001)
  22749. {
  22750. }
  22751. MidiMessageCollector::~MidiMessageCollector()
  22752. {
  22753. }
  22754. void MidiMessageCollector::reset (const double sampleRate_)
  22755. {
  22756. jassert (sampleRate_ > 0);
  22757. const ScopedLock sl (midiCallbackLock);
  22758. sampleRate = sampleRate_;
  22759. incomingMessages.clear();
  22760. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22761. }
  22762. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22763. {
  22764. // you need to call reset() to set the correct sample rate before using this object
  22765. jassert (sampleRate != 44100.0001);
  22766. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22767. // for details of what the number should be.
  22768. jassert (message.getTimeStamp() != 0);
  22769. const ScopedLock sl (midiCallbackLock);
  22770. const int sampleNumber
  22771. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22772. incomingMessages.addEvent (message, sampleNumber);
  22773. // if the messages don't get used for over a second, we'd better
  22774. // get rid of any old ones to avoid the queue getting too big
  22775. if (sampleNumber > sampleRate)
  22776. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22777. }
  22778. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22779. const int numSamples)
  22780. {
  22781. // you need to call reset() to set the correct sample rate before using this object
  22782. jassert (sampleRate != 44100.0001);
  22783. const double timeNow = Time::getMillisecondCounterHiRes();
  22784. const double msElapsed = timeNow - lastCallbackTime;
  22785. const ScopedLock sl (midiCallbackLock);
  22786. lastCallbackTime = timeNow;
  22787. if (! incomingMessages.isEmpty())
  22788. {
  22789. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22790. int startSample = 0;
  22791. int scale = 1 << 16;
  22792. const uint8* midiData;
  22793. int numBytes, samplePosition;
  22794. MidiBuffer::Iterator iter (incomingMessages);
  22795. if (numSourceSamples > numSamples)
  22796. {
  22797. // if our list of events is longer than the buffer we're being
  22798. // asked for, scale them down to squeeze them all in..
  22799. const int maxBlockLengthToUse = numSamples << 5;
  22800. if (numSourceSamples > maxBlockLengthToUse)
  22801. {
  22802. startSample = numSourceSamples - maxBlockLengthToUse;
  22803. numSourceSamples = maxBlockLengthToUse;
  22804. iter.setNextSamplePosition (startSample);
  22805. }
  22806. scale = (numSamples << 10) / numSourceSamples;
  22807. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22808. {
  22809. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22810. destBuffer.addEvent (midiData, numBytes,
  22811. jlimit (0, numSamples - 1, samplePosition));
  22812. }
  22813. }
  22814. else
  22815. {
  22816. // if our event list is shorter than the number we need, put them
  22817. // towards the end of the buffer
  22818. startSample = numSamples - numSourceSamples;
  22819. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22820. {
  22821. destBuffer.addEvent (midiData, numBytes,
  22822. jlimit (0, numSamples - 1, samplePosition + startSample));
  22823. }
  22824. }
  22825. incomingMessages.clear();
  22826. }
  22827. }
  22828. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22829. {
  22830. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22831. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22832. addMessageToQueue (m);
  22833. }
  22834. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22835. {
  22836. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22837. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22838. addMessageToQueue (m);
  22839. }
  22840. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22841. {
  22842. addMessageToQueue (message);
  22843. }
  22844. END_JUCE_NAMESPACE
  22845. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22846. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22847. BEGIN_JUCE_NAMESPACE
  22848. MidiMessageSequence::MidiMessageSequence()
  22849. {
  22850. }
  22851. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22852. {
  22853. list.ensureStorageAllocated (other.list.size());
  22854. for (int i = 0; i < other.list.size(); ++i)
  22855. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22856. }
  22857. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22858. {
  22859. MidiMessageSequence otherCopy (other);
  22860. swapWith (otherCopy);
  22861. return *this;
  22862. }
  22863. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22864. {
  22865. list.swapWithArray (other.list);
  22866. }
  22867. MidiMessageSequence::~MidiMessageSequence()
  22868. {
  22869. }
  22870. void MidiMessageSequence::clear()
  22871. {
  22872. list.clear();
  22873. }
  22874. int MidiMessageSequence::getNumEvents() const
  22875. {
  22876. return list.size();
  22877. }
  22878. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22879. {
  22880. return list [index];
  22881. }
  22882. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22883. {
  22884. const MidiEventHolder* const meh = list [index];
  22885. if (meh != 0 && meh->noteOffObject != 0)
  22886. return meh->noteOffObject->message.getTimeStamp();
  22887. else
  22888. return 0.0;
  22889. }
  22890. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22891. {
  22892. const MidiEventHolder* const meh = list [index];
  22893. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22894. }
  22895. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22896. {
  22897. return list.indexOf (event);
  22898. }
  22899. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22900. {
  22901. const int numEvents = list.size();
  22902. int i;
  22903. for (i = 0; i < numEvents; ++i)
  22904. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22905. break;
  22906. return i;
  22907. }
  22908. double MidiMessageSequence::getStartTime() const
  22909. {
  22910. if (list.size() > 0)
  22911. return list.getUnchecked(0)->message.getTimeStamp();
  22912. else
  22913. return 0;
  22914. }
  22915. double MidiMessageSequence::getEndTime() const
  22916. {
  22917. if (list.size() > 0)
  22918. return list.getLast()->message.getTimeStamp();
  22919. else
  22920. return 0;
  22921. }
  22922. double MidiMessageSequence::getEventTime (const int index) const
  22923. {
  22924. if (((unsigned int) index) < (unsigned int) list.size())
  22925. return list.getUnchecked (index)->message.getTimeStamp();
  22926. return 0.0;
  22927. }
  22928. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22929. double timeAdjustment)
  22930. {
  22931. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22932. timeAdjustment += newMessage.getTimeStamp();
  22933. newOne->message.setTimeStamp (timeAdjustment);
  22934. int i;
  22935. for (i = list.size(); --i >= 0;)
  22936. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22937. break;
  22938. list.insert (i + 1, newOne);
  22939. }
  22940. void MidiMessageSequence::deleteEvent (const int index,
  22941. const bool deleteMatchingNoteUp)
  22942. {
  22943. if (((unsigned int) index) < (unsigned int) list.size())
  22944. {
  22945. if (deleteMatchingNoteUp)
  22946. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22947. list.remove (index);
  22948. }
  22949. }
  22950. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  22951. double timeAdjustment,
  22952. double firstAllowableTime,
  22953. double endOfAllowableDestTimes)
  22954. {
  22955. firstAllowableTime -= timeAdjustment;
  22956. endOfAllowableDestTimes -= timeAdjustment;
  22957. for (int i = 0; i < other.list.size(); ++i)
  22958. {
  22959. const MidiMessage& m = other.list.getUnchecked(i)->message;
  22960. const double t = m.getTimeStamp();
  22961. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  22962. {
  22963. MidiEventHolder* const newOne = new MidiEventHolder (m);
  22964. newOne->message.setTimeStamp (timeAdjustment + t);
  22965. list.add (newOne);
  22966. }
  22967. }
  22968. sort();
  22969. }
  22970. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  22971. const MidiMessageSequence::MidiEventHolder* const second) throw()
  22972. {
  22973. const double diff = first->message.getTimeStamp()
  22974. - second->message.getTimeStamp();
  22975. return (diff > 0) - (diff < 0);
  22976. }
  22977. void MidiMessageSequence::sort()
  22978. {
  22979. list.sort (*this, true);
  22980. }
  22981. void MidiMessageSequence::updateMatchedPairs()
  22982. {
  22983. for (int i = 0; i < list.size(); ++i)
  22984. {
  22985. const MidiMessage& m1 = list.getUnchecked(i)->message;
  22986. if (m1.isNoteOn())
  22987. {
  22988. list.getUnchecked(i)->noteOffObject = 0;
  22989. const int note = m1.getNoteNumber();
  22990. const int chan = m1.getChannel();
  22991. const int len = list.size();
  22992. for (int j = i + 1; j < len; ++j)
  22993. {
  22994. const MidiMessage& m = list.getUnchecked(j)->message;
  22995. if (m.getNoteNumber() == note && m.getChannel() == chan)
  22996. {
  22997. if (m.isNoteOff())
  22998. {
  22999. list.getUnchecked(i)->noteOffObject = list[j];
  23000. break;
  23001. }
  23002. else if (m.isNoteOn())
  23003. {
  23004. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23005. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23006. list.getUnchecked(i)->noteOffObject = list[j];
  23007. break;
  23008. }
  23009. }
  23010. }
  23011. }
  23012. }
  23013. }
  23014. void MidiMessageSequence::addTimeToMessages (const double delta)
  23015. {
  23016. for (int i = list.size(); --i >= 0;)
  23017. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23018. + delta);
  23019. }
  23020. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23021. MidiMessageSequence& destSequence,
  23022. const bool alsoIncludeMetaEvents) const
  23023. {
  23024. for (int i = 0; i < list.size(); ++i)
  23025. {
  23026. const MidiMessage& mm = list.getUnchecked(i)->message;
  23027. if (mm.isForChannel (channelNumberToExtract)
  23028. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23029. {
  23030. destSequence.addEvent (mm);
  23031. }
  23032. }
  23033. }
  23034. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23035. {
  23036. for (int i = 0; i < list.size(); ++i)
  23037. {
  23038. const MidiMessage& mm = list.getUnchecked(i)->message;
  23039. if (mm.isSysEx())
  23040. destSequence.addEvent (mm);
  23041. }
  23042. }
  23043. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23044. {
  23045. for (int i = list.size(); --i >= 0;)
  23046. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23047. list.remove(i);
  23048. }
  23049. void MidiMessageSequence::deleteSysExMessages()
  23050. {
  23051. for (int i = list.size(); --i >= 0;)
  23052. if (list.getUnchecked(i)->message.isSysEx())
  23053. list.remove(i);
  23054. }
  23055. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23056. const double time,
  23057. OwnedArray<MidiMessage>& dest)
  23058. {
  23059. bool doneProg = false;
  23060. bool donePitchWheel = false;
  23061. Array <int> doneControllers;
  23062. doneControllers.ensureStorageAllocated (32);
  23063. for (int i = list.size(); --i >= 0;)
  23064. {
  23065. const MidiMessage& mm = list.getUnchecked(i)->message;
  23066. if (mm.isForChannel (channelNumber)
  23067. && mm.getTimeStamp() <= time)
  23068. {
  23069. if (mm.isProgramChange())
  23070. {
  23071. if (! doneProg)
  23072. {
  23073. dest.add (new MidiMessage (mm, 0.0));
  23074. doneProg = true;
  23075. }
  23076. }
  23077. else if (mm.isController())
  23078. {
  23079. if (! doneControllers.contains (mm.getControllerNumber()))
  23080. {
  23081. dest.add (new MidiMessage (mm, 0.0));
  23082. doneControllers.add (mm.getControllerNumber());
  23083. }
  23084. }
  23085. else if (mm.isPitchWheel())
  23086. {
  23087. if (! donePitchWheel)
  23088. {
  23089. dest.add (new MidiMessage (mm, 0.0));
  23090. donePitchWheel = true;
  23091. }
  23092. }
  23093. }
  23094. }
  23095. }
  23096. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23097. : message (message_),
  23098. noteOffObject (0)
  23099. {
  23100. }
  23101. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23102. {
  23103. }
  23104. END_JUCE_NAMESPACE
  23105. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23106. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23107. BEGIN_JUCE_NAMESPACE
  23108. AudioPluginFormat::AudioPluginFormat() throw()
  23109. {
  23110. }
  23111. AudioPluginFormat::~AudioPluginFormat()
  23112. {
  23113. }
  23114. END_JUCE_NAMESPACE
  23115. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23116. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23117. BEGIN_JUCE_NAMESPACE
  23118. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23119. {
  23120. }
  23121. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23122. {
  23123. clearSingletonInstance();
  23124. }
  23125. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23126. void AudioPluginFormatManager::addDefaultFormats()
  23127. {
  23128. #ifdef JUCE_DEBUG
  23129. // you should only call this method once!
  23130. for (int i = formats.size(); --i >= 0;)
  23131. {
  23132. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23133. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23134. #endif
  23135. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23136. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23137. #endif
  23138. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23139. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23140. #endif
  23141. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23142. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23143. #endif
  23144. }
  23145. #endif
  23146. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23147. formats.add (new AudioUnitPluginFormat());
  23148. #endif
  23149. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23150. formats.add (new VSTPluginFormat());
  23151. #endif
  23152. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23153. formats.add (new DirectXPluginFormat());
  23154. #endif
  23155. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23156. formats.add (new LADSPAPluginFormat());
  23157. #endif
  23158. }
  23159. int AudioPluginFormatManager::getNumFormats() throw()
  23160. {
  23161. return formats.size();
  23162. }
  23163. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23164. {
  23165. return formats [index];
  23166. }
  23167. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23168. {
  23169. formats.add (format);
  23170. }
  23171. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23172. String& errorMessage) const
  23173. {
  23174. AudioPluginInstance* result = 0;
  23175. for (int i = 0; i < formats.size(); ++i)
  23176. {
  23177. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23178. if (result != 0)
  23179. break;
  23180. }
  23181. if (result == 0)
  23182. {
  23183. if (! doesPluginStillExist (description))
  23184. errorMessage = TRANS ("This plug-in file no longer exists");
  23185. else
  23186. errorMessage = TRANS ("This plug-in failed to load correctly");
  23187. }
  23188. return result;
  23189. }
  23190. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23191. {
  23192. for (int i = 0; i < formats.size(); ++i)
  23193. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23194. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23195. return false;
  23196. }
  23197. END_JUCE_NAMESPACE
  23198. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23199. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23200. #define JUCE_PLUGIN_HOST 1
  23201. BEGIN_JUCE_NAMESPACE
  23202. AudioPluginInstance::AudioPluginInstance()
  23203. {
  23204. }
  23205. AudioPluginInstance::~AudioPluginInstance()
  23206. {
  23207. }
  23208. END_JUCE_NAMESPACE
  23209. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23210. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23211. BEGIN_JUCE_NAMESPACE
  23212. KnownPluginList::KnownPluginList()
  23213. {
  23214. }
  23215. KnownPluginList::~KnownPluginList()
  23216. {
  23217. }
  23218. void KnownPluginList::clear()
  23219. {
  23220. if (types.size() > 0)
  23221. {
  23222. types.clear();
  23223. sendChangeMessage (this);
  23224. }
  23225. }
  23226. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23227. {
  23228. for (int i = 0; i < types.size(); ++i)
  23229. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23230. return types.getUnchecked(i);
  23231. return 0;
  23232. }
  23233. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23234. {
  23235. for (int i = 0; i < types.size(); ++i)
  23236. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23237. return types.getUnchecked(i);
  23238. return 0;
  23239. }
  23240. bool KnownPluginList::addType (const PluginDescription& type)
  23241. {
  23242. for (int i = types.size(); --i >= 0;)
  23243. {
  23244. if (types.getUnchecked(i)->isDuplicateOf (type))
  23245. {
  23246. // strange - found a duplicate plugin with different info..
  23247. jassert (types.getUnchecked(i)->name == type.name);
  23248. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23249. *types.getUnchecked(i) = type;
  23250. return false;
  23251. }
  23252. }
  23253. types.add (new PluginDescription (type));
  23254. sendChangeMessage (this);
  23255. return true;
  23256. }
  23257. void KnownPluginList::removeType (const int index) throw()
  23258. {
  23259. types.remove (index);
  23260. sendChangeMessage (this);
  23261. }
  23262. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23263. {
  23264. if (fileOrIdentifier.startsWithChar ('/')
  23265. || fileOrIdentifier[1] == ':')
  23266. {
  23267. return File (fileOrIdentifier).getLastModificationTime();
  23268. }
  23269. return Time (0);
  23270. }
  23271. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23272. {
  23273. return t1 != t2 || t1 == Time (0);
  23274. }
  23275. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23276. {
  23277. if (getTypeForFile (fileOrIdentifier) == 0)
  23278. return false;
  23279. for (int i = types.size(); --i >= 0;)
  23280. {
  23281. const PluginDescription* const d = types.getUnchecked(i);
  23282. if (d->fileOrIdentifier == fileOrIdentifier
  23283. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23284. {
  23285. return false;
  23286. }
  23287. }
  23288. return true;
  23289. }
  23290. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23291. const bool dontRescanIfAlreadyInList,
  23292. OwnedArray <PluginDescription>& typesFound,
  23293. AudioPluginFormat& format)
  23294. {
  23295. bool addedOne = false;
  23296. if (dontRescanIfAlreadyInList
  23297. && getTypeForFile (fileOrIdentifier) != 0)
  23298. {
  23299. bool needsRescanning = false;
  23300. for (int i = types.size(); --i >= 0;)
  23301. {
  23302. const PluginDescription* const d = types.getUnchecked(i);
  23303. if (d->fileOrIdentifier == fileOrIdentifier)
  23304. {
  23305. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23306. needsRescanning = true;
  23307. else
  23308. typesFound.add (new PluginDescription (*d));
  23309. }
  23310. }
  23311. if (! needsRescanning)
  23312. return false;
  23313. }
  23314. OwnedArray <PluginDescription> found;
  23315. format.findAllTypesForFile (found, fileOrIdentifier);
  23316. for (int i = 0; i < found.size(); ++i)
  23317. {
  23318. PluginDescription* const desc = found.getUnchecked(i);
  23319. jassert (desc != 0);
  23320. if (addType (*desc))
  23321. addedOne = true;
  23322. typesFound.add (new PluginDescription (*desc));
  23323. }
  23324. return addedOne;
  23325. }
  23326. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23327. OwnedArray <PluginDescription>& typesFound)
  23328. {
  23329. for (int i = 0; i < files.size(); ++i)
  23330. {
  23331. bool loaded = false;
  23332. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23333. {
  23334. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23335. if (scanAndAddFile (files[i], true, typesFound, *format))
  23336. loaded = true;
  23337. }
  23338. if (! loaded)
  23339. {
  23340. const File f (files[i]);
  23341. if (f.isDirectory())
  23342. {
  23343. StringArray s;
  23344. {
  23345. Array<File> subFiles;
  23346. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23347. for (int j = 0; j < subFiles.size(); ++j)
  23348. s.add (subFiles.getReference(j).getFullPathName());
  23349. }
  23350. scanAndAddDragAndDroppedFiles (s, typesFound);
  23351. }
  23352. }
  23353. }
  23354. }
  23355. class PluginSorter
  23356. {
  23357. public:
  23358. KnownPluginList::SortMethod method;
  23359. PluginSorter() throw() {}
  23360. int compareElements (const PluginDescription* const first,
  23361. const PluginDescription* const second) const throw()
  23362. {
  23363. int diff = 0;
  23364. if (method == KnownPluginList::sortByCategory)
  23365. diff = first->category.compareLexicographically (second->category);
  23366. else if (method == KnownPluginList::sortByManufacturer)
  23367. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23368. else if (method == KnownPluginList::sortByFileSystemLocation)
  23369. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23370. .upToLastOccurrenceOf ("/", false, false)
  23371. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23372. .upToLastOccurrenceOf ("/", false, false));
  23373. if (diff == 0)
  23374. diff = first->name.compareLexicographically (second->name);
  23375. return diff;
  23376. }
  23377. };
  23378. void KnownPluginList::sort (const SortMethod method)
  23379. {
  23380. if (method != defaultOrder)
  23381. {
  23382. PluginSorter sorter;
  23383. sorter.method = method;
  23384. types.sort (sorter, true);
  23385. sendChangeMessage (this);
  23386. }
  23387. }
  23388. XmlElement* KnownPluginList::createXml() const
  23389. {
  23390. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23391. for (int i = 0; i < types.size(); ++i)
  23392. e->addChildElement (types.getUnchecked(i)->createXml());
  23393. return e;
  23394. }
  23395. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23396. {
  23397. clear();
  23398. if (xml.hasTagName ("KNOWNPLUGINS"))
  23399. {
  23400. forEachXmlChildElement (xml, e)
  23401. {
  23402. PluginDescription info;
  23403. if (info.loadFromXml (*e))
  23404. addType (info);
  23405. }
  23406. }
  23407. }
  23408. const int menuIdBase = 0x324503f4;
  23409. // This is used to turn a bunch of paths into a nested menu structure.
  23410. struct PluginFilesystemTree
  23411. {
  23412. private:
  23413. String folder;
  23414. OwnedArray <PluginFilesystemTree> subFolders;
  23415. Array <PluginDescription*> plugins;
  23416. void addPlugin (PluginDescription* const pd, const String& path)
  23417. {
  23418. if (path.isEmpty())
  23419. {
  23420. plugins.add (pd);
  23421. }
  23422. else
  23423. {
  23424. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23425. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23426. for (int i = subFolders.size(); --i >= 0;)
  23427. {
  23428. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23429. {
  23430. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23431. return;
  23432. }
  23433. }
  23434. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23435. newFolder->folder = firstSubFolder;
  23436. subFolders.add (newFolder);
  23437. newFolder->addPlugin (pd, remainingPath);
  23438. }
  23439. }
  23440. // removes any deeply nested folders that don't contain any actual plugins
  23441. void optimise()
  23442. {
  23443. for (int i = subFolders.size(); --i >= 0;)
  23444. {
  23445. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23446. sub->optimise();
  23447. if (sub->plugins.size() == 0)
  23448. {
  23449. for (int j = 0; j < sub->subFolders.size(); ++j)
  23450. subFolders.add (sub->subFolders.getUnchecked(j));
  23451. sub->subFolders.clear (false);
  23452. subFolders.remove (i);
  23453. }
  23454. }
  23455. }
  23456. public:
  23457. void buildTree (const Array <PluginDescription*>& allPlugins)
  23458. {
  23459. for (int i = 0; i < allPlugins.size(); ++i)
  23460. {
  23461. String path (allPlugins.getUnchecked(i)
  23462. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23463. .upToLastOccurrenceOf ("/", false, false));
  23464. if (path.substring (1, 2) == ":")
  23465. path = path.substring (2);
  23466. addPlugin (allPlugins.getUnchecked(i), path);
  23467. }
  23468. optimise();
  23469. }
  23470. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23471. {
  23472. int i;
  23473. for (i = 0; i < subFolders.size(); ++i)
  23474. {
  23475. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23476. PopupMenu subMenu;
  23477. sub->addToMenu (subMenu, allPlugins);
  23478. #if JUCE_MAC
  23479. // avoid the special AU formatting nonsense on Mac..
  23480. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23481. #else
  23482. m.addSubMenu (sub->folder, subMenu);
  23483. #endif
  23484. }
  23485. for (i = 0; i < plugins.size(); ++i)
  23486. {
  23487. PluginDescription* const plugin = plugins.getUnchecked(i);
  23488. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23489. plugin->name, true, false);
  23490. }
  23491. }
  23492. };
  23493. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23494. {
  23495. Array <PluginDescription*> sorted;
  23496. {
  23497. PluginSorter sorter;
  23498. sorter.method = sortMethod;
  23499. for (int i = 0; i < types.size(); ++i)
  23500. sorted.addSorted (sorter, types.getUnchecked(i));
  23501. }
  23502. if (sortMethod == sortByCategory
  23503. || sortMethod == sortByManufacturer)
  23504. {
  23505. String lastSubMenuName;
  23506. PopupMenu sub;
  23507. for (int i = 0; i < sorted.size(); ++i)
  23508. {
  23509. const PluginDescription* const pd = sorted.getUnchecked(i);
  23510. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23511. : pd->manufacturerName);
  23512. if (! thisSubMenuName.containsNonWhitespaceChars())
  23513. thisSubMenuName = "Other";
  23514. if (thisSubMenuName != lastSubMenuName)
  23515. {
  23516. if (sub.getNumItems() > 0)
  23517. {
  23518. menu.addSubMenu (lastSubMenuName, sub);
  23519. sub.clear();
  23520. }
  23521. lastSubMenuName = thisSubMenuName;
  23522. }
  23523. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23524. }
  23525. if (sub.getNumItems() > 0)
  23526. menu.addSubMenu (lastSubMenuName, sub);
  23527. }
  23528. else if (sortMethod == sortByFileSystemLocation)
  23529. {
  23530. PluginFilesystemTree root;
  23531. root.buildTree (sorted);
  23532. root.addToMenu (menu, types);
  23533. }
  23534. else
  23535. {
  23536. for (int i = 0; i < sorted.size(); ++i)
  23537. {
  23538. const PluginDescription* const pd = sorted.getUnchecked(i);
  23539. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23540. }
  23541. }
  23542. }
  23543. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23544. {
  23545. const int i = menuResultCode - menuIdBase;
  23546. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23547. }
  23548. END_JUCE_NAMESPACE
  23549. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23550. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23551. BEGIN_JUCE_NAMESPACE
  23552. PluginDescription::PluginDescription() throw()
  23553. : uid (0),
  23554. isInstrument (false),
  23555. numInputChannels (0),
  23556. numOutputChannels (0)
  23557. {
  23558. }
  23559. PluginDescription::~PluginDescription() throw()
  23560. {
  23561. }
  23562. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23563. : name (other.name),
  23564. pluginFormatName (other.pluginFormatName),
  23565. category (other.category),
  23566. manufacturerName (other.manufacturerName),
  23567. version (other.version),
  23568. fileOrIdentifier (other.fileOrIdentifier),
  23569. lastFileModTime (other.lastFileModTime),
  23570. uid (other.uid),
  23571. isInstrument (other.isInstrument),
  23572. numInputChannels (other.numInputChannels),
  23573. numOutputChannels (other.numOutputChannels)
  23574. {
  23575. }
  23576. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23577. {
  23578. name = other.name;
  23579. pluginFormatName = other.pluginFormatName;
  23580. category = other.category;
  23581. manufacturerName = other.manufacturerName;
  23582. version = other.version;
  23583. fileOrIdentifier = other.fileOrIdentifier;
  23584. uid = other.uid;
  23585. isInstrument = other.isInstrument;
  23586. lastFileModTime = other.lastFileModTime;
  23587. numInputChannels = other.numInputChannels;
  23588. numOutputChannels = other.numOutputChannels;
  23589. return *this;
  23590. }
  23591. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23592. {
  23593. return fileOrIdentifier == other.fileOrIdentifier
  23594. && uid == other.uid;
  23595. }
  23596. const String PluginDescription::createIdentifierString() const throw()
  23597. {
  23598. return pluginFormatName
  23599. + "-" + name
  23600. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23601. + "-" + String::toHexString (uid);
  23602. }
  23603. XmlElement* PluginDescription::createXml() const
  23604. {
  23605. XmlElement* const e = new XmlElement ("PLUGIN");
  23606. e->setAttribute ("name", name);
  23607. e->setAttribute ("format", pluginFormatName);
  23608. e->setAttribute ("category", category);
  23609. e->setAttribute ("manufacturer", manufacturerName);
  23610. e->setAttribute ("version", version);
  23611. e->setAttribute ("file", fileOrIdentifier);
  23612. e->setAttribute ("uid", String::toHexString (uid));
  23613. e->setAttribute ("isInstrument", isInstrument);
  23614. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23615. e->setAttribute ("numInputs", numInputChannels);
  23616. e->setAttribute ("numOutputs", numOutputChannels);
  23617. return e;
  23618. }
  23619. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23620. {
  23621. if (xml.hasTagName ("PLUGIN"))
  23622. {
  23623. name = xml.getStringAttribute ("name");
  23624. pluginFormatName = xml.getStringAttribute ("format");
  23625. category = xml.getStringAttribute ("category");
  23626. manufacturerName = xml.getStringAttribute ("manufacturer");
  23627. version = xml.getStringAttribute ("version");
  23628. fileOrIdentifier = xml.getStringAttribute ("file");
  23629. uid = xml.getStringAttribute ("uid").getHexValue32();
  23630. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23631. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23632. numInputChannels = xml.getIntAttribute ("numInputs");
  23633. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23634. return true;
  23635. }
  23636. return false;
  23637. }
  23638. END_JUCE_NAMESPACE
  23639. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23640. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23641. BEGIN_JUCE_NAMESPACE
  23642. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23643. AudioPluginFormat& formatToLookFor,
  23644. FileSearchPath directoriesToSearch,
  23645. const bool recursive,
  23646. const File& deadMansPedalFile_)
  23647. : list (listToAddTo),
  23648. format (formatToLookFor),
  23649. deadMansPedalFile (deadMansPedalFile_),
  23650. nextIndex (0),
  23651. progress (0)
  23652. {
  23653. directoriesToSearch.removeRedundantPaths();
  23654. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23655. // If any plugins have crashed recently when being loaded, move them to the
  23656. // end of the list to give the others a chance to load correctly..
  23657. const StringArray crashedPlugins (getDeadMansPedalFile());
  23658. for (int i = 0; i < crashedPlugins.size(); ++i)
  23659. {
  23660. const String f = crashedPlugins[i];
  23661. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23662. if (f == filesOrIdentifiersToScan[j])
  23663. filesOrIdentifiersToScan.move (j, -1);
  23664. }
  23665. }
  23666. PluginDirectoryScanner::~PluginDirectoryScanner()
  23667. {
  23668. }
  23669. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23670. {
  23671. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23672. }
  23673. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23674. {
  23675. String file (filesOrIdentifiersToScan [nextIndex]);
  23676. if (file.isNotEmpty())
  23677. {
  23678. if (! list.isListingUpToDate (file))
  23679. {
  23680. OwnedArray <PluginDescription> typesFound;
  23681. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23682. StringArray crashedPlugins (getDeadMansPedalFile());
  23683. crashedPlugins.removeString (file);
  23684. crashedPlugins.add (file);
  23685. setDeadMansPedalFile (crashedPlugins);
  23686. list.scanAndAddFile (file,
  23687. dontRescanIfAlreadyInList,
  23688. typesFound,
  23689. format);
  23690. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23691. crashedPlugins.removeString (file);
  23692. setDeadMansPedalFile (crashedPlugins);
  23693. if (typesFound.size() == 0)
  23694. failedFiles.add (file);
  23695. }
  23696. ++nextIndex;
  23697. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23698. }
  23699. return nextIndex < filesOrIdentifiersToScan.size();
  23700. }
  23701. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23702. {
  23703. StringArray lines;
  23704. if (deadMansPedalFile != File::nonexistent)
  23705. {
  23706. lines.addLines (deadMansPedalFile.loadFileAsString());
  23707. lines.removeEmptyStrings();
  23708. }
  23709. return lines;
  23710. }
  23711. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23712. {
  23713. if (deadMansPedalFile != File::nonexistent)
  23714. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23715. }
  23716. END_JUCE_NAMESPACE
  23717. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23718. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23719. BEGIN_JUCE_NAMESPACE
  23720. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23721. const File& deadMansPedalFile_,
  23722. PropertiesFile* const propertiesToUse_)
  23723. : list (listToEdit),
  23724. deadMansPedalFile (deadMansPedalFile_),
  23725. propertiesToUse (propertiesToUse_)
  23726. {
  23727. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23728. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23729. optionsButton->addButtonListener (this);
  23730. optionsButton->setTriggeredOnMouseDown (true);
  23731. setSize (400, 600);
  23732. list.addChangeListener (this);
  23733. }
  23734. PluginListComponent::~PluginListComponent()
  23735. {
  23736. list.removeChangeListener (this);
  23737. deleteAllChildren();
  23738. }
  23739. void PluginListComponent::resized()
  23740. {
  23741. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23742. optionsButton->changeWidthToFitText (24);
  23743. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23744. }
  23745. void PluginListComponent::changeListenerCallback (void*)
  23746. {
  23747. listBox->updateContent();
  23748. listBox->repaint();
  23749. }
  23750. int PluginListComponent::getNumRows()
  23751. {
  23752. return list.getNumTypes();
  23753. }
  23754. void PluginListComponent::paintListBoxItem (int row,
  23755. Graphics& g,
  23756. int width, int height,
  23757. bool rowIsSelected)
  23758. {
  23759. if (rowIsSelected)
  23760. g.fillAll (findColour (TextEditor::highlightColourId));
  23761. const PluginDescription* const pd = list.getType (row);
  23762. if (pd != 0)
  23763. {
  23764. GlyphArrangement ga;
  23765. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23766. g.setColour (Colours::black);
  23767. ga.draw (g);
  23768. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  23769. String desc;
  23770. desc << pd->pluginFormatName
  23771. << (pd->isInstrument ? " instrument" : " effect")
  23772. << " - "
  23773. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23774. << " / "
  23775. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23776. if (pd->manufacturerName.isNotEmpty())
  23777. desc << " - " << pd->manufacturerName;
  23778. if (pd->version.isNotEmpty())
  23779. desc << " - " << pd->version;
  23780. if (pd->category.isNotEmpty())
  23781. desc << " - category: '" << pd->category << '\'';
  23782. g.setColour (Colours::grey);
  23783. ga.clear();
  23784. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, bb.getRight() + 10.0f, height * 0.8f, width - bb.getRight() - 12.0f, true);
  23785. ga.draw (g);
  23786. }
  23787. }
  23788. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23789. {
  23790. list.removeType (lastRowSelected);
  23791. }
  23792. void PluginListComponent::buttonClicked (Button* b)
  23793. {
  23794. if (optionsButton == b)
  23795. {
  23796. PopupMenu menu;
  23797. menu.addItem (1, TRANS("Clear list"));
  23798. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23799. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23800. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23801. menu.addSeparator();
  23802. menu.addItem (2, TRANS("Sort alphabetically"));
  23803. menu.addItem (3, TRANS("Sort by category"));
  23804. menu.addItem (4, TRANS("Sort by manufacturer"));
  23805. menu.addSeparator();
  23806. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23807. {
  23808. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23809. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23810. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23811. }
  23812. const int r = menu.showAt (optionsButton);
  23813. if (r == 1)
  23814. {
  23815. list.clear();
  23816. }
  23817. else if (r == 2)
  23818. {
  23819. list.sort (KnownPluginList::sortAlphabetically);
  23820. }
  23821. else if (r == 3)
  23822. {
  23823. list.sort (KnownPluginList::sortByCategory);
  23824. }
  23825. else if (r == 4)
  23826. {
  23827. list.sort (KnownPluginList::sortByManufacturer);
  23828. }
  23829. else if (r == 5)
  23830. {
  23831. const SparseSet <int> selected (listBox->getSelectedRows());
  23832. for (int i = list.getNumTypes(); --i >= 0;)
  23833. if (selected.contains (i))
  23834. list.removeType (i);
  23835. }
  23836. else if (r == 6)
  23837. {
  23838. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23839. if (desc != 0)
  23840. {
  23841. if (File (desc->fileOrIdentifier).existsAsFile())
  23842. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23843. }
  23844. }
  23845. else if (r == 7)
  23846. {
  23847. for (int i = list.getNumTypes(); --i >= 0;)
  23848. {
  23849. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23850. {
  23851. list.removeType (i);
  23852. }
  23853. }
  23854. }
  23855. else if (r != 0)
  23856. {
  23857. typeToScan = r - 10;
  23858. startTimer (1);
  23859. }
  23860. }
  23861. }
  23862. void PluginListComponent::timerCallback()
  23863. {
  23864. stopTimer();
  23865. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23866. }
  23867. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23868. {
  23869. return true;
  23870. }
  23871. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23872. {
  23873. OwnedArray <PluginDescription> typesFound;
  23874. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23875. }
  23876. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23877. {
  23878. if (format == 0)
  23879. return;
  23880. FileSearchPath path (format->getDefaultLocationsToSearch());
  23881. if (propertiesToUse != 0)
  23882. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23883. {
  23884. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23885. FileSearchPathListComponent pathList;
  23886. pathList.setSize (500, 300);
  23887. pathList.setPath (path);
  23888. aw.addCustomComponent (&pathList);
  23889. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23890. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23891. if (aw.runModalLoop() == 0)
  23892. return;
  23893. path = pathList.getPath();
  23894. }
  23895. if (propertiesToUse != 0)
  23896. {
  23897. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23898. propertiesToUse->saveIfNeeded();
  23899. }
  23900. double progress = 0.0;
  23901. AlertWindow aw (TRANS("Scanning for plugins..."),
  23902. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23903. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23904. aw.addProgressBarComponent (progress);
  23905. aw.enterModalState();
  23906. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23907. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23908. for (;;)
  23909. {
  23910. aw.setMessage (TRANS("Testing:\n\n")
  23911. + scanner.getNextPluginFileThatWillBeScanned());
  23912. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23913. if (! scanner.scanNextFile (true))
  23914. break;
  23915. if (! aw.isCurrentlyModal())
  23916. break;
  23917. progress = scanner.getProgress();
  23918. }
  23919. if (scanner.getFailedFiles().size() > 0)
  23920. {
  23921. StringArray shortNames;
  23922. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23923. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23924. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23925. TRANS("Scan complete"),
  23926. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23927. + shortNames.joinIntoString (", "));
  23928. }
  23929. }
  23930. END_JUCE_NAMESPACE
  23931. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23932. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23933. #if JUCE_PLUGINHOST_AU && ! (JUCE_LINUX || JUCE_WINDOWS)
  23934. #include <AudioUnit/AudioUnit.h>
  23935. #include <AudioUnit/AUCocoaUIView.h>
  23936. #include <CoreAudioKit/AUGenericView.h>
  23937. #if JUCE_SUPPORT_CARBON
  23938. #include <AudioToolbox/AudioUnitUtilities.h>
  23939. #include <AudioUnit/AudioUnitCarbonView.h>
  23940. #endif
  23941. BEGIN_JUCE_NAMESPACE
  23942. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23943. #endif
  23944. #if JUCE_MAC
  23945. // Change this to disable logging of various activities
  23946. #ifndef AU_LOGGING
  23947. #define AU_LOGGING 1
  23948. #endif
  23949. #if AU_LOGGING
  23950. #define log(a) Logger::writeToLog(a);
  23951. #else
  23952. #define log(a)
  23953. #endif
  23954. static int insideCallback = 0;
  23955. static const String osTypeToString (OSType type)
  23956. {
  23957. char s[4];
  23958. s[0] = (char) (((uint32) type) >> 24);
  23959. s[1] = (char) (((uint32) type) >> 16);
  23960. s[2] = (char) (((uint32) type) >> 8);
  23961. s[3] = (char) ((uint32) type);
  23962. return String (s, 4);
  23963. }
  23964. static OSType stringToOSType (const String& s1)
  23965. {
  23966. const String s (s1 + " ");
  23967. return (((OSType) (unsigned char) s[0]) << 24)
  23968. | (((OSType) (unsigned char) s[1]) << 16)
  23969. | (((OSType) (unsigned char) s[2]) << 8)
  23970. | ((OSType) (unsigned char) s[3]);
  23971. }
  23972. static const char* auIdentifierPrefix = "AudioUnit:";
  23973. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  23974. {
  23975. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  23976. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  23977. String s (auIdentifierPrefix);
  23978. if (desc.componentType == kAudioUnitType_MusicDevice)
  23979. s << "Synths/";
  23980. else if (desc.componentType == kAudioUnitType_MusicEffect
  23981. || desc.componentType == kAudioUnitType_Effect)
  23982. s << "Effects/";
  23983. else if (desc.componentType == kAudioUnitType_Generator)
  23984. s << "Generators/";
  23985. else if (desc.componentType == kAudioUnitType_Panner)
  23986. s << "Panners/";
  23987. s << osTypeToString (desc.componentType) << ","
  23988. << osTypeToString (desc.componentSubType) << ","
  23989. << osTypeToString (desc.componentManufacturer);
  23990. return s;
  23991. }
  23992. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  23993. {
  23994. Handle componentNameHandle = NewHandle (sizeof (void*));
  23995. Handle componentInfoHandle = NewHandle (sizeof (void*));
  23996. if (componentNameHandle != 0 && componentInfoHandle != 0)
  23997. {
  23998. ComponentDescription desc;
  23999. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24000. {
  24001. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24002. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24003. if (nameString != 0 && nameString[0] != 0)
  24004. {
  24005. const String all ((const char*) nameString + 1, nameString[0]);
  24006. DBG ("name: "+ all);
  24007. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  24008. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  24009. }
  24010. if (infoString != 0 && infoString[0] != 0)
  24011. {
  24012. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24013. }
  24014. if (name.isEmpty())
  24015. name = "<Unknown>";
  24016. }
  24017. DisposeHandle (componentNameHandle);
  24018. DisposeHandle (componentInfoHandle);
  24019. }
  24020. }
  24021. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24022. String& name, String& version, String& manufacturer)
  24023. {
  24024. zerostruct (desc);
  24025. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24026. {
  24027. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24028. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24029. StringArray tokens;
  24030. tokens.addTokens (s, ",", String::empty);
  24031. tokens.trim();
  24032. tokens.removeEmptyStrings();
  24033. if (tokens.size() == 3)
  24034. {
  24035. desc.componentType = stringToOSType (tokens[0]);
  24036. desc.componentSubType = stringToOSType (tokens[1]);
  24037. desc.componentManufacturer = stringToOSType (tokens[2]);
  24038. ComponentRecord* comp = FindNextComponent (0, &desc);
  24039. if (comp != 0)
  24040. {
  24041. getAUDetails (comp, name, manufacturer);
  24042. return true;
  24043. }
  24044. }
  24045. }
  24046. return false;
  24047. }
  24048. class AudioUnitPluginWindowCarbon;
  24049. class AudioUnitPluginWindowCocoa;
  24050. class AudioUnitPluginInstance : public AudioPluginInstance
  24051. {
  24052. public:
  24053. ~AudioUnitPluginInstance();
  24054. // AudioPluginInstance methods:
  24055. void fillInPluginDescription (PluginDescription& desc) const
  24056. {
  24057. desc.name = pluginName;
  24058. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24059. desc.uid = ((int) componentDesc.componentType)
  24060. ^ ((int) componentDesc.componentSubType)
  24061. ^ ((int) componentDesc.componentManufacturer);
  24062. desc.lastFileModTime = 0;
  24063. desc.pluginFormatName = "AudioUnit";
  24064. desc.category = getCategory();
  24065. desc.manufacturerName = manufacturer;
  24066. desc.version = version;
  24067. desc.numInputChannels = getNumInputChannels();
  24068. desc.numOutputChannels = getNumOutputChannels();
  24069. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24070. }
  24071. const String getName() const { return pluginName; }
  24072. bool acceptsMidi() const { return wantsMidiMessages; }
  24073. bool producesMidi() const { return false; }
  24074. // AudioProcessor methods:
  24075. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24076. void releaseResources();
  24077. void processBlock (AudioSampleBuffer& buffer,
  24078. MidiBuffer& midiMessages);
  24079. AudioProcessorEditor* createEditor();
  24080. const String getInputChannelName (const int index) const;
  24081. bool isInputChannelStereoPair (int index) const;
  24082. const String getOutputChannelName (const int index) const;
  24083. bool isOutputChannelStereoPair (int index) const;
  24084. int getNumParameters();
  24085. float getParameter (int index);
  24086. void setParameter (int index, float newValue);
  24087. const String getParameterName (int index);
  24088. const String getParameterText (int index);
  24089. bool isParameterAutomatable (int index) const;
  24090. int getNumPrograms();
  24091. int getCurrentProgram();
  24092. void setCurrentProgram (int index);
  24093. const String getProgramName (int index);
  24094. void changeProgramName (int index, const String& newName);
  24095. void getStateInformation (MemoryBlock& destData);
  24096. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24097. void setStateInformation (const void* data, int sizeInBytes);
  24098. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24099. juce_UseDebuggingNewOperator
  24100. private:
  24101. friend class AudioUnitPluginWindowCarbon;
  24102. friend class AudioUnitPluginWindowCocoa;
  24103. friend class AudioUnitPluginFormat;
  24104. ComponentDescription componentDesc;
  24105. String pluginName, manufacturer, version;
  24106. String fileOrIdentifier;
  24107. CriticalSection lock;
  24108. bool initialised, wantsMidiMessages, wasPlaying;
  24109. HeapBlock <AudioBufferList> outputBufferList;
  24110. AudioTimeStamp timeStamp;
  24111. AudioSampleBuffer* currentBuffer;
  24112. AudioUnit audioUnit;
  24113. Array <int> parameterIds;
  24114. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24115. void initialise();
  24116. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24117. const AudioTimeStamp* inTimeStamp,
  24118. UInt32 inBusNumber,
  24119. UInt32 inNumberFrames,
  24120. AudioBufferList* ioData) const;
  24121. static OSStatus renderGetInputCallback (void* inRefCon,
  24122. AudioUnitRenderActionFlags* ioActionFlags,
  24123. const AudioTimeStamp* inTimeStamp,
  24124. UInt32 inBusNumber,
  24125. UInt32 inNumberFrames,
  24126. AudioBufferList* ioData)
  24127. {
  24128. return ((AudioUnitPluginInstance*) inRefCon)
  24129. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24130. }
  24131. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24132. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24133. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24134. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24135. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24136. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24137. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24138. {
  24139. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24140. }
  24141. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24142. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24143. Float64* outCurrentMeasureDownBeat)
  24144. {
  24145. return ((AudioUnitPluginInstance*) inHostUserData)
  24146. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24147. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24148. }
  24149. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24150. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24151. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24152. {
  24153. return ((AudioUnitPluginInstance*) inHostUserData)
  24154. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24155. outCurrentSampleInTimeLine, outIsCycling,
  24156. outCycleStartBeat, outCycleEndBeat);
  24157. }
  24158. void getNumChannels (int& numIns, int& numOuts)
  24159. {
  24160. numIns = 0;
  24161. numOuts = 0;
  24162. AUChannelInfo supportedChannels [128];
  24163. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24164. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24165. 0, supportedChannels, &supportedChannelsSize) == noErr
  24166. && supportedChannelsSize > 0)
  24167. {
  24168. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24169. {
  24170. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24171. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24172. }
  24173. }
  24174. else
  24175. {
  24176. // (this really means the plugin will take any number of ins/outs as long
  24177. // as they are the same)
  24178. numIns = numOuts = 2;
  24179. }
  24180. }
  24181. const String getCategory() const;
  24182. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24183. };
  24184. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24185. : fileOrIdentifier (fileOrIdentifier),
  24186. initialised (false),
  24187. wantsMidiMessages (false),
  24188. audioUnit (0),
  24189. currentBuffer (0)
  24190. {
  24191. try
  24192. {
  24193. ++insideCallback;
  24194. log ("Opening AU: " + fileOrIdentifier);
  24195. if (getComponentDescFromFile (fileOrIdentifier))
  24196. {
  24197. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24198. if (comp != 0)
  24199. {
  24200. audioUnit = (AudioUnit) OpenComponent (comp);
  24201. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24202. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24203. }
  24204. }
  24205. --insideCallback;
  24206. }
  24207. catch (...)
  24208. {
  24209. --insideCallback;
  24210. }
  24211. }
  24212. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24213. {
  24214. const ScopedLock sl (lock);
  24215. jassert (insideCallback == 0);
  24216. if (audioUnit != 0)
  24217. {
  24218. AudioUnitUninitialize (audioUnit);
  24219. CloseComponent (audioUnit);
  24220. audioUnit = 0;
  24221. }
  24222. }
  24223. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24224. {
  24225. zerostruct (componentDesc);
  24226. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24227. return true;
  24228. const File file (fileOrIdentifier);
  24229. if (! file.hasFileExtension (".component"))
  24230. return false;
  24231. const char* const utf8 = fileOrIdentifier.toUTF8();
  24232. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24233. strlen (utf8), file.isDirectory());
  24234. if (url != 0)
  24235. {
  24236. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24237. CFRelease (url);
  24238. if (bundleRef != 0)
  24239. {
  24240. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24241. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24242. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24243. if (pluginName.isEmpty())
  24244. pluginName = file.getFileNameWithoutExtension();
  24245. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24246. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24247. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24248. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24249. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24250. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24251. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24252. UseResFile (resFileId);
  24253. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24254. {
  24255. Handle h = Get1IndResource ('thng', i);
  24256. if (h != 0)
  24257. {
  24258. HLock (h);
  24259. const uint32* const types = (const uint32*) *h;
  24260. if (types[0] == kAudioUnitType_MusicDevice
  24261. || types[0] == kAudioUnitType_MusicEffect
  24262. || types[0] == kAudioUnitType_Effect
  24263. || types[0] == kAudioUnitType_Generator
  24264. || types[0] == kAudioUnitType_Panner)
  24265. {
  24266. componentDesc.componentType = types[0];
  24267. componentDesc.componentSubType = types[1];
  24268. componentDesc.componentManufacturer = types[2];
  24269. break;
  24270. }
  24271. HUnlock (h);
  24272. ReleaseResource (h);
  24273. }
  24274. }
  24275. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24276. CFRelease (bundleRef);
  24277. }
  24278. }
  24279. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24280. }
  24281. void AudioUnitPluginInstance::initialise()
  24282. {
  24283. if (initialised || audioUnit == 0)
  24284. return;
  24285. log ("Initialising AU: " + pluginName);
  24286. parameterIds.clear();
  24287. {
  24288. UInt32 paramListSize = 0;
  24289. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24290. 0, 0, &paramListSize);
  24291. if (paramListSize > 0)
  24292. {
  24293. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24294. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24295. 0, &parameterIds.getReference(0), &paramListSize);
  24296. }
  24297. }
  24298. {
  24299. AURenderCallbackStruct info;
  24300. zerostruct (info);
  24301. info.inputProcRefCon = this;
  24302. info.inputProc = renderGetInputCallback;
  24303. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24304. 0, &info, sizeof (info));
  24305. }
  24306. {
  24307. HostCallbackInfo info;
  24308. zerostruct (info);
  24309. info.hostUserData = this;
  24310. info.beatAndTempoProc = getBeatAndTempoCallback;
  24311. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24312. info.transportStateProc = getTransportStateCallback;
  24313. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24314. 0, &info, sizeof (info));
  24315. }
  24316. int numIns, numOuts;
  24317. getNumChannels (numIns, numOuts);
  24318. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24319. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24320. setLatencySamples (0);
  24321. }
  24322. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24323. int samplesPerBlockExpected)
  24324. {
  24325. initialise();
  24326. if (initialised)
  24327. {
  24328. int numIns, numOuts;
  24329. getNumChannels (numIns, numOuts);
  24330. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24331. Float64 latencySecs = 0.0;
  24332. UInt32 latencySize = sizeof (latencySecs);
  24333. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24334. 0, &latencySecs, &latencySize);
  24335. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24336. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24337. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24338. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24339. AudioStreamBasicDescription stream;
  24340. zerostruct (stream);
  24341. stream.mSampleRate = sampleRate_;
  24342. stream.mFormatID = kAudioFormatLinearPCM;
  24343. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24344. stream.mFramesPerPacket = 1;
  24345. stream.mBytesPerPacket = 4;
  24346. stream.mBytesPerFrame = 4;
  24347. stream.mBitsPerChannel = 32;
  24348. stream.mChannelsPerFrame = numIns;
  24349. OSStatus err = AudioUnitSetProperty (audioUnit,
  24350. kAudioUnitProperty_StreamFormat,
  24351. kAudioUnitScope_Input,
  24352. 0, &stream, sizeof (stream));
  24353. stream.mChannelsPerFrame = numOuts;
  24354. err = AudioUnitSetProperty (audioUnit,
  24355. kAudioUnitProperty_StreamFormat,
  24356. kAudioUnitScope_Output,
  24357. 0, &stream, sizeof (stream));
  24358. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24359. outputBufferList->mNumberBuffers = numOuts;
  24360. for (int i = numOuts; --i >= 0;)
  24361. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24362. zerostruct (timeStamp);
  24363. timeStamp.mSampleTime = 0;
  24364. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24365. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24366. currentBuffer = 0;
  24367. wasPlaying = false;
  24368. }
  24369. }
  24370. void AudioUnitPluginInstance::releaseResources()
  24371. {
  24372. if (initialised)
  24373. {
  24374. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24375. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24376. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24377. outputBufferList.free();
  24378. currentBuffer = 0;
  24379. }
  24380. }
  24381. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24382. const AudioTimeStamp* inTimeStamp,
  24383. UInt32 inBusNumber,
  24384. UInt32 inNumberFrames,
  24385. AudioBufferList* ioData) const
  24386. {
  24387. if (inBusNumber == 0
  24388. && currentBuffer != 0)
  24389. {
  24390. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24391. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24392. {
  24393. if (i < currentBuffer->getNumChannels())
  24394. {
  24395. memcpy (ioData->mBuffers[i].mData,
  24396. currentBuffer->getSampleData (i, 0),
  24397. sizeof (float) * inNumberFrames);
  24398. }
  24399. else
  24400. {
  24401. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24402. }
  24403. }
  24404. }
  24405. return noErr;
  24406. }
  24407. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24408. MidiBuffer& midiMessages)
  24409. {
  24410. const int numSamples = buffer.getNumSamples();
  24411. if (initialised)
  24412. {
  24413. AudioUnitRenderActionFlags flags = 0;
  24414. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24415. for (int i = getNumOutputChannels(); --i >= 0;)
  24416. {
  24417. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24418. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24419. }
  24420. currentBuffer = &buffer;
  24421. if (wantsMidiMessages)
  24422. {
  24423. const uint8* midiEventData;
  24424. int midiEventSize, midiEventPosition;
  24425. MidiBuffer::Iterator i (midiMessages);
  24426. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24427. {
  24428. if (midiEventSize <= 3)
  24429. MusicDeviceMIDIEvent (audioUnit,
  24430. midiEventData[0], midiEventData[1], midiEventData[2],
  24431. midiEventPosition);
  24432. else
  24433. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24434. }
  24435. midiMessages.clear();
  24436. }
  24437. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24438. 0, numSamples, outputBufferList);
  24439. timeStamp.mSampleTime += numSamples;
  24440. }
  24441. else
  24442. {
  24443. // Not initialised, so just bypass..
  24444. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24445. buffer.clear (i, 0, buffer.getNumSamples());
  24446. }
  24447. }
  24448. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24449. {
  24450. AudioPlayHead* const ph = getPlayHead();
  24451. AudioPlayHead::CurrentPositionInfo result;
  24452. if (ph != 0 && ph->getCurrentPosition (result))
  24453. {
  24454. if (outCurrentBeat != 0)
  24455. *outCurrentBeat = result.ppqPosition;
  24456. if (outCurrentTempo != 0)
  24457. *outCurrentTempo = result.bpm;
  24458. }
  24459. else
  24460. {
  24461. if (outCurrentBeat != 0)
  24462. *outCurrentBeat = 0;
  24463. if (outCurrentTempo != 0)
  24464. *outCurrentTempo = 120.0;
  24465. }
  24466. return noErr;
  24467. }
  24468. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24469. Float32* outTimeSig_Numerator,
  24470. UInt32* outTimeSig_Denominator,
  24471. Float64* outCurrentMeasureDownBeat) const
  24472. {
  24473. AudioPlayHead* const ph = getPlayHead();
  24474. AudioPlayHead::CurrentPositionInfo result;
  24475. if (ph != 0 && ph->getCurrentPosition (result))
  24476. {
  24477. if (outTimeSig_Numerator != 0)
  24478. *outTimeSig_Numerator = result.timeSigNumerator;
  24479. if (outTimeSig_Denominator != 0)
  24480. *outTimeSig_Denominator = result.timeSigDenominator;
  24481. if (outDeltaSampleOffsetToNextBeat != 0)
  24482. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24483. if (outCurrentMeasureDownBeat != 0)
  24484. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24485. }
  24486. else
  24487. {
  24488. if (outDeltaSampleOffsetToNextBeat != 0)
  24489. *outDeltaSampleOffsetToNextBeat = 0;
  24490. if (outTimeSig_Numerator != 0)
  24491. *outTimeSig_Numerator = 4;
  24492. if (outTimeSig_Denominator != 0)
  24493. *outTimeSig_Denominator = 4;
  24494. if (outCurrentMeasureDownBeat != 0)
  24495. *outCurrentMeasureDownBeat = 0;
  24496. }
  24497. return noErr;
  24498. }
  24499. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24500. Boolean* outTransportStateChanged,
  24501. Float64* outCurrentSampleInTimeLine,
  24502. Boolean* outIsCycling,
  24503. Float64* outCycleStartBeat,
  24504. Float64* outCycleEndBeat)
  24505. {
  24506. AudioPlayHead* const ph = getPlayHead();
  24507. AudioPlayHead::CurrentPositionInfo result;
  24508. if (ph != 0 && ph->getCurrentPosition (result))
  24509. {
  24510. if (outIsPlaying != 0)
  24511. *outIsPlaying = result.isPlaying;
  24512. if (outTransportStateChanged != 0)
  24513. {
  24514. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24515. wasPlaying = result.isPlaying;
  24516. }
  24517. if (outCurrentSampleInTimeLine != 0)
  24518. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24519. if (outIsCycling != 0)
  24520. *outIsCycling = false;
  24521. if (outCycleStartBeat != 0)
  24522. *outCycleStartBeat = 0;
  24523. if (outCycleEndBeat != 0)
  24524. *outCycleEndBeat = 0;
  24525. }
  24526. else
  24527. {
  24528. if (outIsPlaying != 0)
  24529. *outIsPlaying = false;
  24530. if (outTransportStateChanged != 0)
  24531. *outTransportStateChanged = false;
  24532. if (outCurrentSampleInTimeLine != 0)
  24533. *outCurrentSampleInTimeLine = 0;
  24534. if (outIsCycling != 0)
  24535. *outIsCycling = false;
  24536. if (outCycleStartBeat != 0)
  24537. *outCycleStartBeat = 0;
  24538. if (outCycleEndBeat != 0)
  24539. *outCycleEndBeat = 0;
  24540. }
  24541. return noErr;
  24542. }
  24543. static VoidArray activeWindows;
  24544. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24545. {
  24546. public:
  24547. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24548. : AudioProcessorEditor (&plugin_),
  24549. plugin (plugin_),
  24550. wrapper (0)
  24551. {
  24552. addAndMakeVisible (wrapper = new NSViewComponent());
  24553. activeWindows.add (this);
  24554. setOpaque (true);
  24555. setVisible (true);
  24556. setSize (100, 100);
  24557. createView (createGenericViewIfNeeded);
  24558. }
  24559. ~AudioUnitPluginWindowCocoa()
  24560. {
  24561. const bool wasValid = isValid();
  24562. wrapper->setView (0);
  24563. activeWindows.removeValue (this);
  24564. if (wasValid)
  24565. plugin.editorBeingDeleted (this);
  24566. delete wrapper;
  24567. }
  24568. bool isValid() const { return wrapper->getView() != 0; }
  24569. void paint (Graphics& g)
  24570. {
  24571. g.fillAll (Colours::white);
  24572. }
  24573. void resized()
  24574. {
  24575. wrapper->setSize (getWidth(), getHeight());
  24576. }
  24577. private:
  24578. AudioUnitPluginInstance& plugin;
  24579. NSViewComponent* wrapper;
  24580. bool createView (const bool createGenericViewIfNeeded)
  24581. {
  24582. NSView* pluginView = 0;
  24583. UInt32 dataSize = 0;
  24584. Boolean isWritable = false;
  24585. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24586. 0, &dataSize, &isWritable) == noErr
  24587. && dataSize != 0
  24588. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24589. 0, &dataSize, &isWritable) == noErr)
  24590. {
  24591. HeapBlock <AudioUnitCocoaViewInfo> info;
  24592. info.calloc (dataSize, 1);
  24593. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24594. 0, info, &dataSize) == noErr)
  24595. {
  24596. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24597. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24598. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24599. Class viewClass = [viewBundle classNamed: viewClassName];
  24600. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24601. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24602. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24603. {
  24604. id factory = [[[viewClass alloc] init] autorelease];
  24605. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24606. withSize: NSMakeSize (getWidth(), getHeight())];
  24607. }
  24608. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24609. {
  24610. CFRelease (info->mCocoaAUViewClass[i]);
  24611. CFRelease (info->mCocoaAUViewBundleLocation);
  24612. }
  24613. }
  24614. }
  24615. if (createGenericViewIfNeeded && (pluginView == 0))
  24616. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24617. wrapper->setView (pluginView);
  24618. if (pluginView != 0)
  24619. setSize ([pluginView frame].size.width,
  24620. [pluginView frame].size.height);
  24621. return pluginView != 0;
  24622. }
  24623. };
  24624. #if JUCE_SUPPORT_CARBON
  24625. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24626. {
  24627. public:
  24628. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24629. : AudioProcessorEditor (&plugin_),
  24630. plugin (plugin_),
  24631. viewComponent (0)
  24632. {
  24633. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24634. activeWindows.add (this);
  24635. setOpaque (true);
  24636. setVisible (true);
  24637. setSize (400, 300);
  24638. ComponentDescription viewList [16];
  24639. UInt32 viewListSize = sizeof (viewList);
  24640. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24641. 0, &viewList, &viewListSize);
  24642. componentRecord = FindNextComponent (0, &viewList[0]);
  24643. }
  24644. ~AudioUnitPluginWindowCarbon()
  24645. {
  24646. innerWrapper = 0;
  24647. activeWindows.removeValue (this);
  24648. if (isValid())
  24649. plugin.editorBeingDeleted (this);
  24650. }
  24651. bool isValid() const throw() { return componentRecord != 0; }
  24652. void paint (Graphics& g)
  24653. {
  24654. g.fillAll (Colours::black);
  24655. }
  24656. void resized()
  24657. {
  24658. innerWrapper->setSize (getWidth(), getHeight());
  24659. }
  24660. bool keyStateChanged (bool)
  24661. {
  24662. return false;
  24663. }
  24664. bool keyPressed (const KeyPress&)
  24665. {
  24666. return false;
  24667. }
  24668. void broughtToFront()
  24669. {
  24670. activeWindows.removeValue (this);
  24671. activeWindows.add (this);
  24672. }
  24673. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24674. AudioUnitCarbonView getViewComponent()
  24675. {
  24676. if (viewComponent == 0 && componentRecord != 0)
  24677. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24678. return viewComponent;
  24679. }
  24680. void closeViewComponent()
  24681. {
  24682. if (viewComponent != 0)
  24683. {
  24684. CloseComponent (viewComponent);
  24685. viewComponent = 0;
  24686. }
  24687. }
  24688. juce_UseDebuggingNewOperator
  24689. private:
  24690. AudioUnitPluginInstance& plugin;
  24691. ComponentRecord* componentRecord;
  24692. AudioUnitCarbonView viewComponent;
  24693. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24694. {
  24695. public:
  24696. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24697. : owner (owner_)
  24698. {
  24699. }
  24700. ~InnerWrapperComponent()
  24701. {
  24702. deleteWindow();
  24703. }
  24704. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24705. {
  24706. log ("Opening AU GUI: " + owner->plugin.getName());
  24707. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24708. if (viewComponent == 0)
  24709. return 0;
  24710. Float32Point pos = { 0, 0 };
  24711. Float32Point size = { 250, 200 };
  24712. HIViewRef pluginView = 0;
  24713. AudioUnitCarbonViewCreate (viewComponent,
  24714. owner->getAudioUnit(),
  24715. windowRef,
  24716. rootView,
  24717. &pos,
  24718. &size,
  24719. (ControlRef*) &pluginView);
  24720. return pluginView;
  24721. }
  24722. void removeView (HIViewRef)
  24723. {
  24724. log ("Closing AU GUI: " + owner->plugin.getName());
  24725. owner->closeViewComponent();
  24726. }
  24727. private:
  24728. AudioUnitPluginWindowCarbon* const owner;
  24729. };
  24730. friend class InnerWrapperComponent;
  24731. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24732. };
  24733. #endif
  24734. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24735. {
  24736. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24737. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24738. w = 0;
  24739. #if JUCE_SUPPORT_CARBON
  24740. if (w == 0)
  24741. {
  24742. w = new AudioUnitPluginWindowCarbon (*this);
  24743. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24744. w = 0;
  24745. }
  24746. #endif
  24747. if (w == 0)
  24748. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24749. return w.release();
  24750. }
  24751. const String AudioUnitPluginInstance::getCategory() const
  24752. {
  24753. const char* result = 0;
  24754. switch (componentDesc.componentType)
  24755. {
  24756. case kAudioUnitType_Effect:
  24757. case kAudioUnitType_MusicEffect:
  24758. result = "Effect";
  24759. break;
  24760. case kAudioUnitType_MusicDevice:
  24761. result = "Synth";
  24762. break;
  24763. case kAudioUnitType_Generator:
  24764. result = "Generator";
  24765. break;
  24766. case kAudioUnitType_Panner:
  24767. result = "Panner";
  24768. break;
  24769. default:
  24770. break;
  24771. }
  24772. return result;
  24773. }
  24774. int AudioUnitPluginInstance::getNumParameters()
  24775. {
  24776. return parameterIds.size();
  24777. }
  24778. float AudioUnitPluginInstance::getParameter (int index)
  24779. {
  24780. const ScopedLock sl (lock);
  24781. Float32 value = 0.0f;
  24782. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24783. {
  24784. AudioUnitGetParameter (audioUnit,
  24785. (UInt32) parameterIds.getUnchecked (index),
  24786. kAudioUnitScope_Global, 0,
  24787. &value);
  24788. }
  24789. return value;
  24790. }
  24791. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24792. {
  24793. const ScopedLock sl (lock);
  24794. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24795. {
  24796. AudioUnitSetParameter (audioUnit,
  24797. (UInt32) parameterIds.getUnchecked (index),
  24798. kAudioUnitScope_Global, 0,
  24799. newValue, 0);
  24800. }
  24801. }
  24802. const String AudioUnitPluginInstance::getParameterName (int index)
  24803. {
  24804. AudioUnitParameterInfo info;
  24805. zerostruct (info);
  24806. UInt32 sz = sizeof (info);
  24807. String name;
  24808. if (AudioUnitGetProperty (audioUnit,
  24809. kAudioUnitProperty_ParameterInfo,
  24810. kAudioUnitScope_Global,
  24811. parameterIds [index], &info, &sz) == noErr)
  24812. {
  24813. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24814. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24815. else
  24816. name = String (info.name, sizeof (info.name));
  24817. }
  24818. return name;
  24819. }
  24820. const String AudioUnitPluginInstance::getParameterText (int index)
  24821. {
  24822. return String (getParameter (index));
  24823. }
  24824. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24825. {
  24826. AudioUnitParameterInfo info;
  24827. UInt32 sz = sizeof (info);
  24828. if (AudioUnitGetProperty (audioUnit,
  24829. kAudioUnitProperty_ParameterInfo,
  24830. kAudioUnitScope_Global,
  24831. parameterIds [index], &info, &sz) == noErr)
  24832. {
  24833. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24834. }
  24835. return true;
  24836. }
  24837. int AudioUnitPluginInstance::getNumPrograms()
  24838. {
  24839. CFArrayRef presets;
  24840. UInt32 sz = sizeof (CFArrayRef);
  24841. int num = 0;
  24842. if (AudioUnitGetProperty (audioUnit,
  24843. kAudioUnitProperty_FactoryPresets,
  24844. kAudioUnitScope_Global,
  24845. 0, &presets, &sz) == noErr)
  24846. {
  24847. num = (int) CFArrayGetCount (presets);
  24848. CFRelease (presets);
  24849. }
  24850. return num;
  24851. }
  24852. int AudioUnitPluginInstance::getCurrentProgram()
  24853. {
  24854. AUPreset current;
  24855. current.presetNumber = 0;
  24856. UInt32 sz = sizeof (AUPreset);
  24857. AudioUnitGetProperty (audioUnit,
  24858. kAudioUnitProperty_FactoryPresets,
  24859. kAudioUnitScope_Global,
  24860. 0, &current, &sz);
  24861. return current.presetNumber;
  24862. }
  24863. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24864. {
  24865. AUPreset current;
  24866. current.presetNumber = newIndex;
  24867. current.presetName = 0;
  24868. AudioUnitSetProperty (audioUnit,
  24869. kAudioUnitProperty_FactoryPresets,
  24870. kAudioUnitScope_Global,
  24871. 0, &current, sizeof (AUPreset));
  24872. }
  24873. const String AudioUnitPluginInstance::getProgramName (int index)
  24874. {
  24875. String s;
  24876. CFArrayRef presets;
  24877. UInt32 sz = sizeof (CFArrayRef);
  24878. if (AudioUnitGetProperty (audioUnit,
  24879. kAudioUnitProperty_FactoryPresets,
  24880. kAudioUnitScope_Global,
  24881. 0, &presets, &sz) == noErr)
  24882. {
  24883. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24884. {
  24885. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24886. if (p != 0 && p->presetNumber == index)
  24887. {
  24888. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24889. break;
  24890. }
  24891. }
  24892. CFRelease (presets);
  24893. }
  24894. return s;
  24895. }
  24896. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24897. {
  24898. jassertfalse // xxx not implemented!
  24899. }
  24900. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24901. {
  24902. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24903. return "Input " + String (index + 1);
  24904. return String::empty;
  24905. }
  24906. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24907. {
  24908. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24909. return false;
  24910. return true;
  24911. }
  24912. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24913. {
  24914. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24915. return "Output " + String (index + 1);
  24916. return String::empty;
  24917. }
  24918. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24919. {
  24920. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24921. return false;
  24922. return true;
  24923. }
  24924. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24925. {
  24926. getCurrentProgramStateInformation (destData);
  24927. }
  24928. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24929. {
  24930. CFPropertyListRef propertyList = 0;
  24931. UInt32 sz = sizeof (CFPropertyListRef);
  24932. if (AudioUnitGetProperty (audioUnit,
  24933. kAudioUnitProperty_ClassInfo,
  24934. kAudioUnitScope_Global,
  24935. 0, &propertyList, &sz) == noErr)
  24936. {
  24937. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24938. CFWriteStreamOpen (stream);
  24939. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24940. CFWriteStreamClose (stream);
  24941. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24942. destData.setSize (bytesWritten);
  24943. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24944. CFRelease (data);
  24945. CFRelease (stream);
  24946. CFRelease (propertyList);
  24947. }
  24948. }
  24949. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  24950. {
  24951. setCurrentProgramStateInformation (data, sizeInBytes);
  24952. }
  24953. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  24954. {
  24955. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  24956. (const UInt8*) data,
  24957. sizeInBytes,
  24958. kCFAllocatorNull);
  24959. CFReadStreamOpen (stream);
  24960. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  24961. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  24962. stream,
  24963. 0,
  24964. kCFPropertyListImmutable,
  24965. &format,
  24966. 0);
  24967. CFRelease (stream);
  24968. if (propertyList != 0)
  24969. AudioUnitSetProperty (audioUnit,
  24970. kAudioUnitProperty_ClassInfo,
  24971. kAudioUnitScope_Global,
  24972. 0, &propertyList, sizeof (propertyList));
  24973. }
  24974. AudioUnitPluginFormat::AudioUnitPluginFormat()
  24975. {
  24976. }
  24977. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  24978. {
  24979. }
  24980. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  24981. const String& fileOrIdentifier)
  24982. {
  24983. if (! fileMightContainThisPluginType (fileOrIdentifier))
  24984. return;
  24985. PluginDescription desc;
  24986. desc.fileOrIdentifier = fileOrIdentifier;
  24987. desc.uid = 0;
  24988. try
  24989. {
  24990. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  24991. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  24992. if (auInstance != 0)
  24993. {
  24994. auInstance->fillInPluginDescription (desc);
  24995. results.add (new PluginDescription (desc));
  24996. }
  24997. }
  24998. catch (...)
  24999. {
  25000. // crashed while loading...
  25001. }
  25002. }
  25003. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25004. {
  25005. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25006. {
  25007. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25008. if (result->audioUnit != 0)
  25009. {
  25010. result->initialise();
  25011. return result.release();
  25012. }
  25013. }
  25014. return 0;
  25015. }
  25016. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25017. const bool /*recursive*/)
  25018. {
  25019. StringArray result;
  25020. ComponentRecord* comp = 0;
  25021. ComponentDescription desc;
  25022. zerostruct (desc);
  25023. for (;;)
  25024. {
  25025. zerostruct (desc);
  25026. comp = FindNextComponent (comp, &desc);
  25027. if (comp == 0)
  25028. break;
  25029. GetComponentInfo (comp, &desc, 0, 0, 0);
  25030. if (desc.componentType == kAudioUnitType_MusicDevice
  25031. || desc.componentType == kAudioUnitType_MusicEffect
  25032. || desc.componentType == kAudioUnitType_Effect
  25033. || desc.componentType == kAudioUnitType_Generator
  25034. || desc.componentType == kAudioUnitType_Panner)
  25035. {
  25036. const String s (createAUPluginIdentifier (desc));
  25037. DBG (s);
  25038. result.add (s);
  25039. }
  25040. }
  25041. return result;
  25042. }
  25043. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25044. {
  25045. ComponentDescription desc;
  25046. String name, version, manufacturer;
  25047. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25048. return FindNextComponent (0, &desc) != 0;
  25049. const File f (fileOrIdentifier);
  25050. return f.hasFileExtension (".component")
  25051. && f.isDirectory();
  25052. }
  25053. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25054. {
  25055. ComponentDescription desc;
  25056. String name, version, manufacturer;
  25057. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25058. if (name.isEmpty())
  25059. name = fileOrIdentifier;
  25060. return name;
  25061. }
  25062. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25063. {
  25064. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25065. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25066. else
  25067. return File (desc.fileOrIdentifier).exists();
  25068. }
  25069. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25070. {
  25071. return FileSearchPath ("/(Default AudioUnit locations)");
  25072. }
  25073. #endif
  25074. END_JUCE_NAMESPACE
  25075. #undef log
  25076. #endif
  25077. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25078. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25079. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25080. #define JUCE_MAC_VST_INCLUDED 1
  25081. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25082. #if JUCE_PLUGINHOST_VST
  25083. #if JUCE_WINDOWS
  25084. #undef _WIN32_WINNT
  25085. #define _WIN32_WINNT 0x500
  25086. #undef STRICT
  25087. #define STRICT
  25088. #include <windows.h>
  25089. #include <float.h>
  25090. #pragma warning (disable : 4312 4355)
  25091. #elif JUCE_LINUX
  25092. #include <float.h>
  25093. #include <sys/time.h>
  25094. #include <X11/Xlib.h>
  25095. #include <X11/Xutil.h>
  25096. #include <X11/Xatom.h>
  25097. #undef Font
  25098. #undef KeyPress
  25099. #undef Drawable
  25100. #undef Time
  25101. #else
  25102. #ifndef JUCE_MAC_VST_INCLUDED
  25103. // On the mac, this file needs to be compiled indirectly, by using
  25104. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25105. #error
  25106. #endif
  25107. #include <Cocoa/Cocoa.h>
  25108. #include <Carbon/Carbon.h>
  25109. #endif
  25110. #if ! (JUCE_MAC && JUCE_64BIT)
  25111. BEGIN_JUCE_NAMESPACE
  25112. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25113. #endif
  25114. #undef PRAGMA_ALIGN_SUPPORTED
  25115. #define VST_FORCE_DEPRECATED 0
  25116. #ifdef _MSC_VER
  25117. #pragma warning (push)
  25118. #pragma warning (disable: 4996)
  25119. #endif
  25120. #include "pluginterfaces/vst2.x/aeffectx.h"
  25121. #ifdef _MSC_VER
  25122. #pragma warning (pop)
  25123. #endif
  25124. #if JUCE_LINUX
  25125. #define Font JUCE_NAMESPACE::Font
  25126. #define KeyPress JUCE_NAMESPACE::KeyPress
  25127. #define Drawable JUCE_NAMESPACE::Drawable
  25128. #define Time JUCE_NAMESPACE::Time
  25129. #endif
  25130. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25131. #ifdef __aeffect__
  25132. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25133. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25134. class VSTMidiEventList
  25135. {
  25136. public:
  25137. VSTMidiEventList()
  25138. : numEventsUsed (0), numEventsAllocated (0)
  25139. {
  25140. }
  25141. ~VSTMidiEventList()
  25142. {
  25143. freeEvents();
  25144. }
  25145. void clear()
  25146. {
  25147. numEventsUsed = 0;
  25148. if (events != 0)
  25149. events->numEvents = 0;
  25150. }
  25151. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25152. {
  25153. ensureSize (numEventsUsed + 1);
  25154. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25155. events->numEvents = ++numEventsUsed;
  25156. if (numBytes <= 4)
  25157. {
  25158. if (e->type == kVstSysExType)
  25159. {
  25160. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25161. e->type = kVstMidiType;
  25162. e->byteSize = sizeof (VstMidiEvent);
  25163. e->noteLength = 0;
  25164. e->noteOffset = 0;
  25165. e->detune = 0;
  25166. e->noteOffVelocity = 0;
  25167. }
  25168. e->deltaFrames = frameOffset;
  25169. memcpy (e->midiData, midiData, numBytes);
  25170. }
  25171. else
  25172. {
  25173. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25174. if (se->type == kVstSysExType)
  25175. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25176. else
  25177. se->sysexDump = (char*) juce_malloc (numBytes);
  25178. memcpy (se->sysexDump, midiData, numBytes);
  25179. se->type = kVstSysExType;
  25180. se->byteSize = sizeof (VstMidiSysexEvent);
  25181. se->deltaFrames = frameOffset;
  25182. se->flags = 0;
  25183. se->dumpBytes = numBytes;
  25184. se->resvd1 = 0;
  25185. se->resvd2 = 0;
  25186. }
  25187. }
  25188. // Handy method to pull the events out of an event buffer supplied by the host
  25189. // or plugin.
  25190. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25191. {
  25192. for (int i = 0; i < events->numEvents; ++i)
  25193. {
  25194. const VstEvent* const e = events->events[i];
  25195. if (e != 0)
  25196. {
  25197. if (e->type == kVstMidiType)
  25198. {
  25199. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25200. 4, e->deltaFrames);
  25201. }
  25202. else if (e->type == kVstSysExType)
  25203. {
  25204. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25205. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25206. e->deltaFrames);
  25207. }
  25208. }
  25209. }
  25210. }
  25211. void ensureSize (int numEventsNeeded)
  25212. {
  25213. if (numEventsNeeded > numEventsAllocated)
  25214. {
  25215. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25216. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25217. if (events == 0)
  25218. events.calloc (size, 1);
  25219. else
  25220. events.realloc (size, 1);
  25221. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25222. {
  25223. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25224. (int) sizeof (VstMidiSysexEvent)));
  25225. e->type = kVstMidiType;
  25226. e->byteSize = sizeof (VstMidiEvent);
  25227. events->events[i] = (VstEvent*) e;
  25228. }
  25229. numEventsAllocated = numEventsNeeded;
  25230. }
  25231. }
  25232. void freeEvents()
  25233. {
  25234. if (events != 0)
  25235. {
  25236. for (int i = numEventsAllocated; --i >= 0;)
  25237. {
  25238. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25239. if (e->type == kVstSysExType)
  25240. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25241. juce_free (e);
  25242. }
  25243. events.free();
  25244. numEventsUsed = 0;
  25245. numEventsAllocated = 0;
  25246. }
  25247. }
  25248. HeapBlock <VstEvents> events;
  25249. private:
  25250. int numEventsUsed, numEventsAllocated;
  25251. };
  25252. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25253. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25254. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25255. #if ! JUCE_WIN32
  25256. static void _fpreset() {}
  25257. static void _clearfp() {}
  25258. #endif
  25259. extern void juce_callAnyTimersSynchronously();
  25260. const int fxbVersionNum = 1;
  25261. struct fxProgram
  25262. {
  25263. long chunkMagic; // 'CcnK'
  25264. long byteSize; // of this chunk, excl. magic + byteSize
  25265. long fxMagic; // 'FxCk'
  25266. long version;
  25267. long fxID; // fx unique id
  25268. long fxVersion;
  25269. long numParams;
  25270. char prgName[28];
  25271. float params[1]; // variable no. of parameters
  25272. };
  25273. struct fxSet
  25274. {
  25275. long chunkMagic; // 'CcnK'
  25276. long byteSize; // of this chunk, excl. magic + byteSize
  25277. long fxMagic; // 'FxBk'
  25278. long version;
  25279. long fxID; // fx unique id
  25280. long fxVersion;
  25281. long numPrograms;
  25282. char future[128];
  25283. fxProgram programs[1]; // variable no. of programs
  25284. };
  25285. struct fxChunkSet
  25286. {
  25287. long chunkMagic; // 'CcnK'
  25288. long byteSize; // of this chunk, excl. magic + byteSize
  25289. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25290. long version;
  25291. long fxID; // fx unique id
  25292. long fxVersion;
  25293. long numPrograms;
  25294. char future[128];
  25295. long chunkSize;
  25296. char chunk[8]; // variable
  25297. };
  25298. struct fxProgramSet
  25299. {
  25300. long chunkMagic; // 'CcnK'
  25301. long byteSize; // of this chunk, excl. magic + byteSize
  25302. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25303. long version;
  25304. long fxID; // fx unique id
  25305. long fxVersion;
  25306. long numPrograms;
  25307. char name[28];
  25308. long chunkSize;
  25309. char chunk[8]; // variable
  25310. };
  25311. static long vst_swap (const long x) throw()
  25312. {
  25313. #ifdef JUCE_LITTLE_ENDIAN
  25314. return (long) ByteOrder::swap ((uint32) x);
  25315. #else
  25316. return x;
  25317. #endif
  25318. }
  25319. static float vst_swapFloat (const float x) throw()
  25320. {
  25321. #ifdef JUCE_LITTLE_ENDIAN
  25322. union { uint32 asInt; float asFloat; } n;
  25323. n.asFloat = x;
  25324. n.asInt = ByteOrder::swap (n.asInt);
  25325. return n.asFloat;
  25326. #else
  25327. return x;
  25328. #endif
  25329. }
  25330. typedef AEffect* (*MainCall) (audioMasterCallback);
  25331. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25332. static int shellUIDToCreate = 0;
  25333. static int insideVSTCallback = 0;
  25334. class VSTPluginWindow;
  25335. // Change this to disable logging of various VST activities
  25336. #ifndef VST_LOGGING
  25337. #define VST_LOGGING 1
  25338. #endif
  25339. #if VST_LOGGING
  25340. #define log(a) Logger::writeToLog(a);
  25341. #else
  25342. #define log(a)
  25343. #endif
  25344. #if JUCE_MAC && JUCE_PPC
  25345. static void* NewCFMFromMachO (void* const machofp) throw()
  25346. {
  25347. void* result = juce_malloc (8);
  25348. ((void**) result)[0] = machofp;
  25349. ((void**) result)[1] = result;
  25350. return result;
  25351. }
  25352. #endif
  25353. #if JUCE_LINUX
  25354. extern Display* display;
  25355. extern XContext improbableNumber;
  25356. typedef void (*EventProcPtr) (XEvent* ev);
  25357. static bool xErrorTriggered;
  25358. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25359. {
  25360. xErrorTriggered = true;
  25361. return 0;
  25362. }
  25363. static int getPropertyFromXWindow (Window handle, Atom atom)
  25364. {
  25365. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25366. xErrorTriggered = false;
  25367. int userSize;
  25368. unsigned long bytes, userCount;
  25369. unsigned char* data;
  25370. Atom userType;
  25371. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25372. &userType, &userSize, &userCount, &bytes, &data);
  25373. XSetErrorHandler (oldErrorHandler);
  25374. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25375. : 0;
  25376. }
  25377. static Window getChildWindow (Window windowToCheck)
  25378. {
  25379. Window rootWindow, parentWindow;
  25380. Window* childWindows;
  25381. unsigned int numChildren;
  25382. XQueryTree (display,
  25383. windowToCheck,
  25384. &rootWindow,
  25385. &parentWindow,
  25386. &childWindows,
  25387. &numChildren);
  25388. if (numChildren > 0)
  25389. return childWindows [0];
  25390. return 0;
  25391. }
  25392. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25393. {
  25394. if (e.mods.isLeftButtonDown())
  25395. {
  25396. ev.xbutton.button = Button1;
  25397. ev.xbutton.state |= Button1Mask;
  25398. }
  25399. else if (e.mods.isRightButtonDown())
  25400. {
  25401. ev.xbutton.button = Button3;
  25402. ev.xbutton.state |= Button3Mask;
  25403. }
  25404. else if (e.mods.isMiddleButtonDown())
  25405. {
  25406. ev.xbutton.button = Button2;
  25407. ev.xbutton.state |= Button2Mask;
  25408. }
  25409. }
  25410. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25411. {
  25412. if (e.mods.isLeftButtonDown())
  25413. ev.xmotion.state |= Button1Mask;
  25414. else if (e.mods.isRightButtonDown())
  25415. ev.xmotion.state |= Button3Mask;
  25416. else if (e.mods.isMiddleButtonDown())
  25417. ev.xmotion.state |= Button2Mask;
  25418. }
  25419. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25420. {
  25421. if (e.mods.isLeftButtonDown())
  25422. ev.xcrossing.state |= Button1Mask;
  25423. else if (e.mods.isRightButtonDown())
  25424. ev.xcrossing.state |= Button3Mask;
  25425. else if (e.mods.isMiddleButtonDown())
  25426. ev.xcrossing.state |= Button2Mask;
  25427. }
  25428. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25429. {
  25430. if (increment < 0)
  25431. {
  25432. ev.xbutton.button = Button5;
  25433. ev.xbutton.state |= Button5Mask;
  25434. }
  25435. else if (increment > 0)
  25436. {
  25437. ev.xbutton.button = Button4;
  25438. ev.xbutton.state |= Button4Mask;
  25439. }
  25440. }
  25441. #endif
  25442. static VoidArray activeModules;
  25443. class ModuleHandle : public ReferenceCountedObject
  25444. {
  25445. public:
  25446. File file;
  25447. MainCall moduleMain;
  25448. String pluginName;
  25449. static ModuleHandle* findOrCreateModule (const File& file)
  25450. {
  25451. for (int i = activeModules.size(); --i >= 0;)
  25452. {
  25453. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25454. if (module->file == file)
  25455. return module;
  25456. }
  25457. _fpreset(); // (doesn't do any harm)
  25458. ++insideVSTCallback;
  25459. shellUIDToCreate = 0;
  25460. log ("Attempting to load VST: " + file.getFullPathName());
  25461. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25462. if (! m->open())
  25463. m = 0;
  25464. --insideVSTCallback;
  25465. _fpreset(); // (doesn't do any harm)
  25466. return m.release();
  25467. }
  25468. ModuleHandle (const File& file_)
  25469. : file (file_),
  25470. moduleMain (0),
  25471. #if JUCE_WIN32 || JUCE_LINUX
  25472. hModule (0)
  25473. #elif JUCE_MAC
  25474. fragId (0),
  25475. resHandle (0),
  25476. bundleRef (0),
  25477. resFileId (0)
  25478. #endif
  25479. {
  25480. activeModules.add (this);
  25481. #if JUCE_WIN32 || JUCE_LINUX
  25482. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25483. #elif JUCE_MAC
  25484. FSRef ref;
  25485. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25486. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25487. #endif
  25488. }
  25489. ~ModuleHandle()
  25490. {
  25491. activeModules.removeValue (this);
  25492. close();
  25493. }
  25494. juce_UseDebuggingNewOperator
  25495. #if JUCE_WIN32 || JUCE_LINUX
  25496. void* hModule;
  25497. String fullParentDirectoryPathName;
  25498. bool open()
  25499. {
  25500. #if JUCE_WIN32
  25501. static bool timePeriodSet = false;
  25502. if (! timePeriodSet)
  25503. {
  25504. timePeriodSet = true;
  25505. timeBeginPeriod (2);
  25506. }
  25507. #endif
  25508. pluginName = file.getFileNameWithoutExtension();
  25509. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25510. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25511. if (moduleMain == 0)
  25512. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25513. return moduleMain != 0;
  25514. }
  25515. void close()
  25516. {
  25517. _fpreset(); // (doesn't do any harm)
  25518. PlatformUtilities::freeDynamicLibrary (hModule);
  25519. }
  25520. void closeEffect (AEffect* eff)
  25521. {
  25522. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25523. }
  25524. #else
  25525. CFragConnectionID fragId;
  25526. Handle resHandle;
  25527. CFBundleRef bundleRef;
  25528. FSSpec parentDirFSSpec;
  25529. short resFileId;
  25530. bool open()
  25531. {
  25532. bool ok = false;
  25533. const String filename (file.getFullPathName());
  25534. if (file.hasFileExtension (".vst"))
  25535. {
  25536. const char* const utf8 = filename.toUTF8();
  25537. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25538. strlen (utf8), file.isDirectory());
  25539. if (url != 0)
  25540. {
  25541. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25542. CFRelease (url);
  25543. if (bundleRef != 0)
  25544. {
  25545. if (CFBundleLoadExecutable (bundleRef))
  25546. {
  25547. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25548. if (moduleMain == 0)
  25549. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25550. if (moduleMain != 0)
  25551. {
  25552. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25553. if (name != 0)
  25554. {
  25555. if (CFGetTypeID (name) == CFStringGetTypeID())
  25556. {
  25557. char buffer[1024];
  25558. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25559. pluginName = buffer;
  25560. }
  25561. }
  25562. if (pluginName.isEmpty())
  25563. pluginName = file.getFileNameWithoutExtension();
  25564. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25565. ok = true;
  25566. }
  25567. }
  25568. if (! ok)
  25569. {
  25570. CFBundleUnloadExecutable (bundleRef);
  25571. CFRelease (bundleRef);
  25572. bundleRef = 0;
  25573. }
  25574. }
  25575. }
  25576. }
  25577. #if JUCE_PPC
  25578. else
  25579. {
  25580. FSRef fn;
  25581. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25582. {
  25583. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25584. if (resFileId != -1)
  25585. {
  25586. const int numEffs = Count1Resources ('aEff');
  25587. for (int i = 0; i < numEffs; ++i)
  25588. {
  25589. resHandle = Get1IndResource ('aEff', i + 1);
  25590. if (resHandle != 0)
  25591. {
  25592. OSType type;
  25593. Str255 name;
  25594. SInt16 id;
  25595. GetResInfo (resHandle, &id, &type, name);
  25596. pluginName = String ((const char*) name + 1, name[0]);
  25597. DetachResource (resHandle);
  25598. HLock (resHandle);
  25599. Ptr ptr;
  25600. Str255 errorText;
  25601. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25602. name, kPrivateCFragCopy,
  25603. &fragId, &ptr, errorText);
  25604. if (err == noErr)
  25605. {
  25606. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25607. ok = true;
  25608. }
  25609. else
  25610. {
  25611. HUnlock (resHandle);
  25612. }
  25613. break;
  25614. }
  25615. }
  25616. if (! ok)
  25617. CloseResFile (resFileId);
  25618. }
  25619. }
  25620. }
  25621. #endif
  25622. return ok;
  25623. }
  25624. void close()
  25625. {
  25626. #if JUCE_PPC
  25627. if (fragId != 0)
  25628. {
  25629. if (moduleMain != 0)
  25630. disposeMachOFromCFM ((void*) moduleMain);
  25631. CloseConnection (&fragId);
  25632. HUnlock (resHandle);
  25633. if (resFileId != 0)
  25634. CloseResFile (resFileId);
  25635. }
  25636. else
  25637. #endif
  25638. if (bundleRef != 0)
  25639. {
  25640. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25641. if (CFGetRetainCount (bundleRef) == 1)
  25642. CFBundleUnloadExecutable (bundleRef);
  25643. if (CFGetRetainCount (bundleRef) > 0)
  25644. CFRelease (bundleRef);
  25645. }
  25646. }
  25647. void closeEffect (AEffect* eff)
  25648. {
  25649. #if JUCE_PPC
  25650. if (fragId != 0)
  25651. {
  25652. VoidArray thingsToDelete;
  25653. thingsToDelete.add ((void*) eff->dispatcher);
  25654. thingsToDelete.add ((void*) eff->process);
  25655. thingsToDelete.add ((void*) eff->setParameter);
  25656. thingsToDelete.add ((void*) eff->getParameter);
  25657. thingsToDelete.add ((void*) eff->processReplacing);
  25658. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25659. for (int i = thingsToDelete.size(); --i >= 0;)
  25660. disposeMachOFromCFM (thingsToDelete[i]);
  25661. }
  25662. else
  25663. #endif
  25664. {
  25665. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25666. }
  25667. }
  25668. #if JUCE_PPC
  25669. static void* newMachOFromCFM (void* cfmfp)
  25670. {
  25671. if (cfmfp == 0)
  25672. return 0;
  25673. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25674. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25675. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25676. mfp[2] = 0x800c0000;
  25677. mfp[3] = 0x804c0004;
  25678. mfp[4] = 0x7c0903a6;
  25679. mfp[5] = 0x4e800420;
  25680. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25681. return mfp;
  25682. }
  25683. static void disposeMachOFromCFM (void* ptr)
  25684. {
  25685. juce_free (ptr);
  25686. }
  25687. void coerceAEffectFunctionCalls (AEffect* eff)
  25688. {
  25689. if (fragId != 0)
  25690. {
  25691. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25692. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25693. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25694. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25695. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25696. }
  25697. }
  25698. #endif
  25699. #endif
  25700. };
  25701. class VSTPluginInstance : public AudioPluginInstance,
  25702. private Timer,
  25703. private AsyncUpdater
  25704. {
  25705. public:
  25706. ~VSTPluginInstance();
  25707. // AudioPluginInstance methods:
  25708. void fillInPluginDescription (PluginDescription& desc) const
  25709. {
  25710. desc.name = name;
  25711. desc.fileOrIdentifier = module->file.getFullPathName();
  25712. desc.uid = getUID();
  25713. desc.lastFileModTime = module->file.getLastModificationTime();
  25714. desc.pluginFormatName = "VST";
  25715. desc.category = getCategory();
  25716. {
  25717. char buffer [kVstMaxVendorStrLen + 8];
  25718. zerostruct (buffer);
  25719. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25720. desc.manufacturerName = buffer;
  25721. }
  25722. desc.version = getVersion();
  25723. desc.numInputChannels = getNumInputChannels();
  25724. desc.numOutputChannels = getNumOutputChannels();
  25725. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25726. }
  25727. const String getName() const { return name; }
  25728. int getUID() const throw();
  25729. bool acceptsMidi() const { return wantsMidiMessages; }
  25730. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25731. // AudioProcessor methods:
  25732. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25733. void releaseResources();
  25734. void processBlock (AudioSampleBuffer& buffer,
  25735. MidiBuffer& midiMessages);
  25736. AudioProcessorEditor* createEditor();
  25737. const String getInputChannelName (const int index) const;
  25738. bool isInputChannelStereoPair (int index) const;
  25739. const String getOutputChannelName (const int index) const;
  25740. bool isOutputChannelStereoPair (int index) const;
  25741. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25742. float getParameter (int index);
  25743. void setParameter (int index, float newValue);
  25744. const String getParameterName (int index);
  25745. const String getParameterText (int index);
  25746. bool isParameterAutomatable (int index) const;
  25747. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25748. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25749. void setCurrentProgram (int index);
  25750. const String getProgramName (int index);
  25751. void changeProgramName (int index, const String& newName);
  25752. void getStateInformation (MemoryBlock& destData);
  25753. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25754. void setStateInformation (const void* data, int sizeInBytes);
  25755. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25756. void timerCallback();
  25757. void handleAsyncUpdate();
  25758. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25759. juce_UseDebuggingNewOperator
  25760. private:
  25761. friend class VSTPluginWindow;
  25762. friend class VSTPluginFormat;
  25763. AEffect* effect;
  25764. String name;
  25765. CriticalSection lock;
  25766. bool wantsMidiMessages, initialised, isPowerOn;
  25767. mutable StringArray programNames;
  25768. AudioSampleBuffer tempBuffer;
  25769. CriticalSection midiInLock;
  25770. MidiBuffer incomingMidi;
  25771. VSTMidiEventList midiEventsToSend;
  25772. VstTimeInfo vstHostTime;
  25773. HeapBlock <float*> channels;
  25774. ReferenceCountedObjectPtr <ModuleHandle> module;
  25775. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25776. bool restoreProgramSettings (const fxProgram* const prog);
  25777. const String getCurrentProgramName();
  25778. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25779. void updateStoredProgramNames();
  25780. void initialise();
  25781. void handleMidiFromPlugin (const VstEvents* const events);
  25782. void createTempParameterStore (MemoryBlock& dest);
  25783. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25784. const String getParameterLabel (int index) const;
  25785. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25786. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25787. void setChunkData (const char* data, int size, bool isPreset);
  25788. bool loadFromFXBFile (const void* data, int numBytes);
  25789. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25790. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25791. const String getVersion() const throw();
  25792. const String getCategory() const throw();
  25793. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25794. void setPower (const bool on);
  25795. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25796. };
  25797. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25798. : effect (0),
  25799. wantsMidiMessages (false),
  25800. initialised (false),
  25801. isPowerOn (false),
  25802. tempBuffer (1, 1),
  25803. module (module_)
  25804. {
  25805. try
  25806. {
  25807. _fpreset();
  25808. ++insideVSTCallback;
  25809. name = module->pluginName;
  25810. log ("Creating VST instance: " + name);
  25811. #if JUCE_MAC
  25812. if (module->resFileId != 0)
  25813. UseResFile (module->resFileId);
  25814. #if JUCE_PPC
  25815. if (module->fragId != 0)
  25816. {
  25817. static void* audioMasterCoerced = 0;
  25818. if (audioMasterCoerced == 0)
  25819. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25820. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25821. }
  25822. else
  25823. #endif
  25824. #endif
  25825. {
  25826. effect = module->moduleMain (&audioMaster);
  25827. }
  25828. --insideVSTCallback;
  25829. if (effect != 0 && effect->magic == kEffectMagic)
  25830. {
  25831. #if JUCE_PPC
  25832. module->coerceAEffectFunctionCalls (effect);
  25833. #endif
  25834. jassert (effect->resvd2 == 0);
  25835. jassert (effect->object != 0);
  25836. _fpreset(); // some dodgy plugs fuck around with this
  25837. }
  25838. else
  25839. {
  25840. effect = 0;
  25841. }
  25842. }
  25843. catch (...)
  25844. {
  25845. --insideVSTCallback;
  25846. }
  25847. }
  25848. VSTPluginInstance::~VSTPluginInstance()
  25849. {
  25850. {
  25851. const ScopedLock sl (lock);
  25852. jassert (insideVSTCallback == 0);
  25853. if (effect != 0 && effect->magic == kEffectMagic)
  25854. {
  25855. try
  25856. {
  25857. #if JUCE_MAC
  25858. if (module->resFileId != 0)
  25859. UseResFile (module->resFileId);
  25860. #endif
  25861. // Must delete any editors before deleting the plugin instance!
  25862. jassert (getActiveEditor() == 0);
  25863. _fpreset(); // some dodgy plugs fuck around with this
  25864. module->closeEffect (effect);
  25865. }
  25866. catch (...)
  25867. {}
  25868. }
  25869. module = 0;
  25870. effect = 0;
  25871. }
  25872. }
  25873. void VSTPluginInstance::initialise()
  25874. {
  25875. if (initialised || effect == 0)
  25876. return;
  25877. log ("Initialising VST: " + module->pluginName);
  25878. initialised = true;
  25879. dispatch (effIdentify, 0, 0, 0, 0);
  25880. // this code would ask the plugin for its name, but so few plugins
  25881. // actually bother implementing this correctly, that it's better to
  25882. // just ignore it and use the file name instead.
  25883. if (getSampleRate() > 0)
  25884. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25885. if (getBlockSize() > 0)
  25886. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25887. dispatch (effOpen, 0, 0, 0, 0);
  25888. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25889. getSampleRate(), getBlockSize());
  25890. if (getNumPrograms() > 1)
  25891. setCurrentProgram (0);
  25892. else
  25893. dispatch (effSetProgram, 0, 0, 0, 0);
  25894. int i;
  25895. for (i = effect->numInputs; --i >= 0;)
  25896. dispatch (effConnectInput, i, 1, 0, 0);
  25897. for (i = effect->numOutputs; --i >= 0;)
  25898. dispatch (effConnectOutput, i, 1, 0, 0);
  25899. updateStoredProgramNames();
  25900. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25901. setLatencySamples (effect->initialDelay);
  25902. }
  25903. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25904. int samplesPerBlockExpected)
  25905. {
  25906. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25907. sampleRate_, samplesPerBlockExpected);
  25908. setLatencySamples (effect->initialDelay);
  25909. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25910. vstHostTime.tempo = 120.0;
  25911. vstHostTime.timeSigNumerator = 4;
  25912. vstHostTime.timeSigDenominator = 4;
  25913. vstHostTime.sampleRate = sampleRate_;
  25914. vstHostTime.samplePos = 0;
  25915. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25916. initialise();
  25917. if (initialised)
  25918. {
  25919. wantsMidiMessages = wantsMidiMessages
  25920. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25921. if (wantsMidiMessages)
  25922. midiEventsToSend.ensureSize (256);
  25923. else
  25924. midiEventsToSend.freeEvents();
  25925. incomingMidi.clear();
  25926. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25927. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25928. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25929. if (! isPowerOn)
  25930. setPower (true);
  25931. // dodgy hack to force some plugins to initialise the sample rate..
  25932. if ((! hasEditor()) && getNumParameters() > 0)
  25933. {
  25934. const float old = getParameter (0);
  25935. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25936. setParameter (0, old);
  25937. }
  25938. dispatch (effStartProcess, 0, 0, 0, 0);
  25939. }
  25940. }
  25941. void VSTPluginInstance::releaseResources()
  25942. {
  25943. if (initialised)
  25944. {
  25945. dispatch (effStopProcess, 0, 0, 0, 0);
  25946. setPower (false);
  25947. }
  25948. tempBuffer.setSize (1, 1);
  25949. incomingMidi.clear();
  25950. midiEventsToSend.freeEvents();
  25951. channels.free();
  25952. }
  25953. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  25954. MidiBuffer& midiMessages)
  25955. {
  25956. const int numSamples = buffer.getNumSamples();
  25957. if (initialised)
  25958. {
  25959. AudioPlayHead* playHead = getPlayHead();
  25960. if (playHead != 0)
  25961. {
  25962. AudioPlayHead::CurrentPositionInfo position;
  25963. playHead->getCurrentPosition (position);
  25964. vstHostTime.tempo = position.bpm;
  25965. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  25966. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  25967. vstHostTime.ppqPos = position.ppqPosition;
  25968. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  25969. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  25970. if (position.isPlaying)
  25971. vstHostTime.flags |= kVstTransportPlaying;
  25972. else
  25973. vstHostTime.flags &= ~kVstTransportPlaying;
  25974. }
  25975. #if JUCE_WIN32
  25976. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  25977. #elif JUCE_LINUX
  25978. timeval micro;
  25979. gettimeofday (&micro, 0);
  25980. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  25981. #elif JUCE_MAC
  25982. UnsignedWide micro;
  25983. Microseconds (&micro);
  25984. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  25985. #endif
  25986. if (wantsMidiMessages)
  25987. {
  25988. midiEventsToSend.clear();
  25989. midiEventsToSend.ensureSize (1);
  25990. MidiBuffer::Iterator iter (midiMessages);
  25991. const uint8* midiData;
  25992. int numBytesOfMidiData, samplePosition;
  25993. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  25994. {
  25995. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  25996. jlimit (0, numSamples - 1, samplePosition));
  25997. }
  25998. try
  25999. {
  26000. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26001. }
  26002. catch (...)
  26003. {}
  26004. }
  26005. int i;
  26006. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26007. for (i = 0; i < maxChans; ++i)
  26008. channels[i] = buffer.getSampleData (i);
  26009. channels [maxChans] = 0;
  26010. _clearfp();
  26011. if ((effect->flags & effFlagsCanReplacing) != 0)
  26012. {
  26013. try
  26014. {
  26015. effect->processReplacing (effect, channels, channels, numSamples);
  26016. }
  26017. catch (...)
  26018. {}
  26019. }
  26020. else
  26021. {
  26022. tempBuffer.setSize (effect->numOutputs, numSamples);
  26023. tempBuffer.clear();
  26024. float* outs [64];
  26025. for (i = effect->numOutputs; --i >= 0;)
  26026. outs[i] = tempBuffer.getSampleData (i);
  26027. outs [effect->numOutputs] = 0;
  26028. try
  26029. {
  26030. effect->process (effect, channels, outs, numSamples);
  26031. }
  26032. catch (...)
  26033. {}
  26034. for (i = effect->numOutputs; --i >= 0;)
  26035. buffer.copyFrom (i, 0, outs[i], numSamples);
  26036. }
  26037. }
  26038. else
  26039. {
  26040. // Not initialised, so just bypass..
  26041. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26042. buffer.clear (i, 0, buffer.getNumSamples());
  26043. }
  26044. {
  26045. // copy any incoming midi..
  26046. const ScopedLock sl (midiInLock);
  26047. midiMessages = incomingMidi;
  26048. incomingMidi.clear();
  26049. }
  26050. }
  26051. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26052. {
  26053. if (events != 0)
  26054. {
  26055. const ScopedLock sl (midiInLock);
  26056. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26057. }
  26058. }
  26059. static Array <VSTPluginWindow*> activeVSTWindows;
  26060. class VSTPluginWindow : public AudioProcessorEditor,
  26061. #if ! JUCE_MAC
  26062. public ComponentMovementWatcher,
  26063. #endif
  26064. public Timer
  26065. {
  26066. public:
  26067. VSTPluginWindow (VSTPluginInstance& plugin_)
  26068. : AudioProcessorEditor (&plugin_),
  26069. #if ! JUCE_MAC
  26070. ComponentMovementWatcher (this),
  26071. #endif
  26072. plugin (plugin_),
  26073. isOpen (false),
  26074. wasShowing (false),
  26075. pluginRefusesToResize (false),
  26076. pluginWantsKeys (false),
  26077. alreadyInside (false),
  26078. recursiveResize (false)
  26079. {
  26080. #if JUCE_WIN32
  26081. sizeCheckCount = 0;
  26082. pluginHWND = 0;
  26083. #elif JUCE_LINUX
  26084. pluginWindow = None;
  26085. pluginProc = None;
  26086. #else
  26087. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26088. #endif
  26089. activeVSTWindows.add (this);
  26090. setSize (1, 1);
  26091. setOpaque (true);
  26092. setVisible (true);
  26093. }
  26094. ~VSTPluginWindow()
  26095. {
  26096. #if JUCE_MAC
  26097. innerWrapper = 0;
  26098. #else
  26099. closePluginWindow();
  26100. #endif
  26101. activeVSTWindows.removeValue (this);
  26102. plugin.editorBeingDeleted (this);
  26103. }
  26104. #if ! JUCE_MAC
  26105. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26106. {
  26107. if (recursiveResize)
  26108. return;
  26109. Component* const topComp = getTopLevelComponent();
  26110. if (topComp->getPeer() != 0)
  26111. {
  26112. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26113. recursiveResize = true;
  26114. #if JUCE_WIN32
  26115. if (pluginHWND != 0)
  26116. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26117. #elif JUCE_LINUX
  26118. if (pluginWindow != 0)
  26119. {
  26120. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26121. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26122. XMapRaised (display, pluginWindow);
  26123. }
  26124. #endif
  26125. recursiveResize = false;
  26126. }
  26127. }
  26128. void componentVisibilityChanged (Component&)
  26129. {
  26130. const bool isShowingNow = isShowing();
  26131. if (wasShowing != isShowingNow)
  26132. {
  26133. wasShowing = isShowingNow;
  26134. if (isShowingNow)
  26135. openPluginWindow();
  26136. else
  26137. closePluginWindow();
  26138. }
  26139. componentMovedOrResized (true, true);
  26140. }
  26141. void componentPeerChanged()
  26142. {
  26143. closePluginWindow();
  26144. openPluginWindow();
  26145. }
  26146. #endif
  26147. bool keyStateChanged (bool)
  26148. {
  26149. return pluginWantsKeys;
  26150. }
  26151. bool keyPressed (const KeyPress&)
  26152. {
  26153. return pluginWantsKeys;
  26154. }
  26155. #if JUCE_MAC
  26156. void paint (Graphics& g)
  26157. {
  26158. g.fillAll (Colours::black);
  26159. }
  26160. #else
  26161. void paint (Graphics& g)
  26162. {
  26163. if (isOpen)
  26164. {
  26165. ComponentPeer* const peer = getPeer();
  26166. if (peer != 0)
  26167. {
  26168. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26169. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26170. #if JUCE_LINUX
  26171. if (pluginWindow != 0)
  26172. {
  26173. const Rectangle<int> clip (g.getClipBounds());
  26174. XEvent ev;
  26175. zerostruct (ev);
  26176. ev.xexpose.type = Expose;
  26177. ev.xexpose.display = display;
  26178. ev.xexpose.window = pluginWindow;
  26179. ev.xexpose.x = clip.getX();
  26180. ev.xexpose.y = clip.getY();
  26181. ev.xexpose.width = clip.getWidth();
  26182. ev.xexpose.height = clip.getHeight();
  26183. sendEventToChild (&ev);
  26184. }
  26185. #endif
  26186. }
  26187. }
  26188. else
  26189. {
  26190. g.fillAll (Colours::black);
  26191. }
  26192. }
  26193. #endif
  26194. void timerCallback()
  26195. {
  26196. #if JUCE_WIN32
  26197. if (--sizeCheckCount <= 0)
  26198. {
  26199. sizeCheckCount = 10;
  26200. checkPluginWindowSize();
  26201. }
  26202. #endif
  26203. try
  26204. {
  26205. static bool reentrant = false;
  26206. if (! reentrant)
  26207. {
  26208. reentrant = true;
  26209. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26210. reentrant = false;
  26211. }
  26212. }
  26213. catch (...)
  26214. {}
  26215. }
  26216. void mouseDown (const MouseEvent& e)
  26217. {
  26218. #if JUCE_LINUX
  26219. if (pluginWindow == 0)
  26220. return;
  26221. toFront (true);
  26222. XEvent ev;
  26223. zerostruct (ev);
  26224. ev.xbutton.display = display;
  26225. ev.xbutton.type = ButtonPress;
  26226. ev.xbutton.window = pluginWindow;
  26227. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26228. ev.xbutton.time = CurrentTime;
  26229. ev.xbutton.x = e.x;
  26230. ev.xbutton.y = e.y;
  26231. ev.xbutton.x_root = e.getScreenX();
  26232. ev.xbutton.y_root = e.getScreenY();
  26233. translateJuceToXButtonModifiers (e, ev);
  26234. sendEventToChild (&ev);
  26235. #elif JUCE_WIN32
  26236. (void) e;
  26237. toFront (true);
  26238. #endif
  26239. }
  26240. void broughtToFront()
  26241. {
  26242. activeVSTWindows.removeValue (this);
  26243. activeVSTWindows.add (this);
  26244. #if JUCE_MAC
  26245. dispatch (effEditTop, 0, 0, 0, 0);
  26246. #endif
  26247. }
  26248. juce_UseDebuggingNewOperator
  26249. private:
  26250. VSTPluginInstance& plugin;
  26251. bool isOpen, wasShowing, recursiveResize;
  26252. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26253. #if JUCE_WIN32
  26254. HWND pluginHWND;
  26255. void* originalWndProc;
  26256. int sizeCheckCount;
  26257. #elif JUCE_LINUX
  26258. Window pluginWindow;
  26259. EventProcPtr pluginProc;
  26260. #endif
  26261. #if JUCE_MAC
  26262. void openPluginWindow (WindowRef parentWindow)
  26263. {
  26264. if (isOpen || parentWindow == 0)
  26265. return;
  26266. isOpen = true;
  26267. ERect* rect = 0;
  26268. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26269. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26270. // do this before and after like in the steinberg example
  26271. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26272. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26273. // Install keyboard hooks
  26274. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26275. // double-check it's not too tiny
  26276. int w = 250, h = 150;
  26277. if (rect != 0)
  26278. {
  26279. w = rect->right - rect->left;
  26280. h = rect->bottom - rect->top;
  26281. if (w == 0 || h == 0)
  26282. {
  26283. w = 250;
  26284. h = 150;
  26285. }
  26286. }
  26287. w = jmax (w, 32);
  26288. h = jmax (h, 32);
  26289. setSize (w, h);
  26290. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26291. repaint();
  26292. }
  26293. #else
  26294. void openPluginWindow()
  26295. {
  26296. if (isOpen || getWindowHandle() == 0)
  26297. return;
  26298. log ("Opening VST UI: " + plugin.name);
  26299. isOpen = true;
  26300. ERect* rect = 0;
  26301. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26302. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26303. // do this before and after like in the steinberg example
  26304. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26305. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26306. // Install keyboard hooks
  26307. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26308. #if JUCE_WIN32
  26309. originalWndProc = 0;
  26310. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26311. if (pluginHWND == 0)
  26312. {
  26313. isOpen = false;
  26314. setSize (300, 150);
  26315. return;
  26316. }
  26317. #pragma warning (push)
  26318. #pragma warning (disable: 4244)
  26319. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26320. if (! pluginWantsKeys)
  26321. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) vstHookWndProc);
  26322. #pragma warning (pop)
  26323. int w, h;
  26324. RECT r;
  26325. GetWindowRect (pluginHWND, &r);
  26326. w = r.right - r.left;
  26327. h = r.bottom - r.top;
  26328. if (rect != 0)
  26329. {
  26330. const int rw = rect->right - rect->left;
  26331. const int rh = rect->bottom - rect->top;
  26332. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26333. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26334. {
  26335. // very dodgy logic to decide which size is right.
  26336. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26337. {
  26338. SetWindowPos (pluginHWND, 0,
  26339. 0, 0, rw, rh,
  26340. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26341. GetWindowRect (pluginHWND, &r);
  26342. w = r.right - r.left;
  26343. h = r.bottom - r.top;
  26344. pluginRefusesToResize = (w != rw) || (h != rh);
  26345. w = rw;
  26346. h = rh;
  26347. }
  26348. }
  26349. }
  26350. #elif JUCE_LINUX
  26351. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26352. if (pluginWindow != 0)
  26353. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26354. XInternAtom (display, "_XEventProc", False));
  26355. int w = 250, h = 150;
  26356. if (rect != 0)
  26357. {
  26358. w = rect->right - rect->left;
  26359. h = rect->bottom - rect->top;
  26360. if (w == 0 || h == 0)
  26361. {
  26362. w = 250;
  26363. h = 150;
  26364. }
  26365. }
  26366. if (pluginWindow != 0)
  26367. XMapRaised (display, pluginWindow);
  26368. #endif
  26369. // double-check it's not too tiny
  26370. w = jmax (w, 32);
  26371. h = jmax (h, 32);
  26372. setSize (w, h);
  26373. #if JUCE_WIN32
  26374. checkPluginWindowSize();
  26375. #endif
  26376. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26377. repaint();
  26378. }
  26379. #endif
  26380. #if ! JUCE_MAC
  26381. void closePluginWindow()
  26382. {
  26383. if (isOpen)
  26384. {
  26385. log ("Closing VST UI: " + plugin.getName());
  26386. isOpen = false;
  26387. dispatch (effEditClose, 0, 0, 0, 0);
  26388. #if JUCE_WIN32
  26389. #pragma warning (push)
  26390. #pragma warning (disable: 4244)
  26391. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26392. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) originalWndProc);
  26393. #pragma warning (pop)
  26394. stopTimer();
  26395. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26396. DestroyWindow (pluginHWND);
  26397. pluginHWND = 0;
  26398. #elif JUCE_LINUX
  26399. stopTimer();
  26400. pluginWindow = 0;
  26401. pluginProc = 0;
  26402. #endif
  26403. }
  26404. }
  26405. #endif
  26406. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26407. {
  26408. return plugin.dispatch (opcode, index, value, ptr, opt);
  26409. }
  26410. #if JUCE_WIN32
  26411. void checkPluginWindowSize() throw()
  26412. {
  26413. RECT r;
  26414. GetWindowRect (pluginHWND, &r);
  26415. const int w = r.right - r.left;
  26416. const int h = r.bottom - r.top;
  26417. if (isShowing() && w > 0 && h > 0
  26418. && (w != getWidth() || h != getHeight())
  26419. && ! pluginRefusesToResize)
  26420. {
  26421. setSize (w, h);
  26422. sizeCheckCount = 0;
  26423. }
  26424. }
  26425. // hooks to get keyboard events from VST windows..
  26426. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26427. {
  26428. for (int i = activeVSTWindows.size(); --i >= 0;)
  26429. {
  26430. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26431. if (w->pluginHWND == hW)
  26432. {
  26433. if (message == WM_CHAR
  26434. || message == WM_KEYDOWN
  26435. || message == WM_SYSKEYDOWN
  26436. || message == WM_KEYUP
  26437. || message == WM_SYSKEYUP
  26438. || message == WM_APPCOMMAND)
  26439. {
  26440. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26441. message, wParam, lParam);
  26442. }
  26443. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26444. (HWND) w->pluginHWND,
  26445. message,
  26446. wParam,
  26447. lParam);
  26448. }
  26449. }
  26450. return DefWindowProc (hW, message, wParam, lParam);
  26451. }
  26452. #endif
  26453. #if JUCE_LINUX
  26454. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26455. void sendEventToChild (XEvent* event)
  26456. {
  26457. if (pluginProc != 0)
  26458. {
  26459. // if the plugin publishes an event procedure, pass the event directly..
  26460. pluginProc (event);
  26461. }
  26462. else if (pluginWindow != 0)
  26463. {
  26464. // if the plugin has a window, then send the event to the window so that
  26465. // its message thread will pick it up..
  26466. XSendEvent (display, pluginWindow, False, 0L, event);
  26467. XFlush (display);
  26468. }
  26469. }
  26470. void mouseEnter (const MouseEvent& e)
  26471. {
  26472. if (pluginWindow != 0)
  26473. {
  26474. XEvent ev;
  26475. zerostruct (ev);
  26476. ev.xcrossing.display = display;
  26477. ev.xcrossing.type = EnterNotify;
  26478. ev.xcrossing.window = pluginWindow;
  26479. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26480. ev.xcrossing.time = CurrentTime;
  26481. ev.xcrossing.x = e.x;
  26482. ev.xcrossing.y = e.y;
  26483. ev.xcrossing.x_root = e.getScreenX();
  26484. ev.xcrossing.y_root = e.getScreenY();
  26485. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26486. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26487. translateJuceToXCrossingModifiers (e, ev);
  26488. sendEventToChild (&ev);
  26489. }
  26490. }
  26491. void mouseExit (const MouseEvent& e)
  26492. {
  26493. if (pluginWindow != 0)
  26494. {
  26495. XEvent ev;
  26496. zerostruct (ev);
  26497. ev.xcrossing.display = display;
  26498. ev.xcrossing.type = LeaveNotify;
  26499. ev.xcrossing.window = pluginWindow;
  26500. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26501. ev.xcrossing.time = CurrentTime;
  26502. ev.xcrossing.x = e.x;
  26503. ev.xcrossing.y = e.y;
  26504. ev.xcrossing.x_root = e.getScreenX();
  26505. ev.xcrossing.y_root = e.getScreenY();
  26506. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26507. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26508. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26509. translateJuceToXCrossingModifiers (e, ev);
  26510. sendEventToChild (&ev);
  26511. }
  26512. }
  26513. void mouseMove (const MouseEvent& e)
  26514. {
  26515. if (pluginWindow != 0)
  26516. {
  26517. XEvent ev;
  26518. zerostruct (ev);
  26519. ev.xmotion.display = display;
  26520. ev.xmotion.type = MotionNotify;
  26521. ev.xmotion.window = pluginWindow;
  26522. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26523. ev.xmotion.time = CurrentTime;
  26524. ev.xmotion.is_hint = NotifyNormal;
  26525. ev.xmotion.x = e.x;
  26526. ev.xmotion.y = e.y;
  26527. ev.xmotion.x_root = e.getScreenX();
  26528. ev.xmotion.y_root = e.getScreenY();
  26529. sendEventToChild (&ev);
  26530. }
  26531. }
  26532. void mouseDrag (const MouseEvent& e)
  26533. {
  26534. if (pluginWindow != 0)
  26535. {
  26536. XEvent ev;
  26537. zerostruct (ev);
  26538. ev.xmotion.display = display;
  26539. ev.xmotion.type = MotionNotify;
  26540. ev.xmotion.window = pluginWindow;
  26541. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26542. ev.xmotion.time = CurrentTime;
  26543. ev.xmotion.x = e.x ;
  26544. ev.xmotion.y = e.y;
  26545. ev.xmotion.x_root = e.getScreenX();
  26546. ev.xmotion.y_root = e.getScreenY();
  26547. ev.xmotion.is_hint = NotifyNormal;
  26548. translateJuceToXMotionModifiers (e, ev);
  26549. sendEventToChild (&ev);
  26550. }
  26551. }
  26552. void mouseUp (const MouseEvent& e)
  26553. {
  26554. if (pluginWindow != 0)
  26555. {
  26556. XEvent ev;
  26557. zerostruct (ev);
  26558. ev.xbutton.display = display;
  26559. ev.xbutton.type = ButtonRelease;
  26560. ev.xbutton.window = pluginWindow;
  26561. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26562. ev.xbutton.time = CurrentTime;
  26563. ev.xbutton.x = e.x;
  26564. ev.xbutton.y = e.y;
  26565. ev.xbutton.x_root = e.getScreenX();
  26566. ev.xbutton.y_root = e.getScreenY();
  26567. translateJuceToXButtonModifiers (e, ev);
  26568. sendEventToChild (&ev);
  26569. }
  26570. }
  26571. void mouseWheelMove (const MouseEvent& e,
  26572. float incrementX,
  26573. float incrementY)
  26574. {
  26575. if (pluginWindow != 0)
  26576. {
  26577. XEvent ev;
  26578. zerostruct (ev);
  26579. ev.xbutton.display = display;
  26580. ev.xbutton.type = ButtonPress;
  26581. ev.xbutton.window = pluginWindow;
  26582. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26583. ev.xbutton.time = CurrentTime;
  26584. ev.xbutton.x = e.x;
  26585. ev.xbutton.y = e.y;
  26586. ev.xbutton.x_root = e.getScreenX();
  26587. ev.xbutton.y_root = e.getScreenY();
  26588. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26589. sendEventToChild (&ev);
  26590. // TODO - put a usleep here ?
  26591. ev.xbutton.type = ButtonRelease;
  26592. sendEventToChild (&ev);
  26593. }
  26594. }
  26595. #endif
  26596. #if JUCE_MAC
  26597. #if ! JUCE_SUPPORT_CARBON
  26598. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26599. #endif
  26600. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26601. {
  26602. public:
  26603. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26604. : owner (owner_),
  26605. alreadyInside (false)
  26606. {
  26607. }
  26608. ~InnerWrapperComponent()
  26609. {
  26610. deleteWindow();
  26611. }
  26612. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26613. {
  26614. owner->openPluginWindow (windowRef);
  26615. return 0;
  26616. }
  26617. void removeView (HIViewRef)
  26618. {
  26619. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26620. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26621. }
  26622. bool getEmbeddedViewSize (int& w, int& h)
  26623. {
  26624. ERect* rect = 0;
  26625. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26626. w = rect->right - rect->left;
  26627. h = rect->bottom - rect->top;
  26628. return true;
  26629. }
  26630. void mouseDown (int x, int y)
  26631. {
  26632. if (! alreadyInside)
  26633. {
  26634. alreadyInside = true;
  26635. getTopLevelComponent()->toFront (true);
  26636. owner->dispatch (effEditMouse, x, y, 0, 0);
  26637. alreadyInside = false;
  26638. }
  26639. else
  26640. {
  26641. PostEvent (::mouseDown, 0);
  26642. }
  26643. }
  26644. void paint()
  26645. {
  26646. ComponentPeer* const peer = getPeer();
  26647. if (peer != 0)
  26648. {
  26649. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26650. ERect r;
  26651. r.left = pos.getX();
  26652. r.right = r.left + getWidth();
  26653. r.top = pos.getY();
  26654. r.bottom = r.top + getHeight();
  26655. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26656. }
  26657. }
  26658. private:
  26659. VSTPluginWindow* const owner;
  26660. bool alreadyInside;
  26661. };
  26662. friend class InnerWrapperComponent;
  26663. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26664. void resized()
  26665. {
  26666. innerWrapper->setSize (getWidth(), getHeight());
  26667. }
  26668. #endif
  26669. };
  26670. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26671. {
  26672. if (hasEditor())
  26673. return new VSTPluginWindow (*this);
  26674. return 0;
  26675. }
  26676. void VSTPluginInstance::handleAsyncUpdate()
  26677. {
  26678. // indicates that something about the plugin has changed..
  26679. updateHostDisplay();
  26680. }
  26681. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26682. {
  26683. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26684. {
  26685. changeProgramName (getCurrentProgram(), prog->prgName);
  26686. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26687. setParameter (i, vst_swapFloat (prog->params[i]));
  26688. return true;
  26689. }
  26690. return false;
  26691. }
  26692. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26693. const int dataSize)
  26694. {
  26695. if (dataSize < 28)
  26696. return false;
  26697. const fxSet* const set = (const fxSet*) data;
  26698. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26699. || vst_swap (set->version) > fxbVersionNum)
  26700. return false;
  26701. if (vst_swap (set->fxMagic) == 'FxBk')
  26702. {
  26703. // bank of programs
  26704. if (vst_swap (set->numPrograms) >= 0)
  26705. {
  26706. const int oldProg = getCurrentProgram();
  26707. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26708. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26709. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26710. {
  26711. if (i != oldProg)
  26712. {
  26713. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26714. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26715. return false;
  26716. if (vst_swap (set->numPrograms) > 0)
  26717. setCurrentProgram (i);
  26718. if (! restoreProgramSettings (prog))
  26719. return false;
  26720. }
  26721. }
  26722. if (vst_swap (set->numPrograms) > 0)
  26723. setCurrentProgram (oldProg);
  26724. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26725. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26726. return false;
  26727. if (! restoreProgramSettings (prog))
  26728. return false;
  26729. }
  26730. }
  26731. else if (vst_swap (set->fxMagic) == 'FxCk')
  26732. {
  26733. // single program
  26734. const fxProgram* const prog = (const fxProgram*) data;
  26735. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26736. return false;
  26737. changeProgramName (getCurrentProgram(), prog->prgName);
  26738. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26739. setParameter (i, vst_swapFloat (prog->params[i]));
  26740. }
  26741. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26742. {
  26743. // non-preset chunk
  26744. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26745. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26746. return false;
  26747. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26748. }
  26749. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26750. {
  26751. // preset chunk
  26752. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26753. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26754. return false;
  26755. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26756. changeProgramName (getCurrentProgram(), cset->name);
  26757. }
  26758. else
  26759. {
  26760. return false;
  26761. }
  26762. return true;
  26763. }
  26764. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26765. {
  26766. const int numParams = getNumParameters();
  26767. prog->chunkMagic = vst_swap ('CcnK');
  26768. prog->byteSize = 0;
  26769. prog->fxMagic = vst_swap ('FxCk');
  26770. prog->version = vst_swap (fxbVersionNum);
  26771. prog->fxID = vst_swap (getUID());
  26772. prog->fxVersion = vst_swap (getVersionNumber());
  26773. prog->numParams = vst_swap (numParams);
  26774. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26775. for (int i = 0; i < numParams; ++i)
  26776. prog->params[i] = vst_swapFloat (getParameter (i));
  26777. }
  26778. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26779. {
  26780. const int numPrograms = getNumPrograms();
  26781. const int numParams = getNumParameters();
  26782. if (usesChunks())
  26783. {
  26784. if (isFXB)
  26785. {
  26786. MemoryBlock chunk;
  26787. getChunkData (chunk, false, maxSizeMB);
  26788. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26789. dest.setSize (totalLen, true);
  26790. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26791. set->chunkMagic = vst_swap ('CcnK');
  26792. set->byteSize = 0;
  26793. set->fxMagic = vst_swap ('FBCh');
  26794. set->version = vst_swap (fxbVersionNum);
  26795. set->fxID = vst_swap (getUID());
  26796. set->fxVersion = vst_swap (getVersionNumber());
  26797. set->numPrograms = vst_swap (numPrograms);
  26798. set->chunkSize = vst_swap ((long) chunk.getSize());
  26799. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26800. }
  26801. else
  26802. {
  26803. MemoryBlock chunk;
  26804. getChunkData (chunk, true, maxSizeMB);
  26805. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26806. dest.setSize (totalLen, true);
  26807. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26808. set->chunkMagic = vst_swap ('CcnK');
  26809. set->byteSize = 0;
  26810. set->fxMagic = vst_swap ('FPCh');
  26811. set->version = vst_swap (fxbVersionNum);
  26812. set->fxID = vst_swap (getUID());
  26813. set->fxVersion = vst_swap (getVersionNumber());
  26814. set->numPrograms = vst_swap (numPrograms);
  26815. set->chunkSize = vst_swap ((long) chunk.getSize());
  26816. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26817. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26818. }
  26819. }
  26820. else
  26821. {
  26822. if (isFXB)
  26823. {
  26824. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26825. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26826. dest.setSize (len, true);
  26827. fxSet* const set = (fxSet*) dest.getData();
  26828. set->chunkMagic = vst_swap ('CcnK');
  26829. set->byteSize = 0;
  26830. set->fxMagic = vst_swap ('FxBk');
  26831. set->version = vst_swap (fxbVersionNum);
  26832. set->fxID = vst_swap (getUID());
  26833. set->fxVersion = vst_swap (getVersionNumber());
  26834. set->numPrograms = vst_swap (numPrograms);
  26835. const int oldProgram = getCurrentProgram();
  26836. MemoryBlock oldSettings;
  26837. createTempParameterStore (oldSettings);
  26838. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26839. for (int i = 0; i < numPrograms; ++i)
  26840. {
  26841. if (i != oldProgram)
  26842. {
  26843. setCurrentProgram (i);
  26844. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26845. }
  26846. }
  26847. setCurrentProgram (oldProgram);
  26848. restoreFromTempParameterStore (oldSettings);
  26849. }
  26850. else
  26851. {
  26852. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26853. dest.setSize (totalLen, true);
  26854. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26855. }
  26856. }
  26857. return true;
  26858. }
  26859. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26860. {
  26861. if (usesChunks())
  26862. {
  26863. void* data = 0;
  26864. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26865. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26866. {
  26867. mb.setSize (bytes);
  26868. mb.copyFrom (data, 0, bytes);
  26869. }
  26870. }
  26871. }
  26872. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26873. {
  26874. if (size > 0 && usesChunks())
  26875. {
  26876. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26877. if (! isPreset)
  26878. updateStoredProgramNames();
  26879. }
  26880. }
  26881. void VSTPluginInstance::timerCallback()
  26882. {
  26883. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26884. stopTimer();
  26885. }
  26886. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26887. {
  26888. const ScopedLock sl (lock);
  26889. ++insideVSTCallback;
  26890. int result = 0;
  26891. try
  26892. {
  26893. if (effect != 0)
  26894. {
  26895. #if JUCE_MAC
  26896. if (module->resFileId != 0)
  26897. UseResFile (module->resFileId);
  26898. CGrafPtr oldPort;
  26899. if (getActiveEditor() != 0)
  26900. {
  26901. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26902. GetPort (&oldPort);
  26903. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26904. SetOrigin (-pos.getX(), -pos.getY());
  26905. }
  26906. #endif
  26907. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26908. #if JUCE_MAC
  26909. if (getActiveEditor() != 0)
  26910. SetPort (oldPort);
  26911. module->resFileId = CurResFile();
  26912. #endif
  26913. --insideVSTCallback;
  26914. return result;
  26915. }
  26916. }
  26917. catch (...)
  26918. {
  26919. }
  26920. --insideVSTCallback;
  26921. return result;
  26922. }
  26923. // handles non plugin-specific callbacks..
  26924. static const int defaultVSTSampleRateValue = 16384;
  26925. static const int defaultVSTBlockSizeValue = 512;
  26926. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26927. {
  26928. (void) index;
  26929. (void) value;
  26930. (void) opt;
  26931. switch (opcode)
  26932. {
  26933. case audioMasterCanDo:
  26934. {
  26935. static const char* canDos[] = { "supplyIdle",
  26936. "sendVstEvents",
  26937. "sendVstMidiEvent",
  26938. "sendVstTimeInfo",
  26939. "receiveVstEvents",
  26940. "receiveVstMidiEvent",
  26941. "supportShell",
  26942. "shellCategory" };
  26943. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26944. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26945. return 1;
  26946. return 0;
  26947. }
  26948. case audioMasterVersion:
  26949. return 0x2400;
  26950. case audioMasterCurrentId:
  26951. return shellUIDToCreate;
  26952. case audioMasterGetNumAutomatableParameters:
  26953. return 0;
  26954. case audioMasterGetAutomationState:
  26955. return 1;
  26956. case audioMasterGetVendorVersion:
  26957. return 0x0101;
  26958. case audioMasterGetVendorString:
  26959. case audioMasterGetProductString:
  26960. {
  26961. String hostName ("Juce VST Host");
  26962. if (JUCEApplication::getInstance() != 0)
  26963. hostName = JUCEApplication::getInstance()->getApplicationName();
  26964. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  26965. }
  26966. break;
  26967. case audioMasterGetSampleRate:
  26968. return (VstIntPtr) defaultVSTSampleRateValue;
  26969. case audioMasterGetBlockSize:
  26970. return (VstIntPtr) defaultVSTBlockSizeValue;
  26971. case audioMasterSetOutputSampleRate:
  26972. return 0;
  26973. default:
  26974. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  26975. break;
  26976. }
  26977. return 0;
  26978. }
  26979. // handles callbacks for a specific plugin
  26980. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26981. {
  26982. switch (opcode)
  26983. {
  26984. case audioMasterAutomate:
  26985. sendParamChangeMessageToListeners (index, opt);
  26986. break;
  26987. case audioMasterProcessEvents:
  26988. handleMidiFromPlugin ((const VstEvents*) ptr);
  26989. break;
  26990. case audioMasterGetTime:
  26991. #ifdef _MSC_VER
  26992. #pragma warning (push)
  26993. #pragma warning (disable: 4311)
  26994. #endif
  26995. return (VstIntPtr) &vstHostTime;
  26996. #ifdef _MSC_VER
  26997. #pragma warning (pop)
  26998. #endif
  26999. break;
  27000. case audioMasterIdle:
  27001. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27002. {
  27003. ++insideVSTCallback;
  27004. #if JUCE_MAC
  27005. if (getActiveEditor() != 0)
  27006. dispatch (effEditIdle, 0, 0, 0, 0);
  27007. #endif
  27008. juce_callAnyTimersSynchronously();
  27009. handleUpdateNowIfNeeded();
  27010. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27011. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27012. --insideVSTCallback;
  27013. }
  27014. break;
  27015. case audioMasterUpdateDisplay:
  27016. triggerAsyncUpdate();
  27017. break;
  27018. case audioMasterTempoAt:
  27019. // returns (10000 * bpm)
  27020. break;
  27021. case audioMasterNeedIdle:
  27022. startTimer (50);
  27023. break;
  27024. case audioMasterSizeWindow:
  27025. if (getActiveEditor() != 0)
  27026. getActiveEditor()->setSize (index, value);
  27027. return 1;
  27028. case audioMasterGetSampleRate:
  27029. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27030. case audioMasterGetBlockSize:
  27031. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27032. case audioMasterWantMidi:
  27033. wantsMidiMessages = true;
  27034. break;
  27035. case audioMasterGetDirectory:
  27036. #if JUCE_MAC
  27037. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27038. #else
  27039. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27040. #endif
  27041. case audioMasterGetAutomationState:
  27042. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27043. break;
  27044. // none of these are handled (yet)..
  27045. case audioMasterBeginEdit:
  27046. case audioMasterEndEdit:
  27047. case audioMasterSetTime:
  27048. case audioMasterPinConnected:
  27049. case audioMasterGetParameterQuantization:
  27050. case audioMasterIOChanged:
  27051. case audioMasterGetInputLatency:
  27052. case audioMasterGetOutputLatency:
  27053. case audioMasterGetPreviousPlug:
  27054. case audioMasterGetNextPlug:
  27055. case audioMasterWillReplaceOrAccumulate:
  27056. case audioMasterGetCurrentProcessLevel:
  27057. case audioMasterOfflineStart:
  27058. case audioMasterOfflineRead:
  27059. case audioMasterOfflineWrite:
  27060. case audioMasterOfflineGetCurrentPass:
  27061. case audioMasterOfflineGetCurrentMetaPass:
  27062. case audioMasterVendorSpecific:
  27063. case audioMasterSetIcon:
  27064. case audioMasterGetLanguage:
  27065. case audioMasterOpenWindow:
  27066. case audioMasterCloseWindow:
  27067. break;
  27068. default:
  27069. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27070. }
  27071. return 0;
  27072. }
  27073. // entry point for all callbacks from the plugin
  27074. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27075. {
  27076. try
  27077. {
  27078. if (effect != 0 && effect->resvd2 != 0)
  27079. {
  27080. return ((VSTPluginInstance*)(effect->resvd2))
  27081. ->handleCallback (opcode, index, value, ptr, opt);
  27082. }
  27083. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27084. }
  27085. catch (...)
  27086. {
  27087. return 0;
  27088. }
  27089. }
  27090. const String VSTPluginInstance::getVersion() const throw()
  27091. {
  27092. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27093. String s;
  27094. if (v == 0 || v == -1)
  27095. v = getVersionNumber();
  27096. if (v != 0)
  27097. {
  27098. int versionBits[4];
  27099. int n = 0;
  27100. while (v != 0)
  27101. {
  27102. versionBits [n++] = (v & 0xff);
  27103. v >>= 8;
  27104. }
  27105. s << 'V';
  27106. while (n > 0)
  27107. {
  27108. s << versionBits [--n];
  27109. if (n > 0)
  27110. s << '.';
  27111. }
  27112. }
  27113. return s;
  27114. }
  27115. int VSTPluginInstance::getUID() const throw()
  27116. {
  27117. int uid = effect != 0 ? effect->uniqueID : 0;
  27118. if (uid == 0)
  27119. uid = module->file.hashCode();
  27120. return uid;
  27121. }
  27122. const String VSTPluginInstance::getCategory() const throw()
  27123. {
  27124. const char* result = 0;
  27125. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27126. {
  27127. case kPlugCategEffect:
  27128. result = "Effect";
  27129. break;
  27130. case kPlugCategSynth:
  27131. result = "Synth";
  27132. break;
  27133. case kPlugCategAnalysis:
  27134. result = "Anaylsis";
  27135. break;
  27136. case kPlugCategMastering:
  27137. result = "Mastering";
  27138. break;
  27139. case kPlugCategSpacializer:
  27140. result = "Spacial";
  27141. break;
  27142. case kPlugCategRoomFx:
  27143. result = "Reverb";
  27144. break;
  27145. case kPlugSurroundFx:
  27146. result = "Surround";
  27147. break;
  27148. case kPlugCategRestoration:
  27149. result = "Restoration";
  27150. break;
  27151. case kPlugCategGenerator:
  27152. result = "Tone generation";
  27153. break;
  27154. default:
  27155. break;
  27156. }
  27157. return result;
  27158. }
  27159. float VSTPluginInstance::getParameter (int index)
  27160. {
  27161. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27162. {
  27163. try
  27164. {
  27165. const ScopedLock sl (lock);
  27166. return effect->getParameter (effect, index);
  27167. }
  27168. catch (...)
  27169. {
  27170. }
  27171. }
  27172. return 0.0f;
  27173. }
  27174. void VSTPluginInstance::setParameter (int index, float newValue)
  27175. {
  27176. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27177. {
  27178. try
  27179. {
  27180. const ScopedLock sl (lock);
  27181. if (effect->getParameter (effect, index) != newValue)
  27182. effect->setParameter (effect, index, newValue);
  27183. }
  27184. catch (...)
  27185. {
  27186. }
  27187. }
  27188. }
  27189. const String VSTPluginInstance::getParameterName (int index)
  27190. {
  27191. if (effect != 0)
  27192. {
  27193. jassert (index >= 0 && index < effect->numParams);
  27194. char nm [256];
  27195. zerostruct (nm);
  27196. dispatch (effGetParamName, index, 0, nm, 0);
  27197. return String (nm).trim();
  27198. }
  27199. return String::empty;
  27200. }
  27201. const String VSTPluginInstance::getParameterLabel (int index) const
  27202. {
  27203. if (effect != 0)
  27204. {
  27205. jassert (index >= 0 && index < effect->numParams);
  27206. char nm [256];
  27207. zerostruct (nm);
  27208. dispatch (effGetParamLabel, index, 0, nm, 0);
  27209. return String (nm).trim();
  27210. }
  27211. return String::empty;
  27212. }
  27213. const String VSTPluginInstance::getParameterText (int index)
  27214. {
  27215. if (effect != 0)
  27216. {
  27217. jassert (index >= 0 && index < effect->numParams);
  27218. char nm [256];
  27219. zerostruct (nm);
  27220. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27221. return String (nm).trim();
  27222. }
  27223. return String::empty;
  27224. }
  27225. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27226. {
  27227. if (effect != 0)
  27228. {
  27229. jassert (index >= 0 && index < effect->numParams);
  27230. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27231. }
  27232. return false;
  27233. }
  27234. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27235. {
  27236. dest.setSize (64 + 4 * getNumParameters());
  27237. dest.fillWith (0);
  27238. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27239. float* const p = (float*) (((char*) dest.getData()) + 64);
  27240. for (int i = 0; i < getNumParameters(); ++i)
  27241. p[i] = getParameter(i);
  27242. }
  27243. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27244. {
  27245. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27246. float* p = (float*) (((char*) m.getData()) + 64);
  27247. for (int i = 0; i < getNumParameters(); ++i)
  27248. setParameter (i, p[i]);
  27249. }
  27250. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27251. {
  27252. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27253. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27254. }
  27255. const String VSTPluginInstance::getProgramName (int index)
  27256. {
  27257. if (index == getCurrentProgram())
  27258. {
  27259. return getCurrentProgramName();
  27260. }
  27261. else if (effect != 0)
  27262. {
  27263. char nm [256];
  27264. zerostruct (nm);
  27265. if (dispatch (effGetProgramNameIndexed,
  27266. jlimit (0, getNumPrograms(), index),
  27267. -1, nm, 0) != 0)
  27268. {
  27269. return String (nm).trim();
  27270. }
  27271. }
  27272. return programNames [index];
  27273. }
  27274. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27275. {
  27276. if (index == getCurrentProgram())
  27277. {
  27278. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27279. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27280. }
  27281. else
  27282. {
  27283. jassertfalse // xxx not implemented!
  27284. }
  27285. }
  27286. void VSTPluginInstance::updateStoredProgramNames()
  27287. {
  27288. if (effect != 0 && getNumPrograms() > 0)
  27289. {
  27290. char nm [256];
  27291. zerostruct (nm);
  27292. // only do this if the plugin can't use indexed names..
  27293. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27294. {
  27295. const int oldProgram = getCurrentProgram();
  27296. MemoryBlock oldSettings;
  27297. createTempParameterStore (oldSettings);
  27298. for (int i = 0; i < getNumPrograms(); ++i)
  27299. {
  27300. setCurrentProgram (i);
  27301. getCurrentProgramName(); // (this updates the list)
  27302. }
  27303. setCurrentProgram (oldProgram);
  27304. restoreFromTempParameterStore (oldSettings);
  27305. }
  27306. }
  27307. }
  27308. const String VSTPluginInstance::getCurrentProgramName()
  27309. {
  27310. if (effect != 0)
  27311. {
  27312. char nm [256];
  27313. zerostruct (nm);
  27314. dispatch (effGetProgramName, 0, 0, nm, 0);
  27315. const int index = getCurrentProgram();
  27316. if (programNames[index].isEmpty())
  27317. {
  27318. while (programNames.size() < index)
  27319. programNames.add (String::empty);
  27320. programNames.set (index, String (nm).trim());
  27321. }
  27322. return String (nm).trim();
  27323. }
  27324. return String::empty;
  27325. }
  27326. const String VSTPluginInstance::getInputChannelName (const int index) const
  27327. {
  27328. if (index >= 0 && index < getNumInputChannels())
  27329. {
  27330. VstPinProperties pinProps;
  27331. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27332. return String (pinProps.label, sizeof (pinProps.label));
  27333. }
  27334. return String::empty;
  27335. }
  27336. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27337. {
  27338. if (index < 0 || index >= getNumInputChannels())
  27339. return false;
  27340. VstPinProperties pinProps;
  27341. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27342. return (pinProps.flags & kVstPinIsStereo) != 0;
  27343. return true;
  27344. }
  27345. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27346. {
  27347. if (index >= 0 && index < getNumOutputChannels())
  27348. {
  27349. VstPinProperties pinProps;
  27350. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27351. return String (pinProps.label, sizeof (pinProps.label));
  27352. }
  27353. return String::empty;
  27354. }
  27355. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27356. {
  27357. if (index < 0 || index >= getNumOutputChannels())
  27358. return false;
  27359. VstPinProperties pinProps;
  27360. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27361. return (pinProps.flags & kVstPinIsStereo) != 0;
  27362. return true;
  27363. }
  27364. void VSTPluginInstance::setPower (const bool on)
  27365. {
  27366. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27367. isPowerOn = on;
  27368. }
  27369. const int defaultMaxSizeMB = 64;
  27370. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27371. {
  27372. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27373. }
  27374. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27375. {
  27376. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27377. }
  27378. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27379. {
  27380. loadFromFXBFile (data, sizeInBytes);
  27381. }
  27382. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27383. {
  27384. loadFromFXBFile (data, sizeInBytes);
  27385. }
  27386. VSTPluginFormat::VSTPluginFormat()
  27387. {
  27388. }
  27389. VSTPluginFormat::~VSTPluginFormat()
  27390. {
  27391. }
  27392. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27393. const String& fileOrIdentifier)
  27394. {
  27395. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27396. return;
  27397. PluginDescription desc;
  27398. desc.fileOrIdentifier = fileOrIdentifier;
  27399. desc.uid = 0;
  27400. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27401. if (instance == 0)
  27402. return;
  27403. try
  27404. {
  27405. #if JUCE_MAC
  27406. if (instance->module->resFileId != 0)
  27407. UseResFile (instance->module->resFileId);
  27408. #endif
  27409. instance->fillInPluginDescription (desc);
  27410. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27411. if (category != kPlugCategShell)
  27412. {
  27413. // Normal plugin...
  27414. results.add (new PluginDescription (desc));
  27415. ++insideVSTCallback;
  27416. instance->dispatch (effOpen, 0, 0, 0, 0);
  27417. --insideVSTCallback;
  27418. }
  27419. else
  27420. {
  27421. // It's a shell plugin, so iterate all the subtypes...
  27422. char shellEffectName [64];
  27423. for (;;)
  27424. {
  27425. zerostruct (shellEffectName);
  27426. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27427. if (uid == 0)
  27428. {
  27429. break;
  27430. }
  27431. else
  27432. {
  27433. desc.uid = uid;
  27434. desc.name = shellEffectName;
  27435. bool alreadyThere = false;
  27436. for (int i = results.size(); --i >= 0;)
  27437. {
  27438. PluginDescription* const d = results.getUnchecked(i);
  27439. if (d->isDuplicateOf (desc))
  27440. {
  27441. alreadyThere = true;
  27442. break;
  27443. }
  27444. }
  27445. if (! alreadyThere)
  27446. results.add (new PluginDescription (desc));
  27447. }
  27448. }
  27449. }
  27450. }
  27451. catch (...)
  27452. {
  27453. // crashed while loading...
  27454. }
  27455. }
  27456. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27457. {
  27458. ScopedPointer <VSTPluginInstance> result;
  27459. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27460. {
  27461. File file (desc.fileOrIdentifier);
  27462. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27463. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27464. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27465. if (module != 0)
  27466. {
  27467. shellUIDToCreate = desc.uid;
  27468. result = new VSTPluginInstance (module);
  27469. if (result->effect != 0)
  27470. {
  27471. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27472. result->initialise();
  27473. }
  27474. else
  27475. {
  27476. result = 0;
  27477. }
  27478. }
  27479. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27480. }
  27481. return result.release();
  27482. }
  27483. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27484. {
  27485. const File f (fileOrIdentifier);
  27486. #if JUCE_MAC
  27487. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27488. return true;
  27489. #if JUCE_PPC
  27490. FSRef fileRef;
  27491. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27492. {
  27493. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27494. if (resFileId != -1)
  27495. {
  27496. const int numEffects = Count1Resources ('aEff');
  27497. CloseResFile (resFileId);
  27498. if (numEffects > 0)
  27499. return true;
  27500. }
  27501. }
  27502. #endif
  27503. return false;
  27504. #elif JUCE_WIN32
  27505. return f.existsAsFile()
  27506. && f.hasFileExtension (".dll");
  27507. #elif JUCE_LINUX
  27508. return f.existsAsFile()
  27509. && f.hasFileExtension (".so");
  27510. #endif
  27511. }
  27512. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27513. {
  27514. return fileOrIdentifier;
  27515. }
  27516. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27517. {
  27518. return File (desc.fileOrIdentifier).exists();
  27519. }
  27520. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27521. {
  27522. StringArray results;
  27523. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27524. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27525. return results;
  27526. }
  27527. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27528. {
  27529. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27530. // .component or .vst directories.
  27531. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27532. while (iter.next())
  27533. {
  27534. const File f (iter.getFile());
  27535. bool isPlugin = false;
  27536. if (fileMightContainThisPluginType (f.getFullPathName()))
  27537. {
  27538. isPlugin = true;
  27539. results.add (f.getFullPathName());
  27540. }
  27541. if (recursive && (! isPlugin) && f.isDirectory())
  27542. recursiveFileSearch (results, f, true);
  27543. }
  27544. }
  27545. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27546. {
  27547. #if JUCE_MAC
  27548. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27549. #elif JUCE_WIN32
  27550. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27551. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27552. #elif JUCE_LINUX
  27553. return FileSearchPath ("/usr/lib/vst");
  27554. #endif
  27555. }
  27556. END_JUCE_NAMESPACE
  27557. #endif
  27558. #undef log
  27559. #endif
  27560. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27561. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27562. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27563. BEGIN_JUCE_NAMESPACE
  27564. AudioProcessor::AudioProcessor()
  27565. : playHead (0),
  27566. activeEditor (0),
  27567. sampleRate (0),
  27568. blockSize (0),
  27569. numInputChannels (0),
  27570. numOutputChannels (0),
  27571. latencySamples (0),
  27572. suspended (false),
  27573. nonRealtime (false)
  27574. {
  27575. }
  27576. AudioProcessor::~AudioProcessor()
  27577. {
  27578. // ooh, nasty - the editor should have been deleted before the filter
  27579. // that it refers to is deleted..
  27580. jassert (activeEditor == 0);
  27581. #ifdef JUCE_DEBUG
  27582. // This will fail if you've called beginParameterChangeGesture() for one
  27583. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27584. jassert (changingParams.countNumberOfSetBits() == 0);
  27585. #endif
  27586. }
  27587. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27588. {
  27589. playHead = newPlayHead;
  27590. }
  27591. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27592. {
  27593. const ScopedLock sl (listenerLock);
  27594. listeners.addIfNotAlreadyThere (newListener);
  27595. }
  27596. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27597. {
  27598. const ScopedLock sl (listenerLock);
  27599. listeners.removeValue (listenerToRemove);
  27600. }
  27601. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27602. const int numOuts,
  27603. const double sampleRate_,
  27604. const int blockSize_) throw()
  27605. {
  27606. numInputChannels = numIns;
  27607. numOutputChannels = numOuts;
  27608. sampleRate = sampleRate_;
  27609. blockSize = blockSize_;
  27610. }
  27611. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27612. {
  27613. nonRealtime = nonRealtime_;
  27614. }
  27615. void AudioProcessor::setLatencySamples (const int newLatency)
  27616. {
  27617. if (latencySamples != newLatency)
  27618. {
  27619. latencySamples = newLatency;
  27620. updateHostDisplay();
  27621. }
  27622. }
  27623. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27624. const float newValue)
  27625. {
  27626. setParameter (parameterIndex, newValue);
  27627. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27628. }
  27629. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27630. {
  27631. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27632. for (int i = listeners.size(); --i >= 0;)
  27633. {
  27634. AudioProcessorListener* l;
  27635. {
  27636. const ScopedLock sl (listenerLock);
  27637. l = (AudioProcessorListener*) listeners [i];
  27638. }
  27639. if (l != 0)
  27640. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27641. }
  27642. }
  27643. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27644. {
  27645. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27646. #ifdef JUCE_DEBUG
  27647. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27648. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27649. jassert (! changingParams [parameterIndex]);
  27650. changingParams.setBit (parameterIndex);
  27651. #endif
  27652. for (int i = listeners.size(); --i >= 0;)
  27653. {
  27654. AudioProcessorListener* l;
  27655. {
  27656. const ScopedLock sl (listenerLock);
  27657. l = (AudioProcessorListener*) listeners [i];
  27658. }
  27659. if (l != 0)
  27660. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27661. }
  27662. }
  27663. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27664. {
  27665. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27666. #ifdef JUCE_DEBUG
  27667. // This means you've called endParameterChangeGesture without having previously called
  27668. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27669. // calls matched correctly.
  27670. jassert (changingParams [parameterIndex]);
  27671. changingParams.clearBit (parameterIndex);
  27672. #endif
  27673. for (int i = listeners.size(); --i >= 0;)
  27674. {
  27675. AudioProcessorListener* l;
  27676. {
  27677. const ScopedLock sl (listenerLock);
  27678. l = (AudioProcessorListener*) listeners [i];
  27679. }
  27680. if (l != 0)
  27681. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27682. }
  27683. }
  27684. void AudioProcessor::updateHostDisplay()
  27685. {
  27686. for (int i = listeners.size(); --i >= 0;)
  27687. {
  27688. AudioProcessorListener* l;
  27689. {
  27690. const ScopedLock sl (listenerLock);
  27691. l = (AudioProcessorListener*) listeners [i];
  27692. }
  27693. if (l != 0)
  27694. l->audioProcessorChanged (this);
  27695. }
  27696. }
  27697. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27698. {
  27699. return true;
  27700. }
  27701. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27702. {
  27703. return false;
  27704. }
  27705. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27706. {
  27707. const ScopedLock sl (callbackLock);
  27708. suspended = shouldBeSuspended;
  27709. }
  27710. void AudioProcessor::reset()
  27711. {
  27712. }
  27713. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27714. {
  27715. const ScopedLock sl (callbackLock);
  27716. jassert (activeEditor == editor);
  27717. if (activeEditor == editor)
  27718. activeEditor = 0;
  27719. }
  27720. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27721. {
  27722. if (activeEditor != 0)
  27723. return activeEditor;
  27724. AudioProcessorEditor* const ed = createEditor();
  27725. if (ed != 0)
  27726. {
  27727. // you must give your editor comp a size before returning it..
  27728. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27729. const ScopedLock sl (callbackLock);
  27730. activeEditor = ed;
  27731. }
  27732. return ed;
  27733. }
  27734. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27735. {
  27736. getStateInformation (destData);
  27737. }
  27738. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27739. {
  27740. setStateInformation (data, sizeInBytes);
  27741. }
  27742. // magic number to identify memory blocks that we've stored as XML
  27743. const uint32 magicXmlNumber = 0x21324356;
  27744. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27745. JUCE_NAMESPACE::MemoryBlock& destData)
  27746. {
  27747. const String xmlString (xml.createDocument (String::empty, true, false));
  27748. const int stringLength = xmlString.getNumBytesAsUTF8();
  27749. destData.setSize (stringLength + 10);
  27750. char* const d = (char*) destData.getData();
  27751. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27752. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27753. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27754. }
  27755. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27756. const int sizeInBytes)
  27757. {
  27758. if (sizeInBytes > 8
  27759. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27760. {
  27761. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27762. if (stringLength > 0)
  27763. {
  27764. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27765. jmin ((sizeInBytes - 8), stringLength)));
  27766. return doc.getDocumentElement();
  27767. }
  27768. }
  27769. return 0;
  27770. }
  27771. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27772. {
  27773. }
  27774. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27775. {
  27776. }
  27777. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27778. {
  27779. return timeInSeconds == other.timeInSeconds
  27780. && ppqPosition == other.ppqPosition
  27781. && editOriginTime == other.editOriginTime
  27782. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27783. && frameRate == other.frameRate
  27784. && isPlaying == other.isPlaying
  27785. && isRecording == other.isRecording
  27786. && bpm == other.bpm
  27787. && timeSigNumerator == other.timeSigNumerator
  27788. && timeSigDenominator == other.timeSigDenominator;
  27789. }
  27790. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27791. {
  27792. return ! operator== (other);
  27793. }
  27794. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27795. {
  27796. zerostruct (*this);
  27797. timeSigNumerator = 4;
  27798. timeSigDenominator = 4;
  27799. bpm = 120;
  27800. }
  27801. END_JUCE_NAMESPACE
  27802. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27803. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27804. BEGIN_JUCE_NAMESPACE
  27805. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27806. : owner (owner_)
  27807. {
  27808. // the filter must be valid..
  27809. jassert (owner != 0);
  27810. }
  27811. AudioProcessorEditor::~AudioProcessorEditor()
  27812. {
  27813. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27814. // filter for some reason..
  27815. jassert (owner->getActiveEditor() != this);
  27816. }
  27817. END_JUCE_NAMESPACE
  27818. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27819. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27820. BEGIN_JUCE_NAMESPACE
  27821. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27822. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27823. : id (id_),
  27824. processor (processor_),
  27825. isPrepared (false)
  27826. {
  27827. jassert (processor_ != 0);
  27828. }
  27829. AudioProcessorGraph::Node::~Node()
  27830. {
  27831. delete processor;
  27832. }
  27833. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27834. AudioProcessorGraph* const graph)
  27835. {
  27836. if (! isPrepared)
  27837. {
  27838. isPrepared = true;
  27839. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27840. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27841. if (ioProc != 0)
  27842. ioProc->setParentGraph (graph);
  27843. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27844. processor->getNumOutputChannels(),
  27845. sampleRate, blockSize);
  27846. processor->prepareToPlay (sampleRate, blockSize);
  27847. }
  27848. }
  27849. void AudioProcessorGraph::Node::unprepare()
  27850. {
  27851. if (isPrepared)
  27852. {
  27853. isPrepared = false;
  27854. processor->releaseResources();
  27855. }
  27856. }
  27857. AudioProcessorGraph::AudioProcessorGraph()
  27858. : lastNodeId (0),
  27859. renderingBuffers (1, 1),
  27860. currentAudioOutputBuffer (1, 1)
  27861. {
  27862. }
  27863. AudioProcessorGraph::~AudioProcessorGraph()
  27864. {
  27865. clearRenderingSequence();
  27866. clear();
  27867. }
  27868. const String AudioProcessorGraph::getName() const
  27869. {
  27870. return "Audio Graph";
  27871. }
  27872. void AudioProcessorGraph::clear()
  27873. {
  27874. nodes.clear();
  27875. connections.clear();
  27876. triggerAsyncUpdate();
  27877. }
  27878. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27879. {
  27880. for (int i = nodes.size(); --i >= 0;)
  27881. if (nodes.getUnchecked(i)->id == nodeId)
  27882. return nodes.getUnchecked(i);
  27883. return 0;
  27884. }
  27885. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27886. uint32 nodeId)
  27887. {
  27888. if (newProcessor == 0)
  27889. {
  27890. jassertfalse
  27891. return 0;
  27892. }
  27893. if (nodeId == 0)
  27894. {
  27895. nodeId = ++lastNodeId;
  27896. }
  27897. else
  27898. {
  27899. // you can't add a node with an id that already exists in the graph..
  27900. jassert (getNodeForId (nodeId) == 0);
  27901. removeNode (nodeId);
  27902. }
  27903. lastNodeId = nodeId;
  27904. Node* const n = new Node (nodeId, newProcessor);
  27905. nodes.add (n);
  27906. triggerAsyncUpdate();
  27907. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27908. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27909. if (ioProc != 0)
  27910. ioProc->setParentGraph (this);
  27911. return n;
  27912. }
  27913. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27914. {
  27915. disconnectNode (nodeId);
  27916. for (int i = nodes.size(); --i >= 0;)
  27917. {
  27918. if (nodes.getUnchecked(i)->id == nodeId)
  27919. {
  27920. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27921. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27922. if (ioProc != 0)
  27923. ioProc->setParentGraph (0);
  27924. nodes.remove (i);
  27925. triggerAsyncUpdate();
  27926. return true;
  27927. }
  27928. }
  27929. return false;
  27930. }
  27931. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27932. const int sourceChannelIndex,
  27933. const uint32 destNodeId,
  27934. const int destChannelIndex) const
  27935. {
  27936. for (int i = connections.size(); --i >= 0;)
  27937. {
  27938. const Connection* const c = connections.getUnchecked(i);
  27939. if (c->sourceNodeId == sourceNodeId
  27940. && c->destNodeId == destNodeId
  27941. && c->sourceChannelIndex == sourceChannelIndex
  27942. && c->destChannelIndex == destChannelIndex)
  27943. {
  27944. return c;
  27945. }
  27946. }
  27947. return 0;
  27948. }
  27949. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27950. const uint32 possibleDestNodeId) const
  27951. {
  27952. for (int i = connections.size(); --i >= 0;)
  27953. {
  27954. const Connection* const c = connections.getUnchecked(i);
  27955. if (c->sourceNodeId == possibleSourceNodeId
  27956. && c->destNodeId == possibleDestNodeId)
  27957. {
  27958. return true;
  27959. }
  27960. }
  27961. return false;
  27962. }
  27963. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  27964. const int sourceChannelIndex,
  27965. const uint32 destNodeId,
  27966. const int destChannelIndex) const
  27967. {
  27968. if (sourceChannelIndex < 0
  27969. || destChannelIndex < 0
  27970. || sourceNodeId == destNodeId
  27971. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  27972. return false;
  27973. const Node* const source = getNodeForId (sourceNodeId);
  27974. if (source == 0
  27975. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  27976. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  27977. return false;
  27978. const Node* const dest = getNodeForId (destNodeId);
  27979. if (dest == 0
  27980. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  27981. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  27982. return false;
  27983. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  27984. destNodeId, destChannelIndex) == 0;
  27985. }
  27986. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  27987. const int sourceChannelIndex,
  27988. const uint32 destNodeId,
  27989. const int destChannelIndex)
  27990. {
  27991. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  27992. return false;
  27993. Connection* const c = new Connection();
  27994. c->sourceNodeId = sourceNodeId;
  27995. c->sourceChannelIndex = sourceChannelIndex;
  27996. c->destNodeId = destNodeId;
  27997. c->destChannelIndex = destChannelIndex;
  27998. connections.add (c);
  27999. triggerAsyncUpdate();
  28000. return true;
  28001. }
  28002. void AudioProcessorGraph::removeConnection (const int index)
  28003. {
  28004. connections.remove (index);
  28005. triggerAsyncUpdate();
  28006. }
  28007. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28008. const uint32 destNodeId, const int destChannelIndex)
  28009. {
  28010. bool doneAnything = false;
  28011. for (int i = connections.size(); --i >= 0;)
  28012. {
  28013. const Connection* const c = connections.getUnchecked(i);
  28014. if (c->sourceNodeId == sourceNodeId
  28015. && c->destNodeId == destNodeId
  28016. && c->sourceChannelIndex == sourceChannelIndex
  28017. && c->destChannelIndex == destChannelIndex)
  28018. {
  28019. removeConnection (i);
  28020. doneAnything = true;
  28021. triggerAsyncUpdate();
  28022. }
  28023. }
  28024. return doneAnything;
  28025. }
  28026. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28027. {
  28028. bool doneAnything = false;
  28029. for (int i = connections.size(); --i >= 0;)
  28030. {
  28031. const Connection* const c = connections.getUnchecked(i);
  28032. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28033. {
  28034. removeConnection (i);
  28035. doneAnything = true;
  28036. triggerAsyncUpdate();
  28037. }
  28038. }
  28039. return doneAnything;
  28040. }
  28041. bool AudioProcessorGraph::removeIllegalConnections()
  28042. {
  28043. bool doneAnything = false;
  28044. for (int i = connections.size(); --i >= 0;)
  28045. {
  28046. const Connection* const c = connections.getUnchecked(i);
  28047. const Node* const source = getNodeForId (c->sourceNodeId);
  28048. const Node* const dest = getNodeForId (c->destNodeId);
  28049. if (source == 0 || dest == 0
  28050. || (c->sourceChannelIndex != midiChannelIndex
  28051. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28052. || (c->sourceChannelIndex == midiChannelIndex
  28053. && ! source->processor->producesMidi())
  28054. || (c->destChannelIndex != midiChannelIndex
  28055. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28056. || (c->destChannelIndex == midiChannelIndex
  28057. && ! dest->processor->acceptsMidi()))
  28058. {
  28059. removeConnection (i);
  28060. doneAnything = true;
  28061. triggerAsyncUpdate();
  28062. }
  28063. }
  28064. return doneAnything;
  28065. }
  28066. namespace GraphRenderingOps
  28067. {
  28068. class AudioGraphRenderingOp
  28069. {
  28070. public:
  28071. AudioGraphRenderingOp() {}
  28072. virtual ~AudioGraphRenderingOp() {}
  28073. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28074. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28075. const int numSamples) = 0;
  28076. juce_UseDebuggingNewOperator
  28077. };
  28078. class ClearChannelOp : public AudioGraphRenderingOp
  28079. {
  28080. public:
  28081. ClearChannelOp (const int channelNum_)
  28082. : channelNum (channelNum_)
  28083. {}
  28084. ~ClearChannelOp() {}
  28085. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28086. {
  28087. sharedBufferChans.clear (channelNum, 0, numSamples);
  28088. }
  28089. private:
  28090. const int channelNum;
  28091. ClearChannelOp (const ClearChannelOp&);
  28092. ClearChannelOp& operator= (const ClearChannelOp&);
  28093. };
  28094. class CopyChannelOp : public AudioGraphRenderingOp
  28095. {
  28096. public:
  28097. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28098. : srcChannelNum (srcChannelNum_),
  28099. dstChannelNum (dstChannelNum_)
  28100. {}
  28101. ~CopyChannelOp() {}
  28102. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28103. {
  28104. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28105. }
  28106. private:
  28107. const int srcChannelNum, dstChannelNum;
  28108. CopyChannelOp (const CopyChannelOp&);
  28109. CopyChannelOp& operator= (const CopyChannelOp&);
  28110. };
  28111. class AddChannelOp : public AudioGraphRenderingOp
  28112. {
  28113. public:
  28114. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28115. : srcChannelNum (srcChannelNum_),
  28116. dstChannelNum (dstChannelNum_)
  28117. {}
  28118. ~AddChannelOp() {}
  28119. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28120. {
  28121. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28122. }
  28123. private:
  28124. const int srcChannelNum, dstChannelNum;
  28125. AddChannelOp (const AddChannelOp&);
  28126. AddChannelOp& operator= (const AddChannelOp&);
  28127. };
  28128. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28129. {
  28130. public:
  28131. ClearMidiBufferOp (const int bufferNum_)
  28132. : bufferNum (bufferNum_)
  28133. {}
  28134. ~ClearMidiBufferOp() {}
  28135. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28136. {
  28137. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28138. }
  28139. private:
  28140. const int bufferNum;
  28141. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28142. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28143. };
  28144. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28145. {
  28146. public:
  28147. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28148. : srcBufferNum (srcBufferNum_),
  28149. dstBufferNum (dstBufferNum_)
  28150. {}
  28151. ~CopyMidiBufferOp() {}
  28152. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28153. {
  28154. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28155. }
  28156. private:
  28157. const int srcBufferNum, dstBufferNum;
  28158. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28159. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28160. };
  28161. class AddMidiBufferOp : public AudioGraphRenderingOp
  28162. {
  28163. public:
  28164. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28165. : srcBufferNum (srcBufferNum_),
  28166. dstBufferNum (dstBufferNum_)
  28167. {}
  28168. ~AddMidiBufferOp() {}
  28169. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28170. {
  28171. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28172. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28173. }
  28174. private:
  28175. const int srcBufferNum, dstBufferNum;
  28176. AddMidiBufferOp (const AddMidiBufferOp&);
  28177. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28178. };
  28179. class ProcessBufferOp : public AudioGraphRenderingOp
  28180. {
  28181. public:
  28182. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28183. const Array <int>& audioChannelsToUse_,
  28184. const int totalChans_,
  28185. const int midiBufferToUse_)
  28186. : node (node_),
  28187. processor (node_->processor),
  28188. audioChannelsToUse (audioChannelsToUse_),
  28189. totalChans (jmax (1, totalChans_)),
  28190. midiBufferToUse (midiBufferToUse_)
  28191. {
  28192. channels.calloc (totalChans);
  28193. while (audioChannelsToUse.size() < totalChans)
  28194. audioChannelsToUse.add (0);
  28195. }
  28196. ~ProcessBufferOp()
  28197. {
  28198. }
  28199. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28200. {
  28201. for (int i = totalChans; --i >= 0;)
  28202. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28203. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28204. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28205. }
  28206. const AudioProcessorGraph::Node::Ptr node;
  28207. AudioProcessor* const processor;
  28208. private:
  28209. Array <int> audioChannelsToUse;
  28210. HeapBlock <float*> channels;
  28211. int totalChans;
  28212. int midiBufferToUse;
  28213. ProcessBufferOp (const ProcessBufferOp&);
  28214. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28215. };
  28216. class RenderingOpSequenceCalculator
  28217. {
  28218. public:
  28219. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28220. const VoidArray& orderedNodes_,
  28221. VoidArray& renderingOps)
  28222. : graph (graph_),
  28223. orderedNodes (orderedNodes_)
  28224. {
  28225. nodeIds.add (-2); // first buffer is read-only zeros
  28226. channels.add (0);
  28227. midiNodeIds.add (-2);
  28228. for (int i = 0; i < orderedNodes.size(); ++i)
  28229. {
  28230. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28231. renderingOps, i);
  28232. markAnyUnusedBuffersAsFree (i);
  28233. }
  28234. }
  28235. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28236. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28237. juce_UseDebuggingNewOperator
  28238. private:
  28239. AudioProcessorGraph& graph;
  28240. const VoidArray& orderedNodes;
  28241. Array <int> nodeIds, channels, midiNodeIds;
  28242. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28243. VoidArray& renderingOps,
  28244. const int ourRenderingIndex)
  28245. {
  28246. const int numIns = node->processor->getNumInputChannels();
  28247. const int numOuts = node->processor->getNumOutputChannels();
  28248. const int totalChans = jmax (numIns, numOuts);
  28249. Array <int> audioChannelsToUse;
  28250. int midiBufferToUse = -1;
  28251. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28252. {
  28253. // get a list of all the inputs to this node
  28254. Array <int> sourceNodes, sourceOutputChans;
  28255. for (int i = graph.getNumConnections(); --i >= 0;)
  28256. {
  28257. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28258. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28259. {
  28260. sourceNodes.add (c->sourceNodeId);
  28261. sourceOutputChans.add (c->sourceChannelIndex);
  28262. }
  28263. }
  28264. int bufIndex = -1;
  28265. if (sourceNodes.size() == 0)
  28266. {
  28267. // unconnected input channel
  28268. if (inputChan >= numOuts)
  28269. {
  28270. bufIndex = getReadOnlyEmptyBuffer();
  28271. jassert (bufIndex >= 0);
  28272. }
  28273. else
  28274. {
  28275. bufIndex = getFreeBuffer (false);
  28276. renderingOps.add (new ClearChannelOp (bufIndex));
  28277. }
  28278. }
  28279. else if (sourceNodes.size() == 1)
  28280. {
  28281. // channel with a straightforward single input..
  28282. const int srcNode = sourceNodes.getUnchecked(0);
  28283. const int srcChan = sourceOutputChans.getUnchecked(0);
  28284. bufIndex = getBufferContaining (srcNode, srcChan);
  28285. if (bufIndex < 0)
  28286. {
  28287. // if not found, this is probably a feedback loop
  28288. bufIndex = getReadOnlyEmptyBuffer();
  28289. jassert (bufIndex >= 0);
  28290. }
  28291. if (inputChan < numOuts
  28292. && isBufferNeededLater (ourRenderingIndex,
  28293. inputChan,
  28294. srcNode, srcChan))
  28295. {
  28296. // can't mess up this channel because it's needed later by another node, so we
  28297. // need to use a copy of it..
  28298. const int newFreeBuffer = getFreeBuffer (false);
  28299. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28300. bufIndex = newFreeBuffer;
  28301. }
  28302. }
  28303. else
  28304. {
  28305. // channel with a mix of several inputs..
  28306. // try to find a re-usable channel from our inputs..
  28307. int reusableInputIndex = -1;
  28308. for (int i = 0; i < sourceNodes.size(); ++i)
  28309. {
  28310. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28311. sourceOutputChans.getUnchecked(i));
  28312. if (sourceBufIndex >= 0
  28313. && ! isBufferNeededLater (ourRenderingIndex,
  28314. inputChan,
  28315. sourceNodes.getUnchecked(i),
  28316. sourceOutputChans.getUnchecked(i)))
  28317. {
  28318. // we've found one of our input chans that can be re-used..
  28319. reusableInputIndex = i;
  28320. bufIndex = sourceBufIndex;
  28321. break;
  28322. }
  28323. }
  28324. if (reusableInputIndex < 0)
  28325. {
  28326. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28327. bufIndex = getFreeBuffer (false);
  28328. jassert (bufIndex != 0);
  28329. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28330. sourceOutputChans.getUnchecked (0));
  28331. if (srcIndex < 0)
  28332. {
  28333. // if not found, this is probably a feedback loop
  28334. renderingOps.add (new ClearChannelOp (bufIndex));
  28335. }
  28336. else
  28337. {
  28338. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28339. }
  28340. reusableInputIndex = 0;
  28341. }
  28342. for (int j = 0; j < sourceNodes.size(); ++j)
  28343. {
  28344. if (j != reusableInputIndex)
  28345. {
  28346. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28347. sourceOutputChans.getUnchecked(j));
  28348. if (srcIndex >= 0)
  28349. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28350. }
  28351. }
  28352. }
  28353. jassert (bufIndex >= 0);
  28354. audioChannelsToUse.add (bufIndex);
  28355. if (inputChan < numOuts)
  28356. markBufferAsContaining (bufIndex, node->id, inputChan);
  28357. }
  28358. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28359. {
  28360. const int bufIndex = getFreeBuffer (false);
  28361. jassert (bufIndex != 0);
  28362. audioChannelsToUse.add (bufIndex);
  28363. markBufferAsContaining (bufIndex, node->id, outputChan);
  28364. }
  28365. // Now the same thing for midi..
  28366. Array <int> midiSourceNodes;
  28367. for (int i = graph.getNumConnections(); --i >= 0;)
  28368. {
  28369. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28370. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28371. midiSourceNodes.add (c->sourceNodeId);
  28372. }
  28373. if (midiSourceNodes.size() == 0)
  28374. {
  28375. // No midi inputs..
  28376. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28377. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28378. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28379. }
  28380. else if (midiSourceNodes.size() == 1)
  28381. {
  28382. // One midi input..
  28383. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28384. AudioProcessorGraph::midiChannelIndex);
  28385. if (midiBufferToUse >= 0)
  28386. {
  28387. if (isBufferNeededLater (ourRenderingIndex,
  28388. AudioProcessorGraph::midiChannelIndex,
  28389. midiSourceNodes.getUnchecked(0),
  28390. AudioProcessorGraph::midiChannelIndex))
  28391. {
  28392. // can't mess up this channel because it's needed later by another node, so we
  28393. // need to use a copy of it..
  28394. const int newFreeBuffer = getFreeBuffer (true);
  28395. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28396. midiBufferToUse = newFreeBuffer;
  28397. }
  28398. }
  28399. else
  28400. {
  28401. // probably a feedback loop, so just use an empty one..
  28402. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28403. }
  28404. }
  28405. else
  28406. {
  28407. // More than one midi input being mixed..
  28408. int reusableInputIndex = -1;
  28409. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28410. {
  28411. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28412. AudioProcessorGraph::midiChannelIndex);
  28413. if (sourceBufIndex >= 0
  28414. && ! isBufferNeededLater (ourRenderingIndex,
  28415. AudioProcessorGraph::midiChannelIndex,
  28416. midiSourceNodes.getUnchecked(i),
  28417. AudioProcessorGraph::midiChannelIndex))
  28418. {
  28419. // we've found one of our input buffers that can be re-used..
  28420. reusableInputIndex = i;
  28421. midiBufferToUse = sourceBufIndex;
  28422. break;
  28423. }
  28424. }
  28425. if (reusableInputIndex < 0)
  28426. {
  28427. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28428. midiBufferToUse = getFreeBuffer (true);
  28429. jassert (midiBufferToUse >= 0);
  28430. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28431. AudioProcessorGraph::midiChannelIndex);
  28432. if (srcIndex >= 0)
  28433. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28434. else
  28435. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28436. reusableInputIndex = 0;
  28437. }
  28438. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28439. {
  28440. if (j != reusableInputIndex)
  28441. {
  28442. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28443. AudioProcessorGraph::midiChannelIndex);
  28444. if (srcIndex >= 0)
  28445. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28446. }
  28447. }
  28448. }
  28449. if (node->processor->producesMidi())
  28450. markBufferAsContaining (midiBufferToUse, node->id,
  28451. AudioProcessorGraph::midiChannelIndex);
  28452. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28453. totalChans, midiBufferToUse));
  28454. }
  28455. int getFreeBuffer (const bool forMidi)
  28456. {
  28457. if (forMidi)
  28458. {
  28459. for (int i = 1; i < midiNodeIds.size(); ++i)
  28460. if (midiNodeIds.getUnchecked(i) < 0)
  28461. return i;
  28462. midiNodeIds.add (-1);
  28463. return midiNodeIds.size() - 1;
  28464. }
  28465. else
  28466. {
  28467. for (int i = 1; i < nodeIds.size(); ++i)
  28468. if (nodeIds.getUnchecked(i) < 0)
  28469. return i;
  28470. nodeIds.add (-1);
  28471. channels.add (0);
  28472. return nodeIds.size() - 1;
  28473. }
  28474. }
  28475. int getReadOnlyEmptyBuffer() const
  28476. {
  28477. return 0;
  28478. }
  28479. int getBufferContaining (const int nodeId, const int outputChannel) const
  28480. {
  28481. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28482. {
  28483. for (int i = midiNodeIds.size(); --i >= 0;)
  28484. if (midiNodeIds.getUnchecked(i) == nodeId)
  28485. return i;
  28486. }
  28487. else
  28488. {
  28489. for (int i = nodeIds.size(); --i >= 0;)
  28490. if (nodeIds.getUnchecked(i) == nodeId
  28491. && channels.getUnchecked(i) == outputChannel)
  28492. return i;
  28493. }
  28494. return -1;
  28495. }
  28496. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28497. {
  28498. int i;
  28499. for (i = 0; i < nodeIds.size(); ++i)
  28500. {
  28501. if (nodeIds.getUnchecked(i) >= 0
  28502. && ! isBufferNeededLater (stepIndex, -1,
  28503. nodeIds.getUnchecked(i),
  28504. channels.getUnchecked(i)))
  28505. {
  28506. nodeIds.set (i, -1);
  28507. }
  28508. }
  28509. for (i = 0; i < midiNodeIds.size(); ++i)
  28510. {
  28511. if (midiNodeIds.getUnchecked(i) >= 0
  28512. && ! isBufferNeededLater (stepIndex, -1,
  28513. midiNodeIds.getUnchecked(i),
  28514. AudioProcessorGraph::midiChannelIndex))
  28515. {
  28516. midiNodeIds.set (i, -1);
  28517. }
  28518. }
  28519. }
  28520. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28521. int inputChannelOfIndexToIgnore,
  28522. const int nodeId,
  28523. const int outputChanIndex) const
  28524. {
  28525. while (stepIndexToSearchFrom < orderedNodes.size())
  28526. {
  28527. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28528. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28529. {
  28530. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28531. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28532. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28533. return true;
  28534. }
  28535. else
  28536. {
  28537. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28538. if (i != inputChannelOfIndexToIgnore
  28539. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28540. node->id, i) != 0)
  28541. return true;
  28542. }
  28543. inputChannelOfIndexToIgnore = -1;
  28544. ++stepIndexToSearchFrom;
  28545. }
  28546. return false;
  28547. }
  28548. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28549. {
  28550. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28551. {
  28552. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28553. midiNodeIds.set (bufferNum, nodeId);
  28554. }
  28555. else
  28556. {
  28557. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28558. nodeIds.set (bufferNum, nodeId);
  28559. channels.set (bufferNum, outputIndex);
  28560. }
  28561. }
  28562. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28563. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28564. };
  28565. }
  28566. void AudioProcessorGraph::clearRenderingSequence()
  28567. {
  28568. const ScopedLock sl (renderLock);
  28569. for (int i = renderingOps.size(); --i >= 0;)
  28570. {
  28571. GraphRenderingOps::AudioGraphRenderingOp* const r
  28572. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28573. renderingOps.remove (i);
  28574. delete r;
  28575. }
  28576. }
  28577. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28578. const uint32 possibleDestinationId,
  28579. const int recursionCheck) const
  28580. {
  28581. if (recursionCheck > 0)
  28582. {
  28583. for (int i = connections.size(); --i >= 0;)
  28584. {
  28585. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28586. if (c->destNodeId == possibleDestinationId
  28587. && (c->sourceNodeId == possibleInputId
  28588. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28589. return true;
  28590. }
  28591. }
  28592. return false;
  28593. }
  28594. void AudioProcessorGraph::buildRenderingSequence()
  28595. {
  28596. VoidArray newRenderingOps;
  28597. int numRenderingBuffersNeeded = 2;
  28598. int numMidiBuffersNeeded = 1;
  28599. {
  28600. MessageManagerLock mml;
  28601. VoidArray orderedNodes;
  28602. int i;
  28603. for (i = 0; i < nodes.size(); ++i)
  28604. {
  28605. Node* const node = nodes.getUnchecked(i);
  28606. node->prepare (getSampleRate(), getBlockSize(), this);
  28607. int j = 0;
  28608. for (; j < orderedNodes.size(); ++j)
  28609. if (isAnInputTo (node->id,
  28610. ((Node*) orderedNodes.getUnchecked (j))->id,
  28611. nodes.size() + 1))
  28612. break;
  28613. orderedNodes.insert (j, node);
  28614. }
  28615. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28616. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28617. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28618. }
  28619. VoidArray oldRenderingOps (renderingOps);
  28620. {
  28621. // swap over to the new rendering sequence..
  28622. const ScopedLock sl (renderLock);
  28623. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28624. renderingBuffers.clear();
  28625. for (int i = midiBuffers.size(); --i >= 0;)
  28626. midiBuffers.getUnchecked(i)->clear();
  28627. while (midiBuffers.size() < numMidiBuffersNeeded)
  28628. midiBuffers.add (new MidiBuffer());
  28629. renderingOps = newRenderingOps;
  28630. }
  28631. for (int i = oldRenderingOps.size(); --i >= 0;)
  28632. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28633. }
  28634. void AudioProcessorGraph::handleAsyncUpdate()
  28635. {
  28636. buildRenderingSequence();
  28637. }
  28638. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28639. {
  28640. currentAudioInputBuffer = 0;
  28641. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28642. currentMidiInputBuffer = 0;
  28643. currentMidiOutputBuffer.clear();
  28644. clearRenderingSequence();
  28645. buildRenderingSequence();
  28646. }
  28647. void AudioProcessorGraph::releaseResources()
  28648. {
  28649. for (int i = 0; i < nodes.size(); ++i)
  28650. nodes.getUnchecked(i)->unprepare();
  28651. renderingBuffers.setSize (1, 1);
  28652. midiBuffers.clear();
  28653. currentAudioInputBuffer = 0;
  28654. currentAudioOutputBuffer.setSize (1, 1);
  28655. currentMidiInputBuffer = 0;
  28656. currentMidiOutputBuffer.clear();
  28657. }
  28658. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28659. {
  28660. const int numSamples = buffer.getNumSamples();
  28661. const ScopedLock sl (renderLock);
  28662. currentAudioInputBuffer = &buffer;
  28663. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28664. currentAudioOutputBuffer.clear();
  28665. currentMidiInputBuffer = &midiMessages;
  28666. currentMidiOutputBuffer.clear();
  28667. int i;
  28668. for (i = 0; i < renderingOps.size(); ++i)
  28669. {
  28670. GraphRenderingOps::AudioGraphRenderingOp* const op
  28671. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28672. op->perform (renderingBuffers, midiBuffers, numSamples);
  28673. }
  28674. for (i = 0; i < buffer.getNumChannels(); ++i)
  28675. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28676. midiMessages.clear();
  28677. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28678. }
  28679. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28680. {
  28681. return "Input " + String (channelIndex + 1);
  28682. }
  28683. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28684. {
  28685. return "Output " + String (channelIndex + 1);
  28686. }
  28687. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28688. {
  28689. return true;
  28690. }
  28691. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28692. {
  28693. return true;
  28694. }
  28695. bool AudioProcessorGraph::acceptsMidi() const
  28696. {
  28697. return true;
  28698. }
  28699. bool AudioProcessorGraph::producesMidi() const
  28700. {
  28701. return true;
  28702. }
  28703. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28704. {
  28705. }
  28706. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28707. {
  28708. }
  28709. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28710. : type (type_),
  28711. graph (0)
  28712. {
  28713. }
  28714. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28715. {
  28716. }
  28717. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28718. {
  28719. switch (type)
  28720. {
  28721. case audioOutputNode:
  28722. return "Audio Output";
  28723. case audioInputNode:
  28724. return "Audio Input";
  28725. case midiOutputNode:
  28726. return "Midi Output";
  28727. case midiInputNode:
  28728. return "Midi Input";
  28729. default:
  28730. break;
  28731. }
  28732. return String::empty;
  28733. }
  28734. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28735. {
  28736. d.name = getName();
  28737. d.uid = d.name.hashCode();
  28738. d.category = "I/O devices";
  28739. d.pluginFormatName = "Internal";
  28740. d.manufacturerName = "Raw Material Software";
  28741. d.version = "1.0";
  28742. d.isInstrument = false;
  28743. d.numInputChannels = getNumInputChannels();
  28744. if (type == audioOutputNode && graph != 0)
  28745. d.numInputChannels = graph->getNumInputChannels();
  28746. d.numOutputChannels = getNumOutputChannels();
  28747. if (type == audioInputNode && graph != 0)
  28748. d.numOutputChannels = graph->getNumOutputChannels();
  28749. }
  28750. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28751. {
  28752. jassert (graph != 0);
  28753. }
  28754. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28755. {
  28756. }
  28757. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28758. MidiBuffer& midiMessages)
  28759. {
  28760. jassert (graph != 0);
  28761. switch (type)
  28762. {
  28763. case audioOutputNode:
  28764. {
  28765. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28766. buffer.getNumChannels()); --i >= 0;)
  28767. {
  28768. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28769. }
  28770. break;
  28771. }
  28772. case audioInputNode:
  28773. {
  28774. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28775. buffer.getNumChannels()); --i >= 0;)
  28776. {
  28777. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28778. }
  28779. break;
  28780. }
  28781. case midiOutputNode:
  28782. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28783. break;
  28784. case midiInputNode:
  28785. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28786. break;
  28787. default:
  28788. break;
  28789. }
  28790. }
  28791. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28792. {
  28793. return type == midiOutputNode;
  28794. }
  28795. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28796. {
  28797. return type == midiInputNode;
  28798. }
  28799. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28800. {
  28801. switch (type)
  28802. {
  28803. case audioOutputNode:
  28804. return "Output " + String (channelIndex + 1);
  28805. case midiOutputNode:
  28806. return "Midi Output";
  28807. default:
  28808. break;
  28809. }
  28810. return String::empty;
  28811. }
  28812. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28813. {
  28814. switch (type)
  28815. {
  28816. case audioInputNode:
  28817. return "Input " + String (channelIndex + 1);
  28818. case midiInputNode:
  28819. return "Midi Input";
  28820. default:
  28821. break;
  28822. }
  28823. return String::empty;
  28824. }
  28825. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28826. {
  28827. return type == audioInputNode || type == audioOutputNode;
  28828. }
  28829. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28830. {
  28831. return isInputChannelStereoPair (index);
  28832. }
  28833. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28834. {
  28835. return type == audioInputNode || type == midiInputNode;
  28836. }
  28837. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28838. {
  28839. return type == audioOutputNode || type == midiOutputNode;
  28840. }
  28841. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28842. {
  28843. return 0;
  28844. }
  28845. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28846. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28847. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28848. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28849. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28850. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28851. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28852. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28853. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28854. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28855. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28856. {
  28857. }
  28858. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28859. {
  28860. }
  28861. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28862. {
  28863. graph = newGraph;
  28864. if (graph != 0)
  28865. {
  28866. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28867. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28868. getSampleRate(),
  28869. getBlockSize());
  28870. updateHostDisplay();
  28871. }
  28872. }
  28873. END_JUCE_NAMESPACE
  28874. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28875. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28876. BEGIN_JUCE_NAMESPACE
  28877. AudioProcessorPlayer::AudioProcessorPlayer()
  28878. : processor (0),
  28879. sampleRate (0),
  28880. blockSize (0),
  28881. isPrepared (false),
  28882. numInputChans (0),
  28883. numOutputChans (0),
  28884. tempBuffer (1, 1)
  28885. {
  28886. }
  28887. AudioProcessorPlayer::~AudioProcessorPlayer()
  28888. {
  28889. setProcessor (0);
  28890. }
  28891. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28892. {
  28893. if (processor != processorToPlay)
  28894. {
  28895. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28896. {
  28897. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28898. sampleRate, blockSize);
  28899. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28900. }
  28901. AudioProcessor* oldOne;
  28902. {
  28903. const ScopedLock sl (lock);
  28904. oldOne = isPrepared ? processor : 0;
  28905. processor = processorToPlay;
  28906. isPrepared = true;
  28907. }
  28908. if (oldOne != 0)
  28909. oldOne->releaseResources();
  28910. }
  28911. }
  28912. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28913. int numInputChannels,
  28914. float** outputChannelData,
  28915. int numOutputChannels,
  28916. int numSamples)
  28917. {
  28918. // these should have been prepared by audioDeviceAboutToStart()...
  28919. jassert (sampleRate > 0 && blockSize > 0);
  28920. incomingMidi.clear();
  28921. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28922. int i, totalNumChans = 0;
  28923. if (numInputChannels > numOutputChannels)
  28924. {
  28925. // if there aren't enough output channels for the number of
  28926. // inputs, we need to create some temporary extra ones (can't
  28927. // use the input data in case it gets written to)
  28928. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28929. false, false, true);
  28930. for (i = 0; i < numOutputChannels; ++i)
  28931. {
  28932. channels[totalNumChans] = outputChannelData[i];
  28933. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28934. ++totalNumChans;
  28935. }
  28936. for (i = numOutputChannels; i < numInputChannels; ++i)
  28937. {
  28938. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28939. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28940. ++totalNumChans;
  28941. }
  28942. }
  28943. else
  28944. {
  28945. for (i = 0; i < numInputChannels; ++i)
  28946. {
  28947. channels[totalNumChans] = outputChannelData[i];
  28948. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28949. ++totalNumChans;
  28950. }
  28951. for (i = numInputChannels; i < numOutputChannels; ++i)
  28952. {
  28953. channels[totalNumChans] = outputChannelData[i];
  28954. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28955. ++totalNumChans;
  28956. }
  28957. }
  28958. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28959. const ScopedLock sl (lock);
  28960. if (processor != 0)
  28961. processor->processBlock (buffer, incomingMidi);
  28962. }
  28963. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  28964. {
  28965. const ScopedLock sl (lock);
  28966. sampleRate = device->getCurrentSampleRate();
  28967. blockSize = device->getCurrentBufferSizeSamples();
  28968. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  28969. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  28970. messageCollector.reset (sampleRate);
  28971. zeromem (channels, sizeof (channels));
  28972. if (processor != 0)
  28973. {
  28974. if (isPrepared)
  28975. processor->releaseResources();
  28976. AudioProcessor* const oldProcessor = processor;
  28977. setProcessor (0);
  28978. setProcessor (oldProcessor);
  28979. }
  28980. }
  28981. void AudioProcessorPlayer::audioDeviceStopped()
  28982. {
  28983. const ScopedLock sl (lock);
  28984. if (processor != 0 && isPrepared)
  28985. processor->releaseResources();
  28986. sampleRate = 0.0;
  28987. blockSize = 0;
  28988. isPrepared = false;
  28989. tempBuffer.setSize (1, 1);
  28990. }
  28991. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  28992. {
  28993. messageCollector.addMessageToQueue (message);
  28994. }
  28995. END_JUCE_NAMESPACE
  28996. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28997. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  28998. BEGIN_JUCE_NAMESPACE
  28999. class ProcessorParameterPropertyComp : public PropertyComponent,
  29000. public AudioProcessorListener,
  29001. public AsyncUpdater
  29002. {
  29003. public:
  29004. ProcessorParameterPropertyComp (const String& name,
  29005. AudioProcessor* const owner_,
  29006. const int index_)
  29007. : PropertyComponent (name),
  29008. owner (owner_),
  29009. index (index_)
  29010. {
  29011. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29012. owner_->addListener (this);
  29013. }
  29014. ~ProcessorParameterPropertyComp()
  29015. {
  29016. owner->removeListener (this);
  29017. deleteAllChildren();
  29018. }
  29019. void refresh()
  29020. {
  29021. slider->setValue (owner->getParameter (index), false);
  29022. }
  29023. void audioProcessorChanged (AudioProcessor*) {}
  29024. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29025. {
  29026. if (parameterIndex == index)
  29027. triggerAsyncUpdate();
  29028. }
  29029. void handleAsyncUpdate()
  29030. {
  29031. refresh();
  29032. }
  29033. juce_UseDebuggingNewOperator
  29034. private:
  29035. AudioProcessor* const owner;
  29036. const int index;
  29037. Slider* slider;
  29038. class ParamSlider : public Slider
  29039. {
  29040. public:
  29041. ParamSlider (AudioProcessor* const owner_, const int index_)
  29042. : Slider (String::empty),
  29043. owner (owner_),
  29044. index (index_)
  29045. {
  29046. setRange (0.0, 1.0, 0.0);
  29047. setSliderStyle (Slider::LinearBar);
  29048. setTextBoxIsEditable (false);
  29049. setScrollWheelEnabled (false);
  29050. }
  29051. ~ParamSlider()
  29052. {
  29053. }
  29054. void valueChanged()
  29055. {
  29056. const float newVal = (float) getValue();
  29057. if (owner->getParameter (index) != newVal)
  29058. owner->setParameter (index, newVal);
  29059. }
  29060. const String getTextFromValue (double /*value*/)
  29061. {
  29062. return owner->getParameterText (index);
  29063. }
  29064. juce_UseDebuggingNewOperator
  29065. private:
  29066. AudioProcessor* const owner;
  29067. const int index;
  29068. ParamSlider (const ParamSlider&);
  29069. ParamSlider& operator= (const ParamSlider&);
  29070. };
  29071. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29072. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29073. };
  29074. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29075. : AudioProcessorEditor (owner_)
  29076. {
  29077. setOpaque (true);
  29078. addAndMakeVisible (panel = new PropertyPanel());
  29079. Array <PropertyComponent*> params;
  29080. const int numParams = owner_->getNumParameters();
  29081. int totalHeight = 0;
  29082. for (int i = 0; i < numParams; ++i)
  29083. {
  29084. String name (owner_->getParameterName (i));
  29085. if (name.trim().isEmpty())
  29086. name = "Unnamed";
  29087. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29088. params.add (pc);
  29089. totalHeight += pc->getPreferredHeight();
  29090. }
  29091. panel->addProperties (params);
  29092. setSize (400, jlimit (25, 400, totalHeight));
  29093. }
  29094. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29095. {
  29096. deleteAllChildren();
  29097. }
  29098. void GenericAudioProcessorEditor::paint (Graphics& g)
  29099. {
  29100. g.fillAll (Colours::white);
  29101. }
  29102. void GenericAudioProcessorEditor::resized()
  29103. {
  29104. panel->setSize (getWidth(), getHeight());
  29105. }
  29106. END_JUCE_NAMESPACE
  29107. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29108. /*** Start of inlined file: juce_Sampler.cpp ***/
  29109. BEGIN_JUCE_NAMESPACE
  29110. SamplerSound::SamplerSound (const String& name_,
  29111. AudioFormatReader& source,
  29112. const BigInteger& midiNotes_,
  29113. const int midiNoteForNormalPitch,
  29114. const double attackTimeSecs,
  29115. const double releaseTimeSecs,
  29116. const double maxSampleLengthSeconds)
  29117. : name (name_),
  29118. midiNotes (midiNotes_),
  29119. midiRootNote (midiNoteForNormalPitch)
  29120. {
  29121. sourceSampleRate = source.sampleRate;
  29122. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29123. {
  29124. length = 0;
  29125. attackSamples = 0;
  29126. releaseSamples = 0;
  29127. }
  29128. else
  29129. {
  29130. length = jmin ((int) source.lengthInSamples,
  29131. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29132. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29133. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29134. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29135. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29136. }
  29137. }
  29138. SamplerSound::~SamplerSound()
  29139. {
  29140. }
  29141. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29142. {
  29143. return midiNotes [midiNoteNumber];
  29144. }
  29145. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29146. {
  29147. return true;
  29148. }
  29149. SamplerVoice::SamplerVoice()
  29150. : pitchRatio (0.0),
  29151. sourceSamplePosition (0.0),
  29152. lgain (0.0f),
  29153. rgain (0.0f),
  29154. isInAttack (false),
  29155. isInRelease (false)
  29156. {
  29157. }
  29158. SamplerVoice::~SamplerVoice()
  29159. {
  29160. }
  29161. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29162. {
  29163. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29164. }
  29165. void SamplerVoice::startNote (const int midiNoteNumber,
  29166. const float velocity,
  29167. SynthesiserSound* s,
  29168. const int /*currentPitchWheelPosition*/)
  29169. {
  29170. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29171. jassert (sound != 0); // this object can only play SamplerSounds!
  29172. if (sound != 0)
  29173. {
  29174. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29175. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29176. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29177. sourceSamplePosition = 0.0;
  29178. lgain = velocity;
  29179. rgain = velocity;
  29180. isInAttack = (sound->attackSamples > 0);
  29181. isInRelease = false;
  29182. if (isInAttack)
  29183. {
  29184. attackReleaseLevel = 0.0f;
  29185. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29186. }
  29187. else
  29188. {
  29189. attackReleaseLevel = 1.0f;
  29190. attackDelta = 0.0f;
  29191. }
  29192. if (sound->releaseSamples > 0)
  29193. {
  29194. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29195. }
  29196. else
  29197. {
  29198. releaseDelta = 0.0f;
  29199. }
  29200. }
  29201. }
  29202. void SamplerVoice::stopNote (const bool allowTailOff)
  29203. {
  29204. if (allowTailOff)
  29205. {
  29206. isInAttack = false;
  29207. isInRelease = true;
  29208. }
  29209. else
  29210. {
  29211. clearCurrentNote();
  29212. }
  29213. }
  29214. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29215. {
  29216. }
  29217. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29218. const int /*newValue*/)
  29219. {
  29220. }
  29221. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29222. {
  29223. const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().getObject());
  29224. if (playingSound != 0)
  29225. {
  29226. const float* const inL = playingSound->data->getSampleData (0, 0);
  29227. const float* const inR = playingSound->data->getNumChannels() > 1
  29228. ? playingSound->data->getSampleData (1, 0) : 0;
  29229. float* outL = outputBuffer.getSampleData (0, startSample);
  29230. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29231. while (--numSamples >= 0)
  29232. {
  29233. const int pos = (int) sourceSamplePosition;
  29234. const float alpha = (float) (sourceSamplePosition - pos);
  29235. const float invAlpha = 1.0f - alpha;
  29236. // just using a very simple linear interpolation here..
  29237. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29238. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29239. : l;
  29240. l *= lgain;
  29241. r *= rgain;
  29242. if (isInAttack)
  29243. {
  29244. l *= attackReleaseLevel;
  29245. r *= attackReleaseLevel;
  29246. attackReleaseLevel += attackDelta;
  29247. if (attackReleaseLevel >= 1.0f)
  29248. {
  29249. attackReleaseLevel = 1.0f;
  29250. isInAttack = false;
  29251. }
  29252. }
  29253. else if (isInRelease)
  29254. {
  29255. l *= attackReleaseLevel;
  29256. r *= attackReleaseLevel;
  29257. attackReleaseLevel += releaseDelta;
  29258. if (attackReleaseLevel <= 0.0f)
  29259. {
  29260. stopNote (false);
  29261. break;
  29262. }
  29263. }
  29264. if (outR != 0)
  29265. {
  29266. *outL++ += l;
  29267. *outR++ += r;
  29268. }
  29269. else
  29270. {
  29271. *outL++ += (l + r) * 0.5f;
  29272. }
  29273. sourceSamplePosition += pitchRatio;
  29274. if (sourceSamplePosition > playingSound->length)
  29275. {
  29276. stopNote (false);
  29277. break;
  29278. }
  29279. }
  29280. }
  29281. }
  29282. END_JUCE_NAMESPACE
  29283. /*** End of inlined file: juce_Sampler.cpp ***/
  29284. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29285. BEGIN_JUCE_NAMESPACE
  29286. SynthesiserSound::SynthesiserSound()
  29287. {
  29288. }
  29289. SynthesiserSound::~SynthesiserSound()
  29290. {
  29291. }
  29292. SynthesiserVoice::SynthesiserVoice()
  29293. : currentSampleRate (44100.0),
  29294. currentlyPlayingNote (-1),
  29295. noteOnTime (0),
  29296. currentlyPlayingSound (0)
  29297. {
  29298. }
  29299. SynthesiserVoice::~SynthesiserVoice()
  29300. {
  29301. }
  29302. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29303. {
  29304. return currentlyPlayingSound != 0
  29305. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29306. }
  29307. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29308. {
  29309. currentSampleRate = newRate;
  29310. }
  29311. void SynthesiserVoice::clearCurrentNote()
  29312. {
  29313. currentlyPlayingNote = -1;
  29314. currentlyPlayingSound = 0;
  29315. }
  29316. Synthesiser::Synthesiser()
  29317. : sampleRate (0),
  29318. lastNoteOnCounter (0),
  29319. shouldStealNotes (true)
  29320. {
  29321. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29322. lastPitchWheelValues[i] = 0x2000;
  29323. }
  29324. Synthesiser::~Synthesiser()
  29325. {
  29326. }
  29327. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29328. {
  29329. const ScopedLock sl (lock);
  29330. return voices [index];
  29331. }
  29332. void Synthesiser::clearVoices()
  29333. {
  29334. const ScopedLock sl (lock);
  29335. voices.clear();
  29336. }
  29337. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29338. {
  29339. const ScopedLock sl (lock);
  29340. voices.add (newVoice);
  29341. }
  29342. void Synthesiser::removeVoice (const int index)
  29343. {
  29344. const ScopedLock sl (lock);
  29345. voices.remove (index);
  29346. }
  29347. void Synthesiser::clearSounds()
  29348. {
  29349. const ScopedLock sl (lock);
  29350. sounds.clear();
  29351. }
  29352. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29353. {
  29354. const ScopedLock sl (lock);
  29355. sounds.add (newSound);
  29356. }
  29357. void Synthesiser::removeSound (const int index)
  29358. {
  29359. const ScopedLock sl (lock);
  29360. sounds.remove (index);
  29361. }
  29362. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29363. {
  29364. shouldStealNotes = shouldStealNotes_;
  29365. }
  29366. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29367. {
  29368. if (sampleRate != newRate)
  29369. {
  29370. const ScopedLock sl (lock);
  29371. allNotesOff (0, false);
  29372. sampleRate = newRate;
  29373. for (int i = voices.size(); --i >= 0;)
  29374. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29375. }
  29376. }
  29377. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29378. const MidiBuffer& midiData,
  29379. int startSample,
  29380. int numSamples)
  29381. {
  29382. // must set the sample rate before using this!
  29383. jassert (sampleRate != 0);
  29384. const ScopedLock sl (lock);
  29385. MidiBuffer::Iterator midiIterator (midiData);
  29386. midiIterator.setNextSamplePosition (startSample);
  29387. MidiMessage m (0xf4, 0.0);
  29388. while (numSamples > 0)
  29389. {
  29390. int midiEventPos;
  29391. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29392. && midiEventPos < startSample + numSamples;
  29393. const int numThisTime = useEvent ? midiEventPos - startSample
  29394. : numSamples;
  29395. if (numThisTime > 0)
  29396. {
  29397. for (int i = voices.size(); --i >= 0;)
  29398. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29399. }
  29400. if (useEvent)
  29401. {
  29402. if (m.isNoteOn())
  29403. {
  29404. const int channel = m.getChannel();
  29405. noteOn (channel,
  29406. m.getNoteNumber(),
  29407. m.getFloatVelocity());
  29408. }
  29409. else if (m.isNoteOff())
  29410. {
  29411. noteOff (m.getChannel(),
  29412. m.getNoteNumber(),
  29413. true);
  29414. }
  29415. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29416. {
  29417. allNotesOff (m.getChannel(), true);
  29418. }
  29419. else if (m.isPitchWheel())
  29420. {
  29421. const int channel = m.getChannel();
  29422. const int wheelPos = m.getPitchWheelValue();
  29423. lastPitchWheelValues [channel - 1] = wheelPos;
  29424. handlePitchWheel (channel, wheelPos);
  29425. }
  29426. else if (m.isController())
  29427. {
  29428. handleController (m.getChannel(),
  29429. m.getControllerNumber(),
  29430. m.getControllerValue());
  29431. }
  29432. }
  29433. startSample += numThisTime;
  29434. numSamples -= numThisTime;
  29435. }
  29436. }
  29437. void Synthesiser::noteOn (const int midiChannel,
  29438. const int midiNoteNumber,
  29439. const float velocity)
  29440. {
  29441. const ScopedLock sl (lock);
  29442. for (int i = sounds.size(); --i >= 0;)
  29443. {
  29444. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29445. if (sound->appliesToNote (midiNoteNumber)
  29446. && sound->appliesToChannel (midiChannel))
  29447. {
  29448. startVoice (findFreeVoice (sound, shouldStealNotes),
  29449. sound, midiChannel, midiNoteNumber, velocity);
  29450. }
  29451. }
  29452. }
  29453. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29454. SynthesiserSound* const sound,
  29455. const int midiChannel,
  29456. const int midiNoteNumber,
  29457. const float velocity)
  29458. {
  29459. if (voice != 0 && sound != 0)
  29460. {
  29461. if (voice->currentlyPlayingSound != 0)
  29462. voice->stopNote (false);
  29463. voice->startNote (midiNoteNumber,
  29464. velocity,
  29465. sound,
  29466. lastPitchWheelValues [midiChannel - 1]);
  29467. voice->currentlyPlayingNote = midiNoteNumber;
  29468. voice->noteOnTime = ++lastNoteOnCounter;
  29469. voice->currentlyPlayingSound = sound;
  29470. }
  29471. }
  29472. void Synthesiser::noteOff (const int midiChannel,
  29473. const int midiNoteNumber,
  29474. const bool allowTailOff)
  29475. {
  29476. const ScopedLock sl (lock);
  29477. for (int i = voices.size(); --i >= 0;)
  29478. {
  29479. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29480. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29481. {
  29482. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29483. if (sound != 0
  29484. && sound->appliesToNote (midiNoteNumber)
  29485. && sound->appliesToChannel (midiChannel))
  29486. {
  29487. voice->stopNote (allowTailOff);
  29488. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29489. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29490. }
  29491. }
  29492. }
  29493. }
  29494. void Synthesiser::allNotesOff (const int midiChannel,
  29495. const bool allowTailOff)
  29496. {
  29497. const ScopedLock sl (lock);
  29498. for (int i = voices.size(); --i >= 0;)
  29499. {
  29500. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29501. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29502. voice->stopNote (allowTailOff);
  29503. }
  29504. }
  29505. void Synthesiser::handlePitchWheel (const int midiChannel,
  29506. const int wheelValue)
  29507. {
  29508. const ScopedLock sl (lock);
  29509. for (int i = voices.size(); --i >= 0;)
  29510. {
  29511. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29512. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29513. {
  29514. voice->pitchWheelMoved (wheelValue);
  29515. }
  29516. }
  29517. }
  29518. void Synthesiser::handleController (const int midiChannel,
  29519. const int controllerNumber,
  29520. const int controllerValue)
  29521. {
  29522. const ScopedLock sl (lock);
  29523. for (int i = voices.size(); --i >= 0;)
  29524. {
  29525. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29526. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29527. voice->controllerMoved (controllerNumber, controllerValue);
  29528. }
  29529. }
  29530. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29531. const bool stealIfNoneAvailable) const
  29532. {
  29533. const ScopedLock sl (lock);
  29534. for (int i = voices.size(); --i >= 0;)
  29535. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29536. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29537. return voices.getUnchecked (i);
  29538. if (stealIfNoneAvailable)
  29539. {
  29540. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29541. SynthesiserVoice* oldest = 0;
  29542. for (int i = voices.size(); --i >= 0;)
  29543. {
  29544. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29545. if (voice->canPlaySound (soundToPlay)
  29546. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29547. oldest = voice;
  29548. }
  29549. jassert (oldest != 0);
  29550. return oldest;
  29551. }
  29552. return 0;
  29553. }
  29554. END_JUCE_NAMESPACE
  29555. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29556. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29557. BEGIN_JUCE_NAMESPACE
  29558. ActionBroadcaster::ActionBroadcaster() throw()
  29559. {
  29560. // are you trying to create this object before or after juce has been intialised??
  29561. jassert (MessageManager::instance != 0);
  29562. }
  29563. ActionBroadcaster::~ActionBroadcaster()
  29564. {
  29565. // all event-based objects must be deleted BEFORE juce is shut down!
  29566. jassert (MessageManager::instance != 0);
  29567. }
  29568. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29569. {
  29570. actionListenerList.addActionListener (listener);
  29571. }
  29572. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29573. {
  29574. jassert (actionListenerList.isValidMessageListener());
  29575. if (actionListenerList.isValidMessageListener())
  29576. actionListenerList.removeActionListener (listener);
  29577. }
  29578. void ActionBroadcaster::removeAllActionListeners()
  29579. {
  29580. actionListenerList.removeAllActionListeners();
  29581. }
  29582. void ActionBroadcaster::sendActionMessage (const String& message) const
  29583. {
  29584. actionListenerList.sendActionMessage (message);
  29585. }
  29586. END_JUCE_NAMESPACE
  29587. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29588. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29589. BEGIN_JUCE_NAMESPACE
  29590. // special message of our own with a string in it
  29591. class ActionMessage : public Message
  29592. {
  29593. public:
  29594. const String message;
  29595. ActionMessage (const String& messageText,
  29596. void* const listener_) throw()
  29597. : message (messageText)
  29598. {
  29599. pointerParameter = listener_;
  29600. }
  29601. ~ActionMessage() throw()
  29602. {
  29603. }
  29604. private:
  29605. ActionMessage (const ActionMessage&);
  29606. ActionMessage& operator= (const ActionMessage&);
  29607. };
  29608. ActionListenerList::ActionListenerList() throw()
  29609. {
  29610. }
  29611. ActionListenerList::~ActionListenerList() throw()
  29612. {
  29613. }
  29614. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29615. {
  29616. const ScopedLock sl (actionListenerLock_);
  29617. jassert (listener != 0);
  29618. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29619. if (listener != 0)
  29620. actionListeners_.add (listener);
  29621. }
  29622. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29623. {
  29624. const ScopedLock sl (actionListenerLock_);
  29625. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29626. actionListeners_.removeValue (listener);
  29627. }
  29628. void ActionListenerList::removeAllActionListeners() throw()
  29629. {
  29630. const ScopedLock sl (actionListenerLock_);
  29631. actionListeners_.clear();
  29632. }
  29633. void ActionListenerList::sendActionMessage (const String& message) const
  29634. {
  29635. const ScopedLock sl (actionListenerLock_);
  29636. for (int i = actionListeners_.size(); --i >= 0;)
  29637. postMessage (new ActionMessage (message, static_cast <ActionListener*> (actionListeners_.getUnchecked(i))));
  29638. }
  29639. void ActionListenerList::handleMessage (const Message& message)
  29640. {
  29641. const ActionMessage& am = (const ActionMessage&) message;
  29642. if (actionListeners_.contains (am.pointerParameter))
  29643. static_cast <ActionListener*> (am.pointerParameter)->actionListenerCallback (am.message);
  29644. }
  29645. END_JUCE_NAMESPACE
  29646. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29647. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29648. BEGIN_JUCE_NAMESPACE
  29649. AsyncUpdater::AsyncUpdater() throw()
  29650. : asyncMessagePending (false)
  29651. {
  29652. internalAsyncHandler.owner = this;
  29653. }
  29654. AsyncUpdater::~AsyncUpdater()
  29655. {
  29656. }
  29657. void AsyncUpdater::triggerAsyncUpdate() throw()
  29658. {
  29659. if (! asyncMessagePending)
  29660. {
  29661. asyncMessagePending = true;
  29662. internalAsyncHandler.postMessage (new Message());
  29663. }
  29664. }
  29665. void AsyncUpdater::cancelPendingUpdate() throw()
  29666. {
  29667. asyncMessagePending = false;
  29668. }
  29669. void AsyncUpdater::handleUpdateNowIfNeeded()
  29670. {
  29671. if (asyncMessagePending)
  29672. {
  29673. asyncMessagePending = false;
  29674. handleAsyncUpdate();
  29675. }
  29676. }
  29677. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29678. {
  29679. owner->handleUpdateNowIfNeeded();
  29680. }
  29681. END_JUCE_NAMESPACE
  29682. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29683. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29684. BEGIN_JUCE_NAMESPACE
  29685. ChangeBroadcaster::ChangeBroadcaster() throw()
  29686. {
  29687. // are you trying to create this object before or after juce has been intialised??
  29688. jassert (MessageManager::instance != 0);
  29689. }
  29690. ChangeBroadcaster::~ChangeBroadcaster()
  29691. {
  29692. // all event-based objects must be deleted BEFORE juce is shut down!
  29693. jassert (MessageManager::instance != 0);
  29694. }
  29695. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29696. {
  29697. changeListenerList.addChangeListener (listener);
  29698. }
  29699. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29700. {
  29701. jassert (changeListenerList.isValidMessageListener());
  29702. if (changeListenerList.isValidMessageListener())
  29703. changeListenerList.removeChangeListener (listener);
  29704. }
  29705. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29706. {
  29707. changeListenerList.removeAllChangeListeners();
  29708. }
  29709. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29710. {
  29711. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29712. }
  29713. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29714. {
  29715. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29716. }
  29717. void ChangeBroadcaster::dispatchPendingMessages()
  29718. {
  29719. changeListenerList.dispatchPendingMessages();
  29720. }
  29721. END_JUCE_NAMESPACE
  29722. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29723. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29724. BEGIN_JUCE_NAMESPACE
  29725. ChangeListenerList::ChangeListenerList() throw()
  29726. : lastChangedObject (0),
  29727. messagePending (false)
  29728. {
  29729. }
  29730. ChangeListenerList::~ChangeListenerList() throw()
  29731. {
  29732. }
  29733. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29734. {
  29735. const ScopedLock sl (lock);
  29736. jassert (listener != 0);
  29737. if (listener != 0)
  29738. listeners.add (listener);
  29739. }
  29740. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29741. {
  29742. const ScopedLock sl (lock);
  29743. listeners.removeValue (listener);
  29744. }
  29745. void ChangeListenerList::removeAllChangeListeners() throw()
  29746. {
  29747. const ScopedLock sl (lock);
  29748. listeners.clear();
  29749. }
  29750. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29751. {
  29752. const ScopedLock sl (lock);
  29753. if ((! messagePending) && (listeners.size() > 0))
  29754. {
  29755. lastChangedObject = objectThatHasChanged;
  29756. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29757. messagePending = true;
  29758. }
  29759. }
  29760. void ChangeListenerList::handleMessage (const Message& message)
  29761. {
  29762. sendSynchronousChangeMessage (message.pointerParameter);
  29763. }
  29764. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29765. {
  29766. const ScopedLock sl (lock);
  29767. messagePending = false;
  29768. for (int i = listeners.size(); --i >= 0;)
  29769. {
  29770. ChangeListener* const l = static_cast <ChangeListener*> (listeners.getUnchecked (i));
  29771. {
  29772. const ScopedUnlock tempUnlocker (lock);
  29773. l->changeListenerCallback (objectThatHasChanged);
  29774. }
  29775. i = jmin (i, listeners.size());
  29776. }
  29777. }
  29778. void ChangeListenerList::dispatchPendingMessages()
  29779. {
  29780. if (messagePending)
  29781. sendSynchronousChangeMessage (lastChangedObject);
  29782. }
  29783. END_JUCE_NAMESPACE
  29784. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29785. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29786. BEGIN_JUCE_NAMESPACE
  29787. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29788. const uint32 magicMessageHeaderNumber)
  29789. : Thread ("Juce IPC connection"),
  29790. callbackConnectionState (false),
  29791. useMessageThread (callbacksOnMessageThread),
  29792. magicMessageHeader (magicMessageHeaderNumber),
  29793. pipeReceiveMessageTimeout (-1)
  29794. {
  29795. }
  29796. InterprocessConnection::~InterprocessConnection()
  29797. {
  29798. callbackConnectionState = false;
  29799. disconnect();
  29800. }
  29801. bool InterprocessConnection::connectToSocket (const String& hostName,
  29802. const int portNumber,
  29803. const int timeOutMillisecs)
  29804. {
  29805. disconnect();
  29806. const ScopedLock sl (pipeAndSocketLock);
  29807. socket = new StreamingSocket();
  29808. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29809. {
  29810. connectionMadeInt();
  29811. startThread();
  29812. return true;
  29813. }
  29814. else
  29815. {
  29816. socket = 0;
  29817. return false;
  29818. }
  29819. }
  29820. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29821. const int pipeReceiveMessageTimeoutMs)
  29822. {
  29823. disconnect();
  29824. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29825. if (newPipe->openExisting (pipeName))
  29826. {
  29827. const ScopedLock sl (pipeAndSocketLock);
  29828. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29829. initialiseWithPipe (newPipe.release());
  29830. return true;
  29831. }
  29832. return false;
  29833. }
  29834. bool InterprocessConnection::createPipe (const String& pipeName,
  29835. const int pipeReceiveMessageTimeoutMs)
  29836. {
  29837. disconnect();
  29838. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29839. if (newPipe->createNewPipe (pipeName))
  29840. {
  29841. const ScopedLock sl (pipeAndSocketLock);
  29842. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29843. initialiseWithPipe (newPipe.release());
  29844. return true;
  29845. }
  29846. return false;
  29847. }
  29848. void InterprocessConnection::disconnect()
  29849. {
  29850. if (socket != 0)
  29851. socket->close();
  29852. if (pipe != 0)
  29853. {
  29854. pipe->cancelPendingReads();
  29855. pipe->close();
  29856. }
  29857. stopThread (4000);
  29858. {
  29859. const ScopedLock sl (pipeAndSocketLock);
  29860. socket = 0;
  29861. pipe = 0;
  29862. }
  29863. connectionLostInt();
  29864. }
  29865. bool InterprocessConnection::isConnected() const
  29866. {
  29867. const ScopedLock sl (pipeAndSocketLock);
  29868. return ((socket != 0 && socket->isConnected())
  29869. || (pipe != 0 && pipe->isOpen()))
  29870. && isThreadRunning();
  29871. }
  29872. const String InterprocessConnection::getConnectedHostName() const
  29873. {
  29874. if (pipe != 0)
  29875. {
  29876. return "localhost";
  29877. }
  29878. else if (socket != 0)
  29879. {
  29880. if (! socket->isLocal())
  29881. return socket->getHostName();
  29882. return "localhost";
  29883. }
  29884. return String::empty;
  29885. }
  29886. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29887. {
  29888. uint32 messageHeader[2];
  29889. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29890. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29891. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29892. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29893. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29894. size_t bytesWritten = 0;
  29895. const ScopedLock sl (pipeAndSocketLock);
  29896. if (socket != 0)
  29897. {
  29898. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29899. }
  29900. else if (pipe != 0)
  29901. {
  29902. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29903. }
  29904. if (bytesWritten < 0)
  29905. {
  29906. // error..
  29907. return false;
  29908. }
  29909. return (bytesWritten == messageData.getSize());
  29910. }
  29911. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29912. {
  29913. jassert (socket == 0);
  29914. socket = socket_;
  29915. connectionMadeInt();
  29916. startThread();
  29917. }
  29918. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29919. {
  29920. jassert (pipe == 0);
  29921. pipe = pipe_;
  29922. connectionMadeInt();
  29923. startThread();
  29924. }
  29925. const int messageMagicNumber = 0xb734128b;
  29926. void InterprocessConnection::handleMessage (const Message& message)
  29927. {
  29928. if (message.intParameter1 == messageMagicNumber)
  29929. {
  29930. switch (message.intParameter2)
  29931. {
  29932. case 0:
  29933. {
  29934. ScopedPointer <MemoryBlock> data (static_cast <MemoryBlock*> (message.pointerParameter));
  29935. messageReceived (*data);
  29936. break;
  29937. }
  29938. case 1:
  29939. connectionMade();
  29940. break;
  29941. case 2:
  29942. connectionLost();
  29943. break;
  29944. }
  29945. }
  29946. }
  29947. void InterprocessConnection::connectionMadeInt()
  29948. {
  29949. if (! callbackConnectionState)
  29950. {
  29951. callbackConnectionState = true;
  29952. if (useMessageThread)
  29953. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29954. else
  29955. connectionMade();
  29956. }
  29957. }
  29958. void InterprocessConnection::connectionLostInt()
  29959. {
  29960. if (callbackConnectionState)
  29961. {
  29962. callbackConnectionState = false;
  29963. if (useMessageThread)
  29964. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  29965. else
  29966. connectionLost();
  29967. }
  29968. }
  29969. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  29970. {
  29971. jassert (callbackConnectionState);
  29972. if (useMessageThread)
  29973. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  29974. else
  29975. messageReceived (data);
  29976. }
  29977. bool InterprocessConnection::readNextMessageInt()
  29978. {
  29979. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  29980. uint32 messageHeader[2];
  29981. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  29982. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  29983. if (bytes == sizeof (messageHeader)
  29984. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  29985. {
  29986. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  29987. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  29988. {
  29989. MemoryBlock messageData (bytesInMessage, true);
  29990. int bytesRead = 0;
  29991. while (bytesInMessage > 0)
  29992. {
  29993. if (threadShouldExit())
  29994. return false;
  29995. const int numThisTime = jmin (bytesInMessage, 65536);
  29996. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  29997. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  29998. if (bytesIn <= 0)
  29999. break;
  30000. bytesRead += bytesIn;
  30001. bytesInMessage -= bytesIn;
  30002. }
  30003. if (bytesRead >= 0)
  30004. deliverDataInt (messageData);
  30005. }
  30006. }
  30007. else if (bytes < 0)
  30008. {
  30009. {
  30010. const ScopedLock sl (pipeAndSocketLock);
  30011. socket = 0;
  30012. }
  30013. connectionLostInt();
  30014. return false;
  30015. }
  30016. return true;
  30017. }
  30018. void InterprocessConnection::run()
  30019. {
  30020. while (! threadShouldExit())
  30021. {
  30022. if (socket != 0)
  30023. {
  30024. const int ready = socket->waitUntilReady (true, 0);
  30025. if (ready < 0)
  30026. {
  30027. {
  30028. const ScopedLock sl (pipeAndSocketLock);
  30029. socket = 0;
  30030. }
  30031. connectionLostInt();
  30032. break;
  30033. }
  30034. else if (ready > 0)
  30035. {
  30036. if (! readNextMessageInt())
  30037. break;
  30038. }
  30039. else
  30040. {
  30041. Thread::sleep (2);
  30042. }
  30043. }
  30044. else if (pipe != 0)
  30045. {
  30046. if (! pipe->isOpen())
  30047. {
  30048. {
  30049. const ScopedLock sl (pipeAndSocketLock);
  30050. pipe = 0;
  30051. }
  30052. connectionLostInt();
  30053. break;
  30054. }
  30055. else
  30056. {
  30057. if (! readNextMessageInt())
  30058. break;
  30059. }
  30060. }
  30061. else
  30062. {
  30063. break;
  30064. }
  30065. }
  30066. }
  30067. END_JUCE_NAMESPACE
  30068. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30069. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30070. BEGIN_JUCE_NAMESPACE
  30071. InterprocessConnectionServer::InterprocessConnectionServer()
  30072. : Thread ("Juce IPC server")
  30073. {
  30074. }
  30075. InterprocessConnectionServer::~InterprocessConnectionServer()
  30076. {
  30077. stop();
  30078. }
  30079. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30080. {
  30081. stop();
  30082. socket = new StreamingSocket();
  30083. if (socket->createListener (portNumber))
  30084. {
  30085. startThread();
  30086. return true;
  30087. }
  30088. socket = 0;
  30089. return false;
  30090. }
  30091. void InterprocessConnectionServer::stop()
  30092. {
  30093. signalThreadShouldExit();
  30094. if (socket != 0)
  30095. socket->close();
  30096. stopThread (4000);
  30097. socket = 0;
  30098. }
  30099. void InterprocessConnectionServer::run()
  30100. {
  30101. while ((! threadShouldExit()) && socket != 0)
  30102. {
  30103. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30104. if (clientSocket != 0)
  30105. {
  30106. InterprocessConnection* newConnection = createConnectionObject();
  30107. if (newConnection != 0)
  30108. newConnection->initialiseWithSocket (clientSocket.release());
  30109. }
  30110. }
  30111. }
  30112. END_JUCE_NAMESPACE
  30113. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30114. /*** Start of inlined file: juce_Message.cpp ***/
  30115. BEGIN_JUCE_NAMESPACE
  30116. Message::Message() throw()
  30117. : intParameter1 (0),
  30118. intParameter2 (0),
  30119. intParameter3 (0),
  30120. pointerParameter (0)
  30121. {
  30122. }
  30123. Message::Message (const int intParameter1_,
  30124. const int intParameter2_,
  30125. const int intParameter3_,
  30126. void* const pointerParameter_) throw()
  30127. : intParameter1 (intParameter1_),
  30128. intParameter2 (intParameter2_),
  30129. intParameter3 (intParameter3_),
  30130. pointerParameter (pointerParameter_)
  30131. {
  30132. }
  30133. Message::~Message() throw()
  30134. {
  30135. }
  30136. END_JUCE_NAMESPACE
  30137. /*** End of inlined file: juce_Message.cpp ***/
  30138. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30139. BEGIN_JUCE_NAMESPACE
  30140. MessageListener::MessageListener() throw()
  30141. {
  30142. // are you trying to create a messagelistener before or after juce has been intialised??
  30143. jassert (MessageManager::instance != 0);
  30144. if (MessageManager::instance != 0)
  30145. MessageManager::instance->messageListeners.add (this);
  30146. }
  30147. MessageListener::~MessageListener()
  30148. {
  30149. if (MessageManager::instance != 0)
  30150. MessageManager::instance->messageListeners.removeValue (this);
  30151. }
  30152. void MessageListener::postMessage (Message* const message) const throw()
  30153. {
  30154. message->messageRecipient = const_cast <MessageListener*> (this);
  30155. if (MessageManager::instance == 0)
  30156. MessageManager::getInstance();
  30157. MessageManager::instance->postMessageToQueue (message);
  30158. }
  30159. bool MessageListener::isValidMessageListener() const throw()
  30160. {
  30161. return (MessageManager::instance != 0)
  30162. && MessageManager::instance->messageListeners.contains (this);
  30163. }
  30164. END_JUCE_NAMESPACE
  30165. /*** End of inlined file: juce_MessageListener.cpp ***/
  30166. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30167. BEGIN_JUCE_NAMESPACE
  30168. // platform-specific functions..
  30169. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30170. bool juce_postMessageToSystemQueue (void* message);
  30171. MessageManager* MessageManager::instance = 0;
  30172. static const int quitMessageId = 0xfffff321;
  30173. MessageManager::MessageManager() throw()
  30174. : quitMessagePosted (false),
  30175. quitMessageReceived (false),
  30176. threadWithLock (0)
  30177. {
  30178. messageThreadId = Thread::getCurrentThreadId();
  30179. }
  30180. MessageManager::~MessageManager() throw()
  30181. {
  30182. broadcastListeners = 0;
  30183. doPlatformSpecificShutdown();
  30184. jassert (instance == this);
  30185. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30186. }
  30187. MessageManager* MessageManager::getInstance() throw()
  30188. {
  30189. if (instance == 0)
  30190. {
  30191. instance = new MessageManager();
  30192. doPlatformSpecificInitialisation();
  30193. }
  30194. return instance;
  30195. }
  30196. void MessageManager::postMessageToQueue (Message* const message)
  30197. {
  30198. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30199. delete message;
  30200. }
  30201. CallbackMessage::CallbackMessage() throw() {}
  30202. CallbackMessage::~CallbackMessage() throw() {}
  30203. void CallbackMessage::post()
  30204. {
  30205. if (MessageManager::instance != 0)
  30206. MessageManager::instance->postCallbackMessage (this);
  30207. }
  30208. void MessageManager::postCallbackMessage (Message* const message)
  30209. {
  30210. message->messageRecipient = 0;
  30211. postMessageToQueue (message);
  30212. }
  30213. // not for public use..
  30214. void MessageManager::deliverMessage (void* const message)
  30215. {
  30216. const ScopedPointer <Message> m (static_cast <Message*> (message));
  30217. MessageListener* const recipient = m->messageRecipient;
  30218. JUCE_TRY
  30219. {
  30220. if (messageListeners.contains (recipient))
  30221. {
  30222. recipient->handleMessage (*m);
  30223. }
  30224. else if (recipient == 0)
  30225. {
  30226. if (m->intParameter1 == quitMessageId)
  30227. {
  30228. quitMessageReceived = true;
  30229. }
  30230. else
  30231. {
  30232. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> (static_cast <Message*> (m));
  30233. if (cm != 0)
  30234. cm->messageCallback();
  30235. }
  30236. }
  30237. }
  30238. JUCE_CATCH_EXCEPTION
  30239. }
  30240. #if ! (JUCE_MAC || JUCE_IPHONE)
  30241. void MessageManager::runDispatchLoop()
  30242. {
  30243. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30244. runDispatchLoopUntil (-1);
  30245. }
  30246. void MessageManager::stopDispatchLoop()
  30247. {
  30248. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30249. m->messageRecipient = 0;
  30250. postMessageToQueue (m);
  30251. quitMessagePosted = true;
  30252. }
  30253. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30254. {
  30255. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30256. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30257. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30258. && ! quitMessageReceived)
  30259. {
  30260. JUCE_TRY
  30261. {
  30262. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30263. {
  30264. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30265. if (msToWait > 0)
  30266. Thread::sleep (jmin (5, msToWait));
  30267. }
  30268. }
  30269. JUCE_CATCH_EXCEPTION
  30270. }
  30271. return ! quitMessageReceived;
  30272. }
  30273. #endif
  30274. void MessageManager::deliverBroadcastMessage (const String& value)
  30275. {
  30276. if (broadcastListeners != 0)
  30277. broadcastListeners->sendActionMessage (value);
  30278. }
  30279. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30280. {
  30281. if (broadcastListeners == 0)
  30282. broadcastListeners = new ActionListenerList();
  30283. broadcastListeners->addActionListener (listener);
  30284. }
  30285. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30286. {
  30287. if (broadcastListeners != 0)
  30288. broadcastListeners->removeActionListener (listener);
  30289. }
  30290. bool MessageManager::isThisTheMessageThread() const throw()
  30291. {
  30292. return Thread::getCurrentThreadId() == messageThreadId;
  30293. }
  30294. void MessageManager::setCurrentThreadAsMessageThread()
  30295. {
  30296. if (messageThreadId != Thread::getCurrentThreadId())
  30297. {
  30298. messageThreadId = Thread::getCurrentThreadId();
  30299. // This is needed on windows to make sure the message window is created by this thread
  30300. doPlatformSpecificShutdown();
  30301. doPlatformSpecificInitialisation();
  30302. }
  30303. }
  30304. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30305. {
  30306. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30307. return thisThread == messageThreadId || thisThread == threadWithLock;
  30308. }
  30309. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30310. {
  30311. public:
  30312. SharedEvents() {}
  30313. ~SharedEvents() {}
  30314. WaitableEvent lockedEvent, releaseEvent;
  30315. private:
  30316. SharedEvents (const SharedEvents&);
  30317. SharedEvents& operator= (const SharedEvents&);
  30318. };
  30319. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30320. {
  30321. public:
  30322. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30323. ~BlockingMessage() throw() {}
  30324. void messageCallback()
  30325. {
  30326. events->lockedEvent.signal();
  30327. events->releaseEvent.wait();
  30328. }
  30329. juce_UseDebuggingNewOperator
  30330. private:
  30331. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30332. BlockingMessage (const BlockingMessage&);
  30333. BlockingMessage& operator= (const BlockingMessage&);
  30334. };
  30335. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30336. : sharedEvents (0),
  30337. locked (false)
  30338. {
  30339. init (threadToCheck, 0);
  30340. }
  30341. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30342. : sharedEvents (0),
  30343. locked (false)
  30344. {
  30345. init (0, jobToCheckForExitSignal);
  30346. }
  30347. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30348. {
  30349. if (MessageManager::instance != 0)
  30350. {
  30351. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30352. {
  30353. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30354. }
  30355. else
  30356. {
  30357. if (threadToCheck == 0 && job == 0)
  30358. {
  30359. MessageManager::instance->lockingLock.enter();
  30360. }
  30361. else
  30362. {
  30363. while (! MessageManager::instance->lockingLock.tryEnter())
  30364. {
  30365. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30366. || (job != 0 && job->shouldExit()))
  30367. return;
  30368. Thread::sleep (1);
  30369. }
  30370. }
  30371. sharedEvents = new SharedEvents();
  30372. sharedEvents->incReferenceCount();
  30373. (new BlockingMessage (sharedEvents))->post();
  30374. while (! sharedEvents->lockedEvent.wait (50))
  30375. {
  30376. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30377. || (job != 0 && job->shouldExit()))
  30378. {
  30379. sharedEvents->releaseEvent.signal();
  30380. sharedEvents->decReferenceCount();
  30381. sharedEvents = 0;
  30382. MessageManager::instance->lockingLock.exit();
  30383. return;
  30384. }
  30385. }
  30386. jassert (MessageManager::instance->threadWithLock == 0);
  30387. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30388. locked = true;
  30389. }
  30390. }
  30391. }
  30392. MessageManagerLock::~MessageManagerLock() throw()
  30393. {
  30394. if (sharedEvents != 0)
  30395. {
  30396. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30397. sharedEvents->releaseEvent.signal();
  30398. sharedEvents->decReferenceCount();
  30399. if (MessageManager::instance != 0)
  30400. {
  30401. MessageManager::instance->threadWithLock = 0;
  30402. MessageManager::instance->lockingLock.exit();
  30403. }
  30404. }
  30405. }
  30406. END_JUCE_NAMESPACE
  30407. /*** End of inlined file: juce_MessageManager.cpp ***/
  30408. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30409. BEGIN_JUCE_NAMESPACE
  30410. class MultiTimer::MultiTimerCallback : public Timer
  30411. {
  30412. public:
  30413. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30414. : timerId (timerId_),
  30415. owner (owner_)
  30416. {
  30417. }
  30418. ~MultiTimerCallback()
  30419. {
  30420. }
  30421. void timerCallback()
  30422. {
  30423. owner.timerCallback (timerId);
  30424. }
  30425. const int timerId;
  30426. private:
  30427. MultiTimer& owner;
  30428. };
  30429. MultiTimer::MultiTimer() throw()
  30430. {
  30431. }
  30432. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30433. {
  30434. }
  30435. MultiTimer::~MultiTimer()
  30436. {
  30437. const ScopedLock sl (timerListLock);
  30438. timers.clear();
  30439. }
  30440. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30441. {
  30442. const ScopedLock sl (timerListLock);
  30443. for (int i = timers.size(); --i >= 0;)
  30444. {
  30445. MultiTimerCallback* const t = timers.getUnchecked(i);
  30446. if (t->timerId == timerId)
  30447. {
  30448. t->startTimer (intervalInMilliseconds);
  30449. return;
  30450. }
  30451. }
  30452. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30453. timers.add (newTimer);
  30454. newTimer->startTimer (intervalInMilliseconds);
  30455. }
  30456. void MultiTimer::stopTimer (const int timerId) throw()
  30457. {
  30458. const ScopedLock sl (timerListLock);
  30459. for (int i = timers.size(); --i >= 0;)
  30460. {
  30461. MultiTimerCallback* const t = timers.getUnchecked(i);
  30462. if (t->timerId == timerId)
  30463. t->stopTimer();
  30464. }
  30465. }
  30466. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30467. {
  30468. const ScopedLock sl (timerListLock);
  30469. for (int i = timers.size(); --i >= 0;)
  30470. {
  30471. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30472. if (t->timerId == timerId)
  30473. return t->isTimerRunning();
  30474. }
  30475. return false;
  30476. }
  30477. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30478. {
  30479. const ScopedLock sl (timerListLock);
  30480. for (int i = timers.size(); --i >= 0;)
  30481. {
  30482. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30483. if (t->timerId == timerId)
  30484. return t->getTimerInterval();
  30485. }
  30486. return 0;
  30487. }
  30488. END_JUCE_NAMESPACE
  30489. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30490. /*** Start of inlined file: juce_Timer.cpp ***/
  30491. BEGIN_JUCE_NAMESPACE
  30492. class InternalTimerThread : private Thread,
  30493. private MessageListener,
  30494. private DeletedAtShutdown,
  30495. private AsyncUpdater
  30496. {
  30497. public:
  30498. InternalTimerThread()
  30499. : Thread ("Juce Timer"),
  30500. firstTimer (0),
  30501. callbackNeeded (false)
  30502. {
  30503. triggerAsyncUpdate();
  30504. }
  30505. ~InternalTimerThread() throw()
  30506. {
  30507. stopThread (4000);
  30508. jassert (instance == this || instance == 0);
  30509. if (instance == this)
  30510. instance = 0;
  30511. }
  30512. void run()
  30513. {
  30514. uint32 lastTime = Time::getMillisecondCounter();
  30515. while (! threadShouldExit())
  30516. {
  30517. const uint32 now = Time::getMillisecondCounter();
  30518. if (now <= lastTime)
  30519. {
  30520. wait (2);
  30521. continue;
  30522. }
  30523. const int elapsed = now - lastTime;
  30524. lastTime = now;
  30525. int timeUntilFirstTimer = 1000;
  30526. {
  30527. const ScopedLock sl (lock);
  30528. decrementAllCounters (elapsed);
  30529. if (firstTimer != 0)
  30530. timeUntilFirstTimer = firstTimer->countdownMs;
  30531. }
  30532. if (timeUntilFirstTimer <= 0)
  30533. {
  30534. if (callbackNeeded.set (true))
  30535. {
  30536. postMessage (new Message());
  30537. const uint32 messageDeliveryTimeout = now + 2000;
  30538. while (callbackNeeded.get())
  30539. {
  30540. wait (4);
  30541. if (threadShouldExit())
  30542. return;
  30543. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30544. break;
  30545. }
  30546. }
  30547. }
  30548. else
  30549. {
  30550. // don't wait for too long because running this loop also helps keep the
  30551. // Time::getApproximateMillisecondTimer value stay up-to-date
  30552. wait (jlimit (1, 50, timeUntilFirstTimer));
  30553. }
  30554. }
  30555. }
  30556. void callTimers()
  30557. {
  30558. const ScopedLock sl (lock);
  30559. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30560. {
  30561. Timer* const t = firstTimer;
  30562. t->countdownMs = t->periodMs;
  30563. removeTimer (t);
  30564. addTimer (t);
  30565. const ScopedUnlock ul (lock);
  30566. JUCE_TRY
  30567. {
  30568. t->timerCallback();
  30569. }
  30570. JUCE_CATCH_EXCEPTION
  30571. }
  30572. callbackNeeded.set (false);
  30573. }
  30574. void handleMessage (const Message&)
  30575. {
  30576. callTimers();
  30577. }
  30578. void callTimersSynchronously()
  30579. {
  30580. if (! isThreadRunning())
  30581. {
  30582. // (This is relied on by some plugins in cases where the MM has
  30583. // had to restart and the async callback never started)
  30584. cancelPendingUpdate();
  30585. triggerAsyncUpdate();
  30586. }
  30587. callTimers();
  30588. }
  30589. static void callAnyTimersSynchronously()
  30590. {
  30591. if (InternalTimerThread::instance != 0)
  30592. InternalTimerThread::instance->callTimersSynchronously();
  30593. }
  30594. static inline void add (Timer* const tim) throw()
  30595. {
  30596. if (instance == 0)
  30597. instance = new InternalTimerThread();
  30598. const ScopedLock sl (instance->lock);
  30599. instance->addTimer (tim);
  30600. }
  30601. static inline void remove (Timer* const tim) throw()
  30602. {
  30603. if (instance != 0)
  30604. {
  30605. const ScopedLock sl (instance->lock);
  30606. instance->removeTimer (tim);
  30607. }
  30608. }
  30609. static inline void resetCounter (Timer* const tim,
  30610. const int newCounter) throw()
  30611. {
  30612. if (instance != 0)
  30613. {
  30614. tim->countdownMs = newCounter;
  30615. tim->periodMs = newCounter;
  30616. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30617. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30618. {
  30619. const ScopedLock sl (instance->lock);
  30620. instance->removeTimer (tim);
  30621. instance->addTimer (tim);
  30622. }
  30623. }
  30624. }
  30625. private:
  30626. friend class Timer;
  30627. static InternalTimerThread* instance;
  30628. static CriticalSection lock;
  30629. Timer* volatile firstTimer;
  30630. class AtomicBool
  30631. {
  30632. public:
  30633. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30634. ~AtomicBool() throw() {}
  30635. bool get() const throw() { return value != 0; }
  30636. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30637. private:
  30638. int32 value;
  30639. AtomicBool (const AtomicBool&);
  30640. AtomicBool& operator= (const AtomicBool&);
  30641. };
  30642. AtomicBool callbackNeeded;
  30643. void addTimer (Timer* const t) throw()
  30644. {
  30645. #ifdef JUCE_DEBUG
  30646. Timer* tt = firstTimer;
  30647. while (tt != 0)
  30648. {
  30649. // trying to add a timer that's already here - shouldn't get to this point,
  30650. // so if you get this assertion, let me know!
  30651. jassert (tt != t);
  30652. tt = tt->next;
  30653. }
  30654. jassert (t->previous == 0 && t->next == 0);
  30655. #endif
  30656. Timer* i = firstTimer;
  30657. if (i == 0 || i->countdownMs > t->countdownMs)
  30658. {
  30659. t->next = firstTimer;
  30660. firstTimer = t;
  30661. }
  30662. else
  30663. {
  30664. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30665. i = i->next;
  30666. jassert (i != 0);
  30667. t->next = i->next;
  30668. t->previous = i;
  30669. i->next = t;
  30670. }
  30671. if (t->next != 0)
  30672. t->next->previous = t;
  30673. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30674. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30675. notify();
  30676. }
  30677. void removeTimer (Timer* const t) throw()
  30678. {
  30679. #ifdef JUCE_DEBUG
  30680. Timer* tt = firstTimer;
  30681. bool found = false;
  30682. while (tt != 0)
  30683. {
  30684. if (tt == t)
  30685. {
  30686. found = true;
  30687. break;
  30688. }
  30689. tt = tt->next;
  30690. }
  30691. // trying to remove a timer that's not here - shouldn't get to this point,
  30692. // so if you get this assertion, let me know!
  30693. jassert (found);
  30694. #endif
  30695. if (t->previous != 0)
  30696. {
  30697. jassert (firstTimer != t);
  30698. t->previous->next = t->next;
  30699. }
  30700. else
  30701. {
  30702. jassert (firstTimer == t);
  30703. firstTimer = t->next;
  30704. }
  30705. if (t->next != 0)
  30706. t->next->previous = t->previous;
  30707. t->next = 0;
  30708. t->previous = 0;
  30709. }
  30710. void decrementAllCounters (const int numMillisecs) const
  30711. {
  30712. Timer* t = firstTimer;
  30713. while (t != 0)
  30714. {
  30715. t->countdownMs -= numMillisecs;
  30716. t = t->next;
  30717. }
  30718. }
  30719. void handleAsyncUpdate()
  30720. {
  30721. startThread (7);
  30722. }
  30723. InternalTimerThread (const InternalTimerThread&);
  30724. InternalTimerThread& operator= (const InternalTimerThread&);
  30725. };
  30726. InternalTimerThread* InternalTimerThread::instance = 0;
  30727. CriticalSection InternalTimerThread::lock;
  30728. void juce_callAnyTimersSynchronously()
  30729. {
  30730. InternalTimerThread::callAnyTimersSynchronously();
  30731. }
  30732. #ifdef JUCE_DEBUG
  30733. static SortedSet <Timer*> activeTimers;
  30734. #endif
  30735. Timer::Timer() throw()
  30736. : countdownMs (0),
  30737. periodMs (0),
  30738. previous (0),
  30739. next (0)
  30740. {
  30741. #ifdef JUCE_DEBUG
  30742. activeTimers.add (this);
  30743. #endif
  30744. }
  30745. Timer::Timer (const Timer&) throw()
  30746. : countdownMs (0),
  30747. periodMs (0),
  30748. previous (0),
  30749. next (0)
  30750. {
  30751. #ifdef JUCE_DEBUG
  30752. activeTimers.add (this);
  30753. #endif
  30754. }
  30755. Timer::~Timer()
  30756. {
  30757. stopTimer();
  30758. #ifdef JUCE_DEBUG
  30759. activeTimers.removeValue (this);
  30760. #endif
  30761. }
  30762. void Timer::startTimer (const int interval) throw()
  30763. {
  30764. const ScopedLock sl (InternalTimerThread::lock);
  30765. #ifdef JUCE_DEBUG
  30766. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30767. jassert (activeTimers.contains (this));
  30768. #endif
  30769. if (periodMs == 0)
  30770. {
  30771. countdownMs = interval;
  30772. periodMs = jmax (1, interval);
  30773. InternalTimerThread::add (this);
  30774. }
  30775. else
  30776. {
  30777. InternalTimerThread::resetCounter (this, interval);
  30778. }
  30779. }
  30780. void Timer::stopTimer() throw()
  30781. {
  30782. const ScopedLock sl (InternalTimerThread::lock);
  30783. #ifdef JUCE_DEBUG
  30784. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30785. jassert (activeTimers.contains (this));
  30786. #endif
  30787. if (periodMs > 0)
  30788. {
  30789. InternalTimerThread::remove (this);
  30790. periodMs = 0;
  30791. }
  30792. }
  30793. END_JUCE_NAMESPACE
  30794. /*** End of inlined file: juce_Timer.cpp ***/
  30795. #endif
  30796. #if JUCE_BUILD_GUI
  30797. /*** Start of inlined file: juce_Component.cpp ***/
  30798. BEGIN_JUCE_NAMESPACE
  30799. Component* Component::currentlyFocusedComponent = 0;
  30800. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30801. static Array <int> modalReturnValues;
  30802. enum ComponentMessageNumbers
  30803. {
  30804. customCommandMessage = 0x7fff0001,
  30805. exitModalStateMessage = 0x7fff0002
  30806. };
  30807. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30808. static uint32 nextComponentUID = 0;
  30809. Component::Component()
  30810. : parentComponent_ (0),
  30811. componentUID (++nextComponentUID),
  30812. numDeepMouseListeners (0),
  30813. lookAndFeel_ (0),
  30814. effect_ (0),
  30815. bufferedImage_ (0),
  30816. mouseListeners_ (0),
  30817. keyListeners_ (0),
  30818. componentFlags_ (0)
  30819. {
  30820. }
  30821. Component::Component (const String& name)
  30822. : componentName_ (name),
  30823. parentComponent_ (0),
  30824. componentUID (++nextComponentUID),
  30825. numDeepMouseListeners (0),
  30826. lookAndFeel_ (0),
  30827. effect_ (0),
  30828. bufferedImage_ (0),
  30829. mouseListeners_ (0),
  30830. keyListeners_ (0),
  30831. componentFlags_ (0)
  30832. {
  30833. }
  30834. Component::~Component()
  30835. {
  30836. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30837. if (parentComponent_ != 0)
  30838. {
  30839. parentComponent_->removeChildComponent (this);
  30840. }
  30841. else if ((currentlyFocusedComponent == this)
  30842. || isParentOf (currentlyFocusedComponent))
  30843. {
  30844. giveAwayFocus();
  30845. }
  30846. if (flags.hasHeavyweightPeerFlag)
  30847. removeFromDesktop();
  30848. modalComponentStack.removeValue (this);
  30849. for (int i = childComponentList_.size(); --i >= 0;)
  30850. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30851. delete bufferedImage_;
  30852. delete mouseListeners_;
  30853. delete keyListeners_;
  30854. }
  30855. void Component::setName (const String& name)
  30856. {
  30857. // if component methods are being called from threads other than the message
  30858. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30859. checkMessageManagerIsLocked
  30860. if (componentName_ != name)
  30861. {
  30862. componentName_ = name;
  30863. if (flags.hasHeavyweightPeerFlag)
  30864. {
  30865. ComponentPeer* const peer = getPeer();
  30866. jassert (peer != 0);
  30867. if (peer != 0)
  30868. peer->setTitle (name);
  30869. }
  30870. BailOutChecker checker (this);
  30871. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30872. }
  30873. }
  30874. void Component::setVisible (bool shouldBeVisible)
  30875. {
  30876. if (flags.visibleFlag != shouldBeVisible)
  30877. {
  30878. // if component methods are being called from threads other than the message
  30879. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30880. checkMessageManagerIsLocked
  30881. SafePointer<Component> safePointer (this);
  30882. flags.visibleFlag = shouldBeVisible;
  30883. internalRepaint (0, 0, getWidth(), getHeight());
  30884. sendFakeMouseMove();
  30885. if (! shouldBeVisible)
  30886. {
  30887. if (currentlyFocusedComponent == this
  30888. || isParentOf (currentlyFocusedComponent))
  30889. {
  30890. if (parentComponent_ != 0)
  30891. parentComponent_->grabKeyboardFocus();
  30892. else
  30893. giveAwayFocus();
  30894. }
  30895. }
  30896. if (safePointer != 0)
  30897. {
  30898. sendVisibilityChangeMessage();
  30899. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30900. {
  30901. ComponentPeer* const peer = getPeer();
  30902. jassert (peer != 0);
  30903. if (peer != 0)
  30904. {
  30905. peer->setVisible (shouldBeVisible);
  30906. internalHierarchyChanged();
  30907. }
  30908. }
  30909. }
  30910. }
  30911. }
  30912. void Component::visibilityChanged()
  30913. {
  30914. }
  30915. void Component::sendVisibilityChangeMessage()
  30916. {
  30917. BailOutChecker checker (this);
  30918. visibilityChanged();
  30919. if (! checker.shouldBailOut())
  30920. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30921. }
  30922. bool Component::isShowing() const
  30923. {
  30924. if (flags.visibleFlag)
  30925. {
  30926. if (parentComponent_ != 0)
  30927. {
  30928. return parentComponent_->isShowing();
  30929. }
  30930. else
  30931. {
  30932. const ComponentPeer* const peer = getPeer();
  30933. return peer != 0 && ! peer->isMinimised();
  30934. }
  30935. }
  30936. return false;
  30937. }
  30938. class FadeOutProxyComponent : public Component,
  30939. public Timer
  30940. {
  30941. public:
  30942. FadeOutProxyComponent (Component* comp,
  30943. const int fadeLengthMs,
  30944. const int deltaXToMove,
  30945. const int deltaYToMove,
  30946. const float scaleFactorAtEnd)
  30947. : lastTime (0),
  30948. alpha (1.0f),
  30949. scale (1.0f)
  30950. {
  30951. image = comp->createComponentSnapshot (comp->getLocalBounds());
  30952. setBounds (comp->getBounds());
  30953. comp->getParentComponent()->addAndMakeVisible (this);
  30954. toBehind (comp);
  30955. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30956. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30957. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30958. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30959. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30960. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30961. setInterceptsMouseClicks (false, false);
  30962. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30963. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30964. }
  30965. ~FadeOutProxyComponent()
  30966. {
  30967. delete image;
  30968. }
  30969. void paint (Graphics& g)
  30970. {
  30971. g.setOpacity (alpha);
  30972. g.drawImage (image,
  30973. 0, 0, getWidth(), getHeight(),
  30974. 0, 0, image->getWidth(), image->getHeight());
  30975. }
  30976. void timerCallback()
  30977. {
  30978. const uint32 now = Time::getMillisecondCounter();
  30979. if (lastTime == 0)
  30980. lastTime = now;
  30981. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  30982. lastTime = now;
  30983. alpha += alphaChangePerMs * msPassed;
  30984. if (alpha > 0)
  30985. {
  30986. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  30987. {
  30988. centreX += xChangePerMs * msPassed;
  30989. centreY += yChangePerMs * msPassed;
  30990. scale += scaleChangePerMs * msPassed;
  30991. const int w = roundToInt (image->getWidth() * scale);
  30992. const int h = roundToInt (image->getHeight() * scale);
  30993. setBounds (roundToInt (centreX) - w / 2,
  30994. roundToInt (centreY) - h / 2,
  30995. w, h);
  30996. }
  30997. repaint();
  30998. }
  30999. else
  31000. {
  31001. delete this;
  31002. }
  31003. }
  31004. juce_UseDebuggingNewOperator
  31005. private:
  31006. Image* image;
  31007. uint32 lastTime;
  31008. float alpha, alphaChangePerMs;
  31009. float centreX, xChangePerMs;
  31010. float centreY, yChangePerMs;
  31011. float scale, scaleChangePerMs;
  31012. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31013. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31014. };
  31015. void Component::fadeOutComponent (const int millisecondsToFade,
  31016. const int deltaXToMove,
  31017. const int deltaYToMove,
  31018. const float scaleFactorAtEnd)
  31019. {
  31020. //xxx won't work for comps without parents
  31021. if (isShowing() && millisecondsToFade > 0)
  31022. new FadeOutProxyComponent (this, millisecondsToFade,
  31023. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31024. setVisible (false);
  31025. }
  31026. bool Component::isValidComponent() const
  31027. {
  31028. return (this != 0) && isValidMessageListener();
  31029. }
  31030. void* Component::getWindowHandle() const
  31031. {
  31032. const ComponentPeer* const peer = getPeer();
  31033. if (peer != 0)
  31034. return peer->getNativeHandle();
  31035. return 0;
  31036. }
  31037. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31038. {
  31039. // if component methods are being called from threads other than the message
  31040. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31041. checkMessageManagerIsLocked
  31042. if (isOpaque())
  31043. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31044. else
  31045. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31046. int currentStyleFlags = 0;
  31047. // don't use getPeer(), so that we only get the peer that's specifically
  31048. // for this comp, and not for one of its parents.
  31049. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31050. if (peer != 0)
  31051. currentStyleFlags = peer->getStyleFlags();
  31052. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31053. {
  31054. SafePointer<Component> safePointer (this);
  31055. #if JUCE_LINUX
  31056. // it's wise to give the component a non-zero size before
  31057. // putting it on the desktop, as X windows get confused by this, and
  31058. // a (1, 1) minimum size is enforced here.
  31059. setSize (jmax (1, getWidth()),
  31060. jmax (1, getHeight()));
  31061. #endif
  31062. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31063. bool wasFullscreen = false;
  31064. bool wasMinimised = false;
  31065. ComponentBoundsConstrainer* currentConstainer = 0;
  31066. Rectangle<int> oldNonFullScreenBounds;
  31067. if (peer != 0)
  31068. {
  31069. wasFullscreen = peer->isFullScreen();
  31070. wasMinimised = peer->isMinimised();
  31071. currentConstainer = peer->getConstrainer();
  31072. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31073. removeFromDesktop();
  31074. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31075. }
  31076. if (parentComponent_ != 0)
  31077. parentComponent_->removeChildComponent (this);
  31078. if (safePointer != 0)
  31079. {
  31080. flags.hasHeavyweightPeerFlag = true;
  31081. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31082. Desktop::getInstance().addDesktopComponent (this);
  31083. bounds_.setPosition (topLeft);
  31084. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31085. peer->setVisible (isVisible());
  31086. if (wasFullscreen)
  31087. {
  31088. peer->setFullScreen (true);
  31089. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31090. }
  31091. if (wasMinimised)
  31092. peer->setMinimised (true);
  31093. if (isAlwaysOnTop())
  31094. peer->setAlwaysOnTop (true);
  31095. peer->setConstrainer (currentConstainer);
  31096. repaint();
  31097. }
  31098. internalHierarchyChanged();
  31099. }
  31100. }
  31101. void Component::removeFromDesktop()
  31102. {
  31103. // if component methods are being called from threads other than the message
  31104. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31105. checkMessageManagerIsLocked
  31106. if (flags.hasHeavyweightPeerFlag)
  31107. {
  31108. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31109. flags.hasHeavyweightPeerFlag = false;
  31110. jassert (peer != 0);
  31111. delete peer;
  31112. Desktop::getInstance().removeDesktopComponent (this);
  31113. }
  31114. }
  31115. bool Component::isOnDesktop() const throw()
  31116. {
  31117. return flags.hasHeavyweightPeerFlag;
  31118. }
  31119. void Component::userTriedToCloseWindow()
  31120. {
  31121. /* This means that the user's trying to get rid of your window with the 'close window' system
  31122. menu option (on windows) or possibly the task manager - you should really handle this
  31123. and delete or hide your component in an appropriate way.
  31124. If you want to ignore the event and don't want to trigger this assertion, just override
  31125. this method and do nothing.
  31126. */
  31127. jassertfalse
  31128. }
  31129. void Component::minimisationStateChanged (bool)
  31130. {
  31131. }
  31132. void Component::setOpaque (const bool shouldBeOpaque)
  31133. {
  31134. if (shouldBeOpaque != flags.opaqueFlag)
  31135. {
  31136. flags.opaqueFlag = shouldBeOpaque;
  31137. if (flags.hasHeavyweightPeerFlag)
  31138. {
  31139. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31140. if (peer != 0)
  31141. {
  31142. // to make it recreate the heavyweight window
  31143. addToDesktop (peer->getStyleFlags());
  31144. }
  31145. }
  31146. repaint();
  31147. }
  31148. }
  31149. bool Component::isOpaque() const throw()
  31150. {
  31151. return flags.opaqueFlag;
  31152. }
  31153. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31154. {
  31155. if (shouldBeBuffered != flags.bufferToImageFlag)
  31156. {
  31157. deleteAndZero (bufferedImage_);
  31158. flags.bufferToImageFlag = shouldBeBuffered;
  31159. }
  31160. }
  31161. void Component::toFront (const bool setAsForeground)
  31162. {
  31163. // if component methods are being called from threads other than the message
  31164. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31165. checkMessageManagerIsLocked
  31166. if (flags.hasHeavyweightPeerFlag)
  31167. {
  31168. ComponentPeer* const peer = getPeer();
  31169. if (peer != 0)
  31170. {
  31171. peer->toFront (setAsForeground);
  31172. if (setAsForeground && ! hasKeyboardFocus (true))
  31173. grabKeyboardFocus();
  31174. }
  31175. }
  31176. else if (parentComponent_ != 0)
  31177. {
  31178. Array<Component*>& childList = parentComponent_->childComponentList_;
  31179. if (childList.getLast() != this)
  31180. {
  31181. const int index = childList.indexOf (this);
  31182. if (index >= 0)
  31183. {
  31184. int insertIndex = -1;
  31185. if (! flags.alwaysOnTopFlag)
  31186. {
  31187. insertIndex = childList.size() - 1;
  31188. while (insertIndex > 0 && childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31189. --insertIndex;
  31190. }
  31191. if (index != insertIndex)
  31192. {
  31193. childList.move (index, insertIndex);
  31194. sendFakeMouseMove();
  31195. repaintParent();
  31196. }
  31197. }
  31198. }
  31199. if (setAsForeground)
  31200. {
  31201. internalBroughtToFront();
  31202. grabKeyboardFocus();
  31203. }
  31204. }
  31205. }
  31206. void Component::toBehind (Component* const other)
  31207. {
  31208. if (other != 0 && other != this)
  31209. {
  31210. // the two components must belong to the same parent..
  31211. jassert (parentComponent_ == other->parentComponent_);
  31212. if (parentComponent_ != 0)
  31213. {
  31214. Array<Component*>& childList = parentComponent_->childComponentList_;
  31215. const int index = childList.indexOf (this);
  31216. if (index >= 0 && childList [index + 1] != other)
  31217. {
  31218. int otherIndex = childList.indexOf (other);
  31219. if (otherIndex >= 0)
  31220. {
  31221. if (index < otherIndex)
  31222. --otherIndex;
  31223. childList.move (index, otherIndex);
  31224. sendFakeMouseMove();
  31225. repaintParent();
  31226. }
  31227. }
  31228. }
  31229. else if (isOnDesktop())
  31230. {
  31231. jassert (other->isOnDesktop());
  31232. if (other->isOnDesktop())
  31233. {
  31234. ComponentPeer* const us = getPeer();
  31235. ComponentPeer* const them = other->getPeer();
  31236. jassert (us != 0 && them != 0);
  31237. if (us != 0 && them != 0)
  31238. us->toBehind (them);
  31239. }
  31240. }
  31241. }
  31242. }
  31243. void Component::toBack()
  31244. {
  31245. Array<Component*>& childList = parentComponent_->childComponentList_;
  31246. if (isOnDesktop())
  31247. {
  31248. jassertfalse //xxx need to add this to native window
  31249. }
  31250. else if (parentComponent_ != 0 && childList.getFirst() != this)
  31251. {
  31252. const int index = childList.indexOf (this);
  31253. if (index > 0)
  31254. {
  31255. int insertIndex = 0;
  31256. if (flags.alwaysOnTopFlag)
  31257. {
  31258. while (insertIndex < childList.size()
  31259. && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31260. {
  31261. ++insertIndex;
  31262. }
  31263. }
  31264. if (index != insertIndex)
  31265. {
  31266. childList.move (index, insertIndex);
  31267. sendFakeMouseMove();
  31268. repaintParent();
  31269. }
  31270. }
  31271. }
  31272. }
  31273. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31274. {
  31275. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31276. {
  31277. flags.alwaysOnTopFlag = shouldStayOnTop;
  31278. if (isOnDesktop())
  31279. {
  31280. ComponentPeer* const peer = getPeer();
  31281. jassert (peer != 0);
  31282. if (peer != 0)
  31283. {
  31284. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31285. {
  31286. // some kinds of peer can't change their always-on-top status, so
  31287. // for these, we'll need to create a new window
  31288. const int oldFlags = peer->getStyleFlags();
  31289. removeFromDesktop();
  31290. addToDesktop (oldFlags);
  31291. }
  31292. }
  31293. }
  31294. if (shouldStayOnTop)
  31295. toFront (false);
  31296. internalHierarchyChanged();
  31297. }
  31298. }
  31299. bool Component::isAlwaysOnTop() const throw()
  31300. {
  31301. return flags.alwaysOnTopFlag;
  31302. }
  31303. int Component::proportionOfWidth (const float proportion) const throw()
  31304. {
  31305. return roundToInt (proportion * bounds_.getWidth());
  31306. }
  31307. int Component::proportionOfHeight (const float proportion) const throw()
  31308. {
  31309. return roundToInt (proportion * bounds_.getHeight());
  31310. }
  31311. int Component::getParentWidth() const throw()
  31312. {
  31313. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31314. : getParentMonitorArea().getWidth();
  31315. }
  31316. int Component::getParentHeight() const throw()
  31317. {
  31318. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31319. : getParentMonitorArea().getHeight();
  31320. }
  31321. int Component::getScreenX() const
  31322. {
  31323. return getScreenPosition().getX();
  31324. }
  31325. int Component::getScreenY() const
  31326. {
  31327. return getScreenPosition().getY();
  31328. }
  31329. const Point<int> Component::getScreenPosition() const
  31330. {
  31331. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31332. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31333. : getPosition());
  31334. }
  31335. const Rectangle<int> Component::getScreenBounds() const
  31336. {
  31337. return bounds_.withPosition (getScreenPosition());
  31338. }
  31339. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31340. {
  31341. const Component* c = this;
  31342. Point<int> p (relativePosition);
  31343. do
  31344. {
  31345. if (c->flags.hasHeavyweightPeerFlag)
  31346. return c->getPeer()->relativePositionToGlobal (p);
  31347. p += c->getPosition();
  31348. c = c->parentComponent_;
  31349. }
  31350. while (c != 0);
  31351. return p;
  31352. }
  31353. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31354. {
  31355. if (flags.hasHeavyweightPeerFlag)
  31356. {
  31357. return getPeer()->globalPositionToRelative (screenPosition);
  31358. }
  31359. else
  31360. {
  31361. if (parentComponent_ != 0)
  31362. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31363. return screenPosition - getPosition();
  31364. }
  31365. }
  31366. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31367. {
  31368. Point<int> p (positionRelativeToThis);
  31369. if (targetComponent != 0)
  31370. {
  31371. const Component* c = this;
  31372. do
  31373. {
  31374. if (c == targetComponent)
  31375. return p;
  31376. if (c->flags.hasHeavyweightPeerFlag)
  31377. {
  31378. p = c->getPeer()->relativePositionToGlobal (p);
  31379. break;
  31380. }
  31381. p += c->getPosition();
  31382. c = c->parentComponent_;
  31383. }
  31384. while (c != 0);
  31385. p = targetComponent->globalPositionToRelative (p);
  31386. }
  31387. return p;
  31388. }
  31389. void Component::setBounds (int x, int y, int w, int h)
  31390. {
  31391. // if component methods are being called from threads other than the message
  31392. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31393. checkMessageManagerIsLocked
  31394. if (w < 0) w = 0;
  31395. if (h < 0) h = 0;
  31396. const bool wasResized = (getWidth() != w || getHeight() != h);
  31397. const bool wasMoved = (getX() != x || getY() != y);
  31398. #ifdef JUCE_DEBUG
  31399. // It's a very bad idea to try to resize a window during its paint() method!
  31400. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31401. #endif
  31402. if (wasMoved || wasResized)
  31403. {
  31404. if (flags.visibleFlag)
  31405. {
  31406. // send a fake mouse move to trigger enter/exit messages if needed..
  31407. sendFakeMouseMove();
  31408. if (! flags.hasHeavyweightPeerFlag)
  31409. repaintParent();
  31410. }
  31411. bounds_.setBounds (x, y, w, h);
  31412. if (wasResized)
  31413. repaint();
  31414. else if (! flags.hasHeavyweightPeerFlag)
  31415. repaintParent();
  31416. if (flags.hasHeavyweightPeerFlag)
  31417. {
  31418. ComponentPeer* const peer = getPeer();
  31419. if (peer != 0)
  31420. {
  31421. if (wasMoved && wasResized)
  31422. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31423. else if (wasMoved)
  31424. peer->setPosition (getX(), getY());
  31425. else if (wasResized)
  31426. peer->setSize (getWidth(), getHeight());
  31427. }
  31428. }
  31429. sendMovedResizedMessages (wasMoved, wasResized);
  31430. }
  31431. }
  31432. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31433. {
  31434. JUCE_TRY
  31435. {
  31436. if (wasMoved)
  31437. moved();
  31438. if (wasResized)
  31439. {
  31440. resized();
  31441. for (int i = childComponentList_.size(); --i >= 0;)
  31442. {
  31443. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31444. i = jmin (i, childComponentList_.size());
  31445. }
  31446. }
  31447. BailOutChecker checker (this);
  31448. if (parentComponent_ != 0)
  31449. parentComponent_->childBoundsChanged (this);
  31450. if (! checker.shouldBailOut())
  31451. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31452. *this, wasMoved, wasResized);
  31453. }
  31454. JUCE_CATCH_EXCEPTION
  31455. }
  31456. void Component::setSize (const int w, const int h)
  31457. {
  31458. setBounds (getX(), getY(), w, h);
  31459. }
  31460. void Component::setTopLeftPosition (const int x, const int y)
  31461. {
  31462. setBounds (x, y, getWidth(), getHeight());
  31463. }
  31464. void Component::setTopRightPosition (const int x, const int y)
  31465. {
  31466. setTopLeftPosition (x - getWidth(), y);
  31467. }
  31468. void Component::setBounds (const Rectangle<int>& r)
  31469. {
  31470. setBounds (r.getX(),
  31471. r.getY(),
  31472. r.getWidth(),
  31473. r.getHeight());
  31474. }
  31475. void Component::setBoundsRelative (const float x, const float y,
  31476. const float w, const float h)
  31477. {
  31478. const int pw = getParentWidth();
  31479. const int ph = getParentHeight();
  31480. setBounds (roundToInt (x * pw),
  31481. roundToInt (y * ph),
  31482. roundToInt (w * pw),
  31483. roundToInt (h * ph));
  31484. }
  31485. void Component::setCentrePosition (const int x, const int y)
  31486. {
  31487. setTopLeftPosition (x - getWidth() / 2,
  31488. y - getHeight() / 2);
  31489. }
  31490. void Component::setCentreRelative (const float x, const float y)
  31491. {
  31492. setCentrePosition (roundToInt (getParentWidth() * x),
  31493. roundToInt (getParentHeight() * y));
  31494. }
  31495. void Component::centreWithSize (const int width, const int height)
  31496. {
  31497. setBounds ((getParentWidth() - width) / 2,
  31498. (getParentHeight() - height) / 2,
  31499. width,
  31500. height);
  31501. }
  31502. void Component::setBoundsInset (const BorderSize& borders)
  31503. {
  31504. setBounds (borders.getLeft(),
  31505. borders.getTop(),
  31506. getParentWidth() - (borders.getLeftAndRight()),
  31507. getParentHeight() - (borders.getTopAndBottom()));
  31508. }
  31509. void Component::setBoundsToFit (int x, int y, int width, int height,
  31510. const Justification& justification,
  31511. const bool onlyReduceInSize)
  31512. {
  31513. // it's no good calling this method unless both the component and
  31514. // target rectangle have a finite size.
  31515. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31516. if (getWidth() > 0 && getHeight() > 0
  31517. && width > 0 && height > 0)
  31518. {
  31519. int newW, newH;
  31520. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31521. {
  31522. newW = getWidth();
  31523. newH = getHeight();
  31524. }
  31525. else
  31526. {
  31527. const double imageRatio = getHeight() / (double) getWidth();
  31528. const double targetRatio = height / (double) width;
  31529. if (imageRatio <= targetRatio)
  31530. {
  31531. newW = width;
  31532. newH = jmin (height, roundToInt (newW * imageRatio));
  31533. }
  31534. else
  31535. {
  31536. newH = height;
  31537. newW = jmin (width, roundToInt (newH / imageRatio));
  31538. }
  31539. }
  31540. if (newW > 0 && newH > 0)
  31541. {
  31542. int newX, newY;
  31543. justification.applyToRectangle (newX, newY, newW, newH,
  31544. x, y, width, height);
  31545. setBounds (newX, newY, newW, newH);
  31546. }
  31547. }
  31548. }
  31549. bool Component::hitTest (int x, int y)
  31550. {
  31551. if (! flags.ignoresMouseClicksFlag)
  31552. return true;
  31553. if (flags.allowChildMouseClicksFlag)
  31554. {
  31555. for (int i = getNumChildComponents(); --i >= 0;)
  31556. {
  31557. Component* const c = getChildComponent (i);
  31558. if (c->isVisible()
  31559. && c->bounds_.contains (x, y)
  31560. && c->hitTest (x - c->getX(),
  31561. y - c->getY()))
  31562. {
  31563. return true;
  31564. }
  31565. }
  31566. }
  31567. return false;
  31568. }
  31569. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31570. const bool allowClicksOnChildComponents) throw()
  31571. {
  31572. flags.ignoresMouseClicksFlag = ! allowClicks;
  31573. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31574. }
  31575. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31576. bool& allowsClicksOnChildComponents) const throw()
  31577. {
  31578. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31579. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31580. }
  31581. bool Component::contains (const int x, const int y)
  31582. {
  31583. if (((unsigned int) x) < (unsigned int) getWidth()
  31584. && ((unsigned int) y) < (unsigned int) getHeight()
  31585. && hitTest (x, y))
  31586. {
  31587. if (parentComponent_ != 0)
  31588. {
  31589. return parentComponent_->contains (x + getX(),
  31590. y + getY());
  31591. }
  31592. else if (flags.hasHeavyweightPeerFlag)
  31593. {
  31594. const ComponentPeer* const peer = getPeer();
  31595. if (peer != 0)
  31596. return peer->contains (Point<int> (x, y), true);
  31597. }
  31598. }
  31599. return false;
  31600. }
  31601. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31602. {
  31603. if (! contains (x, y))
  31604. return false;
  31605. Component* p = this;
  31606. while (p->parentComponent_ != 0)
  31607. {
  31608. x += p->getX();
  31609. y += p->getY();
  31610. p = p->parentComponent_;
  31611. }
  31612. const Component* const c = p->getComponentAt (x, y);
  31613. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31614. }
  31615. Component* Component::getComponentAt (const Point<int>& position)
  31616. {
  31617. return getComponentAt (position.getX(), position.getY());
  31618. }
  31619. Component* Component::getComponentAt (const int x, const int y)
  31620. {
  31621. if (flags.visibleFlag
  31622. && ((unsigned int) x) < (unsigned int) getWidth()
  31623. && ((unsigned int) y) < (unsigned int) getHeight()
  31624. && hitTest (x, y))
  31625. {
  31626. for (int i = childComponentList_.size(); --i >= 0;)
  31627. {
  31628. Component* const child = childComponentList_.getUnchecked(i);
  31629. Component* const c = child->getComponentAt (x - child->getX(),
  31630. y - child->getY());
  31631. if (c != 0)
  31632. return c;
  31633. }
  31634. return this;
  31635. }
  31636. return 0;
  31637. }
  31638. void Component::addChildComponent (Component* const child, int zOrder)
  31639. {
  31640. // if component methods are being called from threads other than the message
  31641. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31642. checkMessageManagerIsLocked
  31643. if (child != 0 && child->parentComponent_ != this)
  31644. {
  31645. if (child->parentComponent_ != 0)
  31646. child->parentComponent_->removeChildComponent (child);
  31647. else
  31648. child->removeFromDesktop();
  31649. child->parentComponent_ = this;
  31650. if (child->isVisible())
  31651. child->repaintParent();
  31652. if (! child->isAlwaysOnTop())
  31653. {
  31654. if (zOrder < 0 || zOrder > childComponentList_.size())
  31655. zOrder = childComponentList_.size();
  31656. while (zOrder > 0)
  31657. {
  31658. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31659. break;
  31660. --zOrder;
  31661. }
  31662. }
  31663. childComponentList_.insert (zOrder, child);
  31664. child->internalHierarchyChanged();
  31665. internalChildrenChanged();
  31666. }
  31667. }
  31668. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31669. {
  31670. if (child != 0)
  31671. {
  31672. child->setVisible (true);
  31673. addChildComponent (child, zOrder);
  31674. }
  31675. }
  31676. void Component::removeChildComponent (Component* const child)
  31677. {
  31678. removeChildComponent (childComponentList_.indexOf (child));
  31679. }
  31680. Component* Component::removeChildComponent (const int index)
  31681. {
  31682. // if component methods are being called from threads other than the message
  31683. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31684. checkMessageManagerIsLocked
  31685. Component* const child = childComponentList_ [index];
  31686. if (child != 0)
  31687. {
  31688. sendFakeMouseMove();
  31689. child->repaintParent();
  31690. childComponentList_.remove (index);
  31691. child->parentComponent_ = 0;
  31692. JUCE_TRY
  31693. {
  31694. if ((currentlyFocusedComponent == child)
  31695. || child->isParentOf (currentlyFocusedComponent))
  31696. {
  31697. // get rid first to force the grabKeyboardFocus to change to us.
  31698. giveAwayFocus();
  31699. grabKeyboardFocus();
  31700. }
  31701. }
  31702. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31703. catch (const std::exception& e)
  31704. {
  31705. currentlyFocusedComponent = 0;
  31706. Desktop::getInstance().triggerFocusCallback();
  31707. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31708. }
  31709. catch (...)
  31710. {
  31711. currentlyFocusedComponent = 0;
  31712. Desktop::getInstance().triggerFocusCallback();
  31713. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31714. }
  31715. #endif
  31716. child->internalHierarchyChanged();
  31717. internalChildrenChanged();
  31718. }
  31719. return child;
  31720. }
  31721. void Component::removeAllChildren()
  31722. {
  31723. while (childComponentList_.size() > 0)
  31724. removeChildComponent (childComponentList_.size() - 1);
  31725. }
  31726. void Component::deleteAllChildren()
  31727. {
  31728. while (childComponentList_.size() > 0)
  31729. delete (removeChildComponent (childComponentList_.size() - 1));
  31730. }
  31731. int Component::getNumChildComponents() const throw()
  31732. {
  31733. return childComponentList_.size();
  31734. }
  31735. Component* Component::getChildComponent (const int index) const throw()
  31736. {
  31737. return childComponentList_ [index];
  31738. }
  31739. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31740. {
  31741. return childComponentList_.indexOf (const_cast <Component*> (child));
  31742. }
  31743. Component* Component::getTopLevelComponent() const throw()
  31744. {
  31745. const Component* comp = this;
  31746. while (comp->parentComponent_ != 0)
  31747. comp = comp->parentComponent_;
  31748. return const_cast <Component*> (comp);
  31749. }
  31750. bool Component::isParentOf (const Component* possibleChild) const throw()
  31751. {
  31752. if (! possibleChild->isValidComponent())
  31753. {
  31754. jassert (possibleChild == 0);
  31755. return false;
  31756. }
  31757. while (possibleChild != 0)
  31758. {
  31759. possibleChild = possibleChild->parentComponent_;
  31760. if (possibleChild == this)
  31761. return true;
  31762. }
  31763. return false;
  31764. }
  31765. void Component::parentHierarchyChanged()
  31766. {
  31767. }
  31768. void Component::childrenChanged()
  31769. {
  31770. }
  31771. void Component::internalChildrenChanged()
  31772. {
  31773. if (componentListeners.isEmpty())
  31774. {
  31775. childrenChanged();
  31776. }
  31777. else
  31778. {
  31779. BailOutChecker checker (this);
  31780. childrenChanged();
  31781. if (! checker.shouldBailOut())
  31782. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31783. }
  31784. }
  31785. void Component::internalHierarchyChanged()
  31786. {
  31787. BailOutChecker checker (this);
  31788. parentHierarchyChanged();
  31789. if (checker.shouldBailOut())
  31790. return;
  31791. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31792. if (checker.shouldBailOut())
  31793. return;
  31794. for (int i = childComponentList_.size(); --i >= 0;)
  31795. {
  31796. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31797. if (checker.shouldBailOut())
  31798. {
  31799. // you really shouldn't delete the parent component during a callback telling you
  31800. // that it's changed..
  31801. jassertfalse;
  31802. return;
  31803. }
  31804. i = jmin (i, childComponentList_.size());
  31805. }
  31806. }
  31807. void* Component::runModalLoopCallback (void* userData)
  31808. {
  31809. return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
  31810. }
  31811. int Component::runModalLoop()
  31812. {
  31813. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31814. {
  31815. // use a callback so this can be called from non-gui threads
  31816. return (int) (pointer_sized_int)
  31817. MessageManager::getInstance()
  31818. ->callFunctionOnMessageThread (&runModalLoopCallback, this);
  31819. }
  31820. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31821. if (! isCurrentlyModal())
  31822. enterModalState();
  31823. JUCE_TRY
  31824. {
  31825. while (flags.currentlyModalFlag && flags.visibleFlag)
  31826. {
  31827. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31828. break;
  31829. // check whether this component was deleted during the last message
  31830. if (! isValidMessageListener())
  31831. break;
  31832. }
  31833. }
  31834. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31835. catch (const std::exception& e)
  31836. {
  31837. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31838. return 0;
  31839. }
  31840. catch (...)
  31841. {
  31842. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31843. return 0;
  31844. }
  31845. #endif
  31846. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31847. int returnValue = 0;
  31848. if (modalIndex >= 0)
  31849. {
  31850. modalComponentReturnValueKeys.remove (modalIndex);
  31851. returnValue = modalReturnValues.remove (modalIndex);
  31852. }
  31853. modalComponentStack.removeValue (this);
  31854. if (prevFocused != 0)
  31855. prevFocused->grabKeyboardFocus();
  31856. return returnValue;
  31857. }
  31858. void Component::enterModalState (const bool takeKeyboardFocus_)
  31859. {
  31860. // if component methods are being called from threads other than the message
  31861. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31862. checkMessageManagerIsLocked
  31863. // Check for an attempt to make a component modal when it already is!
  31864. // This can cause nasty problems..
  31865. jassert (! flags.currentlyModalFlag);
  31866. if (! isCurrentlyModal())
  31867. {
  31868. modalComponentStack.add (this);
  31869. modalComponentReturnValueKeys.add (this);
  31870. modalReturnValues.add (0);
  31871. flags.currentlyModalFlag = true;
  31872. setVisible (true);
  31873. if (takeKeyboardFocus_)
  31874. grabKeyboardFocus();
  31875. }
  31876. }
  31877. void Component::exitModalState (const int returnValue)
  31878. {
  31879. if (isCurrentlyModal())
  31880. {
  31881. if (MessageManager::getInstance()->isThisTheMessageThread())
  31882. {
  31883. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31884. if (modalIndex >= 0)
  31885. {
  31886. modalReturnValues.set (modalIndex, returnValue);
  31887. }
  31888. else
  31889. {
  31890. modalComponentReturnValueKeys.add (this);
  31891. modalReturnValues.add (returnValue);
  31892. }
  31893. modalComponentStack.removeValue (this);
  31894. flags.currentlyModalFlag = false;
  31895. bringModalComponentToFront();
  31896. }
  31897. else
  31898. {
  31899. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31900. }
  31901. }
  31902. }
  31903. bool Component::isCurrentlyModal() const throw()
  31904. {
  31905. return flags.currentlyModalFlag
  31906. && getCurrentlyModalComponent() == this;
  31907. }
  31908. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31909. {
  31910. Component* const mc = getCurrentlyModalComponent();
  31911. return mc != 0
  31912. && mc != this
  31913. && (! mc->isParentOf (this))
  31914. && ! mc->canModalEventBeSentToComponent (this);
  31915. }
  31916. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31917. {
  31918. return modalComponentStack.size();
  31919. }
  31920. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31921. {
  31922. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31923. return c->isValidComponent() ? c : 0;
  31924. }
  31925. void Component::bringModalComponentToFront()
  31926. {
  31927. ComponentPeer* lastOne = 0;
  31928. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31929. {
  31930. Component* const c = getCurrentlyModalComponent (i);
  31931. if (c == 0)
  31932. break;
  31933. ComponentPeer* peer = c->getPeer();
  31934. if (peer != 0 && peer != lastOne)
  31935. {
  31936. if (lastOne == 0)
  31937. {
  31938. peer->toFront (true);
  31939. peer->grabFocus();
  31940. }
  31941. else
  31942. peer->toBehind (lastOne);
  31943. lastOne = peer;
  31944. }
  31945. }
  31946. }
  31947. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31948. {
  31949. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31950. }
  31951. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31952. {
  31953. return flags.bringToFrontOnClickFlag;
  31954. }
  31955. void Component::setMouseCursor (const MouseCursor& cursor)
  31956. {
  31957. if (cursor_ != cursor)
  31958. {
  31959. cursor_ = cursor;
  31960. if (flags.visibleFlag)
  31961. updateMouseCursor();
  31962. }
  31963. }
  31964. const MouseCursor Component::getMouseCursor()
  31965. {
  31966. return cursor_;
  31967. }
  31968. void Component::updateMouseCursor() const
  31969. {
  31970. sendFakeMouseMove();
  31971. }
  31972. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  31973. {
  31974. flags.repaintOnMouseActivityFlag = shouldRepaint;
  31975. }
  31976. void Component::repaintParent()
  31977. {
  31978. if (flags.visibleFlag)
  31979. internalRepaint (0, 0, getWidth(), getHeight());
  31980. }
  31981. void Component::repaint()
  31982. {
  31983. repaint (0, 0, getWidth(), getHeight());
  31984. }
  31985. void Component::repaint (const int x, const int y,
  31986. const int w, const int h)
  31987. {
  31988. deleteAndZero (bufferedImage_);
  31989. if (flags.visibleFlag)
  31990. internalRepaint (x, y, w, h);
  31991. }
  31992. void Component::internalRepaint (int x, int y, int w, int h)
  31993. {
  31994. // if component methods are being called from threads other than the message
  31995. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31996. checkMessageManagerIsLocked
  31997. if (x < 0)
  31998. {
  31999. w += x;
  32000. x = 0;
  32001. }
  32002. if (x + w > getWidth())
  32003. w = getWidth() - x;
  32004. if (w > 0)
  32005. {
  32006. if (y < 0)
  32007. {
  32008. h += y;
  32009. y = 0;
  32010. }
  32011. if (y + h > getHeight())
  32012. h = getHeight() - y;
  32013. if (h > 0)
  32014. {
  32015. if (parentComponent_ != 0)
  32016. {
  32017. x += getX();
  32018. y += getY();
  32019. if (parentComponent_->flags.visibleFlag)
  32020. parentComponent_->internalRepaint (x, y, w, h);
  32021. }
  32022. else if (flags.hasHeavyweightPeerFlag)
  32023. {
  32024. ComponentPeer* const peer = getPeer();
  32025. if (peer != 0)
  32026. peer->repaint (x, y, w, h);
  32027. }
  32028. }
  32029. }
  32030. }
  32031. void Component::renderComponent (Graphics& g)
  32032. {
  32033. const Rectangle<int> clipBounds (g.getClipBounds());
  32034. g.saveState();
  32035. clipObscuredRegions (g, clipBounds, 0, 0);
  32036. if (! g.isClipEmpty())
  32037. {
  32038. if (flags.bufferToImageFlag)
  32039. {
  32040. if (bufferedImage_ == 0)
  32041. {
  32042. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32043. getWidth(), getHeight(), ! flags.opaqueFlag);
  32044. Graphics imG (*bufferedImage_);
  32045. paint (imG);
  32046. }
  32047. g.setColour (Colours::black);
  32048. g.drawImageAt (bufferedImage_, 0, 0);
  32049. }
  32050. else
  32051. {
  32052. paint (g);
  32053. }
  32054. }
  32055. g.restoreState();
  32056. for (int i = 0; i < childComponentList_.size(); ++i)
  32057. {
  32058. Component* const child = childComponentList_.getUnchecked (i);
  32059. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32060. {
  32061. g.saveState();
  32062. if (g.reduceClipRegion (child->getX(), child->getY(),
  32063. child->getWidth(), child->getHeight()))
  32064. {
  32065. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32066. {
  32067. const Component* const sibling = childComponentList_.getUnchecked (j);
  32068. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32069. g.excludeClipRegion (sibling->getBounds());
  32070. }
  32071. if (! g.isClipEmpty())
  32072. {
  32073. g.setOrigin (child->getX(), child->getY());
  32074. child->paintEntireComponent (g);
  32075. }
  32076. }
  32077. g.restoreState();
  32078. }
  32079. }
  32080. g.saveState();
  32081. paintOverChildren (g);
  32082. g.restoreState();
  32083. }
  32084. void Component::paintEntireComponent (Graphics& g)
  32085. {
  32086. jassert (! g.isClipEmpty());
  32087. #ifdef JUCE_DEBUG
  32088. flags.isInsidePaintCall = true;
  32089. #endif
  32090. if (effect_ != 0)
  32091. {
  32092. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32093. getWidth(), getHeight(),
  32094. ! flags.opaqueFlag));
  32095. {
  32096. Graphics g2 (*effectImage);
  32097. renderComponent (g2);
  32098. }
  32099. effect_->applyEffect (*effectImage, g);
  32100. }
  32101. else
  32102. {
  32103. renderComponent (g);
  32104. }
  32105. #ifdef JUCE_DEBUG
  32106. flags.isInsidePaintCall = false;
  32107. #endif
  32108. }
  32109. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32110. const bool clipImageToComponentBounds)
  32111. {
  32112. Rectangle<int> r (areaToGrab);
  32113. if (clipImageToComponentBounds)
  32114. r = r.getIntersection (getLocalBounds());
  32115. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32116. jmax (1, r.getWidth()),
  32117. jmax (1, r.getHeight()),
  32118. true));
  32119. Graphics imageContext (*componentImage);
  32120. imageContext.setOrigin (-r.getX(), -r.getY());
  32121. paintEntireComponent (imageContext);
  32122. return componentImage.release();
  32123. }
  32124. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32125. {
  32126. if (effect_ != effect)
  32127. {
  32128. effect_ = effect;
  32129. repaint();
  32130. }
  32131. }
  32132. LookAndFeel& Component::getLookAndFeel() const throw()
  32133. {
  32134. const Component* c = this;
  32135. do
  32136. {
  32137. if (c->lookAndFeel_ != 0)
  32138. return *(c->lookAndFeel_);
  32139. c = c->parentComponent_;
  32140. }
  32141. while (c != 0);
  32142. return LookAndFeel::getDefaultLookAndFeel();
  32143. }
  32144. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32145. {
  32146. if (lookAndFeel_ != newLookAndFeel)
  32147. {
  32148. lookAndFeel_ = newLookAndFeel;
  32149. sendLookAndFeelChange();
  32150. }
  32151. }
  32152. void Component::lookAndFeelChanged()
  32153. {
  32154. }
  32155. void Component::sendLookAndFeelChange()
  32156. {
  32157. repaint();
  32158. lookAndFeelChanged();
  32159. // (it's not a great idea to do anything that would delete this component
  32160. // during the lookAndFeelChanged() callback)
  32161. jassert (isValidComponent());
  32162. SafePointer<Component> safePointer (this);
  32163. for (int i = childComponentList_.size(); --i >= 0;)
  32164. {
  32165. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32166. if (safePointer == 0)
  32167. return;
  32168. i = jmin (i, childComponentList_.size());
  32169. }
  32170. }
  32171. static const var::identifier getColourPropertyId (const int colourId)
  32172. {
  32173. String s;
  32174. s.preallocateStorage (18);
  32175. s << "jcclr_" << String::toHexString (colourId);
  32176. return s;
  32177. }
  32178. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32179. {
  32180. var* v = properties.getItem (getColourPropertyId (colourId));
  32181. if (v != 0)
  32182. return Colour ((int) *v);
  32183. if (inheritFromParent && parentComponent_ != 0)
  32184. return parentComponent_->findColour (colourId, true);
  32185. return getLookAndFeel().findColour (colourId);
  32186. }
  32187. bool Component::isColourSpecified (const int colourId) const
  32188. {
  32189. return properties.contains (getColourPropertyId (colourId));
  32190. }
  32191. void Component::removeColour (const int colourId)
  32192. {
  32193. if (properties.remove (getColourPropertyId (colourId)))
  32194. colourChanged();
  32195. }
  32196. void Component::setColour (const int colourId, const Colour& colour)
  32197. {
  32198. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32199. colourChanged();
  32200. }
  32201. void Component::copyAllExplicitColoursTo (Component& target) const
  32202. {
  32203. bool changed = false;
  32204. for (int i = properties.size(); --i >= 0;)
  32205. {
  32206. const var::identifier name (properties.getName(i));
  32207. if (name.name.startsWith ("jcclr_"))
  32208. if (target.properties.set (name, properties [name]))
  32209. changed = true;
  32210. }
  32211. if (changed)
  32212. target.colourChanged();
  32213. }
  32214. void Component::colourChanged()
  32215. {
  32216. }
  32217. const Rectangle<int> Component::getLocalBounds() const throw()
  32218. {
  32219. return Rectangle<int> (0, 0, getWidth(), getHeight());
  32220. }
  32221. const Rectangle<int> Component::getUnclippedArea() const
  32222. {
  32223. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32224. Component* p = parentComponent_;
  32225. int px = getX();
  32226. int py = getY();
  32227. while (p != 0)
  32228. {
  32229. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32230. return Rectangle<int>();
  32231. px += p->getX();
  32232. py += p->getY();
  32233. p = p->parentComponent_;
  32234. }
  32235. return Rectangle<int> (x, y, w, h);
  32236. }
  32237. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32238. const int deltaX, const int deltaY) const
  32239. {
  32240. for (int i = childComponentList_.size(); --i >= 0;)
  32241. {
  32242. const Component* const c = childComponentList_.getUnchecked(i);
  32243. if (c->isVisible())
  32244. {
  32245. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32246. if (! newClip.isEmpty())
  32247. {
  32248. if (c->isOpaque())
  32249. {
  32250. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32251. }
  32252. else
  32253. {
  32254. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32255. c->getX() + deltaX,
  32256. c->getY() + deltaY);
  32257. }
  32258. }
  32259. }
  32260. }
  32261. }
  32262. void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const
  32263. {
  32264. result.clear();
  32265. const Rectangle<int> unclipped (getUnclippedArea());
  32266. if (! unclipped.isEmpty())
  32267. {
  32268. result.add (unclipped);
  32269. if (includeSiblings)
  32270. {
  32271. const Component* const c = getTopLevelComponent();
  32272. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32273. c->getLocalBounds(), this);
  32274. }
  32275. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32276. result.consolidate();
  32277. }
  32278. }
  32279. void Component::subtractObscuredRegions (RectangleList& result,
  32280. const Point<int>& delta,
  32281. const Rectangle<int>& clipRect,
  32282. const Component* const compToAvoid) const
  32283. {
  32284. for (int i = childComponentList_.size(); --i >= 0;)
  32285. {
  32286. const Component* const c = childComponentList_.getUnchecked(i);
  32287. if (c != compToAvoid && c->isVisible())
  32288. {
  32289. if (c->isOpaque())
  32290. {
  32291. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32292. childBounds.translate (delta.getX(), delta.getY());
  32293. result.subtract (childBounds);
  32294. }
  32295. else
  32296. {
  32297. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32298. newClip.translate (-c->getX(), -c->getY());
  32299. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32300. newClip, compToAvoid);
  32301. }
  32302. }
  32303. }
  32304. }
  32305. void Component::mouseEnter (const MouseEvent&)
  32306. {
  32307. // base class does nothing
  32308. }
  32309. void Component::mouseExit (const MouseEvent&)
  32310. {
  32311. // base class does nothing
  32312. }
  32313. void Component::mouseDown (const MouseEvent&)
  32314. {
  32315. // base class does nothing
  32316. }
  32317. void Component::mouseUp (const MouseEvent&)
  32318. {
  32319. // base class does nothing
  32320. }
  32321. void Component::mouseDrag (const MouseEvent&)
  32322. {
  32323. // base class does nothing
  32324. }
  32325. void Component::mouseMove (const MouseEvent&)
  32326. {
  32327. // base class does nothing
  32328. }
  32329. void Component::mouseDoubleClick (const MouseEvent&)
  32330. {
  32331. // base class does nothing
  32332. }
  32333. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32334. {
  32335. // the base class just passes this event up to its parent..
  32336. if (parentComponent_ != 0)
  32337. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32338. wheelIncrementX, wheelIncrementY);
  32339. }
  32340. void Component::resized()
  32341. {
  32342. // base class does nothing
  32343. }
  32344. void Component::moved()
  32345. {
  32346. // base class does nothing
  32347. }
  32348. void Component::childBoundsChanged (Component*)
  32349. {
  32350. // base class does nothing
  32351. }
  32352. void Component::parentSizeChanged()
  32353. {
  32354. // base class does nothing
  32355. }
  32356. void Component::addComponentListener (ComponentListener* const newListener)
  32357. {
  32358. jassert (isValidComponent());
  32359. componentListeners.add (newListener);
  32360. }
  32361. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32362. {
  32363. jassert (isValidComponent());
  32364. componentListeners.remove (listenerToRemove);
  32365. }
  32366. void Component::inputAttemptWhenModal()
  32367. {
  32368. bringModalComponentToFront();
  32369. getLookAndFeel().playAlertSound();
  32370. }
  32371. bool Component::canModalEventBeSentToComponent (const Component*)
  32372. {
  32373. return false;
  32374. }
  32375. void Component::internalModalInputAttempt()
  32376. {
  32377. Component* const current = getCurrentlyModalComponent();
  32378. if (current != 0)
  32379. current->inputAttemptWhenModal();
  32380. }
  32381. void Component::paint (Graphics&)
  32382. {
  32383. // all painting is done in the subclasses
  32384. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32385. }
  32386. void Component::paintOverChildren (Graphics&)
  32387. {
  32388. // all painting is done in the subclasses
  32389. }
  32390. void Component::handleMessage (const Message& message)
  32391. {
  32392. if (message.intParameter1 == exitModalStateMessage)
  32393. {
  32394. exitModalState (message.intParameter2);
  32395. }
  32396. else if (message.intParameter1 == customCommandMessage)
  32397. {
  32398. handleCommandMessage (message.intParameter2);
  32399. }
  32400. }
  32401. void Component::postCommandMessage (const int commandId)
  32402. {
  32403. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32404. }
  32405. void Component::handleCommandMessage (int)
  32406. {
  32407. // used by subclasses
  32408. }
  32409. void Component::addMouseListener (MouseListener* const newListener,
  32410. const bool wantsEventsForAllNestedChildComponents)
  32411. {
  32412. // if component methods are being called from threads other than the message
  32413. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32414. checkMessageManagerIsLocked
  32415. if (mouseListeners_ == 0)
  32416. mouseListeners_ = new Array<MouseListener*>();
  32417. if (! mouseListeners_->contains (newListener))
  32418. {
  32419. if (wantsEventsForAllNestedChildComponents)
  32420. {
  32421. mouseListeners_->insert (0, newListener);
  32422. ++numDeepMouseListeners;
  32423. }
  32424. else
  32425. {
  32426. mouseListeners_->add (newListener);
  32427. }
  32428. }
  32429. }
  32430. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32431. {
  32432. // if component methods are being called from threads other than the message
  32433. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32434. checkMessageManagerIsLocked
  32435. if (mouseListeners_ != 0)
  32436. {
  32437. const int index = mouseListeners_->indexOf (listenerToRemove);
  32438. if (index >= 0)
  32439. {
  32440. if (index < numDeepMouseListeners)
  32441. --numDeepMouseListeners;
  32442. mouseListeners_->remove (index);
  32443. }
  32444. }
  32445. }
  32446. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32447. {
  32448. if (isCurrentlyBlockedByAnotherModalComponent())
  32449. {
  32450. // if something else is modal, always just show a normal mouse cursor
  32451. source.showMouseCursor (MouseCursor::NormalCursor);
  32452. return;
  32453. }
  32454. if (! flags.mouseInsideFlag)
  32455. {
  32456. flags.mouseInsideFlag = true;
  32457. flags.mouseOverFlag = true;
  32458. flags.draggingFlag = false;
  32459. BailOutChecker checker (this);
  32460. if (flags.repaintOnMouseActivityFlag)
  32461. repaint();
  32462. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32463. this, time, relativePos,
  32464. time, 0, false);
  32465. mouseEnter (me);
  32466. if (checker.shouldBailOut())
  32467. return;
  32468. Desktop::getInstance().resetTimer();
  32469. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32470. if (checker.shouldBailOut())
  32471. return;
  32472. if (mouseListeners_ != 0)
  32473. {
  32474. for (int i = mouseListeners_->size(); --i >= 0;)
  32475. {
  32476. mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32477. if (checker.shouldBailOut())
  32478. return;
  32479. i = jmin (i, mouseListeners_->size());
  32480. }
  32481. }
  32482. Component* p = parentComponent_;
  32483. while (p != 0)
  32484. {
  32485. if (p->numDeepMouseListeners > 0)
  32486. {
  32487. BailOutChecker checker (this, p);
  32488. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32489. {
  32490. p->mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32491. if (checker.shouldBailOut())
  32492. return;
  32493. i = jmin (i, p->numDeepMouseListeners);
  32494. }
  32495. }
  32496. p = p->parentComponent_;
  32497. }
  32498. }
  32499. }
  32500. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32501. {
  32502. BailOutChecker checker (this);
  32503. if (flags.draggingFlag)
  32504. {
  32505. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32506. if (checker.shouldBailOut())
  32507. return;
  32508. }
  32509. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32510. {
  32511. flags.mouseInsideFlag = false;
  32512. flags.mouseOverFlag = false;
  32513. flags.draggingFlag = false;
  32514. if (flags.repaintOnMouseActivityFlag)
  32515. repaint();
  32516. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32517. this, time, relativePos,
  32518. time, 0, false);
  32519. mouseExit (me);
  32520. if (checker.shouldBailOut())
  32521. return;
  32522. Desktop::getInstance().resetTimer();
  32523. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32524. if (checker.shouldBailOut())
  32525. return;
  32526. if (mouseListeners_ != 0)
  32527. {
  32528. for (int i = mouseListeners_->size(); --i >= 0;)
  32529. {
  32530. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32531. if (checker.shouldBailOut())
  32532. return;
  32533. i = jmin (i, mouseListeners_->size());
  32534. }
  32535. }
  32536. Component* p = parentComponent_;
  32537. while (p != 0)
  32538. {
  32539. if (p->numDeepMouseListeners > 0)
  32540. {
  32541. BailOutChecker checker (this, p);
  32542. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32543. {
  32544. p->mouseListeners_->getUnchecked (i)->mouseExit (me);
  32545. if (checker.shouldBailOut())
  32546. return;
  32547. i = jmin (i, p->numDeepMouseListeners);
  32548. }
  32549. }
  32550. p = p->parentComponent_;
  32551. }
  32552. }
  32553. }
  32554. class InternalDragRepeater : public Timer
  32555. {
  32556. public:
  32557. InternalDragRepeater()
  32558. {}
  32559. ~InternalDragRepeater()
  32560. {
  32561. clearSingletonInstance();
  32562. }
  32563. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32564. void timerCallback()
  32565. {
  32566. Desktop& desktop = Desktop::getInstance();
  32567. int numMiceDown = 0;
  32568. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32569. {
  32570. MouseInputSource* const source = desktop.getMouseSource(i);
  32571. if (source->isDragging())
  32572. {
  32573. source->triggerFakeMove();
  32574. ++numMiceDown;
  32575. }
  32576. }
  32577. if (numMiceDown == 0)
  32578. deleteInstance();
  32579. }
  32580. juce_UseDebuggingNewOperator
  32581. private:
  32582. InternalDragRepeater (const InternalDragRepeater&);
  32583. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32584. };
  32585. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32586. void Component::beginDragAutoRepeat (const int interval)
  32587. {
  32588. if (interval > 0)
  32589. {
  32590. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32591. InternalDragRepeater::getInstance()->startTimer (interval);
  32592. }
  32593. else
  32594. {
  32595. InternalDragRepeater::deleteInstance();
  32596. }
  32597. }
  32598. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32599. {
  32600. Desktop& desktop = Desktop::getInstance();
  32601. BailOutChecker checker (this);
  32602. if (isCurrentlyBlockedByAnotherModalComponent())
  32603. {
  32604. internalModalInputAttempt();
  32605. if (checker.shouldBailOut())
  32606. return;
  32607. // If processing the input attempt has exited the modal loop, we'll allow the event
  32608. // to be delivered..
  32609. if (isCurrentlyBlockedByAnotherModalComponent())
  32610. {
  32611. // allow blocked mouse-events to go to global listeners..
  32612. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32613. this, time, relativePos, time,
  32614. source.getNumberOfMultipleClicks(), false);
  32615. desktop.resetTimer();
  32616. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32617. return;
  32618. }
  32619. }
  32620. {
  32621. Component* c = this;
  32622. while (c != 0)
  32623. {
  32624. if (c->isBroughtToFrontOnMouseClick())
  32625. {
  32626. c->toFront (true);
  32627. if (checker.shouldBailOut())
  32628. return;
  32629. }
  32630. c = c->parentComponent_;
  32631. }
  32632. }
  32633. if (! flags.dontFocusOnMouseClickFlag)
  32634. {
  32635. grabFocusInternal (focusChangedByMouseClick);
  32636. if (checker.shouldBailOut())
  32637. return;
  32638. }
  32639. flags.draggingFlag = true;
  32640. flags.mouseOverFlag = true;
  32641. if (flags.repaintOnMouseActivityFlag)
  32642. repaint();
  32643. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32644. this, time, relativePos, time,
  32645. source.getNumberOfMultipleClicks(), false);
  32646. mouseDown (me);
  32647. if (checker.shouldBailOut())
  32648. return;
  32649. desktop.resetTimer();
  32650. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32651. if (checker.shouldBailOut())
  32652. return;
  32653. if (mouseListeners_ != 0)
  32654. {
  32655. for (int i = mouseListeners_->size(); --i >= 0;)
  32656. {
  32657. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32658. if (checker.shouldBailOut())
  32659. return;
  32660. i = jmin (i, mouseListeners_->size());
  32661. }
  32662. }
  32663. Component* p = parentComponent_;
  32664. while (p != 0)
  32665. {
  32666. if (p->numDeepMouseListeners > 0)
  32667. {
  32668. BailOutChecker checker (this, p);
  32669. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32670. {
  32671. p->mouseListeners_->getUnchecked (i)->mouseDown (me);
  32672. if (checker.shouldBailOut())
  32673. return;
  32674. i = jmin (i, p->numDeepMouseListeners);
  32675. }
  32676. }
  32677. p = p->parentComponent_;
  32678. }
  32679. }
  32680. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32681. {
  32682. if (flags.draggingFlag)
  32683. {
  32684. Desktop& desktop = Desktop::getInstance();
  32685. flags.draggingFlag = false;
  32686. BailOutChecker checker (this);
  32687. if (flags.repaintOnMouseActivityFlag)
  32688. repaint();
  32689. const MouseEvent me (source, relativePos,
  32690. oldModifiers, this, time,
  32691. globalPositionToRelative (source.getLastMouseDownPosition()),
  32692. source.getLastMouseDownTime(),
  32693. source.getNumberOfMultipleClicks(),
  32694. source.hasMouseMovedSignificantlySincePressed());
  32695. mouseUp (me);
  32696. if (checker.shouldBailOut())
  32697. return;
  32698. desktop.resetTimer();
  32699. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32700. if (checker.shouldBailOut())
  32701. return;
  32702. if (mouseListeners_ != 0)
  32703. {
  32704. for (int i = mouseListeners_->size(); --i >= 0;)
  32705. {
  32706. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32707. if (checker.shouldBailOut())
  32708. return;
  32709. i = jmin (i, mouseListeners_->size());
  32710. }
  32711. }
  32712. {
  32713. Component* p = parentComponent_;
  32714. while (p != 0)
  32715. {
  32716. if (p->numDeepMouseListeners > 0)
  32717. {
  32718. BailOutChecker checker (this, p);
  32719. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32720. {
  32721. p->mouseListeners_->getUnchecked (i)->mouseUp (me);
  32722. if (checker.shouldBailOut())
  32723. return;
  32724. i = jmin (i, p->numDeepMouseListeners);
  32725. }
  32726. }
  32727. p = p->parentComponent_;
  32728. }
  32729. }
  32730. // check for double-click
  32731. if (me.getNumberOfClicks() >= 2)
  32732. {
  32733. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32734. mouseDoubleClick (me);
  32735. if (checker.shouldBailOut())
  32736. return;
  32737. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32738. if (checker.shouldBailOut())
  32739. return;
  32740. for (int i = numListeners; --i >= 0;)
  32741. {
  32742. if (checker.shouldBailOut())
  32743. return;
  32744. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32745. if (ml != 0)
  32746. ml->mouseDoubleClick (me);
  32747. }
  32748. if (checker.shouldBailOut())
  32749. return;
  32750. Component* p = parentComponent_;
  32751. while (p != 0)
  32752. {
  32753. if (p->numDeepMouseListeners > 0)
  32754. {
  32755. BailOutChecker checker (this, p);
  32756. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32757. {
  32758. p->mouseListeners_->getUnchecked (i)->mouseDoubleClick (me);
  32759. if (checker.shouldBailOut())
  32760. return;
  32761. i = jmin (i, p->numDeepMouseListeners);
  32762. }
  32763. }
  32764. p = p->parentComponent_;
  32765. }
  32766. }
  32767. }
  32768. }
  32769. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32770. {
  32771. if (flags.draggingFlag)
  32772. {
  32773. Desktop& desktop = Desktop::getInstance();
  32774. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32775. BailOutChecker checker (this);
  32776. const MouseEvent me (source, relativePos,
  32777. source.getCurrentModifiers(), this, time,
  32778. globalPositionToRelative (source.getLastMouseDownPosition()),
  32779. source.getLastMouseDownTime(),
  32780. source.getNumberOfMultipleClicks(),
  32781. source.hasMouseMovedSignificantlySincePressed());
  32782. mouseDrag (me);
  32783. if (checker.shouldBailOut())
  32784. return;
  32785. desktop.resetTimer();
  32786. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32787. if (checker.shouldBailOut())
  32788. return;
  32789. if (mouseListeners_ != 0)
  32790. {
  32791. for (int i = mouseListeners_->size(); --i >= 0;)
  32792. {
  32793. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32794. if (checker.shouldBailOut())
  32795. return;
  32796. i = jmin (i, mouseListeners_->size());
  32797. }
  32798. }
  32799. Component* p = parentComponent_;
  32800. while (p != 0)
  32801. {
  32802. if (p->numDeepMouseListeners > 0)
  32803. {
  32804. BailOutChecker checker (this, p);
  32805. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32806. {
  32807. p->mouseListeners_->getUnchecked (i)->mouseDrag (me);
  32808. if (checker.shouldBailOut())
  32809. return;
  32810. i = jmin (i, p->numDeepMouseListeners);
  32811. }
  32812. }
  32813. p = p->parentComponent_;
  32814. }
  32815. }
  32816. }
  32817. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32818. {
  32819. Desktop& desktop = Desktop::getInstance();
  32820. BailOutChecker checker (this);
  32821. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32822. this, time, relativePos,
  32823. time, 0, false);
  32824. if (isCurrentlyBlockedByAnotherModalComponent())
  32825. {
  32826. // allow blocked mouse-events to go to global listeners..
  32827. desktop.sendMouseMove();
  32828. }
  32829. else
  32830. {
  32831. flags.mouseOverFlag = true;
  32832. mouseMove (me);
  32833. if (checker.shouldBailOut())
  32834. return;
  32835. desktop.resetTimer();
  32836. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32837. if (checker.shouldBailOut())
  32838. return;
  32839. if (mouseListeners_ != 0)
  32840. {
  32841. for (int i = mouseListeners_->size(); --i >= 0;)
  32842. {
  32843. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32844. if (checker.shouldBailOut())
  32845. return;
  32846. i = jmin (i, mouseListeners_->size());
  32847. }
  32848. }
  32849. Component* p = parentComponent_;
  32850. while (p != 0)
  32851. {
  32852. if (p->numDeepMouseListeners > 0)
  32853. {
  32854. BailOutChecker checker (this, p);
  32855. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32856. {
  32857. p->mouseListeners_->getUnchecked (i)->mouseMove (me);
  32858. if (checker.shouldBailOut())
  32859. return;
  32860. i = jmin (i, p->numDeepMouseListeners);
  32861. }
  32862. }
  32863. p = p->parentComponent_;
  32864. }
  32865. }
  32866. }
  32867. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32868. const Time& time, const float amountX, const float amountY)
  32869. {
  32870. Desktop& desktop = Desktop::getInstance();
  32871. BailOutChecker checker (this);
  32872. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32873. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32874. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32875. this, time, relativePos, time, 0, false);
  32876. if (isCurrentlyBlockedByAnotherModalComponent())
  32877. {
  32878. // allow blocked mouse-events to go to global listeners..
  32879. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32880. }
  32881. else
  32882. {
  32883. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32884. if (checker.shouldBailOut())
  32885. return;
  32886. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32887. if (checker.shouldBailOut())
  32888. return;
  32889. if (mouseListeners_ != 0)
  32890. {
  32891. for (int i = mouseListeners_->size(); --i >= 0;)
  32892. {
  32893. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32894. if (checker.shouldBailOut())
  32895. return;
  32896. i = jmin (i, mouseListeners_->size());
  32897. }
  32898. }
  32899. Component* p = parentComponent_;
  32900. while (p != 0)
  32901. {
  32902. if (p->numDeepMouseListeners > 0)
  32903. {
  32904. BailOutChecker checker (this, p);
  32905. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32906. {
  32907. p->mouseListeners_->getUnchecked (i)->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32908. if (checker.shouldBailOut())
  32909. return;
  32910. i = jmin (i, p->numDeepMouseListeners);
  32911. }
  32912. }
  32913. p = p->parentComponent_;
  32914. }
  32915. }
  32916. }
  32917. void Component::sendFakeMouseMove() const
  32918. {
  32919. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32920. }
  32921. void Component::broughtToFront()
  32922. {
  32923. }
  32924. void Component::internalBroughtToFront()
  32925. {
  32926. if (! isValidComponent())
  32927. return;
  32928. if (flags.hasHeavyweightPeerFlag)
  32929. Desktop::getInstance().componentBroughtToFront (this);
  32930. BailOutChecker checker (this);
  32931. broughtToFront();
  32932. if (checker.shouldBailOut())
  32933. return;
  32934. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32935. if (checker.shouldBailOut())
  32936. return;
  32937. // When brought to the front and there's a modal component blocking this one,
  32938. // we need to bring the modal one to the front instead..
  32939. Component* const cm = getCurrentlyModalComponent();
  32940. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32941. bringModalComponentToFront();
  32942. }
  32943. void Component::focusGained (FocusChangeType)
  32944. {
  32945. // base class does nothing
  32946. }
  32947. void Component::internalFocusGain (const FocusChangeType cause)
  32948. {
  32949. SafePointer<Component> safePointer (this);
  32950. focusGained (cause);
  32951. if (safePointer != 0)
  32952. internalChildFocusChange (cause);
  32953. }
  32954. void Component::focusLost (FocusChangeType)
  32955. {
  32956. // base class does nothing
  32957. }
  32958. void Component::internalFocusLoss (const FocusChangeType cause)
  32959. {
  32960. SafePointer<Component> safePointer (this);
  32961. focusLost (focusChangedDirectly);
  32962. if (safePointer != 0)
  32963. internalChildFocusChange (cause);
  32964. }
  32965. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  32966. {
  32967. // base class does nothing
  32968. }
  32969. void Component::internalChildFocusChange (FocusChangeType cause)
  32970. {
  32971. const bool childIsNowFocused = hasKeyboardFocus (true);
  32972. if (flags.childCompFocusedFlag != childIsNowFocused)
  32973. {
  32974. flags.childCompFocusedFlag = childIsNowFocused;
  32975. SafePointer<Component> safePointer (this);
  32976. focusOfChildComponentChanged (cause);
  32977. if (safePointer == 0)
  32978. return;
  32979. }
  32980. if (parentComponent_ != 0)
  32981. parentComponent_->internalChildFocusChange (cause);
  32982. }
  32983. bool Component::isEnabled() const throw()
  32984. {
  32985. return (! flags.isDisabledFlag)
  32986. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  32987. }
  32988. void Component::setEnabled (const bool shouldBeEnabled)
  32989. {
  32990. if (flags.isDisabledFlag == shouldBeEnabled)
  32991. {
  32992. flags.isDisabledFlag = ! shouldBeEnabled;
  32993. // if any parent components are disabled, setting our flag won't make a difference,
  32994. // so no need to send a change message
  32995. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  32996. sendEnablementChangeMessage();
  32997. }
  32998. }
  32999. void Component::sendEnablementChangeMessage()
  33000. {
  33001. SafePointer<Component> safePointer (this);
  33002. enablementChanged();
  33003. if (safePointer == 0)
  33004. return;
  33005. for (int i = getNumChildComponents(); --i >= 0;)
  33006. {
  33007. Component* const c = getChildComponent (i);
  33008. if (c != 0)
  33009. {
  33010. c->sendEnablementChangeMessage();
  33011. if (safePointer == 0)
  33012. return;
  33013. }
  33014. }
  33015. }
  33016. void Component::enablementChanged()
  33017. {
  33018. }
  33019. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33020. {
  33021. flags.wantsFocusFlag = wantsFocus;
  33022. }
  33023. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33024. {
  33025. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33026. }
  33027. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33028. {
  33029. return ! flags.dontFocusOnMouseClickFlag;
  33030. }
  33031. bool Component::getWantsKeyboardFocus() const throw()
  33032. {
  33033. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33034. }
  33035. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33036. {
  33037. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33038. }
  33039. bool Component::isFocusContainer() const throw()
  33040. {
  33041. return flags.isFocusContainerFlag;
  33042. }
  33043. int Component::getExplicitFocusOrder() const
  33044. {
  33045. return properties ["_jexfo"];
  33046. }
  33047. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33048. {
  33049. properties.set ("_jexfo", newFocusOrderIndex);
  33050. }
  33051. KeyboardFocusTraverser* Component::createFocusTraverser()
  33052. {
  33053. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33054. return new KeyboardFocusTraverser();
  33055. return parentComponent_->createFocusTraverser();
  33056. }
  33057. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33058. {
  33059. // give the focus to this component
  33060. if (currentlyFocusedComponent != this)
  33061. {
  33062. JUCE_TRY
  33063. {
  33064. // get the focus onto our desktop window
  33065. ComponentPeer* const peer = getPeer();
  33066. if (peer != 0)
  33067. {
  33068. SafePointer<Component> safePointer (this);
  33069. peer->grabFocus();
  33070. if (peer->isFocused() && currentlyFocusedComponent != this)
  33071. {
  33072. Component* const componentLosingFocus = currentlyFocusedComponent;
  33073. currentlyFocusedComponent = this;
  33074. Desktop::getInstance().triggerFocusCallback();
  33075. // call this after setting currentlyFocusedComponent so that the one that's
  33076. // losing it has a chance to see where focus is going
  33077. if (componentLosingFocus->isValidComponent())
  33078. componentLosingFocus->internalFocusLoss (cause);
  33079. if (currentlyFocusedComponent == this)
  33080. {
  33081. focusGained (cause);
  33082. if (safePointer != 0)
  33083. internalChildFocusChange (cause);
  33084. }
  33085. }
  33086. }
  33087. }
  33088. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33089. catch (const std::exception& e)
  33090. {
  33091. currentlyFocusedComponent = 0;
  33092. Desktop::getInstance().triggerFocusCallback();
  33093. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33094. }
  33095. catch (...)
  33096. {
  33097. currentlyFocusedComponent = 0;
  33098. Desktop::getInstance().triggerFocusCallback();
  33099. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33100. }
  33101. #endif
  33102. }
  33103. }
  33104. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33105. {
  33106. if (isShowing())
  33107. {
  33108. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33109. {
  33110. takeKeyboardFocus (cause);
  33111. }
  33112. else
  33113. {
  33114. if (isParentOf (currentlyFocusedComponent)
  33115. && currentlyFocusedComponent->isShowing())
  33116. {
  33117. // do nothing if the focused component is actually a child of ours..
  33118. }
  33119. else
  33120. {
  33121. // find the default child component..
  33122. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33123. if (traverser != 0)
  33124. {
  33125. Component* const defaultComp = traverser->getDefaultComponent (this);
  33126. traverser = 0;
  33127. if (defaultComp != 0)
  33128. {
  33129. defaultComp->grabFocusInternal (cause, false);
  33130. return;
  33131. }
  33132. }
  33133. if (canTryParent && parentComponent_ != 0)
  33134. {
  33135. // if no children want it and we're allowed to try our parent comp,
  33136. // then pass up to parent, which will try our siblings.
  33137. parentComponent_->grabFocusInternal (cause, true);
  33138. }
  33139. }
  33140. }
  33141. }
  33142. }
  33143. void Component::grabKeyboardFocus()
  33144. {
  33145. // if component methods are being called from threads other than the message
  33146. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33147. checkMessageManagerIsLocked
  33148. grabFocusInternal (focusChangedDirectly);
  33149. }
  33150. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33151. {
  33152. // if component methods are being called from threads other than the message
  33153. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33154. checkMessageManagerIsLocked
  33155. if (parentComponent_ != 0)
  33156. {
  33157. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33158. if (traverser != 0)
  33159. {
  33160. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33161. : traverser->getPreviousComponent (this);
  33162. traverser = 0;
  33163. if (nextComp != 0)
  33164. {
  33165. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33166. {
  33167. SafePointer<Component> nextCompPointer (nextComp);
  33168. internalModalInputAttempt();
  33169. if (nextCompPointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33170. return;
  33171. }
  33172. nextComp->grabFocusInternal (focusChangedByTabKey);
  33173. return;
  33174. }
  33175. }
  33176. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33177. }
  33178. }
  33179. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33180. {
  33181. return (currentlyFocusedComponent == this)
  33182. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33183. }
  33184. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33185. {
  33186. return currentlyFocusedComponent;
  33187. }
  33188. void Component::giveAwayFocus()
  33189. {
  33190. // use a copy so we can clear the value before the call
  33191. Component* const componentLosingFocus = currentlyFocusedComponent;
  33192. currentlyFocusedComponent = 0;
  33193. Desktop::getInstance().triggerFocusCallback();
  33194. if (componentLosingFocus->isValidComponent())
  33195. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33196. }
  33197. bool Component::isMouseOver() const throw()
  33198. {
  33199. return flags.mouseOverFlag;
  33200. }
  33201. bool Component::isMouseButtonDown() const throw()
  33202. {
  33203. return flags.draggingFlag;
  33204. }
  33205. bool Component::isMouseOverOrDragging() const throw()
  33206. {
  33207. return flags.mouseOverFlag || flags.draggingFlag;
  33208. }
  33209. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33210. {
  33211. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33212. }
  33213. const Point<int> Component::getMouseXYRelative() const
  33214. {
  33215. return globalPositionToRelative (Desktop::getMousePosition());
  33216. }
  33217. const Rectangle<int> Component::getParentMonitorArea() const
  33218. {
  33219. return Desktop::getInstance()
  33220. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33221. getHeight() / 2)));
  33222. }
  33223. void Component::addKeyListener (KeyListener* const newListener)
  33224. {
  33225. if (keyListeners_ == 0)
  33226. keyListeners_ = new VoidArray();
  33227. keyListeners_->addIfNotAlreadyThere (newListener);
  33228. }
  33229. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33230. {
  33231. if (keyListeners_ != 0)
  33232. keyListeners_->removeValue (listenerToRemove);
  33233. }
  33234. bool Component::keyPressed (const KeyPress&)
  33235. {
  33236. return false;
  33237. }
  33238. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33239. {
  33240. return false;
  33241. }
  33242. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33243. {
  33244. if (parentComponent_ != 0)
  33245. parentComponent_->modifierKeysChanged (modifiers);
  33246. }
  33247. void Component::internalModifierKeysChanged()
  33248. {
  33249. sendFakeMouseMove();
  33250. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33251. }
  33252. ComponentPeer* Component::getPeer() const
  33253. {
  33254. if (flags.hasHeavyweightPeerFlag)
  33255. return ComponentPeer::getPeerFor (this);
  33256. else if (parentComponent_ != 0)
  33257. return parentComponent_->getPeer();
  33258. else
  33259. return 0;
  33260. }
  33261. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33262. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33263. {
  33264. jassert (component1 != 0);
  33265. }
  33266. bool Component::BailOutChecker::shouldBailOut() const throw()
  33267. {
  33268. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33269. }
  33270. END_JUCE_NAMESPACE
  33271. /*** End of inlined file: juce_Component.cpp ***/
  33272. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33273. BEGIN_JUCE_NAMESPACE
  33274. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33275. void ComponentListener::componentBroughtToFront (Component&) {}
  33276. void ComponentListener::componentVisibilityChanged (Component&) {}
  33277. void ComponentListener::componentChildrenChanged (Component&) {}
  33278. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33279. void ComponentListener::componentNameChanged (Component&) {}
  33280. void ComponentListener::componentBeingDeleted (Component&) {}
  33281. END_JUCE_NAMESPACE
  33282. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33283. /*** Start of inlined file: juce_Desktop.cpp ***/
  33284. BEGIN_JUCE_NAMESPACE
  33285. Desktop::Desktop()
  33286. : mouseClickCounter (0),
  33287. kioskModeComponent (0)
  33288. {
  33289. createMouseInputSources();
  33290. refreshMonitorSizes();
  33291. }
  33292. Desktop::~Desktop()
  33293. {
  33294. jassert (instance == this);
  33295. instance = 0;
  33296. // doh! If you don't delete all your windows before exiting, you're going to
  33297. // be leaking memory!
  33298. jassert (desktopComponents.size() == 0);
  33299. }
  33300. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33301. {
  33302. if (instance == 0)
  33303. instance = new Desktop();
  33304. return *instance;
  33305. }
  33306. Desktop* Desktop::instance = 0;
  33307. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33308. const bool clipToWorkArea);
  33309. void Desktop::refreshMonitorSizes()
  33310. {
  33311. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33312. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33313. monitorCoordsClipped.clear();
  33314. monitorCoordsUnclipped.clear();
  33315. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33316. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33317. jassert (monitorCoordsClipped.size() > 0
  33318. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33319. if (oldClipped != monitorCoordsClipped
  33320. || oldUnclipped != monitorCoordsUnclipped)
  33321. {
  33322. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33323. {
  33324. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33325. if (p != 0)
  33326. p->handleScreenSizeChange();
  33327. }
  33328. }
  33329. }
  33330. int Desktop::getNumDisplayMonitors() const throw()
  33331. {
  33332. return monitorCoordsClipped.size();
  33333. }
  33334. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33335. {
  33336. return clippedToWorkArea ? monitorCoordsClipped [index]
  33337. : monitorCoordsUnclipped [index];
  33338. }
  33339. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33340. {
  33341. RectangleList rl;
  33342. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33343. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33344. return rl;
  33345. }
  33346. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33347. {
  33348. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33349. }
  33350. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33351. {
  33352. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33353. double bestDistance = 1.0e10;
  33354. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33355. {
  33356. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33357. if (rect.contains (position))
  33358. return rect;
  33359. const double distance = rect.getCentre().getDistanceFrom (position);
  33360. if (distance < bestDistance)
  33361. {
  33362. bestDistance = distance;
  33363. best = rect;
  33364. }
  33365. }
  33366. return best;
  33367. }
  33368. int Desktop::getNumComponents() const throw()
  33369. {
  33370. return desktopComponents.size();
  33371. }
  33372. Component* Desktop::getComponent (const int index) const throw()
  33373. {
  33374. return desktopComponents [index];
  33375. }
  33376. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33377. {
  33378. for (int i = desktopComponents.size(); --i >= 0;)
  33379. {
  33380. Component* const c = desktopComponents.getUnchecked(i);
  33381. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33382. if (c->contains (relative.getX(), relative.getY()))
  33383. return c->getComponentAt (relative.getX(), relative.getY());
  33384. }
  33385. return 0;
  33386. }
  33387. void Desktop::addDesktopComponent (Component* const c)
  33388. {
  33389. jassert (c != 0);
  33390. jassert (! desktopComponents.contains (c));
  33391. desktopComponents.addIfNotAlreadyThere (c);
  33392. }
  33393. void Desktop::removeDesktopComponent (Component* const c)
  33394. {
  33395. desktopComponents.removeValue (c);
  33396. }
  33397. void Desktop::componentBroughtToFront (Component* const c)
  33398. {
  33399. const int index = desktopComponents.indexOf (c);
  33400. jassert (index >= 0);
  33401. if (index >= 0)
  33402. {
  33403. int newIndex = -1;
  33404. if (! c->isAlwaysOnTop())
  33405. {
  33406. newIndex = desktopComponents.size();
  33407. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33408. --newIndex;
  33409. --newIndex;
  33410. }
  33411. desktopComponents.move (index, newIndex);
  33412. }
  33413. }
  33414. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33415. {
  33416. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33417. }
  33418. int Desktop::getMouseButtonClickCounter() throw()
  33419. {
  33420. return getInstance().mouseClickCounter;
  33421. }
  33422. void Desktop::incrementMouseClickCounter() throw()
  33423. {
  33424. ++mouseClickCounter;
  33425. }
  33426. int Desktop::getNumDraggingMouseSources() const throw()
  33427. {
  33428. int num = 0;
  33429. for (int i = mouseSources.size(); --i >= 0;)
  33430. if (mouseSources.getUnchecked(i)->isDragging())
  33431. ++num;
  33432. return num;
  33433. }
  33434. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33435. {
  33436. int num = 0;
  33437. for (int i = mouseSources.size(); --i >= 0;)
  33438. {
  33439. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33440. if (mi->isDragging())
  33441. {
  33442. if (index == num)
  33443. return mi;
  33444. ++num;
  33445. }
  33446. }
  33447. return 0;
  33448. }
  33449. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33450. {
  33451. focusListeners.add (listener);
  33452. }
  33453. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33454. {
  33455. focusListeners.remove (listener);
  33456. }
  33457. void Desktop::triggerFocusCallback()
  33458. {
  33459. triggerAsyncUpdate();
  33460. }
  33461. void Desktop::handleAsyncUpdate()
  33462. {
  33463. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33464. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33465. }
  33466. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33467. {
  33468. mouseListeners.add (listener);
  33469. resetTimer();
  33470. }
  33471. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33472. {
  33473. mouseListeners.remove (listener);
  33474. resetTimer();
  33475. }
  33476. void Desktop::timerCallback()
  33477. {
  33478. if (lastFakeMouseMove != getMousePosition())
  33479. sendMouseMove();
  33480. }
  33481. void Desktop::sendMouseMove()
  33482. {
  33483. if (! mouseListeners.isEmpty())
  33484. {
  33485. startTimer (20);
  33486. lastFakeMouseMove = getMousePosition();
  33487. Component* const target = findComponentAt (lastFakeMouseMove);
  33488. if (target != 0)
  33489. {
  33490. Component::BailOutChecker checker (target);
  33491. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33492. const Time now (Time::getCurrentTime());
  33493. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33494. target, now, pos, now, 0, false);
  33495. if (me.mods.isAnyMouseButtonDown())
  33496. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33497. else
  33498. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33499. }
  33500. }
  33501. }
  33502. void Desktop::resetTimer()
  33503. {
  33504. if (mouseListeners.size() == 0)
  33505. stopTimer();
  33506. else
  33507. startTimer (100);
  33508. lastFakeMouseMove = getMousePosition();
  33509. }
  33510. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33511. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33512. {
  33513. if (kioskModeComponent != componentToUse)
  33514. {
  33515. // agh! Don't delete a component without first stopping it being the kiosk comp
  33516. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33517. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33518. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33519. if (kioskModeComponent->isValidComponent())
  33520. {
  33521. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33522. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33523. }
  33524. kioskModeComponent = componentToUse;
  33525. if (kioskModeComponent != 0)
  33526. {
  33527. jassert (kioskModeComponent->isValidComponent());
  33528. // Only components that are already on the desktop can be put into kiosk mode!
  33529. jassert (kioskModeComponent->isOnDesktop());
  33530. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33531. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33532. }
  33533. }
  33534. }
  33535. END_JUCE_NAMESPACE
  33536. /*** End of inlined file: juce_Desktop.cpp ***/
  33537. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33538. BEGIN_JUCE_NAMESPACE
  33539. ArrowButton::ArrowButton (const String& name,
  33540. float arrowDirectionInRadians,
  33541. const Colour& arrowColour)
  33542. : Button (name),
  33543. colour (arrowColour)
  33544. {
  33545. path.lineTo (0.0f, 1.0f);
  33546. path.lineTo (1.0f, 0.5f);
  33547. path.closeSubPath();
  33548. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33549. 0.5f, 0.5f));
  33550. setComponentEffect (&shadow);
  33551. buttonStateChanged();
  33552. }
  33553. ArrowButton::~ArrowButton()
  33554. {
  33555. }
  33556. void ArrowButton::paintButton (Graphics& g,
  33557. bool /*isMouseOverButton*/,
  33558. bool /*isButtonDown*/)
  33559. {
  33560. g.setColour (colour);
  33561. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33562. (float) offset,
  33563. (float) (getWidth() - 3),
  33564. (float) (getHeight() - 3),
  33565. false));
  33566. }
  33567. void ArrowButton::buttonStateChanged()
  33568. {
  33569. offset = (isDown()) ? 1 : 0;
  33570. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33571. 0.3f, -1, 0);
  33572. }
  33573. END_JUCE_NAMESPACE
  33574. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33575. /*** Start of inlined file: juce_Button.cpp ***/
  33576. BEGIN_JUCE_NAMESPACE
  33577. class Button::RepeatTimer : public Timer
  33578. {
  33579. public:
  33580. RepeatTimer (Button& owner_) : owner (owner_) {}
  33581. void timerCallback() { owner.repeatTimerCallback(); }
  33582. juce_UseDebuggingNewOperator
  33583. private:
  33584. Button& owner;
  33585. RepeatTimer (const RepeatTimer&);
  33586. RepeatTimer& operator= (const RepeatTimer&);
  33587. };
  33588. Button::Button (const String& name)
  33589. : Component (name),
  33590. text (name),
  33591. buttonPressTime (0),
  33592. lastTimeCallbackTime (0),
  33593. commandManagerToUse (0),
  33594. autoRepeatDelay (-1),
  33595. autoRepeatSpeed (0),
  33596. autoRepeatMinimumDelay (-1),
  33597. radioGroupId (0),
  33598. commandID (0),
  33599. connectedEdgeFlags (0),
  33600. buttonState (buttonNormal),
  33601. lastToggleState (false),
  33602. clickTogglesState (false),
  33603. needsToRelease (false),
  33604. needsRepainting (false),
  33605. isKeyDown (false),
  33606. triggerOnMouseDown (false),
  33607. generateTooltip (false)
  33608. {
  33609. setWantsKeyboardFocus (true);
  33610. isOn.addListener (this);
  33611. }
  33612. Button::~Button()
  33613. {
  33614. isOn.removeListener (this);
  33615. if (commandManagerToUse != 0)
  33616. commandManagerToUse->removeListener (this);
  33617. repeatTimer = 0;
  33618. clearShortcuts();
  33619. }
  33620. void Button::setButtonText (const String& newText)
  33621. {
  33622. if (text != newText)
  33623. {
  33624. text = newText;
  33625. repaint();
  33626. }
  33627. }
  33628. void Button::setTooltip (const String& newTooltip)
  33629. {
  33630. SettableTooltipClient::setTooltip (newTooltip);
  33631. generateTooltip = false;
  33632. }
  33633. const String Button::getTooltip()
  33634. {
  33635. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33636. {
  33637. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33638. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33639. for (int i = 0; i < keyPresses.size(); ++i)
  33640. {
  33641. const String key (keyPresses.getReference(i).getTextDescription());
  33642. tt << " [";
  33643. if (key.length() == 1)
  33644. tt << TRANS("shortcut") << ": '" << key << "']";
  33645. else
  33646. tt << key << ']';
  33647. }
  33648. return tt;
  33649. }
  33650. return SettableTooltipClient::getTooltip();
  33651. }
  33652. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33653. {
  33654. if (connectedEdgeFlags != connectedEdgeFlags_)
  33655. {
  33656. connectedEdgeFlags = connectedEdgeFlags_;
  33657. repaint();
  33658. }
  33659. }
  33660. void Button::setToggleState (const bool shouldBeOn,
  33661. const bool sendChangeNotification)
  33662. {
  33663. if (shouldBeOn != lastToggleState)
  33664. {
  33665. isOn = shouldBeOn;
  33666. lastToggleState = shouldBeOn;
  33667. repaint();
  33668. if (sendChangeNotification)
  33669. {
  33670. Component::SafePointer<Component> deletionWatcher (this);
  33671. sendClickMessage (ModifierKeys());
  33672. if (deletionWatcher == 0)
  33673. return;
  33674. }
  33675. if (lastToggleState)
  33676. turnOffOtherButtonsInGroup (sendChangeNotification);
  33677. }
  33678. }
  33679. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33680. {
  33681. clickTogglesState = shouldToggle;
  33682. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33683. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33684. // it is that this button represents, and the button will update its state to reflect this
  33685. // in the applicationCommandListChanged() method.
  33686. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33687. }
  33688. bool Button::getClickingTogglesState() const throw()
  33689. {
  33690. return clickTogglesState;
  33691. }
  33692. void Button::valueChanged (Value& value)
  33693. {
  33694. if (value.refersToSameSourceAs (isOn))
  33695. setToggleState (isOn.getValue(), true);
  33696. }
  33697. void Button::setRadioGroupId (const int newGroupId)
  33698. {
  33699. if (radioGroupId != newGroupId)
  33700. {
  33701. radioGroupId = newGroupId;
  33702. if (lastToggleState)
  33703. turnOffOtherButtonsInGroup (true);
  33704. }
  33705. }
  33706. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33707. {
  33708. Component* const p = getParentComponent();
  33709. if (p != 0 && radioGroupId != 0)
  33710. {
  33711. Component::SafePointer<Component> deletionWatcher (this);
  33712. for (int i = p->getNumChildComponents(); --i >= 0;)
  33713. {
  33714. Component* const c = p->getChildComponent (i);
  33715. if (c != this)
  33716. {
  33717. Button* const b = dynamic_cast <Button*> (c);
  33718. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33719. {
  33720. b->setToggleState (false, sendChangeNotification);
  33721. if (deletionWatcher == 0)
  33722. return;
  33723. }
  33724. }
  33725. }
  33726. }
  33727. }
  33728. void Button::enablementChanged()
  33729. {
  33730. updateState (0);
  33731. repaint();
  33732. }
  33733. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33734. {
  33735. ButtonState state = buttonNormal;
  33736. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33737. {
  33738. Point<int> mousePos;
  33739. if (e == 0)
  33740. mousePos = getMouseXYRelative();
  33741. else
  33742. mousePos = e->getEventRelativeTo (this).getPosition();
  33743. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33744. const bool down = isMouseButtonDown();
  33745. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33746. state = buttonDown;
  33747. else if (over)
  33748. state = buttonOver;
  33749. }
  33750. setState (state);
  33751. return state;
  33752. }
  33753. void Button::setState (const ButtonState newState)
  33754. {
  33755. if (buttonState != newState)
  33756. {
  33757. buttonState = newState;
  33758. repaint();
  33759. if (buttonState == buttonDown)
  33760. {
  33761. buttonPressTime = Time::getApproximateMillisecondCounter();
  33762. lastTimeCallbackTime = buttonPressTime;
  33763. }
  33764. sendStateMessage();
  33765. }
  33766. }
  33767. bool Button::isDown() const throw()
  33768. {
  33769. return buttonState == buttonDown;
  33770. }
  33771. bool Button::isOver() const throw()
  33772. {
  33773. return buttonState != buttonNormal;
  33774. }
  33775. void Button::buttonStateChanged()
  33776. {
  33777. }
  33778. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33779. {
  33780. const uint32 now = Time::getApproximateMillisecondCounter();
  33781. return now > buttonPressTime ? now - buttonPressTime : 0;
  33782. }
  33783. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33784. {
  33785. triggerOnMouseDown = isTriggeredOnMouseDown;
  33786. }
  33787. void Button::clicked()
  33788. {
  33789. }
  33790. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33791. {
  33792. clicked();
  33793. }
  33794. static const int clickMessageId = 0x2f3f4f99;
  33795. void Button::triggerClick()
  33796. {
  33797. postCommandMessage (clickMessageId);
  33798. }
  33799. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33800. {
  33801. if (clickTogglesState)
  33802. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33803. sendClickMessage (modifiers);
  33804. }
  33805. void Button::flashButtonState()
  33806. {
  33807. if (isEnabled())
  33808. {
  33809. needsToRelease = true;
  33810. setState (buttonDown);
  33811. getRepeatTimer().startTimer (100);
  33812. }
  33813. }
  33814. void Button::handleCommandMessage (int commandId)
  33815. {
  33816. if (commandId == clickMessageId)
  33817. {
  33818. if (isEnabled())
  33819. {
  33820. flashButtonState();
  33821. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33822. }
  33823. }
  33824. else
  33825. {
  33826. Component::handleCommandMessage (commandId);
  33827. }
  33828. }
  33829. void Button::addButtonListener (ButtonListener* const newListener)
  33830. {
  33831. buttonListeners.add (newListener);
  33832. }
  33833. void Button::removeButtonListener (ButtonListener* const listener)
  33834. {
  33835. buttonListeners.remove (listener);
  33836. }
  33837. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33838. {
  33839. Component::BailOutChecker checker (this);
  33840. if (commandManagerToUse != 0 && commandID != 0)
  33841. {
  33842. ApplicationCommandTarget::InvocationInfo info (commandID);
  33843. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33844. info.originatingComponent = this;
  33845. commandManagerToUse->invoke (info, true);
  33846. }
  33847. clicked (modifiers);
  33848. if (! checker.shouldBailOut())
  33849. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33850. }
  33851. void Button::sendStateMessage()
  33852. {
  33853. Component::BailOutChecker checker (this);
  33854. buttonStateChanged();
  33855. if (! checker.shouldBailOut())
  33856. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33857. }
  33858. void Button::paint (Graphics& g)
  33859. {
  33860. if (needsToRelease && isEnabled())
  33861. {
  33862. needsToRelease = false;
  33863. needsRepainting = true;
  33864. }
  33865. paintButton (g, isOver(), isDown());
  33866. }
  33867. void Button::mouseEnter (const MouseEvent& e)
  33868. {
  33869. updateState (&e);
  33870. }
  33871. void Button::mouseExit (const MouseEvent& e)
  33872. {
  33873. updateState (&e);
  33874. }
  33875. void Button::mouseDown (const MouseEvent& e)
  33876. {
  33877. updateState (&e);
  33878. if (isDown())
  33879. {
  33880. if (autoRepeatDelay >= 0)
  33881. getRepeatTimer().startTimer (autoRepeatDelay);
  33882. if (triggerOnMouseDown)
  33883. internalClickCallback (e.mods);
  33884. }
  33885. }
  33886. void Button::mouseUp (const MouseEvent& e)
  33887. {
  33888. const bool wasDown = isDown();
  33889. updateState (&e);
  33890. if (wasDown && isOver() && ! triggerOnMouseDown)
  33891. internalClickCallback (e.mods);
  33892. }
  33893. void Button::mouseDrag (const MouseEvent& e)
  33894. {
  33895. const ButtonState oldState = buttonState;
  33896. updateState (&e);
  33897. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33898. getRepeatTimer().startTimer (autoRepeatSpeed);
  33899. }
  33900. void Button::focusGained (FocusChangeType)
  33901. {
  33902. updateState (0);
  33903. repaint();
  33904. }
  33905. void Button::focusLost (FocusChangeType)
  33906. {
  33907. updateState (0);
  33908. repaint();
  33909. }
  33910. void Button::setVisible (bool shouldBeVisible)
  33911. {
  33912. if (shouldBeVisible != isVisible())
  33913. {
  33914. Component::setVisible (shouldBeVisible);
  33915. if (! shouldBeVisible)
  33916. needsToRelease = false;
  33917. updateState (0);
  33918. }
  33919. else
  33920. {
  33921. Component::setVisible (shouldBeVisible);
  33922. }
  33923. }
  33924. void Button::parentHierarchyChanged()
  33925. {
  33926. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33927. if (newKeySource != keySource.getComponent())
  33928. {
  33929. if (keySource != 0)
  33930. keySource->removeKeyListener (this);
  33931. keySource = newKeySource;
  33932. if (keySource != 0)
  33933. keySource->addKeyListener (this);
  33934. }
  33935. }
  33936. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33937. const int commandID_,
  33938. const bool generateTooltip_)
  33939. {
  33940. commandID = commandID_;
  33941. generateTooltip = generateTooltip_;
  33942. if (commandManagerToUse != commandManagerToUse_)
  33943. {
  33944. if (commandManagerToUse != 0)
  33945. commandManagerToUse->removeListener (this);
  33946. commandManagerToUse = commandManagerToUse_;
  33947. if (commandManagerToUse != 0)
  33948. commandManagerToUse->addListener (this);
  33949. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33950. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33951. // it is that this button represents, and the button will update its state to reflect this
  33952. // in the applicationCommandListChanged() method.
  33953. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33954. }
  33955. if (commandManagerToUse != 0)
  33956. applicationCommandListChanged();
  33957. else
  33958. setEnabled (true);
  33959. }
  33960. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33961. {
  33962. if (info.commandID == commandID
  33963. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33964. {
  33965. flashButtonState();
  33966. }
  33967. }
  33968. void Button::applicationCommandListChanged()
  33969. {
  33970. if (commandManagerToUse != 0)
  33971. {
  33972. ApplicationCommandInfo info (0);
  33973. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  33974. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  33975. if (target != 0)
  33976. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  33977. }
  33978. }
  33979. void Button::addShortcut (const KeyPress& key)
  33980. {
  33981. if (key.isValid())
  33982. {
  33983. jassert (! isRegisteredForShortcut (key)); // already registered!
  33984. shortcuts.add (key);
  33985. parentHierarchyChanged();
  33986. }
  33987. }
  33988. void Button::clearShortcuts()
  33989. {
  33990. shortcuts.clear();
  33991. parentHierarchyChanged();
  33992. }
  33993. bool Button::isShortcutPressed() const
  33994. {
  33995. if (! isCurrentlyBlockedByAnotherModalComponent())
  33996. {
  33997. for (int i = shortcuts.size(); --i >= 0;)
  33998. if (shortcuts.getReference(i).isCurrentlyDown())
  33999. return true;
  34000. }
  34001. return false;
  34002. }
  34003. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34004. {
  34005. for (int i = shortcuts.size(); --i >= 0;)
  34006. if (key == shortcuts.getReference(i))
  34007. return true;
  34008. return false;
  34009. }
  34010. bool Button::keyStateChanged (const bool, Component*)
  34011. {
  34012. if (! isEnabled())
  34013. return false;
  34014. const bool wasDown = isKeyDown;
  34015. isKeyDown = isShortcutPressed();
  34016. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34017. getRepeatTimer().startTimer (autoRepeatDelay);
  34018. updateState (0);
  34019. if (isEnabled() && wasDown && ! isKeyDown)
  34020. {
  34021. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34022. // (return immediately - this button may now have been deleted)
  34023. return true;
  34024. }
  34025. return wasDown || isKeyDown;
  34026. }
  34027. bool Button::keyPressed (const KeyPress&, Component*)
  34028. {
  34029. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34030. return isShortcutPressed();
  34031. }
  34032. bool Button::keyPressed (const KeyPress& key)
  34033. {
  34034. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34035. {
  34036. triggerClick();
  34037. return true;
  34038. }
  34039. return false;
  34040. }
  34041. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34042. const int repeatMillisecs,
  34043. const int minimumDelayInMillisecs) throw()
  34044. {
  34045. autoRepeatDelay = initialDelayMillisecs;
  34046. autoRepeatSpeed = repeatMillisecs;
  34047. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34048. }
  34049. void Button::repeatTimerCallback()
  34050. {
  34051. if (needsRepainting)
  34052. {
  34053. getRepeatTimer().stopTimer();
  34054. updateState (0);
  34055. needsRepainting = false;
  34056. }
  34057. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34058. {
  34059. int repeatSpeed = autoRepeatSpeed;
  34060. if (autoRepeatMinimumDelay >= 0)
  34061. {
  34062. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34063. timeHeldDown *= timeHeldDown;
  34064. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34065. }
  34066. repeatSpeed = jmax (1, repeatSpeed);
  34067. getRepeatTimer().startTimer (repeatSpeed);
  34068. const uint32 now = Time::getApproximateMillisecondCounter();
  34069. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34070. lastTimeCallbackTime = now;
  34071. Component::SafePointer<Component> deletionWatcher (this);
  34072. for (int i = numTimesToCallback; --i >= 0;)
  34073. {
  34074. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34075. if (deletionWatcher == 0 || ! isDown())
  34076. return;
  34077. }
  34078. }
  34079. else if (! needsToRelease)
  34080. {
  34081. getRepeatTimer().stopTimer();
  34082. }
  34083. }
  34084. Button::RepeatTimer& Button::getRepeatTimer()
  34085. {
  34086. if (repeatTimer == 0)
  34087. repeatTimer = new RepeatTimer (*this);
  34088. return *repeatTimer;
  34089. }
  34090. END_JUCE_NAMESPACE
  34091. /*** End of inlined file: juce_Button.cpp ***/
  34092. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34093. BEGIN_JUCE_NAMESPACE
  34094. DrawableButton::DrawableButton (const String& name,
  34095. const DrawableButton::ButtonStyle buttonStyle)
  34096. : Button (name),
  34097. style (buttonStyle),
  34098. edgeIndent (3)
  34099. {
  34100. if (buttonStyle == ImageOnButtonBackground)
  34101. {
  34102. backgroundOff = Colour (0xffbbbbff);
  34103. backgroundOn = Colour (0xff3333ff);
  34104. }
  34105. else
  34106. {
  34107. backgroundOff = Colours::transparentBlack;
  34108. backgroundOn = Colour (0xaabbbbff);
  34109. }
  34110. }
  34111. DrawableButton::~DrawableButton()
  34112. {
  34113. deleteImages();
  34114. }
  34115. void DrawableButton::deleteImages()
  34116. {
  34117. }
  34118. void DrawableButton::setImages (const Drawable* normal,
  34119. const Drawable* over,
  34120. const Drawable* down,
  34121. const Drawable* disabled,
  34122. const Drawable* normalOn,
  34123. const Drawable* overOn,
  34124. const Drawable* downOn,
  34125. const Drawable* disabledOn)
  34126. {
  34127. deleteImages();
  34128. jassert (normal != 0); // you really need to give it at least a normal image..
  34129. if (normal != 0)
  34130. normalImage = normal->createCopy();
  34131. if (over != 0)
  34132. overImage = over->createCopy();
  34133. if (down != 0)
  34134. downImage = down->createCopy();
  34135. if (disabled != 0)
  34136. disabledImage = disabled->createCopy();
  34137. if (normalOn != 0)
  34138. normalImageOn = normalOn->createCopy();
  34139. if (overOn != 0)
  34140. overImageOn = overOn->createCopy();
  34141. if (downOn != 0)
  34142. downImageOn = downOn->createCopy();
  34143. if (disabledOn != 0)
  34144. disabledImageOn = disabledOn->createCopy();
  34145. repaint();
  34146. }
  34147. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34148. {
  34149. if (style != newStyle)
  34150. {
  34151. style = newStyle;
  34152. repaint();
  34153. }
  34154. }
  34155. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34156. const Colour& toggledOnColour)
  34157. {
  34158. if (backgroundOff != toggledOffColour
  34159. || backgroundOn != toggledOnColour)
  34160. {
  34161. backgroundOff = toggledOffColour;
  34162. backgroundOn = toggledOnColour;
  34163. repaint();
  34164. }
  34165. }
  34166. const Colour& DrawableButton::getBackgroundColour() const throw()
  34167. {
  34168. return getToggleState() ? backgroundOn
  34169. : backgroundOff;
  34170. }
  34171. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34172. {
  34173. edgeIndent = numPixelsIndent;
  34174. repaint();
  34175. }
  34176. void DrawableButton::paintButton (Graphics& g,
  34177. bool isMouseOverButton,
  34178. bool isButtonDown)
  34179. {
  34180. Rectangle<int> imageSpace;
  34181. if (style == ImageOnButtonBackground)
  34182. {
  34183. const int insetX = getWidth() / 4;
  34184. const int insetY = getHeight() / 4;
  34185. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34186. getLookAndFeel().drawButtonBackground (g, *this,
  34187. getBackgroundColour(),
  34188. isMouseOverButton,
  34189. isButtonDown);
  34190. }
  34191. else
  34192. {
  34193. g.fillAll (getBackgroundColour());
  34194. const int textH = (style == ImageAboveTextLabel)
  34195. ? jmin (16, proportionOfHeight (0.25f))
  34196. : 0;
  34197. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34198. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34199. imageSpace.setBounds (indentX, indentY,
  34200. getWidth() - indentX * 2,
  34201. getHeight() - indentY * 2 - textH);
  34202. if (textH > 0)
  34203. {
  34204. g.setFont ((float) textH);
  34205. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34206. g.drawFittedText (getButtonText(),
  34207. 2, getHeight() - textH - 1,
  34208. getWidth() - 4, textH,
  34209. Justification::centred, 1);
  34210. }
  34211. }
  34212. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34213. g.setOpacity (1.0f);
  34214. const Drawable* imageToDraw = 0;
  34215. if (isEnabled())
  34216. {
  34217. imageToDraw = getCurrentImage();
  34218. }
  34219. else
  34220. {
  34221. imageToDraw = getToggleState() ? disabledImageOn
  34222. : disabledImage;
  34223. if (imageToDraw == 0)
  34224. {
  34225. g.setOpacity (0.4f);
  34226. imageToDraw = getNormalImage();
  34227. }
  34228. }
  34229. if (imageToDraw != 0)
  34230. {
  34231. if (style == ImageRaw)
  34232. {
  34233. imageToDraw->draw (g, 1.0f);
  34234. }
  34235. else
  34236. {
  34237. imageToDraw->drawWithin (g,
  34238. imageSpace.getX(),
  34239. imageSpace.getY(),
  34240. imageSpace.getWidth(),
  34241. imageSpace.getHeight(),
  34242. RectanglePlacement::centred,
  34243. 1.0f);
  34244. }
  34245. }
  34246. }
  34247. const Drawable* DrawableButton::getCurrentImage() const throw()
  34248. {
  34249. if (isDown())
  34250. return getDownImage();
  34251. if (isOver())
  34252. return getOverImage();
  34253. return getNormalImage();
  34254. }
  34255. const Drawable* DrawableButton::getNormalImage() const throw()
  34256. {
  34257. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34258. : normalImage;
  34259. }
  34260. const Drawable* DrawableButton::getOverImage() const throw()
  34261. {
  34262. const Drawable* d = normalImage;
  34263. if (getToggleState())
  34264. {
  34265. if (overImageOn != 0)
  34266. d = overImageOn;
  34267. else if (normalImageOn != 0)
  34268. d = normalImageOn;
  34269. else if (overImage != 0)
  34270. d = overImage;
  34271. }
  34272. else
  34273. {
  34274. if (overImage != 0)
  34275. d = overImage;
  34276. }
  34277. return d;
  34278. }
  34279. const Drawable* DrawableButton::getDownImage() const throw()
  34280. {
  34281. const Drawable* d = normalImage;
  34282. if (getToggleState())
  34283. {
  34284. if (downImageOn != 0)
  34285. d = downImageOn;
  34286. else if (overImageOn != 0)
  34287. d = overImageOn;
  34288. else if (normalImageOn != 0)
  34289. d = normalImageOn;
  34290. else if (downImage != 0)
  34291. d = downImage;
  34292. else
  34293. d = getOverImage();
  34294. }
  34295. else
  34296. {
  34297. if (downImage != 0)
  34298. d = downImage;
  34299. else
  34300. d = getOverImage();
  34301. }
  34302. return d;
  34303. }
  34304. END_JUCE_NAMESPACE
  34305. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34306. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34307. BEGIN_JUCE_NAMESPACE
  34308. HyperlinkButton::HyperlinkButton (const String& linkText,
  34309. const URL& linkURL)
  34310. : Button (linkText),
  34311. url (linkURL),
  34312. font (14.0f, Font::underlined),
  34313. resizeFont (true),
  34314. justification (Justification::centred)
  34315. {
  34316. setMouseCursor (MouseCursor::PointingHandCursor);
  34317. setTooltip (linkURL.toString (false));
  34318. }
  34319. HyperlinkButton::~HyperlinkButton()
  34320. {
  34321. }
  34322. void HyperlinkButton::setFont (const Font& newFont,
  34323. const bool resizeToMatchComponentHeight,
  34324. const Justification& justificationType)
  34325. {
  34326. font = newFont;
  34327. resizeFont = resizeToMatchComponentHeight;
  34328. justification = justificationType;
  34329. repaint();
  34330. }
  34331. void HyperlinkButton::setURL (const URL& newURL) throw()
  34332. {
  34333. url = newURL;
  34334. setTooltip (newURL.toString (false));
  34335. }
  34336. const Font HyperlinkButton::getFontToUse() const
  34337. {
  34338. Font f (font);
  34339. if (resizeFont)
  34340. f.setHeight (getHeight() * 0.7f);
  34341. return f;
  34342. }
  34343. void HyperlinkButton::changeWidthToFitText()
  34344. {
  34345. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34346. }
  34347. void HyperlinkButton::colourChanged()
  34348. {
  34349. repaint();
  34350. }
  34351. void HyperlinkButton::clicked()
  34352. {
  34353. if (url.isWellFormed())
  34354. url.launchInDefaultBrowser();
  34355. }
  34356. void HyperlinkButton::paintButton (Graphics& g,
  34357. bool isMouseOverButton,
  34358. bool isButtonDown)
  34359. {
  34360. const Colour textColour (findColour (textColourId));
  34361. if (isEnabled())
  34362. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34363. : textColour);
  34364. else
  34365. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34366. g.setFont (getFontToUse());
  34367. g.drawText (getButtonText(),
  34368. 2, 0, getWidth() - 2, getHeight(),
  34369. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34370. true);
  34371. }
  34372. END_JUCE_NAMESPACE
  34373. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34374. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34375. BEGIN_JUCE_NAMESPACE
  34376. ImageButton::ImageButton (const String& text_)
  34377. : Button (text_),
  34378. scaleImageToFit (true),
  34379. preserveProportions (true),
  34380. alphaThreshold (0),
  34381. imageX (0),
  34382. imageY (0),
  34383. imageW (0),
  34384. imageH (0),
  34385. normalImage (0),
  34386. overImage (0),
  34387. downImage (0)
  34388. {
  34389. }
  34390. ImageButton::~ImageButton()
  34391. {
  34392. deleteImages();
  34393. }
  34394. void ImageButton::deleteImages()
  34395. {
  34396. ImageCache::releaseOrDelete (normalImage);
  34397. ImageCache::releaseOrDelete (overImage);
  34398. ImageCache::releaseOrDelete (downImage);
  34399. }
  34400. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34401. const bool rescaleImagesWhenButtonSizeChanges,
  34402. const bool preserveImageProportions,
  34403. Image* const normalImage_,
  34404. const float imageOpacityWhenNormal,
  34405. const Colour& overlayColourWhenNormal,
  34406. Image* const overImage_,
  34407. const float imageOpacityWhenOver,
  34408. const Colour& overlayColourWhenOver,
  34409. Image* const downImage_,
  34410. const float imageOpacityWhenDown,
  34411. const Colour& overlayColourWhenDown,
  34412. const float hitTestAlphaThreshold)
  34413. {
  34414. deleteImages();
  34415. normalImage = normalImage_;
  34416. overImage = overImage_;
  34417. downImage = downImage_;
  34418. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34419. {
  34420. imageW = normalImage->getWidth();
  34421. imageH = normalImage->getHeight();
  34422. setSize (imageW, imageH);
  34423. }
  34424. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34425. preserveProportions = preserveImageProportions;
  34426. normalOpacity = imageOpacityWhenNormal;
  34427. normalOverlay = overlayColourWhenNormal;
  34428. overOpacity = imageOpacityWhenOver;
  34429. overOverlay = overlayColourWhenOver;
  34430. downOpacity = imageOpacityWhenDown;
  34431. downOverlay = overlayColourWhenDown;
  34432. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34433. repaint();
  34434. }
  34435. Image* ImageButton::getCurrentImage() const
  34436. {
  34437. if (isDown() || getToggleState())
  34438. return getDownImage();
  34439. if (isOver())
  34440. return getOverImage();
  34441. return getNormalImage();
  34442. }
  34443. Image* ImageButton::getNormalImage() const throw()
  34444. {
  34445. return normalImage;
  34446. }
  34447. Image* ImageButton::getOverImage() const throw()
  34448. {
  34449. return (overImage != 0) ? overImage
  34450. : normalImage;
  34451. }
  34452. Image* ImageButton::getDownImage() const throw()
  34453. {
  34454. return (downImage != 0) ? downImage
  34455. : getOverImage();
  34456. }
  34457. void ImageButton::paintButton (Graphics& g,
  34458. bool isMouseOverButton,
  34459. bool isButtonDown)
  34460. {
  34461. if (! isEnabled())
  34462. {
  34463. isMouseOverButton = false;
  34464. isButtonDown = false;
  34465. }
  34466. Image* const im = getCurrentImage();
  34467. if (im != 0)
  34468. {
  34469. const int iw = im->getWidth();
  34470. const int ih = im->getHeight();
  34471. imageW = getWidth();
  34472. imageH = getHeight();
  34473. imageX = (imageW - iw) >> 1;
  34474. imageY = (imageH - ih) >> 1;
  34475. if (scaleImageToFit)
  34476. {
  34477. if (preserveProportions)
  34478. {
  34479. int newW, newH;
  34480. const float imRatio = ih / (float)iw;
  34481. const float destRatio = imageH / (float)imageW;
  34482. if (imRatio > destRatio)
  34483. {
  34484. newW = roundToInt (imageH / imRatio);
  34485. newH = imageH;
  34486. }
  34487. else
  34488. {
  34489. newW = imageW;
  34490. newH = roundToInt (imageW * imRatio);
  34491. }
  34492. imageX = (imageW - newW) / 2;
  34493. imageY = (imageH - newH) / 2;
  34494. imageW = newW;
  34495. imageH = newH;
  34496. }
  34497. else
  34498. {
  34499. imageX = 0;
  34500. imageY = 0;
  34501. }
  34502. }
  34503. if (! scaleImageToFit)
  34504. {
  34505. imageW = iw;
  34506. imageH = ih;
  34507. }
  34508. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34509. isButtonDown ? downOverlay
  34510. : (isMouseOverButton ? overOverlay
  34511. : normalOverlay),
  34512. isButtonDown ? downOpacity
  34513. : (isMouseOverButton ? overOpacity
  34514. : normalOpacity),
  34515. *this);
  34516. }
  34517. }
  34518. bool ImageButton::hitTest (int x, int y)
  34519. {
  34520. if (alphaThreshold == 0)
  34521. return true;
  34522. Image* const im = getCurrentImage();
  34523. return im == 0
  34524. || (imageW > 0 && imageH > 0
  34525. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34526. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34527. }
  34528. END_JUCE_NAMESPACE
  34529. /*** End of inlined file: juce_ImageButton.cpp ***/
  34530. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34531. BEGIN_JUCE_NAMESPACE
  34532. ShapeButton::ShapeButton (const String& text_,
  34533. const Colour& normalColour_,
  34534. const Colour& overColour_,
  34535. const Colour& downColour_)
  34536. : Button (text_),
  34537. normalColour (normalColour_),
  34538. overColour (overColour_),
  34539. downColour (downColour_),
  34540. maintainShapeProportions (false),
  34541. outlineWidth (0.0f)
  34542. {
  34543. }
  34544. ShapeButton::~ShapeButton()
  34545. {
  34546. }
  34547. void ShapeButton::setColours (const Colour& newNormalColour,
  34548. const Colour& newOverColour,
  34549. const Colour& newDownColour)
  34550. {
  34551. normalColour = newNormalColour;
  34552. overColour = newOverColour;
  34553. downColour = newDownColour;
  34554. }
  34555. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34556. const float newOutlineWidth)
  34557. {
  34558. outlineColour = newOutlineColour;
  34559. outlineWidth = newOutlineWidth;
  34560. }
  34561. void ShapeButton::setShape (const Path& newShape,
  34562. const bool resizeNowToFitThisShape,
  34563. const bool maintainShapeProportions_,
  34564. const bool hasShadow)
  34565. {
  34566. shape = newShape;
  34567. maintainShapeProportions = maintainShapeProportions_;
  34568. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34569. setComponentEffect ((hasShadow) ? &shadow : 0);
  34570. if (resizeNowToFitThisShape)
  34571. {
  34572. Rectangle<float> bounds (shape.getBounds());
  34573. if (hasShadow)
  34574. bounds.expand (4.0f, 4.0f);
  34575. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34576. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34577. 1 + (int) (bounds.getHeight() + outlineWidth));
  34578. }
  34579. }
  34580. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34581. {
  34582. if (! isEnabled())
  34583. {
  34584. isMouseOverButton = false;
  34585. isButtonDown = false;
  34586. }
  34587. g.setColour ((isButtonDown) ? downColour
  34588. : (isMouseOverButton) ? overColour
  34589. : normalColour);
  34590. int w = getWidth();
  34591. int h = getHeight();
  34592. if (getComponentEffect() != 0)
  34593. {
  34594. w -= 4;
  34595. h -= 4;
  34596. }
  34597. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34598. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34599. w - offset - outlineWidth,
  34600. h - offset - outlineWidth,
  34601. maintainShapeProportions));
  34602. g.fillPath (shape, trans);
  34603. if (outlineWidth > 0.0f)
  34604. {
  34605. g.setColour (outlineColour);
  34606. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34607. }
  34608. }
  34609. END_JUCE_NAMESPACE
  34610. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34611. /*** Start of inlined file: juce_TextButton.cpp ***/
  34612. BEGIN_JUCE_NAMESPACE
  34613. TextButton::TextButton (const String& name,
  34614. const String& toolTip)
  34615. : Button (name)
  34616. {
  34617. setTooltip (toolTip);
  34618. }
  34619. TextButton::~TextButton()
  34620. {
  34621. }
  34622. void TextButton::paintButton (Graphics& g,
  34623. bool isMouseOverButton,
  34624. bool isButtonDown)
  34625. {
  34626. getLookAndFeel().drawButtonBackground (g, *this,
  34627. findColour (getToggleState() ? buttonOnColourId
  34628. : buttonColourId),
  34629. isMouseOverButton,
  34630. isButtonDown);
  34631. getLookAndFeel().drawButtonText (g, *this,
  34632. isMouseOverButton,
  34633. isButtonDown);
  34634. }
  34635. void TextButton::colourChanged()
  34636. {
  34637. repaint();
  34638. }
  34639. const Font TextButton::getFont()
  34640. {
  34641. return Font (jmin (15.0f, getHeight() * 0.6f));
  34642. }
  34643. void TextButton::changeWidthToFitText (const int newHeight)
  34644. {
  34645. if (newHeight >= 0)
  34646. setSize (jmax (1, getWidth()), newHeight);
  34647. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34648. getHeight());
  34649. }
  34650. END_JUCE_NAMESPACE
  34651. /*** End of inlined file: juce_TextButton.cpp ***/
  34652. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34653. BEGIN_JUCE_NAMESPACE
  34654. ToggleButton::ToggleButton (const String& buttonText)
  34655. : Button (buttonText)
  34656. {
  34657. setClickingTogglesState (true);
  34658. }
  34659. ToggleButton::~ToggleButton()
  34660. {
  34661. }
  34662. void ToggleButton::paintButton (Graphics& g,
  34663. bool isMouseOverButton,
  34664. bool isButtonDown)
  34665. {
  34666. getLookAndFeel().drawToggleButton (g, *this,
  34667. isMouseOverButton,
  34668. isButtonDown);
  34669. }
  34670. void ToggleButton::changeWidthToFitText()
  34671. {
  34672. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34673. }
  34674. void ToggleButton::colourChanged()
  34675. {
  34676. repaint();
  34677. }
  34678. END_JUCE_NAMESPACE
  34679. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34680. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34681. BEGIN_JUCE_NAMESPACE
  34682. ToolbarButton::ToolbarButton (const int itemId_,
  34683. const String& buttonText,
  34684. Drawable* const normalImage_,
  34685. Drawable* const toggledOnImage_)
  34686. : ToolbarItemComponent (itemId_, buttonText, true),
  34687. normalImage (normalImage_),
  34688. toggledOnImage (toggledOnImage_)
  34689. {
  34690. }
  34691. ToolbarButton::~ToolbarButton()
  34692. {
  34693. }
  34694. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34695. bool /*isToolbarVertical*/,
  34696. int& preferredSize,
  34697. int& minSize, int& maxSize)
  34698. {
  34699. preferredSize = minSize = maxSize = toolbarDepth;
  34700. return true;
  34701. }
  34702. void ToolbarButton::paintButtonArea (Graphics& g,
  34703. int width, int height,
  34704. bool /*isMouseOver*/,
  34705. bool /*isMouseDown*/)
  34706. {
  34707. Drawable* d = normalImage;
  34708. if (getToggleState() && toggledOnImage != 0)
  34709. d = toggledOnImage;
  34710. if (! isEnabled())
  34711. {
  34712. Image im (Image::ARGB, width, height, true);
  34713. Graphics g2 (im);
  34714. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34715. im.desaturate();
  34716. g.drawImageAt (&im, 0, 0);
  34717. }
  34718. else
  34719. {
  34720. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34721. }
  34722. }
  34723. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34724. {
  34725. }
  34726. END_JUCE_NAMESPACE
  34727. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34728. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34729. BEGIN_JUCE_NAMESPACE
  34730. class CodeDocumentLine
  34731. {
  34732. public:
  34733. CodeDocumentLine (const juce_wchar* const line_,
  34734. const int lineLength_,
  34735. const int numNewLineChars,
  34736. const int lineStartInFile_)
  34737. : line (line_, lineLength_),
  34738. lineStartInFile (lineStartInFile_),
  34739. lineLength (lineLength_),
  34740. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34741. {
  34742. }
  34743. ~CodeDocumentLine()
  34744. {
  34745. }
  34746. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34747. {
  34748. const juce_wchar* const t = text;
  34749. int pos = 0;
  34750. while (t [pos] != 0)
  34751. {
  34752. const int startOfLine = pos;
  34753. int numNewLineChars = 0;
  34754. while (t[pos] != 0)
  34755. {
  34756. if (t[pos] == '\r')
  34757. {
  34758. ++numNewLineChars;
  34759. ++pos;
  34760. if (t[pos] == '\n')
  34761. {
  34762. ++numNewLineChars;
  34763. ++pos;
  34764. }
  34765. break;
  34766. }
  34767. if (t[pos] == '\n')
  34768. {
  34769. ++numNewLineChars;
  34770. ++pos;
  34771. break;
  34772. }
  34773. ++pos;
  34774. }
  34775. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34776. numNewLineChars, startOfLine));
  34777. }
  34778. jassert (pos == text.length());
  34779. }
  34780. bool endsWithLineBreak() const throw()
  34781. {
  34782. return lineLengthWithoutNewLines != lineLength;
  34783. }
  34784. void updateLength() throw()
  34785. {
  34786. lineLengthWithoutNewLines = lineLength = line.length();
  34787. while (lineLengthWithoutNewLines > 0
  34788. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34789. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34790. {
  34791. --lineLengthWithoutNewLines;
  34792. }
  34793. }
  34794. String line;
  34795. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34796. };
  34797. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34798. : document (document_),
  34799. currentLine (document_->lines[0]),
  34800. line (0),
  34801. position (0)
  34802. {
  34803. }
  34804. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34805. : document (other.document),
  34806. currentLine (other.currentLine),
  34807. line (other.line),
  34808. position (other.position)
  34809. {
  34810. }
  34811. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34812. {
  34813. document = other.document;
  34814. currentLine = other.currentLine;
  34815. line = other.line;
  34816. position = other.position;
  34817. return *this;
  34818. }
  34819. CodeDocument::Iterator::~Iterator() throw()
  34820. {
  34821. }
  34822. juce_wchar CodeDocument::Iterator::nextChar()
  34823. {
  34824. if (currentLine == 0)
  34825. return 0;
  34826. jassert (currentLine == document->lines.getUnchecked (line));
  34827. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34828. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34829. {
  34830. ++line;
  34831. currentLine = document->lines [line];
  34832. }
  34833. return result;
  34834. }
  34835. void CodeDocument::Iterator::skip()
  34836. {
  34837. if (currentLine != 0)
  34838. {
  34839. jassert (currentLine == document->lines.getUnchecked (line));
  34840. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34841. {
  34842. ++line;
  34843. currentLine = document->lines [line];
  34844. }
  34845. }
  34846. }
  34847. void CodeDocument::Iterator::skipToEndOfLine()
  34848. {
  34849. if (currentLine != 0)
  34850. {
  34851. jassert (currentLine == document->lines.getUnchecked (line));
  34852. ++line;
  34853. currentLine = document->lines [line];
  34854. if (currentLine != 0)
  34855. position = currentLine->lineStartInFile;
  34856. else
  34857. position = document->getNumCharacters();
  34858. }
  34859. }
  34860. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34861. {
  34862. if (currentLine == 0)
  34863. return 0;
  34864. jassert (currentLine == document->lines.getUnchecked (line));
  34865. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34866. }
  34867. void CodeDocument::Iterator::skipWhitespace()
  34868. {
  34869. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34870. skip();
  34871. }
  34872. bool CodeDocument::Iterator::isEOF() const throw()
  34873. {
  34874. return currentLine == 0;
  34875. }
  34876. CodeDocument::Position::Position() throw()
  34877. : owner (0), characterPos (0), line (0),
  34878. indexInLine (0), positionMaintained (false)
  34879. {
  34880. }
  34881. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34882. const int line_, const int indexInLine_) throw()
  34883. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34884. characterPos (0), line (line_),
  34885. indexInLine (indexInLine_), positionMaintained (false)
  34886. {
  34887. setLineAndIndex (line_, indexInLine_);
  34888. }
  34889. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34890. const int characterPos_) throw()
  34891. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34892. positionMaintained (false)
  34893. {
  34894. setPosition (characterPos_);
  34895. }
  34896. CodeDocument::Position::Position (const Position& other) throw()
  34897. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34898. indexInLine (other.indexInLine), positionMaintained (false)
  34899. {
  34900. jassert (*this == other);
  34901. }
  34902. CodeDocument::Position::~Position() throw()
  34903. {
  34904. setPositionMaintained (false);
  34905. }
  34906. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34907. {
  34908. if (this != &other)
  34909. {
  34910. const bool wasPositionMaintained = positionMaintained;
  34911. if (owner != other.owner)
  34912. setPositionMaintained (false);
  34913. owner = other.owner;
  34914. line = other.line;
  34915. indexInLine = other.indexInLine;
  34916. characterPos = other.characterPos;
  34917. setPositionMaintained (wasPositionMaintained);
  34918. jassert (*this == other);
  34919. }
  34920. return *this;
  34921. }
  34922. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34923. {
  34924. jassert ((characterPos == other.characterPos)
  34925. == (line == other.line && indexInLine == other.indexInLine));
  34926. return characterPos == other.characterPos
  34927. && line == other.line
  34928. && indexInLine == other.indexInLine
  34929. && owner == other.owner;
  34930. }
  34931. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34932. {
  34933. return ! operator== (other);
  34934. }
  34935. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34936. {
  34937. jassert (owner != 0);
  34938. if (owner->lines.size() == 0)
  34939. {
  34940. line = 0;
  34941. indexInLine = 0;
  34942. characterPos = 0;
  34943. }
  34944. else
  34945. {
  34946. if (newLine >= owner->lines.size())
  34947. {
  34948. line = owner->lines.size() - 1;
  34949. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34950. jassert (l != 0);
  34951. indexInLine = l->lineLengthWithoutNewLines;
  34952. characterPos = l->lineStartInFile + indexInLine;
  34953. }
  34954. else
  34955. {
  34956. line = jmax (0, newLine);
  34957. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34958. jassert (l != 0);
  34959. if (l->lineLengthWithoutNewLines > 0)
  34960. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34961. else
  34962. indexInLine = 0;
  34963. characterPos = l->lineStartInFile + indexInLine;
  34964. }
  34965. }
  34966. }
  34967. void CodeDocument::Position::setPosition (const int newPosition) throw()
  34968. {
  34969. jassert (owner != 0);
  34970. line = 0;
  34971. indexInLine = 0;
  34972. characterPos = 0;
  34973. if (newPosition > 0)
  34974. {
  34975. int lineStart = 0;
  34976. int lineEnd = owner->lines.size();
  34977. for (;;)
  34978. {
  34979. if (lineEnd - lineStart < 4)
  34980. {
  34981. for (int i = lineStart; i < lineEnd; ++i)
  34982. {
  34983. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  34984. int index = newPosition - l->lineStartInFile;
  34985. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  34986. {
  34987. line = i;
  34988. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  34989. characterPos = l->lineStartInFile + indexInLine;
  34990. }
  34991. }
  34992. break;
  34993. }
  34994. else
  34995. {
  34996. const int midIndex = (lineStart + lineEnd + 1) / 2;
  34997. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  34998. if (newPosition >= mid->lineStartInFile)
  34999. lineStart = midIndex;
  35000. else
  35001. lineEnd = midIndex;
  35002. }
  35003. }
  35004. }
  35005. }
  35006. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35007. {
  35008. jassert (owner != 0);
  35009. if (characterDelta == 1)
  35010. {
  35011. setPosition (getPosition());
  35012. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35013. if (line < owner->lines.size())
  35014. {
  35015. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35016. if (indexInLine + characterDelta < l->lineLength
  35017. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35018. ++characterDelta;
  35019. }
  35020. }
  35021. setPosition (characterPos + characterDelta);
  35022. }
  35023. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35024. {
  35025. CodeDocument::Position p (*this);
  35026. p.moveBy (characterDelta);
  35027. return p;
  35028. }
  35029. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35030. {
  35031. CodeDocument::Position p (*this);
  35032. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35033. return p;
  35034. }
  35035. const juce_wchar CodeDocument::Position::getCharacter() const throw()
  35036. {
  35037. const CodeDocumentLine* const l = owner->lines [line];
  35038. return l == 0 ? 0 : l->line [getIndexInLine()];
  35039. }
  35040. const String CodeDocument::Position::getLineText() const throw()
  35041. {
  35042. const CodeDocumentLine* const l = owner->lines [line];
  35043. return l == 0 ? String::empty : l->line;
  35044. }
  35045. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35046. {
  35047. if (isMaintained != positionMaintained)
  35048. {
  35049. positionMaintained = isMaintained;
  35050. if (owner != 0)
  35051. {
  35052. if (isMaintained)
  35053. {
  35054. jassert (! owner->positionsToMaintain.contains (this));
  35055. owner->positionsToMaintain.add (this);
  35056. }
  35057. else
  35058. {
  35059. jassert (owner->positionsToMaintain.contains (this));
  35060. owner->positionsToMaintain.removeValue (this);
  35061. }
  35062. }
  35063. }
  35064. }
  35065. CodeDocument::CodeDocument()
  35066. : undoManager (std::numeric_limits<int>::max(), 10000),
  35067. currentActionIndex (0),
  35068. indexOfSavedState (-1),
  35069. maximumLineLength (-1),
  35070. newLineChars ("\r\n")
  35071. {
  35072. }
  35073. CodeDocument::~CodeDocument()
  35074. {
  35075. }
  35076. const String CodeDocument::getAllContent() const throw()
  35077. {
  35078. return getTextBetween (Position (this, 0),
  35079. Position (this, lines.size(), 0));
  35080. }
  35081. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35082. {
  35083. if (end.getPosition() <= start.getPosition())
  35084. return String::empty;
  35085. const int startLine = start.getLineNumber();
  35086. const int endLine = end.getLineNumber();
  35087. if (startLine == endLine)
  35088. {
  35089. CodeDocumentLine* const line = lines [startLine];
  35090. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35091. }
  35092. String result;
  35093. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35094. String::Concatenator concatenator (result);
  35095. const int maxLine = jmin (lines.size() - 1, endLine);
  35096. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35097. {
  35098. const CodeDocumentLine* line = lines.getUnchecked(i);
  35099. int len = line->lineLength;
  35100. if (i == startLine)
  35101. {
  35102. const int index = start.getIndexInLine();
  35103. concatenator.append (line->line.substring (index, len));
  35104. }
  35105. else if (i == endLine)
  35106. {
  35107. len = end.getIndexInLine();
  35108. concatenator.append (line->line.substring (0, len));
  35109. }
  35110. else
  35111. {
  35112. concatenator.append (line->line);
  35113. }
  35114. }
  35115. return result;
  35116. }
  35117. int CodeDocument::getNumCharacters() const throw()
  35118. {
  35119. const CodeDocumentLine* const lastLine = lines.getLast();
  35120. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35121. }
  35122. const String CodeDocument::getLine (const int lineIndex) const throw()
  35123. {
  35124. const CodeDocumentLine* const line = lines [lineIndex];
  35125. return (line == 0) ? String::empty : line->line;
  35126. }
  35127. int CodeDocument::getMaximumLineLength() throw()
  35128. {
  35129. if (maximumLineLength < 0)
  35130. {
  35131. maximumLineLength = 0;
  35132. for (int i = lines.size(); --i >= 0;)
  35133. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35134. }
  35135. return maximumLineLength;
  35136. }
  35137. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35138. {
  35139. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35140. }
  35141. void CodeDocument::insertText (const Position& position, const String& text)
  35142. {
  35143. insert (text, position.getPosition(), true);
  35144. }
  35145. void CodeDocument::replaceAllContent (const String& newContent)
  35146. {
  35147. remove (0, getNumCharacters(), true);
  35148. insert (newContent, 0, true);
  35149. }
  35150. bool CodeDocument::loadFromStream (InputStream& stream)
  35151. {
  35152. replaceAllContent (stream.readEntireStreamAsString());
  35153. setSavePoint();
  35154. clearUndoHistory();
  35155. return true;
  35156. }
  35157. bool CodeDocument::writeToStream (OutputStream& stream)
  35158. {
  35159. for (int i = 0; i < lines.size(); ++i)
  35160. {
  35161. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35162. const char* utf8 = temp.toUTF8();
  35163. if (! stream.write (utf8, (int) strlen (utf8)))
  35164. return false;
  35165. }
  35166. return true;
  35167. }
  35168. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35169. {
  35170. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35171. newLineChars = newLine;
  35172. }
  35173. void CodeDocument::newTransaction()
  35174. {
  35175. undoManager.beginNewTransaction (String::empty);
  35176. }
  35177. void CodeDocument::undo()
  35178. {
  35179. newTransaction();
  35180. undoManager.undo();
  35181. }
  35182. void CodeDocument::redo()
  35183. {
  35184. undoManager.redo();
  35185. }
  35186. void CodeDocument::clearUndoHistory()
  35187. {
  35188. undoManager.clearUndoHistory();
  35189. }
  35190. void CodeDocument::setSavePoint() throw()
  35191. {
  35192. indexOfSavedState = currentActionIndex;
  35193. }
  35194. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35195. {
  35196. return currentActionIndex != indexOfSavedState;
  35197. }
  35198. static int getCodeCharacterCategory (const juce_wchar character) throw()
  35199. {
  35200. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35201. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35202. }
  35203. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35204. {
  35205. Position p (position);
  35206. const int maxDistance = 256;
  35207. int i = 0;
  35208. while (i < maxDistance
  35209. && CharacterFunctions::isWhitespace (p.getCharacter())
  35210. && (i == 0 || (p.getCharacter() != '\n'
  35211. && p.getCharacter() != '\r')))
  35212. {
  35213. ++i;
  35214. p.moveBy (1);
  35215. }
  35216. if (i == 0)
  35217. {
  35218. const int type = getCodeCharacterCategory (p.getCharacter());
  35219. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35220. {
  35221. ++i;
  35222. p.moveBy (1);
  35223. }
  35224. while (i < maxDistance
  35225. && CharacterFunctions::isWhitespace (p.getCharacter())
  35226. && (i == 0 || (p.getCharacter() != '\n'
  35227. && p.getCharacter() != '\r')))
  35228. {
  35229. ++i;
  35230. p.moveBy (1);
  35231. }
  35232. }
  35233. return p;
  35234. }
  35235. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35236. {
  35237. Position p (position);
  35238. const int maxDistance = 256;
  35239. int i = 0;
  35240. bool stoppedAtLineStart = false;
  35241. while (i < maxDistance)
  35242. {
  35243. const juce_wchar c = p.movedBy (-1).getCharacter();
  35244. if (c == '\r' || c == '\n')
  35245. {
  35246. stoppedAtLineStart = true;
  35247. if (i > 0)
  35248. break;
  35249. }
  35250. if (! CharacterFunctions::isWhitespace (c))
  35251. break;
  35252. p.moveBy (-1);
  35253. ++i;
  35254. }
  35255. if (i < maxDistance && ! stoppedAtLineStart)
  35256. {
  35257. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35258. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35259. {
  35260. p.moveBy (-1);
  35261. ++i;
  35262. }
  35263. }
  35264. return p;
  35265. }
  35266. void CodeDocument::checkLastLineStatus()
  35267. {
  35268. while (lines.size() > 0
  35269. && lines.getLast()->lineLength == 0
  35270. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35271. {
  35272. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35273. lines.removeLast();
  35274. }
  35275. const CodeDocumentLine* const lastLine = lines.getLast();
  35276. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35277. {
  35278. // check that there's an empty line at the end if the preceding one ends in a newline..
  35279. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35280. }
  35281. }
  35282. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35283. {
  35284. listeners.add (listener);
  35285. }
  35286. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35287. {
  35288. listeners.remove (listener);
  35289. }
  35290. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35291. {
  35292. Position startPos (this, startLine, 0);
  35293. Position endPos (this, endLine, 0);
  35294. listeners.call (&Listener::codeDocumentChanged, startPos, endPos);
  35295. }
  35296. class CodeDocumentInsertAction : public UndoableAction
  35297. {
  35298. CodeDocument& owner;
  35299. const String text;
  35300. int insertPos;
  35301. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35302. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35303. public:
  35304. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35305. : owner (owner_),
  35306. text (text_),
  35307. insertPos (insertPos_)
  35308. {
  35309. }
  35310. ~CodeDocumentInsertAction() {}
  35311. bool perform()
  35312. {
  35313. owner.currentActionIndex++;
  35314. owner.insert (text, insertPos, false);
  35315. return true;
  35316. }
  35317. bool undo()
  35318. {
  35319. owner.currentActionIndex--;
  35320. owner.remove (insertPos, insertPos + text.length(), false);
  35321. return true;
  35322. }
  35323. int getSizeInUnits() { return text.length() + 32; }
  35324. };
  35325. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35326. {
  35327. if (text.isEmpty())
  35328. return;
  35329. if (undoable)
  35330. {
  35331. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35332. }
  35333. else
  35334. {
  35335. Position pos (this, insertPos);
  35336. const int firstAffectedLine = pos.getLineNumber();
  35337. int lastAffectedLine = firstAffectedLine + 1;
  35338. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35339. String textInsideOriginalLine (text);
  35340. if (firstLine != 0)
  35341. {
  35342. const int index = pos.getIndexInLine();
  35343. textInsideOriginalLine = firstLine->line.substring (0, index)
  35344. + textInsideOriginalLine
  35345. + firstLine->line.substring (index);
  35346. }
  35347. maximumLineLength = -1;
  35348. Array <CodeDocumentLine*> newLines;
  35349. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35350. jassert (newLines.size() > 0);
  35351. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35352. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35353. lines.set (firstAffectedLine, newFirstLine);
  35354. if (newLines.size() > 1)
  35355. {
  35356. for (int i = 1; i < newLines.size(); ++i)
  35357. {
  35358. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35359. lines.insert (firstAffectedLine + i, l);
  35360. }
  35361. lastAffectedLine = lines.size();
  35362. }
  35363. int i, lineStart = newFirstLine->lineStartInFile;
  35364. for (i = firstAffectedLine; i < lines.size(); ++i)
  35365. {
  35366. CodeDocumentLine* const l = lines.getUnchecked (i);
  35367. l->lineStartInFile = lineStart;
  35368. lineStart += l->lineLength;
  35369. }
  35370. checkLastLineStatus();
  35371. const int newTextLength = text.length();
  35372. for (i = 0; i < positionsToMaintain.size(); ++i)
  35373. {
  35374. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35375. if (p->getPosition() >= insertPos)
  35376. p->setPosition (p->getPosition() + newTextLength);
  35377. }
  35378. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35379. }
  35380. }
  35381. class CodeDocumentDeleteAction : public UndoableAction
  35382. {
  35383. CodeDocument& owner;
  35384. int startPos, endPos;
  35385. String removedText;
  35386. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35387. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35388. public:
  35389. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35390. : owner (owner_),
  35391. startPos (startPos_),
  35392. endPos (endPos_)
  35393. {
  35394. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35395. CodeDocument::Position (&owner, endPos));
  35396. }
  35397. ~CodeDocumentDeleteAction() {}
  35398. bool perform()
  35399. {
  35400. owner.currentActionIndex++;
  35401. owner.remove (startPos, endPos, false);
  35402. return true;
  35403. }
  35404. bool undo()
  35405. {
  35406. owner.currentActionIndex--;
  35407. owner.insert (removedText, startPos, false);
  35408. return true;
  35409. }
  35410. int getSizeInUnits() { return removedText.length() + 32; }
  35411. };
  35412. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35413. {
  35414. if (endPos <= startPos)
  35415. return;
  35416. if (undoable)
  35417. {
  35418. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35419. }
  35420. else
  35421. {
  35422. Position startPosition (this, startPos);
  35423. Position endPosition (this, endPos);
  35424. maximumLineLength = -1;
  35425. const int firstAffectedLine = startPosition.getLineNumber();
  35426. const int endLine = endPosition.getLineNumber();
  35427. int lastAffectedLine = firstAffectedLine + 1;
  35428. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35429. if (firstAffectedLine == endLine)
  35430. {
  35431. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35432. + firstLine->line.substring (endPosition.getIndexInLine());
  35433. firstLine->updateLength();
  35434. }
  35435. else
  35436. {
  35437. lastAffectedLine = lines.size();
  35438. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35439. jassert (lastLine != 0);
  35440. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35441. + lastLine->line.substring (endPosition.getIndexInLine());
  35442. firstLine->updateLength();
  35443. int numLinesToRemove = endLine - firstAffectedLine;
  35444. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35445. }
  35446. int i;
  35447. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35448. {
  35449. CodeDocumentLine* const l = lines.getUnchecked (i);
  35450. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35451. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35452. }
  35453. checkLastLineStatus();
  35454. const int totalChars = getNumCharacters();
  35455. for (i = 0; i < positionsToMaintain.size(); ++i)
  35456. {
  35457. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35458. if (p->getPosition() > startPosition.getPosition())
  35459. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35460. if (p->getPosition() > totalChars)
  35461. p->setPosition (totalChars);
  35462. }
  35463. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35464. }
  35465. }
  35466. END_JUCE_NAMESPACE
  35467. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35468. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35469. BEGIN_JUCE_NAMESPACE
  35470. class CodeEditorComponent::CaretComponent : public Component,
  35471. public Timer
  35472. {
  35473. public:
  35474. CaretComponent()
  35475. {
  35476. setAlwaysOnTop (true);
  35477. setInterceptsMouseClicks (false, false);
  35478. }
  35479. ~CaretComponent()
  35480. {
  35481. }
  35482. void paint (Graphics& g)
  35483. {
  35484. if (getParentComponent()->hasKeyboardFocus (true))
  35485. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35486. }
  35487. void timerCallback()
  35488. {
  35489. setVisible (! isVisible());
  35490. }
  35491. void updatePosition (CodeEditorComponent& owner)
  35492. {
  35493. startTimer (400);
  35494. setVisible (true);
  35495. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35496. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35497. }
  35498. private:
  35499. CaretComponent (const CaretComponent&);
  35500. CaretComponent& operator= (const CaretComponent&);
  35501. };
  35502. class CodeEditorComponent::CodeEditorLine
  35503. {
  35504. public:
  35505. CodeEditorLine() throw()
  35506. : highlightColumnStart (0), highlightColumnEnd (0)
  35507. {
  35508. }
  35509. ~CodeEditorLine() throw()
  35510. {
  35511. }
  35512. bool update (CodeDocument& document, int lineNum,
  35513. CodeDocument::Iterator& source,
  35514. CodeTokeniser* analyser, const int spacesPerTab,
  35515. const CodeDocument::Position& selectionStart,
  35516. const CodeDocument::Position& selectionEnd)
  35517. {
  35518. Array <SyntaxToken> newTokens;
  35519. newTokens.ensureStorageAllocated (8);
  35520. if (analyser == 0)
  35521. {
  35522. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35523. }
  35524. else if (lineNum < document.getNumLines())
  35525. {
  35526. const CodeDocument::Position pos (&document, lineNum, 0);
  35527. createTokens (pos.getPosition(), pos.getLineText(),
  35528. source, analyser, newTokens);
  35529. }
  35530. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35531. int newHighlightStart = 0;
  35532. int newHighlightEnd = 0;
  35533. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35534. {
  35535. const String line (document.getLine (lineNum));
  35536. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35537. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35538. line, spacesPerTab);
  35539. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35540. line, spacesPerTab);
  35541. }
  35542. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35543. {
  35544. highlightColumnStart = newHighlightStart;
  35545. highlightColumnEnd = newHighlightEnd;
  35546. }
  35547. else
  35548. {
  35549. if (tokens.size() == newTokens.size())
  35550. {
  35551. bool allTheSame = true;
  35552. for (int i = newTokens.size(); --i >= 0;)
  35553. {
  35554. if (tokens.getReference(i) != newTokens.getReference(i))
  35555. {
  35556. allTheSame = false;
  35557. break;
  35558. }
  35559. }
  35560. if (allTheSame)
  35561. return false;
  35562. }
  35563. }
  35564. tokens.swapWithArray (newTokens);
  35565. return true;
  35566. }
  35567. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35568. float x, const int y, const int baselineOffset, const int lineHeight,
  35569. const Colour& highlightColour) const throw()
  35570. {
  35571. if (highlightColumnStart < highlightColumnEnd)
  35572. {
  35573. g.setColour (highlightColour);
  35574. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35575. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35576. }
  35577. int lastType = std::numeric_limits<int>::min();
  35578. for (int i = 0; i < tokens.size(); ++i)
  35579. {
  35580. SyntaxToken& token = tokens.getReference(i);
  35581. if (lastType != token.tokenType)
  35582. {
  35583. lastType = token.tokenType;
  35584. g.setColour (owner.getColourForTokenType (lastType));
  35585. }
  35586. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35587. if (i < tokens.size() - 1)
  35588. {
  35589. if (token.width < 0)
  35590. token.width = font.getStringWidthFloat (token.text);
  35591. x += token.width;
  35592. }
  35593. }
  35594. }
  35595. private:
  35596. struct SyntaxToken
  35597. {
  35598. String text;
  35599. int tokenType;
  35600. float width;
  35601. SyntaxToken (const String& text_, const int type) throw()
  35602. : text (text_), tokenType (type), width (-1.0f)
  35603. {
  35604. }
  35605. bool operator!= (const SyntaxToken& other) const throw()
  35606. {
  35607. return text != other.text || tokenType != other.tokenType;
  35608. }
  35609. };
  35610. Array <SyntaxToken> tokens;
  35611. int highlightColumnStart, highlightColumnEnd;
  35612. static void createTokens (int startPosition, const String& lineText,
  35613. CodeDocument::Iterator& source,
  35614. CodeTokeniser* analyser,
  35615. Array <SyntaxToken>& newTokens)
  35616. {
  35617. CodeDocument::Iterator lastIterator (source);
  35618. const int lineLength = lineText.length();
  35619. for (;;)
  35620. {
  35621. int tokenType = analyser->readNextToken (source);
  35622. int tokenStart = lastIterator.getPosition();
  35623. int tokenEnd = source.getPosition();
  35624. if (tokenEnd <= tokenStart)
  35625. break;
  35626. tokenEnd -= startPosition;
  35627. if (tokenEnd > 0)
  35628. {
  35629. tokenStart -= startPosition;
  35630. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35631. tokenType));
  35632. if (tokenEnd >= lineLength)
  35633. break;
  35634. }
  35635. lastIterator = source;
  35636. }
  35637. source = lastIterator;
  35638. }
  35639. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35640. {
  35641. int x = 0;
  35642. for (int i = 0; i < tokens.size(); ++i)
  35643. {
  35644. SyntaxToken& t = tokens.getReference(i);
  35645. for (;;)
  35646. {
  35647. int tabPos = t.text.indexOfChar ('\t');
  35648. if (tabPos < 0)
  35649. break;
  35650. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35651. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35652. }
  35653. x += t.text.length();
  35654. }
  35655. }
  35656. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35657. {
  35658. jassert (index <= line.length());
  35659. int col = 0;
  35660. for (int i = 0; i < index; ++i)
  35661. {
  35662. if (line[i] != '\t')
  35663. ++col;
  35664. else
  35665. col += spacesPerTab - (col % spacesPerTab);
  35666. }
  35667. return col;
  35668. }
  35669. };
  35670. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35671. CodeTokeniser* const codeTokeniser_)
  35672. : document (document_),
  35673. firstLineOnScreen (0),
  35674. gutter (5),
  35675. spacesPerTab (4),
  35676. lineHeight (0),
  35677. linesOnScreen (0),
  35678. columnsOnScreen (0),
  35679. scrollbarThickness (16),
  35680. columnToTryToMaintain (-1),
  35681. useSpacesForTabs (false),
  35682. xOffset (0),
  35683. codeTokeniser (codeTokeniser_)
  35684. {
  35685. caretPos = CodeDocument::Position (&document_, 0, 0);
  35686. caretPos.setPositionMaintained (true);
  35687. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35688. selectionStart.setPositionMaintained (true);
  35689. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35690. selectionEnd.setPositionMaintained (true);
  35691. setOpaque (true);
  35692. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35693. setWantsKeyboardFocus (true);
  35694. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35695. verticalScrollBar->setSingleStepSize (1.0);
  35696. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35697. horizontalScrollBar->setSingleStepSize (1.0);
  35698. addAndMakeVisible (caret = new CaretComponent());
  35699. Font f (12.0f);
  35700. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35701. setFont (f);
  35702. resetToDefaultColours();
  35703. verticalScrollBar->addListener (this);
  35704. horizontalScrollBar->addListener (this);
  35705. document.addListener (this);
  35706. }
  35707. CodeEditorComponent::~CodeEditorComponent()
  35708. {
  35709. document.removeListener (this);
  35710. deleteAllChildren();
  35711. }
  35712. void CodeEditorComponent::loadContent (const String& newContent)
  35713. {
  35714. clearCachedIterators (0);
  35715. document.replaceAllContent (newContent);
  35716. document.clearUndoHistory();
  35717. document.setSavePoint();
  35718. caretPos.setPosition (0);
  35719. selectionStart.setPosition (0);
  35720. selectionEnd.setPosition (0);
  35721. scrollToLine (0);
  35722. }
  35723. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35724. const CodeDocument::Position& affectedTextEnd)
  35725. {
  35726. clearCachedIterators (affectedTextStart.getLineNumber());
  35727. triggerAsyncUpdate();
  35728. caret->updatePosition (*this);
  35729. columnToTryToMaintain = -1;
  35730. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35731. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35732. deselectAll();
  35733. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35734. || caretPos.getPosition() < affectedTextStart.getPosition())
  35735. moveCaretTo (affectedTextStart, false);
  35736. updateScrollBars();
  35737. }
  35738. void CodeEditorComponent::resized()
  35739. {
  35740. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35741. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35742. lines.clear();
  35743. rebuildLineTokens();
  35744. caret->updatePosition (*this);
  35745. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35746. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35747. updateScrollBars();
  35748. }
  35749. void CodeEditorComponent::paint (Graphics& g)
  35750. {
  35751. handleUpdateNowIfNeeded();
  35752. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35753. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35754. g.setFont (font);
  35755. const int baselineOffset = (int) font.getAscent();
  35756. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35757. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35758. const Rectangle<int> clip (g.getClipBounds());
  35759. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35760. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35761. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35762. {
  35763. lines.getUnchecked(j)->draw (*this, g, font,
  35764. (float) (gutter - xOffset * charWidth),
  35765. lineHeight * j, baselineOffset, lineHeight,
  35766. highlightColour);
  35767. }
  35768. }
  35769. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35770. {
  35771. if (scrollbarThickness != thickness)
  35772. {
  35773. scrollbarThickness = thickness;
  35774. resized();
  35775. }
  35776. }
  35777. void CodeEditorComponent::handleAsyncUpdate()
  35778. {
  35779. rebuildLineTokens();
  35780. }
  35781. void CodeEditorComponent::rebuildLineTokens()
  35782. {
  35783. cancelPendingUpdate();
  35784. const int numNeeded = linesOnScreen + 1;
  35785. int minLineToRepaint = numNeeded;
  35786. int maxLineToRepaint = 0;
  35787. if (numNeeded != lines.size())
  35788. {
  35789. lines.clear();
  35790. for (int i = numNeeded; --i >= 0;)
  35791. lines.add (new CodeEditorLine());
  35792. minLineToRepaint = 0;
  35793. maxLineToRepaint = numNeeded;
  35794. }
  35795. jassert (numNeeded == lines.size());
  35796. CodeDocument::Iterator source (&document);
  35797. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35798. for (int i = 0; i < numNeeded; ++i)
  35799. {
  35800. CodeEditorLine* const line = lines.getUnchecked(i);
  35801. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35802. selectionStart, selectionEnd))
  35803. {
  35804. minLineToRepaint = jmin (minLineToRepaint, i);
  35805. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35806. }
  35807. }
  35808. if (minLineToRepaint <= maxLineToRepaint)
  35809. {
  35810. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35811. verticalScrollBar->getX() - gutter,
  35812. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35813. }
  35814. }
  35815. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35816. {
  35817. caretPos = newPos;
  35818. columnToTryToMaintain = -1;
  35819. if (highlighting)
  35820. {
  35821. if (dragType == notDragging)
  35822. {
  35823. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35824. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35825. dragType = draggingSelectionStart;
  35826. else
  35827. dragType = draggingSelectionEnd;
  35828. }
  35829. if (dragType == draggingSelectionStart)
  35830. {
  35831. selectionStart = caretPos;
  35832. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35833. {
  35834. const CodeDocument::Position temp (selectionStart);
  35835. selectionStart = selectionEnd;
  35836. selectionEnd = temp;
  35837. dragType = draggingSelectionEnd;
  35838. }
  35839. }
  35840. else
  35841. {
  35842. selectionEnd = caretPos;
  35843. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35844. {
  35845. const CodeDocument::Position temp (selectionStart);
  35846. selectionStart = selectionEnd;
  35847. selectionEnd = temp;
  35848. dragType = draggingSelectionStart;
  35849. }
  35850. }
  35851. triggerAsyncUpdate();
  35852. }
  35853. else
  35854. {
  35855. deselectAll();
  35856. }
  35857. caret->updatePosition (*this);
  35858. scrollToKeepCaretOnScreen();
  35859. updateScrollBars();
  35860. }
  35861. void CodeEditorComponent::deselectAll()
  35862. {
  35863. if (selectionStart != selectionEnd)
  35864. triggerAsyncUpdate();
  35865. selectionStart = caretPos;
  35866. selectionEnd = caretPos;
  35867. }
  35868. void CodeEditorComponent::updateScrollBars()
  35869. {
  35870. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35871. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35872. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35873. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35874. }
  35875. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35876. {
  35877. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35878. newFirstLineOnScreen);
  35879. if (newFirstLineOnScreen != firstLineOnScreen)
  35880. {
  35881. firstLineOnScreen = newFirstLineOnScreen;
  35882. caret->updatePosition (*this);
  35883. updateCachedIterators (firstLineOnScreen);
  35884. triggerAsyncUpdate();
  35885. }
  35886. }
  35887. void CodeEditorComponent::scrollToColumnInternal (double column)
  35888. {
  35889. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35890. if (xOffset != newOffset)
  35891. {
  35892. xOffset = newOffset;
  35893. caret->updatePosition (*this);
  35894. repaint();
  35895. }
  35896. }
  35897. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35898. {
  35899. scrollToLineInternal (newFirstLineOnScreen);
  35900. updateScrollBars();
  35901. }
  35902. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35903. {
  35904. scrollToColumnInternal (newFirstColumnOnScreen);
  35905. updateScrollBars();
  35906. }
  35907. void CodeEditorComponent::scrollBy (int deltaLines)
  35908. {
  35909. scrollToLine (firstLineOnScreen + deltaLines);
  35910. }
  35911. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35912. {
  35913. if (caretPos.getLineNumber() < firstLineOnScreen)
  35914. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35915. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35916. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35917. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35918. if (column >= xOffset + columnsOnScreen - 1)
  35919. scrollToColumn (column + 1 - columnsOnScreen);
  35920. else if (column < xOffset)
  35921. scrollToColumn (column);
  35922. }
  35923. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35924. {
  35925. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35926. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35927. roundToInt (charWidth),
  35928. lineHeight);
  35929. }
  35930. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35931. {
  35932. const int line = y / lineHeight + firstLineOnScreen;
  35933. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35934. const int index = columnToIndex (line, column);
  35935. return CodeDocument::Position (&document, line, index);
  35936. }
  35937. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35938. {
  35939. document.deleteSection (selectionStart, selectionEnd);
  35940. if (newText.isNotEmpty())
  35941. document.insertText (caretPos, newText);
  35942. scrollToKeepCaretOnScreen();
  35943. }
  35944. void CodeEditorComponent::insertTabAtCaret()
  35945. {
  35946. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35947. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35948. {
  35949. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35950. }
  35951. if (useSpacesForTabs)
  35952. {
  35953. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35954. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35955. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  35956. }
  35957. else
  35958. {
  35959. insertTextAtCaret ("\t");
  35960. }
  35961. }
  35962. void CodeEditorComponent::cut()
  35963. {
  35964. insertTextAtCaret (String::empty);
  35965. }
  35966. void CodeEditorComponent::copy()
  35967. {
  35968. newTransaction();
  35969. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  35970. if (selection.isNotEmpty())
  35971. SystemClipboard::copyTextToClipboard (selection);
  35972. }
  35973. void CodeEditorComponent::copyThenCut()
  35974. {
  35975. copy();
  35976. cut();
  35977. newTransaction();
  35978. }
  35979. void CodeEditorComponent::paste()
  35980. {
  35981. newTransaction();
  35982. const String clip (SystemClipboard::getTextFromClipboard());
  35983. if (clip.isNotEmpty())
  35984. insertTextAtCaret (clip);
  35985. newTransaction();
  35986. }
  35987. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  35988. {
  35989. newTransaction();
  35990. if (moveInWholeWordSteps)
  35991. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  35992. else
  35993. moveCaretTo (caretPos.movedBy (-1), selecting);
  35994. }
  35995. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  35996. {
  35997. newTransaction();
  35998. if (moveInWholeWordSteps)
  35999. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36000. else
  36001. moveCaretTo (caretPos.movedBy (1), selecting);
  36002. }
  36003. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36004. {
  36005. CodeDocument::Position pos (caretPos);
  36006. const int newLineNum = pos.getLineNumber() + delta;
  36007. if (columnToTryToMaintain < 0)
  36008. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36009. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36010. const int colToMaintain = columnToTryToMaintain;
  36011. moveCaretTo (pos, selecting);
  36012. columnToTryToMaintain = colToMaintain;
  36013. }
  36014. void CodeEditorComponent::cursorDown (const bool selecting)
  36015. {
  36016. newTransaction();
  36017. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36018. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36019. else
  36020. moveLineDelta (1, selecting);
  36021. }
  36022. void CodeEditorComponent::cursorUp (const bool selecting)
  36023. {
  36024. newTransaction();
  36025. if (caretPos.getLineNumber() == 0)
  36026. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36027. else
  36028. moveLineDelta (-1, selecting);
  36029. }
  36030. void CodeEditorComponent::pageDown (const bool selecting)
  36031. {
  36032. newTransaction();
  36033. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36034. moveLineDelta (linesOnScreen, selecting);
  36035. }
  36036. void CodeEditorComponent::pageUp (const bool selecting)
  36037. {
  36038. newTransaction();
  36039. scrollBy (-linesOnScreen);
  36040. moveLineDelta (-linesOnScreen, selecting);
  36041. }
  36042. void CodeEditorComponent::scrollUp()
  36043. {
  36044. newTransaction();
  36045. scrollBy (1);
  36046. if (caretPos.getLineNumber() < firstLineOnScreen)
  36047. moveLineDelta (1, false);
  36048. }
  36049. void CodeEditorComponent::scrollDown()
  36050. {
  36051. newTransaction();
  36052. scrollBy (-1);
  36053. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36054. moveLineDelta (-1, false);
  36055. }
  36056. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36057. {
  36058. newTransaction();
  36059. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36060. }
  36061. static int findFirstNonWhitespaceChar (const String& line) throw()
  36062. {
  36063. const int len = line.length();
  36064. for (int i = 0; i < len; ++i)
  36065. if (! CharacterFunctions::isWhitespace (line [i]))
  36066. return i;
  36067. return 0;
  36068. }
  36069. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36070. {
  36071. newTransaction();
  36072. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36073. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36074. index = 0;
  36075. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36076. }
  36077. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36078. {
  36079. newTransaction();
  36080. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36081. }
  36082. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36083. {
  36084. newTransaction();
  36085. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36086. }
  36087. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36088. {
  36089. if (moveInWholeWordSteps)
  36090. {
  36091. cut(); // in case something is already highlighted
  36092. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36093. }
  36094. else
  36095. {
  36096. if (selectionStart == selectionEnd)
  36097. selectionStart.moveBy (-1);
  36098. }
  36099. cut();
  36100. }
  36101. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36102. {
  36103. if (moveInWholeWordSteps)
  36104. {
  36105. cut(); // in case something is already highlighted
  36106. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36107. }
  36108. else
  36109. {
  36110. if (selectionStart == selectionEnd)
  36111. selectionEnd.moveBy (1);
  36112. else
  36113. newTransaction();
  36114. }
  36115. cut();
  36116. }
  36117. void CodeEditorComponent::selectAll()
  36118. {
  36119. newTransaction();
  36120. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36121. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36122. }
  36123. void CodeEditorComponent::undo()
  36124. {
  36125. document.undo();
  36126. scrollToKeepCaretOnScreen();
  36127. }
  36128. void CodeEditorComponent::redo()
  36129. {
  36130. document.redo();
  36131. scrollToKeepCaretOnScreen();
  36132. }
  36133. void CodeEditorComponent::newTransaction()
  36134. {
  36135. document.newTransaction();
  36136. startTimer (600);
  36137. }
  36138. void CodeEditorComponent::timerCallback()
  36139. {
  36140. newTransaction();
  36141. }
  36142. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36143. {
  36144. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36145. }
  36146. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36147. {
  36148. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36149. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36150. }
  36151. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36152. {
  36153. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36154. CodeDocument::Position (&document, range.getEnd()));
  36155. }
  36156. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36157. {
  36158. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36159. const bool shiftDown = key.getModifiers().isShiftDown();
  36160. if (key.isKeyCode (KeyPress::leftKey))
  36161. {
  36162. cursorLeft (moveInWholeWordSteps, shiftDown);
  36163. }
  36164. else if (key.isKeyCode (KeyPress::rightKey))
  36165. {
  36166. cursorRight (moveInWholeWordSteps, shiftDown);
  36167. }
  36168. else if (key.isKeyCode (KeyPress::upKey))
  36169. {
  36170. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36171. scrollDown();
  36172. #if JUCE_MAC
  36173. else if (key.getModifiers().isCommandDown())
  36174. goToStartOfDocument (shiftDown);
  36175. #endif
  36176. else
  36177. cursorUp (shiftDown);
  36178. }
  36179. else if (key.isKeyCode (KeyPress::downKey))
  36180. {
  36181. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36182. scrollUp();
  36183. #if JUCE_MAC
  36184. else if (key.getModifiers().isCommandDown())
  36185. goToEndOfDocument (shiftDown);
  36186. #endif
  36187. else
  36188. cursorDown (shiftDown);
  36189. }
  36190. else if (key.isKeyCode (KeyPress::pageDownKey))
  36191. {
  36192. pageDown (shiftDown);
  36193. }
  36194. else if (key.isKeyCode (KeyPress::pageUpKey))
  36195. {
  36196. pageUp (shiftDown);
  36197. }
  36198. else if (key.isKeyCode (KeyPress::homeKey))
  36199. {
  36200. if (moveInWholeWordSteps)
  36201. goToStartOfDocument (shiftDown);
  36202. else
  36203. goToStartOfLine (shiftDown);
  36204. }
  36205. else if (key.isKeyCode (KeyPress::endKey))
  36206. {
  36207. if (moveInWholeWordSteps)
  36208. goToEndOfDocument (shiftDown);
  36209. else
  36210. goToEndOfLine (shiftDown);
  36211. }
  36212. else if (key.isKeyCode (KeyPress::backspaceKey))
  36213. {
  36214. backspace (moveInWholeWordSteps);
  36215. }
  36216. else if (key.isKeyCode (KeyPress::deleteKey))
  36217. {
  36218. deleteForward (moveInWholeWordSteps);
  36219. }
  36220. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36221. {
  36222. copy();
  36223. }
  36224. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36225. {
  36226. copyThenCut();
  36227. }
  36228. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36229. {
  36230. paste();
  36231. }
  36232. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36233. {
  36234. undo();
  36235. }
  36236. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36237. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36238. {
  36239. redo();
  36240. }
  36241. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36242. {
  36243. selectAll();
  36244. }
  36245. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36246. {
  36247. insertTabAtCaret();
  36248. }
  36249. else if (key == KeyPress::returnKey)
  36250. {
  36251. newTransaction();
  36252. insertTextAtCaret (document.getNewLineCharacters());
  36253. }
  36254. else if (key.isKeyCode (KeyPress::escapeKey))
  36255. {
  36256. newTransaction();
  36257. }
  36258. else if (key.getTextCharacter() >= ' ')
  36259. {
  36260. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36261. }
  36262. else
  36263. {
  36264. return false;
  36265. }
  36266. return true;
  36267. }
  36268. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36269. {
  36270. newTransaction();
  36271. dragType = notDragging;
  36272. if (! e.mods.isPopupMenu())
  36273. {
  36274. beginDragAutoRepeat (100);
  36275. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36276. }
  36277. else
  36278. {
  36279. }
  36280. }
  36281. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36282. {
  36283. if (! e.mods.isPopupMenu())
  36284. moveCaretTo (getPositionAt (e.x, e.y), true);
  36285. }
  36286. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36287. {
  36288. newTransaction();
  36289. beginDragAutoRepeat (0);
  36290. dragType = notDragging;
  36291. }
  36292. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36293. {
  36294. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36295. CodeDocument::Position tokenEnd (tokenStart);
  36296. if (e.getNumberOfClicks() > 2)
  36297. {
  36298. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36299. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36300. }
  36301. else
  36302. {
  36303. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36304. tokenEnd.moveBy (1);
  36305. tokenStart = tokenEnd;
  36306. while (tokenStart.getIndexInLine() > 0
  36307. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36308. tokenStart.moveBy (-1);
  36309. }
  36310. moveCaretTo (tokenEnd, false);
  36311. moveCaretTo (tokenStart, true);
  36312. }
  36313. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36314. {
  36315. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36316. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36317. }
  36318. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36319. {
  36320. if (scrollBarThatHasMoved == verticalScrollBar)
  36321. scrollToLineInternal ((int) newRangeStart);
  36322. else
  36323. scrollToColumnInternal (newRangeStart);
  36324. }
  36325. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36326. {
  36327. useSpacesForTabs = insertSpaces;
  36328. if (spacesPerTab != numSpaces)
  36329. {
  36330. spacesPerTab = numSpaces;
  36331. triggerAsyncUpdate();
  36332. }
  36333. }
  36334. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36335. {
  36336. const String line (document.getLine (lineNum));
  36337. jassert (index <= line.length());
  36338. int col = 0;
  36339. for (int i = 0; i < index; ++i)
  36340. {
  36341. if (line[i] != '\t')
  36342. ++col;
  36343. else
  36344. col += getTabSize() - (col % getTabSize());
  36345. }
  36346. return col;
  36347. }
  36348. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36349. {
  36350. const String line (document.getLine (lineNum));
  36351. const int lineLength = line.length();
  36352. int i, col = 0;
  36353. for (i = 0; i < lineLength; ++i)
  36354. {
  36355. if (line[i] != '\t')
  36356. ++col;
  36357. else
  36358. col += getTabSize() - (col % getTabSize());
  36359. if (col > column)
  36360. break;
  36361. }
  36362. return i;
  36363. }
  36364. void CodeEditorComponent::setFont (const Font& newFont)
  36365. {
  36366. font = newFont;
  36367. charWidth = font.getStringWidthFloat ("0");
  36368. lineHeight = roundToInt (font.getHeight());
  36369. resized();
  36370. }
  36371. void CodeEditorComponent::resetToDefaultColours()
  36372. {
  36373. coloursForTokenCategories.clear();
  36374. if (codeTokeniser != 0)
  36375. {
  36376. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36377. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36378. }
  36379. }
  36380. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36381. {
  36382. jassert (tokenType < 256);
  36383. while (coloursForTokenCategories.size() < tokenType)
  36384. coloursForTokenCategories.add (Colours::black);
  36385. coloursForTokenCategories.set (tokenType, colour);
  36386. repaint();
  36387. }
  36388. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36389. {
  36390. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36391. return findColour (CodeEditorComponent::defaultTextColourId);
  36392. return coloursForTokenCategories.getReference (tokenType);
  36393. }
  36394. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36395. {
  36396. int i;
  36397. for (i = cachedIterators.size(); --i >= 0;)
  36398. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36399. break;
  36400. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36401. }
  36402. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36403. {
  36404. const int maxNumCachedPositions = 5000;
  36405. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36406. if (cachedIterators.size() == 0)
  36407. cachedIterators.add (new CodeDocument::Iterator (&document));
  36408. if (codeTokeniser == 0)
  36409. return;
  36410. for (;;)
  36411. {
  36412. CodeDocument::Iterator* last = cachedIterators.getLast();
  36413. if (last->getLine() >= maxLineNum)
  36414. break;
  36415. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36416. cachedIterators.add (t);
  36417. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36418. for (;;)
  36419. {
  36420. codeTokeniser->readNextToken (*t);
  36421. if (t->getLine() >= targetLine)
  36422. break;
  36423. if (t->isEOF())
  36424. return;
  36425. }
  36426. }
  36427. }
  36428. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36429. {
  36430. if (codeTokeniser == 0)
  36431. return;
  36432. for (int i = cachedIterators.size(); --i >= 0;)
  36433. {
  36434. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36435. if (t->getPosition() <= position)
  36436. {
  36437. source = *t;
  36438. break;
  36439. }
  36440. }
  36441. while (source.getPosition() < position)
  36442. {
  36443. const CodeDocument::Iterator original (source);
  36444. codeTokeniser->readNextToken (source);
  36445. if (source.getPosition() > position || source.isEOF())
  36446. {
  36447. source = original;
  36448. break;
  36449. }
  36450. }
  36451. }
  36452. END_JUCE_NAMESPACE
  36453. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36454. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36455. BEGIN_JUCE_NAMESPACE
  36456. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36457. {
  36458. }
  36459. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36460. {
  36461. }
  36462. namespace CppTokeniser
  36463. {
  36464. static bool isIdentifierStart (const juce_wchar c) throw()
  36465. {
  36466. return CharacterFunctions::isLetter (c)
  36467. || c == '_' || c == '@';
  36468. }
  36469. static bool isIdentifierBody (const juce_wchar c) throw()
  36470. {
  36471. return CharacterFunctions::isLetter (c)
  36472. || CharacterFunctions::isDigit (c)
  36473. || c == '_' || c == '@';
  36474. }
  36475. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36476. {
  36477. static const juce_wchar* keywords2Char[] =
  36478. { T("if"), T("do"), T("or"), 0 };
  36479. static const juce_wchar* keywords3Char[] =
  36480. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36481. static const juce_wchar* keywords4Char[] =
  36482. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36483. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36484. static const juce_wchar* keywords5Char[] =
  36485. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36486. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36487. static const juce_wchar* keywords6Char[] =
  36488. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36489. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36490. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36491. static const juce_wchar* keywordsOther[] =
  36492. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36493. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36494. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36495. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36496. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36497. int tokenLength = 0;
  36498. juce_wchar possibleIdentifier [19];
  36499. while (isIdentifierBody (source.peekNextChar()))
  36500. {
  36501. const juce_wchar c = source.nextChar();
  36502. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36503. possibleIdentifier [tokenLength] = c;
  36504. ++tokenLength;
  36505. }
  36506. if (tokenLength > 1 && tokenLength <= 16)
  36507. {
  36508. possibleIdentifier [tokenLength] = 0;
  36509. const juce_wchar** k;
  36510. switch (tokenLength)
  36511. {
  36512. case 2: k = keywords2Char; break;
  36513. case 3: k = keywords3Char; break;
  36514. case 4: k = keywords4Char; break;
  36515. case 5: k = keywords5Char; break;
  36516. case 6: k = keywords6Char; break;
  36517. default: k = keywordsOther; break;
  36518. }
  36519. int i = 0;
  36520. while (k[i] != 0)
  36521. {
  36522. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36523. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36524. ++i;
  36525. }
  36526. }
  36527. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36528. }
  36529. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36530. {
  36531. const juce_wchar c = source.peekNextChar();
  36532. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36533. source.skip();
  36534. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36535. return false;
  36536. return true;
  36537. }
  36538. static bool isHexDigit (const juce_wchar c) throw()
  36539. {
  36540. return (c >= '0' && c <= '9')
  36541. || (c >= 'a' && c <= 'f')
  36542. || (c >= 'A' && c <= 'F');
  36543. }
  36544. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36545. {
  36546. if (source.nextChar() != '0')
  36547. return false;
  36548. juce_wchar c = source.nextChar();
  36549. if (c != 'x' && c != 'X')
  36550. return false;
  36551. int numDigits = 0;
  36552. while (isHexDigit (source.peekNextChar()))
  36553. {
  36554. ++numDigits;
  36555. source.skip();
  36556. }
  36557. if (numDigits == 0)
  36558. return false;
  36559. return skipNumberSuffix (source);
  36560. }
  36561. static bool isOctalDigit (const juce_wchar c) throw()
  36562. {
  36563. return c >= '0' && c <= '7';
  36564. }
  36565. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36566. {
  36567. if (source.nextChar() != '0')
  36568. return false;
  36569. if (! isOctalDigit (source.nextChar()))
  36570. return false;
  36571. while (isOctalDigit (source.peekNextChar()))
  36572. source.skip();
  36573. return skipNumberSuffix (source);
  36574. }
  36575. static bool isDecimalDigit (const juce_wchar c) throw()
  36576. {
  36577. return c >= '0' && c <= '9';
  36578. }
  36579. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36580. {
  36581. int numChars = 0;
  36582. while (isDecimalDigit (source.peekNextChar()))
  36583. {
  36584. ++numChars;
  36585. source.skip();
  36586. }
  36587. if (numChars == 0)
  36588. return false;
  36589. return skipNumberSuffix (source);
  36590. }
  36591. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36592. {
  36593. int numDigits = 0;
  36594. while (isDecimalDigit (source.peekNextChar()))
  36595. {
  36596. source.skip();
  36597. ++numDigits;
  36598. }
  36599. const bool hasPoint = (source.peekNextChar() == '.');
  36600. if (hasPoint)
  36601. {
  36602. source.skip();
  36603. while (isDecimalDigit (source.peekNextChar()))
  36604. {
  36605. source.skip();
  36606. ++numDigits;
  36607. }
  36608. }
  36609. if (numDigits == 0)
  36610. return false;
  36611. juce_wchar c = source.peekNextChar();
  36612. const bool hasExponent = (c == 'e' || c == 'E');
  36613. if (hasExponent)
  36614. {
  36615. source.skip();
  36616. c = source.peekNextChar();
  36617. if (c == '+' || c == '-')
  36618. source.skip();
  36619. int numExpDigits = 0;
  36620. while (isDecimalDigit (source.peekNextChar()))
  36621. {
  36622. source.skip();
  36623. ++numExpDigits;
  36624. }
  36625. if (numExpDigits == 0)
  36626. return false;
  36627. }
  36628. c = source.peekNextChar();
  36629. if (c == 'f' || c == 'F')
  36630. source.skip();
  36631. else if (! (hasExponent || hasPoint))
  36632. return false;
  36633. return true;
  36634. }
  36635. static int parseNumber (CodeDocument::Iterator& source)
  36636. {
  36637. const CodeDocument::Iterator original (source);
  36638. if (parseFloatLiteral (source))
  36639. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36640. source = original;
  36641. if (parseHexLiteral (source))
  36642. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36643. source = original;
  36644. if (parseOctalLiteral (source))
  36645. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36646. source = original;
  36647. if (parseDecimalLiteral (source))
  36648. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36649. source = original;
  36650. source.skip();
  36651. return CPlusPlusCodeTokeniser::tokenType_error;
  36652. }
  36653. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36654. {
  36655. const juce_wchar quote = source.nextChar();
  36656. for (;;)
  36657. {
  36658. const juce_wchar c = source.nextChar();
  36659. if (c == quote || c == 0)
  36660. break;
  36661. if (c == '\\')
  36662. source.skip();
  36663. }
  36664. }
  36665. static void skipComment (CodeDocument::Iterator& source) throw()
  36666. {
  36667. bool lastWasStar = false;
  36668. for (;;)
  36669. {
  36670. const juce_wchar c = source.nextChar();
  36671. if (c == 0 || (c == '/' && lastWasStar))
  36672. break;
  36673. lastWasStar = (c == '*');
  36674. }
  36675. }
  36676. }
  36677. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36678. {
  36679. int result = tokenType_error;
  36680. source.skipWhitespace();
  36681. juce_wchar firstChar = source.peekNextChar();
  36682. switch (firstChar)
  36683. {
  36684. case 0:
  36685. source.skip();
  36686. break;
  36687. case '0':
  36688. case '1':
  36689. case '2':
  36690. case '3':
  36691. case '4':
  36692. case '5':
  36693. case '6':
  36694. case '7':
  36695. case '8':
  36696. case '9':
  36697. result = CppTokeniser::parseNumber (source);
  36698. break;
  36699. case '.':
  36700. result = CppTokeniser::parseNumber (source);
  36701. if (result == tokenType_error)
  36702. result = tokenType_punctuation;
  36703. break;
  36704. case ',':
  36705. case ';':
  36706. case ':':
  36707. source.skip();
  36708. result = tokenType_punctuation;
  36709. break;
  36710. case '(':
  36711. case ')':
  36712. case '{':
  36713. case '}':
  36714. case '[':
  36715. case ']':
  36716. source.skip();
  36717. result = tokenType_bracket;
  36718. break;
  36719. case '"':
  36720. case '\'':
  36721. CppTokeniser::skipQuotedString (source);
  36722. result = tokenType_stringLiteral;
  36723. break;
  36724. case '+':
  36725. result = tokenType_operator;
  36726. source.skip();
  36727. if (source.peekNextChar() == '+')
  36728. source.skip();
  36729. else if (source.peekNextChar() == '=')
  36730. source.skip();
  36731. break;
  36732. case '-':
  36733. source.skip();
  36734. result = CppTokeniser::parseNumber (source);
  36735. if (result == tokenType_error)
  36736. {
  36737. result = tokenType_operator;
  36738. if (source.peekNextChar() == '-')
  36739. source.skip();
  36740. else if (source.peekNextChar() == '=')
  36741. source.skip();
  36742. }
  36743. break;
  36744. case '*':
  36745. case '%':
  36746. case '=':
  36747. case '!':
  36748. result = tokenType_operator;
  36749. source.skip();
  36750. if (source.peekNextChar() == '=')
  36751. source.skip();
  36752. break;
  36753. case '/':
  36754. result = tokenType_operator;
  36755. source.skip();
  36756. if (source.peekNextChar() == '=')
  36757. {
  36758. source.skip();
  36759. }
  36760. else if (source.peekNextChar() == '/')
  36761. {
  36762. result = tokenType_comment;
  36763. source.skipToEndOfLine();
  36764. }
  36765. else if (source.peekNextChar() == '*')
  36766. {
  36767. source.skip();
  36768. result = tokenType_comment;
  36769. CppTokeniser::skipComment (source);
  36770. }
  36771. break;
  36772. case '?':
  36773. case '~':
  36774. source.skip();
  36775. result = tokenType_operator;
  36776. break;
  36777. case '<':
  36778. source.skip();
  36779. result = tokenType_operator;
  36780. if (source.peekNextChar() == '=')
  36781. {
  36782. source.skip();
  36783. }
  36784. else if (source.peekNextChar() == '<')
  36785. {
  36786. source.skip();
  36787. if (source.peekNextChar() == '=')
  36788. source.skip();
  36789. }
  36790. break;
  36791. case '>':
  36792. source.skip();
  36793. result = tokenType_operator;
  36794. if (source.peekNextChar() == '=')
  36795. {
  36796. source.skip();
  36797. }
  36798. else if (source.peekNextChar() == '<')
  36799. {
  36800. source.skip();
  36801. if (source.peekNextChar() == '=')
  36802. source.skip();
  36803. }
  36804. break;
  36805. case '|':
  36806. source.skip();
  36807. result = tokenType_operator;
  36808. if (source.peekNextChar() == '=')
  36809. {
  36810. source.skip();
  36811. }
  36812. else if (source.peekNextChar() == '|')
  36813. {
  36814. source.skip();
  36815. if (source.peekNextChar() == '=')
  36816. source.skip();
  36817. }
  36818. break;
  36819. case '&':
  36820. source.skip();
  36821. result = tokenType_operator;
  36822. if (source.peekNextChar() == '=')
  36823. {
  36824. source.skip();
  36825. }
  36826. else if (source.peekNextChar() == '&')
  36827. {
  36828. source.skip();
  36829. if (source.peekNextChar() == '=')
  36830. source.skip();
  36831. }
  36832. break;
  36833. case '^':
  36834. source.skip();
  36835. result = tokenType_operator;
  36836. if (source.peekNextChar() == '=')
  36837. {
  36838. source.skip();
  36839. }
  36840. else if (source.peekNextChar() == '^')
  36841. {
  36842. source.skip();
  36843. if (source.peekNextChar() == '=')
  36844. source.skip();
  36845. }
  36846. break;
  36847. case '#':
  36848. result = tokenType_preprocessor;
  36849. source.skipToEndOfLine();
  36850. break;
  36851. default:
  36852. if (CppTokeniser::isIdentifierStart (firstChar))
  36853. result = CppTokeniser::parseIdentifier (source);
  36854. else
  36855. source.skip();
  36856. break;
  36857. }
  36858. //jassert (result != tokenType_unknown);
  36859. return result;
  36860. }
  36861. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36862. {
  36863. StringArray s;
  36864. s.add ("Error");
  36865. s.add ("Comment");
  36866. s.add ("C++ keyword");
  36867. s.add ("Identifier");
  36868. s.add ("Integer literal");
  36869. s.add ("Float literal");
  36870. s.add ("String literal");
  36871. s.add ("Operator");
  36872. s.add ("Bracket");
  36873. s.add ("Punctuation");
  36874. s.add ("Preprocessor line");
  36875. return s;
  36876. }
  36877. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36878. {
  36879. const uint32 colours[] =
  36880. {
  36881. 0xffcc0000, // error
  36882. 0xff00aa00, // comment
  36883. 0xff0000cc, // keyword
  36884. 0xff000000, // identifier
  36885. 0xff880000, // int literal
  36886. 0xff885500, // float literal
  36887. 0xff990099, // string literal
  36888. 0xff225500, // operator
  36889. 0xff000055, // bracket
  36890. 0xff004400, // punctuation
  36891. 0xff660000 // preprocessor
  36892. };
  36893. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36894. return Colour (colours [tokenType]);
  36895. return Colours::black;
  36896. }
  36897. END_JUCE_NAMESPACE
  36898. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36899. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36900. BEGIN_JUCE_NAMESPACE
  36901. ComboBox::ComboBox (const String& name)
  36902. : Component (name),
  36903. lastCurrentId (0),
  36904. isButtonDown (false),
  36905. separatorPending (false),
  36906. menuActive (false),
  36907. label (0)
  36908. {
  36909. noChoicesMessage = TRANS("(no choices)");
  36910. setRepaintsOnMouseActivity (true);
  36911. lookAndFeelChanged();
  36912. currentId.addListener (this);
  36913. }
  36914. ComboBox::~ComboBox()
  36915. {
  36916. currentId.removeListener (this);
  36917. if (menuActive)
  36918. PopupMenu::dismissAllActiveMenus();
  36919. label = 0;
  36920. deleteAllChildren();
  36921. }
  36922. void ComboBox::setEditableText (const bool isEditable)
  36923. {
  36924. label->setEditable (isEditable, isEditable, false);
  36925. setWantsKeyboardFocus (! isEditable);
  36926. resized();
  36927. }
  36928. bool ComboBox::isTextEditable() const throw()
  36929. {
  36930. return label->isEditable();
  36931. }
  36932. void ComboBox::setJustificationType (const Justification& justification) throw()
  36933. {
  36934. label->setJustificationType (justification);
  36935. }
  36936. const Justification ComboBox::getJustificationType() const throw()
  36937. {
  36938. return label->getJustificationType();
  36939. }
  36940. void ComboBox::setTooltip (const String& newTooltip)
  36941. {
  36942. SettableTooltipClient::setTooltip (newTooltip);
  36943. label->setTooltip (newTooltip);
  36944. }
  36945. void ComboBox::addItem (const String& newItemText,
  36946. const int newItemId) throw()
  36947. {
  36948. // you can't add empty strings to the list..
  36949. jassert (newItemText.isNotEmpty());
  36950. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36951. jassert (newItemId != 0);
  36952. // you shouldn't use duplicate item IDs!
  36953. jassert (getItemForId (newItemId) == 0);
  36954. if (newItemText.isNotEmpty() && newItemId != 0)
  36955. {
  36956. if (separatorPending)
  36957. {
  36958. separatorPending = false;
  36959. ItemInfo* const item = new ItemInfo();
  36960. item->itemId = 0;
  36961. item->isEnabled = false;
  36962. item->isHeading = false;
  36963. items.add (item);
  36964. }
  36965. ItemInfo* const item = new ItemInfo();
  36966. item->name = newItemText;
  36967. item->itemId = newItemId;
  36968. item->isEnabled = true;
  36969. item->isHeading = false;
  36970. items.add (item);
  36971. }
  36972. }
  36973. void ComboBox::addSeparator() throw()
  36974. {
  36975. separatorPending = (items.size() > 0);
  36976. }
  36977. void ComboBox::addSectionHeading (const String& headingName) throw()
  36978. {
  36979. // you can't add empty strings to the list..
  36980. jassert (headingName.isNotEmpty());
  36981. if (headingName.isNotEmpty())
  36982. {
  36983. if (separatorPending)
  36984. {
  36985. separatorPending = false;
  36986. ItemInfo* const item = new ItemInfo();
  36987. item->itemId = 0;
  36988. item->isEnabled = false;
  36989. item->isHeading = false;
  36990. items.add (item);
  36991. }
  36992. ItemInfo* const item = new ItemInfo();
  36993. item->name = headingName;
  36994. item->itemId = 0;
  36995. item->isEnabled = true;
  36996. item->isHeading = true;
  36997. items.add (item);
  36998. }
  36999. }
  37000. void ComboBox::setItemEnabled (const int itemId,
  37001. const bool shouldBeEnabled) throw()
  37002. {
  37003. ItemInfo* const item = getItemForId (itemId);
  37004. if (item != 0)
  37005. item->isEnabled = shouldBeEnabled;
  37006. }
  37007. void ComboBox::changeItemText (const int itemId,
  37008. const String& newText) throw()
  37009. {
  37010. ItemInfo* const item = getItemForId (itemId);
  37011. jassert (item != 0);
  37012. if (item != 0)
  37013. item->name = newText;
  37014. }
  37015. void ComboBox::clear (const bool dontSendChangeMessage)
  37016. {
  37017. items.clear();
  37018. separatorPending = false;
  37019. if (! label->isEditable())
  37020. setSelectedItemIndex (-1, dontSendChangeMessage);
  37021. }
  37022. bool ComboBox::ItemInfo::isSeparator() const throw()
  37023. {
  37024. return name.isEmpty();
  37025. }
  37026. bool ComboBox::ItemInfo::isRealItem() const throw()
  37027. {
  37028. return ! (isHeading || name.isEmpty());
  37029. }
  37030. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37031. {
  37032. if (itemId != 0)
  37033. {
  37034. for (int i = items.size(); --i >= 0;)
  37035. if (items.getUnchecked(i)->itemId == itemId)
  37036. return items.getUnchecked(i);
  37037. }
  37038. return 0;
  37039. }
  37040. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37041. {
  37042. int n = 0;
  37043. for (int i = 0; i < items.size(); ++i)
  37044. {
  37045. ItemInfo* const item = items.getUnchecked(i);
  37046. if (item->isRealItem())
  37047. if (n++ == index)
  37048. return item;
  37049. }
  37050. return 0;
  37051. }
  37052. int ComboBox::getNumItems() const throw()
  37053. {
  37054. int n = 0;
  37055. for (int i = items.size(); --i >= 0;)
  37056. if (items.getUnchecked(i)->isRealItem())
  37057. ++n;
  37058. return n;
  37059. }
  37060. const String ComboBox::getItemText (const int index) const throw()
  37061. {
  37062. const ItemInfo* const item = getItemForIndex (index);
  37063. if (item != 0)
  37064. return item->name;
  37065. return String::empty;
  37066. }
  37067. int ComboBox::getItemId (const int index) const throw()
  37068. {
  37069. const ItemInfo* const item = getItemForIndex (index);
  37070. return (item != 0) ? item->itemId : 0;
  37071. }
  37072. int ComboBox::indexOfItemId (const int itemId) const throw()
  37073. {
  37074. int n = 0;
  37075. for (int i = 0; i < items.size(); ++i)
  37076. {
  37077. const ItemInfo* const item = items.getUnchecked(i);
  37078. if (item->isRealItem())
  37079. {
  37080. if (item->itemId == itemId)
  37081. return n;
  37082. ++n;
  37083. }
  37084. }
  37085. return -1;
  37086. }
  37087. int ComboBox::getSelectedItemIndex() const throw()
  37088. {
  37089. int index = indexOfItemId (currentId.getValue());
  37090. if (getText() != getItemText (index))
  37091. index = -1;
  37092. return index;
  37093. }
  37094. void ComboBox::setSelectedItemIndex (const int index,
  37095. const bool dontSendChangeMessage) throw()
  37096. {
  37097. setSelectedId (getItemId (index), dontSendChangeMessage);
  37098. }
  37099. int ComboBox::getSelectedId() const throw()
  37100. {
  37101. const ItemInfo* const item = getItemForId (currentId.getValue());
  37102. return (item != 0 && getText() == item->name)
  37103. ? item->itemId
  37104. : 0;
  37105. }
  37106. void ComboBox::setSelectedId (const int newItemId,
  37107. const bool dontSendChangeMessage) throw()
  37108. {
  37109. const ItemInfo* const item = getItemForId (newItemId);
  37110. const String newItemText (item != 0 ? item->name : String::empty);
  37111. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37112. {
  37113. if (! dontSendChangeMessage)
  37114. triggerAsyncUpdate();
  37115. label->setText (newItemText, false);
  37116. lastCurrentId = newItemId;
  37117. currentId = newItemId;
  37118. repaint(); // for the benefit of the 'none selected' text
  37119. }
  37120. }
  37121. void ComboBox::valueChanged (Value&)
  37122. {
  37123. if (lastCurrentId != (int) currentId.getValue())
  37124. setSelectedId (currentId.getValue(), false);
  37125. }
  37126. const String ComboBox::getText() const throw()
  37127. {
  37128. return label->getText();
  37129. }
  37130. void ComboBox::setText (const String& newText,
  37131. const bool dontSendChangeMessage) throw()
  37132. {
  37133. for (int i = items.size(); --i >= 0;)
  37134. {
  37135. const ItemInfo* const item = items.getUnchecked(i);
  37136. if (item->isRealItem()
  37137. && item->name == newText)
  37138. {
  37139. setSelectedId (item->itemId, dontSendChangeMessage);
  37140. return;
  37141. }
  37142. }
  37143. lastCurrentId = 0;
  37144. currentId = 0;
  37145. if (label->getText() != newText)
  37146. {
  37147. label->setText (newText, false);
  37148. if (! dontSendChangeMessage)
  37149. triggerAsyncUpdate();
  37150. }
  37151. repaint();
  37152. }
  37153. void ComboBox::showEditor()
  37154. {
  37155. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37156. label->showEditor();
  37157. }
  37158. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37159. {
  37160. textWhenNothingSelected = newMessage;
  37161. repaint();
  37162. }
  37163. const String ComboBox::getTextWhenNothingSelected() const throw()
  37164. {
  37165. return textWhenNothingSelected;
  37166. }
  37167. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37168. {
  37169. noChoicesMessage = newMessage;
  37170. }
  37171. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37172. {
  37173. return noChoicesMessage;
  37174. }
  37175. void ComboBox::paint (Graphics& g)
  37176. {
  37177. getLookAndFeel().drawComboBox (g,
  37178. getWidth(),
  37179. getHeight(),
  37180. isButtonDown,
  37181. label->getRight(),
  37182. 0,
  37183. getWidth() - label->getRight(),
  37184. getHeight(),
  37185. *this);
  37186. if (textWhenNothingSelected.isNotEmpty()
  37187. && label->getText().isEmpty()
  37188. && ! label->isBeingEdited())
  37189. {
  37190. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37191. g.setFont (label->getFont());
  37192. g.drawFittedText (textWhenNothingSelected,
  37193. label->getX() + 2, label->getY() + 1,
  37194. label->getWidth() - 4, label->getHeight() - 2,
  37195. label->getJustificationType(),
  37196. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37197. }
  37198. }
  37199. void ComboBox::resized()
  37200. {
  37201. if (getHeight() > 0 && getWidth() > 0)
  37202. getLookAndFeel().positionComboBoxText (*this, *label);
  37203. }
  37204. void ComboBox::enablementChanged()
  37205. {
  37206. repaint();
  37207. }
  37208. void ComboBox::lookAndFeelChanged()
  37209. {
  37210. repaint();
  37211. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37212. if (label != 0)
  37213. {
  37214. newLabel->setEditable (label->isEditable());
  37215. newLabel->setJustificationType (label->getJustificationType());
  37216. newLabel->setTooltip (label->getTooltip());
  37217. newLabel->setText (label->getText(), false);
  37218. }
  37219. label = newLabel;
  37220. addAndMakeVisible (newLabel);
  37221. newLabel->addListener (this);
  37222. newLabel->addMouseListener (this, false);
  37223. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37224. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37225. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37226. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37227. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37228. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37229. resized();
  37230. }
  37231. void ComboBox::colourChanged()
  37232. {
  37233. lookAndFeelChanged();
  37234. }
  37235. bool ComboBox::keyPressed (const KeyPress& key)
  37236. {
  37237. bool used = false;
  37238. if (key.isKeyCode (KeyPress::upKey)
  37239. || key.isKeyCode (KeyPress::leftKey))
  37240. {
  37241. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37242. used = true;
  37243. }
  37244. else if (key.isKeyCode (KeyPress::downKey)
  37245. || key.isKeyCode (KeyPress::rightKey))
  37246. {
  37247. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37248. used = true;
  37249. }
  37250. else if (key.isKeyCode (KeyPress::returnKey))
  37251. {
  37252. showPopup();
  37253. used = true;
  37254. }
  37255. return used;
  37256. }
  37257. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37258. {
  37259. // only forward key events that aren't used by this component
  37260. return isKeyDown
  37261. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37262. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37263. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37264. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37265. }
  37266. void ComboBox::focusGained (FocusChangeType)
  37267. {
  37268. repaint();
  37269. }
  37270. void ComboBox::focusLost (FocusChangeType)
  37271. {
  37272. repaint();
  37273. }
  37274. void ComboBox::labelTextChanged (Label*)
  37275. {
  37276. triggerAsyncUpdate();
  37277. }
  37278. void ComboBox::showPopup()
  37279. {
  37280. if (! menuActive)
  37281. {
  37282. const int selectedId = getSelectedId();
  37283. Component::SafePointer<Component> deletionWatcher (this);
  37284. PopupMenu menu;
  37285. menu.setLookAndFeel (&getLookAndFeel());
  37286. for (int i = 0; i < items.size(); ++i)
  37287. {
  37288. const ItemInfo* const item = items.getUnchecked(i);
  37289. if (item->isSeparator())
  37290. menu.addSeparator();
  37291. else if (item->isHeading)
  37292. menu.addSectionHeader (item->name);
  37293. else
  37294. menu.addItem (item->itemId, item->name,
  37295. item->isEnabled, item->itemId == selectedId);
  37296. }
  37297. if (items.size() == 0)
  37298. menu.addItem (1, noChoicesMessage, false);
  37299. const int itemHeight = jlimit (12, 24, getHeight());
  37300. menuActive = true;
  37301. const int resultId = menu.showAt (this, selectedId,
  37302. getWidth(), 1, itemHeight);
  37303. if (deletionWatcher == 0)
  37304. return;
  37305. menuActive = false;
  37306. if (resultId != 0)
  37307. setSelectedId (resultId);
  37308. }
  37309. }
  37310. void ComboBox::mouseDown (const MouseEvent& e)
  37311. {
  37312. beginDragAutoRepeat (300);
  37313. isButtonDown = isEnabled();
  37314. if (isButtonDown
  37315. && (e.eventComponent == this || ! label->isEditable()))
  37316. {
  37317. showPopup();
  37318. }
  37319. }
  37320. void ComboBox::mouseDrag (const MouseEvent& e)
  37321. {
  37322. beginDragAutoRepeat (50);
  37323. if (isButtonDown && ! e.mouseWasClicked())
  37324. showPopup();
  37325. }
  37326. void ComboBox::mouseUp (const MouseEvent& e2)
  37327. {
  37328. if (isButtonDown)
  37329. {
  37330. isButtonDown = false;
  37331. repaint();
  37332. const MouseEvent e (e2.getEventRelativeTo (this));
  37333. if (reallyContains (e.x, e.y, true)
  37334. && (e2.eventComponent == this || ! label->isEditable()))
  37335. {
  37336. showPopup();
  37337. }
  37338. }
  37339. }
  37340. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37341. {
  37342. listeners.add (listener);
  37343. }
  37344. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37345. {
  37346. listeners.remove (listener);
  37347. }
  37348. void ComboBox::handleAsyncUpdate()
  37349. {
  37350. Component::BailOutChecker checker (this);
  37351. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37352. }
  37353. END_JUCE_NAMESPACE
  37354. /*** End of inlined file: juce_ComboBox.cpp ***/
  37355. /*** Start of inlined file: juce_Label.cpp ***/
  37356. BEGIN_JUCE_NAMESPACE
  37357. Label::Label (const String& componentName,
  37358. const String& labelText)
  37359. : Component (componentName),
  37360. textValue (labelText),
  37361. lastTextValue (labelText),
  37362. font (15.0f),
  37363. justification (Justification::centredLeft),
  37364. ownerComponent (0),
  37365. horizontalBorderSize (5),
  37366. verticalBorderSize (1),
  37367. minimumHorizontalScale (0.7f),
  37368. editSingleClick (false),
  37369. editDoubleClick (false),
  37370. lossOfFocusDiscardsChanges (false)
  37371. {
  37372. setColour (TextEditor::textColourId, Colours::black);
  37373. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37374. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37375. textValue.addListener (this);
  37376. }
  37377. Label::~Label()
  37378. {
  37379. textValue.removeListener (this);
  37380. if (ownerComponent != 0)
  37381. ownerComponent->removeComponentListener (this);
  37382. editor = 0;
  37383. }
  37384. void Label::setText (const String& newText,
  37385. const bool broadcastChangeMessage)
  37386. {
  37387. hideEditor (true);
  37388. if (lastTextValue != newText)
  37389. {
  37390. lastTextValue = newText;
  37391. textValue = newText;
  37392. repaint();
  37393. textWasChanged();
  37394. if (ownerComponent != 0)
  37395. componentMovedOrResized (*ownerComponent, true, true);
  37396. if (broadcastChangeMessage)
  37397. callChangeListeners();
  37398. }
  37399. }
  37400. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37401. {
  37402. return (returnActiveEditorContents && isBeingEdited())
  37403. ? editor->getText()
  37404. : textValue.toString();
  37405. }
  37406. void Label::valueChanged (Value&)
  37407. {
  37408. if (lastTextValue != textValue.toString())
  37409. setText (textValue.toString(), true);
  37410. }
  37411. void Label::setFont (const Font& newFont) throw()
  37412. {
  37413. font = newFont;
  37414. repaint();
  37415. }
  37416. const Font& Label::getFont() const throw()
  37417. {
  37418. return font;
  37419. }
  37420. void Label::setEditable (const bool editOnSingleClick,
  37421. const bool editOnDoubleClick,
  37422. const bool lossOfFocusDiscardsChanges_) throw()
  37423. {
  37424. editSingleClick = editOnSingleClick;
  37425. editDoubleClick = editOnDoubleClick;
  37426. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37427. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37428. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37429. }
  37430. void Label::setJustificationType (const Justification& justification_) throw()
  37431. {
  37432. justification = justification_;
  37433. repaint();
  37434. }
  37435. void Label::setBorderSize (int h, int v)
  37436. {
  37437. horizontalBorderSize = h;
  37438. verticalBorderSize = v;
  37439. repaint();
  37440. }
  37441. Component* Label::getAttachedComponent() const
  37442. {
  37443. return static_cast<Component*> (ownerComponent);
  37444. }
  37445. void Label::attachToComponent (Component* owner,
  37446. const bool onLeft)
  37447. {
  37448. if (ownerComponent != 0)
  37449. ownerComponent->removeComponentListener (this);
  37450. ownerComponent = owner;
  37451. leftOfOwnerComp = onLeft;
  37452. if (ownerComponent != 0)
  37453. {
  37454. setVisible (owner->isVisible());
  37455. ownerComponent->addComponentListener (this);
  37456. componentParentHierarchyChanged (*ownerComponent);
  37457. componentMovedOrResized (*ownerComponent, true, true);
  37458. }
  37459. }
  37460. void Label::componentMovedOrResized (Component& component,
  37461. bool /*wasMoved*/,
  37462. bool /*wasResized*/)
  37463. {
  37464. if (leftOfOwnerComp)
  37465. {
  37466. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37467. component.getHeight());
  37468. setTopRightPosition (component.getX(), component.getY());
  37469. }
  37470. else
  37471. {
  37472. setSize (component.getWidth(),
  37473. 8 + roundToInt (getFont().getHeight()));
  37474. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37475. }
  37476. }
  37477. void Label::componentParentHierarchyChanged (Component& component)
  37478. {
  37479. if (component.getParentComponent() != 0)
  37480. component.getParentComponent()->addChildComponent (this);
  37481. }
  37482. void Label::componentVisibilityChanged (Component& component)
  37483. {
  37484. setVisible (component.isVisible());
  37485. }
  37486. void Label::textWasEdited()
  37487. {
  37488. }
  37489. void Label::textWasChanged()
  37490. {
  37491. }
  37492. void Label::showEditor()
  37493. {
  37494. if (editor == 0)
  37495. {
  37496. addAndMakeVisible (editor = createEditorComponent());
  37497. editor->setText (getText(), false);
  37498. editor->addListener (this);
  37499. editor->grabKeyboardFocus();
  37500. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37501. editor->addListener (this);
  37502. resized();
  37503. repaint();
  37504. editorShown (editor);
  37505. enterModalState (false);
  37506. editor->grabKeyboardFocus();
  37507. }
  37508. }
  37509. void Label::editorShown (TextEditor* /*editorComponent*/)
  37510. {
  37511. }
  37512. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37513. {
  37514. }
  37515. bool Label::updateFromTextEditorContents()
  37516. {
  37517. jassert (editor != 0);
  37518. const String newText (editor->getText());
  37519. if (textValue.toString() != newText)
  37520. {
  37521. lastTextValue = newText;
  37522. textValue = newText;
  37523. repaint();
  37524. textWasChanged();
  37525. if (ownerComponent != 0)
  37526. componentMovedOrResized (*ownerComponent, true, true);
  37527. return true;
  37528. }
  37529. return false;
  37530. }
  37531. void Label::hideEditor (const bool discardCurrentEditorContents)
  37532. {
  37533. if (editor != 0)
  37534. {
  37535. Component::SafePointer<Component> deletionChecker (this);
  37536. editorAboutToBeHidden (editor);
  37537. const bool changed = (! discardCurrentEditorContents)
  37538. && updateFromTextEditorContents();
  37539. editor = 0;
  37540. repaint();
  37541. if (changed)
  37542. textWasEdited();
  37543. if (deletionChecker != 0)
  37544. exitModalState (0);
  37545. if (changed && deletionChecker != 0)
  37546. callChangeListeners();
  37547. }
  37548. }
  37549. void Label::inputAttemptWhenModal()
  37550. {
  37551. if (editor != 0)
  37552. {
  37553. if (lossOfFocusDiscardsChanges)
  37554. textEditorEscapeKeyPressed (*editor);
  37555. else
  37556. textEditorReturnKeyPressed (*editor);
  37557. }
  37558. }
  37559. bool Label::isBeingEdited() const throw()
  37560. {
  37561. return editor != 0;
  37562. }
  37563. TextEditor* Label::createEditorComponent()
  37564. {
  37565. TextEditor* const ed = new TextEditor (getName());
  37566. ed->setFont (font);
  37567. // copy these colours from our own settings..
  37568. const int cols[] = { TextEditor::backgroundColourId,
  37569. TextEditor::textColourId,
  37570. TextEditor::highlightColourId,
  37571. TextEditor::highlightedTextColourId,
  37572. TextEditor::caretColourId,
  37573. TextEditor::outlineColourId,
  37574. TextEditor::focusedOutlineColourId,
  37575. TextEditor::shadowColourId };
  37576. for (int i = 0; i < numElementsInArray (cols); ++i)
  37577. ed->setColour (cols[i], findColour (cols[i]));
  37578. return ed;
  37579. }
  37580. void Label::paint (Graphics& g)
  37581. {
  37582. getLookAndFeel().drawLabel (g, *this);
  37583. }
  37584. void Label::mouseUp (const MouseEvent& e)
  37585. {
  37586. if (editSingleClick
  37587. && e.mouseWasClicked()
  37588. && contains (e.x, e.y)
  37589. && ! e.mods.isPopupMenu())
  37590. {
  37591. showEditor();
  37592. }
  37593. }
  37594. void Label::mouseDoubleClick (const MouseEvent& e)
  37595. {
  37596. if (editDoubleClick && ! e.mods.isPopupMenu())
  37597. showEditor();
  37598. }
  37599. void Label::resized()
  37600. {
  37601. if (editor != 0)
  37602. editor->setBoundsInset (BorderSize (0));
  37603. }
  37604. void Label::focusGained (FocusChangeType cause)
  37605. {
  37606. if (editSingleClick && cause == focusChangedByTabKey)
  37607. showEditor();
  37608. }
  37609. void Label::enablementChanged()
  37610. {
  37611. repaint();
  37612. }
  37613. void Label::colourChanged()
  37614. {
  37615. repaint();
  37616. }
  37617. void Label::setMinimumHorizontalScale (const float newScale)
  37618. {
  37619. if (minimumHorizontalScale != newScale)
  37620. {
  37621. minimumHorizontalScale = newScale;
  37622. repaint();
  37623. }
  37624. }
  37625. // We'll use a custom focus traverser here to make sure focus goes from the
  37626. // text editor to another component rather than back to the label itself.
  37627. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37628. {
  37629. public:
  37630. LabelKeyboardFocusTraverser() {}
  37631. Component* getNextComponent (Component* current)
  37632. {
  37633. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37634. ? current->getParentComponent() : current);
  37635. }
  37636. Component* getPreviousComponent (Component* current)
  37637. {
  37638. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37639. ? current->getParentComponent() : current);
  37640. }
  37641. };
  37642. KeyboardFocusTraverser* Label::createFocusTraverser()
  37643. {
  37644. return new LabelKeyboardFocusTraverser();
  37645. }
  37646. void Label::addListener (LabelListener* const listener) throw()
  37647. {
  37648. listeners.add (listener);
  37649. }
  37650. void Label::removeListener (LabelListener* const listener) throw()
  37651. {
  37652. listeners.remove (listener);
  37653. }
  37654. void Label::callChangeListeners()
  37655. {
  37656. Component::BailOutChecker checker (this);
  37657. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37658. }
  37659. void Label::textEditorTextChanged (TextEditor& ed)
  37660. {
  37661. if (editor != 0)
  37662. {
  37663. jassert (&ed == editor);
  37664. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37665. {
  37666. if (lossOfFocusDiscardsChanges)
  37667. textEditorEscapeKeyPressed (ed);
  37668. else
  37669. textEditorReturnKeyPressed (ed);
  37670. }
  37671. }
  37672. }
  37673. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37674. {
  37675. if (editor != 0)
  37676. {
  37677. jassert (&ed == editor);
  37678. (void) ed;
  37679. const bool changed = updateFromTextEditorContents();
  37680. hideEditor (true);
  37681. if (changed)
  37682. {
  37683. Component::SafePointer<Component> deletionChecker (this);
  37684. textWasEdited();
  37685. if (deletionChecker != 0)
  37686. callChangeListeners();
  37687. }
  37688. }
  37689. }
  37690. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37691. {
  37692. if (editor != 0)
  37693. {
  37694. jassert (&ed == editor);
  37695. (void) ed;
  37696. editor->setText (textValue.toString(), false);
  37697. hideEditor (true);
  37698. }
  37699. }
  37700. void Label::textEditorFocusLost (TextEditor& ed)
  37701. {
  37702. textEditorTextChanged (ed);
  37703. }
  37704. END_JUCE_NAMESPACE
  37705. /*** End of inlined file: juce_Label.cpp ***/
  37706. /*** Start of inlined file: juce_ListBox.cpp ***/
  37707. BEGIN_JUCE_NAMESPACE
  37708. class ListBoxRowComponent : public Component,
  37709. public TooltipClient
  37710. {
  37711. public:
  37712. ListBoxRowComponent (ListBox& owner_)
  37713. : owner (owner_),
  37714. row (-1),
  37715. selected (false),
  37716. isDragging (false)
  37717. {
  37718. }
  37719. ~ListBoxRowComponent()
  37720. {
  37721. deleteAllChildren();
  37722. }
  37723. void paint (Graphics& g)
  37724. {
  37725. if (owner.getModel() != 0)
  37726. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37727. }
  37728. void update (const int row_, const bool selected_)
  37729. {
  37730. if (row != row_ || selected != selected_)
  37731. {
  37732. repaint();
  37733. row = row_;
  37734. selected = selected_;
  37735. }
  37736. if (owner.getModel() != 0)
  37737. {
  37738. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37739. if (customComp != 0)
  37740. {
  37741. addAndMakeVisible (customComp);
  37742. customComp->setBounds (0, 0, getWidth(), getHeight());
  37743. for (int i = getNumChildComponents(); --i >= 0;)
  37744. if (getChildComponent (i) != customComp)
  37745. delete getChildComponent (i);
  37746. }
  37747. else
  37748. {
  37749. deleteAllChildren();
  37750. }
  37751. }
  37752. }
  37753. void mouseDown (const MouseEvent& e)
  37754. {
  37755. isDragging = false;
  37756. selectRowOnMouseUp = false;
  37757. if (isEnabled())
  37758. {
  37759. if (! selected)
  37760. {
  37761. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37762. if (owner.getModel() != 0)
  37763. owner.getModel()->listBoxItemClicked (row, e);
  37764. }
  37765. else
  37766. {
  37767. selectRowOnMouseUp = true;
  37768. }
  37769. }
  37770. }
  37771. void mouseUp (const MouseEvent& e)
  37772. {
  37773. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37774. {
  37775. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37776. if (owner.getModel() != 0)
  37777. owner.getModel()->listBoxItemClicked (row, e);
  37778. }
  37779. }
  37780. void mouseDoubleClick (const MouseEvent& e)
  37781. {
  37782. if (owner.getModel() != 0 && isEnabled())
  37783. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37784. }
  37785. void mouseDrag (const MouseEvent& e)
  37786. {
  37787. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37788. {
  37789. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37790. if (selectedRows.size() > 0)
  37791. {
  37792. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37793. if (dragDescription.isNotEmpty())
  37794. {
  37795. isDragging = true;
  37796. owner.startDragAndDrop (e, dragDescription);
  37797. }
  37798. }
  37799. }
  37800. }
  37801. void resized()
  37802. {
  37803. if (getNumChildComponents() > 0)
  37804. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37805. }
  37806. const String getTooltip()
  37807. {
  37808. if (owner.getModel() != 0)
  37809. return owner.getModel()->getTooltipForRow (row);
  37810. return String::empty;
  37811. }
  37812. juce_UseDebuggingNewOperator
  37813. bool neededFlag;
  37814. private:
  37815. ListBox& owner;
  37816. int row;
  37817. bool selected, isDragging, selectRowOnMouseUp;
  37818. ListBoxRowComponent (const ListBoxRowComponent&);
  37819. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37820. };
  37821. class ListViewport : public Viewport
  37822. {
  37823. public:
  37824. int firstIndex, firstWholeIndex, lastWholeIndex;
  37825. bool hasUpdated;
  37826. ListViewport (ListBox& owner_)
  37827. : owner (owner_)
  37828. {
  37829. setWantsKeyboardFocus (false);
  37830. setViewedComponent (new Component());
  37831. getViewedComponent()->addMouseListener (this, false);
  37832. getViewedComponent()->setWantsKeyboardFocus (false);
  37833. }
  37834. ~ListViewport()
  37835. {
  37836. getViewedComponent()->removeMouseListener (this);
  37837. getViewedComponent()->deleteAllChildren();
  37838. }
  37839. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37840. {
  37841. return static_cast <ListBoxRowComponent*>
  37842. (getViewedComponent()->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents())));
  37843. }
  37844. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37845. {
  37846. const int index = getIndexOfChildComponent (rowComponent);
  37847. const int num = getViewedComponent()->getNumChildComponents();
  37848. for (int i = num; --i >= 0;)
  37849. if (((firstIndex + i) % jmax (1, num)) == index)
  37850. return firstIndex + i;
  37851. return -1;
  37852. }
  37853. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37854. {
  37855. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37856. ? getComponentForRow (row) : 0;
  37857. }
  37858. void visibleAreaChanged (int, int, int, int)
  37859. {
  37860. updateVisibleArea (true);
  37861. if (owner.getModel() != 0)
  37862. owner.getModel()->listWasScrolled();
  37863. }
  37864. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37865. {
  37866. hasUpdated = false;
  37867. const int newX = getViewedComponent()->getX();
  37868. int newY = getViewedComponent()->getY();
  37869. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37870. const int newH = owner.totalItems * owner.getRowHeight();
  37871. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37872. newY = getMaximumVisibleHeight() - newH;
  37873. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37874. if (makeSureItUpdatesContent && ! hasUpdated)
  37875. updateContents();
  37876. }
  37877. void updateContents()
  37878. {
  37879. hasUpdated = true;
  37880. const int rowHeight = owner.getRowHeight();
  37881. if (rowHeight > 0)
  37882. {
  37883. const int y = getViewPositionY();
  37884. const int w = getViewedComponent()->getWidth();
  37885. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37886. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37887. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37888. jassert (numNeeded >= 0);
  37889. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37890. {
  37891. Component* const rowToRemove
  37892. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37893. delete rowToRemove;
  37894. }
  37895. firstIndex = y / rowHeight;
  37896. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37897. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37898. for (int i = 0; i < numNeeded; ++i)
  37899. {
  37900. const int row = i + firstIndex;
  37901. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37902. if (rowComp != 0)
  37903. {
  37904. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37905. rowComp->update (row, owner.isRowSelected (row));
  37906. }
  37907. }
  37908. }
  37909. if (owner.headerComponent != 0)
  37910. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37911. owner.outlineThickness,
  37912. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37913. getViewedComponent()->getWidth()),
  37914. owner.headerComponent->getHeight());
  37915. }
  37916. void paint (Graphics& g)
  37917. {
  37918. if (isOpaque())
  37919. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37920. }
  37921. bool keyPressed (const KeyPress& key)
  37922. {
  37923. if (key.isKeyCode (KeyPress::upKey)
  37924. || key.isKeyCode (KeyPress::downKey)
  37925. || key.isKeyCode (KeyPress::pageUpKey)
  37926. || key.isKeyCode (KeyPress::pageDownKey)
  37927. || key.isKeyCode (KeyPress::homeKey)
  37928. || key.isKeyCode (KeyPress::endKey))
  37929. {
  37930. // we want to avoid these keypresses going to the viewport, and instead allow
  37931. // them to pass up to our listbox..
  37932. return false;
  37933. }
  37934. return Viewport::keyPressed (key);
  37935. }
  37936. juce_UseDebuggingNewOperator
  37937. private:
  37938. ListBox& owner;
  37939. ListViewport (const ListViewport&);
  37940. ListViewport& operator= (const ListViewport&);
  37941. };
  37942. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37943. : Component (name),
  37944. model (model_),
  37945. headerComponent (0),
  37946. totalItems (0),
  37947. rowHeight (22),
  37948. minimumRowWidth (0),
  37949. outlineThickness (0),
  37950. lastRowSelected (-1),
  37951. mouseMoveSelects (false),
  37952. multipleSelection (false),
  37953. hasDoneInitialUpdate (false)
  37954. {
  37955. addAndMakeVisible (viewport = new ListViewport (*this));
  37956. setWantsKeyboardFocus (true);
  37957. colourChanged();
  37958. }
  37959. ListBox::~ListBox()
  37960. {
  37961. deleteAllChildren();
  37962. }
  37963. void ListBox::setModel (ListBoxModel* const newModel)
  37964. {
  37965. if (model != newModel)
  37966. {
  37967. model = newModel;
  37968. updateContent();
  37969. }
  37970. }
  37971. void ListBox::setMultipleSelectionEnabled (bool b)
  37972. {
  37973. multipleSelection = b;
  37974. }
  37975. void ListBox::setMouseMoveSelectsRows (bool b)
  37976. {
  37977. mouseMoveSelects = b;
  37978. if (b)
  37979. addMouseListener (this, true);
  37980. }
  37981. void ListBox::paint (Graphics& g)
  37982. {
  37983. if (! hasDoneInitialUpdate)
  37984. updateContent();
  37985. g.fillAll (findColour (backgroundColourId));
  37986. }
  37987. void ListBox::paintOverChildren (Graphics& g)
  37988. {
  37989. if (outlineThickness > 0)
  37990. {
  37991. g.setColour (findColour (outlineColourId));
  37992. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  37993. }
  37994. }
  37995. void ListBox::resized()
  37996. {
  37997. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  37998. outlineThickness,
  37999. outlineThickness,
  38000. outlineThickness));
  38001. viewport->setSingleStepSizes (20, getRowHeight());
  38002. viewport->updateVisibleArea (false);
  38003. }
  38004. void ListBox::visibilityChanged()
  38005. {
  38006. viewport->updateVisibleArea (true);
  38007. }
  38008. Viewport* ListBox::getViewport() const throw()
  38009. {
  38010. return viewport;
  38011. }
  38012. void ListBox::updateContent()
  38013. {
  38014. hasDoneInitialUpdate = true;
  38015. totalItems = (model != 0) ? model->getNumRows() : 0;
  38016. bool selectionChanged = false;
  38017. if (selected [selected.size() - 1] >= totalItems)
  38018. {
  38019. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38020. lastRowSelected = getSelectedRow (0);
  38021. selectionChanged = true;
  38022. }
  38023. viewport->updateVisibleArea (isVisible());
  38024. viewport->resized();
  38025. if (selectionChanged && model != 0)
  38026. model->selectedRowsChanged (lastRowSelected);
  38027. }
  38028. void ListBox::selectRow (const int row,
  38029. bool dontScroll,
  38030. bool deselectOthersFirst)
  38031. {
  38032. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38033. }
  38034. void ListBox::selectRowInternal (const int row,
  38035. bool dontScroll,
  38036. bool deselectOthersFirst,
  38037. bool isMouseClick)
  38038. {
  38039. if (! multipleSelection)
  38040. deselectOthersFirst = true;
  38041. if ((! isRowSelected (row))
  38042. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38043. {
  38044. if (((unsigned int) row) < (unsigned int) totalItems)
  38045. {
  38046. if (deselectOthersFirst)
  38047. selected.clear();
  38048. selected.addRange (row, 1);
  38049. if (getHeight() == 0 || getWidth() == 0)
  38050. dontScroll = true;
  38051. viewport->hasUpdated = false;
  38052. if (row < viewport->firstWholeIndex && ! dontScroll)
  38053. {
  38054. viewport->setViewPosition (viewport->getViewPositionX(),
  38055. row * getRowHeight());
  38056. }
  38057. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38058. {
  38059. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38060. if (row >= lastRowSelected + rowsOnScreen
  38061. && rowsOnScreen < totalItems - 1
  38062. && ! isMouseClick)
  38063. {
  38064. viewport->setViewPosition (viewport->getViewPositionX(),
  38065. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38066. * getRowHeight());
  38067. }
  38068. else
  38069. {
  38070. viewport->setViewPosition (viewport->getViewPositionX(),
  38071. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38072. }
  38073. }
  38074. if (! viewport->hasUpdated)
  38075. viewport->updateContents();
  38076. lastRowSelected = row;
  38077. model->selectedRowsChanged (row);
  38078. }
  38079. else
  38080. {
  38081. if (deselectOthersFirst)
  38082. deselectAllRows();
  38083. }
  38084. }
  38085. }
  38086. void ListBox::deselectRow (const int row)
  38087. {
  38088. if (selected.contains (row))
  38089. {
  38090. selected.removeRange (row, 1);
  38091. if (row == lastRowSelected)
  38092. lastRowSelected = getSelectedRow (0);
  38093. viewport->updateContents();
  38094. model->selectedRowsChanged (lastRowSelected);
  38095. }
  38096. }
  38097. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38098. const bool sendNotificationEventToModel)
  38099. {
  38100. selected = setOfRowsToBeSelected;
  38101. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38102. if (! isRowSelected (lastRowSelected))
  38103. lastRowSelected = getSelectedRow (0);
  38104. viewport->updateContents();
  38105. if ((model != 0) && sendNotificationEventToModel)
  38106. model->selectedRowsChanged (lastRowSelected);
  38107. }
  38108. const SparseSet<int> ListBox::getSelectedRows() const
  38109. {
  38110. return selected;
  38111. }
  38112. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38113. {
  38114. if (multipleSelection && (firstRow != lastRow))
  38115. {
  38116. const int numRows = totalItems - 1;
  38117. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38118. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38119. selected.addRange (jmin (firstRow, lastRow),
  38120. abs (firstRow - lastRow) + 1);
  38121. selected.removeRange (lastRow, 1);
  38122. }
  38123. selectRowInternal (lastRow, false, false, true);
  38124. }
  38125. void ListBox::flipRowSelection (const int row)
  38126. {
  38127. if (isRowSelected (row))
  38128. deselectRow (row);
  38129. else
  38130. selectRowInternal (row, false, false, true);
  38131. }
  38132. void ListBox::deselectAllRows()
  38133. {
  38134. if (! selected.isEmpty())
  38135. {
  38136. selected.clear();
  38137. lastRowSelected = -1;
  38138. viewport->updateContents();
  38139. if (model != 0)
  38140. model->selectedRowsChanged (lastRowSelected);
  38141. }
  38142. }
  38143. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38144. const ModifierKeys& mods)
  38145. {
  38146. if (multipleSelection && mods.isCommandDown())
  38147. {
  38148. flipRowSelection (row);
  38149. }
  38150. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38151. {
  38152. selectRangeOfRows (lastRowSelected, row);
  38153. }
  38154. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38155. {
  38156. selectRowInternal (row, false, true, true);
  38157. }
  38158. }
  38159. int ListBox::getNumSelectedRows() const
  38160. {
  38161. return selected.size();
  38162. }
  38163. int ListBox::getSelectedRow (const int index) const
  38164. {
  38165. return (((unsigned int) index) < (unsigned int) selected.size())
  38166. ? selected [index] : -1;
  38167. }
  38168. bool ListBox::isRowSelected (const int row) const
  38169. {
  38170. return selected.contains (row);
  38171. }
  38172. int ListBox::getLastRowSelected() const
  38173. {
  38174. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38175. }
  38176. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38177. {
  38178. if (((unsigned int) x) < (unsigned int) getWidth())
  38179. {
  38180. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38181. if (((unsigned int) row) < (unsigned int) totalItems)
  38182. return row;
  38183. }
  38184. return -1;
  38185. }
  38186. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38187. {
  38188. if (((unsigned int) x) < (unsigned int) getWidth())
  38189. {
  38190. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38191. return jlimit (0, totalItems, row);
  38192. }
  38193. return -1;
  38194. }
  38195. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38196. {
  38197. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38198. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38199. }
  38200. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38201. {
  38202. return viewport->getRowNumberOfComponent (rowComponent);
  38203. }
  38204. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38205. const bool relativeToComponentTopLeft) const throw()
  38206. {
  38207. const int rowHeight = getRowHeight();
  38208. int y = viewport->getY() + rowHeight * rowNumber;
  38209. if (relativeToComponentTopLeft)
  38210. y -= viewport->getViewPositionY();
  38211. return Rectangle<int> (viewport->getX(), y,
  38212. viewport->getViewedComponent()->getWidth(), rowHeight);
  38213. }
  38214. void ListBox::setVerticalPosition (const double proportion)
  38215. {
  38216. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38217. viewport->setViewPosition (viewport->getViewPositionX(),
  38218. jmax (0, roundToInt (proportion * offscreen)));
  38219. }
  38220. double ListBox::getVerticalPosition() const
  38221. {
  38222. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38223. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38224. : 0;
  38225. }
  38226. int ListBox::getVisibleRowWidth() const throw()
  38227. {
  38228. return viewport->getViewWidth();
  38229. }
  38230. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38231. {
  38232. if (row < viewport->firstWholeIndex)
  38233. {
  38234. viewport->setViewPosition (viewport->getViewPositionX(),
  38235. row * getRowHeight());
  38236. }
  38237. else if (row >= viewport->lastWholeIndex)
  38238. {
  38239. viewport->setViewPosition (viewport->getViewPositionX(),
  38240. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38241. }
  38242. }
  38243. bool ListBox::keyPressed (const KeyPress& key)
  38244. {
  38245. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38246. const bool multiple = multipleSelection
  38247. && (lastRowSelected >= 0)
  38248. && (key.getModifiers().isShiftDown()
  38249. || key.getModifiers().isCtrlDown()
  38250. || key.getModifiers().isCommandDown());
  38251. if (key.isKeyCode (KeyPress::upKey))
  38252. {
  38253. if (multiple)
  38254. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38255. else
  38256. selectRow (jmax (0, lastRowSelected - 1));
  38257. }
  38258. else if (key.isKeyCode (KeyPress::returnKey)
  38259. && isRowSelected (lastRowSelected))
  38260. {
  38261. if (model != 0)
  38262. model->returnKeyPressed (lastRowSelected);
  38263. }
  38264. else if (key.isKeyCode (KeyPress::pageUpKey))
  38265. {
  38266. if (multiple)
  38267. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38268. else
  38269. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38270. }
  38271. else if (key.isKeyCode (KeyPress::pageDownKey))
  38272. {
  38273. if (multiple)
  38274. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38275. else
  38276. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38277. }
  38278. else if (key.isKeyCode (KeyPress::homeKey))
  38279. {
  38280. if (multiple && key.getModifiers().isShiftDown())
  38281. selectRangeOfRows (lastRowSelected, 0);
  38282. else
  38283. selectRow (0);
  38284. }
  38285. else if (key.isKeyCode (KeyPress::endKey))
  38286. {
  38287. if (multiple && key.getModifiers().isShiftDown())
  38288. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38289. else
  38290. selectRow (totalItems - 1);
  38291. }
  38292. else if (key.isKeyCode (KeyPress::downKey))
  38293. {
  38294. if (multiple)
  38295. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38296. else
  38297. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38298. }
  38299. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38300. && isRowSelected (lastRowSelected))
  38301. {
  38302. if (model != 0)
  38303. model->deleteKeyPressed (lastRowSelected);
  38304. }
  38305. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38306. {
  38307. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38308. }
  38309. else
  38310. {
  38311. return false;
  38312. }
  38313. return true;
  38314. }
  38315. bool ListBox::keyStateChanged (const bool isKeyDown)
  38316. {
  38317. return isKeyDown
  38318. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38319. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38320. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38321. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38322. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38323. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38324. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38325. }
  38326. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38327. {
  38328. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38329. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38330. }
  38331. void ListBox::mouseMove (const MouseEvent& e)
  38332. {
  38333. if (mouseMoveSelects)
  38334. {
  38335. const MouseEvent e2 (e.getEventRelativeTo (this));
  38336. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38337. }
  38338. }
  38339. void ListBox::mouseExit (const MouseEvent& e)
  38340. {
  38341. mouseMove (e);
  38342. }
  38343. void ListBox::mouseUp (const MouseEvent& e)
  38344. {
  38345. if (e.mouseWasClicked() && model != 0)
  38346. model->backgroundClicked();
  38347. }
  38348. void ListBox::setRowHeight (const int newHeight)
  38349. {
  38350. rowHeight = jmax (1, newHeight);
  38351. viewport->setSingleStepSizes (20, rowHeight);
  38352. updateContent();
  38353. }
  38354. int ListBox::getNumRowsOnScreen() const throw()
  38355. {
  38356. return viewport->getMaximumVisibleHeight() / rowHeight;
  38357. }
  38358. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38359. {
  38360. minimumRowWidth = newMinimumWidth;
  38361. updateContent();
  38362. }
  38363. int ListBox::getVisibleContentWidth() const throw()
  38364. {
  38365. return viewport->getMaximumVisibleWidth();
  38366. }
  38367. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38368. {
  38369. return viewport->getVerticalScrollBar();
  38370. }
  38371. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38372. {
  38373. return viewport->getHorizontalScrollBar();
  38374. }
  38375. void ListBox::colourChanged()
  38376. {
  38377. setOpaque (findColour (backgroundColourId).isOpaque());
  38378. viewport->setOpaque (isOpaque());
  38379. repaint();
  38380. }
  38381. void ListBox::setOutlineThickness (const int outlineThickness_)
  38382. {
  38383. outlineThickness = outlineThickness_;
  38384. resized();
  38385. }
  38386. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38387. {
  38388. if (headerComponent != newHeaderComponent)
  38389. {
  38390. delete headerComponent;
  38391. headerComponent = newHeaderComponent;
  38392. addAndMakeVisible (newHeaderComponent);
  38393. ListBox::resized();
  38394. }
  38395. }
  38396. void ListBox::repaintRow (const int rowNumber) throw()
  38397. {
  38398. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38399. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38400. }
  38401. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38402. {
  38403. Rectangle<int> imageArea;
  38404. const int firstRow = getRowContainingPosition (0, 0);
  38405. int i;
  38406. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38407. {
  38408. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38409. if (rowComp != 0 && isRowSelected (firstRow + i))
  38410. {
  38411. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38412. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38413. if (imageArea.isEmpty())
  38414. imageArea = rowRect;
  38415. else
  38416. imageArea = imageArea.getUnion (rowRect);
  38417. }
  38418. }
  38419. imageArea = imageArea.getIntersection (getLocalBounds());
  38420. imageX = imageArea.getX();
  38421. imageY = imageArea.getY();
  38422. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38423. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38424. {
  38425. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38426. if (rowComp != 0 && isRowSelected (firstRow + i))
  38427. {
  38428. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38429. Graphics g (*snapshot);
  38430. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38431. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38432. rowComp->paintEntireComponent (g);
  38433. }
  38434. }
  38435. return snapshot;
  38436. }
  38437. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38438. {
  38439. DragAndDropContainer* const dragContainer
  38440. = DragAndDropContainer::findParentDragContainerFor (this);
  38441. if (dragContainer != 0)
  38442. {
  38443. int x, y;
  38444. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38445. dragImage->multiplyAllAlphas (0.6f);
  38446. MouseEvent e2 (e.getEventRelativeTo (this));
  38447. const Point<int> p (x - e2.x, y - e2.y);
  38448. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38449. }
  38450. else
  38451. {
  38452. // to be able to do a drag-and-drop operation, the listbox needs to
  38453. // be inside a component which is also a DragAndDropContainer.
  38454. jassertfalse
  38455. }
  38456. }
  38457. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38458. {
  38459. (void) existingComponentToUpdate;
  38460. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38461. return 0;
  38462. }
  38463. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38464. {
  38465. }
  38466. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38467. {
  38468. }
  38469. void ListBoxModel::backgroundClicked()
  38470. {
  38471. }
  38472. void ListBoxModel::selectedRowsChanged (int)
  38473. {
  38474. }
  38475. void ListBoxModel::deleteKeyPressed (int)
  38476. {
  38477. }
  38478. void ListBoxModel::returnKeyPressed (int)
  38479. {
  38480. }
  38481. void ListBoxModel::listWasScrolled()
  38482. {
  38483. }
  38484. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38485. {
  38486. return String::empty;
  38487. }
  38488. const String ListBoxModel::getTooltipForRow (int)
  38489. {
  38490. return String::empty;
  38491. }
  38492. END_JUCE_NAMESPACE
  38493. /*** End of inlined file: juce_ListBox.cpp ***/
  38494. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38495. BEGIN_JUCE_NAMESPACE
  38496. ProgressBar::ProgressBar (double& progress_)
  38497. : progress (progress_),
  38498. displayPercentage (true),
  38499. lastCallbackTime (0)
  38500. {
  38501. currentValue = jlimit (0.0, 1.0, progress);
  38502. }
  38503. ProgressBar::~ProgressBar()
  38504. {
  38505. }
  38506. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38507. {
  38508. displayPercentage = shouldDisplayPercentage;
  38509. repaint();
  38510. }
  38511. void ProgressBar::setTextToDisplay (const String& text)
  38512. {
  38513. displayPercentage = false;
  38514. displayedMessage = text;
  38515. }
  38516. void ProgressBar::lookAndFeelChanged()
  38517. {
  38518. setOpaque (findColour (backgroundColourId).isOpaque());
  38519. }
  38520. void ProgressBar::colourChanged()
  38521. {
  38522. lookAndFeelChanged();
  38523. }
  38524. void ProgressBar::paint (Graphics& g)
  38525. {
  38526. String text;
  38527. if (displayPercentage)
  38528. {
  38529. if (currentValue >= 0 && currentValue <= 1.0)
  38530. text << roundToInt (currentValue * 100.0) << '%';
  38531. }
  38532. else
  38533. {
  38534. text = displayedMessage;
  38535. }
  38536. getLookAndFeel().drawProgressBar (g, *this,
  38537. getWidth(), getHeight(),
  38538. currentValue, text);
  38539. }
  38540. void ProgressBar::visibilityChanged()
  38541. {
  38542. if (isVisible())
  38543. startTimer (30);
  38544. else
  38545. stopTimer();
  38546. }
  38547. void ProgressBar::timerCallback()
  38548. {
  38549. double newProgress = progress;
  38550. const uint32 now = Time::getMillisecondCounter();
  38551. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38552. lastCallbackTime = now;
  38553. if (currentValue != newProgress
  38554. || newProgress < 0 || newProgress >= 1.0
  38555. || currentMessage != displayedMessage)
  38556. {
  38557. if (currentValue < newProgress
  38558. && newProgress >= 0 && newProgress < 1.0
  38559. && currentValue >= 0 && currentValue < 1.0)
  38560. {
  38561. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38562. newProgress);
  38563. }
  38564. currentValue = newProgress;
  38565. currentMessage = displayedMessage;
  38566. repaint();
  38567. }
  38568. }
  38569. END_JUCE_NAMESPACE
  38570. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38571. /*** Start of inlined file: juce_Slider.cpp ***/
  38572. BEGIN_JUCE_NAMESPACE
  38573. class SliderPopupDisplayComponent : public BubbleComponent
  38574. {
  38575. public:
  38576. SliderPopupDisplayComponent (Slider* const owner_)
  38577. : owner (owner_),
  38578. font (15.0f, Font::bold)
  38579. {
  38580. setAlwaysOnTop (true);
  38581. }
  38582. ~SliderPopupDisplayComponent()
  38583. {
  38584. }
  38585. void paintContent (Graphics& g, int w, int h)
  38586. {
  38587. g.setFont (font);
  38588. g.setColour (Colours::black);
  38589. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38590. }
  38591. void getContentSize (int& w, int& h)
  38592. {
  38593. w = font.getStringWidth (text) + 18;
  38594. h = (int) (font.getHeight() * 1.6f);
  38595. }
  38596. void updatePosition (const String& newText)
  38597. {
  38598. if (text != newText)
  38599. {
  38600. text = newText;
  38601. repaint();
  38602. }
  38603. BubbleComponent::setPosition (owner);
  38604. }
  38605. juce_UseDebuggingNewOperator
  38606. private:
  38607. Slider* owner;
  38608. Font font;
  38609. String text;
  38610. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38611. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38612. };
  38613. Slider::Slider (const String& name)
  38614. : Component (name),
  38615. lastCurrentValue (0),
  38616. lastValueMin (0),
  38617. lastValueMax (0),
  38618. minimum (0),
  38619. maximum (10),
  38620. interval (0),
  38621. skewFactor (1.0),
  38622. velocityModeSensitivity (1.0),
  38623. velocityModeOffset (0.0),
  38624. velocityModeThreshold (1),
  38625. rotaryStart (float_Pi * 1.2f),
  38626. rotaryEnd (float_Pi * 2.8f),
  38627. numDecimalPlaces (7),
  38628. sliderRegionStart (0),
  38629. sliderRegionSize (1),
  38630. sliderBeingDragged (-1),
  38631. pixelsForFullDragExtent (250),
  38632. style (LinearHorizontal),
  38633. textBoxPos (TextBoxLeft),
  38634. textBoxWidth (80),
  38635. textBoxHeight (20),
  38636. incDecButtonMode (incDecButtonsNotDraggable),
  38637. editableText (true),
  38638. doubleClickToValue (false),
  38639. isVelocityBased (false),
  38640. userKeyOverridesVelocity (true),
  38641. rotaryStop (true),
  38642. incDecButtonsSideBySide (false),
  38643. sendChangeOnlyOnRelease (false),
  38644. popupDisplayEnabled (false),
  38645. menuEnabled (false),
  38646. menuShown (false),
  38647. scrollWheelEnabled (true),
  38648. snapsToMousePos (true),
  38649. valueBox (0),
  38650. incButton (0),
  38651. decButton (0),
  38652. popupDisplay (0),
  38653. parentForPopupDisplay (0)
  38654. {
  38655. setWantsKeyboardFocus (false);
  38656. setRepaintsOnMouseActivity (true);
  38657. lookAndFeelChanged();
  38658. updateText();
  38659. currentValue.addListener (this);
  38660. valueMin.addListener (this);
  38661. valueMax.addListener (this);
  38662. }
  38663. Slider::~Slider()
  38664. {
  38665. currentValue.removeListener (this);
  38666. valueMin.removeListener (this);
  38667. valueMax.removeListener (this);
  38668. popupDisplay = 0;
  38669. deleteAllChildren();
  38670. }
  38671. void Slider::handleAsyncUpdate()
  38672. {
  38673. cancelPendingUpdate();
  38674. Component::BailOutChecker checker (this);
  38675. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38676. }
  38677. void Slider::sendDragStart()
  38678. {
  38679. startedDragging();
  38680. Component::BailOutChecker checker (this);
  38681. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38682. }
  38683. void Slider::sendDragEnd()
  38684. {
  38685. stoppedDragging();
  38686. sliderBeingDragged = -1;
  38687. Component::BailOutChecker checker (this);
  38688. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38689. }
  38690. void Slider::addListener (SliderListener* const listener)
  38691. {
  38692. listeners.add (listener);
  38693. }
  38694. void Slider::removeListener (SliderListener* const listener)
  38695. {
  38696. listeners.remove (listener);
  38697. }
  38698. void Slider::setSliderStyle (const SliderStyle newStyle)
  38699. {
  38700. if (style != newStyle)
  38701. {
  38702. style = newStyle;
  38703. repaint();
  38704. lookAndFeelChanged();
  38705. }
  38706. }
  38707. void Slider::setRotaryParameters (const float startAngleRadians,
  38708. const float endAngleRadians,
  38709. const bool stopAtEnd)
  38710. {
  38711. // make sure the values are sensible..
  38712. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38713. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38714. jassert (rotaryStart < rotaryEnd);
  38715. rotaryStart = startAngleRadians;
  38716. rotaryEnd = endAngleRadians;
  38717. rotaryStop = stopAtEnd;
  38718. }
  38719. void Slider::setVelocityBasedMode (const bool velBased)
  38720. {
  38721. isVelocityBased = velBased;
  38722. }
  38723. void Slider::setVelocityModeParameters (const double sensitivity,
  38724. const int threshold,
  38725. const double offset,
  38726. const bool userCanPressKeyToSwapMode)
  38727. {
  38728. jassert (threshold >= 0);
  38729. jassert (sensitivity > 0);
  38730. jassert (offset >= 0);
  38731. velocityModeSensitivity = sensitivity;
  38732. velocityModeOffset = offset;
  38733. velocityModeThreshold = threshold;
  38734. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38735. }
  38736. void Slider::setSkewFactor (const double factor)
  38737. {
  38738. skewFactor = factor;
  38739. }
  38740. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38741. {
  38742. if (maximum > minimum)
  38743. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38744. / (maximum - minimum));
  38745. }
  38746. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38747. {
  38748. jassert (distanceForFullScaleDrag > 0);
  38749. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38750. }
  38751. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38752. {
  38753. if (incDecButtonMode != mode)
  38754. {
  38755. incDecButtonMode = mode;
  38756. lookAndFeelChanged();
  38757. }
  38758. }
  38759. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38760. const bool isReadOnly,
  38761. const int textEntryBoxWidth,
  38762. const int textEntryBoxHeight)
  38763. {
  38764. textBoxPos = newPosition;
  38765. editableText = ! isReadOnly;
  38766. textBoxWidth = textEntryBoxWidth;
  38767. textBoxHeight = textEntryBoxHeight;
  38768. repaint();
  38769. lookAndFeelChanged();
  38770. }
  38771. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38772. {
  38773. editableText = shouldBeEditable;
  38774. if (valueBox != 0)
  38775. valueBox->setEditable (shouldBeEditable && isEnabled());
  38776. }
  38777. void Slider::showTextBox()
  38778. {
  38779. jassert (editableText); // this should probably be avoided in read-only sliders.
  38780. if (valueBox != 0)
  38781. valueBox->showEditor();
  38782. }
  38783. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38784. {
  38785. if (valueBox != 0)
  38786. {
  38787. valueBox->hideEditor (discardCurrentEditorContents);
  38788. if (discardCurrentEditorContents)
  38789. updateText();
  38790. }
  38791. }
  38792. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38793. {
  38794. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38795. }
  38796. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38797. {
  38798. snapsToMousePos = shouldSnapToMouse;
  38799. }
  38800. void Slider::setPopupDisplayEnabled (const bool enabled,
  38801. Component* const parentComponentToUse)
  38802. {
  38803. popupDisplayEnabled = enabled;
  38804. parentForPopupDisplay = parentComponentToUse;
  38805. }
  38806. void Slider::colourChanged()
  38807. {
  38808. lookAndFeelChanged();
  38809. }
  38810. void Slider::lookAndFeelChanged()
  38811. {
  38812. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38813. : getTextFromValue (currentValue.getValue()));
  38814. deleteAllChildren();
  38815. valueBox = 0;
  38816. LookAndFeel& lf = getLookAndFeel();
  38817. if (textBoxPos != NoTextBox)
  38818. {
  38819. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38820. valueBox->setWantsKeyboardFocus (false);
  38821. valueBox->setText (previousTextBoxContent, false);
  38822. valueBox->setEditable (editableText && isEnabled());
  38823. valueBox->addListener (this);
  38824. if (style == LinearBar)
  38825. valueBox->addMouseListener (this, false);
  38826. valueBox->setTooltip (getTooltip());
  38827. }
  38828. if (style == IncDecButtons)
  38829. {
  38830. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38831. incButton->addButtonListener (this);
  38832. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38833. decButton->addButtonListener (this);
  38834. if (incDecButtonMode != incDecButtonsNotDraggable)
  38835. {
  38836. incButton->addMouseListener (this, false);
  38837. decButton->addMouseListener (this, false);
  38838. }
  38839. else
  38840. {
  38841. incButton->setRepeatSpeed (300, 100, 20);
  38842. incButton->addMouseListener (decButton, false);
  38843. decButton->setRepeatSpeed (300, 100, 20);
  38844. decButton->addMouseListener (incButton, false);
  38845. }
  38846. incButton->setTooltip (getTooltip());
  38847. decButton->setTooltip (getTooltip());
  38848. }
  38849. setComponentEffect (lf.getSliderEffect());
  38850. resized();
  38851. repaint();
  38852. }
  38853. void Slider::setRange (const double newMin,
  38854. const double newMax,
  38855. const double newInt)
  38856. {
  38857. if (minimum != newMin
  38858. || maximum != newMax
  38859. || interval != newInt)
  38860. {
  38861. minimum = newMin;
  38862. maximum = newMax;
  38863. interval = newInt;
  38864. // figure out the number of DPs needed to display all values at this
  38865. // interval setting.
  38866. numDecimalPlaces = 7;
  38867. if (newInt != 0)
  38868. {
  38869. int v = abs ((int) (newInt * 10000000));
  38870. while ((v % 10) == 0)
  38871. {
  38872. --numDecimalPlaces;
  38873. v /= 10;
  38874. }
  38875. }
  38876. // keep the current values inside the new range..
  38877. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38878. {
  38879. setValue (getValue(), false, false);
  38880. }
  38881. else
  38882. {
  38883. setMinValue (getMinValue(), false, false);
  38884. setMaxValue (getMaxValue(), false, false);
  38885. }
  38886. updateText();
  38887. }
  38888. }
  38889. void Slider::triggerChangeMessage (const bool synchronous)
  38890. {
  38891. if (synchronous)
  38892. handleAsyncUpdate();
  38893. else
  38894. triggerAsyncUpdate();
  38895. valueChanged();
  38896. }
  38897. void Slider::valueChanged (Value& value)
  38898. {
  38899. if (value.refersToSameSourceAs (currentValue))
  38900. {
  38901. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38902. setValue (currentValue.getValue(), false, false);
  38903. }
  38904. else if (value.refersToSameSourceAs (valueMin))
  38905. setMinValue (valueMin.getValue(), false, false, true);
  38906. else if (value.refersToSameSourceAs (valueMax))
  38907. setMaxValue (valueMax.getValue(), false, false, true);
  38908. }
  38909. double Slider::getValue() const
  38910. {
  38911. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38912. // methods to get the two values.
  38913. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38914. return currentValue.getValue();
  38915. }
  38916. void Slider::setValue (double newValue,
  38917. const bool sendUpdateMessage,
  38918. const bool sendMessageSynchronously)
  38919. {
  38920. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38921. // methods to set the two values.
  38922. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38923. newValue = constrainedValue (newValue);
  38924. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38925. {
  38926. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38927. newValue = jlimit ((double) valueMin.getValue(),
  38928. (double) valueMax.getValue(),
  38929. newValue);
  38930. }
  38931. if (newValue != lastCurrentValue)
  38932. {
  38933. if (valueBox != 0)
  38934. valueBox->hideEditor (true);
  38935. lastCurrentValue = newValue;
  38936. currentValue = newValue;
  38937. updateText();
  38938. repaint();
  38939. if (popupDisplay != 0)
  38940. {
  38941. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38942. ->updatePosition (getTextFromValue (newValue));
  38943. popupDisplay->repaint();
  38944. }
  38945. if (sendUpdateMessage)
  38946. triggerChangeMessage (sendMessageSynchronously);
  38947. }
  38948. }
  38949. double Slider::getMinValue() const
  38950. {
  38951. // The minimum value only applies to sliders that are in two- or three-value mode.
  38952. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38953. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38954. return valueMin.getValue();
  38955. }
  38956. double Slider::getMaxValue() const
  38957. {
  38958. // The maximum value only applies to sliders that are in two- or three-value mode.
  38959. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38960. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38961. return valueMax.getValue();
  38962. }
  38963. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38964. {
  38965. // The minimum value only applies to sliders that are in two- or three-value mode.
  38966. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38967. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38968. newValue = constrainedValue (newValue);
  38969. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38970. {
  38971. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  38972. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38973. newValue = jmin ((double) valueMax.getValue(), newValue);
  38974. }
  38975. else
  38976. {
  38977. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  38978. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38979. newValue = jmin (lastCurrentValue, newValue);
  38980. }
  38981. if (lastValueMin != newValue)
  38982. {
  38983. lastValueMin = newValue;
  38984. valueMin = newValue;
  38985. repaint();
  38986. if (popupDisplay != 0)
  38987. {
  38988. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38989. ->updatePosition (getTextFromValue (newValue));
  38990. popupDisplay->repaint();
  38991. }
  38992. if (sendUpdateMessage)
  38993. triggerChangeMessage (sendMessageSynchronously);
  38994. }
  38995. }
  38996. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38997. {
  38998. // The maximum value only applies to sliders that are in two- or three-value mode.
  38999. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39000. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39001. newValue = constrainedValue (newValue);
  39002. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39003. {
  39004. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39005. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39006. newValue = jmax ((double) valueMin.getValue(), newValue);
  39007. }
  39008. else
  39009. {
  39010. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39011. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39012. newValue = jmax (lastCurrentValue, newValue);
  39013. }
  39014. if (lastValueMax != newValue)
  39015. {
  39016. lastValueMax = newValue;
  39017. valueMax = newValue;
  39018. repaint();
  39019. if (popupDisplay != 0)
  39020. {
  39021. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39022. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39023. popupDisplay->repaint();
  39024. }
  39025. if (sendUpdateMessage)
  39026. triggerChangeMessage (sendMessageSynchronously);
  39027. }
  39028. }
  39029. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39030. const double valueToSetOnDoubleClick)
  39031. {
  39032. doubleClickToValue = isDoubleClickEnabled;
  39033. doubleClickReturnValue = valueToSetOnDoubleClick;
  39034. }
  39035. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39036. {
  39037. isEnabled_ = doubleClickToValue;
  39038. return doubleClickReturnValue;
  39039. }
  39040. void Slider::updateText()
  39041. {
  39042. if (valueBox != 0)
  39043. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39044. }
  39045. void Slider::setTextValueSuffix (const String& suffix)
  39046. {
  39047. if (textSuffix != suffix)
  39048. {
  39049. textSuffix = suffix;
  39050. updateText();
  39051. }
  39052. }
  39053. const String Slider::getTextValueSuffix() const
  39054. {
  39055. return textSuffix;
  39056. }
  39057. const String Slider::getTextFromValue (double v)
  39058. {
  39059. if (getNumDecimalPlacesToDisplay() > 0)
  39060. return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
  39061. else
  39062. return String (roundToInt (v)) + getTextValueSuffix();
  39063. }
  39064. double Slider::getValueFromText (const String& text)
  39065. {
  39066. String t (text.trimStart());
  39067. if (t.endsWith (textSuffix))
  39068. t = t.substring (0, t.length() - textSuffix.length());
  39069. while (t.startsWithChar ('+'))
  39070. t = t.substring (1).trimStart();
  39071. return t.initialSectionContainingOnly ("0123456789.,-")
  39072. .getDoubleValue();
  39073. }
  39074. double Slider::proportionOfLengthToValue (double proportion)
  39075. {
  39076. if (skewFactor != 1.0 && proportion > 0.0)
  39077. proportion = exp (log (proportion) / skewFactor);
  39078. return minimum + (maximum - minimum) * proportion;
  39079. }
  39080. double Slider::valueToProportionOfLength (double value)
  39081. {
  39082. const double n = (value - minimum) / (maximum - minimum);
  39083. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39084. }
  39085. double Slider::snapValue (double attemptedValue, const bool)
  39086. {
  39087. return attemptedValue;
  39088. }
  39089. void Slider::startedDragging()
  39090. {
  39091. }
  39092. void Slider::stoppedDragging()
  39093. {
  39094. }
  39095. void Slider::valueChanged()
  39096. {
  39097. }
  39098. void Slider::enablementChanged()
  39099. {
  39100. repaint();
  39101. }
  39102. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39103. {
  39104. menuEnabled = menuEnabled_;
  39105. }
  39106. void Slider::setScrollWheelEnabled (const bool enabled)
  39107. {
  39108. scrollWheelEnabled = enabled;
  39109. }
  39110. void Slider::labelTextChanged (Label* label)
  39111. {
  39112. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39113. if (newValue != (double) currentValue.getValue())
  39114. {
  39115. sendDragStart();
  39116. setValue (newValue, true, true);
  39117. sendDragEnd();
  39118. }
  39119. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39120. }
  39121. void Slider::buttonClicked (Button* button)
  39122. {
  39123. if (style == IncDecButtons)
  39124. {
  39125. sendDragStart();
  39126. if (button == incButton)
  39127. setValue (snapValue (getValue() + interval, false), true, true);
  39128. else if (button == decButton)
  39129. setValue (snapValue (getValue() - interval, false), true, true);
  39130. sendDragEnd();
  39131. }
  39132. }
  39133. double Slider::constrainedValue (double value) const
  39134. {
  39135. if (interval > 0)
  39136. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39137. if (value <= minimum || maximum <= minimum)
  39138. value = minimum;
  39139. else if (value >= maximum)
  39140. value = maximum;
  39141. return value;
  39142. }
  39143. float Slider::getLinearSliderPos (const double value)
  39144. {
  39145. double sliderPosProportional;
  39146. if (maximum > minimum)
  39147. {
  39148. if (value < minimum)
  39149. {
  39150. sliderPosProportional = 0.0;
  39151. }
  39152. else if (value > maximum)
  39153. {
  39154. sliderPosProportional = 1.0;
  39155. }
  39156. else
  39157. {
  39158. sliderPosProportional = valueToProportionOfLength (value);
  39159. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39160. }
  39161. }
  39162. else
  39163. {
  39164. sliderPosProportional = 0.5;
  39165. }
  39166. if (isVertical() || style == IncDecButtons)
  39167. sliderPosProportional = 1.0 - sliderPosProportional;
  39168. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39169. }
  39170. bool Slider::isHorizontal() const
  39171. {
  39172. return style == LinearHorizontal
  39173. || style == LinearBar
  39174. || style == TwoValueHorizontal
  39175. || style == ThreeValueHorizontal;
  39176. }
  39177. bool Slider::isVertical() const
  39178. {
  39179. return style == LinearVertical
  39180. || style == TwoValueVertical
  39181. || style == ThreeValueVertical;
  39182. }
  39183. bool Slider::incDecDragDirectionIsHorizontal() const
  39184. {
  39185. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39186. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39187. }
  39188. float Slider::getPositionOfValue (const double value)
  39189. {
  39190. if (isHorizontal() || isVertical())
  39191. {
  39192. return getLinearSliderPos (value);
  39193. }
  39194. else
  39195. {
  39196. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39197. return 0.0f;
  39198. }
  39199. }
  39200. void Slider::paint (Graphics& g)
  39201. {
  39202. if (style != IncDecButtons)
  39203. {
  39204. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39205. {
  39206. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39207. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39208. getLookAndFeel().drawRotarySlider (g,
  39209. sliderRect.getX(),
  39210. sliderRect.getY(),
  39211. sliderRect.getWidth(),
  39212. sliderRect.getHeight(),
  39213. sliderPos,
  39214. rotaryStart, rotaryEnd,
  39215. *this);
  39216. }
  39217. else
  39218. {
  39219. getLookAndFeel().drawLinearSlider (g,
  39220. sliderRect.getX(),
  39221. sliderRect.getY(),
  39222. sliderRect.getWidth(),
  39223. sliderRect.getHeight(),
  39224. getLinearSliderPos (lastCurrentValue),
  39225. getLinearSliderPos (lastValueMin),
  39226. getLinearSliderPos (lastValueMax),
  39227. style,
  39228. *this);
  39229. }
  39230. if (style == LinearBar && valueBox == 0)
  39231. {
  39232. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39233. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39234. }
  39235. }
  39236. }
  39237. void Slider::resized()
  39238. {
  39239. int minXSpace = 0;
  39240. int minYSpace = 0;
  39241. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39242. minXSpace = 30;
  39243. else
  39244. minYSpace = 15;
  39245. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39246. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39247. if (style == LinearBar)
  39248. {
  39249. if (valueBox != 0)
  39250. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39251. }
  39252. else
  39253. {
  39254. if (textBoxPos == NoTextBox)
  39255. {
  39256. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39257. }
  39258. else if (textBoxPos == TextBoxLeft)
  39259. {
  39260. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39261. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39262. }
  39263. else if (textBoxPos == TextBoxRight)
  39264. {
  39265. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39266. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39267. }
  39268. else if (textBoxPos == TextBoxAbove)
  39269. {
  39270. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39271. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39272. }
  39273. else if (textBoxPos == TextBoxBelow)
  39274. {
  39275. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39276. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39277. }
  39278. }
  39279. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39280. if (style == LinearBar)
  39281. {
  39282. const int barIndent = 1;
  39283. sliderRegionStart = barIndent;
  39284. sliderRegionSize = getWidth() - barIndent * 2;
  39285. sliderRect.setBounds (sliderRegionStart, barIndent,
  39286. sliderRegionSize, getHeight() - barIndent * 2);
  39287. }
  39288. else if (isHorizontal())
  39289. {
  39290. sliderRegionStart = sliderRect.getX() + indent;
  39291. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39292. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39293. sliderRegionSize, sliderRect.getHeight());
  39294. }
  39295. else if (isVertical())
  39296. {
  39297. sliderRegionStart = sliderRect.getY() + indent;
  39298. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39299. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39300. sliderRect.getWidth(), sliderRegionSize);
  39301. }
  39302. else
  39303. {
  39304. sliderRegionStart = 0;
  39305. sliderRegionSize = 100;
  39306. }
  39307. if (style == IncDecButtons)
  39308. {
  39309. Rectangle<int> buttonRect (sliderRect);
  39310. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39311. buttonRect.expand (-2, 0);
  39312. else
  39313. buttonRect.expand (0, -2);
  39314. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39315. if (incDecButtonsSideBySide)
  39316. {
  39317. decButton->setBounds (buttonRect.getX(),
  39318. buttonRect.getY(),
  39319. buttonRect.getWidth() / 2,
  39320. buttonRect.getHeight());
  39321. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39322. incButton->setBounds (buttonRect.getCentreX(),
  39323. buttonRect.getY(),
  39324. buttonRect.getWidth() / 2,
  39325. buttonRect.getHeight());
  39326. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39327. }
  39328. else
  39329. {
  39330. incButton->setBounds (buttonRect.getX(),
  39331. buttonRect.getY(),
  39332. buttonRect.getWidth(),
  39333. buttonRect.getHeight() / 2);
  39334. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39335. decButton->setBounds (buttonRect.getX(),
  39336. buttonRect.getCentreY(),
  39337. buttonRect.getWidth(),
  39338. buttonRect.getHeight() / 2);
  39339. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39340. }
  39341. }
  39342. }
  39343. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39344. {
  39345. repaint();
  39346. }
  39347. void Slider::mouseDown (const MouseEvent& e)
  39348. {
  39349. mouseWasHidden = false;
  39350. incDecDragged = false;
  39351. mouseXWhenLastDragged = e.x;
  39352. mouseYWhenLastDragged = e.y;
  39353. mouseDragStartX = e.getMouseDownX();
  39354. mouseDragStartY = e.getMouseDownY();
  39355. if (isEnabled())
  39356. {
  39357. if (e.mods.isPopupMenu() && menuEnabled)
  39358. {
  39359. menuShown = true;
  39360. PopupMenu m;
  39361. m.setLookAndFeel (&getLookAndFeel());
  39362. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39363. m.addSeparator();
  39364. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39365. {
  39366. PopupMenu rotaryMenu;
  39367. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39368. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39369. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39370. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39371. }
  39372. const int r = m.show();
  39373. if (r == 1)
  39374. {
  39375. setVelocityBasedMode (! isVelocityBased);
  39376. }
  39377. else if (r == 2)
  39378. {
  39379. setSliderStyle (Rotary);
  39380. }
  39381. else if (r == 3)
  39382. {
  39383. setSliderStyle (RotaryHorizontalDrag);
  39384. }
  39385. else if (r == 4)
  39386. {
  39387. setSliderStyle (RotaryVerticalDrag);
  39388. }
  39389. }
  39390. else if (maximum > minimum)
  39391. {
  39392. menuShown = false;
  39393. if (valueBox != 0)
  39394. valueBox->hideEditor (true);
  39395. sliderBeingDragged = 0;
  39396. if (style == TwoValueHorizontal
  39397. || style == TwoValueVertical
  39398. || style == ThreeValueHorizontal
  39399. || style == ThreeValueVertical)
  39400. {
  39401. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39402. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39403. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39404. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39405. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39406. {
  39407. if (maxPosDistance <= minPosDistance)
  39408. sliderBeingDragged = 2;
  39409. else
  39410. sliderBeingDragged = 1;
  39411. }
  39412. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39413. {
  39414. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39415. sliderBeingDragged = 1;
  39416. else if (normalPosDistance >= maxPosDistance)
  39417. sliderBeingDragged = 2;
  39418. }
  39419. }
  39420. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39421. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39422. * valueToProportionOfLength (currentValue.getValue());
  39423. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39424. : ((sliderBeingDragged == 1) ? valueMin
  39425. : currentValue)).getValue();
  39426. valueOnMouseDown = valueWhenLastDragged;
  39427. if (popupDisplayEnabled)
  39428. {
  39429. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39430. popupDisplay = popup;
  39431. if (parentForPopupDisplay != 0)
  39432. {
  39433. parentForPopupDisplay->addChildComponent (popup);
  39434. }
  39435. else
  39436. {
  39437. popup->addToDesktop (0);
  39438. }
  39439. popup->setVisible (true);
  39440. }
  39441. sendDragStart();
  39442. mouseDrag (e);
  39443. }
  39444. }
  39445. }
  39446. void Slider::mouseUp (const MouseEvent&)
  39447. {
  39448. if (isEnabled()
  39449. && (! menuShown)
  39450. && (maximum > minimum)
  39451. && (style != IncDecButtons || incDecDragged))
  39452. {
  39453. restoreMouseIfHidden();
  39454. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39455. triggerChangeMessage (false);
  39456. sendDragEnd();
  39457. popupDisplay = 0;
  39458. if (style == IncDecButtons)
  39459. {
  39460. incButton->setState (Button::buttonNormal);
  39461. decButton->setState (Button::buttonNormal);
  39462. }
  39463. }
  39464. }
  39465. void Slider::restoreMouseIfHidden()
  39466. {
  39467. if (mouseWasHidden)
  39468. {
  39469. mouseWasHidden = false;
  39470. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39471. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39472. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39473. : ((sliderBeingDragged == 1) ? getMinValue()
  39474. : (double) currentValue.getValue());
  39475. Point<int> mousePos;
  39476. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39477. {
  39478. mousePos = Desktop::getLastMouseDownPosition();
  39479. if (style == RotaryHorizontalDrag)
  39480. {
  39481. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39482. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39483. }
  39484. else
  39485. {
  39486. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39487. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39488. }
  39489. }
  39490. else
  39491. {
  39492. const int pixelPos = (int) getLinearSliderPos (pos);
  39493. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39494. isVertical() ? pixelPos : (getHeight() / 2)));
  39495. }
  39496. Desktop::setMousePosition (mousePos);
  39497. }
  39498. }
  39499. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39500. {
  39501. if (isEnabled()
  39502. && style != IncDecButtons
  39503. && style != Rotary
  39504. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39505. {
  39506. restoreMouseIfHidden();
  39507. }
  39508. }
  39509. static double smallestAngleBetween (double a1, double a2)
  39510. {
  39511. return jmin (fabs (a1 - a2),
  39512. fabs (a1 + double_Pi * 2.0 - a2),
  39513. fabs (a2 + double_Pi * 2.0 - a1));
  39514. }
  39515. void Slider::mouseDrag (const MouseEvent& e)
  39516. {
  39517. if (isEnabled()
  39518. && (! menuShown)
  39519. && (maximum > minimum))
  39520. {
  39521. if (style == Rotary)
  39522. {
  39523. int dx = e.x - sliderRect.getCentreX();
  39524. int dy = e.y - sliderRect.getCentreY();
  39525. if (dx * dx + dy * dy > 25)
  39526. {
  39527. double angle = atan2 ((double) dx, (double) -dy);
  39528. while (angle < 0.0)
  39529. angle += double_Pi * 2.0;
  39530. if (rotaryStop && ! e.mouseWasClicked())
  39531. {
  39532. if (fabs (angle - lastAngle) > double_Pi)
  39533. {
  39534. if (angle >= lastAngle)
  39535. angle -= double_Pi * 2.0;
  39536. else
  39537. angle += double_Pi * 2.0;
  39538. }
  39539. if (angle >= lastAngle)
  39540. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39541. else
  39542. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39543. }
  39544. else
  39545. {
  39546. while (angle < rotaryStart)
  39547. angle += double_Pi * 2.0;
  39548. if (angle > rotaryEnd)
  39549. {
  39550. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39551. angle = rotaryStart;
  39552. else
  39553. angle = rotaryEnd;
  39554. }
  39555. }
  39556. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39557. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39558. lastAngle = angle;
  39559. }
  39560. }
  39561. else
  39562. {
  39563. if (style == LinearBar && e.mouseWasClicked()
  39564. && valueBox != 0 && valueBox->isEditable())
  39565. return;
  39566. if (style == IncDecButtons && ! incDecDragged)
  39567. {
  39568. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39569. return;
  39570. incDecDragged = true;
  39571. mouseDragStartX = e.x;
  39572. mouseDragStartY = e.y;
  39573. }
  39574. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39575. : false))
  39576. || ((maximum - minimum) / sliderRegionSize < interval))
  39577. {
  39578. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39579. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39580. if (style == RotaryHorizontalDrag
  39581. || style == RotaryVerticalDrag
  39582. || style == IncDecButtons
  39583. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39584. && ! snapsToMousePos))
  39585. {
  39586. const int mouseDiff = (style == RotaryHorizontalDrag
  39587. || style == LinearHorizontal
  39588. || style == LinearBar
  39589. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39590. ? e.x - mouseDragStartX
  39591. : mouseDragStartY - e.y;
  39592. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39593. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39594. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39595. if (style == IncDecButtons)
  39596. {
  39597. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39598. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39599. }
  39600. }
  39601. else
  39602. {
  39603. if (isVertical())
  39604. scaledMousePos = 1.0 - scaledMousePos;
  39605. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39606. }
  39607. }
  39608. else
  39609. {
  39610. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39611. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39612. ? e.x - mouseXWhenLastDragged
  39613. : e.y - mouseYWhenLastDragged;
  39614. const double maxSpeed = jmax (200, sliderRegionSize);
  39615. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39616. if (speed != 0)
  39617. {
  39618. speed = 0.2 * velocityModeSensitivity
  39619. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39620. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39621. / maxSpeed))));
  39622. if (mouseDiff < 0)
  39623. speed = -speed;
  39624. if (isVertical() || style == RotaryVerticalDrag
  39625. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39626. speed = -speed;
  39627. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39628. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39629. e.source.enableUnboundedMouseMovement (true, false);
  39630. mouseWasHidden = true;
  39631. }
  39632. }
  39633. }
  39634. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39635. if (sliderBeingDragged == 0)
  39636. {
  39637. setValue (snapValue (valueWhenLastDragged, true),
  39638. ! sendChangeOnlyOnRelease, true);
  39639. }
  39640. else if (sliderBeingDragged == 1)
  39641. {
  39642. setMinValue (snapValue (valueWhenLastDragged, true),
  39643. ! sendChangeOnlyOnRelease, false, true);
  39644. if (e.mods.isShiftDown())
  39645. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39646. else
  39647. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39648. }
  39649. else
  39650. {
  39651. jassert (sliderBeingDragged == 2);
  39652. setMaxValue (snapValue (valueWhenLastDragged, true),
  39653. ! sendChangeOnlyOnRelease, false, true);
  39654. if (e.mods.isShiftDown())
  39655. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39656. else
  39657. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39658. }
  39659. mouseXWhenLastDragged = e.x;
  39660. mouseYWhenLastDragged = e.y;
  39661. }
  39662. }
  39663. void Slider::mouseDoubleClick (const MouseEvent&)
  39664. {
  39665. if (doubleClickToValue
  39666. && isEnabled()
  39667. && style != IncDecButtons
  39668. && minimum <= doubleClickReturnValue
  39669. && maximum >= doubleClickReturnValue)
  39670. {
  39671. sendDragStart();
  39672. setValue (doubleClickReturnValue, true, true);
  39673. sendDragEnd();
  39674. }
  39675. }
  39676. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39677. {
  39678. if (scrollWheelEnabled && isEnabled()
  39679. && style != TwoValueHorizontal
  39680. && style != TwoValueVertical)
  39681. {
  39682. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39683. {
  39684. if (valueBox != 0)
  39685. valueBox->hideEditor (false);
  39686. const double value = (double) currentValue.getValue();
  39687. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39688. const double currentPos = valueToProportionOfLength (value);
  39689. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39690. double delta = (newValue != value)
  39691. ? jmax (fabs (newValue - value), interval) : 0;
  39692. if (value > newValue)
  39693. delta = -delta;
  39694. sendDragStart();
  39695. setValue (snapValue (value + delta, false), true, true);
  39696. sendDragEnd();
  39697. }
  39698. }
  39699. else
  39700. {
  39701. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39702. }
  39703. }
  39704. void SliderListener::sliderDragStarted (Slider*)
  39705. {
  39706. }
  39707. void SliderListener::sliderDragEnded (Slider*)
  39708. {
  39709. }
  39710. END_JUCE_NAMESPACE
  39711. /*** End of inlined file: juce_Slider.cpp ***/
  39712. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39713. BEGIN_JUCE_NAMESPACE
  39714. class DragOverlayComp : public Component
  39715. {
  39716. public:
  39717. DragOverlayComp (Image* const image_)
  39718. : image (image_)
  39719. {
  39720. image->multiplyAllAlphas (0.8f);
  39721. setAlwaysOnTop (true);
  39722. }
  39723. ~DragOverlayComp()
  39724. {
  39725. }
  39726. void paint (Graphics& g)
  39727. {
  39728. g.drawImageAt (image, 0, 0);
  39729. }
  39730. private:
  39731. ScopedPointer <Image> image;
  39732. DragOverlayComp (const DragOverlayComp&);
  39733. DragOverlayComp& operator= (const DragOverlayComp&);
  39734. };
  39735. TableHeaderComponent::TableHeaderComponent()
  39736. : columnsChanged (false),
  39737. columnsResized (false),
  39738. sortChanged (false),
  39739. menuActive (true),
  39740. stretchToFit (false),
  39741. columnIdBeingResized (0),
  39742. columnIdBeingDragged (0),
  39743. columnIdUnderMouse (0),
  39744. lastDeliberateWidth (0)
  39745. {
  39746. }
  39747. TableHeaderComponent::~TableHeaderComponent()
  39748. {
  39749. dragOverlayComp = 0;
  39750. }
  39751. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39752. {
  39753. menuActive = hasMenu;
  39754. }
  39755. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39756. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39757. {
  39758. if (onlyCountVisibleColumns)
  39759. {
  39760. int num = 0;
  39761. for (int i = columns.size(); --i >= 0;)
  39762. if (columns.getUnchecked(i)->isVisible())
  39763. ++num;
  39764. return num;
  39765. }
  39766. else
  39767. {
  39768. return columns.size();
  39769. }
  39770. }
  39771. const String TableHeaderComponent::getColumnName (const int columnId) const
  39772. {
  39773. const ColumnInfo* const ci = getInfoForId (columnId);
  39774. return ci != 0 ? ci->name : String::empty;
  39775. }
  39776. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39777. {
  39778. ColumnInfo* const ci = getInfoForId (columnId);
  39779. if (ci != 0 && ci->name != newName)
  39780. {
  39781. ci->name = newName;
  39782. sendColumnsChanged();
  39783. }
  39784. }
  39785. void TableHeaderComponent::addColumn (const String& columnName,
  39786. const int columnId,
  39787. const int width,
  39788. const int minimumWidth,
  39789. const int maximumWidth,
  39790. const int propertyFlags,
  39791. const int insertIndex)
  39792. {
  39793. // can't have a duplicate or null ID!
  39794. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39795. jassert (width > 0);
  39796. ColumnInfo* const ci = new ColumnInfo();
  39797. ci->name = columnName;
  39798. ci->id = columnId;
  39799. ci->width = width;
  39800. ci->lastDeliberateWidth = width;
  39801. ci->minimumWidth = minimumWidth;
  39802. ci->maximumWidth = maximumWidth;
  39803. if (ci->maximumWidth < 0)
  39804. ci->maximumWidth = std::numeric_limits<int>::max();
  39805. jassert (ci->maximumWidth >= ci->minimumWidth);
  39806. ci->propertyFlags = propertyFlags;
  39807. columns.insert (insertIndex, ci);
  39808. sendColumnsChanged();
  39809. }
  39810. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39811. {
  39812. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39813. if (index >= 0)
  39814. {
  39815. columns.remove (index);
  39816. sortChanged = true;
  39817. sendColumnsChanged();
  39818. }
  39819. }
  39820. void TableHeaderComponent::removeAllColumns()
  39821. {
  39822. if (columns.size() > 0)
  39823. {
  39824. columns.clear();
  39825. sendColumnsChanged();
  39826. }
  39827. }
  39828. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39829. {
  39830. const int currentIndex = getIndexOfColumnId (columnId, false);
  39831. newIndex = visibleIndexToTotalIndex (newIndex);
  39832. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39833. {
  39834. columns.move (currentIndex, newIndex);
  39835. sendColumnsChanged();
  39836. }
  39837. }
  39838. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39839. {
  39840. const ColumnInfo* const ci = getInfoForId (columnId);
  39841. return ci != 0 ? ci->width : 0;
  39842. }
  39843. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39844. {
  39845. ColumnInfo* const ci = getInfoForId (columnId);
  39846. if (ci != 0 && ci->width != newWidth)
  39847. {
  39848. const int numColumns = getNumColumns (true);
  39849. ci->lastDeliberateWidth = ci->width
  39850. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39851. if (stretchToFit)
  39852. {
  39853. const int index = getIndexOfColumnId (columnId, true) + 1;
  39854. if (((unsigned int) index) < (unsigned int) numColumns)
  39855. {
  39856. const int x = getColumnPosition (index).getX();
  39857. if (lastDeliberateWidth == 0)
  39858. lastDeliberateWidth = getTotalWidth();
  39859. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39860. }
  39861. }
  39862. repaint();
  39863. columnsResized = true;
  39864. triggerAsyncUpdate();
  39865. }
  39866. }
  39867. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39868. {
  39869. int n = 0;
  39870. for (int i = 0; i < columns.size(); ++i)
  39871. {
  39872. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39873. {
  39874. if (columns.getUnchecked(i)->id == columnId)
  39875. return n;
  39876. ++n;
  39877. }
  39878. }
  39879. return -1;
  39880. }
  39881. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39882. {
  39883. if (onlyCountVisibleColumns)
  39884. index = visibleIndexToTotalIndex (index);
  39885. const ColumnInfo* const ci = columns [index];
  39886. return (ci != 0) ? ci->id : 0;
  39887. }
  39888. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39889. {
  39890. int x = 0, width = 0, n = 0;
  39891. for (int i = 0; i < columns.size(); ++i)
  39892. {
  39893. x += width;
  39894. if (columns.getUnchecked(i)->isVisible())
  39895. {
  39896. width = columns.getUnchecked(i)->width;
  39897. if (n++ == index)
  39898. break;
  39899. }
  39900. else
  39901. {
  39902. width = 0;
  39903. }
  39904. }
  39905. return Rectangle<int> (x, 0, width, getHeight());
  39906. }
  39907. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39908. {
  39909. if (xToFind >= 0)
  39910. {
  39911. int x = 0;
  39912. for (int i = 0; i < columns.size(); ++i)
  39913. {
  39914. const ColumnInfo* const ci = columns.getUnchecked(i);
  39915. if (ci->isVisible())
  39916. {
  39917. x += ci->width;
  39918. if (xToFind < x)
  39919. return ci->id;
  39920. }
  39921. }
  39922. }
  39923. return 0;
  39924. }
  39925. int TableHeaderComponent::getTotalWidth() const
  39926. {
  39927. int w = 0;
  39928. for (int i = columns.size(); --i >= 0;)
  39929. if (columns.getUnchecked(i)->isVisible())
  39930. w += columns.getUnchecked(i)->width;
  39931. return w;
  39932. }
  39933. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39934. {
  39935. stretchToFit = shouldStretchToFit;
  39936. lastDeliberateWidth = getTotalWidth();
  39937. resized();
  39938. }
  39939. bool TableHeaderComponent::isStretchToFitActive() const
  39940. {
  39941. return stretchToFit;
  39942. }
  39943. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39944. {
  39945. if (stretchToFit && getWidth() > 0
  39946. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39947. {
  39948. lastDeliberateWidth = targetTotalWidth;
  39949. resizeColumnsToFit (0, targetTotalWidth);
  39950. }
  39951. }
  39952. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39953. {
  39954. targetTotalWidth = jmax (targetTotalWidth, 0);
  39955. StretchableObjectResizer sor;
  39956. int i;
  39957. for (i = firstColumnIndex; i < columns.size(); ++i)
  39958. {
  39959. ColumnInfo* const ci = columns.getUnchecked(i);
  39960. if (ci->isVisible())
  39961. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39962. }
  39963. sor.resizeToFit (targetTotalWidth);
  39964. int visIndex = 0;
  39965. for (i = firstColumnIndex; i < columns.size(); ++i)
  39966. {
  39967. ColumnInfo* const ci = columns.getUnchecked(i);
  39968. if (ci->isVisible())
  39969. {
  39970. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  39971. (int) floor (sor.getItemSize (visIndex++)));
  39972. if (newWidth != ci->width)
  39973. {
  39974. ci->width = newWidth;
  39975. repaint();
  39976. columnsResized = true;
  39977. triggerAsyncUpdate();
  39978. }
  39979. }
  39980. }
  39981. }
  39982. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  39983. {
  39984. ColumnInfo* const ci = getInfoForId (columnId);
  39985. if (ci != 0 && shouldBeVisible != ci->isVisible())
  39986. {
  39987. if (shouldBeVisible)
  39988. ci->propertyFlags |= visible;
  39989. else
  39990. ci->propertyFlags &= ~visible;
  39991. sendColumnsChanged();
  39992. resized();
  39993. }
  39994. }
  39995. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  39996. {
  39997. const ColumnInfo* const ci = getInfoForId (columnId);
  39998. return ci != 0 && ci->isVisible();
  39999. }
  40000. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40001. {
  40002. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40003. {
  40004. for (int i = columns.size(); --i >= 0;)
  40005. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40006. ColumnInfo* const ci = getInfoForId (columnId);
  40007. if (ci != 0)
  40008. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40009. reSortTable();
  40010. }
  40011. }
  40012. int TableHeaderComponent::getSortColumnId() const
  40013. {
  40014. for (int i = columns.size(); --i >= 0;)
  40015. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40016. return columns.getUnchecked(i)->id;
  40017. return 0;
  40018. }
  40019. bool TableHeaderComponent::isSortedForwards() const
  40020. {
  40021. for (int i = columns.size(); --i >= 0;)
  40022. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40023. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40024. return true;
  40025. }
  40026. void TableHeaderComponent::reSortTable()
  40027. {
  40028. sortChanged = true;
  40029. repaint();
  40030. triggerAsyncUpdate();
  40031. }
  40032. const String TableHeaderComponent::toString() const
  40033. {
  40034. String s;
  40035. XmlElement doc ("TABLELAYOUT");
  40036. doc.setAttribute ("sortedCol", getSortColumnId());
  40037. doc.setAttribute ("sortForwards", isSortedForwards());
  40038. for (int i = 0; i < columns.size(); ++i)
  40039. {
  40040. const ColumnInfo* const ci = columns.getUnchecked (i);
  40041. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40042. e->setAttribute ("id", ci->id);
  40043. e->setAttribute ("visible", ci->isVisible());
  40044. e->setAttribute ("width", ci->width);
  40045. }
  40046. return doc.createDocument (String::empty, true, false);
  40047. }
  40048. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40049. {
  40050. XmlDocument doc (storedVersion);
  40051. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40052. int index = 0;
  40053. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40054. {
  40055. forEachXmlChildElement (*storedXml, col)
  40056. {
  40057. const int tabId = col->getIntAttribute ("id");
  40058. ColumnInfo* const ci = getInfoForId (tabId);
  40059. if (ci != 0)
  40060. {
  40061. columns.move (columns.indexOf (ci), index);
  40062. ci->width = col->getIntAttribute ("width");
  40063. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40064. }
  40065. ++index;
  40066. }
  40067. columnsResized = true;
  40068. sendColumnsChanged();
  40069. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40070. storedXml->getBoolAttribute ("sortForwards", true));
  40071. }
  40072. }
  40073. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40074. {
  40075. listeners.addIfNotAlreadyThere (newListener);
  40076. }
  40077. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40078. {
  40079. listeners.removeValue (listenerToRemove);
  40080. }
  40081. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40082. {
  40083. const ColumnInfo* const ci = getInfoForId (columnId);
  40084. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40085. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40086. }
  40087. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40088. {
  40089. for (int i = 0; i < columns.size(); ++i)
  40090. {
  40091. const ColumnInfo* const ci = columns.getUnchecked(i);
  40092. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40093. menu.addItem (ci->id, ci->name,
  40094. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40095. isColumnVisible (ci->id));
  40096. }
  40097. }
  40098. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40099. {
  40100. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40101. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40102. }
  40103. void TableHeaderComponent::paint (Graphics& g)
  40104. {
  40105. LookAndFeel& lf = getLookAndFeel();
  40106. lf.drawTableHeaderBackground (g, *this);
  40107. const Rectangle<int> clip (g.getClipBounds());
  40108. int x = 0;
  40109. for (int i = 0; i < columns.size(); ++i)
  40110. {
  40111. const ColumnInfo* const ci = columns.getUnchecked(i);
  40112. if (ci->isVisible())
  40113. {
  40114. if (x + ci->width > clip.getX()
  40115. && (ci->id != columnIdBeingDragged
  40116. || dragOverlayComp == 0
  40117. || ! dragOverlayComp->isVisible()))
  40118. {
  40119. g.saveState();
  40120. g.setOrigin (x, 0);
  40121. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40122. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40123. ci->id == columnIdUnderMouse,
  40124. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40125. ci->propertyFlags);
  40126. g.restoreState();
  40127. }
  40128. x += ci->width;
  40129. if (x >= clip.getRight())
  40130. break;
  40131. }
  40132. }
  40133. }
  40134. void TableHeaderComponent::resized()
  40135. {
  40136. }
  40137. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40138. {
  40139. updateColumnUnderMouse (e.x, e.y);
  40140. }
  40141. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40142. {
  40143. updateColumnUnderMouse (e.x, e.y);
  40144. }
  40145. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40146. {
  40147. updateColumnUnderMouse (e.x, e.y);
  40148. }
  40149. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40150. {
  40151. repaint();
  40152. columnIdBeingResized = 0;
  40153. columnIdBeingDragged = 0;
  40154. if (columnIdUnderMouse != 0)
  40155. {
  40156. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40157. if (e.mods.isPopupMenu())
  40158. columnClicked (columnIdUnderMouse, e.mods);
  40159. }
  40160. if (menuActive && e.mods.isPopupMenu())
  40161. showColumnChooserMenu (columnIdUnderMouse);
  40162. }
  40163. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40164. {
  40165. if (columnIdBeingResized == 0
  40166. && columnIdBeingDragged == 0
  40167. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40168. {
  40169. dragOverlayComp = 0;
  40170. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40171. if (columnIdBeingResized != 0)
  40172. {
  40173. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40174. initialColumnWidth = ci->width;
  40175. }
  40176. else
  40177. {
  40178. beginDrag (e);
  40179. }
  40180. }
  40181. if (columnIdBeingResized != 0)
  40182. {
  40183. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40184. if (ci != 0)
  40185. {
  40186. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40187. initialColumnWidth + e.getDistanceFromDragStartX());
  40188. if (stretchToFit)
  40189. {
  40190. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40191. int minWidthOnRight = 0;
  40192. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40193. if (columns.getUnchecked (i)->isVisible())
  40194. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40195. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40196. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40197. }
  40198. setColumnWidth (columnIdBeingResized, w);
  40199. }
  40200. }
  40201. else if (columnIdBeingDragged != 0)
  40202. {
  40203. if (e.y >= -50 && e.y < getHeight() + 50)
  40204. {
  40205. if (dragOverlayComp != 0)
  40206. {
  40207. dragOverlayComp->setVisible (true);
  40208. dragOverlayComp->setBounds (jlimit (0,
  40209. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40210. e.x - draggingColumnOffset),
  40211. 0,
  40212. dragOverlayComp->getWidth(),
  40213. getHeight());
  40214. for (int i = columns.size(); --i >= 0;)
  40215. {
  40216. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40217. int newIndex = currentIndex;
  40218. if (newIndex > 0)
  40219. {
  40220. // if the previous column isn't draggable, we can't move our column
  40221. // past it, because that'd change the undraggable column's position..
  40222. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40223. if ((previous->propertyFlags & draggable) != 0)
  40224. {
  40225. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40226. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40227. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40228. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40229. {
  40230. --newIndex;
  40231. }
  40232. }
  40233. }
  40234. if (newIndex < columns.size() - 1)
  40235. {
  40236. // if the next column isn't draggable, we can't move our column
  40237. // past it, because that'd change the undraggable column's position..
  40238. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40239. if ((nextCol->propertyFlags & draggable) != 0)
  40240. {
  40241. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40242. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40243. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40244. > abs (dragOverlayComp->getRight() - rightOfNext))
  40245. {
  40246. ++newIndex;
  40247. }
  40248. }
  40249. }
  40250. if (newIndex != currentIndex)
  40251. moveColumn (columnIdBeingDragged, newIndex);
  40252. else
  40253. break;
  40254. }
  40255. }
  40256. }
  40257. else
  40258. {
  40259. endDrag (draggingColumnOriginalIndex);
  40260. }
  40261. }
  40262. }
  40263. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40264. {
  40265. if (columnIdBeingDragged == 0)
  40266. {
  40267. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40268. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40269. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40270. {
  40271. columnIdBeingDragged = 0;
  40272. }
  40273. else
  40274. {
  40275. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40276. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40277. const int temp = columnIdBeingDragged;
  40278. columnIdBeingDragged = 0;
  40279. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40280. columnIdBeingDragged = temp;
  40281. dragOverlayComp->setBounds (columnRect);
  40282. for (int i = listeners.size(); --i >= 0;)
  40283. {
  40284. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40285. i = jmin (i, listeners.size() - 1);
  40286. }
  40287. }
  40288. }
  40289. }
  40290. void TableHeaderComponent::endDrag (const int finalIndex)
  40291. {
  40292. if (columnIdBeingDragged != 0)
  40293. {
  40294. moveColumn (columnIdBeingDragged, finalIndex);
  40295. columnIdBeingDragged = 0;
  40296. repaint();
  40297. for (int i = listeners.size(); --i >= 0;)
  40298. {
  40299. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40300. i = jmin (i, listeners.size() - 1);
  40301. }
  40302. }
  40303. }
  40304. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40305. {
  40306. mouseDrag (e);
  40307. for (int i = columns.size(); --i >= 0;)
  40308. if (columns.getUnchecked (i)->isVisible())
  40309. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40310. columnIdBeingResized = 0;
  40311. repaint();
  40312. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40313. updateColumnUnderMouse (e.x, e.y);
  40314. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40315. columnClicked (columnIdUnderMouse, e.mods);
  40316. dragOverlayComp = 0;
  40317. }
  40318. const MouseCursor TableHeaderComponent::getMouseCursor()
  40319. {
  40320. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40321. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40322. return Component::getMouseCursor();
  40323. }
  40324. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40325. {
  40326. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40327. }
  40328. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40329. {
  40330. for (int i = columns.size(); --i >= 0;)
  40331. if (columns.getUnchecked(i)->id == id)
  40332. return columns.getUnchecked(i);
  40333. return 0;
  40334. }
  40335. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40336. {
  40337. int n = 0;
  40338. for (int i = 0; i < columns.size(); ++i)
  40339. {
  40340. if (columns.getUnchecked(i)->isVisible())
  40341. {
  40342. if (n == visibleIndex)
  40343. return i;
  40344. ++n;
  40345. }
  40346. }
  40347. return -1;
  40348. }
  40349. void TableHeaderComponent::sendColumnsChanged()
  40350. {
  40351. if (stretchToFit && lastDeliberateWidth > 0)
  40352. resizeAllColumnsToFit (lastDeliberateWidth);
  40353. repaint();
  40354. columnsChanged = true;
  40355. triggerAsyncUpdate();
  40356. }
  40357. void TableHeaderComponent::handleAsyncUpdate()
  40358. {
  40359. const bool changed = columnsChanged || sortChanged;
  40360. const bool sized = columnsResized || changed;
  40361. const bool sorted = sortChanged;
  40362. columnsChanged = false;
  40363. columnsResized = false;
  40364. sortChanged = false;
  40365. if (sorted)
  40366. {
  40367. for (int i = listeners.size(); --i >= 0;)
  40368. {
  40369. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40370. i = jmin (i, listeners.size() - 1);
  40371. }
  40372. }
  40373. if (changed)
  40374. {
  40375. for (int i = listeners.size(); --i >= 0;)
  40376. {
  40377. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40378. i = jmin (i, listeners.size() - 1);
  40379. }
  40380. }
  40381. if (sized)
  40382. {
  40383. for (int i = listeners.size(); --i >= 0;)
  40384. {
  40385. listeners.getUnchecked(i)->tableColumnsResized (this);
  40386. i = jmin (i, listeners.size() - 1);
  40387. }
  40388. }
  40389. }
  40390. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40391. {
  40392. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40393. {
  40394. const int draggableDistance = 3;
  40395. int x = 0;
  40396. for (int i = 0; i < columns.size(); ++i)
  40397. {
  40398. const ColumnInfo* const ci = columns.getUnchecked(i);
  40399. if (ci->isVisible())
  40400. {
  40401. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40402. && (ci->propertyFlags & resizable) != 0)
  40403. return ci->id;
  40404. x += ci->width;
  40405. }
  40406. }
  40407. }
  40408. return 0;
  40409. }
  40410. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40411. {
  40412. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40413. ? getColumnIdAtX (x) : 0;
  40414. if (newCol != columnIdUnderMouse)
  40415. {
  40416. columnIdUnderMouse = newCol;
  40417. repaint();
  40418. }
  40419. }
  40420. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40421. {
  40422. PopupMenu m;
  40423. addMenuItems (m, columnIdClicked);
  40424. if (m.getNumItems() > 0)
  40425. {
  40426. m.setLookAndFeel (&getLookAndFeel());
  40427. const int result = m.show();
  40428. if (result != 0)
  40429. reactToMenuItem (result, columnIdClicked);
  40430. }
  40431. }
  40432. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40433. {
  40434. }
  40435. END_JUCE_NAMESPACE
  40436. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40437. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40438. BEGIN_JUCE_NAMESPACE
  40439. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40440. class TableListRowComp : public Component,
  40441. public TooltipClient
  40442. {
  40443. public:
  40444. TableListRowComp (TableListBox& owner_)
  40445. : owner (owner_),
  40446. row (-1),
  40447. isSelected (false)
  40448. {
  40449. }
  40450. ~TableListRowComp()
  40451. {
  40452. deleteAllChildren();
  40453. }
  40454. void paint (Graphics& g)
  40455. {
  40456. TableListBoxModel* const model = owner.getModel();
  40457. if (model != 0)
  40458. {
  40459. const TableHeaderComponent* const header = owner.getHeader();
  40460. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40461. const int numColumns = header->getNumColumns (true);
  40462. for (int i = 0; i < numColumns; ++i)
  40463. {
  40464. if (! columnsWithComponents [i])
  40465. {
  40466. const int columnId = header->getColumnIdOfIndex (i, true);
  40467. Rectangle<int> columnRect (header->getColumnPosition (i));
  40468. columnRect.setSize (columnRect.getWidth(), getHeight());
  40469. g.saveState();
  40470. g.reduceClipRegion (columnRect);
  40471. g.setOrigin (columnRect.getX(), 0);
  40472. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40473. g.restoreState();
  40474. }
  40475. }
  40476. }
  40477. }
  40478. void update (const int newRow, const bool isNowSelected)
  40479. {
  40480. if (newRow != row || isNowSelected != isSelected)
  40481. {
  40482. row = newRow;
  40483. isSelected = isNowSelected;
  40484. repaint();
  40485. }
  40486. if (row < owner.getNumRows())
  40487. {
  40488. jassert (row >= 0);
  40489. const var::identifier tagPropertyName ("_tableLastUseNum");
  40490. const int newTag = Random::getSystemRandom().nextInt();
  40491. const TableHeaderComponent* const header = owner.getHeader();
  40492. const int numColumns = header->getNumColumns (true);
  40493. int i;
  40494. columnsWithComponents.clear();
  40495. if (owner.getModel() != 0)
  40496. {
  40497. for (i = 0; i < numColumns; ++i)
  40498. {
  40499. const int columnId = header->getColumnIdOfIndex (i, true);
  40500. Component* const newComp
  40501. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40502. findChildComponentForColumn (columnId));
  40503. if (newComp != 0)
  40504. {
  40505. addAndMakeVisible (newComp);
  40506. newComp->getProperties().set (tagPropertyName, newTag);
  40507. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40508. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40509. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40510. columnsWithComponents.setBit (i);
  40511. }
  40512. }
  40513. }
  40514. for (i = getNumChildComponents(); --i >= 0;)
  40515. {
  40516. Component* const c = getChildComponent (i);
  40517. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40518. delete c;
  40519. }
  40520. }
  40521. else
  40522. {
  40523. columnsWithComponents.clear();
  40524. deleteAllChildren();
  40525. }
  40526. }
  40527. void resized()
  40528. {
  40529. for (int i = getNumChildComponents(); --i >= 0;)
  40530. {
  40531. Component* const c = getChildComponent (i);
  40532. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40533. if (columnId != 0)
  40534. {
  40535. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40536. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40537. }
  40538. }
  40539. }
  40540. void mouseDown (const MouseEvent& e)
  40541. {
  40542. isDragging = false;
  40543. selectRowOnMouseUp = false;
  40544. if (isEnabled())
  40545. {
  40546. if (! isSelected)
  40547. {
  40548. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40549. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40550. if (columnId != 0 && owner.getModel() != 0)
  40551. owner.getModel()->cellClicked (row, columnId, e);
  40552. }
  40553. else
  40554. {
  40555. selectRowOnMouseUp = true;
  40556. }
  40557. }
  40558. }
  40559. void mouseDrag (const MouseEvent& e)
  40560. {
  40561. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40562. {
  40563. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40564. if (selectedRows.size() > 0)
  40565. {
  40566. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40567. if (dragDescription.isNotEmpty())
  40568. {
  40569. isDragging = true;
  40570. owner.startDragAndDrop (e, dragDescription);
  40571. }
  40572. }
  40573. }
  40574. }
  40575. void mouseUp (const MouseEvent& e)
  40576. {
  40577. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40578. {
  40579. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40580. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40581. if (columnId != 0 && owner.getModel() != 0)
  40582. owner.getModel()->cellClicked (row, columnId, e);
  40583. }
  40584. }
  40585. void mouseDoubleClick (const MouseEvent& e)
  40586. {
  40587. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40588. if (columnId != 0 && owner.getModel() != 0)
  40589. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40590. }
  40591. const String getTooltip()
  40592. {
  40593. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40594. if (columnId != 0 && owner.getModel() != 0)
  40595. return owner.getModel()->getCellTooltip (row, columnId);
  40596. return String::empty;
  40597. }
  40598. juce_UseDebuggingNewOperator
  40599. private:
  40600. TableListBox& owner;
  40601. int row;
  40602. bool isSelected, isDragging, selectRowOnMouseUp;
  40603. BigInteger columnsWithComponents;
  40604. Component* findChildComponentForColumn (const int columnId) const
  40605. {
  40606. for (int i = getNumChildComponents(); --i >= 0;)
  40607. {
  40608. Component* const c = getChildComponent (i);
  40609. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40610. return c;
  40611. }
  40612. return 0;
  40613. }
  40614. TableListRowComp (const TableListRowComp&);
  40615. TableListRowComp& operator= (const TableListRowComp&);
  40616. };
  40617. class TableListBoxHeader : public TableHeaderComponent
  40618. {
  40619. public:
  40620. TableListBoxHeader (TableListBox& owner_)
  40621. : owner (owner_)
  40622. {
  40623. }
  40624. ~TableListBoxHeader()
  40625. {
  40626. }
  40627. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40628. {
  40629. if (owner.isAutoSizeMenuOptionShown())
  40630. {
  40631. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40632. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40633. menu.addSeparator();
  40634. }
  40635. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40636. }
  40637. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40638. {
  40639. if (menuReturnId == 0xf836743)
  40640. {
  40641. owner.autoSizeColumn (columnIdClicked);
  40642. }
  40643. else if (menuReturnId == 0xf836744)
  40644. {
  40645. owner.autoSizeAllColumns();
  40646. }
  40647. else
  40648. {
  40649. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40650. }
  40651. }
  40652. juce_UseDebuggingNewOperator
  40653. private:
  40654. TableListBox& owner;
  40655. TableListBoxHeader (const TableListBoxHeader&);
  40656. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40657. };
  40658. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40659. : ListBox (name, 0),
  40660. model (model_),
  40661. autoSizeOptionsShown (true)
  40662. {
  40663. ListBox::model = this;
  40664. header = new TableListBoxHeader (*this);
  40665. header->setSize (100, 28);
  40666. header->addListener (this);
  40667. setHeaderComponent (header);
  40668. }
  40669. TableListBox::~TableListBox()
  40670. {
  40671. deleteAllChildren();
  40672. }
  40673. void TableListBox::setModel (TableListBoxModel* const newModel)
  40674. {
  40675. if (model != newModel)
  40676. {
  40677. model = newModel;
  40678. updateContent();
  40679. }
  40680. }
  40681. int TableListBox::getHeaderHeight() const
  40682. {
  40683. return header->getHeight();
  40684. }
  40685. void TableListBox::setHeaderHeight (const int newHeight)
  40686. {
  40687. header->setSize (header->getWidth(), newHeight);
  40688. resized();
  40689. }
  40690. void TableListBox::autoSizeColumn (const int columnId)
  40691. {
  40692. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40693. if (width > 0)
  40694. header->setColumnWidth (columnId, width);
  40695. }
  40696. void TableListBox::autoSizeAllColumns()
  40697. {
  40698. for (int i = 0; i < header->getNumColumns (true); ++i)
  40699. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40700. }
  40701. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40702. {
  40703. autoSizeOptionsShown = shouldBeShown;
  40704. }
  40705. bool TableListBox::isAutoSizeMenuOptionShown() const
  40706. {
  40707. return autoSizeOptionsShown;
  40708. }
  40709. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40710. const int rowNumber,
  40711. const bool relativeToComponentTopLeft) const
  40712. {
  40713. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40714. if (relativeToComponentTopLeft)
  40715. headerCell.translate (header->getX(), 0);
  40716. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40717. return Rectangle<int> (headerCell.getX(), row.getY(),
  40718. headerCell.getWidth(), row.getHeight());
  40719. }
  40720. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40721. {
  40722. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40723. if (scrollbar != 0)
  40724. {
  40725. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40726. double x = scrollbar->getCurrentRangeStart();
  40727. const double w = scrollbar->getCurrentRangeSize();
  40728. if (pos.getX() < x)
  40729. x = pos.getX();
  40730. else if (pos.getRight() > x + w)
  40731. x += jmax (0.0, pos.getRight() - (x + w));
  40732. scrollbar->setCurrentRangeStart (x);
  40733. }
  40734. }
  40735. int TableListBox::getNumRows()
  40736. {
  40737. return model != 0 ? model->getNumRows() : 0;
  40738. }
  40739. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40740. {
  40741. }
  40742. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40743. {
  40744. if (existingComponentToUpdate == 0)
  40745. existingComponentToUpdate = new TableListRowComp (*this);
  40746. static_cast <TableListRowComp*> (existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40747. return existingComponentToUpdate;
  40748. }
  40749. void TableListBox::selectedRowsChanged (int row)
  40750. {
  40751. if (model != 0)
  40752. model->selectedRowsChanged (row);
  40753. }
  40754. void TableListBox::deleteKeyPressed (int row)
  40755. {
  40756. if (model != 0)
  40757. model->deleteKeyPressed (row);
  40758. }
  40759. void TableListBox::returnKeyPressed (int row)
  40760. {
  40761. if (model != 0)
  40762. model->returnKeyPressed (row);
  40763. }
  40764. void TableListBox::backgroundClicked()
  40765. {
  40766. if (model != 0)
  40767. model->backgroundClicked();
  40768. }
  40769. void TableListBox::listWasScrolled()
  40770. {
  40771. if (model != 0)
  40772. model->listWasScrolled();
  40773. }
  40774. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40775. {
  40776. setMinimumContentWidth (header->getTotalWidth());
  40777. repaint();
  40778. updateColumnComponents();
  40779. }
  40780. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40781. {
  40782. setMinimumContentWidth (header->getTotalWidth());
  40783. repaint();
  40784. updateColumnComponents();
  40785. }
  40786. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40787. {
  40788. if (model != 0)
  40789. model->sortOrderChanged (header->getSortColumnId(),
  40790. header->isSortedForwards());
  40791. }
  40792. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40793. {
  40794. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40795. repaint();
  40796. }
  40797. void TableListBox::resized()
  40798. {
  40799. ListBox::resized();
  40800. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40801. setMinimumContentWidth (header->getTotalWidth());
  40802. }
  40803. void TableListBox::updateColumnComponents() const
  40804. {
  40805. const int firstRow = getRowContainingPosition (0, 0);
  40806. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40807. {
  40808. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40809. if (rowComp != 0)
  40810. rowComp->resized();
  40811. }
  40812. }
  40813. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40814. {
  40815. }
  40816. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40817. {
  40818. }
  40819. void TableListBoxModel::backgroundClicked()
  40820. {
  40821. }
  40822. void TableListBoxModel::sortOrderChanged (int, const bool)
  40823. {
  40824. }
  40825. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40826. {
  40827. return 0;
  40828. }
  40829. void TableListBoxModel::selectedRowsChanged (int)
  40830. {
  40831. }
  40832. void TableListBoxModel::deleteKeyPressed (int)
  40833. {
  40834. }
  40835. void TableListBoxModel::returnKeyPressed (int)
  40836. {
  40837. }
  40838. void TableListBoxModel::listWasScrolled()
  40839. {
  40840. }
  40841. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40842. {
  40843. return String::empty;
  40844. }
  40845. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40846. {
  40847. return String::empty;
  40848. }
  40849. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40850. {
  40851. (void) existingComponentToUpdate;
  40852. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40853. return 0;
  40854. }
  40855. END_JUCE_NAMESPACE
  40856. /*** End of inlined file: juce_TableListBox.cpp ***/
  40857. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40858. BEGIN_JUCE_NAMESPACE
  40859. // a word or space that can't be broken down any further
  40860. struct TextAtom
  40861. {
  40862. String atomText;
  40863. float width;
  40864. uint16 numChars;
  40865. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40866. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40867. const String getText (const juce_wchar passwordCharacter) const
  40868. {
  40869. if (passwordCharacter == 0)
  40870. return atomText;
  40871. else
  40872. return String::repeatedString (String::charToString (passwordCharacter),
  40873. atomText.length());
  40874. }
  40875. const String getTrimmedText (const juce_wchar passwordCharacter) const
  40876. {
  40877. if (passwordCharacter == 0)
  40878. return atomText.substring (0, numChars);
  40879. else if (isNewLine())
  40880. return String::empty;
  40881. else
  40882. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40883. }
  40884. };
  40885. // a run of text with a single font and colour
  40886. class TextEditor::UniformTextSection
  40887. {
  40888. public:
  40889. UniformTextSection (const String& text,
  40890. const Font& font_,
  40891. const Colour& colour_,
  40892. const juce_wchar passwordCharacter)
  40893. : font (font_),
  40894. colour (colour_)
  40895. {
  40896. initialiseAtoms (text, passwordCharacter);
  40897. }
  40898. UniformTextSection (const UniformTextSection& other)
  40899. : font (other.font),
  40900. colour (other.colour)
  40901. {
  40902. atoms.ensureStorageAllocated (other.atoms.size());
  40903. for (int i = 0; i < other.atoms.size(); ++i)
  40904. atoms.add (new TextAtom (*other.atoms.getUnchecked(i)));
  40905. }
  40906. ~UniformTextSection()
  40907. {
  40908. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40909. }
  40910. void clear()
  40911. {
  40912. for (int i = atoms.size(); --i >= 0;)
  40913. delete getAtom(i);
  40914. atoms.clear();
  40915. }
  40916. int getNumAtoms() const
  40917. {
  40918. return atoms.size();
  40919. }
  40920. TextAtom* getAtom (const int index) const throw()
  40921. {
  40922. return atoms.getUnchecked (index);
  40923. }
  40924. void append (const UniformTextSection& other, const juce_wchar passwordCharacter)
  40925. {
  40926. if (other.atoms.size() > 0)
  40927. {
  40928. TextAtom* const lastAtom = atoms.getLast();
  40929. int i = 0;
  40930. if (lastAtom != 0)
  40931. {
  40932. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40933. {
  40934. TextAtom* const first = other.getAtom(0);
  40935. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40936. {
  40937. lastAtom->atomText += first->atomText;
  40938. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40939. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40940. delete first;
  40941. ++i;
  40942. }
  40943. }
  40944. }
  40945. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40946. while (i < other.atoms.size())
  40947. {
  40948. atoms.add (other.getAtom(i));
  40949. ++i;
  40950. }
  40951. }
  40952. }
  40953. UniformTextSection* split (const int indexToBreakAt,
  40954. const juce_wchar passwordCharacter)
  40955. {
  40956. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40957. font, colour,
  40958. passwordCharacter);
  40959. int index = 0;
  40960. for (int i = 0; i < atoms.size(); ++i)
  40961. {
  40962. TextAtom* const atom = getAtom(i);
  40963. const int nextIndex = index + atom->numChars;
  40964. if (index == indexToBreakAt)
  40965. {
  40966. int j;
  40967. for (j = i; j < atoms.size(); ++j)
  40968. section2->atoms.add (getAtom (j));
  40969. for (j = atoms.size(); --j >= i;)
  40970. atoms.remove (j);
  40971. break;
  40972. }
  40973. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  40974. {
  40975. TextAtom* const secondAtom = new TextAtom();
  40976. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  40977. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  40978. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  40979. section2->atoms.add (secondAtom);
  40980. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  40981. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  40982. atom->numChars = (uint16) (indexToBreakAt - index);
  40983. int j;
  40984. for (j = i + 1; j < atoms.size(); ++j)
  40985. section2->atoms.add (getAtom (j));
  40986. for (j = atoms.size(); --j > i;)
  40987. atoms.remove (j);
  40988. break;
  40989. }
  40990. index = nextIndex;
  40991. }
  40992. return section2;
  40993. }
  40994. void appendAllText (String::Concatenator& concatenator) const
  40995. {
  40996. for (int i = 0; i < atoms.size(); ++i)
  40997. concatenator.append (getAtom(i)->atomText);
  40998. }
  40999. void appendSubstring (String::Concatenator& concatenator,
  41000. const Range<int>& range) const
  41001. {
  41002. int index = 0;
  41003. for (int i = 0; i < atoms.size(); ++i)
  41004. {
  41005. const TextAtom* const atom = getAtom (i);
  41006. const int nextIndex = index + atom->numChars;
  41007. if (range.getStart() < nextIndex)
  41008. {
  41009. if (range.getEnd() <= index)
  41010. break;
  41011. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41012. if (! r.isEmpty())
  41013. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41014. }
  41015. index = nextIndex;
  41016. }
  41017. }
  41018. int getTotalLength() const
  41019. {
  41020. int total = 0;
  41021. for (int i = atoms.size(); --i >= 0;)
  41022. total += getAtom(i)->numChars;
  41023. return total;
  41024. }
  41025. void setFont (const Font& newFont,
  41026. const juce_wchar passwordCharacter)
  41027. {
  41028. if (font != newFont)
  41029. {
  41030. font = newFont;
  41031. for (int i = atoms.size(); --i >= 0;)
  41032. {
  41033. TextAtom* const atom = atoms.getUnchecked(i);
  41034. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41035. }
  41036. }
  41037. }
  41038. juce_UseDebuggingNewOperator
  41039. Font font;
  41040. Colour colour;
  41041. private:
  41042. Array <TextAtom*> atoms;
  41043. void initialiseAtoms (const String& textToParse,
  41044. const juce_wchar passwordCharacter)
  41045. {
  41046. int i = 0;
  41047. const int len = textToParse.length();
  41048. const juce_wchar* const text = textToParse;
  41049. while (i < len)
  41050. {
  41051. int start = i;
  41052. // create a whitespace atom unless it starts with non-ws
  41053. if (CharacterFunctions::isWhitespace (text[i])
  41054. && text[i] != '\r'
  41055. && text[i] != '\n')
  41056. {
  41057. while (i < len
  41058. && CharacterFunctions::isWhitespace (text[i])
  41059. && text[i] != '\r'
  41060. && text[i] != '\n')
  41061. {
  41062. ++i;
  41063. }
  41064. }
  41065. else
  41066. {
  41067. if (text[i] == '\r')
  41068. {
  41069. ++i;
  41070. if ((i < len) && (text[i] == '\n'))
  41071. {
  41072. ++start;
  41073. ++i;
  41074. }
  41075. }
  41076. else if (text[i] == '\n')
  41077. {
  41078. ++i;
  41079. }
  41080. else
  41081. {
  41082. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41083. ++i;
  41084. }
  41085. }
  41086. TextAtom* const atom = new TextAtom();
  41087. atom->atomText = String (text + start, i - start);
  41088. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41089. atom->numChars = (uint16) (i - start);
  41090. atoms.add (atom);
  41091. }
  41092. }
  41093. UniformTextSection& operator= (const UniformTextSection& other);
  41094. };
  41095. class TextEditor::Iterator
  41096. {
  41097. public:
  41098. Iterator (const Array <UniformTextSection*>& sections_,
  41099. const float wordWrapWidth_,
  41100. const juce_wchar passwordCharacter_)
  41101. : indexInText (0),
  41102. lineY (0),
  41103. lineHeight (0),
  41104. maxDescent (0),
  41105. atomX (0),
  41106. atomRight (0),
  41107. atom (0),
  41108. currentSection (0),
  41109. sections (sections_),
  41110. sectionIndex (0),
  41111. atomIndex (0),
  41112. wordWrapWidth (wordWrapWidth_),
  41113. passwordCharacter (passwordCharacter_)
  41114. {
  41115. jassert (wordWrapWidth_ > 0);
  41116. if (sections.size() > 0)
  41117. {
  41118. currentSection = sections.getUnchecked (sectionIndex);
  41119. if (currentSection != 0)
  41120. beginNewLine();
  41121. }
  41122. }
  41123. Iterator (const Iterator& other)
  41124. : indexInText (other.indexInText),
  41125. lineY (other.lineY),
  41126. lineHeight (other.lineHeight),
  41127. maxDescent (other.maxDescent),
  41128. atomX (other.atomX),
  41129. atomRight (other.atomRight),
  41130. atom (other.atom),
  41131. currentSection (other.currentSection),
  41132. sections (other.sections),
  41133. sectionIndex (other.sectionIndex),
  41134. atomIndex (other.atomIndex),
  41135. wordWrapWidth (other.wordWrapWidth),
  41136. passwordCharacter (other.passwordCharacter),
  41137. tempAtom (other.tempAtom)
  41138. {
  41139. }
  41140. ~Iterator()
  41141. {
  41142. }
  41143. bool next()
  41144. {
  41145. if (atom == &tempAtom)
  41146. {
  41147. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41148. if (numRemaining > 0)
  41149. {
  41150. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41151. atomX = 0;
  41152. if (tempAtom.numChars > 0)
  41153. lineY += lineHeight;
  41154. indexInText += tempAtom.numChars;
  41155. GlyphArrangement g;
  41156. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41157. int split;
  41158. for (split = 0; split < g.getNumGlyphs(); ++split)
  41159. if (shouldWrap (g.getGlyph (split).getRight()))
  41160. break;
  41161. if (split > 0 && split <= numRemaining)
  41162. {
  41163. tempAtom.numChars = (uint16) split;
  41164. tempAtom.width = g.getGlyph (split - 1).getRight();
  41165. atomRight = atomX + tempAtom.width;
  41166. return true;
  41167. }
  41168. }
  41169. }
  41170. bool forceNewLine = false;
  41171. if (sectionIndex >= sections.size())
  41172. {
  41173. moveToEndOfLastAtom();
  41174. return false;
  41175. }
  41176. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41177. {
  41178. if (atomIndex >= currentSection->getNumAtoms())
  41179. {
  41180. if (++sectionIndex >= sections.size())
  41181. {
  41182. moveToEndOfLastAtom();
  41183. return false;
  41184. }
  41185. atomIndex = 0;
  41186. currentSection = sections.getUnchecked (sectionIndex);
  41187. }
  41188. else
  41189. {
  41190. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41191. if (! lastAtom->isWhitespace())
  41192. {
  41193. // handle the case where the last atom in a section is actually part of the same
  41194. // word as the first atom of the next section...
  41195. float right = atomRight + lastAtom->width;
  41196. float lineHeight2 = lineHeight;
  41197. float maxDescent2 = maxDescent;
  41198. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41199. {
  41200. const UniformTextSection* const s = sections.getUnchecked (section);
  41201. if (s->getNumAtoms() == 0)
  41202. break;
  41203. const TextAtom* const nextAtom = s->getAtom (0);
  41204. if (nextAtom->isWhitespace())
  41205. break;
  41206. right += nextAtom->width;
  41207. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41208. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41209. if (shouldWrap (right))
  41210. {
  41211. lineHeight = lineHeight2;
  41212. maxDescent = maxDescent2;
  41213. forceNewLine = true;
  41214. break;
  41215. }
  41216. if (s->getNumAtoms() > 1)
  41217. break;
  41218. }
  41219. }
  41220. }
  41221. }
  41222. if (atom != 0)
  41223. {
  41224. atomX = atomRight;
  41225. indexInText += atom->numChars;
  41226. if (atom->isNewLine())
  41227. beginNewLine();
  41228. }
  41229. atom = currentSection->getAtom (atomIndex);
  41230. atomRight = atomX + atom->width;
  41231. ++atomIndex;
  41232. if (shouldWrap (atomRight) || forceNewLine)
  41233. {
  41234. if (atom->isWhitespace())
  41235. {
  41236. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41237. atomRight = jmin (atomRight, wordWrapWidth);
  41238. }
  41239. else
  41240. {
  41241. atomRight = atom->width;
  41242. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41243. {
  41244. tempAtom = *atom;
  41245. tempAtom.width = 0;
  41246. tempAtom.numChars = 0;
  41247. atom = &tempAtom;
  41248. if (atomX > 0)
  41249. beginNewLine();
  41250. return next();
  41251. }
  41252. beginNewLine();
  41253. return true;
  41254. }
  41255. }
  41256. return true;
  41257. }
  41258. void beginNewLine()
  41259. {
  41260. atomX = 0;
  41261. lineY += lineHeight;
  41262. int tempSectionIndex = sectionIndex;
  41263. int tempAtomIndex = atomIndex;
  41264. const UniformTextSection* section = sections.getUnchecked (tempSectionIndex);
  41265. lineHeight = section->font.getHeight();
  41266. maxDescent = section->font.getDescent();
  41267. float x = (atom != 0) ? atom->width : 0;
  41268. while (! shouldWrap (x))
  41269. {
  41270. if (tempSectionIndex >= sections.size())
  41271. break;
  41272. bool checkSize = false;
  41273. if (tempAtomIndex >= section->getNumAtoms())
  41274. {
  41275. if (++tempSectionIndex >= sections.size())
  41276. break;
  41277. tempAtomIndex = 0;
  41278. section = sections.getUnchecked (tempSectionIndex);
  41279. checkSize = true;
  41280. }
  41281. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41282. if (nextAtom == 0)
  41283. break;
  41284. x += nextAtom->width;
  41285. if (shouldWrap (x) || nextAtom->isNewLine())
  41286. break;
  41287. if (checkSize)
  41288. {
  41289. lineHeight = jmax (lineHeight, section->font.getHeight());
  41290. maxDescent = jmax (maxDescent, section->font.getDescent());
  41291. }
  41292. ++tempAtomIndex;
  41293. }
  41294. }
  41295. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41296. {
  41297. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41298. {
  41299. if (lastSection != currentSection)
  41300. {
  41301. lastSection = currentSection;
  41302. g.setColour (currentSection->colour);
  41303. g.setFont (currentSection->font);
  41304. }
  41305. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41306. GlyphArrangement ga;
  41307. ga.addLineOfText (currentSection->font,
  41308. atom->getTrimmedText (passwordCharacter),
  41309. atomX,
  41310. (float) roundToInt (lineY + lineHeight - maxDescent));
  41311. ga.draw (g);
  41312. }
  41313. }
  41314. void drawSelection (Graphics& g,
  41315. const Range<int>& selection) const
  41316. {
  41317. const int startX = roundToInt (indexToX (selection.getStart()));
  41318. const int endX = roundToInt (indexToX (selection.getEnd()));
  41319. const int y = roundToInt (lineY);
  41320. const int nextY = roundToInt (lineY + lineHeight);
  41321. g.fillRect (startX, y, endX - startX, nextY - y);
  41322. }
  41323. void drawSelectedText (Graphics& g,
  41324. const Range<int>& selection,
  41325. const Colour& selectedTextColour) const
  41326. {
  41327. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41328. {
  41329. GlyphArrangement ga;
  41330. ga.addLineOfText (currentSection->font,
  41331. atom->getTrimmedText (passwordCharacter),
  41332. atomX,
  41333. (float) roundToInt (lineY + lineHeight - maxDescent));
  41334. if (selection.getEnd() < indexInText + atom->numChars)
  41335. {
  41336. GlyphArrangement ga2 (ga);
  41337. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41338. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41339. g.setColour (currentSection->colour);
  41340. ga2.draw (g);
  41341. }
  41342. if (selection.getStart() > indexInText)
  41343. {
  41344. GlyphArrangement ga2 (ga);
  41345. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41346. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41347. g.setColour (currentSection->colour);
  41348. ga2.draw (g);
  41349. }
  41350. g.setColour (selectedTextColour);
  41351. ga.draw (g);
  41352. }
  41353. }
  41354. float indexToX (const int indexToFind) const
  41355. {
  41356. if (indexToFind <= indexInText)
  41357. return atomX;
  41358. if (indexToFind >= indexInText + atom->numChars)
  41359. return atomRight;
  41360. GlyphArrangement g;
  41361. g.addLineOfText (currentSection->font,
  41362. atom->getText (passwordCharacter),
  41363. atomX, 0.0f);
  41364. if (indexToFind - indexInText >= g.getNumGlyphs())
  41365. return atomRight;
  41366. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41367. }
  41368. int xToIndex (const float xToFind) const
  41369. {
  41370. if (xToFind <= atomX || atom->isNewLine())
  41371. return indexInText;
  41372. if (xToFind >= atomRight)
  41373. return indexInText + atom->numChars;
  41374. GlyphArrangement g;
  41375. g.addLineOfText (currentSection->font,
  41376. atom->getText (passwordCharacter),
  41377. atomX, 0.0f);
  41378. int j;
  41379. for (j = 0; j < g.getNumGlyphs(); ++j)
  41380. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41381. break;
  41382. return indexInText + j;
  41383. }
  41384. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41385. {
  41386. while (next())
  41387. {
  41388. if (indexInText + atom->numChars > index)
  41389. {
  41390. cx = indexToX (index);
  41391. cy = lineY;
  41392. lineHeight_ = lineHeight;
  41393. return true;
  41394. }
  41395. }
  41396. cx = atomX;
  41397. cy = lineY;
  41398. lineHeight_ = lineHeight;
  41399. return false;
  41400. }
  41401. juce_UseDebuggingNewOperator
  41402. int indexInText;
  41403. float lineY, lineHeight, maxDescent;
  41404. float atomX, atomRight;
  41405. const TextAtom* atom;
  41406. const UniformTextSection* currentSection;
  41407. private:
  41408. const Array <UniformTextSection*>& sections;
  41409. int sectionIndex, atomIndex;
  41410. const float wordWrapWidth;
  41411. const juce_wchar passwordCharacter;
  41412. TextAtom tempAtom;
  41413. Iterator& operator= (const Iterator&);
  41414. void moveToEndOfLastAtom()
  41415. {
  41416. if (atom != 0)
  41417. {
  41418. atomX = atomRight;
  41419. if (atom->isNewLine())
  41420. {
  41421. atomX = 0.0f;
  41422. lineY += lineHeight;
  41423. }
  41424. }
  41425. }
  41426. bool shouldWrap (const float x) const
  41427. {
  41428. return (x - 0.0001f) >= wordWrapWidth;
  41429. }
  41430. };
  41431. class TextEditor::InsertAction : public UndoableAction
  41432. {
  41433. TextEditor& owner;
  41434. const String text;
  41435. const int insertIndex, oldCaretPos, newCaretPos;
  41436. const Font font;
  41437. const Colour colour;
  41438. InsertAction (const InsertAction&);
  41439. InsertAction& operator= (const InsertAction&);
  41440. public:
  41441. InsertAction (TextEditor& owner_,
  41442. const String& text_,
  41443. const int insertIndex_,
  41444. const Font& font_,
  41445. const Colour& colour_,
  41446. const int oldCaretPos_,
  41447. const int newCaretPos_)
  41448. : owner (owner_),
  41449. text (text_),
  41450. insertIndex (insertIndex_),
  41451. oldCaretPos (oldCaretPos_),
  41452. newCaretPos (newCaretPos_),
  41453. font (font_),
  41454. colour (colour_)
  41455. {
  41456. }
  41457. ~InsertAction()
  41458. {
  41459. }
  41460. bool perform()
  41461. {
  41462. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41463. return true;
  41464. }
  41465. bool undo()
  41466. {
  41467. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41468. return true;
  41469. }
  41470. int getSizeInUnits()
  41471. {
  41472. return text.length() + 16;
  41473. }
  41474. };
  41475. class TextEditor::RemoveAction : public UndoableAction
  41476. {
  41477. TextEditor& owner;
  41478. const Range<int> range;
  41479. const int oldCaretPos, newCaretPos;
  41480. Array <UniformTextSection*> removedSections;
  41481. RemoveAction (const RemoveAction&);
  41482. RemoveAction& operator= (const RemoveAction&);
  41483. public:
  41484. RemoveAction (TextEditor& owner_,
  41485. const Range<int> range_,
  41486. const int oldCaretPos_,
  41487. const int newCaretPos_,
  41488. const Array <UniformTextSection*>& removedSections_)
  41489. : owner (owner_),
  41490. range (range_),
  41491. oldCaretPos (oldCaretPos_),
  41492. newCaretPos (newCaretPos_),
  41493. removedSections (removedSections_)
  41494. {
  41495. }
  41496. ~RemoveAction()
  41497. {
  41498. for (int i = removedSections.size(); --i >= 0;)
  41499. {
  41500. UniformTextSection* const section = removedSections.getUnchecked (i);
  41501. section->clear();
  41502. delete section;
  41503. }
  41504. }
  41505. bool perform()
  41506. {
  41507. owner.remove (range, 0, newCaretPos);
  41508. return true;
  41509. }
  41510. bool undo()
  41511. {
  41512. owner.reinsert (range.getStart(), removedSections);
  41513. owner.moveCursorTo (oldCaretPos, false);
  41514. return true;
  41515. }
  41516. int getSizeInUnits()
  41517. {
  41518. int n = 0;
  41519. for (int i = removedSections.size(); --i >= 0;)
  41520. n += removedSections.getUnchecked (i)->getTotalLength();
  41521. return n + 16;
  41522. }
  41523. };
  41524. class TextEditor::TextHolderComponent : public Component,
  41525. public Timer,
  41526. public Value::Listener
  41527. {
  41528. public:
  41529. TextHolderComponent (TextEditor& owner_)
  41530. : owner (owner_)
  41531. {
  41532. setWantsKeyboardFocus (false);
  41533. setInterceptsMouseClicks (false, true);
  41534. owner.getTextValue().addListener (this);
  41535. }
  41536. ~TextHolderComponent()
  41537. {
  41538. owner.getTextValue().removeListener (this);
  41539. }
  41540. void paint (Graphics& g)
  41541. {
  41542. owner.drawContent (g);
  41543. }
  41544. void timerCallback()
  41545. {
  41546. owner.timerCallbackInt();
  41547. }
  41548. const MouseCursor getMouseCursor()
  41549. {
  41550. return owner.getMouseCursor();
  41551. }
  41552. void valueChanged (Value&)
  41553. {
  41554. owner.textWasChangedByValue();
  41555. }
  41556. private:
  41557. TextEditor& owner;
  41558. TextHolderComponent (const TextHolderComponent&);
  41559. TextHolderComponent& operator= (const TextHolderComponent&);
  41560. };
  41561. class TextEditorViewport : public Viewport
  41562. {
  41563. public:
  41564. TextEditorViewport (TextEditor* const owner_)
  41565. : owner (owner_),
  41566. lastWordWrapWidth (0)
  41567. {
  41568. }
  41569. ~TextEditorViewport()
  41570. {
  41571. }
  41572. void visibleAreaChanged (int, int, int, int)
  41573. {
  41574. const float wordWrapWidth = owner->getWordWrapWidth();
  41575. if (wordWrapWidth != lastWordWrapWidth)
  41576. {
  41577. lastWordWrapWidth = wordWrapWidth;
  41578. owner->updateTextHolderSize();
  41579. }
  41580. }
  41581. private:
  41582. TextEditor* const owner;
  41583. float lastWordWrapWidth;
  41584. TextEditorViewport (const TextEditorViewport&);
  41585. TextEditorViewport& operator= (const TextEditorViewport&);
  41586. };
  41587. namespace TextEditorDefs
  41588. {
  41589. const int flashSpeedIntervalMs = 380;
  41590. const int textChangeMessageId = 0x10003001;
  41591. const int returnKeyMessageId = 0x10003002;
  41592. const int escapeKeyMessageId = 0x10003003;
  41593. const int focusLossMessageId = 0x10003004;
  41594. const int maxActionsPerTransaction = 100;
  41595. }
  41596. TextEditor::TextEditor (const String& name,
  41597. const juce_wchar passwordCharacter_)
  41598. : Component (name),
  41599. borderSize (1, 1, 1, 3),
  41600. readOnly (false),
  41601. multiline (false),
  41602. wordWrap (false),
  41603. returnKeyStartsNewLine (false),
  41604. caretVisible (true),
  41605. popupMenuEnabled (true),
  41606. selectAllTextWhenFocused (false),
  41607. scrollbarVisible (true),
  41608. wasFocused (false),
  41609. caretFlashState (true),
  41610. keepCursorOnScreen (true),
  41611. tabKeyUsed (false),
  41612. menuActive (false),
  41613. valueTextNeedsUpdating (false),
  41614. cursorX (0),
  41615. cursorY (0),
  41616. cursorHeight (0),
  41617. maxTextLength (0),
  41618. leftIndent (4),
  41619. topIndent (4),
  41620. lastTransactionTime (0),
  41621. currentFont (14.0f),
  41622. totalNumChars (0),
  41623. caretPosition (0),
  41624. passwordCharacter (passwordCharacter_),
  41625. dragType (notDragging)
  41626. {
  41627. setOpaque (true);
  41628. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41629. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41630. viewport->setWantsKeyboardFocus (false);
  41631. viewport->setScrollBarsShown (false, false);
  41632. setMouseCursor (MouseCursor::IBeamCursor);
  41633. setWantsKeyboardFocus (true);
  41634. }
  41635. TextEditor::~TextEditor()
  41636. {
  41637. textValue.referTo (Value());
  41638. clearInternal (0);
  41639. viewport = 0;
  41640. textHolder = 0;
  41641. }
  41642. void TextEditor::newTransaction()
  41643. {
  41644. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41645. undoManager.beginNewTransaction();
  41646. }
  41647. void TextEditor::doUndoRedo (const bool isRedo)
  41648. {
  41649. if (! isReadOnly())
  41650. {
  41651. if (isRedo ? undoManager.redo()
  41652. : undoManager.undo())
  41653. {
  41654. scrollToMakeSureCursorIsVisible();
  41655. repaint();
  41656. textChanged();
  41657. }
  41658. }
  41659. }
  41660. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41661. const bool shouldWordWrap)
  41662. {
  41663. multiline = shouldBeMultiLine;
  41664. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41665. setScrollbarsShown (scrollbarVisible);
  41666. viewport->setViewPosition (0, 0);
  41667. resized();
  41668. scrollToMakeSureCursorIsVisible();
  41669. }
  41670. bool TextEditor::isMultiLine() const
  41671. {
  41672. return multiline;
  41673. }
  41674. void TextEditor::setScrollbarsShown (bool enabled)
  41675. {
  41676. scrollbarVisible = enabled;
  41677. enabled = enabled && isMultiLine();
  41678. viewport->setScrollBarsShown (enabled, enabled);
  41679. }
  41680. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41681. {
  41682. readOnly = shouldBeReadOnly;
  41683. enablementChanged();
  41684. }
  41685. bool TextEditor::isReadOnly() const
  41686. {
  41687. return readOnly || ! isEnabled();
  41688. }
  41689. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41690. {
  41691. returnKeyStartsNewLine = shouldStartNewLine;
  41692. }
  41693. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41694. {
  41695. tabKeyUsed = shouldTabKeyBeUsed;
  41696. }
  41697. void TextEditor::setPopupMenuEnabled (const bool b)
  41698. {
  41699. popupMenuEnabled = b;
  41700. }
  41701. void TextEditor::setSelectAllWhenFocused (const bool b)
  41702. {
  41703. selectAllTextWhenFocused = b;
  41704. }
  41705. const Font TextEditor::getFont() const
  41706. {
  41707. return currentFont;
  41708. }
  41709. void TextEditor::setFont (const Font& newFont)
  41710. {
  41711. currentFont = newFont;
  41712. scrollToMakeSureCursorIsVisible();
  41713. }
  41714. void TextEditor::applyFontToAllText (const Font& newFont)
  41715. {
  41716. currentFont = newFont;
  41717. const Colour overallColour (findColour (textColourId));
  41718. for (int i = sections.size(); --i >= 0;)
  41719. {
  41720. UniformTextSection* const uts = sections.getUnchecked (i);
  41721. uts->setFont (newFont, passwordCharacter);
  41722. uts->colour = overallColour;
  41723. }
  41724. coalesceSimilarSections();
  41725. updateTextHolderSize();
  41726. scrollToMakeSureCursorIsVisible();
  41727. repaint();
  41728. }
  41729. void TextEditor::colourChanged()
  41730. {
  41731. setOpaque (findColour (backgroundColourId).isOpaque());
  41732. repaint();
  41733. }
  41734. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41735. {
  41736. caretVisible = shouldCaretBeVisible;
  41737. if (shouldCaretBeVisible)
  41738. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41739. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41740. : MouseCursor::NormalCursor);
  41741. }
  41742. void TextEditor::setInputRestrictions (const int maxLen,
  41743. const String& chars)
  41744. {
  41745. maxTextLength = jmax (0, maxLen);
  41746. allowedCharacters = chars;
  41747. }
  41748. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41749. {
  41750. textToShowWhenEmpty = text;
  41751. colourForTextWhenEmpty = colourToUse;
  41752. }
  41753. void TextEditor::setPasswordCharacter (const juce_wchar newPasswordCharacter)
  41754. {
  41755. if (passwordCharacter != newPasswordCharacter)
  41756. {
  41757. passwordCharacter = newPasswordCharacter;
  41758. resized();
  41759. repaint();
  41760. }
  41761. }
  41762. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41763. {
  41764. viewport->setScrollBarThickness (newThicknessPixels);
  41765. }
  41766. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41767. {
  41768. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41769. }
  41770. void TextEditor::clear()
  41771. {
  41772. clearInternal (0);
  41773. updateTextHolderSize();
  41774. undoManager.clearUndoHistory();
  41775. }
  41776. void TextEditor::setText (const String& newText,
  41777. const bool sendTextChangeMessage)
  41778. {
  41779. const int newLength = newText.length();
  41780. if (newLength != getTotalNumChars() || getText() != newText)
  41781. {
  41782. const int oldCursorPos = caretPosition;
  41783. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41784. clearInternal (0);
  41785. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41786. // if you're adding text with line-feeds to a single-line text editor, it
  41787. // ain't gonna look right!
  41788. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41789. if (cursorWasAtEnd && ! isMultiLine())
  41790. moveCursorTo (getTotalNumChars(), false);
  41791. else
  41792. moveCursorTo (oldCursorPos, false);
  41793. if (sendTextChangeMessage)
  41794. textChanged();
  41795. repaint();
  41796. }
  41797. updateTextHolderSize();
  41798. scrollToMakeSureCursorIsVisible();
  41799. undoManager.clearUndoHistory();
  41800. }
  41801. Value& TextEditor::getTextValue()
  41802. {
  41803. if (valueTextNeedsUpdating)
  41804. {
  41805. valueTextNeedsUpdating = false;
  41806. textValue = getText();
  41807. }
  41808. return textValue;
  41809. }
  41810. void TextEditor::textWasChangedByValue()
  41811. {
  41812. if (textValue.getValueSource().getReferenceCount() > 1)
  41813. setText (textValue.getValue());
  41814. }
  41815. void TextEditor::textChanged()
  41816. {
  41817. updateTextHolderSize();
  41818. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41819. if (textValue.getValueSource().getReferenceCount() > 1)
  41820. {
  41821. valueTextNeedsUpdating = false;
  41822. textValue = getText();
  41823. }
  41824. }
  41825. void TextEditor::returnPressed()
  41826. {
  41827. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41828. }
  41829. void TextEditor::escapePressed()
  41830. {
  41831. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41832. }
  41833. void TextEditor::addListener (TextEditorListener* const newListener)
  41834. {
  41835. listeners.add (newListener);
  41836. }
  41837. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41838. {
  41839. listeners.remove (listenerToRemove);
  41840. }
  41841. void TextEditor::timerCallbackInt()
  41842. {
  41843. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41844. if (caretFlashState != newState)
  41845. {
  41846. caretFlashState = newState;
  41847. if (caretFlashState)
  41848. wasFocused = true;
  41849. if (caretVisible
  41850. && hasKeyboardFocus (false)
  41851. && ! isReadOnly())
  41852. {
  41853. repaintCaret();
  41854. }
  41855. }
  41856. const unsigned int now = Time::getApproximateMillisecondCounter();
  41857. if (now > lastTransactionTime + 200)
  41858. newTransaction();
  41859. }
  41860. void TextEditor::repaintCaret()
  41861. {
  41862. if (! findColour (caretColourId).isTransparent())
  41863. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41864. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41865. 4,
  41866. roundToInt (cursorHeight) + 2);
  41867. }
  41868. void TextEditor::repaintText (const Range<int>& range)
  41869. {
  41870. if (! range.isEmpty())
  41871. {
  41872. float x = 0, y = 0, lh = currentFont.getHeight();
  41873. const float wordWrapWidth = getWordWrapWidth();
  41874. if (wordWrapWidth > 0)
  41875. {
  41876. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41877. i.getCharPosition (range.getStart(), x, y, lh);
  41878. const int y1 = (int) y;
  41879. int y2;
  41880. if (range.getEnd() >= getTotalNumChars())
  41881. {
  41882. y2 = textHolder->getHeight();
  41883. }
  41884. else
  41885. {
  41886. i.getCharPosition (range.getEnd(), x, y, lh);
  41887. y2 = (int) (y + lh * 2.0f);
  41888. }
  41889. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41890. }
  41891. }
  41892. }
  41893. void TextEditor::moveCaret (int newCaretPos)
  41894. {
  41895. if (newCaretPos < 0)
  41896. newCaretPos = 0;
  41897. else if (newCaretPos > getTotalNumChars())
  41898. newCaretPos = getTotalNumChars();
  41899. if (newCaretPos != getCaretPosition())
  41900. {
  41901. repaintCaret();
  41902. caretFlashState = true;
  41903. caretPosition = newCaretPos;
  41904. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41905. scrollToMakeSureCursorIsVisible();
  41906. repaintCaret();
  41907. }
  41908. }
  41909. void TextEditor::setCaretPosition (const int newIndex)
  41910. {
  41911. moveCursorTo (newIndex, false);
  41912. }
  41913. int TextEditor::getCaretPosition() const
  41914. {
  41915. return caretPosition;
  41916. }
  41917. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41918. const int desiredCaretY)
  41919. {
  41920. updateCaretPosition();
  41921. int vx = roundToInt (cursorX) - desiredCaretX;
  41922. int vy = roundToInt (cursorY) - desiredCaretY;
  41923. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41924. {
  41925. vx += desiredCaretX - proportionOfWidth (0.2f);
  41926. }
  41927. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41928. {
  41929. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41930. }
  41931. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41932. if (! isMultiLine())
  41933. {
  41934. vy = viewport->getViewPositionY();
  41935. }
  41936. else
  41937. {
  41938. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41939. const int curH = roundToInt (cursorHeight);
  41940. if (desiredCaretY < 0)
  41941. {
  41942. vy = jmax (0, desiredCaretY + vy);
  41943. }
  41944. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41945. {
  41946. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41947. }
  41948. }
  41949. viewport->setViewPosition (vx, vy);
  41950. }
  41951. const Rectangle<int> TextEditor::getCaretRectangle()
  41952. {
  41953. updateCaretPosition();
  41954. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41955. roundToInt (cursorY) - viewport->getY(),
  41956. 1, roundToInt (cursorHeight));
  41957. }
  41958. float TextEditor::getWordWrapWidth() const
  41959. {
  41960. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41961. : 1.0e10f;
  41962. }
  41963. void TextEditor::updateTextHolderSize()
  41964. {
  41965. const float wordWrapWidth = getWordWrapWidth();
  41966. if (wordWrapWidth > 0)
  41967. {
  41968. float maxWidth = 0.0f;
  41969. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41970. while (i.next())
  41971. maxWidth = jmax (maxWidth, i.atomRight);
  41972. const int w = leftIndent + roundToInt (maxWidth);
  41973. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  41974. currentFont.getHeight()));
  41975. textHolder->setSize (w + 1, h + 1);
  41976. }
  41977. }
  41978. int TextEditor::getTextWidth() const
  41979. {
  41980. return textHolder->getWidth();
  41981. }
  41982. int TextEditor::getTextHeight() const
  41983. {
  41984. return textHolder->getHeight();
  41985. }
  41986. void TextEditor::setIndents (const int newLeftIndent,
  41987. const int newTopIndent)
  41988. {
  41989. leftIndent = newLeftIndent;
  41990. topIndent = newTopIndent;
  41991. }
  41992. void TextEditor::setBorder (const BorderSize& border)
  41993. {
  41994. borderSize = border;
  41995. resized();
  41996. }
  41997. const BorderSize TextEditor::getBorder() const
  41998. {
  41999. return borderSize;
  42000. }
  42001. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42002. {
  42003. keepCursorOnScreen = shouldScrollToShowCursor;
  42004. }
  42005. void TextEditor::updateCaretPosition()
  42006. {
  42007. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42008. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42009. }
  42010. void TextEditor::scrollToMakeSureCursorIsVisible()
  42011. {
  42012. updateCaretPosition();
  42013. if (keepCursorOnScreen)
  42014. {
  42015. int x = viewport->getViewPositionX();
  42016. int y = viewport->getViewPositionY();
  42017. const int relativeCursorX = roundToInt (cursorX) - x;
  42018. const int relativeCursorY = roundToInt (cursorY) - y;
  42019. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42020. {
  42021. x += relativeCursorX - proportionOfWidth (0.2f);
  42022. }
  42023. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42024. {
  42025. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42026. }
  42027. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42028. if (! isMultiLine())
  42029. {
  42030. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42031. }
  42032. else
  42033. {
  42034. const int curH = roundToInt (cursorHeight);
  42035. if (relativeCursorY < 0)
  42036. {
  42037. y = jmax (0, relativeCursorY + y);
  42038. }
  42039. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42040. {
  42041. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42042. }
  42043. }
  42044. viewport->setViewPosition (x, y);
  42045. }
  42046. }
  42047. void TextEditor::moveCursorTo (const int newPosition,
  42048. const bool isSelecting)
  42049. {
  42050. if (isSelecting)
  42051. {
  42052. moveCaret (newPosition);
  42053. const Range<int> oldSelection (selection);
  42054. if (dragType == notDragging)
  42055. {
  42056. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42057. dragType = draggingSelectionStart;
  42058. else
  42059. dragType = draggingSelectionEnd;
  42060. }
  42061. if (dragType == draggingSelectionStart)
  42062. {
  42063. if (getCaretPosition() >= selection.getEnd())
  42064. dragType = draggingSelectionEnd;
  42065. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42066. }
  42067. else
  42068. {
  42069. if (getCaretPosition() < selection.getStart())
  42070. dragType = draggingSelectionStart;
  42071. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42072. }
  42073. repaintText (selection.getUnionWith (oldSelection));
  42074. }
  42075. else
  42076. {
  42077. dragType = notDragging;
  42078. repaintText (selection);
  42079. moveCaret (newPosition);
  42080. selection = Range<int>::emptyRange (getCaretPosition());
  42081. }
  42082. }
  42083. int TextEditor::getTextIndexAt (const int x,
  42084. const int y)
  42085. {
  42086. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42087. (float) (y + viewport->getViewPositionY() - topIndent));
  42088. }
  42089. void TextEditor::insertTextAtCaret (const String& newText_)
  42090. {
  42091. String newText (newText_);
  42092. if (allowedCharacters.isNotEmpty())
  42093. newText = newText.retainCharacters (allowedCharacters);
  42094. if ((! returnKeyStartsNewLine) && newText == "\n")
  42095. {
  42096. returnPressed();
  42097. return;
  42098. }
  42099. if (! isMultiLine())
  42100. newText = newText.replaceCharacters ("\r\n", " ");
  42101. else
  42102. newText = newText.replace ("\r\n", "\n");
  42103. const int newCaretPos = selection.getStart() + newText.length();
  42104. const int insertIndex = selection.getStart();
  42105. remove (selection, getUndoManager(),
  42106. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42107. if (maxTextLength > 0)
  42108. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42109. if (newText.isNotEmpty())
  42110. insert (newText,
  42111. insertIndex,
  42112. currentFont,
  42113. findColour (textColourId),
  42114. getUndoManager(),
  42115. newCaretPos);
  42116. textChanged();
  42117. }
  42118. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42119. {
  42120. moveCursorTo (newSelection.getStart(), false);
  42121. moveCursorTo (newSelection.getEnd(), true);
  42122. }
  42123. void TextEditor::copy()
  42124. {
  42125. if (passwordCharacter == 0)
  42126. {
  42127. const String selection (getHighlightedText());
  42128. if (selection.isNotEmpty())
  42129. SystemClipboard::copyTextToClipboard (selection);
  42130. }
  42131. }
  42132. void TextEditor::paste()
  42133. {
  42134. if (! isReadOnly())
  42135. {
  42136. const String clip (SystemClipboard::getTextFromClipboard());
  42137. if (clip.isNotEmpty())
  42138. insertTextAtCaret (clip);
  42139. }
  42140. }
  42141. void TextEditor::cut()
  42142. {
  42143. if (! isReadOnly())
  42144. {
  42145. moveCaret (selection.getEnd());
  42146. insertTextAtCaret (String::empty);
  42147. }
  42148. }
  42149. void TextEditor::drawContent (Graphics& g)
  42150. {
  42151. const float wordWrapWidth = getWordWrapWidth();
  42152. if (wordWrapWidth > 0)
  42153. {
  42154. g.setOrigin (leftIndent, topIndent);
  42155. const Rectangle<int> clip (g.getClipBounds());
  42156. Colour selectedTextColour;
  42157. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42158. while (i.lineY + 200.0 < clip.getY() && i.next())
  42159. {}
  42160. if (! selection.isEmpty())
  42161. {
  42162. g.setColour (findColour (highlightColourId)
  42163. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42164. selectedTextColour = findColour (highlightedTextColourId);
  42165. Iterator i2 (i);
  42166. while (i2.next() && i2.lineY < clip.getBottom())
  42167. {
  42168. if (i2.lineY + i2.lineHeight >= clip.getY()
  42169. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42170. {
  42171. i2.drawSelection (g, selection);
  42172. }
  42173. }
  42174. }
  42175. const UniformTextSection* lastSection = 0;
  42176. while (i.next() && i.lineY < clip.getBottom())
  42177. {
  42178. if (i.lineY + i.lineHeight >= clip.getY())
  42179. {
  42180. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42181. {
  42182. i.drawSelectedText (g, selection, selectedTextColour);
  42183. lastSection = 0;
  42184. }
  42185. else
  42186. {
  42187. i.draw (g, lastSection);
  42188. }
  42189. }
  42190. }
  42191. }
  42192. }
  42193. void TextEditor::paint (Graphics& g)
  42194. {
  42195. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42196. }
  42197. void TextEditor::paintOverChildren (Graphics& g)
  42198. {
  42199. if (caretFlashState
  42200. && hasKeyboardFocus (false)
  42201. && caretVisible
  42202. && ! isReadOnly())
  42203. {
  42204. g.setColour (findColour (caretColourId));
  42205. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42206. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42207. 2.0f, cursorHeight);
  42208. }
  42209. if (textToShowWhenEmpty.isNotEmpty()
  42210. && (! hasKeyboardFocus (false))
  42211. && getTotalNumChars() == 0)
  42212. {
  42213. g.setColour (colourForTextWhenEmpty);
  42214. g.setFont (getFont());
  42215. if (isMultiLine())
  42216. {
  42217. g.drawText (textToShowWhenEmpty,
  42218. 0, 0, getWidth(), getHeight(),
  42219. Justification::centred, true);
  42220. }
  42221. else
  42222. {
  42223. g.drawText (textToShowWhenEmpty,
  42224. leftIndent, topIndent,
  42225. viewport->getWidth() - leftIndent,
  42226. viewport->getHeight() - topIndent,
  42227. Justification::centredLeft, true);
  42228. }
  42229. }
  42230. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42231. }
  42232. void TextEditor::mouseDown (const MouseEvent& e)
  42233. {
  42234. beginDragAutoRepeat (100);
  42235. newTransaction();
  42236. if (wasFocused || ! selectAllTextWhenFocused)
  42237. {
  42238. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42239. {
  42240. moveCursorTo (getTextIndexAt (e.x, e.y),
  42241. e.mods.isShiftDown());
  42242. }
  42243. else
  42244. {
  42245. PopupMenu m;
  42246. m.setLookAndFeel (&getLookAndFeel());
  42247. addPopupMenuItems (m, &e);
  42248. menuActive = true;
  42249. const int result = m.show();
  42250. menuActive = false;
  42251. if (result != 0)
  42252. performPopupMenuAction (result);
  42253. }
  42254. }
  42255. }
  42256. void TextEditor::mouseDrag (const MouseEvent& e)
  42257. {
  42258. if (wasFocused || ! selectAllTextWhenFocused)
  42259. {
  42260. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42261. {
  42262. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42263. }
  42264. }
  42265. }
  42266. void TextEditor::mouseUp (const MouseEvent& e)
  42267. {
  42268. newTransaction();
  42269. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42270. if (wasFocused || ! selectAllTextWhenFocused)
  42271. {
  42272. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42273. {
  42274. moveCaret (getTextIndexAt (e.x, e.y));
  42275. }
  42276. }
  42277. wasFocused = true;
  42278. }
  42279. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42280. {
  42281. int tokenEnd = getTextIndexAt (e.x, e.y);
  42282. int tokenStart = tokenEnd;
  42283. if (e.getNumberOfClicks() > 3)
  42284. {
  42285. tokenStart = 0;
  42286. tokenEnd = getTotalNumChars();
  42287. }
  42288. else
  42289. {
  42290. const String t (getText());
  42291. const int totalLength = getTotalNumChars();
  42292. while (tokenEnd < totalLength)
  42293. {
  42294. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42295. ++tokenEnd;
  42296. else
  42297. break;
  42298. }
  42299. tokenStart = tokenEnd;
  42300. while (tokenStart > 0)
  42301. {
  42302. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42303. --tokenStart;
  42304. else
  42305. break;
  42306. }
  42307. if (e.getNumberOfClicks() > 2)
  42308. {
  42309. while (tokenEnd < totalLength)
  42310. {
  42311. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42312. ++tokenEnd;
  42313. else
  42314. break;
  42315. }
  42316. while (tokenStart > 0)
  42317. {
  42318. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42319. --tokenStart;
  42320. else
  42321. break;
  42322. }
  42323. }
  42324. }
  42325. moveCursorTo (tokenEnd, false);
  42326. moveCursorTo (tokenStart, true);
  42327. }
  42328. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42329. {
  42330. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42331. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42332. }
  42333. bool TextEditor::keyPressed (const KeyPress& key)
  42334. {
  42335. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42336. return false;
  42337. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42338. if (key.isKeyCode (KeyPress::leftKey)
  42339. || key.isKeyCode (KeyPress::upKey))
  42340. {
  42341. newTransaction();
  42342. int newPos;
  42343. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42344. newPos = indexAtPosition (cursorX, cursorY - 1);
  42345. else if (moveInWholeWordSteps)
  42346. newPos = findWordBreakBefore (getCaretPosition());
  42347. else
  42348. newPos = getCaretPosition() - 1;
  42349. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42350. }
  42351. else if (key.isKeyCode (KeyPress::rightKey)
  42352. || key.isKeyCode (KeyPress::downKey))
  42353. {
  42354. newTransaction();
  42355. int newPos;
  42356. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42357. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42358. else if (moveInWholeWordSteps)
  42359. newPos = findWordBreakAfter (getCaretPosition());
  42360. else
  42361. newPos = getCaretPosition() + 1;
  42362. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42363. }
  42364. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42365. {
  42366. newTransaction();
  42367. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42368. key.getModifiers().isShiftDown());
  42369. }
  42370. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42371. {
  42372. newTransaction();
  42373. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42374. key.getModifiers().isShiftDown());
  42375. }
  42376. else if (key.isKeyCode (KeyPress::homeKey))
  42377. {
  42378. newTransaction();
  42379. if (isMultiLine() && ! moveInWholeWordSteps)
  42380. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42381. key.getModifiers().isShiftDown());
  42382. else
  42383. moveCursorTo (0, key.getModifiers().isShiftDown());
  42384. }
  42385. else if (key.isKeyCode (KeyPress::endKey))
  42386. {
  42387. newTransaction();
  42388. if (isMultiLine() && ! moveInWholeWordSteps)
  42389. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42390. key.getModifiers().isShiftDown());
  42391. else
  42392. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42393. }
  42394. else if (key.isKeyCode (KeyPress::backspaceKey))
  42395. {
  42396. if (moveInWholeWordSteps)
  42397. {
  42398. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42399. }
  42400. else
  42401. {
  42402. if (selection.isEmpty() && selection.getStart() > 0)
  42403. selection.setStart (selection.getEnd() - 1);
  42404. }
  42405. cut();
  42406. }
  42407. else if (key.isKeyCode (KeyPress::deleteKey))
  42408. {
  42409. if (key.getModifiers().isShiftDown())
  42410. copy();
  42411. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42412. selection.setEnd (selection.getStart() + 1);
  42413. cut();
  42414. }
  42415. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42416. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42417. {
  42418. newTransaction();
  42419. copy();
  42420. }
  42421. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42422. {
  42423. newTransaction();
  42424. copy();
  42425. cut();
  42426. }
  42427. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42428. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42429. {
  42430. newTransaction();
  42431. paste();
  42432. }
  42433. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42434. {
  42435. newTransaction();
  42436. doUndoRedo (false);
  42437. }
  42438. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42439. {
  42440. newTransaction();
  42441. doUndoRedo (true);
  42442. }
  42443. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42444. {
  42445. newTransaction();
  42446. moveCursorTo (getTotalNumChars(), false);
  42447. moveCursorTo (0, true);
  42448. }
  42449. else if (key == KeyPress::returnKey)
  42450. {
  42451. newTransaction();
  42452. insertTextAtCaret ("\n");
  42453. }
  42454. else if (key.isKeyCode (KeyPress::escapeKey))
  42455. {
  42456. newTransaction();
  42457. moveCursorTo (getCaretPosition(), false);
  42458. escapePressed();
  42459. }
  42460. else if (key.getTextCharacter() >= ' '
  42461. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42462. {
  42463. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42464. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42465. }
  42466. else
  42467. {
  42468. return false;
  42469. }
  42470. return true;
  42471. }
  42472. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42473. {
  42474. if (! isKeyDown)
  42475. return false;
  42476. #if JUCE_WIN32
  42477. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42478. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42479. #endif
  42480. // (overridden to avoid forwarding key events to the parent)
  42481. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42482. }
  42483. const int baseMenuItemID = 0x7fff0000;
  42484. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42485. {
  42486. const bool writable = ! isReadOnly();
  42487. if (passwordCharacter == 0)
  42488. {
  42489. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42490. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42491. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42492. }
  42493. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42494. m.addSeparator();
  42495. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42496. m.addSeparator();
  42497. if (getUndoManager() != 0)
  42498. {
  42499. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42500. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42501. }
  42502. }
  42503. void TextEditor::performPopupMenuAction (const int menuItemID)
  42504. {
  42505. switch (menuItemID)
  42506. {
  42507. case baseMenuItemID + 1:
  42508. copy();
  42509. cut();
  42510. break;
  42511. case baseMenuItemID + 2:
  42512. copy();
  42513. break;
  42514. case baseMenuItemID + 3:
  42515. paste();
  42516. break;
  42517. case baseMenuItemID + 4:
  42518. cut();
  42519. break;
  42520. case baseMenuItemID + 5:
  42521. moveCursorTo (getTotalNumChars(), false);
  42522. moveCursorTo (0, true);
  42523. break;
  42524. case baseMenuItemID + 6:
  42525. doUndoRedo (false);
  42526. break;
  42527. case baseMenuItemID + 7:
  42528. doUndoRedo (true);
  42529. break;
  42530. default:
  42531. break;
  42532. }
  42533. }
  42534. void TextEditor::focusGained (FocusChangeType)
  42535. {
  42536. newTransaction();
  42537. caretFlashState = true;
  42538. if (selectAllTextWhenFocused)
  42539. {
  42540. moveCursorTo (0, false);
  42541. moveCursorTo (getTotalNumChars(), true);
  42542. }
  42543. repaint();
  42544. if (caretVisible)
  42545. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42546. ComponentPeer* const peer = getPeer();
  42547. if (peer != 0 && ! isReadOnly())
  42548. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42549. }
  42550. void TextEditor::focusLost (FocusChangeType)
  42551. {
  42552. newTransaction();
  42553. wasFocused = false;
  42554. textHolder->stopTimer();
  42555. caretFlashState = false;
  42556. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42557. repaint();
  42558. }
  42559. void TextEditor::resized()
  42560. {
  42561. viewport->setBoundsInset (borderSize);
  42562. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42563. updateTextHolderSize();
  42564. if (! isMultiLine())
  42565. {
  42566. scrollToMakeSureCursorIsVisible();
  42567. }
  42568. else
  42569. {
  42570. updateCaretPosition();
  42571. }
  42572. }
  42573. void TextEditor::handleCommandMessage (const int commandId)
  42574. {
  42575. Component::BailOutChecker checker (this);
  42576. switch (commandId)
  42577. {
  42578. case TextEditorDefs::textChangeMessageId:
  42579. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42580. break;
  42581. case TextEditorDefs::returnKeyMessageId:
  42582. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42583. break;
  42584. case TextEditorDefs::escapeKeyMessageId:
  42585. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42586. break;
  42587. case TextEditorDefs::focusLossMessageId:
  42588. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42589. break;
  42590. default:
  42591. jassertfalse
  42592. break;
  42593. }
  42594. }
  42595. void TextEditor::enablementChanged()
  42596. {
  42597. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42598. : MouseCursor::IBeamCursor);
  42599. repaint();
  42600. }
  42601. UndoManager* TextEditor::getUndoManager() throw()
  42602. {
  42603. return isReadOnly() ? &undoManager : 0;
  42604. }
  42605. void TextEditor::clearInternal (UndoManager* const um)
  42606. {
  42607. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42608. }
  42609. void TextEditor::insert (const String& text,
  42610. const int insertIndex,
  42611. const Font& font,
  42612. const Colour& colour,
  42613. UndoManager* const um,
  42614. const int caretPositionToMoveTo)
  42615. {
  42616. if (text.isNotEmpty())
  42617. {
  42618. if (um != 0)
  42619. {
  42620. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42621. newTransaction();
  42622. um->perform (new InsertAction (*this, text, insertIndex, font, colour,
  42623. caretPosition, caretPositionToMoveTo));
  42624. }
  42625. else
  42626. {
  42627. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42628. // a line gets moved due to word wrap
  42629. int index = 0;
  42630. int nextIndex = 0;
  42631. for (int i = 0; i < sections.size(); ++i)
  42632. {
  42633. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42634. if (insertIndex == index)
  42635. {
  42636. sections.insert (i, new UniformTextSection (text,
  42637. font, colour,
  42638. passwordCharacter));
  42639. break;
  42640. }
  42641. else if (insertIndex > index && insertIndex < nextIndex)
  42642. {
  42643. splitSection (i, insertIndex - index);
  42644. sections.insert (i + 1, new UniformTextSection (text,
  42645. font, colour,
  42646. passwordCharacter));
  42647. break;
  42648. }
  42649. index = nextIndex;
  42650. }
  42651. if (nextIndex == insertIndex)
  42652. sections.add (new UniformTextSection (text,
  42653. font, colour,
  42654. passwordCharacter));
  42655. coalesceSimilarSections();
  42656. totalNumChars = -1;
  42657. valueTextNeedsUpdating = true;
  42658. moveCursorTo (caretPositionToMoveTo, false);
  42659. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42660. }
  42661. }
  42662. }
  42663. void TextEditor::reinsert (const int insertIndex,
  42664. const Array <UniformTextSection*>& sectionsToInsert)
  42665. {
  42666. int index = 0;
  42667. int nextIndex = 0;
  42668. for (int i = 0; i < sections.size(); ++i)
  42669. {
  42670. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42671. if (insertIndex == index)
  42672. {
  42673. for (int j = sectionsToInsert.size(); --j >= 0;)
  42674. sections.insert (i, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42675. break;
  42676. }
  42677. else if (insertIndex > index && insertIndex < nextIndex)
  42678. {
  42679. splitSection (i, insertIndex - index);
  42680. for (int j = sectionsToInsert.size(); --j >= 0;)
  42681. sections.insert (i + 1, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42682. break;
  42683. }
  42684. index = nextIndex;
  42685. }
  42686. if (nextIndex == insertIndex)
  42687. {
  42688. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42689. sections.add (new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42690. }
  42691. coalesceSimilarSections();
  42692. totalNumChars = -1;
  42693. valueTextNeedsUpdating = true;
  42694. }
  42695. void TextEditor::remove (const Range<int>& range,
  42696. UndoManager* const um,
  42697. const int caretPositionToMoveTo)
  42698. {
  42699. if (! range.isEmpty())
  42700. {
  42701. int index = 0;
  42702. for (int i = 0; i < sections.size(); ++i)
  42703. {
  42704. const int nextIndex = index + sections.getUnchecked(i)->getTotalLength();
  42705. if (range.getStart() > index && range.getStart() < nextIndex)
  42706. {
  42707. splitSection (i, range.getStart() - index);
  42708. --i;
  42709. }
  42710. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42711. {
  42712. splitSection (i, range.getEnd() - index);
  42713. --i;
  42714. }
  42715. else
  42716. {
  42717. index = nextIndex;
  42718. if (index > range.getEnd())
  42719. break;
  42720. }
  42721. }
  42722. index = 0;
  42723. if (um != 0)
  42724. {
  42725. Array <UniformTextSection*> removedSections;
  42726. for (int i = 0; i < sections.size(); ++i)
  42727. {
  42728. if (range.getEnd() <= range.getStart())
  42729. break;
  42730. UniformTextSection* const section = sections.getUnchecked (i);
  42731. const int nextIndex = index + section->getTotalLength();
  42732. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42733. removedSections.add (new UniformTextSection (*section));
  42734. index = nextIndex;
  42735. }
  42736. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42737. newTransaction();
  42738. um->perform (new RemoveAction (*this, range, caretPosition,
  42739. caretPositionToMoveTo, removedSections));
  42740. }
  42741. else
  42742. {
  42743. Range<int> remainingRange (range);
  42744. for (int i = 0; i < sections.size(); ++i)
  42745. {
  42746. UniformTextSection* const section = sections.getUnchecked (i);
  42747. const int nextIndex = index + section->getTotalLength();
  42748. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42749. {
  42750. sections.remove(i);
  42751. section->clear();
  42752. delete section;
  42753. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42754. if (remainingRange.isEmpty())
  42755. break;
  42756. --i;
  42757. }
  42758. else
  42759. {
  42760. index = nextIndex;
  42761. }
  42762. }
  42763. coalesceSimilarSections();
  42764. totalNumChars = -1;
  42765. valueTextNeedsUpdating = true;
  42766. moveCursorTo (caretPositionToMoveTo, false);
  42767. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42768. }
  42769. }
  42770. }
  42771. const String TextEditor::getText() const
  42772. {
  42773. String t;
  42774. t.preallocateStorage (getTotalNumChars());
  42775. String::Concatenator concatenator (t);
  42776. for (int i = 0; i < sections.size(); ++i)
  42777. sections.getUnchecked (i)->appendAllText (concatenator);
  42778. return t;
  42779. }
  42780. const String TextEditor::getTextInRange (const Range<int>& range) const
  42781. {
  42782. String t;
  42783. if (! range.isEmpty())
  42784. {
  42785. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42786. String::Concatenator concatenator (t);
  42787. int index = 0;
  42788. for (int i = 0; i < sections.size(); ++i)
  42789. {
  42790. const UniformTextSection* const s = sections.getUnchecked (i);
  42791. const int nextIndex = index + s->getTotalLength();
  42792. if (range.getStart() < nextIndex)
  42793. {
  42794. if (range.getEnd() <= index)
  42795. break;
  42796. s->appendSubstring (concatenator, range - index);
  42797. }
  42798. index = nextIndex;
  42799. }
  42800. }
  42801. return t;
  42802. }
  42803. const String TextEditor::getHighlightedText() const
  42804. {
  42805. return getTextInRange (selection);
  42806. }
  42807. int TextEditor::getTotalNumChars() const
  42808. {
  42809. if (totalNumChars < 0)
  42810. {
  42811. totalNumChars = 0;
  42812. for (int i = sections.size(); --i >= 0;)
  42813. totalNumChars += sections.getUnchecked (i)->getTotalLength();
  42814. }
  42815. return totalNumChars;
  42816. }
  42817. bool TextEditor::isEmpty() const
  42818. {
  42819. return getTotalNumChars() == 0;
  42820. }
  42821. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42822. {
  42823. const float wordWrapWidth = getWordWrapWidth();
  42824. if (wordWrapWidth > 0 && sections.size() > 0)
  42825. {
  42826. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42827. i.getCharPosition (index, cx, cy, lineHeight);
  42828. }
  42829. else
  42830. {
  42831. cx = cy = 0;
  42832. lineHeight = currentFont.getHeight();
  42833. }
  42834. }
  42835. int TextEditor::indexAtPosition (const float x, const float y)
  42836. {
  42837. const float wordWrapWidth = getWordWrapWidth();
  42838. if (wordWrapWidth > 0)
  42839. {
  42840. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42841. while (i.next())
  42842. {
  42843. if (i.lineY + i.lineHeight > y)
  42844. {
  42845. if (i.lineY > y)
  42846. return jmax (0, i.indexInText - 1);
  42847. if (i.atomX >= x)
  42848. return i.indexInText;
  42849. if (x < i.atomRight)
  42850. return i.xToIndex (x);
  42851. }
  42852. }
  42853. }
  42854. return getTotalNumChars();
  42855. }
  42856. static int getCharacterCategory (const juce_wchar character)
  42857. {
  42858. return CharacterFunctions::isLetterOrDigit (character)
  42859. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42860. }
  42861. int TextEditor::findWordBreakAfter (const int position) const
  42862. {
  42863. const String t (getTextInRange (Range<int> (position, position + 512)));
  42864. const int totalLength = t.length();
  42865. int i = 0;
  42866. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42867. ++i;
  42868. const int type = getCharacterCategory (t[i]);
  42869. while (i < totalLength && type == getCharacterCategory (t[i]))
  42870. ++i;
  42871. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42872. ++i;
  42873. return position + i;
  42874. }
  42875. int TextEditor::findWordBreakBefore (const int position) const
  42876. {
  42877. if (position <= 0)
  42878. return 0;
  42879. const int startOfBuffer = jmax (0, position - 512);
  42880. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42881. int i = position - startOfBuffer;
  42882. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42883. --i;
  42884. if (i > 0)
  42885. {
  42886. const int type = getCharacterCategory (t [i - 1]);
  42887. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42888. --i;
  42889. }
  42890. jassert (startOfBuffer + i >= 0);
  42891. return startOfBuffer + i;
  42892. }
  42893. void TextEditor::splitSection (const int sectionIndex,
  42894. const int charToSplitAt)
  42895. {
  42896. jassert (sections[sectionIndex] != 0);
  42897. sections.insert (sectionIndex + 1,
  42898. sections.getUnchecked (sectionIndex)->split (charToSplitAt, passwordCharacter));
  42899. }
  42900. void TextEditor::coalesceSimilarSections()
  42901. {
  42902. for (int i = 0; i < sections.size() - 1; ++i)
  42903. {
  42904. UniformTextSection* const s1 = sections.getUnchecked (i);
  42905. UniformTextSection* const s2 = sections.getUnchecked (i + 1);
  42906. if (s1->font == s2->font
  42907. && s1->colour == s2->colour)
  42908. {
  42909. s1->append (*s2, passwordCharacter);
  42910. sections.remove (i + 1);
  42911. delete s2;
  42912. --i;
  42913. }
  42914. }
  42915. }
  42916. END_JUCE_NAMESPACE
  42917. /*** End of inlined file: juce_TextEditor.cpp ***/
  42918. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42919. BEGIN_JUCE_NAMESPACE
  42920. const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
  42921. class ToolbarSpacerComp : public ToolbarItemComponent
  42922. {
  42923. public:
  42924. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42925. : ToolbarItemComponent (itemId_, String::empty, false),
  42926. fixedSize (fixedSize_),
  42927. drawBar (drawBar_)
  42928. {
  42929. }
  42930. ~ToolbarSpacerComp()
  42931. {
  42932. }
  42933. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42934. int& preferredSize, int& minSize, int& maxSize)
  42935. {
  42936. if (fixedSize <= 0)
  42937. {
  42938. preferredSize = toolbarThickness * 2;
  42939. minSize = 4;
  42940. maxSize = 32768;
  42941. }
  42942. else
  42943. {
  42944. maxSize = roundToInt (toolbarThickness * fixedSize);
  42945. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42946. preferredSize = maxSize;
  42947. if (getEditingMode() == editableOnPalette)
  42948. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42949. }
  42950. return true;
  42951. }
  42952. void paintButtonArea (Graphics&, int, int, bool, bool)
  42953. {
  42954. }
  42955. void contentAreaChanged (const Rectangle<int>&)
  42956. {
  42957. }
  42958. int getResizeOrder() const throw()
  42959. {
  42960. return fixedSize <= 0 ? 0 : 1;
  42961. }
  42962. void paint (Graphics& g)
  42963. {
  42964. const int w = getWidth();
  42965. const int h = getHeight();
  42966. if (drawBar)
  42967. {
  42968. g.setColour (findColour (Toolbar::separatorColourId, true));
  42969. const float thickness = 0.2f;
  42970. if (isToolbarVertical())
  42971. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  42972. else
  42973. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  42974. }
  42975. if (getEditingMode() != normalMode && ! drawBar)
  42976. {
  42977. g.setColour (findColour (Toolbar::separatorColourId, true));
  42978. const int indentX = jmin (2, (w - 3) / 2);
  42979. const int indentY = jmin (2, (h - 3) / 2);
  42980. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  42981. if (fixedSize <= 0)
  42982. {
  42983. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  42984. if (isToolbarVertical())
  42985. {
  42986. x1 = w * 0.5f;
  42987. y1 = h * 0.4f;
  42988. x2 = x1;
  42989. y2 = indentX * 2.0f;
  42990. x3 = x1;
  42991. y3 = h * 0.6f;
  42992. x4 = x1;
  42993. y4 = h - y2;
  42994. hw = w * 0.15f;
  42995. hl = w * 0.2f;
  42996. }
  42997. else
  42998. {
  42999. x1 = w * 0.4f;
  43000. y1 = h * 0.5f;
  43001. x2 = indentX * 2.0f;
  43002. y2 = y1;
  43003. x3 = w * 0.6f;
  43004. y3 = y1;
  43005. x4 = w - x2;
  43006. y4 = y1;
  43007. hw = h * 0.15f;
  43008. hl = h * 0.2f;
  43009. }
  43010. Path p;
  43011. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43012. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43013. g.fillPath (p);
  43014. }
  43015. }
  43016. }
  43017. juce_UseDebuggingNewOperator
  43018. private:
  43019. const float fixedSize;
  43020. const bool drawBar;
  43021. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43022. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43023. };
  43024. class MissingItemsComponent : public PopupMenuCustomComponent
  43025. {
  43026. public:
  43027. MissingItemsComponent (Toolbar& owner_, const int height_)
  43028. : PopupMenuCustomComponent (true),
  43029. owner (owner_),
  43030. height (height_)
  43031. {
  43032. for (int i = owner_.items.size(); --i >= 0;)
  43033. {
  43034. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43035. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43036. {
  43037. oldIndexes.insert (0, i);
  43038. addAndMakeVisible (tc, 0);
  43039. }
  43040. }
  43041. layout (400);
  43042. }
  43043. ~MissingItemsComponent()
  43044. {
  43045. // deleting the toolbar while its menu it open??
  43046. jassert (owner.isValidComponent());
  43047. for (int i = 0; i < getNumChildComponents(); ++i)
  43048. {
  43049. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43050. if (tc != 0)
  43051. {
  43052. tc->setVisible (false);
  43053. const int index = oldIndexes.remove (i);
  43054. owner.addChildComponent (tc, index);
  43055. --i;
  43056. }
  43057. }
  43058. owner.resized();
  43059. }
  43060. void layout (const int preferredWidth)
  43061. {
  43062. const int indent = 8;
  43063. int x = indent;
  43064. int y = indent;
  43065. int maxX = 0;
  43066. for (int i = 0; i < getNumChildComponents(); ++i)
  43067. {
  43068. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43069. if (tc != 0)
  43070. {
  43071. int preferredSize = 1, minSize = 1, maxSize = 1;
  43072. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43073. {
  43074. if (x + preferredSize > preferredWidth && x > indent)
  43075. {
  43076. x = indent;
  43077. y += height;
  43078. }
  43079. tc->setBounds (x, y, preferredSize, height);
  43080. x += preferredSize;
  43081. maxX = jmax (maxX, x);
  43082. }
  43083. }
  43084. }
  43085. setSize (maxX + 8, y + height + 8);
  43086. }
  43087. void getIdealSize (int& idealWidth, int& idealHeight)
  43088. {
  43089. idealWidth = getWidth();
  43090. idealHeight = getHeight();
  43091. }
  43092. juce_UseDebuggingNewOperator
  43093. private:
  43094. Toolbar& owner;
  43095. const int height;
  43096. Array <int> oldIndexes;
  43097. MissingItemsComponent (const MissingItemsComponent&);
  43098. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43099. };
  43100. Toolbar::Toolbar()
  43101. : vertical (false),
  43102. isEditingActive (false),
  43103. toolbarStyle (Toolbar::iconsOnly)
  43104. {
  43105. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43106. missingItemsButton->setAlwaysOnTop (true);
  43107. missingItemsButton->addButtonListener (this);
  43108. }
  43109. Toolbar::~Toolbar()
  43110. {
  43111. animator.cancelAllAnimations (true);
  43112. deleteAllChildren();
  43113. }
  43114. void Toolbar::setVertical (const bool shouldBeVertical)
  43115. {
  43116. if (vertical != shouldBeVertical)
  43117. {
  43118. vertical = shouldBeVertical;
  43119. resized();
  43120. }
  43121. }
  43122. void Toolbar::clear()
  43123. {
  43124. for (int i = items.size(); --i >= 0;)
  43125. {
  43126. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43127. items.remove (i);
  43128. delete tc;
  43129. }
  43130. resized();
  43131. }
  43132. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43133. {
  43134. if (itemId == ToolbarItemFactory::separatorBarId)
  43135. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43136. else if (itemId == ToolbarItemFactory::spacerId)
  43137. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43138. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43139. return new ToolbarSpacerComp (itemId, 0, false);
  43140. return factory.createItem (itemId);
  43141. }
  43142. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43143. const int itemId,
  43144. const int insertIndex)
  43145. {
  43146. // An ID can't be zero - this might indicate a mistake somewhere?
  43147. jassert (itemId != 0);
  43148. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43149. if (tc != 0)
  43150. {
  43151. #ifdef JUCE_DEBUG
  43152. Array <int> allowedIds;
  43153. factory.getAllToolbarItemIds (allowedIds);
  43154. // If your factory can create an item for a given ID, it must also return
  43155. // that ID from its getAllToolbarItemIds() method!
  43156. jassert (allowedIds.contains (itemId));
  43157. #endif
  43158. items.insert (insertIndex, tc);
  43159. addAndMakeVisible (tc, insertIndex);
  43160. }
  43161. }
  43162. void Toolbar::addItem (ToolbarItemFactory& factory,
  43163. const int itemId,
  43164. const int insertIndex)
  43165. {
  43166. addItemInternal (factory, itemId, insertIndex);
  43167. resized();
  43168. }
  43169. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43170. {
  43171. Array <int> ids;
  43172. factoryToUse.getDefaultItemSet (ids);
  43173. clear();
  43174. for (int i = 0; i < ids.size(); ++i)
  43175. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43176. resized();
  43177. }
  43178. void Toolbar::removeToolbarItem (const int itemIndex)
  43179. {
  43180. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43181. if (tc != 0)
  43182. {
  43183. items.removeValue (tc);
  43184. delete tc;
  43185. resized();
  43186. }
  43187. }
  43188. int Toolbar::getNumItems() const throw()
  43189. {
  43190. return items.size();
  43191. }
  43192. int Toolbar::getItemId (const int itemIndex) const throw()
  43193. {
  43194. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43195. return tc != 0 ? tc->getItemId() : 0;
  43196. }
  43197. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43198. {
  43199. return items [itemIndex];
  43200. }
  43201. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43202. {
  43203. for (;;)
  43204. {
  43205. index += delta;
  43206. ToolbarItemComponent* const tc = getItemComponent (index);
  43207. if (tc == 0)
  43208. break;
  43209. if (tc->isActive)
  43210. return tc;
  43211. }
  43212. return 0;
  43213. }
  43214. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43215. {
  43216. if (toolbarStyle != newStyle)
  43217. {
  43218. toolbarStyle = newStyle;
  43219. updateAllItemPositions (false);
  43220. }
  43221. }
  43222. const String Toolbar::toString() const
  43223. {
  43224. String s ("TB:");
  43225. for (int i = 0; i < getNumItems(); ++i)
  43226. s << getItemId(i) << ' ';
  43227. return s.trimEnd();
  43228. }
  43229. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43230. const String& savedVersion)
  43231. {
  43232. if (! savedVersion.startsWith ("TB:"))
  43233. return false;
  43234. StringArray tokens;
  43235. tokens.addTokens (savedVersion.substring (3), false);
  43236. clear();
  43237. for (int i = 0; i < tokens.size(); ++i)
  43238. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43239. resized();
  43240. return true;
  43241. }
  43242. void Toolbar::paint (Graphics& g)
  43243. {
  43244. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43245. }
  43246. int Toolbar::getThickness() const throw()
  43247. {
  43248. return vertical ? getWidth() : getHeight();
  43249. }
  43250. int Toolbar::getLength() const throw()
  43251. {
  43252. return vertical ? getHeight() : getWidth();
  43253. }
  43254. void Toolbar::setEditingActive (const bool active)
  43255. {
  43256. if (isEditingActive != active)
  43257. {
  43258. isEditingActive = active;
  43259. updateAllItemPositions (false);
  43260. }
  43261. }
  43262. void Toolbar::resized()
  43263. {
  43264. updateAllItemPositions (false);
  43265. }
  43266. void Toolbar::updateAllItemPositions (const bool animate)
  43267. {
  43268. if (getWidth() > 0 && getHeight() > 0)
  43269. {
  43270. StretchableObjectResizer resizer;
  43271. int i;
  43272. for (i = 0; i < items.size(); ++i)
  43273. {
  43274. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43275. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43276. : ToolbarItemComponent::normalMode);
  43277. tc->setStyle (toolbarStyle);
  43278. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43279. int preferredSize = 1, minSize = 1, maxSize = 1;
  43280. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43281. preferredSize, minSize, maxSize))
  43282. {
  43283. tc->isActive = true;
  43284. resizer.addItem (preferredSize, minSize, maxSize,
  43285. spacer != 0 ? spacer->getResizeOrder() : 2);
  43286. }
  43287. else
  43288. {
  43289. tc->isActive = false;
  43290. tc->setVisible (false);
  43291. }
  43292. }
  43293. resizer.resizeToFit (getLength());
  43294. int totalLength = 0;
  43295. for (i = 0; i < resizer.getNumItems(); ++i)
  43296. totalLength += (int) resizer.getItemSize (i);
  43297. const bool itemsOffTheEnd = totalLength > getLength();
  43298. const int extrasButtonSize = getThickness() / 2;
  43299. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43300. missingItemsButton->setVisible (itemsOffTheEnd);
  43301. missingItemsButton->setEnabled (! isEditingActive);
  43302. if (vertical)
  43303. missingItemsButton->setCentrePosition (getWidth() / 2,
  43304. getHeight() - 4 - extrasButtonSize / 2);
  43305. else
  43306. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43307. getHeight() / 2);
  43308. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43309. : missingItemsButton->getX()) - 4
  43310. : getLength();
  43311. int pos = 0, activeIndex = 0;
  43312. for (i = 0; i < items.size(); ++i)
  43313. {
  43314. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43315. if (tc->isActive)
  43316. {
  43317. const int size = (int) resizer.getItemSize (activeIndex++);
  43318. Rectangle<int> newBounds;
  43319. if (vertical)
  43320. newBounds.setBounds (0, pos, getWidth(), size);
  43321. else
  43322. newBounds.setBounds (pos, 0, size, getHeight());
  43323. if (animate)
  43324. {
  43325. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43326. }
  43327. else
  43328. {
  43329. animator.cancelAnimation (tc, false);
  43330. tc->setBounds (newBounds);
  43331. }
  43332. pos += size;
  43333. tc->setVisible (pos <= maxLength
  43334. && ((! tc->isBeingDragged)
  43335. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43336. }
  43337. }
  43338. }
  43339. }
  43340. void Toolbar::buttonClicked (Button*)
  43341. {
  43342. jassert (missingItemsButton->isShowing());
  43343. if (missingItemsButton->isShowing())
  43344. {
  43345. PopupMenu m;
  43346. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43347. m.showAt (missingItemsButton);
  43348. }
  43349. }
  43350. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43351. Component* /*sourceComponent*/)
  43352. {
  43353. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43354. }
  43355. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43356. {
  43357. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43358. if (tc != 0)
  43359. {
  43360. if (getNumItems() == 0)
  43361. {
  43362. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43363. {
  43364. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43365. if (palette != 0)
  43366. palette->replaceComponent (tc);
  43367. }
  43368. else
  43369. {
  43370. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43371. }
  43372. items.add (tc);
  43373. addChildComponent (tc);
  43374. updateAllItemPositions (false);
  43375. }
  43376. else
  43377. {
  43378. for (int i = getNumItems(); --i >= 0;)
  43379. {
  43380. int currentIndex = getIndexOfChildComponent (tc);
  43381. if (currentIndex < 0)
  43382. {
  43383. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43384. {
  43385. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43386. if (palette != 0)
  43387. palette->replaceComponent (tc);
  43388. }
  43389. else
  43390. {
  43391. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43392. }
  43393. items.add (tc);
  43394. addChildComponent (tc);
  43395. currentIndex = getIndexOfChildComponent (tc);
  43396. updateAllItemPositions (true);
  43397. }
  43398. int newIndex = currentIndex;
  43399. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43400. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43401. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43402. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43403. if (prev != 0)
  43404. {
  43405. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43406. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43407. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43408. {
  43409. newIndex = getIndexOfChildComponent (prev);
  43410. }
  43411. }
  43412. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43413. if (next != 0)
  43414. {
  43415. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43416. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43417. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43418. {
  43419. newIndex = getIndexOfChildComponent (next) + 1;
  43420. }
  43421. }
  43422. if (newIndex != currentIndex)
  43423. {
  43424. items.removeValue (tc);
  43425. removeChildComponent (tc);
  43426. addChildComponent (tc, newIndex);
  43427. items.insert (newIndex, tc);
  43428. updateAllItemPositions (true);
  43429. }
  43430. else
  43431. {
  43432. break;
  43433. }
  43434. }
  43435. }
  43436. }
  43437. }
  43438. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43439. {
  43440. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43441. if (tc != 0)
  43442. {
  43443. if (isParentOf (tc))
  43444. {
  43445. items.removeValue (tc);
  43446. removeChildComponent (tc);
  43447. updateAllItemPositions (true);
  43448. }
  43449. }
  43450. }
  43451. void Toolbar::itemDropped (const String&, Component*, int, int)
  43452. {
  43453. }
  43454. void Toolbar::mouseDown (const MouseEvent& e)
  43455. {
  43456. if (e.mods.isPopupMenu())
  43457. {
  43458. }
  43459. }
  43460. class ToolbarCustomisationDialog : public DialogWindow
  43461. {
  43462. public:
  43463. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43464. Toolbar* const toolbar_,
  43465. const int optionFlags)
  43466. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43467. toolbar (toolbar_)
  43468. {
  43469. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43470. setResizable (true, true);
  43471. setResizeLimits (400, 300, 1500, 1000);
  43472. positionNearBar();
  43473. }
  43474. ~ToolbarCustomisationDialog()
  43475. {
  43476. setContentComponent (0, true);
  43477. }
  43478. void closeButtonPressed()
  43479. {
  43480. setVisible (false);
  43481. }
  43482. bool canModalEventBeSentToComponent (const Component* comp)
  43483. {
  43484. return toolbar->isParentOf (comp);
  43485. }
  43486. void positionNearBar()
  43487. {
  43488. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43489. const int tbx = toolbar->getScreenX();
  43490. const int tby = toolbar->getScreenY();
  43491. const int gap = 8;
  43492. int x, y;
  43493. if (toolbar->isVertical())
  43494. {
  43495. y = tby;
  43496. if (tbx > screenSize.getCentreX())
  43497. x = tbx - getWidth() - gap;
  43498. else
  43499. x = tbx + toolbar->getWidth() + gap;
  43500. }
  43501. else
  43502. {
  43503. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43504. if (tby > screenSize.getCentreY())
  43505. y = tby - getHeight() - gap;
  43506. else
  43507. y = tby + toolbar->getHeight() + gap;
  43508. }
  43509. setTopLeftPosition (x, y);
  43510. }
  43511. private:
  43512. Toolbar* const toolbar;
  43513. class CustomiserPanel : public Component,
  43514. private ComboBoxListener,
  43515. private ButtonListener
  43516. {
  43517. public:
  43518. CustomiserPanel (ToolbarItemFactory& factory_,
  43519. Toolbar* const toolbar_,
  43520. const int optionFlags)
  43521. : factory (factory_),
  43522. toolbar (toolbar_),
  43523. styleBox (0),
  43524. defaultButton (0)
  43525. {
  43526. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43527. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43528. | Toolbar::allowIconsWithTextChoice
  43529. | Toolbar::allowTextOnlyChoice)) != 0)
  43530. {
  43531. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43532. styleBox->setEditableText (false);
  43533. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43534. styleBox->addItem (TRANS("Show icons only"), 1);
  43535. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43536. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43537. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43538. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43539. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43540. styleBox->setSelectedId (1);
  43541. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43542. styleBox->setSelectedId (2);
  43543. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43544. styleBox->setSelectedId (3);
  43545. styleBox->addListener (this);
  43546. }
  43547. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43548. {
  43549. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43550. defaultButton->addButtonListener (this);
  43551. }
  43552. addAndMakeVisible (instructions = new Label (String::empty,
  43553. 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.")));
  43554. instructions->setFont (Font (13.0f));
  43555. setSize (500, 300);
  43556. }
  43557. ~CustomiserPanel()
  43558. {
  43559. deleteAllChildren();
  43560. }
  43561. void comboBoxChanged (ComboBox*)
  43562. {
  43563. if (styleBox->getSelectedId() == 1)
  43564. toolbar->setStyle (Toolbar::iconsOnly);
  43565. else if (styleBox->getSelectedId() == 2)
  43566. toolbar->setStyle (Toolbar::iconsWithText);
  43567. else if (styleBox->getSelectedId() == 3)
  43568. toolbar->setStyle (Toolbar::textOnly);
  43569. palette->resized(); // to make it update the styles
  43570. }
  43571. void buttonClicked (Button*)
  43572. {
  43573. toolbar->addDefaultItems (factory);
  43574. }
  43575. void paint (Graphics& g)
  43576. {
  43577. Colour background;
  43578. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43579. if (dw != 0)
  43580. background = dw->getBackgroundColour();
  43581. g.setColour (background.contrasting().withAlpha (0.3f));
  43582. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43583. }
  43584. void resized()
  43585. {
  43586. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43587. if (styleBox != 0)
  43588. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43589. if (defaultButton != 0)
  43590. {
  43591. defaultButton->changeWidthToFitText (22);
  43592. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43593. }
  43594. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43595. }
  43596. private:
  43597. ToolbarItemFactory& factory;
  43598. Toolbar* const toolbar;
  43599. Label* instructions;
  43600. ToolbarItemPalette* palette;
  43601. ComboBox* styleBox;
  43602. TextButton* defaultButton;
  43603. };
  43604. };
  43605. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43606. {
  43607. setEditingActive (true);
  43608. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43609. dw.runModalLoop();
  43610. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43611. setEditingActive (false);
  43612. }
  43613. END_JUCE_NAMESPACE
  43614. /*** End of inlined file: juce_Toolbar.cpp ***/
  43615. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43616. BEGIN_JUCE_NAMESPACE
  43617. ToolbarItemFactory::ToolbarItemFactory()
  43618. {
  43619. }
  43620. ToolbarItemFactory::~ToolbarItemFactory()
  43621. {
  43622. }
  43623. class ItemDragAndDropOverlayComponent : public Component
  43624. {
  43625. public:
  43626. ItemDragAndDropOverlayComponent()
  43627. : isDragging (false)
  43628. {
  43629. setAlwaysOnTop (true);
  43630. setRepaintsOnMouseActivity (true);
  43631. setMouseCursor (MouseCursor::DraggingHandCursor);
  43632. }
  43633. ~ItemDragAndDropOverlayComponent()
  43634. {
  43635. }
  43636. void paint (Graphics& g)
  43637. {
  43638. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43639. if (isMouseOverOrDragging()
  43640. && tc != 0
  43641. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43642. {
  43643. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43644. g.drawRect (0, 0, getWidth(), getHeight(),
  43645. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43646. }
  43647. }
  43648. void mouseDown (const MouseEvent& e)
  43649. {
  43650. isDragging = false;
  43651. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43652. if (tc != 0)
  43653. {
  43654. tc->dragOffsetX = e.x;
  43655. tc->dragOffsetY = e.y;
  43656. }
  43657. }
  43658. void mouseDrag (const MouseEvent& e)
  43659. {
  43660. if (! (isDragging || e.mouseWasClicked()))
  43661. {
  43662. isDragging = true;
  43663. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43664. if (dnd != 0)
  43665. {
  43666. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43667. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43668. if (tc != 0)
  43669. {
  43670. tc->isBeingDragged = true;
  43671. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43672. tc->setVisible (false);
  43673. }
  43674. }
  43675. }
  43676. }
  43677. void mouseUp (const MouseEvent&)
  43678. {
  43679. isDragging = false;
  43680. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43681. if (tc != 0)
  43682. {
  43683. tc->isBeingDragged = false;
  43684. Toolbar* const tb = tc->getToolbar();
  43685. if (tb != 0)
  43686. tb->updateAllItemPositions (true);
  43687. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43688. delete tc;
  43689. }
  43690. }
  43691. void parentSizeChanged()
  43692. {
  43693. setBounds (0, 0, getParentWidth(), getParentHeight());
  43694. }
  43695. juce_UseDebuggingNewOperator
  43696. private:
  43697. bool isDragging;
  43698. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43699. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43700. };
  43701. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43702. const String& labelText,
  43703. const bool isBeingUsedAsAButton_)
  43704. : Button (labelText),
  43705. itemId (itemId_),
  43706. mode (normalMode),
  43707. toolbarStyle (Toolbar::iconsOnly),
  43708. dragOffsetX (0),
  43709. dragOffsetY (0),
  43710. isActive (true),
  43711. isBeingDragged (false),
  43712. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43713. {
  43714. // Your item ID can't be 0!
  43715. jassert (itemId_ != 0);
  43716. }
  43717. ToolbarItemComponent::~ToolbarItemComponent()
  43718. {
  43719. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43720. overlayComp = 0;
  43721. }
  43722. Toolbar* ToolbarItemComponent::getToolbar() const
  43723. {
  43724. return dynamic_cast <Toolbar*> (getParentComponent());
  43725. }
  43726. bool ToolbarItemComponent::isToolbarVertical() const
  43727. {
  43728. const Toolbar* const t = getToolbar();
  43729. return t != 0 && t->isVertical();
  43730. }
  43731. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43732. {
  43733. if (toolbarStyle != newStyle)
  43734. {
  43735. toolbarStyle = newStyle;
  43736. repaint();
  43737. resized();
  43738. }
  43739. }
  43740. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43741. {
  43742. if (isBeingUsedAsAButton)
  43743. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43744. isMouseOver, isMouseDown, *this);
  43745. if (toolbarStyle != Toolbar::iconsOnly)
  43746. {
  43747. const int indent = contentArea.getX();
  43748. int y = indent;
  43749. int h = getHeight() - indent * 2;
  43750. if (toolbarStyle == Toolbar::iconsWithText)
  43751. {
  43752. y = contentArea.getBottom() + indent / 2;
  43753. h -= contentArea.getHeight();
  43754. }
  43755. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43756. getButtonText(), *this);
  43757. }
  43758. if (! contentArea.isEmpty())
  43759. {
  43760. g.saveState();
  43761. g.setOrigin (contentArea.getX(), contentArea.getY());
  43762. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43763. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43764. g.restoreState();
  43765. }
  43766. }
  43767. void ToolbarItemComponent::resized()
  43768. {
  43769. if (toolbarStyle != Toolbar::textOnly)
  43770. {
  43771. const int indent = jmin (proportionOfWidth (0.08f),
  43772. proportionOfHeight (0.08f));
  43773. contentArea = Rectangle<int> (indent, indent,
  43774. getWidth() - indent * 2,
  43775. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43776. : (getHeight() - indent * 2));
  43777. }
  43778. else
  43779. {
  43780. contentArea = Rectangle<int>();
  43781. }
  43782. contentAreaChanged (contentArea);
  43783. }
  43784. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43785. {
  43786. if (mode != newMode)
  43787. {
  43788. mode = newMode;
  43789. repaint();
  43790. if (mode == normalMode)
  43791. {
  43792. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43793. overlayComp = 0;
  43794. }
  43795. else if (overlayComp == 0)
  43796. {
  43797. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43798. overlayComp->parentSizeChanged();
  43799. }
  43800. resized();
  43801. }
  43802. }
  43803. END_JUCE_NAMESPACE
  43804. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43805. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43806. BEGIN_JUCE_NAMESPACE
  43807. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43808. Toolbar* const toolbar_)
  43809. : factory (factory_),
  43810. toolbar (toolbar_)
  43811. {
  43812. Component* const itemHolder = new Component();
  43813. Array <int> allIds;
  43814. factory_.getAllToolbarItemIds (allIds);
  43815. for (int i = 0; i < allIds.size(); ++i)
  43816. {
  43817. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43818. jassert (tc != 0);
  43819. if (tc != 0)
  43820. {
  43821. itemHolder->addAndMakeVisible (tc);
  43822. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43823. }
  43824. }
  43825. viewport = new Viewport();
  43826. viewport->setViewedComponent (itemHolder);
  43827. addAndMakeVisible (viewport);
  43828. }
  43829. ToolbarItemPalette::~ToolbarItemPalette()
  43830. {
  43831. viewport->getViewedComponent()->deleteAllChildren();
  43832. deleteAllChildren();
  43833. }
  43834. void ToolbarItemPalette::resized()
  43835. {
  43836. viewport->setBoundsInset (BorderSize (1));
  43837. Component* const itemHolder = viewport->getViewedComponent();
  43838. const int indent = 8;
  43839. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43840. const int height = toolbar->getThickness();
  43841. int x = indent;
  43842. int y = indent;
  43843. int maxX = 0;
  43844. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43845. {
  43846. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43847. if (tc != 0)
  43848. {
  43849. tc->setStyle (toolbar->getStyle());
  43850. int preferredSize = 1, minSize = 1, maxSize = 1;
  43851. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43852. {
  43853. if (x + preferredSize > preferredWidth && x > indent)
  43854. {
  43855. x = indent;
  43856. y += height;
  43857. }
  43858. tc->setBounds (x, y, preferredSize, height);
  43859. x += preferredSize + 8;
  43860. maxX = jmax (maxX, x);
  43861. }
  43862. }
  43863. }
  43864. itemHolder->setSize (maxX, y + height + 8);
  43865. }
  43866. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43867. {
  43868. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43869. jassert (tc != 0);
  43870. if (tc != 0)
  43871. {
  43872. tc->setBounds (comp->getBounds());
  43873. tc->setStyle (toolbar->getStyle());
  43874. tc->setEditingMode (comp->getEditingMode());
  43875. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43876. }
  43877. }
  43878. END_JUCE_NAMESPACE
  43879. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43880. /*** Start of inlined file: juce_TreeView.cpp ***/
  43881. BEGIN_JUCE_NAMESPACE
  43882. class TreeViewContentComponent : public Component,
  43883. public TooltipClient
  43884. {
  43885. public:
  43886. TreeViewContentComponent (TreeView* const owner_)
  43887. : owner (owner_),
  43888. buttonUnderMouse (0),
  43889. isDragging (false)
  43890. {
  43891. }
  43892. ~TreeViewContentComponent()
  43893. {
  43894. deleteAllChildren();
  43895. }
  43896. void mouseDown (const MouseEvent& e)
  43897. {
  43898. updateButtonUnderMouse (e);
  43899. isDragging = false;
  43900. needSelectionOnMouseUp = false;
  43901. Rectangle<int> pos;
  43902. TreeViewItem* const item = findItemAt (e.y, pos);
  43903. if (item == 0)
  43904. return;
  43905. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43906. // as selection clicks)
  43907. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43908. {
  43909. if (e.x >= pos.getX() - owner->getIndentSize())
  43910. item->setOpen (! item->isOpen());
  43911. // (clicks to the left of an open/close button are ignored)
  43912. }
  43913. else
  43914. {
  43915. // mouse-down inside the body of the item..
  43916. if (! owner->isMultiSelectEnabled())
  43917. item->setSelected (true, true);
  43918. else if (item->isSelected())
  43919. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43920. else
  43921. selectBasedOnModifiers (item, e.mods);
  43922. if (e.x >= pos.getX())
  43923. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43924. }
  43925. }
  43926. void mouseUp (const MouseEvent& e)
  43927. {
  43928. updateButtonUnderMouse (e);
  43929. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43930. {
  43931. Rectangle<int> pos;
  43932. TreeViewItem* const item = findItemAt (e.y, pos);
  43933. if (item != 0)
  43934. selectBasedOnModifiers (item, e.mods);
  43935. }
  43936. }
  43937. void mouseDoubleClick (const MouseEvent& e)
  43938. {
  43939. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43940. {
  43941. Rectangle<int> pos;
  43942. TreeViewItem* const item = findItemAt (e.y, pos);
  43943. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43944. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43945. }
  43946. }
  43947. void mouseDrag (const MouseEvent& e)
  43948. {
  43949. if (isEnabled()
  43950. && ! (isDragging || e.mouseWasClicked()
  43951. || e.getDistanceFromDragStart() < 5
  43952. || e.mods.isPopupMenu()))
  43953. {
  43954. isDragging = true;
  43955. Rectangle<int> pos;
  43956. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43957. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43958. {
  43959. const String dragDescription (item->getDragSourceDescription());
  43960. if (dragDescription.isNotEmpty())
  43961. {
  43962. DragAndDropContainer* const dragContainer
  43963. = DragAndDropContainer::findParentDragContainerFor (this);
  43964. if (dragContainer != 0)
  43965. {
  43966. pos.setSize (pos.getWidth(), item->itemHeight);
  43967. Image* dragImage = Component::createComponentSnapshot (pos, true);
  43968. dragImage->multiplyAllAlphas (0.6f);
  43969. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  43970. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  43971. }
  43972. else
  43973. {
  43974. // to be able to do a drag-and-drop operation, the treeview needs to
  43975. // be inside a component which is also a DragAndDropContainer.
  43976. jassertfalse
  43977. }
  43978. }
  43979. }
  43980. }
  43981. }
  43982. void mouseMove (const MouseEvent& e)
  43983. {
  43984. updateButtonUnderMouse (e);
  43985. }
  43986. void mouseExit (const MouseEvent& e)
  43987. {
  43988. updateButtonUnderMouse (e);
  43989. }
  43990. void paint (Graphics& g);
  43991. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  43992. static bool isMouseDraggingInChildCompOf (Component* const comp)
  43993. {
  43994. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  43995. {
  43996. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  43997. if (source->isDragging())
  43998. {
  43999. Component* const underMouse = source->getComponentUnderMouse();
  44000. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44001. return true;
  44002. }
  44003. }
  44004. return false;
  44005. }
  44006. void updateComponents()
  44007. {
  44008. const int visibleTop = -getY();
  44009. const int visibleBottom = visibleTop + getParentHeight();
  44010. BigInteger itemsToKeep;
  44011. TreeViewItem* item = owner->rootItem;
  44012. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44013. while (item != 0 && y < visibleBottom)
  44014. {
  44015. y += item->itemHeight;
  44016. if (y >= visibleTop)
  44017. {
  44018. const int index = rowComponentIds.indexOf (item->uid);
  44019. if (index < 0)
  44020. {
  44021. Component* const comp = item->createItemComponent();
  44022. if (comp != 0)
  44023. {
  44024. addAndMakeVisible (comp);
  44025. itemsToKeep.setBit (rowComponentItems.size());
  44026. rowComponentItems.add (item);
  44027. rowComponentIds.add (item->uid);
  44028. rowComponents.add (comp);
  44029. }
  44030. }
  44031. else
  44032. {
  44033. itemsToKeep.setBit (index);
  44034. }
  44035. }
  44036. item = item->getNextVisibleItem (true);
  44037. }
  44038. for (int i = rowComponentItems.size(); --i >= 0;)
  44039. {
  44040. Component* const comp = rowComponents.getUnchecked(i);
  44041. bool keep = false;
  44042. if (isParentOf (comp))
  44043. {
  44044. if (itemsToKeep[i])
  44045. {
  44046. const TreeViewItem* const item = rowComponentItems.getUnchecked(i);
  44047. Rectangle<int> pos (item->getItemPosition (false));
  44048. pos.setSize (pos.getWidth(), item->itemHeight);
  44049. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44050. {
  44051. keep = true;
  44052. comp->setBounds (pos);
  44053. }
  44054. }
  44055. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44056. {
  44057. keep = true;
  44058. comp->setSize (0, 0);
  44059. }
  44060. }
  44061. if (! keep)
  44062. {
  44063. delete comp;
  44064. rowComponents.remove (i);
  44065. rowComponentIds.remove (i);
  44066. rowComponentItems.remove (i);
  44067. }
  44068. }
  44069. }
  44070. void updateButtonUnderMouse (const MouseEvent& e)
  44071. {
  44072. TreeViewItem* newItem = 0;
  44073. if (owner->openCloseButtonsVisible)
  44074. {
  44075. Rectangle<int> pos;
  44076. TreeViewItem* item = findItemAt (e.y, pos);
  44077. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44078. {
  44079. newItem = item;
  44080. if (! newItem->mightContainSubItems())
  44081. newItem = 0;
  44082. }
  44083. }
  44084. if (buttonUnderMouse != newItem)
  44085. {
  44086. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44087. {
  44088. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44089. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44090. }
  44091. buttonUnderMouse = newItem;
  44092. if (buttonUnderMouse != 0)
  44093. {
  44094. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44095. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44096. }
  44097. }
  44098. }
  44099. bool isMouseOverButton (TreeViewItem* item) const throw()
  44100. {
  44101. return item == buttonUnderMouse;
  44102. }
  44103. void resized()
  44104. {
  44105. owner->itemsChanged();
  44106. }
  44107. const String getTooltip()
  44108. {
  44109. Rectangle<int> pos;
  44110. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44111. if (item != 0)
  44112. return item->getTooltip();
  44113. return owner->getTooltip();
  44114. }
  44115. juce_UseDebuggingNewOperator
  44116. private:
  44117. TreeView* const owner;
  44118. Array <TreeViewItem*> rowComponentItems;
  44119. Array <int> rowComponentIds;
  44120. Array <Component*> rowComponents;
  44121. TreeViewItem* buttonUnderMouse;
  44122. bool isDragging, needSelectionOnMouseUp;
  44123. TreeViewContentComponent (const TreeViewContentComponent&);
  44124. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44125. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44126. {
  44127. TreeViewItem* firstSelected = 0;
  44128. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44129. {
  44130. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44131. jassert (lastSelected != 0);
  44132. int rowStart = firstSelected->getRowNumberInTree();
  44133. int rowEnd = lastSelected->getRowNumberInTree();
  44134. if (rowStart > rowEnd)
  44135. swapVariables (rowStart, rowEnd);
  44136. int ourRow = item->getRowNumberInTree();
  44137. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44138. if (ourRow > otherEnd)
  44139. swapVariables (ourRow, otherEnd);
  44140. for (int i = ourRow; i <= otherEnd; ++i)
  44141. owner->getItemOnRow (i)->setSelected (true, false);
  44142. }
  44143. else
  44144. {
  44145. const bool cmd = modifiers.isCommandDown();
  44146. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44147. }
  44148. }
  44149. bool containsItem (TreeViewItem* const item) const
  44150. {
  44151. for (int i = rowComponentItems.size(); --i >= 0;)
  44152. if (rowComponentItems.getUnchecked(i) == item)
  44153. return true;
  44154. return false;
  44155. }
  44156. };
  44157. class TreeView::TreeViewport : public Viewport
  44158. {
  44159. public:
  44160. TreeViewport() throw() {}
  44161. ~TreeViewport() throw() {}
  44162. void updateComponents()
  44163. {
  44164. TreeViewContentComponent* const tvc = static_cast <TreeViewContentComponent*> (getViewedComponent());
  44165. if (tvc != 0)
  44166. tvc->updateComponents();
  44167. repaint();
  44168. }
  44169. void visibleAreaChanged (int, int, int, int)
  44170. {
  44171. updateComponents();
  44172. }
  44173. juce_UseDebuggingNewOperator
  44174. private:
  44175. TreeViewport (const TreeViewport&);
  44176. TreeViewport& operator= (const TreeViewport&);
  44177. };
  44178. TreeView::TreeView (const String& componentName)
  44179. : Component (componentName),
  44180. rootItem (0),
  44181. dragInsertPointHighlight (0),
  44182. dragTargetGroupHighlight (0),
  44183. indentSize (24),
  44184. defaultOpenness (false),
  44185. needsRecalculating (true),
  44186. rootItemVisible (true),
  44187. multiSelectEnabled (false),
  44188. openCloseButtonsVisible (true)
  44189. {
  44190. addAndMakeVisible (viewport = new TreeViewport());
  44191. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44192. viewport->setWantsKeyboardFocus (false);
  44193. setWantsKeyboardFocus (true);
  44194. }
  44195. TreeView::~TreeView()
  44196. {
  44197. if (rootItem != 0)
  44198. rootItem->setOwnerView (0);
  44199. deleteAllChildren();
  44200. }
  44201. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44202. {
  44203. if (rootItem != newRootItem)
  44204. {
  44205. if (newRootItem != 0)
  44206. {
  44207. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44208. if (newRootItem->ownerView != 0)
  44209. newRootItem->ownerView->setRootItem (0);
  44210. }
  44211. if (rootItem != 0)
  44212. rootItem->setOwnerView (0);
  44213. rootItem = newRootItem;
  44214. if (newRootItem != 0)
  44215. newRootItem->setOwnerView (this);
  44216. needsRecalculating = true;
  44217. handleAsyncUpdate();
  44218. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44219. {
  44220. rootItem->setOpen (false); // force a re-open
  44221. rootItem->setOpen (true);
  44222. }
  44223. }
  44224. }
  44225. void TreeView::deleteRootItem()
  44226. {
  44227. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44228. setRootItem (0);
  44229. }
  44230. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44231. {
  44232. rootItemVisible = shouldBeVisible;
  44233. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44234. {
  44235. rootItem->setOpen (false); // force a re-open
  44236. rootItem->setOpen (true);
  44237. }
  44238. itemsChanged();
  44239. }
  44240. void TreeView::colourChanged()
  44241. {
  44242. setOpaque (findColour (backgroundColourId).isOpaque());
  44243. repaint();
  44244. }
  44245. void TreeView::setIndentSize (const int newIndentSize)
  44246. {
  44247. if (indentSize != newIndentSize)
  44248. {
  44249. indentSize = newIndentSize;
  44250. resized();
  44251. }
  44252. }
  44253. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44254. {
  44255. if (defaultOpenness != isOpenByDefault)
  44256. {
  44257. defaultOpenness = isOpenByDefault;
  44258. itemsChanged();
  44259. }
  44260. }
  44261. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44262. {
  44263. multiSelectEnabled = canMultiSelect;
  44264. }
  44265. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44266. {
  44267. if (openCloseButtonsVisible != shouldBeVisible)
  44268. {
  44269. openCloseButtonsVisible = shouldBeVisible;
  44270. itemsChanged();
  44271. }
  44272. }
  44273. Viewport* TreeView::getViewport() const throw()
  44274. {
  44275. return viewport;
  44276. }
  44277. void TreeView::clearSelectedItems()
  44278. {
  44279. if (rootItem != 0)
  44280. rootItem->deselectAllRecursively();
  44281. }
  44282. int TreeView::getNumSelectedItems() const throw()
  44283. {
  44284. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44285. }
  44286. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44287. {
  44288. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44289. }
  44290. int TreeView::getNumRowsInTree() const
  44291. {
  44292. if (rootItem != 0)
  44293. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44294. return 0;
  44295. }
  44296. TreeViewItem* TreeView::getItemOnRow (int index) const
  44297. {
  44298. if (! rootItemVisible)
  44299. ++index;
  44300. if (rootItem != 0 && index >= 0)
  44301. return rootItem->getItemOnRow (index);
  44302. return 0;
  44303. }
  44304. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44305. {
  44306. TreeViewContentComponent* const tc = static_cast <TreeViewContentComponent*> (viewport->getViewedComponent());
  44307. Rectangle<int> pos;
  44308. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44309. }
  44310. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44311. {
  44312. if (rootItem == 0)
  44313. return 0;
  44314. return rootItem->findItemFromIdentifierString (identifierString);
  44315. }
  44316. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44317. {
  44318. XmlElement* e = 0;
  44319. if (rootItem != 0)
  44320. {
  44321. e = rootItem->getOpennessState();
  44322. if (e != 0 && alsoIncludeScrollPosition)
  44323. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44324. }
  44325. return e;
  44326. }
  44327. void TreeView::restoreOpennessState (const XmlElement& newState)
  44328. {
  44329. if (rootItem != 0)
  44330. {
  44331. rootItem->restoreOpennessState (newState);
  44332. if (newState.hasAttribute ("scrollPos"))
  44333. viewport->setViewPosition (viewport->getViewPositionX(),
  44334. newState.getIntAttribute ("scrollPos"));
  44335. }
  44336. }
  44337. void TreeView::paint (Graphics& g)
  44338. {
  44339. g.fillAll (findColour (backgroundColourId));
  44340. }
  44341. void TreeView::resized()
  44342. {
  44343. viewport->setBounds (0, 0, getWidth(), getHeight());
  44344. itemsChanged();
  44345. handleAsyncUpdate();
  44346. }
  44347. void TreeView::enablementChanged()
  44348. {
  44349. repaint();
  44350. }
  44351. void TreeView::moveSelectedRow (int delta)
  44352. {
  44353. if (delta == 0)
  44354. return;
  44355. int rowSelected = 0;
  44356. TreeViewItem* const firstSelected = getSelectedItem (0);
  44357. if (firstSelected != 0)
  44358. rowSelected = firstSelected->getRowNumberInTree();
  44359. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44360. for (;;)
  44361. {
  44362. TreeViewItem* item = getItemOnRow (rowSelected);
  44363. if (item != 0)
  44364. {
  44365. if (! item->canBeSelected())
  44366. {
  44367. // if the row we want to highlight doesn't allow it, try skipping
  44368. // to the next item..
  44369. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44370. rowSelected + (delta < 0 ? -1 : 1));
  44371. if (rowSelected != nextRowToTry)
  44372. {
  44373. rowSelected = nextRowToTry;
  44374. continue;
  44375. }
  44376. else
  44377. {
  44378. break;
  44379. }
  44380. }
  44381. item->setSelected (true, true);
  44382. scrollToKeepItemVisible (item);
  44383. }
  44384. break;
  44385. }
  44386. }
  44387. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44388. {
  44389. if (item != 0 && item->ownerView == this)
  44390. {
  44391. handleAsyncUpdate();
  44392. item = item->getDeepestOpenParentItem();
  44393. int y = item->y;
  44394. int viewTop = viewport->getViewPositionY();
  44395. if (y < viewTop)
  44396. {
  44397. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44398. }
  44399. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44400. {
  44401. viewport->setViewPosition (viewport->getViewPositionX(),
  44402. (y + item->itemHeight) - viewport->getViewHeight());
  44403. }
  44404. }
  44405. }
  44406. bool TreeView::keyPressed (const KeyPress& key)
  44407. {
  44408. if (key.isKeyCode (KeyPress::upKey))
  44409. {
  44410. moveSelectedRow (-1);
  44411. }
  44412. else if (key.isKeyCode (KeyPress::downKey))
  44413. {
  44414. moveSelectedRow (1);
  44415. }
  44416. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44417. {
  44418. if (rootItem != 0)
  44419. {
  44420. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44421. if (key.isKeyCode (KeyPress::pageUpKey))
  44422. rowsOnScreen = -rowsOnScreen;
  44423. moveSelectedRow (rowsOnScreen);
  44424. }
  44425. }
  44426. else if (key.isKeyCode (KeyPress::homeKey))
  44427. {
  44428. moveSelectedRow (-0x3fffffff);
  44429. }
  44430. else if (key.isKeyCode (KeyPress::endKey))
  44431. {
  44432. moveSelectedRow (0x3fffffff);
  44433. }
  44434. else if (key.isKeyCode (KeyPress::returnKey))
  44435. {
  44436. TreeViewItem* const firstSelected = getSelectedItem (0);
  44437. if (firstSelected != 0)
  44438. firstSelected->setOpen (! firstSelected->isOpen());
  44439. }
  44440. else if (key.isKeyCode (KeyPress::leftKey))
  44441. {
  44442. TreeViewItem* const firstSelected = getSelectedItem (0);
  44443. if (firstSelected != 0)
  44444. {
  44445. if (firstSelected->isOpen())
  44446. {
  44447. firstSelected->setOpen (false);
  44448. }
  44449. else
  44450. {
  44451. TreeViewItem* parent = firstSelected->parentItem;
  44452. if ((! rootItemVisible) && parent == rootItem)
  44453. parent = 0;
  44454. if (parent != 0)
  44455. {
  44456. parent->setSelected (true, true);
  44457. scrollToKeepItemVisible (parent);
  44458. }
  44459. }
  44460. }
  44461. }
  44462. else if (key.isKeyCode (KeyPress::rightKey))
  44463. {
  44464. TreeViewItem* const firstSelected = getSelectedItem (0);
  44465. if (firstSelected != 0)
  44466. {
  44467. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44468. moveSelectedRow (1);
  44469. else
  44470. firstSelected->setOpen (true);
  44471. }
  44472. }
  44473. else
  44474. {
  44475. return false;
  44476. }
  44477. return true;
  44478. }
  44479. void TreeView::itemsChanged() throw()
  44480. {
  44481. needsRecalculating = true;
  44482. repaint();
  44483. triggerAsyncUpdate();
  44484. }
  44485. void TreeView::handleAsyncUpdate()
  44486. {
  44487. if (needsRecalculating)
  44488. {
  44489. needsRecalculating = false;
  44490. const ScopedLock sl (nodeAlterationLock);
  44491. if (rootItem != 0)
  44492. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44493. viewport->updateComponents();
  44494. if (rootItem != 0)
  44495. {
  44496. viewport->getViewedComponent()
  44497. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44498. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44499. }
  44500. else
  44501. {
  44502. viewport->getViewedComponent()->setSize (0, 0);
  44503. }
  44504. }
  44505. }
  44506. class TreeView::InsertPointHighlight : public Component
  44507. {
  44508. public:
  44509. InsertPointHighlight()
  44510. : lastItem (0)
  44511. {
  44512. setSize (100, 12);
  44513. setAlwaysOnTop (true);
  44514. setInterceptsMouseClicks (false, false);
  44515. }
  44516. ~InsertPointHighlight() {}
  44517. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44518. {
  44519. lastItem = item;
  44520. lastIndex = insertIndex;
  44521. const int offset = getHeight() / 2;
  44522. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44523. }
  44524. void paint (Graphics& g)
  44525. {
  44526. Path p;
  44527. const float h = (float) getHeight();
  44528. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44529. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44530. p.lineTo ((float) getWidth(), h / 2.0f);
  44531. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44532. g.strokePath (p, PathStrokeType (2.0f));
  44533. }
  44534. TreeViewItem* lastItem;
  44535. int lastIndex;
  44536. private:
  44537. InsertPointHighlight (const InsertPointHighlight&);
  44538. InsertPointHighlight& operator= (const InsertPointHighlight&);
  44539. };
  44540. class TreeView::TargetGroupHighlight : public Component
  44541. {
  44542. public:
  44543. TargetGroupHighlight()
  44544. {
  44545. setAlwaysOnTop (true);
  44546. setInterceptsMouseClicks (false, false);
  44547. }
  44548. ~TargetGroupHighlight() {}
  44549. void setTargetPosition (TreeViewItem* const item) throw()
  44550. {
  44551. Rectangle<int> r (item->getItemPosition (true));
  44552. r.setHeight (item->getItemHeight());
  44553. setBounds (r);
  44554. }
  44555. void paint (Graphics& g)
  44556. {
  44557. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44558. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44559. }
  44560. private:
  44561. TargetGroupHighlight (const TargetGroupHighlight&);
  44562. TargetGroupHighlight& operator= (const TargetGroupHighlight&);
  44563. };
  44564. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44565. {
  44566. beginDragAutoRepeat (1000 / 30);
  44567. if (dragInsertPointHighlight == 0)
  44568. {
  44569. addAndMakeVisible (dragInsertPointHighlight = new InsertPointHighlight());
  44570. addAndMakeVisible (dragTargetGroupHighlight = new TargetGroupHighlight());
  44571. }
  44572. dragInsertPointHighlight->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44573. dragTargetGroupHighlight->setTargetPosition (item);
  44574. }
  44575. void TreeView::hideDragHighlight() throw()
  44576. {
  44577. deleteAndZero (dragInsertPointHighlight);
  44578. deleteAndZero (dragTargetGroupHighlight);
  44579. }
  44580. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44581. const StringArray& files, const String& sourceDescription,
  44582. Component* sourceComponent) const throw()
  44583. {
  44584. insertIndex = 0;
  44585. TreeViewItem* item = getItemAt (y);
  44586. if (item == 0)
  44587. return 0;
  44588. Rectangle<int> itemPos (item->getItemPosition (true));
  44589. insertIndex = item->getIndexInParent();
  44590. const int oldY = y;
  44591. y = itemPos.getY();
  44592. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44593. {
  44594. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44595. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44596. {
  44597. // Check if we're trying to drag into an empty group item..
  44598. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44599. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44600. {
  44601. insertIndex = 0;
  44602. x = itemPos.getX() + getIndentSize();
  44603. y = itemPos.getBottom();
  44604. return item;
  44605. }
  44606. }
  44607. }
  44608. if (oldY > itemPos.getCentreY())
  44609. {
  44610. y += item->getItemHeight();
  44611. while (item->isLastOfSiblings() && item->parentItem != 0
  44612. && item->parentItem->parentItem != 0)
  44613. {
  44614. if (x > itemPos.getX())
  44615. break;
  44616. item = item->parentItem;
  44617. itemPos = item->getItemPosition (true);
  44618. insertIndex = item->getIndexInParent();
  44619. }
  44620. ++insertIndex;
  44621. }
  44622. x = itemPos.getX();
  44623. return item->parentItem;
  44624. }
  44625. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44626. {
  44627. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44628. int insertIndex;
  44629. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44630. if (item != 0)
  44631. {
  44632. if (scrolled || dragInsertPointHighlight == 0
  44633. || dragInsertPointHighlight->lastItem != item
  44634. || dragInsertPointHighlight->lastIndex != insertIndex)
  44635. {
  44636. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44637. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44638. showDragHighlight (item, insertIndex, x, y);
  44639. else
  44640. hideDragHighlight();
  44641. }
  44642. }
  44643. else
  44644. {
  44645. hideDragHighlight();
  44646. }
  44647. }
  44648. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44649. {
  44650. hideDragHighlight();
  44651. int insertIndex;
  44652. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44653. if (item != 0)
  44654. {
  44655. if (files.size() > 0)
  44656. {
  44657. if (item->isInterestedInFileDrag (files))
  44658. item->filesDropped (files, insertIndex);
  44659. }
  44660. else
  44661. {
  44662. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44663. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44664. }
  44665. }
  44666. }
  44667. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44668. {
  44669. return true;
  44670. }
  44671. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44672. {
  44673. fileDragMove (files, x, y);
  44674. }
  44675. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44676. {
  44677. handleDrag (files, String::empty, 0, x, y);
  44678. }
  44679. void TreeView::fileDragExit (const StringArray&)
  44680. {
  44681. hideDragHighlight();
  44682. }
  44683. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44684. {
  44685. handleDrop (files, String::empty, 0, x, y);
  44686. }
  44687. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44688. {
  44689. return true;
  44690. }
  44691. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44692. {
  44693. itemDragMove (sourceDescription, sourceComponent, x, y);
  44694. }
  44695. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44696. {
  44697. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44698. }
  44699. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44700. {
  44701. hideDragHighlight();
  44702. }
  44703. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44704. {
  44705. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44706. }
  44707. void TreeViewContentComponent::paint (Graphics& g)
  44708. {
  44709. if (owner->rootItem != 0)
  44710. {
  44711. owner->handleAsyncUpdate();
  44712. if (! owner->rootItemVisible)
  44713. g.setOrigin (0, -owner->rootItem->itemHeight);
  44714. owner->rootItem->paintRecursively (g, getWidth());
  44715. }
  44716. }
  44717. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44718. {
  44719. if (owner->rootItem != 0)
  44720. {
  44721. owner->handleAsyncUpdate();
  44722. if (! owner->rootItemVisible)
  44723. y += owner->rootItem->itemHeight;
  44724. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44725. if (ti != 0)
  44726. itemPosition = ti->getItemPosition (false);
  44727. return ti;
  44728. }
  44729. return 0;
  44730. }
  44731. enum TreeViewOpenness
  44732. {
  44733. opennessDefault = 0,
  44734. opennessClosed = 1,
  44735. opennessOpen = 2
  44736. };
  44737. TreeViewItem::TreeViewItem()
  44738. : ownerView (0),
  44739. parentItem (0),
  44740. y (0),
  44741. itemHeight (0),
  44742. totalHeight (0),
  44743. selected (false),
  44744. redrawNeeded (true),
  44745. drawLinesInside (true),
  44746. drawsInLeftMargin (false),
  44747. openness (opennessDefault)
  44748. {
  44749. static int nextUID = 0;
  44750. uid = nextUID++;
  44751. }
  44752. TreeViewItem::~TreeViewItem()
  44753. {
  44754. }
  44755. const String TreeViewItem::getUniqueName() const
  44756. {
  44757. return String::empty;
  44758. }
  44759. void TreeViewItem::itemOpennessChanged (bool)
  44760. {
  44761. }
  44762. int TreeViewItem::getNumSubItems() const throw()
  44763. {
  44764. return subItems.size();
  44765. }
  44766. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44767. {
  44768. return subItems [index];
  44769. }
  44770. void TreeViewItem::clearSubItems()
  44771. {
  44772. if (subItems.size() > 0)
  44773. {
  44774. if (ownerView != 0)
  44775. {
  44776. const ScopedLock sl (ownerView->nodeAlterationLock);
  44777. subItems.clear();
  44778. treeHasChanged();
  44779. }
  44780. else
  44781. {
  44782. subItems.clear();
  44783. }
  44784. }
  44785. }
  44786. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44787. {
  44788. if (newItem != 0)
  44789. {
  44790. newItem->parentItem = this;
  44791. newItem->setOwnerView (ownerView);
  44792. newItem->y = 0;
  44793. newItem->itemHeight = newItem->getItemHeight();
  44794. newItem->totalHeight = 0;
  44795. newItem->itemWidth = newItem->getItemWidth();
  44796. newItem->totalWidth = 0;
  44797. if (ownerView != 0)
  44798. {
  44799. const ScopedLock sl (ownerView->nodeAlterationLock);
  44800. subItems.insert (insertPosition, newItem);
  44801. treeHasChanged();
  44802. if (newItem->isOpen())
  44803. newItem->itemOpennessChanged (true);
  44804. }
  44805. else
  44806. {
  44807. subItems.insert (insertPosition, newItem);
  44808. if (newItem->isOpen())
  44809. newItem->itemOpennessChanged (true);
  44810. }
  44811. }
  44812. }
  44813. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44814. {
  44815. if (ownerView != 0)
  44816. {
  44817. const ScopedLock sl (ownerView->nodeAlterationLock);
  44818. if (((unsigned int) index) < (unsigned int) subItems.size())
  44819. {
  44820. subItems.remove (index, deleteItem);
  44821. treeHasChanged();
  44822. }
  44823. }
  44824. else
  44825. {
  44826. subItems.remove (index, deleteItem);
  44827. }
  44828. }
  44829. bool TreeViewItem::isOpen() const throw()
  44830. {
  44831. if (openness == opennessDefault)
  44832. return ownerView != 0 && ownerView->defaultOpenness;
  44833. else
  44834. return openness == opennessOpen;
  44835. }
  44836. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44837. {
  44838. if (isOpen() != shouldBeOpen)
  44839. {
  44840. openness = shouldBeOpen ? opennessOpen
  44841. : opennessClosed;
  44842. treeHasChanged();
  44843. itemOpennessChanged (isOpen());
  44844. }
  44845. }
  44846. bool TreeViewItem::isSelected() const throw()
  44847. {
  44848. return selected;
  44849. }
  44850. void TreeViewItem::deselectAllRecursively()
  44851. {
  44852. setSelected (false, false);
  44853. for (int i = 0; i < subItems.size(); ++i)
  44854. subItems.getUnchecked(i)->deselectAllRecursively();
  44855. }
  44856. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44857. const bool deselectOtherItemsFirst)
  44858. {
  44859. if (shouldBeSelected && ! canBeSelected())
  44860. return;
  44861. if (deselectOtherItemsFirst)
  44862. getTopLevelItem()->deselectAllRecursively();
  44863. if (shouldBeSelected != selected)
  44864. {
  44865. selected = shouldBeSelected;
  44866. if (ownerView != 0)
  44867. ownerView->repaint();
  44868. itemSelectionChanged (shouldBeSelected);
  44869. }
  44870. }
  44871. void TreeViewItem::paintItem (Graphics&, int, int)
  44872. {
  44873. }
  44874. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44875. {
  44876. ownerView->getLookAndFeel()
  44877. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44878. }
  44879. void TreeViewItem::itemClicked (const MouseEvent&)
  44880. {
  44881. }
  44882. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44883. {
  44884. if (mightContainSubItems())
  44885. setOpen (! isOpen());
  44886. }
  44887. void TreeViewItem::itemSelectionChanged (bool)
  44888. {
  44889. }
  44890. const String TreeViewItem::getTooltip()
  44891. {
  44892. return String::empty;
  44893. }
  44894. const String TreeViewItem::getDragSourceDescription()
  44895. {
  44896. return String::empty;
  44897. }
  44898. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44899. {
  44900. return false;
  44901. }
  44902. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44903. {
  44904. }
  44905. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44906. {
  44907. return false;
  44908. }
  44909. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44910. {
  44911. }
  44912. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44913. {
  44914. const int indentX = getIndentX();
  44915. int width = itemWidth;
  44916. if (ownerView != 0 && width < 0)
  44917. width = ownerView->viewport->getViewWidth() - indentX;
  44918. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44919. if (relativeToTreeViewTopLeft)
  44920. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44921. r.getY() - ownerView->viewport->getViewPositionY());
  44922. return r;
  44923. }
  44924. void TreeViewItem::treeHasChanged() const throw()
  44925. {
  44926. if (ownerView != 0)
  44927. ownerView->itemsChanged();
  44928. }
  44929. void TreeViewItem::repaintItem() const
  44930. {
  44931. if (ownerView != 0 && areAllParentsOpen())
  44932. {
  44933. const Rectangle<int> r (getItemPosition (true));
  44934. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44935. }
  44936. }
  44937. bool TreeViewItem::areAllParentsOpen() const throw()
  44938. {
  44939. return parentItem == 0
  44940. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44941. }
  44942. void TreeViewItem::updatePositions (int newY)
  44943. {
  44944. y = newY;
  44945. itemHeight = getItemHeight();
  44946. totalHeight = itemHeight;
  44947. itemWidth = getItemWidth();
  44948. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44949. if (isOpen())
  44950. {
  44951. newY += totalHeight;
  44952. for (int i = 0; i < subItems.size(); ++i)
  44953. {
  44954. TreeViewItem* const ti = subItems.getUnchecked(i);
  44955. ti->updatePositions (newY);
  44956. newY += ti->totalHeight;
  44957. totalHeight += ti->totalHeight;
  44958. totalWidth = jmax (totalWidth, ti->totalWidth);
  44959. }
  44960. }
  44961. }
  44962. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44963. {
  44964. TreeViewItem* result = this;
  44965. TreeViewItem* item = this;
  44966. while (item->parentItem != 0)
  44967. {
  44968. item = item->parentItem;
  44969. if (! item->isOpen())
  44970. result = item;
  44971. }
  44972. return result;
  44973. }
  44974. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  44975. {
  44976. ownerView = newOwner;
  44977. for (int i = subItems.size(); --i >= 0;)
  44978. subItems.getUnchecked(i)->setOwnerView (newOwner);
  44979. }
  44980. int TreeViewItem::getIndentX() const throw()
  44981. {
  44982. const int indentWidth = ownerView->getIndentSize();
  44983. int x = ownerView->rootItemVisible ? indentWidth : 0;
  44984. if (! ownerView->openCloseButtonsVisible)
  44985. x -= indentWidth;
  44986. TreeViewItem* p = parentItem;
  44987. while (p != 0)
  44988. {
  44989. x += indentWidth;
  44990. p = p->parentItem;
  44991. }
  44992. return x;
  44993. }
  44994. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  44995. {
  44996. drawsInLeftMargin = canDrawInLeftMargin;
  44997. }
  44998. void TreeViewItem::paintRecursively (Graphics& g, int width)
  44999. {
  45000. jassert (ownerView != 0);
  45001. if (ownerView == 0)
  45002. return;
  45003. const int indent = getIndentX();
  45004. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45005. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45006. const float halfH = itemHeight * 0.5f;
  45007. int depth = 0;
  45008. TreeViewItem* p = parentItem;
  45009. while (p != 0)
  45010. {
  45011. ++depth;
  45012. p = p->parentItem;
  45013. }
  45014. if (! ownerView->rootItemVisible)
  45015. --depth;
  45016. const int indentWidth = ownerView->getIndentSize();
  45017. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45018. {
  45019. float x = (depth + 0.5f) * indentWidth;
  45020. if (depth >= 0)
  45021. {
  45022. if (parentItem != 0 && parentItem->drawLinesInside)
  45023. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45024. if ((parentItem != 0 && parentItem->drawLinesInside)
  45025. || (parentItem == 0 && drawLinesInside))
  45026. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45027. }
  45028. p = parentItem;
  45029. int d = depth;
  45030. while (p != 0 && --d >= 0)
  45031. {
  45032. x -= (float) indentWidth;
  45033. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45034. && ! p->isLastOfSiblings())
  45035. {
  45036. g.drawLine (x, 0, x, (float) itemHeight);
  45037. }
  45038. p = p->parentItem;
  45039. }
  45040. if (mightContainSubItems())
  45041. {
  45042. g.saveState();
  45043. g.setOrigin (depth * indentWidth, 0);
  45044. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45045. paintOpenCloseButton (g, indentWidth, itemHeight,
  45046. static_cast <TreeViewContentComponent*> (ownerView->viewport->getViewedComponent())
  45047. ->isMouseOverButton (this));
  45048. g.restoreState();
  45049. }
  45050. }
  45051. {
  45052. g.saveState();
  45053. g.setOrigin (indent, 0);
  45054. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45055. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45056. paintItem (g, itemW, itemHeight);
  45057. g.restoreState();
  45058. }
  45059. if (isOpen())
  45060. {
  45061. const Rectangle<int> clip (g.getClipBounds());
  45062. for (int i = 0; i < subItems.size(); ++i)
  45063. {
  45064. TreeViewItem* const ti = subItems.getUnchecked(i);
  45065. const int relY = ti->y - y;
  45066. if (relY >= clip.getBottom())
  45067. break;
  45068. if (relY + ti->totalHeight >= clip.getY())
  45069. {
  45070. g.saveState();
  45071. g.setOrigin (0, relY);
  45072. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45073. ti->paintRecursively (g, width);
  45074. g.restoreState();
  45075. }
  45076. }
  45077. }
  45078. }
  45079. bool TreeViewItem::isLastOfSiblings() const throw()
  45080. {
  45081. return parentItem == 0
  45082. || parentItem->subItems.getLast() == this;
  45083. }
  45084. int TreeViewItem::getIndexInParent() const throw()
  45085. {
  45086. if (parentItem == 0)
  45087. return 0;
  45088. return parentItem->subItems.indexOf (this);
  45089. }
  45090. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45091. {
  45092. return (parentItem == 0) ? this
  45093. : parentItem->getTopLevelItem();
  45094. }
  45095. int TreeViewItem::getNumRows() const throw()
  45096. {
  45097. int num = 1;
  45098. if (isOpen())
  45099. {
  45100. for (int i = subItems.size(); --i >= 0;)
  45101. num += subItems.getUnchecked(i)->getNumRows();
  45102. }
  45103. return num;
  45104. }
  45105. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45106. {
  45107. if (index == 0)
  45108. return this;
  45109. if (index > 0 && isOpen())
  45110. {
  45111. --index;
  45112. for (int i = 0; i < subItems.size(); ++i)
  45113. {
  45114. TreeViewItem* const item = subItems.getUnchecked(i);
  45115. if (index == 0)
  45116. return item;
  45117. const int numRows = item->getNumRows();
  45118. if (numRows > index)
  45119. return item->getItemOnRow (index);
  45120. index -= numRows;
  45121. }
  45122. }
  45123. return 0;
  45124. }
  45125. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45126. {
  45127. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45128. {
  45129. const int h = itemHeight;
  45130. if (targetY < h)
  45131. return this;
  45132. if (isOpen())
  45133. {
  45134. targetY -= h;
  45135. for (int i = 0; i < subItems.size(); ++i)
  45136. {
  45137. TreeViewItem* const ti = subItems.getUnchecked(i);
  45138. if (targetY < ti->totalHeight)
  45139. return ti->findItemRecursively (targetY);
  45140. targetY -= ti->totalHeight;
  45141. }
  45142. }
  45143. }
  45144. return 0;
  45145. }
  45146. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45147. {
  45148. int total = 0;
  45149. if (isSelected())
  45150. ++total;
  45151. for (int i = subItems.size(); --i >= 0;)
  45152. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45153. return total;
  45154. }
  45155. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45156. {
  45157. if (isSelected())
  45158. {
  45159. if (index == 0)
  45160. return this;
  45161. --index;
  45162. }
  45163. if (index >= 0)
  45164. {
  45165. for (int i = 0; i < subItems.size(); ++i)
  45166. {
  45167. TreeViewItem* const item = subItems.getUnchecked(i);
  45168. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45169. if (found != 0)
  45170. return found;
  45171. index -= item->countSelectedItemsRecursively();
  45172. }
  45173. }
  45174. return 0;
  45175. }
  45176. int TreeViewItem::getRowNumberInTree() const throw()
  45177. {
  45178. if (parentItem != 0 && ownerView != 0)
  45179. {
  45180. int n = 1 + parentItem->getRowNumberInTree();
  45181. int ourIndex = parentItem->subItems.indexOf (this);
  45182. jassert (ourIndex >= 0);
  45183. while (--ourIndex >= 0)
  45184. n += parentItem->subItems [ourIndex]->getNumRows();
  45185. if (parentItem->parentItem == 0
  45186. && ! ownerView->rootItemVisible)
  45187. --n;
  45188. return n;
  45189. }
  45190. else
  45191. {
  45192. return 0;
  45193. }
  45194. }
  45195. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45196. {
  45197. drawLinesInside = drawLines;
  45198. }
  45199. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45200. {
  45201. if (recurse && isOpen() && subItems.size() > 0)
  45202. return subItems [0];
  45203. if (parentItem != 0)
  45204. {
  45205. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45206. if (nextIndex >= parentItem->subItems.size())
  45207. return parentItem->getNextVisibleItem (false);
  45208. return parentItem->subItems [nextIndex];
  45209. }
  45210. return 0;
  45211. }
  45212. const String TreeViewItem::getItemIdentifierString() const
  45213. {
  45214. String s;
  45215. if (parentItem != 0)
  45216. s = parentItem->getItemIdentifierString();
  45217. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45218. }
  45219. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45220. {
  45221. const String uid (getUniqueName());
  45222. if (uid == identifierString)
  45223. return this;
  45224. if (identifierString.startsWith (uid + "/"))
  45225. {
  45226. const String remainingPath (identifierString.substring (uid.length() + 1));
  45227. bool wasOpen = isOpen();
  45228. setOpen (true);
  45229. for (int i = subItems.size(); --i >= 0;)
  45230. {
  45231. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45232. if (item != 0)
  45233. return item;
  45234. }
  45235. setOpen (wasOpen);
  45236. }
  45237. return 0;
  45238. }
  45239. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45240. {
  45241. if (e.hasTagName ("CLOSED"))
  45242. {
  45243. setOpen (false);
  45244. }
  45245. else if (e.hasTagName ("OPEN"))
  45246. {
  45247. setOpen (true);
  45248. forEachXmlChildElement (e, n)
  45249. {
  45250. const String id (n->getStringAttribute ("id"));
  45251. for (int i = 0; i < subItems.size(); ++i)
  45252. {
  45253. TreeViewItem* const ti = subItems.getUnchecked(i);
  45254. if (ti->getUniqueName() == id)
  45255. {
  45256. ti->restoreOpennessState (*n);
  45257. break;
  45258. }
  45259. }
  45260. }
  45261. }
  45262. }
  45263. XmlElement* TreeViewItem::getOpennessState() const throw()
  45264. {
  45265. const String name (getUniqueName());
  45266. if (name.isNotEmpty())
  45267. {
  45268. XmlElement* e;
  45269. if (isOpen())
  45270. {
  45271. e = new XmlElement ("OPEN");
  45272. for (int i = 0; i < subItems.size(); ++i)
  45273. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45274. }
  45275. else
  45276. {
  45277. e = new XmlElement ("CLOSED");
  45278. }
  45279. e->setAttribute ("id", name);
  45280. return e;
  45281. }
  45282. else
  45283. {
  45284. // trying to save the openness for an element that has no name - this won't
  45285. // work because it needs the names to identify what to open.
  45286. jassertfalse
  45287. }
  45288. return 0;
  45289. }
  45290. END_JUCE_NAMESPACE
  45291. /*** End of inlined file: juce_TreeView.cpp ***/
  45292. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45293. BEGIN_JUCE_NAMESPACE
  45294. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45295. : fileList (listToShow)
  45296. {
  45297. }
  45298. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45299. {
  45300. }
  45301. FileBrowserListener::~FileBrowserListener()
  45302. {
  45303. }
  45304. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
  45305. {
  45306. listeners.add (listener);
  45307. }
  45308. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
  45309. {
  45310. listeners.remove (listener);
  45311. }
  45312. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45313. {
  45314. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45315. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45316. }
  45317. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45318. {
  45319. if (fileList.getDirectory().exists())
  45320. {
  45321. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45322. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45323. }
  45324. }
  45325. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45326. {
  45327. if (fileList.getDirectory().exists())
  45328. {
  45329. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45330. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45331. }
  45332. }
  45333. END_JUCE_NAMESPACE
  45334. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45335. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45336. BEGIN_JUCE_NAMESPACE
  45337. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45338. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45339. Time* creationTime, bool* isReadOnly);
  45340. bool juce_findFileNext (void* handle, String& resultFile,
  45341. bool* isDirectory, bool* isHidden, int64* fileSize,
  45342. Time* modTime, Time* creationTime, bool* isReadOnly);
  45343. void juce_findFileClose (void* handle);
  45344. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45345. TimeSliceThread& thread_)
  45346. : fileFilter (fileFilter_),
  45347. thread (thread_),
  45348. includeDirectories (false),
  45349. includeFiles (false),
  45350. ignoreHiddenFiles (true),
  45351. fileFindHandle (0),
  45352. shouldStop (true)
  45353. {
  45354. }
  45355. DirectoryContentsList::~DirectoryContentsList()
  45356. {
  45357. clear();
  45358. }
  45359. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45360. {
  45361. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45362. }
  45363. const File& DirectoryContentsList::getDirectory() const
  45364. {
  45365. return root;
  45366. }
  45367. void DirectoryContentsList::setDirectory (const File& directory,
  45368. const bool includeDirectories_,
  45369. const bool includeFiles_)
  45370. {
  45371. if (directory != root
  45372. || includeDirectories != includeDirectories_
  45373. || includeFiles != includeFiles_)
  45374. {
  45375. clear();
  45376. root = directory;
  45377. includeDirectories = includeDirectories_;
  45378. includeFiles = includeFiles_;
  45379. refresh();
  45380. }
  45381. }
  45382. void DirectoryContentsList::clear()
  45383. {
  45384. shouldStop = true;
  45385. thread.removeTimeSliceClient (this);
  45386. if (fileFindHandle != 0)
  45387. {
  45388. juce_findFileClose (fileFindHandle);
  45389. fileFindHandle = 0;
  45390. }
  45391. if (files.size() > 0)
  45392. {
  45393. files.clear();
  45394. changed();
  45395. }
  45396. }
  45397. void DirectoryContentsList::refresh()
  45398. {
  45399. clear();
  45400. if (root.isDirectory())
  45401. {
  45402. String fileFound;
  45403. bool fileFoundIsDir, isHidden, isReadOnly;
  45404. int64 fileSize;
  45405. Time modTime, creationTime;
  45406. String path (root.getFullPathName());
  45407. if (! path.endsWithChar (File::separator))
  45408. path += File::separator;
  45409. jassert (fileFindHandle == 0);
  45410. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45411. &fileFoundIsDir,
  45412. &isHidden,
  45413. &fileSize,
  45414. &modTime,
  45415. &creationTime,
  45416. &isReadOnly);
  45417. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45418. {
  45419. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45420. fileSize, modTime, creationTime, isReadOnly))
  45421. {
  45422. changed();
  45423. }
  45424. }
  45425. shouldStop = false;
  45426. thread.addTimeSliceClient (this);
  45427. }
  45428. }
  45429. int DirectoryContentsList::getNumFiles() const
  45430. {
  45431. return files.size();
  45432. }
  45433. bool DirectoryContentsList::getFileInfo (const int index,
  45434. FileInfo& result) const
  45435. {
  45436. const ScopedLock sl (fileListLock);
  45437. const FileInfo* const info = files [index];
  45438. if (info != 0)
  45439. {
  45440. result = *info;
  45441. return true;
  45442. }
  45443. return false;
  45444. }
  45445. const File DirectoryContentsList::getFile (const int index) const
  45446. {
  45447. const ScopedLock sl (fileListLock);
  45448. const FileInfo* const info = files [index];
  45449. if (info != 0)
  45450. return root.getChildFile (info->filename);
  45451. return File::nonexistent;
  45452. }
  45453. bool DirectoryContentsList::isStillLoading() const
  45454. {
  45455. return fileFindHandle != 0;
  45456. }
  45457. void DirectoryContentsList::changed()
  45458. {
  45459. sendChangeMessage (this);
  45460. }
  45461. bool DirectoryContentsList::useTimeSlice()
  45462. {
  45463. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45464. bool hasChanged = false;
  45465. for (int i = 100; --i >= 0;)
  45466. {
  45467. if (! checkNextFile (hasChanged))
  45468. {
  45469. if (hasChanged)
  45470. changed();
  45471. return false;
  45472. }
  45473. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45474. break;
  45475. }
  45476. if (hasChanged)
  45477. changed();
  45478. return true;
  45479. }
  45480. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45481. {
  45482. if (fileFindHandle != 0)
  45483. {
  45484. String fileFound;
  45485. bool fileFoundIsDir, isHidden, isReadOnly;
  45486. int64 fileSize;
  45487. Time modTime, creationTime;
  45488. if (juce_findFileNext (fileFindHandle, fileFound,
  45489. &fileFoundIsDir, &isHidden,
  45490. &fileSize,
  45491. &modTime,
  45492. &creationTime,
  45493. &isReadOnly))
  45494. {
  45495. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45496. modTime, creationTime, isReadOnly))
  45497. {
  45498. hasChanged = true;
  45499. }
  45500. return true;
  45501. }
  45502. else
  45503. {
  45504. juce_findFileClose (fileFindHandle);
  45505. fileFindHandle = 0;
  45506. }
  45507. }
  45508. return false;
  45509. }
  45510. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45511. const DirectoryContentsList::FileInfo* const second)
  45512. {
  45513. #if JUCE_WINDOWS
  45514. if (first->isDirectory != second->isDirectory)
  45515. return first->isDirectory ? -1 : 1;
  45516. #endif
  45517. return first->filename.compareIgnoreCase (second->filename);
  45518. }
  45519. bool DirectoryContentsList::addFile (const String& filename,
  45520. const bool isDir,
  45521. const bool isHidden,
  45522. const int64 fileSize,
  45523. const Time& modTime,
  45524. const Time& creationTime,
  45525. const bool isReadOnly)
  45526. {
  45527. if (filename == ".."
  45528. || filename == "."
  45529. || (ignoreHiddenFiles && isHidden))
  45530. return false;
  45531. const File file (root.getChildFile (filename));
  45532. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45533. && (fileFilter == 0
  45534. || ((! isDir) && fileFilter->isFileSuitable (file))
  45535. || (isDir && fileFilter->isDirectorySuitable (file))))
  45536. {
  45537. ScopedPointer <FileInfo> info (new FileInfo());
  45538. info->filename = filename;
  45539. info->fileSize = fileSize;
  45540. info->modificationTime = modTime;
  45541. info->creationTime = creationTime;
  45542. info->isDirectory = isDir;
  45543. info->isReadOnly = isReadOnly;
  45544. const ScopedLock sl (fileListLock);
  45545. for (int i = files.size(); --i >= 0;)
  45546. if (files.getUnchecked(i)->filename == info->filename)
  45547. return false;
  45548. files.addSorted (*this, info.release());
  45549. return true;
  45550. }
  45551. return false;
  45552. }
  45553. END_JUCE_NAMESPACE
  45554. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45555. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45556. BEGIN_JUCE_NAMESPACE
  45557. FileBrowserComponent::FileBrowserComponent (int flags_,
  45558. const File& initialFileOrDirectory,
  45559. const FileFilter* fileFilter_,
  45560. FilePreviewComponent* previewComp_)
  45561. : FileFilter (String::empty),
  45562. fileFilter (fileFilter_),
  45563. flags (flags_),
  45564. previewComp (previewComp_),
  45565. thread ("Juce FileBrowser")
  45566. {
  45567. // You need to specify one or other of the open/save flags..
  45568. jassert ((flags & (saveMode | openMode)) != 0);
  45569. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45570. // You need to specify at least one of these flags..
  45571. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45572. String filename;
  45573. if (initialFileOrDirectory == File::nonexistent)
  45574. {
  45575. currentRoot = File::getCurrentWorkingDirectory();
  45576. }
  45577. else if (initialFileOrDirectory.isDirectory())
  45578. {
  45579. currentRoot = initialFileOrDirectory;
  45580. }
  45581. else
  45582. {
  45583. chosenFiles.add (initialFileOrDirectory);
  45584. currentRoot = initialFileOrDirectory.getParentDirectory();
  45585. filename = initialFileOrDirectory.getFileName();
  45586. }
  45587. fileList = new DirectoryContentsList (this, thread);
  45588. if ((flags & useTreeView) != 0)
  45589. {
  45590. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45591. if ((flags & canSelectMultipleItems) != 0)
  45592. tree->setMultiSelectEnabled (true);
  45593. addAndMakeVisible (tree);
  45594. fileListComponent = tree;
  45595. }
  45596. else
  45597. {
  45598. FileListComponent* const list = new FileListComponent (*fileList);
  45599. list->setOutlineThickness (1);
  45600. if ((flags & canSelectMultipleItems) != 0)
  45601. list->setMultipleSelectionEnabled (true);
  45602. addAndMakeVisible (list);
  45603. fileListComponent = list;
  45604. }
  45605. fileListComponent->addListener (this);
  45606. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45607. currentPathBox->setEditableText (true);
  45608. StringArray rootNames, rootPaths;
  45609. const BigInteger separators (getRoots (rootNames, rootPaths));
  45610. for (int i = 0; i < rootNames.size(); ++i)
  45611. {
  45612. if (separators [i])
  45613. currentPathBox->addSeparator();
  45614. currentPathBox->addItem (rootNames[i], i + 1);
  45615. }
  45616. currentPathBox->addSeparator();
  45617. currentPathBox->addListener (this);
  45618. addAndMakeVisible (filenameBox = new TextEditor());
  45619. filenameBox->setMultiLine (false);
  45620. filenameBox->setSelectAllWhenFocused (true);
  45621. filenameBox->setText (filename, false);
  45622. filenameBox->addListener (this);
  45623. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45624. Label* label = new Label ("f", TRANS("file:"));
  45625. addAndMakeVisible (label);
  45626. label->attachToComponent (filenameBox, true);
  45627. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45628. goUpButton->addButtonListener (this);
  45629. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45630. if (previewComp != 0)
  45631. addAndMakeVisible (previewComp);
  45632. setRoot (currentRoot);
  45633. thread.startThread (4);
  45634. }
  45635. FileBrowserComponent::~FileBrowserComponent()
  45636. {
  45637. if (previewComp != 0)
  45638. removeChildComponent (previewComp);
  45639. deleteAllChildren();
  45640. fileList = 0;
  45641. thread.stopThread (10000);
  45642. }
  45643. void FileBrowserComponent::addListener (FileBrowserListener* const newListener)
  45644. {
  45645. listeners.add (newListener);
  45646. }
  45647. void FileBrowserComponent::removeListener (FileBrowserListener* const listener)
  45648. {
  45649. listeners.remove (listener);
  45650. }
  45651. bool FileBrowserComponent::isSaveMode() const throw()
  45652. {
  45653. return (flags & saveMode) != 0;
  45654. }
  45655. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45656. {
  45657. if (chosenFiles.size() == 0 && currentFileIsValid())
  45658. return 1;
  45659. return chosenFiles.size();
  45660. }
  45661. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45662. {
  45663. if (! filenameBox->isReadOnly())
  45664. return currentRoot.getChildFile (filenameBox->getText());
  45665. else
  45666. return chosenFiles[index];
  45667. }
  45668. bool FileBrowserComponent::currentFileIsValid() const
  45669. {
  45670. if (isSaveMode())
  45671. return ! getSelectedFile (0).isDirectory();
  45672. else
  45673. return getSelectedFile (0).exists();
  45674. }
  45675. const File FileBrowserComponent::getHighlightedFile() const throw()
  45676. {
  45677. return fileListComponent->getSelectedFile (0);
  45678. }
  45679. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45680. {
  45681. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45682. : false;
  45683. }
  45684. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45685. {
  45686. return true;
  45687. }
  45688. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45689. {
  45690. if (f.isDirectory())
  45691. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45692. return (flags & canSelectFiles) != 0 && f.exists()
  45693. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45694. }
  45695. const File FileBrowserComponent::getRoot() const
  45696. {
  45697. return currentRoot;
  45698. }
  45699. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45700. {
  45701. if (currentRoot != newRootDirectory)
  45702. {
  45703. fileListComponent->scrollToTop();
  45704. String path (newRootDirectory.getFullPathName());
  45705. if (path.isEmpty())
  45706. path += File::separator;
  45707. StringArray rootNames, rootPaths;
  45708. getRoots (rootNames, rootPaths);
  45709. if (! rootPaths.contains (path, true))
  45710. {
  45711. bool alreadyListed = false;
  45712. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45713. {
  45714. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45715. {
  45716. alreadyListed = true;
  45717. break;
  45718. }
  45719. }
  45720. if (! alreadyListed)
  45721. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45722. }
  45723. }
  45724. currentRoot = newRootDirectory;
  45725. fileList->setDirectory (currentRoot, true, true);
  45726. String currentRootName (currentRoot.getFullPathName());
  45727. if (currentRootName.isEmpty())
  45728. currentRootName += File::separator;
  45729. currentPathBox->setText (currentRootName, true);
  45730. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45731. && currentRoot.getParentDirectory() != currentRoot);
  45732. }
  45733. void FileBrowserComponent::goUp()
  45734. {
  45735. setRoot (getRoot().getParentDirectory());
  45736. }
  45737. void FileBrowserComponent::refresh()
  45738. {
  45739. fileList->refresh();
  45740. }
  45741. const String FileBrowserComponent::getActionVerb() const
  45742. {
  45743. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45744. }
  45745. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45746. {
  45747. return previewComp;
  45748. }
  45749. void FileBrowserComponent::resized()
  45750. {
  45751. getLookAndFeel()
  45752. .layoutFileBrowserComponent (*this, fileListComponent,
  45753. previewComp, currentPathBox,
  45754. filenameBox, goUpButton);
  45755. }
  45756. void FileBrowserComponent::sendListenerChangeMessage()
  45757. {
  45758. Component::BailOutChecker checker (this);
  45759. if (previewComp != 0)
  45760. previewComp->selectedFileChanged (getSelectedFile (0));
  45761. // You shouldn't delete the browser when the file gets changed!
  45762. jassert (! checker.shouldBailOut());
  45763. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45764. }
  45765. void FileBrowserComponent::selectionChanged()
  45766. {
  45767. StringArray newFilenames;
  45768. bool resetChosenFiles = true;
  45769. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45770. {
  45771. const File f (fileListComponent->getSelectedFile (i));
  45772. if (isFileOrDirSuitable (f))
  45773. {
  45774. if (resetChosenFiles)
  45775. {
  45776. chosenFiles.clear();
  45777. resetChosenFiles = false;
  45778. }
  45779. chosenFiles.add (f);
  45780. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45781. }
  45782. }
  45783. if (newFilenames.size() > 0)
  45784. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45785. sendListenerChangeMessage();
  45786. }
  45787. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45788. {
  45789. Component::BailOutChecker checker (this);
  45790. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45791. }
  45792. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45793. {
  45794. if (f.isDirectory())
  45795. {
  45796. setRoot (f);
  45797. }
  45798. else
  45799. {
  45800. Component::BailOutChecker checker (this);
  45801. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45802. }
  45803. }
  45804. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45805. {
  45806. #if JUCE_LINUX || JUCE_WINDOWS
  45807. if (key.getModifiers().isCommandDown()
  45808. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45809. {
  45810. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45811. fileList->refresh();
  45812. return true;
  45813. }
  45814. #endif
  45815. return false;
  45816. }
  45817. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45818. {
  45819. sendListenerChangeMessage();
  45820. }
  45821. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45822. {
  45823. if (filenameBox->getText().containsChar (File::separator))
  45824. {
  45825. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45826. if (f.isDirectory())
  45827. {
  45828. setRoot (f);
  45829. chosenFiles.clear();
  45830. filenameBox->setText (String::empty);
  45831. }
  45832. else
  45833. {
  45834. setRoot (f.getParentDirectory());
  45835. chosenFiles.clear();
  45836. chosenFiles.add (f);
  45837. filenameBox->setText (f.getFileName());
  45838. }
  45839. }
  45840. else
  45841. {
  45842. fileDoubleClicked (getSelectedFile (0));
  45843. }
  45844. }
  45845. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45846. {
  45847. }
  45848. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45849. {
  45850. if (! isSaveMode())
  45851. selectionChanged();
  45852. }
  45853. void FileBrowserComponent::buttonClicked (Button*)
  45854. {
  45855. goUp();
  45856. }
  45857. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45858. {
  45859. const String newText (currentPathBox->getText().trim().unquoted());
  45860. if (newText.isNotEmpty())
  45861. {
  45862. const int index = currentPathBox->getSelectedId() - 1;
  45863. StringArray rootNames, rootPaths;
  45864. getRoots (rootNames, rootPaths);
  45865. if (rootPaths [index].isNotEmpty())
  45866. {
  45867. setRoot (File (rootPaths [index]));
  45868. }
  45869. else
  45870. {
  45871. File f (newText);
  45872. for (;;)
  45873. {
  45874. if (f.isDirectory())
  45875. {
  45876. setRoot (f);
  45877. break;
  45878. }
  45879. if (f.getParentDirectory() == f)
  45880. break;
  45881. f = f.getParentDirectory();
  45882. }
  45883. }
  45884. }
  45885. }
  45886. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45887. {
  45888. BigInteger separators;
  45889. #if JUCE_WINDOWS
  45890. Array<File> roots;
  45891. File::findFileSystemRoots (roots);
  45892. rootPaths.clear();
  45893. for (int i = 0; i < roots.size(); ++i)
  45894. {
  45895. const File& drive = roots.getReference(i);
  45896. String name (drive.getFullPathName());
  45897. rootPaths.add (name);
  45898. if (drive.isOnHardDisk())
  45899. {
  45900. String volume (drive.getVolumeLabel());
  45901. if (volume.isEmpty())
  45902. volume = TRANS("Hard Drive");
  45903. name << " [" << drive.getVolumeLabel() << ']';
  45904. }
  45905. else if (drive.isOnCDRomDrive())
  45906. {
  45907. name << TRANS(" [CD/DVD drive]");
  45908. }
  45909. rootNames.add (name);
  45910. }
  45911. separators.setBit (rootPaths.size());
  45912. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45913. rootNames.add ("Documents");
  45914. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45915. rootNames.add ("Desktop");
  45916. #endif
  45917. #if JUCE_MAC
  45918. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45919. rootNames.add ("Home folder");
  45920. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45921. rootNames.add ("Documents");
  45922. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45923. rootNames.add ("Desktop");
  45924. separators.setBit (rootPaths.size());
  45925. Array <File> volumes;
  45926. File vol ("/Volumes");
  45927. vol.findChildFiles (volumes, File::findDirectories, false);
  45928. for (int i = 0; i < volumes.size(); ++i)
  45929. {
  45930. const File& volume = volumes.getReference(i);
  45931. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45932. {
  45933. rootPaths.add (volume.getFullPathName());
  45934. rootNames.add (volume.getFileName());
  45935. }
  45936. }
  45937. #endif
  45938. #if JUCE_LINUX
  45939. rootPaths.add ("/");
  45940. rootNames.add ("/");
  45941. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45942. rootNames.add ("Home folder");
  45943. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45944. rootNames.add ("Desktop");
  45945. #endif
  45946. return separators;
  45947. }
  45948. END_JUCE_NAMESPACE
  45949. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45950. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45951. BEGIN_JUCE_NAMESPACE
  45952. FileChooser::FileChooser (const String& chooserBoxTitle,
  45953. const File& currentFileOrDirectory,
  45954. const String& fileFilters,
  45955. const bool useNativeDialogBox_)
  45956. : title (chooserBoxTitle),
  45957. filters (fileFilters),
  45958. startingFile (currentFileOrDirectory),
  45959. useNativeDialogBox (useNativeDialogBox_)
  45960. {
  45961. #if JUCE_LINUX
  45962. useNativeDialogBox = false;
  45963. #endif
  45964. if (! fileFilters.containsNonWhitespaceChars())
  45965. filters = "*";
  45966. }
  45967. FileChooser::~FileChooser()
  45968. {
  45969. }
  45970. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  45971. {
  45972. return showDialog (false, true, false, false, false, previewComponent);
  45973. }
  45974. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  45975. {
  45976. return showDialog (false, true, false, false, true, previewComponent);
  45977. }
  45978. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  45979. {
  45980. return showDialog (true, true, false, false, true, previewComponent);
  45981. }
  45982. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  45983. {
  45984. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  45985. }
  45986. bool FileChooser::browseForDirectory()
  45987. {
  45988. return showDialog (true, false, false, false, false, 0);
  45989. }
  45990. const File FileChooser::getResult() const
  45991. {
  45992. // if you've used a multiple-file select, you should use the getResults() method
  45993. // to retrieve all the files that were chosen.
  45994. jassert (results.size() <= 1);
  45995. return results.getFirst();
  45996. }
  45997. const Array<File>& FileChooser::getResults() const
  45998. {
  45999. return results;
  46000. }
  46001. bool FileChooser::showDialog (const bool selectsDirectories,
  46002. const bool selectsFiles,
  46003. const bool isSave,
  46004. const bool warnAboutOverwritingExistingFiles,
  46005. const bool selectMultipleFiles,
  46006. FilePreviewComponent* const previewComponent)
  46007. {
  46008. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46009. results.clear();
  46010. // the preview component needs to be the right size before you pass it in here..
  46011. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46012. && previewComponent->getHeight() > 10));
  46013. #if JUCE_WINDOWS
  46014. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46015. #elif JUCE_MAC
  46016. if (useNativeDialogBox && (previewComponent == 0))
  46017. #else
  46018. if (false)
  46019. #endif
  46020. {
  46021. showPlatformDialog (results, title, startingFile, filters,
  46022. selectsDirectories, selectsFiles, isSave,
  46023. warnAboutOverwritingExistingFiles,
  46024. selectMultipleFiles,
  46025. previewComponent);
  46026. }
  46027. else
  46028. {
  46029. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46030. selectsDirectories ? "*" : String::empty,
  46031. String::empty);
  46032. int flags = isSave ? FileBrowserComponent::saveMode
  46033. : FileBrowserComponent::openMode;
  46034. if (selectsFiles)
  46035. flags |= FileBrowserComponent::canSelectFiles;
  46036. if (selectsDirectories)
  46037. flags |= FileBrowserComponent::canSelectDirectories;
  46038. if (selectMultipleFiles)
  46039. flags |= FileBrowserComponent::canSelectMultipleItems;
  46040. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46041. FileChooserDialogBox box (title, String::empty,
  46042. browserComponent,
  46043. warnAboutOverwritingExistingFiles,
  46044. browserComponent.findColour (AlertWindow::backgroundColourId));
  46045. if (box.show())
  46046. {
  46047. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46048. results.add (browserComponent.getSelectedFile (i));
  46049. }
  46050. }
  46051. if (previouslyFocused != 0)
  46052. previouslyFocused->grabKeyboardFocus();
  46053. return results.size() > 0;
  46054. }
  46055. FilePreviewComponent::FilePreviewComponent()
  46056. {
  46057. }
  46058. FilePreviewComponent::~FilePreviewComponent()
  46059. {
  46060. }
  46061. END_JUCE_NAMESPACE
  46062. /*** End of inlined file: juce_FileChooser.cpp ***/
  46063. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46064. BEGIN_JUCE_NAMESPACE
  46065. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46066. const String& instructions,
  46067. FileBrowserComponent& chooserComponent,
  46068. const bool warnAboutOverwritingExistingFiles_,
  46069. const Colour& backgroundColour)
  46070. : ResizableWindow (name, backgroundColour, true),
  46071. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46072. {
  46073. content = new ContentComponent();
  46074. content->setName (name);
  46075. content->instructions = instructions;
  46076. content->chooserComponent = &chooserComponent;
  46077. content->addAndMakeVisible (&chooserComponent);
  46078. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46079. content->addAndMakeVisible (content->okButton);
  46080. content->okButton->addButtonListener (this);
  46081. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46082. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46083. content->cancelButton = new TextButton (TRANS("Cancel"));
  46084. content->addAndMakeVisible (content->cancelButton);
  46085. content->cancelButton->addButtonListener (this);
  46086. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46087. setContentComponent (content);
  46088. setResizable (true, true);
  46089. setResizeLimits (300, 300, 1200, 1000);
  46090. content->chooserComponent->addListener (this);
  46091. }
  46092. FileChooserDialogBox::~FileChooserDialogBox()
  46093. {
  46094. content->chooserComponent->removeListener (this);
  46095. }
  46096. bool FileChooserDialogBox::show (int w, int h)
  46097. {
  46098. if (w <= 0)
  46099. {
  46100. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46101. if (previewComp != 0)
  46102. w = 400 + previewComp->getWidth();
  46103. else
  46104. w = 600;
  46105. }
  46106. if (h <= 0)
  46107. h = 500;
  46108. centreWithSize (w, h);
  46109. const bool ok = (runModalLoop() != 0);
  46110. setVisible (false);
  46111. return ok;
  46112. }
  46113. void FileChooserDialogBox::buttonClicked (Button* button)
  46114. {
  46115. if (button == content->okButton)
  46116. {
  46117. if (warnAboutOverwritingExistingFiles
  46118. && content->chooserComponent->isSaveMode()
  46119. && content->chooserComponent->getSelectedFile(0).exists())
  46120. {
  46121. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46122. TRANS("File already exists"),
  46123. TRANS("There's already a file called:")
  46124. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46125. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46126. TRANS("overwrite"),
  46127. TRANS("cancel")))
  46128. {
  46129. return;
  46130. }
  46131. }
  46132. exitModalState (1);
  46133. }
  46134. else if (button == content->cancelButton)
  46135. closeButtonPressed();
  46136. }
  46137. void FileChooserDialogBox::closeButtonPressed()
  46138. {
  46139. setVisible (false);
  46140. }
  46141. void FileChooserDialogBox::selectionChanged()
  46142. {
  46143. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46144. }
  46145. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46146. {
  46147. }
  46148. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46149. {
  46150. selectionChanged();
  46151. content->okButton->triggerClick();
  46152. }
  46153. FileChooserDialogBox::ContentComponent::ContentComponent()
  46154. {
  46155. setInterceptsMouseClicks (false, true);
  46156. }
  46157. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46158. {
  46159. delete okButton;
  46160. delete cancelButton;
  46161. }
  46162. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46163. {
  46164. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46165. text.draw (g);
  46166. }
  46167. void FileChooserDialogBox::ContentComponent::resized()
  46168. {
  46169. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46170. const Rectangle<float> bb (text.getBoundingBox (0, text.getNumGlyphs(), false));
  46171. const int y = roundToInt (bb.getBottom()) + 10;
  46172. const int buttonHeight = 26;
  46173. const int buttonY = getHeight() - buttonHeight - 8;
  46174. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46175. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46176. proportionOfWidth (0.2f), buttonHeight);
  46177. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46178. proportionOfWidth (0.2f), buttonHeight);
  46179. }
  46180. END_JUCE_NAMESPACE
  46181. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46182. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46183. BEGIN_JUCE_NAMESPACE
  46184. FileFilter::FileFilter (const String& filterDescription)
  46185. : description (filterDescription)
  46186. {
  46187. }
  46188. FileFilter::~FileFilter()
  46189. {
  46190. }
  46191. const String& FileFilter::getDescription() const throw()
  46192. {
  46193. return description;
  46194. }
  46195. END_JUCE_NAMESPACE
  46196. /*** End of inlined file: juce_FileFilter.cpp ***/
  46197. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46198. BEGIN_JUCE_NAMESPACE
  46199. Image* juce_createIconForFile (const File& file);
  46200. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46201. : ListBox (String::empty, 0),
  46202. DirectoryContentsDisplayComponent (listToShow)
  46203. {
  46204. setModel (this);
  46205. fileList.addChangeListener (this);
  46206. }
  46207. FileListComponent::~FileListComponent()
  46208. {
  46209. fileList.removeChangeListener (this);
  46210. deleteAllChildren();
  46211. }
  46212. int FileListComponent::getNumSelectedFiles() const
  46213. {
  46214. return getNumSelectedRows();
  46215. }
  46216. const File FileListComponent::getSelectedFile (int index) const
  46217. {
  46218. return fileList.getFile (getSelectedRow (index));
  46219. }
  46220. void FileListComponent::scrollToTop()
  46221. {
  46222. getVerticalScrollBar()->setCurrentRangeStart (0);
  46223. }
  46224. void FileListComponent::changeListenerCallback (void*)
  46225. {
  46226. updateContent();
  46227. if (lastDirectory != fileList.getDirectory())
  46228. {
  46229. lastDirectory = fileList.getDirectory();
  46230. deselectAllRows();
  46231. }
  46232. }
  46233. class FileListItemComponent : public Component,
  46234. public TimeSliceClient,
  46235. public AsyncUpdater
  46236. {
  46237. public:
  46238. FileListItemComponent (FileListComponent& owner_, TimeSliceThread& thread_)
  46239. : owner (owner_), thread (thread_),
  46240. highlighted (false), index (0), icon (0)
  46241. {
  46242. }
  46243. ~FileListItemComponent()
  46244. {
  46245. thread.removeTimeSliceClient (this);
  46246. clearIcon();
  46247. }
  46248. void paint (Graphics& g)
  46249. {
  46250. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46251. file.getFileName(),
  46252. icon,
  46253. fileSize, modTime,
  46254. isDirectory, highlighted,
  46255. index);
  46256. }
  46257. void mouseDown (const MouseEvent& e)
  46258. {
  46259. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46260. owner.sendMouseClickMessage (file, e);
  46261. }
  46262. void mouseDoubleClick (const MouseEvent&)
  46263. {
  46264. owner.sendDoubleClickMessage (file);
  46265. }
  46266. void update (const File& root,
  46267. const DirectoryContentsList::FileInfo* const fileInfo,
  46268. const int index_,
  46269. const bool highlighted_)
  46270. {
  46271. thread.removeTimeSliceClient (this);
  46272. if (highlighted_ != highlighted
  46273. || index_ != index)
  46274. {
  46275. index = index_;
  46276. highlighted = highlighted_;
  46277. repaint();
  46278. }
  46279. File newFile;
  46280. String newFileSize;
  46281. String newModTime;
  46282. if (fileInfo != 0)
  46283. {
  46284. newFile = root.getChildFile (fileInfo->filename);
  46285. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46286. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46287. }
  46288. if (newFile != file
  46289. || fileSize != newFileSize
  46290. || modTime != newModTime)
  46291. {
  46292. file = newFile;
  46293. fileSize = newFileSize;
  46294. modTime = newModTime;
  46295. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46296. repaint();
  46297. clearIcon();
  46298. }
  46299. if (file != File::nonexistent
  46300. && icon == 0 && ! isDirectory)
  46301. {
  46302. updateIcon (true);
  46303. if (icon == 0)
  46304. thread.addTimeSliceClient (this);
  46305. }
  46306. }
  46307. bool useTimeSlice()
  46308. {
  46309. updateIcon (false);
  46310. return false;
  46311. }
  46312. void handleAsyncUpdate()
  46313. {
  46314. repaint();
  46315. }
  46316. juce_UseDebuggingNewOperator
  46317. private:
  46318. FileListComponent& owner;
  46319. TimeSliceThread& thread;
  46320. bool highlighted;
  46321. int index;
  46322. File file;
  46323. String fileSize;
  46324. String modTime;
  46325. Image* icon;
  46326. bool isDirectory;
  46327. void clearIcon()
  46328. {
  46329. ImageCache::release (icon);
  46330. icon = 0;
  46331. }
  46332. void updateIcon (const bool onlyUpdateIfCached)
  46333. {
  46334. if (icon == 0)
  46335. {
  46336. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46337. Image* im = ImageCache::getFromHashCode (hashCode);
  46338. if (im == 0 && ! onlyUpdateIfCached)
  46339. {
  46340. im = juce_createIconForFile (file);
  46341. if (im != 0)
  46342. ImageCache::addImageToCache (im, hashCode);
  46343. }
  46344. if (im != 0)
  46345. {
  46346. icon = im;
  46347. triggerAsyncUpdate();
  46348. }
  46349. }
  46350. }
  46351. };
  46352. int FileListComponent::getNumRows()
  46353. {
  46354. return fileList.getNumFiles();
  46355. }
  46356. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46357. {
  46358. }
  46359. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46360. {
  46361. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46362. if (comp == 0)
  46363. {
  46364. delete existingComponentToUpdate;
  46365. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46366. }
  46367. DirectoryContentsList::FileInfo fileInfo;
  46368. if (fileList.getFileInfo (row, fileInfo))
  46369. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46370. else
  46371. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46372. return comp;
  46373. }
  46374. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46375. {
  46376. sendSelectionChangeMessage();
  46377. }
  46378. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46379. {
  46380. }
  46381. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46382. {
  46383. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46384. }
  46385. END_JUCE_NAMESPACE
  46386. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46387. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46388. BEGIN_JUCE_NAMESPACE
  46389. FilenameComponent::FilenameComponent (const String& name,
  46390. const File& currentFile,
  46391. const bool canEditFilename,
  46392. const bool isDirectory,
  46393. const bool isForSaving,
  46394. const String& fileBrowserWildcard,
  46395. const String& enforcedSuffix_,
  46396. const String& textWhenNothingSelected)
  46397. : Component (name),
  46398. maxRecentFiles (30),
  46399. isDir (isDirectory),
  46400. isSaving (isForSaving),
  46401. isFileDragOver (false),
  46402. wildcard (fileBrowserWildcard),
  46403. enforcedSuffix (enforcedSuffix_)
  46404. {
  46405. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46406. filenameBox->setEditableText (canEditFilename);
  46407. filenameBox->addListener (this);
  46408. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46409. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46410. browseButton = 0;
  46411. setBrowseButtonText ("...");
  46412. setCurrentFile (currentFile, true);
  46413. }
  46414. FilenameComponent::~FilenameComponent()
  46415. {
  46416. deleteAllChildren();
  46417. }
  46418. void FilenameComponent::paintOverChildren (Graphics& g)
  46419. {
  46420. if (isFileDragOver)
  46421. {
  46422. g.setColour (Colours::red.withAlpha (0.2f));
  46423. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46424. }
  46425. }
  46426. void FilenameComponent::resized()
  46427. {
  46428. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46429. }
  46430. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46431. {
  46432. browseButtonText = newBrowseButtonText;
  46433. lookAndFeelChanged();
  46434. }
  46435. void FilenameComponent::lookAndFeelChanged()
  46436. {
  46437. deleteAndZero (browseButton);
  46438. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46439. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46440. resized();
  46441. browseButton->addButtonListener (this);
  46442. }
  46443. void FilenameComponent::setTooltip (const String& newTooltip)
  46444. {
  46445. SettableTooltipClient::setTooltip (newTooltip);
  46446. filenameBox->setTooltip (newTooltip);
  46447. }
  46448. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46449. {
  46450. defaultBrowseFile = newDefaultDirectory;
  46451. }
  46452. void FilenameComponent::buttonClicked (Button*)
  46453. {
  46454. FileChooser fc (TRANS("Choose a new file"),
  46455. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46456. : getCurrentFile(),
  46457. wildcard);
  46458. if (isDir ? fc.browseForDirectory()
  46459. : (isSaving ? fc.browseForFileToSave (false)
  46460. : fc.browseForFileToOpen()))
  46461. {
  46462. setCurrentFile (fc.getResult(), true);
  46463. }
  46464. }
  46465. void FilenameComponent::comboBoxChanged (ComboBox*)
  46466. {
  46467. setCurrentFile (getCurrentFile(), true);
  46468. }
  46469. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46470. {
  46471. return true;
  46472. }
  46473. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46474. {
  46475. isFileDragOver = false;
  46476. repaint();
  46477. const File f (filenames[0]);
  46478. if (f.exists() && (f.isDirectory() == isDir))
  46479. setCurrentFile (f, true);
  46480. }
  46481. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46482. {
  46483. isFileDragOver = true;
  46484. repaint();
  46485. }
  46486. void FilenameComponent::fileDragExit (const StringArray&)
  46487. {
  46488. isFileDragOver = false;
  46489. repaint();
  46490. }
  46491. const File FilenameComponent::getCurrentFile() const
  46492. {
  46493. File f (filenameBox->getText());
  46494. if (enforcedSuffix.isNotEmpty())
  46495. f = f.withFileExtension (enforcedSuffix);
  46496. return f;
  46497. }
  46498. void FilenameComponent::setCurrentFile (File newFile,
  46499. const bool addToRecentlyUsedList,
  46500. const bool sendChangeNotification)
  46501. {
  46502. if (enforcedSuffix.isNotEmpty())
  46503. newFile = newFile.withFileExtension (enforcedSuffix);
  46504. if (newFile.getFullPathName() != lastFilename)
  46505. {
  46506. lastFilename = newFile.getFullPathName();
  46507. if (addToRecentlyUsedList)
  46508. addRecentlyUsedFile (newFile);
  46509. filenameBox->setText (lastFilename, true);
  46510. if (sendChangeNotification)
  46511. triggerAsyncUpdate();
  46512. }
  46513. }
  46514. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46515. {
  46516. filenameBox->setEditableText (shouldBeEditable);
  46517. }
  46518. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46519. {
  46520. StringArray names;
  46521. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46522. names.add (filenameBox->getItemText (i));
  46523. return names;
  46524. }
  46525. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46526. {
  46527. if (filenames != getRecentlyUsedFilenames())
  46528. {
  46529. filenameBox->clear();
  46530. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46531. filenameBox->addItem (filenames[i], i + 1);
  46532. }
  46533. }
  46534. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46535. {
  46536. maxRecentFiles = jmax (1, newMaximum);
  46537. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46538. }
  46539. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46540. {
  46541. StringArray files (getRecentlyUsedFilenames());
  46542. if (file.getFullPathName().isNotEmpty())
  46543. {
  46544. files.removeString (file.getFullPathName(), true);
  46545. files.insert (0, file.getFullPathName());
  46546. setRecentlyUsedFilenames (files);
  46547. }
  46548. }
  46549. void FilenameComponent::addListener (FilenameComponentListener* const listener)
  46550. {
  46551. listeners.add (listener);
  46552. }
  46553. void FilenameComponent::removeListener (FilenameComponentListener* const listener)
  46554. {
  46555. listeners.remove (listener);
  46556. }
  46557. void FilenameComponent::handleAsyncUpdate()
  46558. {
  46559. Component::BailOutChecker checker (this);
  46560. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46561. }
  46562. END_JUCE_NAMESPACE
  46563. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46564. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46565. BEGIN_JUCE_NAMESPACE
  46566. FileSearchPathListComponent::FileSearchPathListComponent()
  46567. {
  46568. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46569. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46570. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46571. listBox->setOutlineThickness (1);
  46572. addAndMakeVisible (addButton = new TextButton ("+"));
  46573. addButton->addButtonListener (this);
  46574. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46575. addAndMakeVisible (removeButton = new TextButton ("-"));
  46576. removeButton->addButtonListener (this);
  46577. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46578. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46579. changeButton->addButtonListener (this);
  46580. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46581. upButton->addButtonListener (this);
  46582. {
  46583. Path arrowPath;
  46584. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46585. DrawablePath arrowImage;
  46586. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46587. arrowImage.setPath (arrowPath);
  46588. upButton->setImages (&arrowImage);
  46589. }
  46590. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46591. downButton->addButtonListener (this);
  46592. {
  46593. Path arrowPath;
  46594. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46595. DrawablePath arrowImage;
  46596. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46597. arrowImage.setPath (arrowPath);
  46598. downButton->setImages (&arrowImage);
  46599. }
  46600. updateButtons();
  46601. }
  46602. FileSearchPathListComponent::~FileSearchPathListComponent()
  46603. {
  46604. deleteAllChildren();
  46605. }
  46606. void FileSearchPathListComponent::updateButtons()
  46607. {
  46608. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46609. removeButton->setEnabled (anythingSelected);
  46610. changeButton->setEnabled (anythingSelected);
  46611. upButton->setEnabled (anythingSelected);
  46612. downButton->setEnabled (anythingSelected);
  46613. }
  46614. void FileSearchPathListComponent::changed()
  46615. {
  46616. listBox->updateContent();
  46617. listBox->repaint();
  46618. updateButtons();
  46619. }
  46620. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46621. {
  46622. if (newPath.toString() != path.toString())
  46623. {
  46624. path = newPath;
  46625. changed();
  46626. }
  46627. }
  46628. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46629. {
  46630. defaultBrowseTarget = newDefaultDirectory;
  46631. }
  46632. int FileSearchPathListComponent::getNumRows()
  46633. {
  46634. return path.getNumPaths();
  46635. }
  46636. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46637. {
  46638. if (rowIsSelected)
  46639. g.fillAll (findColour (TextEditor::highlightColourId));
  46640. g.setColour (findColour (ListBox::textColourId));
  46641. Font f (height * 0.7f);
  46642. f.setHorizontalScale (0.9f);
  46643. g.setFont (f);
  46644. g.drawText (path [rowNumber].getFullPathName(),
  46645. 4, 0, width - 6, height,
  46646. Justification::centredLeft, true);
  46647. }
  46648. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46649. {
  46650. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46651. {
  46652. path.remove (row);
  46653. changed();
  46654. }
  46655. }
  46656. void FileSearchPathListComponent::returnKeyPressed (int row)
  46657. {
  46658. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46659. if (chooser.browseForDirectory())
  46660. {
  46661. path.remove (row);
  46662. path.add (chooser.getResult(), row);
  46663. changed();
  46664. }
  46665. }
  46666. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46667. {
  46668. returnKeyPressed (row);
  46669. }
  46670. void FileSearchPathListComponent::selectedRowsChanged (int)
  46671. {
  46672. updateButtons();
  46673. }
  46674. void FileSearchPathListComponent::paint (Graphics& g)
  46675. {
  46676. g.fillAll (findColour (backgroundColourId));
  46677. }
  46678. void FileSearchPathListComponent::resized()
  46679. {
  46680. const int buttonH = 22;
  46681. const int buttonY = getHeight() - buttonH - 4;
  46682. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46683. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46684. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46685. changeButton->changeWidthToFitText (buttonH);
  46686. downButton->setSize (buttonH * 2, buttonH);
  46687. upButton->setSize (buttonH * 2, buttonH);
  46688. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46689. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46690. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46691. }
  46692. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46693. {
  46694. return true;
  46695. }
  46696. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46697. {
  46698. for (int i = filenames.size(); --i >= 0;)
  46699. {
  46700. const File f (filenames[i]);
  46701. if (f.isDirectory())
  46702. {
  46703. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46704. path.add (f, row);
  46705. changed();
  46706. }
  46707. }
  46708. }
  46709. void FileSearchPathListComponent::buttonClicked (Button* button)
  46710. {
  46711. const int currentRow = listBox->getSelectedRow();
  46712. if (button == removeButton)
  46713. {
  46714. deleteKeyPressed (currentRow);
  46715. }
  46716. else if (button == addButton)
  46717. {
  46718. File start (defaultBrowseTarget);
  46719. if (start == File::nonexistent)
  46720. start = path [0];
  46721. if (start == File::nonexistent)
  46722. start = File::getCurrentWorkingDirectory();
  46723. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46724. if (chooser.browseForDirectory())
  46725. {
  46726. path.add (chooser.getResult(), currentRow);
  46727. }
  46728. }
  46729. else if (button == changeButton)
  46730. {
  46731. returnKeyPressed (currentRow);
  46732. }
  46733. else if (button == upButton)
  46734. {
  46735. if (currentRow > 0 && currentRow < path.getNumPaths())
  46736. {
  46737. const File f (path[currentRow]);
  46738. path.remove (currentRow);
  46739. path.add (f, currentRow - 1);
  46740. listBox->selectRow (currentRow - 1);
  46741. }
  46742. }
  46743. else if (button == downButton)
  46744. {
  46745. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46746. {
  46747. const File f (path[currentRow]);
  46748. path.remove (currentRow);
  46749. path.add (f, currentRow + 1);
  46750. listBox->selectRow (currentRow + 1);
  46751. }
  46752. }
  46753. changed();
  46754. }
  46755. END_JUCE_NAMESPACE
  46756. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46757. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46758. BEGIN_JUCE_NAMESPACE
  46759. Image* juce_createIconForFile (const File& file);
  46760. class FileListTreeItem : public TreeViewItem,
  46761. public TimeSliceClient,
  46762. public AsyncUpdater,
  46763. public ChangeListener
  46764. {
  46765. public:
  46766. FileListTreeItem (FileTreeComponent& owner_,
  46767. DirectoryContentsList* const parentContentsList_,
  46768. const int indexInContentsList_,
  46769. const File& file_,
  46770. TimeSliceThread& thread_)
  46771. : file (file_),
  46772. owner (owner_),
  46773. parentContentsList (parentContentsList_),
  46774. indexInContentsList (indexInContentsList_),
  46775. subContentsList (0),
  46776. canDeleteSubContentsList (false),
  46777. thread (thread_),
  46778. icon (0)
  46779. {
  46780. DirectoryContentsList::FileInfo fileInfo;
  46781. if (parentContentsList_ != 0
  46782. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46783. {
  46784. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46785. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46786. isDirectory = fileInfo.isDirectory;
  46787. }
  46788. else
  46789. {
  46790. isDirectory = true;
  46791. }
  46792. }
  46793. ~FileListTreeItem()
  46794. {
  46795. thread.removeTimeSliceClient (this);
  46796. clearSubItems();
  46797. ImageCache::release (icon);
  46798. if (canDeleteSubContentsList)
  46799. delete subContentsList;
  46800. }
  46801. bool mightContainSubItems() { return isDirectory; }
  46802. const String getUniqueName() const { return file.getFullPathName(); }
  46803. int getItemHeight() const { return 22; }
  46804. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46805. void itemOpennessChanged (bool isNowOpen)
  46806. {
  46807. if (isNowOpen)
  46808. {
  46809. clearSubItems();
  46810. isDirectory = file.isDirectory();
  46811. if (isDirectory)
  46812. {
  46813. if (subContentsList == 0)
  46814. {
  46815. jassert (parentContentsList != 0);
  46816. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46817. l->setDirectory (file, true, true);
  46818. setSubContentsList (l);
  46819. canDeleteSubContentsList = true;
  46820. }
  46821. changeListenerCallback (0);
  46822. }
  46823. }
  46824. }
  46825. void setSubContentsList (DirectoryContentsList* newList)
  46826. {
  46827. jassert (subContentsList == 0);
  46828. subContentsList = newList;
  46829. newList->addChangeListener (this);
  46830. }
  46831. void changeListenerCallback (void*)
  46832. {
  46833. clearSubItems();
  46834. if (isOpen() && subContentsList != 0)
  46835. {
  46836. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46837. {
  46838. FileListTreeItem* const item
  46839. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46840. addSubItem (item);
  46841. }
  46842. }
  46843. }
  46844. void paintItem (Graphics& g, int width, int height)
  46845. {
  46846. if (file != File::nonexistent)
  46847. {
  46848. updateIcon (true);
  46849. if (icon == 0)
  46850. thread.addTimeSliceClient (this);
  46851. }
  46852. owner.getLookAndFeel()
  46853. .drawFileBrowserRow (g, width, height,
  46854. file.getFileName(),
  46855. icon,
  46856. fileSize, modTime,
  46857. isDirectory, isSelected(),
  46858. indexInContentsList);
  46859. }
  46860. void itemClicked (const MouseEvent& e)
  46861. {
  46862. owner.sendMouseClickMessage (file, e);
  46863. }
  46864. void itemDoubleClicked (const MouseEvent& e)
  46865. {
  46866. TreeViewItem::itemDoubleClicked (e);
  46867. owner.sendDoubleClickMessage (file);
  46868. }
  46869. void itemSelectionChanged (bool)
  46870. {
  46871. owner.sendSelectionChangeMessage();
  46872. }
  46873. bool useTimeSlice()
  46874. {
  46875. updateIcon (false);
  46876. thread.removeTimeSliceClient (this);
  46877. return false;
  46878. }
  46879. void handleAsyncUpdate()
  46880. {
  46881. owner.repaint();
  46882. }
  46883. const File file;
  46884. juce_UseDebuggingNewOperator
  46885. private:
  46886. FileTreeComponent& owner;
  46887. DirectoryContentsList* parentContentsList;
  46888. int indexInContentsList;
  46889. DirectoryContentsList* subContentsList;
  46890. bool isDirectory, canDeleteSubContentsList;
  46891. TimeSliceThread& thread;
  46892. Image* icon;
  46893. String fileSize;
  46894. String modTime;
  46895. void updateIcon (const bool onlyUpdateIfCached)
  46896. {
  46897. if (icon == 0)
  46898. {
  46899. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46900. Image* im = ImageCache::getFromHashCode (hashCode);
  46901. if (im == 0 && ! onlyUpdateIfCached)
  46902. {
  46903. im = juce_createIconForFile (file);
  46904. if (im != 0)
  46905. ImageCache::addImageToCache (im, hashCode);
  46906. }
  46907. if (im != 0)
  46908. {
  46909. icon = im;
  46910. triggerAsyncUpdate();
  46911. }
  46912. }
  46913. }
  46914. };
  46915. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46916. : DirectoryContentsDisplayComponent (listToShow)
  46917. {
  46918. FileListTreeItem* const root
  46919. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46920. listToShow.getTimeSliceThread());
  46921. root->setSubContentsList (&listToShow);
  46922. setRootItemVisible (false);
  46923. setRootItem (root);
  46924. }
  46925. FileTreeComponent::~FileTreeComponent()
  46926. {
  46927. deleteRootItem();
  46928. }
  46929. const File FileTreeComponent::getSelectedFile (const int index) const
  46930. {
  46931. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46932. if (item != 0)
  46933. return item->file;
  46934. return File::nonexistent;
  46935. }
  46936. void FileTreeComponent::scrollToTop()
  46937. {
  46938. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46939. }
  46940. void FileTreeComponent::setDragAndDropDescription (const String& description)
  46941. {
  46942. dragAndDropDescription = description;
  46943. }
  46944. END_JUCE_NAMESPACE
  46945. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46946. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46947. BEGIN_JUCE_NAMESPACE
  46948. ImagePreviewComponent::ImagePreviewComponent()
  46949. {
  46950. }
  46951. ImagePreviewComponent::~ImagePreviewComponent()
  46952. {
  46953. }
  46954. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46955. {
  46956. const int availableW = proportionOfWidth (0.97f);
  46957. const int availableH = getHeight() - 13 * 4;
  46958. const double scale = jmin (1.0,
  46959. availableW / (double) w,
  46960. availableH / (double) h);
  46961. w = roundToInt (scale * w);
  46962. h = roundToInt (scale * h);
  46963. }
  46964. void ImagePreviewComponent::selectedFileChanged (const File& file)
  46965. {
  46966. if (fileToLoad != file)
  46967. {
  46968. fileToLoad = file;
  46969. startTimer (100);
  46970. }
  46971. }
  46972. void ImagePreviewComponent::timerCallback()
  46973. {
  46974. stopTimer();
  46975. currentThumbnail = 0;
  46976. currentDetails = String::empty;
  46977. repaint();
  46978. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  46979. if (in != 0)
  46980. {
  46981. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  46982. if (format != 0)
  46983. {
  46984. currentThumbnail = format->decodeImage (*in);
  46985. if (currentThumbnail != 0)
  46986. {
  46987. int w = currentThumbnail->getWidth();
  46988. int h = currentThumbnail->getHeight();
  46989. currentDetails
  46990. << fileToLoad.getFileName() << "\n"
  46991. << format->getFormatName() << "\n"
  46992. << w << " x " << h << " pixels\n"
  46993. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  46994. getThumbSize (w, h);
  46995. currentThumbnail = currentThumbnail->createCopy (w, h);
  46996. }
  46997. }
  46998. }
  46999. }
  47000. void ImagePreviewComponent::paint (Graphics& g)
  47001. {
  47002. if (currentThumbnail != 0)
  47003. {
  47004. g.setFont (13.0f);
  47005. int w = currentThumbnail->getWidth();
  47006. int h = currentThumbnail->getHeight();
  47007. getThumbSize (w, h);
  47008. const int numLines = 4;
  47009. const int totalH = 13 * numLines + h + 4;
  47010. const int y = (getHeight() - totalH) / 2;
  47011. g.drawImageWithin (currentThumbnail,
  47012. (getWidth() - w) / 2, y, w, h,
  47013. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47014. false);
  47015. g.drawFittedText (currentDetails,
  47016. 0, y + h + 4, getWidth(), 100,
  47017. Justification::centredTop, numLines);
  47018. }
  47019. }
  47020. END_JUCE_NAMESPACE
  47021. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47022. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47023. BEGIN_JUCE_NAMESPACE
  47024. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47025. const String& directoryWildcardPatterns,
  47026. const String& description_)
  47027. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47028. : (description_ + " (" + fileWildcardPatterns + ")"))
  47029. {
  47030. parse (fileWildcardPatterns, fileWildcards);
  47031. parse (directoryWildcardPatterns, directoryWildcards);
  47032. }
  47033. WildcardFileFilter::~WildcardFileFilter()
  47034. {
  47035. }
  47036. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47037. {
  47038. return match (file, fileWildcards);
  47039. }
  47040. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47041. {
  47042. return match (file, directoryWildcards);
  47043. }
  47044. void WildcardFileFilter::parse (const String& pattern, StringArray& result)
  47045. {
  47046. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47047. result.trim();
  47048. result.removeEmptyStrings();
  47049. // special case for *.*, because people use it to mean "any file", but it
  47050. // would actually ignore files with no extension.
  47051. for (int i = result.size(); --i >= 0;)
  47052. if (result[i] == "*.*")
  47053. result.set (i, "*");
  47054. }
  47055. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards)
  47056. {
  47057. const String filename (file.getFileName());
  47058. for (int i = wildcards.size(); --i >= 0;)
  47059. if (filename.matchesWildcard (wildcards[i], true))
  47060. return true;
  47061. return false;
  47062. }
  47063. END_JUCE_NAMESPACE
  47064. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47065. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47066. BEGIN_JUCE_NAMESPACE
  47067. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47068. {
  47069. }
  47070. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47071. {
  47072. }
  47073. namespace KeyboardFocusHelpers
  47074. {
  47075. // This will sort a set of components, so that they are ordered in terms of
  47076. // left-to-right and then top-to-bottom.
  47077. class ScreenPositionComparator
  47078. {
  47079. public:
  47080. ScreenPositionComparator() {}
  47081. static int compareElements (const Component* const first, const Component* const second)
  47082. {
  47083. int explicitOrder1 = first->getExplicitFocusOrder();
  47084. if (explicitOrder1 <= 0)
  47085. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47086. int explicitOrder2 = second->getExplicitFocusOrder();
  47087. if (explicitOrder2 <= 0)
  47088. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47089. if (explicitOrder1 != explicitOrder2)
  47090. return explicitOrder1 - explicitOrder2;
  47091. const int diff = first->getY() - second->getY();
  47092. return (diff == 0) ? first->getX() - second->getX()
  47093. : diff;
  47094. }
  47095. };
  47096. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47097. {
  47098. if (parent->getNumChildComponents() > 0)
  47099. {
  47100. Array <Component*> localComps;
  47101. ScreenPositionComparator comparator;
  47102. int i;
  47103. for (i = parent->getNumChildComponents(); --i >= 0;)
  47104. {
  47105. Component* const c = parent->getChildComponent (i);
  47106. if (c->isVisible() && c->isEnabled())
  47107. localComps.addSorted (comparator, c);
  47108. }
  47109. for (i = 0; i < localComps.size(); ++i)
  47110. {
  47111. Component* const c = localComps.getUnchecked (i);
  47112. if (c->getWantsKeyboardFocus())
  47113. comps.add (c);
  47114. if (! c->isFocusContainer())
  47115. findAllFocusableComponents (c, comps);
  47116. }
  47117. }
  47118. }
  47119. }
  47120. static Component* getIncrementedComponent (Component* const current, const int delta)
  47121. {
  47122. Component* focusContainer = current->getParentComponent();
  47123. if (focusContainer != 0)
  47124. {
  47125. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47126. focusContainer = focusContainer->getParentComponent();
  47127. if (focusContainer != 0)
  47128. {
  47129. Array <Component*> comps;
  47130. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47131. if (comps.size() > 0)
  47132. {
  47133. const int index = comps.indexOf (current);
  47134. return comps [(index + comps.size() + delta) % comps.size()];
  47135. }
  47136. }
  47137. }
  47138. return 0;
  47139. }
  47140. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47141. {
  47142. return getIncrementedComponent (current, 1);
  47143. }
  47144. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47145. {
  47146. return getIncrementedComponent (current, -1);
  47147. }
  47148. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47149. {
  47150. Array <Component*> comps;
  47151. if (parentComponent != 0)
  47152. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47153. return comps.getFirst();
  47154. }
  47155. END_JUCE_NAMESPACE
  47156. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47157. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47158. BEGIN_JUCE_NAMESPACE
  47159. bool KeyListener::keyStateChanged (const bool, Component*)
  47160. {
  47161. return false;
  47162. }
  47163. END_JUCE_NAMESPACE
  47164. /*** End of inlined file: juce_KeyListener.cpp ***/
  47165. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47166. BEGIN_JUCE_NAMESPACE
  47167. // N.B. these two includes are put here deliberately to avoid problems with
  47168. // old GCCs failing on long include paths
  47169. const int maxKeys = 3;
  47170. class KeyMappingChangeButton : public Button
  47171. {
  47172. public:
  47173. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47174. const CommandID commandID_,
  47175. const String& keyName,
  47176. const int keyNum_)
  47177. : Button (keyName),
  47178. owner (owner_),
  47179. commandID (commandID_),
  47180. keyNum (keyNum_)
  47181. {
  47182. setWantsKeyboardFocus (false);
  47183. setTriggeredOnMouseDown (keyNum >= 0);
  47184. if (keyNum_ < 0)
  47185. setTooltip (TRANS("adds a new key-mapping"));
  47186. else
  47187. setTooltip (TRANS("click to change this key-mapping"));
  47188. }
  47189. ~KeyMappingChangeButton()
  47190. {
  47191. }
  47192. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47193. {
  47194. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47195. keyNum >= 0 ? getName() : String::empty);
  47196. }
  47197. void clicked()
  47198. {
  47199. if (keyNum >= 0)
  47200. {
  47201. // existing key clicked..
  47202. PopupMenu m;
  47203. m.addItem (1, TRANS("change this key-mapping"));
  47204. m.addSeparator();
  47205. m.addItem (2, TRANS("remove this key-mapping"));
  47206. const int res = m.show();
  47207. if (res == 1)
  47208. {
  47209. owner->assignNewKey (commandID, keyNum);
  47210. }
  47211. else if (res == 2)
  47212. {
  47213. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47214. }
  47215. }
  47216. else
  47217. {
  47218. // + button pressed..
  47219. owner->assignNewKey (commandID, -1);
  47220. }
  47221. }
  47222. void fitToContent (const int h) throw()
  47223. {
  47224. if (keyNum < 0)
  47225. {
  47226. setSize (h, h);
  47227. }
  47228. else
  47229. {
  47230. Font f (h * 0.6f);
  47231. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47232. }
  47233. }
  47234. juce_UseDebuggingNewOperator
  47235. private:
  47236. KeyMappingEditorComponent* const owner;
  47237. const CommandID commandID;
  47238. const int keyNum;
  47239. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47240. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47241. };
  47242. class KeyMappingItemComponent : public Component
  47243. {
  47244. public:
  47245. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47246. const CommandID commandID_)
  47247. : owner (owner_),
  47248. commandID (commandID_)
  47249. {
  47250. setInterceptsMouseClicks (false, true);
  47251. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47252. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47253. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47254. {
  47255. KeyMappingChangeButton* const kb
  47256. = new KeyMappingChangeButton (owner_, commandID,
  47257. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47258. kb->setEnabled (! isReadOnly);
  47259. addAndMakeVisible (kb);
  47260. }
  47261. KeyMappingChangeButton* const kb
  47262. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47263. addChildComponent (kb);
  47264. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47265. }
  47266. ~KeyMappingItemComponent()
  47267. {
  47268. deleteAllChildren();
  47269. }
  47270. void paint (Graphics& g)
  47271. {
  47272. g.setFont (getHeight() * 0.7f);
  47273. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47274. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47275. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47276. Justification::centredLeft, true);
  47277. }
  47278. void resized()
  47279. {
  47280. int x = getWidth() - 4;
  47281. for (int i = getNumChildComponents(); --i >= 0;)
  47282. {
  47283. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47284. kb->fitToContent (getHeight() - 2);
  47285. kb->setTopRightPosition (x, 1);
  47286. x -= kb->getWidth() + 5;
  47287. }
  47288. }
  47289. juce_UseDebuggingNewOperator
  47290. private:
  47291. KeyMappingEditorComponent* const owner;
  47292. const CommandID commandID;
  47293. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47294. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47295. };
  47296. class KeyMappingTreeViewItem : public TreeViewItem
  47297. {
  47298. public:
  47299. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47300. const CommandID commandID_)
  47301. : owner (owner_),
  47302. commandID (commandID_)
  47303. {
  47304. }
  47305. ~KeyMappingTreeViewItem()
  47306. {
  47307. }
  47308. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47309. bool mightContainSubItems() { return false; }
  47310. int getItemHeight() const { return 20; }
  47311. Component* createItemComponent()
  47312. {
  47313. return new KeyMappingItemComponent (owner, commandID);
  47314. }
  47315. juce_UseDebuggingNewOperator
  47316. private:
  47317. KeyMappingEditorComponent* const owner;
  47318. const CommandID commandID;
  47319. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47320. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47321. };
  47322. class KeyCategoryTreeViewItem : public TreeViewItem
  47323. {
  47324. public:
  47325. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47326. const String& name)
  47327. : owner (owner_),
  47328. categoryName (name)
  47329. {
  47330. }
  47331. ~KeyCategoryTreeViewItem()
  47332. {
  47333. }
  47334. const String getUniqueName() const { return categoryName + "_cat"; }
  47335. bool mightContainSubItems() { return true; }
  47336. int getItemHeight() const { return 28; }
  47337. void paintItem (Graphics& g, int width, int height)
  47338. {
  47339. g.setFont (height * 0.6f, Font::bold);
  47340. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47341. g.drawText (categoryName,
  47342. 2, 0, width - 2, height,
  47343. Justification::centredLeft, true);
  47344. }
  47345. void itemOpennessChanged (bool isNowOpen)
  47346. {
  47347. if (isNowOpen)
  47348. {
  47349. if (getNumSubItems() == 0)
  47350. {
  47351. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47352. for (int i = 0; i < commands.size(); ++i)
  47353. {
  47354. if (owner->shouldCommandBeIncluded (commands[i]))
  47355. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47356. }
  47357. }
  47358. }
  47359. else
  47360. {
  47361. clearSubItems();
  47362. }
  47363. }
  47364. juce_UseDebuggingNewOperator
  47365. private:
  47366. KeyMappingEditorComponent* owner;
  47367. String categoryName;
  47368. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47369. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47370. };
  47371. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47372. const bool showResetToDefaultButton)
  47373. : mappings (mappingManager)
  47374. {
  47375. jassert (mappingManager != 0); // can't be null!
  47376. mappingManager->addChangeListener (this);
  47377. setLinesDrawnForSubItems (false);
  47378. resetButton = 0;
  47379. if (showResetToDefaultButton)
  47380. {
  47381. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47382. resetButton->addButtonListener (this);
  47383. }
  47384. addAndMakeVisible (tree = new TreeView());
  47385. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47386. tree->setRootItemVisible (false);
  47387. tree->setDefaultOpenness (true);
  47388. tree->setRootItem (this);
  47389. }
  47390. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47391. {
  47392. mappings->removeChangeListener (this);
  47393. deleteAllChildren();
  47394. }
  47395. bool KeyMappingEditorComponent::mightContainSubItems()
  47396. {
  47397. return true;
  47398. }
  47399. const String KeyMappingEditorComponent::getUniqueName() const
  47400. {
  47401. return "keys";
  47402. }
  47403. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47404. const Colour& textColour)
  47405. {
  47406. setColour (backgroundColourId, mainBackground);
  47407. setColour (textColourId, textColour);
  47408. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47409. }
  47410. void KeyMappingEditorComponent::parentHierarchyChanged()
  47411. {
  47412. changeListenerCallback (0);
  47413. }
  47414. void KeyMappingEditorComponent::resized()
  47415. {
  47416. int h = getHeight();
  47417. if (resetButton != 0)
  47418. {
  47419. const int buttonHeight = 20;
  47420. h -= buttonHeight + 8;
  47421. int x = getWidth() - 8;
  47422. const int y = h + 6;
  47423. resetButton->changeWidthToFitText (buttonHeight);
  47424. resetButton->setTopRightPosition (x, y);
  47425. }
  47426. tree->setBounds (0, 0, getWidth(), h);
  47427. }
  47428. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47429. {
  47430. if (button == resetButton)
  47431. {
  47432. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47433. TRANS("Reset to defaults"),
  47434. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47435. TRANS("Reset")))
  47436. {
  47437. mappings->resetToDefaultMappings();
  47438. }
  47439. }
  47440. }
  47441. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47442. {
  47443. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47444. clearSubItems();
  47445. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47446. for (int i = 0; i < categories.size(); ++i)
  47447. {
  47448. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47449. int count = 0;
  47450. for (int j = 0; j < commands.size(); ++j)
  47451. if (shouldCommandBeIncluded (commands[j]))
  47452. ++count;
  47453. if (count > 0)
  47454. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47455. }
  47456. if (openness != 0)
  47457. tree->restoreOpennessState (*openness);
  47458. }
  47459. class KeyEntryWindow : public AlertWindow
  47460. {
  47461. public:
  47462. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47463. : AlertWindow (TRANS("New key-mapping"),
  47464. TRANS("Please press a key combination now..."),
  47465. AlertWindow::NoIcon),
  47466. owner (owner_)
  47467. {
  47468. addButton (TRANS("ok"), 1);
  47469. addButton (TRANS("cancel"), 0);
  47470. // (avoid return + escape keys getting processed by the buttons..)
  47471. for (int i = getNumChildComponents(); --i >= 0;)
  47472. getChildComponent (i)->setWantsKeyboardFocus (false);
  47473. setWantsKeyboardFocus (true);
  47474. grabKeyboardFocus();
  47475. }
  47476. ~KeyEntryWindow()
  47477. {
  47478. }
  47479. bool keyPressed (const KeyPress& key)
  47480. {
  47481. lastPress = key;
  47482. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47483. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47484. if (previousCommand != 0)
  47485. {
  47486. message << "\n\n"
  47487. << TRANS("(Currently assigned to \"")
  47488. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47489. << "\")";
  47490. }
  47491. setMessage (message);
  47492. return true;
  47493. }
  47494. bool keyStateChanged (bool)
  47495. {
  47496. return true;
  47497. }
  47498. KeyPress lastPress;
  47499. juce_UseDebuggingNewOperator
  47500. private:
  47501. KeyMappingEditorComponent* owner;
  47502. KeyEntryWindow (const KeyEntryWindow&);
  47503. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47504. };
  47505. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47506. {
  47507. KeyEntryWindow entryWindow (this);
  47508. if (entryWindow.runModalLoop() != 0)
  47509. {
  47510. entryWindow.setVisible (false);
  47511. if (entryWindow.lastPress.isValid())
  47512. {
  47513. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47514. if (previousCommand != 0)
  47515. {
  47516. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47517. TRANS("Change key-mapping"),
  47518. TRANS("This key is already assigned to the command \"")
  47519. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47520. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47521. TRANS("re-assign"),
  47522. TRANS("cancel")))
  47523. {
  47524. return;
  47525. }
  47526. }
  47527. mappings->removeKeyPress (entryWindow.lastPress);
  47528. if (index >= 0)
  47529. mappings->removeKeyPress (commandID, index);
  47530. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47531. }
  47532. }
  47533. }
  47534. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47535. {
  47536. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47537. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47538. }
  47539. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47540. {
  47541. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47542. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47543. }
  47544. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47545. {
  47546. return key.getTextDescription();
  47547. }
  47548. END_JUCE_NAMESPACE
  47549. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47550. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47551. BEGIN_JUCE_NAMESPACE
  47552. KeyPress::KeyPress() throw()
  47553. : keyCode (0),
  47554. mods (0),
  47555. textCharacter (0)
  47556. {
  47557. }
  47558. KeyPress::KeyPress (const int keyCode_,
  47559. const ModifierKeys& mods_,
  47560. const juce_wchar textCharacter_) throw()
  47561. : keyCode (keyCode_),
  47562. mods (mods_),
  47563. textCharacter (textCharacter_)
  47564. {
  47565. }
  47566. KeyPress::KeyPress (const int keyCode_) throw()
  47567. : keyCode (keyCode_),
  47568. textCharacter (0)
  47569. {
  47570. }
  47571. KeyPress::KeyPress (const KeyPress& other) throw()
  47572. : keyCode (other.keyCode),
  47573. mods (other.mods),
  47574. textCharacter (other.textCharacter)
  47575. {
  47576. }
  47577. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47578. {
  47579. keyCode = other.keyCode;
  47580. mods = other.mods;
  47581. textCharacter = other.textCharacter;
  47582. return *this;
  47583. }
  47584. bool KeyPress::operator== (const KeyPress& other) const throw()
  47585. {
  47586. return mods.getRawFlags() == other.mods.getRawFlags()
  47587. && (textCharacter == other.textCharacter
  47588. || textCharacter == 0
  47589. || other.textCharacter == 0)
  47590. && (keyCode == other.keyCode
  47591. || (keyCode < 256
  47592. && other.keyCode < 256
  47593. && CharacterFunctions::toLowerCase ((juce_wchar) keyCode)
  47594. == CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
  47595. }
  47596. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47597. {
  47598. return ! operator== (other);
  47599. }
  47600. bool KeyPress::isCurrentlyDown() const
  47601. {
  47602. return isKeyCurrentlyDown (keyCode)
  47603. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47604. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47605. }
  47606. namespace KeyPressHelpers
  47607. {
  47608. struct KeyNameAndCode
  47609. {
  47610. const char* name;
  47611. int code;
  47612. };
  47613. static const KeyNameAndCode translations[] =
  47614. {
  47615. { "spacebar", KeyPress::spaceKey },
  47616. { "return", KeyPress::returnKey },
  47617. { "escape", KeyPress::escapeKey },
  47618. { "backspace", KeyPress::backspaceKey },
  47619. { "cursor left", KeyPress::leftKey },
  47620. { "cursor right", KeyPress::rightKey },
  47621. { "cursor up", KeyPress::upKey },
  47622. { "cursor down", KeyPress::downKey },
  47623. { "page up", KeyPress::pageUpKey },
  47624. { "page down", KeyPress::pageDownKey },
  47625. { "home", KeyPress::homeKey },
  47626. { "end", KeyPress::endKey },
  47627. { "delete", KeyPress::deleteKey },
  47628. { "insert", KeyPress::insertKey },
  47629. { "tab", KeyPress::tabKey },
  47630. { "play", KeyPress::playKey },
  47631. { "stop", KeyPress::stopKey },
  47632. { "fast forward", KeyPress::fastForwardKey },
  47633. { "rewind", KeyPress::rewindKey }
  47634. };
  47635. static const String numberPadPrefix() { return "numpad "; }
  47636. }
  47637. const KeyPress KeyPress::createFromDescription (const String& desc)
  47638. {
  47639. int modifiers = 0;
  47640. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47641. || desc.containsWholeWordIgnoreCase ("control")
  47642. || desc.containsWholeWordIgnoreCase ("ctl"))
  47643. modifiers |= ModifierKeys::ctrlModifier;
  47644. if (desc.containsWholeWordIgnoreCase ("shift")
  47645. || desc.containsWholeWordIgnoreCase ("shft"))
  47646. modifiers |= ModifierKeys::shiftModifier;
  47647. if (desc.containsWholeWordIgnoreCase ("alt")
  47648. || desc.containsWholeWordIgnoreCase ("option"))
  47649. modifiers |= ModifierKeys::altModifier;
  47650. if (desc.containsWholeWordIgnoreCase ("command")
  47651. || desc.containsWholeWordIgnoreCase ("cmd"))
  47652. modifiers |= ModifierKeys::commandModifier;
  47653. int key = 0;
  47654. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47655. {
  47656. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47657. {
  47658. key = KeyPressHelpers::translations[i].code;
  47659. break;
  47660. }
  47661. }
  47662. if (key == 0)
  47663. {
  47664. // see if it's a numpad key..
  47665. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47666. {
  47667. const juce_wchar lastChar = desc.trimEnd().getLastCharacter();
  47668. if (lastChar >= '0' && lastChar <= '9')
  47669. key = numberPad0 + lastChar - '0';
  47670. else if (lastChar == '+')
  47671. key = numberPadAdd;
  47672. else if (lastChar == '-')
  47673. key = numberPadSubtract;
  47674. else if (lastChar == '*')
  47675. key = numberPadMultiply;
  47676. else if (lastChar == '/')
  47677. key = numberPadDivide;
  47678. else if (lastChar == '.')
  47679. key = numberPadDecimalPoint;
  47680. else if (lastChar == '=')
  47681. key = numberPadEquals;
  47682. else if (desc.endsWith ("separator"))
  47683. key = numberPadSeparator;
  47684. else if (desc.endsWith ("delete"))
  47685. key = numberPadDelete;
  47686. }
  47687. if (key == 0)
  47688. {
  47689. // see if it's a function key..
  47690. for (int i = 1; i <= 12; ++i)
  47691. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47692. key = F1Key + i - 1;
  47693. if (key == 0)
  47694. {
  47695. // give up and use the hex code..
  47696. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47697. .toLowerCase()
  47698. .retainCharacters ("0123456789abcdef")
  47699. .getHexValue32();
  47700. if (hexCode > 0)
  47701. key = hexCode;
  47702. else
  47703. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47704. }
  47705. }
  47706. }
  47707. return KeyPress (key, ModifierKeys (modifiers), 0);
  47708. }
  47709. const String KeyPress::getTextDescription() const
  47710. {
  47711. String desc;
  47712. if (keyCode > 0)
  47713. {
  47714. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47715. // want to store it as being a slash, not shift+whatever.
  47716. if (textCharacter == '/')
  47717. return "/";
  47718. if (mods.isCtrlDown())
  47719. desc << "ctrl + ";
  47720. if (mods.isShiftDown())
  47721. desc << "shift + ";
  47722. #if JUCE_MAC
  47723. // only do this on the mac, because on Windows ctrl and command are the same,
  47724. // and this would get confusing
  47725. if (mods.isCommandDown())
  47726. desc << "command + ";
  47727. if (mods.isAltDown())
  47728. desc << "option + ";
  47729. #else
  47730. if (mods.isAltDown())
  47731. desc << "alt + ";
  47732. #endif
  47733. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47734. if (keyCode == KeyPressHelpers::translations[i].code)
  47735. return desc + KeyPressHelpers::translations[i].name;
  47736. if (keyCode >= F1Key && keyCode <= F16Key)
  47737. desc << 'F' << (1 + keyCode - F1Key);
  47738. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47739. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47740. else if (keyCode >= 33 && keyCode < 176)
  47741. desc += CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  47742. else if (keyCode == numberPadAdd)
  47743. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47744. else if (keyCode == numberPadSubtract)
  47745. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47746. else if (keyCode == numberPadMultiply)
  47747. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47748. else if (keyCode == numberPadDivide)
  47749. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47750. else if (keyCode == numberPadSeparator)
  47751. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47752. else if (keyCode == numberPadDecimalPoint)
  47753. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47754. else if (keyCode == numberPadDelete)
  47755. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47756. else
  47757. desc << '#' << String::toHexString (keyCode);
  47758. }
  47759. return desc;
  47760. }
  47761. END_JUCE_NAMESPACE
  47762. /*** End of inlined file: juce_KeyPress.cpp ***/
  47763. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47764. BEGIN_JUCE_NAMESPACE
  47765. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
  47766. : commandManager (commandManager_)
  47767. {
  47768. // A manager is needed to get the descriptions of commands, and will be called when
  47769. // a command is invoked. So you can't leave this null..
  47770. jassert (commandManager_ != 0);
  47771. Desktop::getInstance().addFocusChangeListener (this);
  47772. }
  47773. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
  47774. : commandManager (other.commandManager)
  47775. {
  47776. Desktop::getInstance().addFocusChangeListener (this);
  47777. }
  47778. KeyPressMappingSet::~KeyPressMappingSet()
  47779. {
  47780. Desktop::getInstance().removeFocusChangeListener (this);
  47781. }
  47782. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const
  47783. {
  47784. for (int i = 0; i < mappings.size(); ++i)
  47785. if (mappings.getUnchecked(i)->commandID == commandID)
  47786. return mappings.getUnchecked (i)->keypresses;
  47787. return Array <KeyPress> ();
  47788. }
  47789. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47790. const KeyPress& newKeyPress,
  47791. int insertIndex)
  47792. {
  47793. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47794. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47795. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47796. && ! newKeyPress.getModifiers().isShiftDown()));
  47797. if (findCommandForKeyPress (newKeyPress) != commandID)
  47798. {
  47799. removeKeyPress (newKeyPress);
  47800. if (newKeyPress.isValid())
  47801. {
  47802. for (int i = mappings.size(); --i >= 0;)
  47803. {
  47804. if (mappings.getUnchecked(i)->commandID == commandID)
  47805. {
  47806. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47807. sendChangeMessage (this);
  47808. return;
  47809. }
  47810. }
  47811. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47812. if (ci != 0)
  47813. {
  47814. CommandMapping* const cm = new CommandMapping();
  47815. cm->commandID = commandID;
  47816. cm->keypresses.add (newKeyPress);
  47817. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47818. mappings.add (cm);
  47819. sendChangeMessage (this);
  47820. }
  47821. }
  47822. }
  47823. }
  47824. void KeyPressMappingSet::resetToDefaultMappings()
  47825. {
  47826. mappings.clear();
  47827. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47828. {
  47829. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47830. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47831. {
  47832. addKeyPress (ci->commandID,
  47833. ci->defaultKeypresses.getReference (j));
  47834. }
  47835. }
  47836. sendChangeMessage (this);
  47837. }
  47838. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
  47839. {
  47840. clearAllKeyPresses (commandID);
  47841. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47842. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47843. {
  47844. addKeyPress (ci->commandID,
  47845. ci->defaultKeypresses.getReference (j));
  47846. }
  47847. }
  47848. void KeyPressMappingSet::clearAllKeyPresses()
  47849. {
  47850. if (mappings.size() > 0)
  47851. {
  47852. sendChangeMessage (this);
  47853. mappings.clear();
  47854. }
  47855. }
  47856. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
  47857. {
  47858. for (int i = mappings.size(); --i >= 0;)
  47859. {
  47860. if (mappings.getUnchecked(i)->commandID == commandID)
  47861. {
  47862. mappings.remove (i);
  47863. sendChangeMessage (this);
  47864. }
  47865. }
  47866. }
  47867. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
  47868. {
  47869. if (keypress.isValid())
  47870. {
  47871. for (int i = mappings.size(); --i >= 0;)
  47872. {
  47873. CommandMapping* const cm = mappings.getUnchecked(i);
  47874. for (int j = cm->keypresses.size(); --j >= 0;)
  47875. {
  47876. if (keypress == cm->keypresses [j])
  47877. {
  47878. cm->keypresses.remove (j);
  47879. sendChangeMessage (this);
  47880. }
  47881. }
  47882. }
  47883. }
  47884. }
  47885. void KeyPressMappingSet::removeKeyPress (const CommandID commandID, const int keyPressIndex)
  47886. {
  47887. for (int i = mappings.size(); --i >= 0;)
  47888. {
  47889. if (mappings.getUnchecked(i)->commandID == commandID)
  47890. {
  47891. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47892. sendChangeMessage (this);
  47893. break;
  47894. }
  47895. }
  47896. }
  47897. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47898. {
  47899. for (int i = 0; i < mappings.size(); ++i)
  47900. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47901. return mappings.getUnchecked(i)->commandID;
  47902. return 0;
  47903. }
  47904. bool KeyPressMappingSet::containsMapping (const CommandID commandID, const KeyPress& keyPress) const throw()
  47905. {
  47906. for (int i = mappings.size(); --i >= 0;)
  47907. if (mappings.getUnchecked(i)->commandID == commandID)
  47908. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47909. return false;
  47910. }
  47911. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47912. const KeyPress& key,
  47913. const bool isKeyDown,
  47914. const int millisecsSinceKeyPressed,
  47915. Component* const originatingComponent) const
  47916. {
  47917. ApplicationCommandTarget::InvocationInfo info (commandID);
  47918. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47919. info.isKeyDown = isKeyDown;
  47920. info.keyPress = key;
  47921. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47922. info.originatingComponent = originatingComponent;
  47923. commandManager->invoke (info, false);
  47924. }
  47925. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47926. {
  47927. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47928. {
  47929. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47930. {
  47931. // if the XML was created as a set of differences from the default mappings,
  47932. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47933. resetToDefaultMappings();
  47934. }
  47935. else
  47936. {
  47937. // if the XML was created calling createXml (false), then we need to clear all
  47938. // the keys and treat the xml as describing the entire set of mappings.
  47939. clearAllKeyPresses();
  47940. }
  47941. forEachXmlChildElement (xmlVersion, map)
  47942. {
  47943. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47944. if (commandId != 0)
  47945. {
  47946. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47947. if (map->hasTagName ("MAPPING"))
  47948. {
  47949. addKeyPress (commandId, key);
  47950. }
  47951. else if (map->hasTagName ("UNMAPPING"))
  47952. {
  47953. if (containsMapping (commandId, key))
  47954. removeKeyPress (key);
  47955. }
  47956. }
  47957. }
  47958. return true;
  47959. }
  47960. return false;
  47961. }
  47962. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  47963. {
  47964. ScopedPointer <KeyPressMappingSet> defaultSet;
  47965. if (saveDifferencesFromDefaultSet)
  47966. {
  47967. defaultSet = new KeyPressMappingSet (commandManager);
  47968. defaultSet->resetToDefaultMappings();
  47969. }
  47970. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  47971. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  47972. int i;
  47973. for (i = 0; i < mappings.size(); ++i)
  47974. {
  47975. const CommandMapping* const cm = mappings.getUnchecked(i);
  47976. for (int j = 0; j < cm->keypresses.size(); ++j)
  47977. {
  47978. if (defaultSet == 0
  47979. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47980. {
  47981. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  47982. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47983. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47984. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47985. }
  47986. }
  47987. }
  47988. if (defaultSet != 0)
  47989. {
  47990. for (i = 0; i < defaultSet->mappings.size(); ++i)
  47991. {
  47992. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  47993. for (int j = 0; j < cm->keypresses.size(); ++j)
  47994. {
  47995. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47996. {
  47997. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  47998. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47999. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48000. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48001. }
  48002. }
  48003. }
  48004. }
  48005. return doc;
  48006. }
  48007. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48008. Component* originatingComponent)
  48009. {
  48010. bool used = false;
  48011. const CommandID commandID = findCommandForKeyPress (key);
  48012. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48013. if (ci != 0
  48014. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48015. {
  48016. ApplicationCommandInfo info (0);
  48017. if (commandManager->getTargetForCommand (commandID, info) != 0
  48018. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48019. {
  48020. invokeCommand (commandID, key, true, 0, originatingComponent);
  48021. used = true;
  48022. }
  48023. else
  48024. {
  48025. if (originatingComponent != 0)
  48026. originatingComponent->getLookAndFeel().playAlertSound();
  48027. }
  48028. }
  48029. return used;
  48030. }
  48031. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48032. {
  48033. bool used = false;
  48034. const uint32 now = Time::getMillisecondCounter();
  48035. for (int i = mappings.size(); --i >= 0;)
  48036. {
  48037. CommandMapping* const cm = mappings.getUnchecked(i);
  48038. if (cm->wantsKeyUpDownCallbacks)
  48039. {
  48040. for (int j = cm->keypresses.size(); --j >= 0;)
  48041. {
  48042. const KeyPress key (cm->keypresses.getReference (j));
  48043. const bool isDown = key.isCurrentlyDown();
  48044. int keyPressEntryIndex = 0;
  48045. bool wasDown = false;
  48046. for (int k = keysDown.size(); --k >= 0;)
  48047. {
  48048. if (key == keysDown.getUnchecked(k)->key)
  48049. {
  48050. keyPressEntryIndex = k;
  48051. wasDown = true;
  48052. used = true;
  48053. break;
  48054. }
  48055. }
  48056. if (isDown != wasDown)
  48057. {
  48058. int millisecs = 0;
  48059. if (isDown)
  48060. {
  48061. KeyPressTime* const k = new KeyPressTime();
  48062. k->key = key;
  48063. k->timeWhenPressed = now;
  48064. keysDown.add (k);
  48065. }
  48066. else
  48067. {
  48068. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48069. if (now > pressTime)
  48070. millisecs = now - pressTime;
  48071. keysDown.remove (keyPressEntryIndex);
  48072. }
  48073. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48074. used = true;
  48075. }
  48076. }
  48077. }
  48078. }
  48079. return used;
  48080. }
  48081. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48082. {
  48083. if (focusedComponent != 0)
  48084. focusedComponent->keyStateChanged (false);
  48085. }
  48086. END_JUCE_NAMESPACE
  48087. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48088. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48089. BEGIN_JUCE_NAMESPACE
  48090. ModifierKeys::ModifierKeys (const int flags_) throw()
  48091. : flags (flags_)
  48092. {
  48093. }
  48094. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48095. : flags (other.flags)
  48096. {
  48097. }
  48098. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48099. {
  48100. flags = other.flags;
  48101. return *this;
  48102. }
  48103. ModifierKeys ModifierKeys::currentModifiers;
  48104. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48105. {
  48106. return currentModifiers;
  48107. }
  48108. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48109. {
  48110. int num = 0;
  48111. if (isLeftButtonDown()) ++num;
  48112. if (isRightButtonDown()) ++num;
  48113. if (isMiddleButtonDown()) ++num;
  48114. return num;
  48115. }
  48116. END_JUCE_NAMESPACE
  48117. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48118. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48119. BEGIN_JUCE_NAMESPACE
  48120. class ComponentAnimator::AnimationTask
  48121. {
  48122. public:
  48123. AnimationTask (Component* const comp)
  48124. : component (comp)
  48125. {
  48126. }
  48127. Component::SafePointer<Component> component;
  48128. Rectangle<int> destination;
  48129. int msElapsed, msTotal;
  48130. double startSpeed, midSpeed, endSpeed, lastProgress;
  48131. double left, top, right, bottom;
  48132. bool useTimeslice (const int elapsed)
  48133. {
  48134. if (component == 0)
  48135. return false;
  48136. msElapsed += elapsed;
  48137. double newProgress = msElapsed / (double) msTotal;
  48138. if (newProgress >= 0 && newProgress < 1.0)
  48139. {
  48140. newProgress = timeToDistance (newProgress);
  48141. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48142. jassert (newProgress >= lastProgress);
  48143. lastProgress = newProgress;
  48144. left += (destination.getX() - left) * delta;
  48145. top += (destination.getY() - top) * delta;
  48146. right += (destination.getRight() - right) * delta;
  48147. bottom += (destination.getBottom() - bottom) * delta;
  48148. if (delta < 1.0)
  48149. {
  48150. const Rectangle<int> newBounds (roundToInt (left),
  48151. roundToInt (top),
  48152. roundToInt (right - left),
  48153. roundToInt (bottom - top));
  48154. if (newBounds != destination)
  48155. {
  48156. component->setBounds (newBounds);
  48157. return true;
  48158. }
  48159. }
  48160. }
  48161. component->setBounds (destination);
  48162. return false;
  48163. }
  48164. void moveToFinalDestination()
  48165. {
  48166. if (component != 0)
  48167. component->setBounds (destination);
  48168. }
  48169. private:
  48170. inline double timeToDistance (const double time) const
  48171. {
  48172. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48173. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48174. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48175. }
  48176. };
  48177. ComponentAnimator::ComponentAnimator()
  48178. : lastTime (0)
  48179. {
  48180. }
  48181. ComponentAnimator::~ComponentAnimator()
  48182. {
  48183. cancelAllAnimations (false);
  48184. jassert (tasks.size() == 0);
  48185. }
  48186. ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const
  48187. {
  48188. for (int i = tasks.size(); --i >= 0;)
  48189. if (component == tasks.getUnchecked(i)->component.getComponent())
  48190. return tasks.getUnchecked(i);
  48191. return 0;
  48192. }
  48193. void ComponentAnimator::animateComponent (Component* const component,
  48194. const Rectangle<int>& finalPosition,
  48195. const int millisecondsToSpendMoving,
  48196. const double startSpeed,
  48197. const double endSpeed)
  48198. {
  48199. if (component != 0)
  48200. {
  48201. AnimationTask* at = findTaskFor (component);
  48202. if (at == 0)
  48203. {
  48204. at = new AnimationTask (component);
  48205. tasks.add (at);
  48206. sendChangeMessage (this);
  48207. }
  48208. at->msElapsed = 0;
  48209. at->lastProgress = 0;
  48210. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48211. at->destination = finalPosition;
  48212. // the speeds must be 0 or greater!
  48213. jassert (startSpeed >= 0 && endSpeed >= 0)
  48214. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48215. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48216. at->midSpeed = invTotalDistance;
  48217. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48218. at->left = component->getX();
  48219. at->top = component->getY();
  48220. at->right = component->getRight();
  48221. at->bottom = component->getBottom();
  48222. if (! isTimerRunning())
  48223. {
  48224. lastTime = Time::getMillisecondCounter();
  48225. startTimer (1000 / 50);
  48226. }
  48227. }
  48228. }
  48229. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48230. {
  48231. for (int i = tasks.size(); --i >= 0;)
  48232. {
  48233. AnimationTask* const at = tasks.getUnchecked(i);
  48234. if (moveComponentsToTheirFinalPositions)
  48235. at->moveToFinalDestination();
  48236. delete at;
  48237. tasks.remove (i);
  48238. sendChangeMessage (this);
  48239. }
  48240. }
  48241. void ComponentAnimator::cancelAnimation (Component* const component,
  48242. const bool moveComponentToItsFinalPosition)
  48243. {
  48244. AnimationTask* const at = findTaskFor (component);
  48245. if (at != 0)
  48246. {
  48247. if (moveComponentToItsFinalPosition)
  48248. at->moveToFinalDestination();
  48249. tasks.removeValue (at);
  48250. delete at;
  48251. sendChangeMessage (this);
  48252. }
  48253. }
  48254. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48255. {
  48256. AnimationTask* const at = findTaskFor (component);
  48257. if (at != 0)
  48258. return at->destination;
  48259. else if (component != 0)
  48260. return component->getBounds();
  48261. return Rectangle<int>();
  48262. }
  48263. bool ComponentAnimator::isAnimating (Component* component) const
  48264. {
  48265. return findTaskFor (component) != 0;
  48266. }
  48267. void ComponentAnimator::timerCallback()
  48268. {
  48269. const uint32 timeNow = Time::getMillisecondCounter();
  48270. if (lastTime == 0 || lastTime == timeNow)
  48271. lastTime = timeNow;
  48272. const int elapsed = timeNow - lastTime;
  48273. for (int i = tasks.size(); --i >= 0;)
  48274. {
  48275. AnimationTask* const at = tasks.getUnchecked(i);
  48276. if (! at->useTimeslice (elapsed))
  48277. {
  48278. tasks.remove (i);
  48279. delete at;
  48280. sendChangeMessage (this);
  48281. }
  48282. }
  48283. lastTime = timeNow;
  48284. if (tasks.size() == 0)
  48285. stopTimer();
  48286. }
  48287. END_JUCE_NAMESPACE
  48288. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48289. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48290. BEGIN_JUCE_NAMESPACE
  48291. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48292. : minW (0),
  48293. maxW (0x3fffffff),
  48294. minH (0),
  48295. maxH (0x3fffffff),
  48296. minOffTop (0),
  48297. minOffLeft (0),
  48298. minOffBottom (0),
  48299. minOffRight (0),
  48300. aspectRatio (0.0)
  48301. {
  48302. }
  48303. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48304. {
  48305. }
  48306. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48307. {
  48308. minW = minimumWidth;
  48309. }
  48310. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48311. {
  48312. maxW = maximumWidth;
  48313. }
  48314. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48315. {
  48316. minH = minimumHeight;
  48317. }
  48318. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48319. {
  48320. maxH = maximumHeight;
  48321. }
  48322. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48323. {
  48324. jassert (maxW >= minimumWidth);
  48325. jassert (maxH >= minimumHeight);
  48326. jassert (minimumWidth > 0 && minimumHeight > 0);
  48327. minW = minimumWidth;
  48328. minH = minimumHeight;
  48329. if (minW > maxW)
  48330. maxW = minW;
  48331. if (minH > maxH)
  48332. maxH = minH;
  48333. }
  48334. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48335. {
  48336. jassert (maximumWidth >= minW);
  48337. jassert (maximumHeight >= minH);
  48338. jassert (maximumWidth > 0 && maximumHeight > 0);
  48339. maxW = jmax (minW, maximumWidth);
  48340. maxH = jmax (minH, maximumHeight);
  48341. }
  48342. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48343. const int minimumHeight,
  48344. const int maximumWidth,
  48345. const int maximumHeight) throw()
  48346. {
  48347. jassert (maximumWidth >= minimumWidth);
  48348. jassert (maximumHeight >= minimumHeight);
  48349. jassert (maximumWidth > 0 && maximumHeight > 0);
  48350. jassert (minimumWidth > 0 && minimumHeight > 0);
  48351. minW = jmax (0, minimumWidth);
  48352. minH = jmax (0, minimumHeight);
  48353. maxW = jmax (minW, maximumWidth);
  48354. maxH = jmax (minH, maximumHeight);
  48355. }
  48356. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48357. const int minimumWhenOffTheLeft,
  48358. const int minimumWhenOffTheBottom,
  48359. const int minimumWhenOffTheRight) throw()
  48360. {
  48361. minOffTop = minimumWhenOffTheTop;
  48362. minOffLeft = minimumWhenOffTheLeft;
  48363. minOffBottom = minimumWhenOffTheBottom;
  48364. minOffRight = minimumWhenOffTheRight;
  48365. }
  48366. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48367. {
  48368. aspectRatio = jmax (0.0, widthOverHeight);
  48369. }
  48370. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48371. {
  48372. return aspectRatio;
  48373. }
  48374. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48375. const Rectangle<int>& targetBounds,
  48376. const bool isStretchingTop,
  48377. const bool isStretchingLeft,
  48378. const bool isStretchingBottom,
  48379. const bool isStretchingRight)
  48380. {
  48381. jassert (component != 0);
  48382. Rectangle<int> limits, bounds (targetBounds);
  48383. BorderSize border;
  48384. Component* const parent = component->getParentComponent();
  48385. if (parent == 0)
  48386. {
  48387. ComponentPeer* peer = component->getPeer();
  48388. if (peer != 0)
  48389. border = peer->getFrameSize();
  48390. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48391. }
  48392. else
  48393. {
  48394. limits.setSize (parent->getWidth(), parent->getHeight());
  48395. }
  48396. border.addTo (bounds);
  48397. checkBounds (bounds,
  48398. border.addedTo (component->getBounds()), limits,
  48399. isStretchingTop, isStretchingLeft,
  48400. isStretchingBottom, isStretchingRight);
  48401. border.subtractFrom (bounds);
  48402. applyBoundsToComponent (component, bounds);
  48403. }
  48404. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48405. {
  48406. setBoundsForComponent (component, component->getBounds(),
  48407. false, false, false, false);
  48408. }
  48409. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48410. const Rectangle<int>& bounds)
  48411. {
  48412. component->setBounds (bounds);
  48413. }
  48414. void ComponentBoundsConstrainer::resizeStart()
  48415. {
  48416. }
  48417. void ComponentBoundsConstrainer::resizeEnd()
  48418. {
  48419. }
  48420. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48421. const Rectangle<int>& old,
  48422. const Rectangle<int>& limits,
  48423. const bool isStretchingTop,
  48424. const bool isStretchingLeft,
  48425. const bool isStretchingBottom,
  48426. const bool isStretchingRight)
  48427. {
  48428. int x = bounds.getX();
  48429. int y = bounds.getY();
  48430. int w = bounds.getWidth();
  48431. int h = bounds.getHeight();
  48432. // constrain the size if it's being stretched..
  48433. if (isStretchingLeft)
  48434. {
  48435. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48436. w = old.getRight() - x;
  48437. }
  48438. if (isStretchingRight)
  48439. {
  48440. w = jlimit (minW, maxW, w);
  48441. }
  48442. if (isStretchingTop)
  48443. {
  48444. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48445. h = old.getBottom() - y;
  48446. }
  48447. if (isStretchingBottom)
  48448. {
  48449. h = jlimit (minH, maxH, h);
  48450. }
  48451. // constrain the aspect ratio if one has been specified..
  48452. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48453. {
  48454. bool adjustWidth;
  48455. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48456. {
  48457. adjustWidth = true;
  48458. }
  48459. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48460. {
  48461. adjustWidth = false;
  48462. }
  48463. else
  48464. {
  48465. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48466. const double newRatio = fabs (w / (double) h);
  48467. adjustWidth = (oldRatio > newRatio);
  48468. }
  48469. if (adjustWidth)
  48470. {
  48471. w = roundToInt (h * aspectRatio);
  48472. if (w > maxW || w < minW)
  48473. {
  48474. w = jlimit (minW, maxW, w);
  48475. h = roundToInt (w / aspectRatio);
  48476. }
  48477. }
  48478. else
  48479. {
  48480. h = roundToInt (w / aspectRatio);
  48481. if (h > maxH || h < minH)
  48482. {
  48483. h = jlimit (minH, maxH, h);
  48484. w = roundToInt (h * aspectRatio);
  48485. }
  48486. }
  48487. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48488. {
  48489. x = old.getX() + (old.getWidth() - w) / 2;
  48490. }
  48491. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48492. {
  48493. y = old.getY() + (old.getHeight() - h) / 2;
  48494. }
  48495. else
  48496. {
  48497. if (isStretchingLeft)
  48498. x = old.getRight() - w;
  48499. if (isStretchingTop)
  48500. y = old.getBottom() - h;
  48501. }
  48502. }
  48503. // ...and constrain the position if limits have been set for that.
  48504. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48505. {
  48506. if (minOffTop > 0)
  48507. {
  48508. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48509. if (y < limit)
  48510. {
  48511. if (isStretchingTop)
  48512. h -= (limit - y);
  48513. y = limit;
  48514. }
  48515. }
  48516. if (minOffLeft > 0)
  48517. {
  48518. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48519. if (x < limit)
  48520. {
  48521. if (isStretchingLeft)
  48522. w -= (limit - x);
  48523. x = limit;
  48524. }
  48525. }
  48526. if (minOffBottom > 0)
  48527. {
  48528. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48529. if (y > limit)
  48530. {
  48531. if (isStretchingBottom)
  48532. h += (limit - y);
  48533. else
  48534. y = limit;
  48535. }
  48536. }
  48537. if (minOffRight > 0)
  48538. {
  48539. const int limit = limits.getRight() - jmin (minOffRight, w);
  48540. if (x > limit)
  48541. {
  48542. if (isStretchingRight)
  48543. w += (limit - x);
  48544. else
  48545. x = limit;
  48546. }
  48547. }
  48548. }
  48549. jassert (w >= 0 && h >= 0);
  48550. bounds = Rectangle<int> (x, y, w, h);
  48551. }
  48552. END_JUCE_NAMESPACE
  48553. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48554. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48555. BEGIN_JUCE_NAMESPACE
  48556. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48557. : component (component_),
  48558. lastPeer (0),
  48559. reentrant (false)
  48560. {
  48561. jassert (component != 0); // can't use this with a null pointer..
  48562. component->addComponentListener (this);
  48563. registerWithParentComps();
  48564. }
  48565. ComponentMovementWatcher::~ComponentMovementWatcher()
  48566. {
  48567. component->removeComponentListener (this);
  48568. unregister();
  48569. }
  48570. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48571. {
  48572. // agh! don't delete the target component without deleting this object first!
  48573. jassert (component != 0);
  48574. if (! reentrant)
  48575. {
  48576. reentrant = true;
  48577. ComponentPeer* const peer = component->getPeer();
  48578. if (peer != lastPeer)
  48579. {
  48580. componentPeerChanged();
  48581. if (component == 0)
  48582. return;
  48583. lastPeer = peer;
  48584. }
  48585. unregister();
  48586. registerWithParentComps();
  48587. reentrant = false;
  48588. componentMovedOrResized (*component, true, true);
  48589. }
  48590. }
  48591. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48592. {
  48593. // agh! don't delete the target component without deleting this object first!
  48594. jassert (component != 0);
  48595. if (wasMoved)
  48596. {
  48597. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48598. wasMoved = lastBounds.getPosition() != pos;
  48599. lastBounds.setPosition (pos);
  48600. }
  48601. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48602. lastBounds.setSize (component->getWidth(), component->getHeight());
  48603. if (wasMoved || wasResized)
  48604. componentMovedOrResized (wasMoved, wasResized);
  48605. }
  48606. void ComponentMovementWatcher::registerWithParentComps() throw()
  48607. {
  48608. Component* p = component->getParentComponent();
  48609. while (p != 0)
  48610. {
  48611. p->addComponentListener (this);
  48612. registeredParentComps.add (p);
  48613. p = p->getParentComponent();
  48614. }
  48615. }
  48616. void ComponentMovementWatcher::unregister() throw()
  48617. {
  48618. for (int i = registeredParentComps.size(); --i >= 0;)
  48619. static_cast <Component*> (registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48620. registeredParentComps.clear();
  48621. }
  48622. END_JUCE_NAMESPACE
  48623. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48624. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48625. BEGIN_JUCE_NAMESPACE
  48626. GroupComponent::GroupComponent (const String& componentName,
  48627. const String& labelText)
  48628. : Component (componentName),
  48629. text (labelText),
  48630. justification (Justification::left)
  48631. {
  48632. setInterceptsMouseClicks (false, true);
  48633. }
  48634. GroupComponent::~GroupComponent()
  48635. {
  48636. }
  48637. void GroupComponent::setText (const String& newText)
  48638. {
  48639. if (text != newText)
  48640. {
  48641. text = newText;
  48642. repaint();
  48643. }
  48644. }
  48645. const String GroupComponent::getText() const
  48646. {
  48647. return text;
  48648. }
  48649. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48650. {
  48651. if (justification.getFlags() != newJustification.getFlags())
  48652. {
  48653. justification = newJustification;
  48654. repaint();
  48655. }
  48656. }
  48657. void GroupComponent::paint (Graphics& g)
  48658. {
  48659. getLookAndFeel()
  48660. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48661. text, justification,
  48662. *this);
  48663. }
  48664. void GroupComponent::enablementChanged()
  48665. {
  48666. repaint();
  48667. }
  48668. void GroupComponent::colourChanged()
  48669. {
  48670. repaint();
  48671. }
  48672. END_JUCE_NAMESPACE
  48673. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48674. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48675. BEGIN_JUCE_NAMESPACE
  48676. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48677. : DocumentWindow (String::empty, backgroundColour,
  48678. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48679. {
  48680. }
  48681. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48682. {
  48683. }
  48684. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48685. {
  48686. MultiDocumentPanel* const owner = getOwner();
  48687. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48688. if (owner != 0)
  48689. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48690. }
  48691. void MultiDocumentPanelWindow::closeButtonPressed()
  48692. {
  48693. MultiDocumentPanel* const owner = getOwner();
  48694. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48695. if (owner != 0)
  48696. owner->closeDocument (getContentComponent(), true);
  48697. }
  48698. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48699. {
  48700. DocumentWindow::activeWindowStatusChanged();
  48701. updateOrder();
  48702. }
  48703. void MultiDocumentPanelWindow::broughtToFront()
  48704. {
  48705. DocumentWindow::broughtToFront();
  48706. updateOrder();
  48707. }
  48708. void MultiDocumentPanelWindow::updateOrder()
  48709. {
  48710. MultiDocumentPanel* const owner = getOwner();
  48711. if (owner != 0)
  48712. owner->updateOrder();
  48713. }
  48714. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48715. {
  48716. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48717. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48718. }
  48719. class MDITabbedComponentInternal : public TabbedComponent
  48720. {
  48721. public:
  48722. MDITabbedComponentInternal()
  48723. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48724. {
  48725. }
  48726. ~MDITabbedComponentInternal()
  48727. {
  48728. }
  48729. void currentTabChanged (int, const String&)
  48730. {
  48731. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48732. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48733. if (owner != 0)
  48734. owner->updateOrder();
  48735. }
  48736. };
  48737. MultiDocumentPanel::MultiDocumentPanel()
  48738. : mode (MaximisedWindowsWithTabs),
  48739. tabComponent (0),
  48740. backgroundColour (Colours::lightblue),
  48741. maximumNumDocuments (0),
  48742. numDocsBeforeTabsUsed (0)
  48743. {
  48744. setOpaque (true);
  48745. }
  48746. MultiDocumentPanel::~MultiDocumentPanel()
  48747. {
  48748. closeAllDocuments (false);
  48749. }
  48750. static bool shouldDeleteComp (Component* const c)
  48751. {
  48752. return c->getProperties() ["mdiDocumentDelete_"];
  48753. }
  48754. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48755. {
  48756. while (components.size() > 0)
  48757. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48758. return false;
  48759. return true;
  48760. }
  48761. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48762. {
  48763. return new MultiDocumentPanelWindow (backgroundColour);
  48764. }
  48765. void MultiDocumentPanel::addWindow (Component* component)
  48766. {
  48767. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48768. dw->setResizable (true, false);
  48769. dw->setContentComponent (component, false, true);
  48770. dw->setName (component->getName());
  48771. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48772. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48773. int x = 4;
  48774. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48775. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48776. x += 16;
  48777. dw->setTopLeftPosition (x, x);
  48778. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48779. if (pos.toString().isNotEmpty())
  48780. dw->restoreWindowStateFromString (pos.toString());
  48781. addAndMakeVisible (dw);
  48782. dw->toFront (true);
  48783. }
  48784. bool MultiDocumentPanel::addDocument (Component* const component,
  48785. const Colour& docColour,
  48786. const bool deleteWhenRemoved)
  48787. {
  48788. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48789. // with a frame-within-a-frame! Just pass in the bare content component.
  48790. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48791. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48792. return false;
  48793. components.add (component);
  48794. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48795. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48796. component->addComponentListener (this);
  48797. if (mode == FloatingWindows)
  48798. {
  48799. if (isFullscreenWhenOneDocument())
  48800. {
  48801. if (components.size() == 1)
  48802. {
  48803. addAndMakeVisible (component);
  48804. }
  48805. else
  48806. {
  48807. if (components.size() == 2)
  48808. addWindow (components.getFirst());
  48809. addWindow (component);
  48810. }
  48811. }
  48812. else
  48813. {
  48814. addWindow (component);
  48815. }
  48816. }
  48817. else
  48818. {
  48819. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48820. {
  48821. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48822. Array <Component*> temp (components);
  48823. for (int i = 0; i < temp.size(); ++i)
  48824. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48825. resized();
  48826. }
  48827. else
  48828. {
  48829. if (tabComponent != 0)
  48830. tabComponent->addTab (component->getName(), docColour, component, false);
  48831. else
  48832. addAndMakeVisible (component);
  48833. }
  48834. setActiveDocument (component);
  48835. }
  48836. resized();
  48837. activeDocumentChanged();
  48838. return true;
  48839. }
  48840. bool MultiDocumentPanel::closeDocument (Component* component,
  48841. const bool checkItsOkToCloseFirst)
  48842. {
  48843. if (components.contains (component))
  48844. {
  48845. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48846. return false;
  48847. component->removeComponentListener (this);
  48848. const bool shouldDelete = shouldDeleteComp (component);
  48849. component->getProperties().remove ("mdiDocumentDelete_");
  48850. component->getProperties().remove ("mdiDocumentBkg_");
  48851. if (mode == FloatingWindows)
  48852. {
  48853. for (int i = getNumChildComponents(); --i >= 0;)
  48854. {
  48855. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48856. if (dw != 0 && dw->getContentComponent() == component)
  48857. {
  48858. dw->setContentComponent (0, false);
  48859. delete dw;
  48860. break;
  48861. }
  48862. }
  48863. if (shouldDelete)
  48864. delete component;
  48865. components.removeValue (component);
  48866. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48867. {
  48868. for (int i = getNumChildComponents(); --i >= 0;)
  48869. {
  48870. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48871. if (dw != 0)
  48872. {
  48873. dw->setContentComponent (0, false);
  48874. delete dw;
  48875. }
  48876. }
  48877. addAndMakeVisible (components.getFirst());
  48878. }
  48879. }
  48880. else
  48881. {
  48882. jassert (components.indexOf (component) >= 0);
  48883. if (tabComponent != 0)
  48884. {
  48885. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48886. if (tabComponent->getTabContentComponent (i) == component)
  48887. tabComponent->removeTab (i);
  48888. }
  48889. else
  48890. {
  48891. removeChildComponent (component);
  48892. }
  48893. if (shouldDelete)
  48894. delete component;
  48895. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48896. deleteAndZero (tabComponent);
  48897. components.removeValue (component);
  48898. if (components.size() > 0 && tabComponent == 0)
  48899. addAndMakeVisible (components.getFirst());
  48900. }
  48901. resized();
  48902. activeDocumentChanged();
  48903. }
  48904. else
  48905. {
  48906. jassertfalse
  48907. }
  48908. return true;
  48909. }
  48910. int MultiDocumentPanel::getNumDocuments() const throw()
  48911. {
  48912. return components.size();
  48913. }
  48914. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48915. {
  48916. return components [index];
  48917. }
  48918. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48919. {
  48920. if (mode == FloatingWindows)
  48921. {
  48922. for (int i = getNumChildComponents(); --i >= 0;)
  48923. {
  48924. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48925. if (dw != 0 && dw->isActiveWindow())
  48926. return dw->getContentComponent();
  48927. }
  48928. }
  48929. return components.getLast();
  48930. }
  48931. void MultiDocumentPanel::setActiveDocument (Component* component)
  48932. {
  48933. if (mode == FloatingWindows)
  48934. {
  48935. component = getContainerComp (component);
  48936. if (component != 0)
  48937. component->toFront (true);
  48938. }
  48939. else if (tabComponent != 0)
  48940. {
  48941. jassert (components.indexOf (component) >= 0);
  48942. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48943. {
  48944. if (tabComponent->getTabContentComponent (i) == component)
  48945. {
  48946. tabComponent->setCurrentTabIndex (i);
  48947. break;
  48948. }
  48949. }
  48950. }
  48951. else
  48952. {
  48953. component->grabKeyboardFocus();
  48954. }
  48955. }
  48956. void MultiDocumentPanel::activeDocumentChanged()
  48957. {
  48958. }
  48959. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48960. {
  48961. maximumNumDocuments = newNumber;
  48962. }
  48963. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  48964. {
  48965. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  48966. }
  48967. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  48968. {
  48969. return numDocsBeforeTabsUsed != 0;
  48970. }
  48971. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  48972. {
  48973. if (mode != newLayoutMode)
  48974. {
  48975. mode = newLayoutMode;
  48976. if (mode == FloatingWindows)
  48977. {
  48978. deleteAndZero (tabComponent);
  48979. }
  48980. else
  48981. {
  48982. for (int i = getNumChildComponents(); --i >= 0;)
  48983. {
  48984. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48985. if (dw != 0)
  48986. {
  48987. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  48988. dw->setContentComponent (0, false);
  48989. delete dw;
  48990. }
  48991. }
  48992. }
  48993. resized();
  48994. const Array <Component*> tempComps (components);
  48995. components.clear();
  48996. for (int i = 0; i < tempComps.size(); ++i)
  48997. {
  48998. Component* const c = tempComps.getUnchecked(i);
  48999. addDocument (c,
  49000. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49001. shouldDeleteComp (c));
  49002. }
  49003. }
  49004. }
  49005. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49006. {
  49007. if (backgroundColour != newBackgroundColour)
  49008. {
  49009. backgroundColour = newBackgroundColour;
  49010. setOpaque (newBackgroundColour.isOpaque());
  49011. repaint();
  49012. }
  49013. }
  49014. void MultiDocumentPanel::paint (Graphics& g)
  49015. {
  49016. g.fillAll (backgroundColour);
  49017. }
  49018. void MultiDocumentPanel::resized()
  49019. {
  49020. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49021. {
  49022. for (int i = getNumChildComponents(); --i >= 0;)
  49023. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49024. }
  49025. setWantsKeyboardFocus (components.size() == 0);
  49026. }
  49027. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49028. {
  49029. if (mode == FloatingWindows)
  49030. {
  49031. for (int i = 0; i < getNumChildComponents(); ++i)
  49032. {
  49033. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49034. if (dw != 0 && dw->getContentComponent() == c)
  49035. {
  49036. c = dw;
  49037. break;
  49038. }
  49039. }
  49040. }
  49041. return c;
  49042. }
  49043. void MultiDocumentPanel::componentNameChanged (Component&)
  49044. {
  49045. if (mode == FloatingWindows)
  49046. {
  49047. for (int i = 0; i < getNumChildComponents(); ++i)
  49048. {
  49049. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49050. if (dw != 0)
  49051. dw->setName (dw->getContentComponent()->getName());
  49052. }
  49053. }
  49054. else if (tabComponent != 0)
  49055. {
  49056. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49057. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49058. }
  49059. }
  49060. void MultiDocumentPanel::updateOrder()
  49061. {
  49062. const Array <Component*> oldList (components);
  49063. if (mode == FloatingWindows)
  49064. {
  49065. components.clear();
  49066. for (int i = 0; i < getNumChildComponents(); ++i)
  49067. {
  49068. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49069. if (dw != 0)
  49070. components.add (dw->getContentComponent());
  49071. }
  49072. }
  49073. else
  49074. {
  49075. if (tabComponent != 0)
  49076. {
  49077. Component* const current = tabComponent->getCurrentContentComponent();
  49078. if (current != 0)
  49079. {
  49080. components.removeValue (current);
  49081. components.add (current);
  49082. }
  49083. }
  49084. }
  49085. if (components != oldList)
  49086. activeDocumentChanged();
  49087. }
  49088. END_JUCE_NAMESPACE
  49089. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49090. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49091. BEGIN_JUCE_NAMESPACE
  49092. ResizableBorderComponent::Zone::Zone (int zoneFlags) throw()
  49093. : zone (zoneFlags)
  49094. {
  49095. }
  49096. ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) throw() : zone (other.zone) {}
  49097. ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) throw() { zone = other.zone; return *this; }
  49098. bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const throw() { return zone == other.zone; }
  49099. bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const throw() { return zone != other.zone; }
  49100. const ResizableBorderComponent::Zone ResizableBorderComponent::Zone::fromPositionOnBorder (const Rectangle<int>& totalSize,
  49101. const BorderSize& border,
  49102. const Point<int>& position)
  49103. {
  49104. int z = 0;
  49105. if (totalSize.contains (position)
  49106. && ! border.subtractedFrom (totalSize).contains (position))
  49107. {
  49108. const int minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
  49109. if (position.getX() < jmax (border.getLeft(), minW))
  49110. z |= left;
  49111. else if (position.getX() >= totalSize.getWidth() - jmax (border.getRight(), minW))
  49112. z |= right;
  49113. const int minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
  49114. if (position.getY() < jmax (border.getTop(), minH))
  49115. z |= top;
  49116. else if (position.getY() >= totalSize.getHeight() - jmax (border.getBottom(), minH))
  49117. z |= bottom;
  49118. }
  49119. return Zone (z);
  49120. }
  49121. const MouseCursor ResizableBorderComponent::Zone::getMouseCursor() const throw()
  49122. {
  49123. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49124. switch (zone)
  49125. {
  49126. case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49127. case top: mc = MouseCursor::TopEdgeResizeCursor; break;
  49128. case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49129. case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49130. case right: mc = MouseCursor::RightEdgeResizeCursor; break;
  49131. case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49132. case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49133. case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49134. default: break;
  49135. }
  49136. return mc;
  49137. }
  49138. const Rectangle<int> ResizableBorderComponent::Zone::resizeRectangleBy (Rectangle<int> b, const Point<int>& offset) const throw()
  49139. {
  49140. if (isDraggingWholeObject())
  49141. return b + offset;
  49142. if (isDraggingLeftEdge())
  49143. b.setLeft (b.getX() + offset.getX());
  49144. if (isDraggingRightEdge())
  49145. b.setWidth (jmax (0, b.getWidth() + offset.getX()));
  49146. if (isDraggingTopEdge())
  49147. b.setTop (b.getY() + offset.getY());
  49148. if (isDraggingBottomEdge())
  49149. b.setHeight (jmax (0, b.getHeight() + offset.getY()));
  49150. return b;
  49151. }
  49152. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49153. ComponentBoundsConstrainer* const constrainer_)
  49154. : component (componentToResize),
  49155. constrainer (constrainer_),
  49156. borderSize (5),
  49157. mouseZone (0)
  49158. {
  49159. }
  49160. ResizableBorderComponent::~ResizableBorderComponent()
  49161. {
  49162. }
  49163. void ResizableBorderComponent::paint (Graphics& g)
  49164. {
  49165. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49166. }
  49167. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49168. {
  49169. updateMouseZone (e);
  49170. }
  49171. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49172. {
  49173. updateMouseZone (e);
  49174. }
  49175. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49176. {
  49177. if (component == 0)
  49178. {
  49179. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49180. return;
  49181. }
  49182. updateMouseZone (e);
  49183. originalBounds = component->getBounds();
  49184. if (constrainer != 0)
  49185. constrainer->resizeStart();
  49186. }
  49187. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49188. {
  49189. if (component == 0)
  49190. {
  49191. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49192. return;
  49193. }
  49194. const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart()));
  49195. if (constrainer != 0)
  49196. constrainer->setBoundsForComponent (component, bounds,
  49197. mouseZone.isDraggingTopEdge(),
  49198. mouseZone.isDraggingLeftEdge(),
  49199. mouseZone.isDraggingBottomEdge(),
  49200. mouseZone.isDraggingRightEdge());
  49201. else
  49202. component->setBounds (bounds);
  49203. }
  49204. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49205. {
  49206. if (constrainer != 0)
  49207. constrainer->resizeEnd();
  49208. }
  49209. bool ResizableBorderComponent::hitTest (int x, int y)
  49210. {
  49211. return x < borderSize.getLeft()
  49212. || x >= getWidth() - borderSize.getRight()
  49213. || y < borderSize.getTop()
  49214. || y >= getHeight() - borderSize.getBottom();
  49215. }
  49216. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49217. {
  49218. if (borderSize != newBorderSize)
  49219. {
  49220. borderSize = newBorderSize;
  49221. repaint();
  49222. }
  49223. }
  49224. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49225. {
  49226. return borderSize;
  49227. }
  49228. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49229. {
  49230. Zone newZone (Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition()));
  49231. if (mouseZone != newZone)
  49232. {
  49233. mouseZone = newZone;
  49234. setMouseCursor (newZone.getMouseCursor());
  49235. }
  49236. }
  49237. END_JUCE_NAMESPACE
  49238. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49239. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49240. BEGIN_JUCE_NAMESPACE
  49241. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49242. ComponentBoundsConstrainer* const constrainer_)
  49243. : component (componentToResize),
  49244. constrainer (constrainer_)
  49245. {
  49246. setRepaintsOnMouseActivity (true);
  49247. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49248. }
  49249. ResizableCornerComponent::~ResizableCornerComponent()
  49250. {
  49251. }
  49252. void ResizableCornerComponent::paint (Graphics& g)
  49253. {
  49254. getLookAndFeel()
  49255. .drawCornerResizer (g, getWidth(), getHeight(),
  49256. isMouseOverOrDragging(),
  49257. isMouseButtonDown());
  49258. }
  49259. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49260. {
  49261. if (component == 0)
  49262. {
  49263. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49264. return;
  49265. }
  49266. originalBounds = component->getBounds();
  49267. if (constrainer != 0)
  49268. constrainer->resizeStart();
  49269. }
  49270. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49271. {
  49272. if (component == 0)
  49273. {
  49274. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49275. return;
  49276. }
  49277. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49278. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49279. if (constrainer != 0)
  49280. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49281. else
  49282. component->setBounds (r);
  49283. }
  49284. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49285. {
  49286. if (constrainer != 0)
  49287. constrainer->resizeStart();
  49288. }
  49289. bool ResizableCornerComponent::hitTest (int x, int y)
  49290. {
  49291. if (getWidth() <= 0)
  49292. return false;
  49293. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49294. return y >= yAtX - getHeight() / 4;
  49295. }
  49296. END_JUCE_NAMESPACE
  49297. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49298. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49299. BEGIN_JUCE_NAMESPACE
  49300. class ScrollBar::ScrollbarButton : public Button
  49301. {
  49302. public:
  49303. int direction;
  49304. ScrollbarButton (const int direction_, ScrollBar& owner_)
  49305. : Button (String::empty),
  49306. direction (direction_),
  49307. owner (owner_)
  49308. {
  49309. setWantsKeyboardFocus (false);
  49310. }
  49311. ~ScrollbarButton()
  49312. {
  49313. }
  49314. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  49315. {
  49316. getLookAndFeel()
  49317. .drawScrollbarButton (g, owner,
  49318. getWidth(), getHeight(),
  49319. direction,
  49320. owner.isVertical(),
  49321. isMouseOver, isMouseDown);
  49322. }
  49323. void clicked()
  49324. {
  49325. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49326. }
  49327. juce_UseDebuggingNewOperator
  49328. private:
  49329. ScrollBar& owner;
  49330. ScrollbarButton (const ScrollbarButton&);
  49331. ScrollbarButton& operator= (const ScrollbarButton&);
  49332. };
  49333. ScrollBar::ScrollBar (const bool vertical_,
  49334. const bool buttonsAreVisible)
  49335. : totalRange (0.0, 1.0),
  49336. visibleRange (0.0, 0.1),
  49337. singleStepSize (0.1),
  49338. thumbAreaStart (0),
  49339. thumbAreaSize (0),
  49340. thumbStart (0),
  49341. thumbSize (0),
  49342. initialDelayInMillisecs (100),
  49343. repeatDelayInMillisecs (50),
  49344. minimumDelayInMillisecs (10),
  49345. vertical (vertical_),
  49346. isDraggingThumb (false),
  49347. alwaysVisible (false),
  49348. upButton (0),
  49349. downButton (0)
  49350. {
  49351. setButtonVisibility (buttonsAreVisible);
  49352. setRepaintsOnMouseActivity (true);
  49353. setFocusContainer (true);
  49354. }
  49355. ScrollBar::~ScrollBar()
  49356. {
  49357. deleteAllChildren();
  49358. }
  49359. void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit)
  49360. {
  49361. if (totalRange != newRangeLimit)
  49362. {
  49363. totalRange = newRangeLimit;
  49364. setCurrentRange (visibleRange);
  49365. updateThumbPosition();
  49366. }
  49367. }
  49368. void ScrollBar::setRangeLimits (const double newMinimum, const double newMaximum)
  49369. {
  49370. jassert (newMaximum >= newMinimum); // these can't be the wrong way round!
  49371. setRangeLimits (Range<double> (newMinimum, newMaximum));
  49372. }
  49373. void ScrollBar::setCurrentRange (const Range<double>& newRange)
  49374. {
  49375. const Range<double> constrainedRange (totalRange.constrainRange (newRange));
  49376. if (visibleRange != constrainedRange)
  49377. {
  49378. visibleRange = constrainedRange;
  49379. updateThumbPosition();
  49380. triggerAsyncUpdate();
  49381. }
  49382. }
  49383. void ScrollBar::setCurrentRange (const double newStart, const double newSize)
  49384. {
  49385. setCurrentRange (Range<double> (newStart, newStart + newSize));
  49386. }
  49387. void ScrollBar::setCurrentRangeStart (const double newStart)
  49388. {
  49389. setCurrentRange (visibleRange.movedToStartAt (newStart));
  49390. }
  49391. void ScrollBar::setSingleStepSize (const double newSingleStepSize)
  49392. {
  49393. singleStepSize = newSingleStepSize;
  49394. }
  49395. void ScrollBar::moveScrollbarInSteps (const int howManySteps)
  49396. {
  49397. setCurrentRange (visibleRange + howManySteps * singleStepSize);
  49398. }
  49399. void ScrollBar::moveScrollbarInPages (const int howManyPages)
  49400. {
  49401. setCurrentRange (visibleRange + howManyPages * visibleRange.getLength());
  49402. }
  49403. void ScrollBar::scrollToTop()
  49404. {
  49405. setCurrentRange (visibleRange.movedToStartAt (getMinimumRangeLimit()));
  49406. }
  49407. void ScrollBar::scrollToBottom()
  49408. {
  49409. setCurrentRange (visibleRange.movedToEndAt (getMaximumRangeLimit()));
  49410. }
  49411. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49412. const int repeatDelayInMillisecs_,
  49413. const int minimumDelayInMillisecs_)
  49414. {
  49415. initialDelayInMillisecs = initialDelayInMillisecs_;
  49416. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49417. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49418. if (upButton != 0)
  49419. {
  49420. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49421. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49422. }
  49423. }
  49424. void ScrollBar::addListener (ScrollBarListener* const listener)
  49425. {
  49426. listeners.add (listener);
  49427. }
  49428. void ScrollBar::removeListener (ScrollBarListener* const listener)
  49429. {
  49430. listeners.remove (listener);
  49431. }
  49432. void ScrollBar::handleAsyncUpdate()
  49433. {
  49434. double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
  49435. listeners.call (&ScrollBarListener::scrollBarMoved, this, start);
  49436. }
  49437. void ScrollBar::updateThumbPosition()
  49438. {
  49439. int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
  49440. : thumbAreaSize);
  49441. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49442. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49443. if (newThumbSize > thumbAreaSize)
  49444. newThumbSize = thumbAreaSize;
  49445. int newThumbStart = thumbAreaStart;
  49446. if (totalRange.getLength() > visibleRange.getLength())
  49447. newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
  49448. / (totalRange.getLength() - visibleRange.getLength()));
  49449. setVisible (alwaysVisible || (totalRange.getLength() > visibleRange.getLength() && visibleRange.getLength() > 0.0));
  49450. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49451. {
  49452. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49453. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49454. if (vertical)
  49455. repaint (0, repaintStart, getWidth(), repaintSize);
  49456. else
  49457. repaint (repaintStart, 0, repaintSize, getHeight());
  49458. thumbStart = newThumbStart;
  49459. thumbSize = newThumbSize;
  49460. }
  49461. }
  49462. void ScrollBar::setOrientation (const bool shouldBeVertical)
  49463. {
  49464. if (vertical != shouldBeVertical)
  49465. {
  49466. vertical = shouldBeVertical;
  49467. if (upButton != 0)
  49468. {
  49469. upButton->direction = vertical ? 0 : 3;
  49470. downButton->direction = vertical ? 2 : 1;
  49471. }
  49472. updateThumbPosition();
  49473. }
  49474. }
  49475. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49476. {
  49477. delete upButton;
  49478. upButton = 0;
  49479. delete downButton;
  49480. downButton = 0;
  49481. if (buttonsAreVisible)
  49482. {
  49483. addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
  49484. addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
  49485. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49486. }
  49487. updateThumbPosition();
  49488. }
  49489. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49490. {
  49491. alwaysVisible = ! shouldHideWhenFullRange;
  49492. updateThumbPosition();
  49493. }
  49494. void ScrollBar::paint (Graphics& g)
  49495. {
  49496. if (thumbAreaSize > 0)
  49497. {
  49498. LookAndFeel& lf = getLookAndFeel();
  49499. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49500. ? thumbSize : 0;
  49501. if (vertical)
  49502. {
  49503. lf.drawScrollbar (g, *this,
  49504. 0, thumbAreaStart,
  49505. getWidth(), thumbAreaSize,
  49506. vertical,
  49507. thumbStart, thumb,
  49508. isMouseOver(), isMouseButtonDown());
  49509. }
  49510. else
  49511. {
  49512. lf.drawScrollbar (g, *this,
  49513. thumbAreaStart, 0,
  49514. thumbAreaSize, getHeight(),
  49515. vertical,
  49516. thumbStart, thumb,
  49517. isMouseOver(), isMouseButtonDown());
  49518. }
  49519. }
  49520. }
  49521. void ScrollBar::lookAndFeelChanged()
  49522. {
  49523. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49524. }
  49525. void ScrollBar::resized()
  49526. {
  49527. const int length = ((vertical) ? getHeight() : getWidth());
  49528. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49529. : 0;
  49530. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49531. {
  49532. thumbAreaStart = length >> 1;
  49533. thumbAreaSize = 0;
  49534. }
  49535. else
  49536. {
  49537. thumbAreaStart = buttonSize;
  49538. thumbAreaSize = length - (buttonSize << 1);
  49539. }
  49540. if (upButton != 0)
  49541. {
  49542. if (vertical)
  49543. {
  49544. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49545. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49546. }
  49547. else
  49548. {
  49549. upButton->setBounds (0, 0, buttonSize, getHeight());
  49550. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49551. }
  49552. }
  49553. updateThumbPosition();
  49554. }
  49555. void ScrollBar::mouseDown (const MouseEvent& e)
  49556. {
  49557. isDraggingThumb = false;
  49558. lastMousePos = vertical ? e.y : e.x;
  49559. dragStartMousePos = lastMousePos;
  49560. dragStartRange = visibleRange.getStart();
  49561. if (dragStartMousePos < thumbStart)
  49562. {
  49563. moveScrollbarInPages (-1);
  49564. startTimer (400);
  49565. }
  49566. else if (dragStartMousePos >= thumbStart + thumbSize)
  49567. {
  49568. moveScrollbarInPages (1);
  49569. startTimer (400);
  49570. }
  49571. else
  49572. {
  49573. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49574. && (thumbAreaSize > thumbSize);
  49575. }
  49576. }
  49577. void ScrollBar::mouseDrag (const MouseEvent& e)
  49578. {
  49579. if (isDraggingThumb)
  49580. {
  49581. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49582. setCurrentRangeStart (dragStartRange
  49583. + deltaPixels * (totalRange.getLength() - visibleRange.getLength())
  49584. / (thumbAreaSize - thumbSize));
  49585. }
  49586. else
  49587. {
  49588. lastMousePos = (vertical) ? e.y : e.x;
  49589. }
  49590. }
  49591. void ScrollBar::mouseUp (const MouseEvent&)
  49592. {
  49593. isDraggingThumb = false;
  49594. stopTimer();
  49595. repaint();
  49596. }
  49597. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49598. float wheelIncrementX,
  49599. float wheelIncrementY)
  49600. {
  49601. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49602. if (increment < 0)
  49603. increment = jmin (increment * 10.0f, -1.0f);
  49604. else if (increment > 0)
  49605. increment = jmax (increment * 10.0f, 1.0f);
  49606. setCurrentRange (visibleRange - singleStepSize * increment);
  49607. }
  49608. void ScrollBar::timerCallback()
  49609. {
  49610. if (isMouseButtonDown())
  49611. {
  49612. startTimer (40);
  49613. if (lastMousePos < thumbStart)
  49614. setCurrentRange (visibleRange - visibleRange.getLength());
  49615. else if (lastMousePos > thumbStart + thumbSize)
  49616. setCurrentRangeStart (visibleRange.getEnd());
  49617. }
  49618. else
  49619. {
  49620. stopTimer();
  49621. }
  49622. }
  49623. bool ScrollBar::keyPressed (const KeyPress& key)
  49624. {
  49625. if (! isVisible())
  49626. return false;
  49627. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49628. moveScrollbarInSteps (-1);
  49629. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49630. moveScrollbarInSteps (1);
  49631. else if (key.isKeyCode (KeyPress::pageUpKey))
  49632. moveScrollbarInPages (-1);
  49633. else if (key.isKeyCode (KeyPress::pageDownKey))
  49634. moveScrollbarInPages (1);
  49635. else if (key.isKeyCode (KeyPress::homeKey))
  49636. scrollToTop();
  49637. else if (key.isKeyCode (KeyPress::endKey))
  49638. scrollToBottom();
  49639. else
  49640. return false;
  49641. return true;
  49642. }
  49643. END_JUCE_NAMESPACE
  49644. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49645. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49646. BEGIN_JUCE_NAMESPACE
  49647. StretchableLayoutManager::StretchableLayoutManager()
  49648. : totalSize (0)
  49649. {
  49650. }
  49651. StretchableLayoutManager::~StretchableLayoutManager()
  49652. {
  49653. }
  49654. void StretchableLayoutManager::clearAllItems()
  49655. {
  49656. items.clear();
  49657. totalSize = 0;
  49658. }
  49659. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49660. const double minimumSize,
  49661. const double maximumSize,
  49662. const double preferredSize)
  49663. {
  49664. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49665. if (layout == 0)
  49666. {
  49667. layout = new ItemLayoutProperties();
  49668. layout->itemIndex = itemIndex;
  49669. int i;
  49670. for (i = 0; i < items.size(); ++i)
  49671. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49672. break;
  49673. items.insert (i, layout);
  49674. }
  49675. layout->minSize = minimumSize;
  49676. layout->maxSize = maximumSize;
  49677. layout->preferredSize = preferredSize;
  49678. layout->currentSize = 0;
  49679. }
  49680. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49681. double& minimumSize,
  49682. double& maximumSize,
  49683. double& preferredSize) const
  49684. {
  49685. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49686. if (layout != 0)
  49687. {
  49688. minimumSize = layout->minSize;
  49689. maximumSize = layout->maxSize;
  49690. preferredSize = layout->preferredSize;
  49691. return true;
  49692. }
  49693. return false;
  49694. }
  49695. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49696. {
  49697. totalSize = newTotalSize;
  49698. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49699. }
  49700. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49701. {
  49702. int pos = 0;
  49703. for (int i = 0; i < itemIndex; ++i)
  49704. {
  49705. const ItemLayoutProperties* const layout = getInfoFor (i);
  49706. if (layout != 0)
  49707. pos += layout->currentSize;
  49708. }
  49709. return pos;
  49710. }
  49711. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49712. {
  49713. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49714. if (layout != 0)
  49715. return layout->currentSize;
  49716. return 0;
  49717. }
  49718. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49719. {
  49720. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49721. if (layout != 0)
  49722. return -layout->currentSize / (double) totalSize;
  49723. return 0;
  49724. }
  49725. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49726. int newPosition)
  49727. {
  49728. for (int i = items.size(); --i >= 0;)
  49729. {
  49730. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49731. if (layout->itemIndex == itemIndex)
  49732. {
  49733. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49734. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49735. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49736. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49737. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49738. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49739. endPos += layout->currentSize;
  49740. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49741. updatePrefSizesToMatchCurrentPositions();
  49742. break;
  49743. }
  49744. }
  49745. }
  49746. void StretchableLayoutManager::layOutComponents (Component** const components,
  49747. int numComponents,
  49748. int x, int y, int w, int h,
  49749. const bool vertically,
  49750. const bool resizeOtherDimension)
  49751. {
  49752. setTotalSize (vertically ? h : w);
  49753. int pos = vertically ? y : x;
  49754. for (int i = 0; i < numComponents; ++i)
  49755. {
  49756. const ItemLayoutProperties* const layout = getInfoFor (i);
  49757. if (layout != 0)
  49758. {
  49759. Component* const c = components[i];
  49760. if (c != 0)
  49761. {
  49762. if (i == numComponents - 1)
  49763. {
  49764. // if it's the last item, crop it to exactly fit the available space..
  49765. if (resizeOtherDimension)
  49766. {
  49767. if (vertically)
  49768. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49769. else
  49770. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49771. }
  49772. else
  49773. {
  49774. if (vertically)
  49775. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49776. else
  49777. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49778. }
  49779. }
  49780. else
  49781. {
  49782. if (resizeOtherDimension)
  49783. {
  49784. if (vertically)
  49785. c->setBounds (x, pos, w, layout->currentSize);
  49786. else
  49787. c->setBounds (pos, y, layout->currentSize, h);
  49788. }
  49789. else
  49790. {
  49791. if (vertically)
  49792. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49793. else
  49794. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49795. }
  49796. }
  49797. }
  49798. pos += layout->currentSize;
  49799. }
  49800. }
  49801. }
  49802. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49803. {
  49804. for (int i = items.size(); --i >= 0;)
  49805. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49806. return items.getUnchecked(i);
  49807. return 0;
  49808. }
  49809. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49810. const int endIndex,
  49811. const int availableSpace,
  49812. int startPos)
  49813. {
  49814. // calculate the total sizes
  49815. int i;
  49816. double totalIdealSize = 0.0;
  49817. int totalMinimums = 0;
  49818. for (i = startIndex; i < endIndex; ++i)
  49819. {
  49820. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49821. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49822. totalMinimums += layout->currentSize;
  49823. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49824. }
  49825. if (totalIdealSize <= 0)
  49826. totalIdealSize = 1.0;
  49827. // now calc the best sizes..
  49828. int extraSpace = availableSpace - totalMinimums;
  49829. while (extraSpace > 0)
  49830. {
  49831. int numWantingMoreSpace = 0;
  49832. int numHavingTakenExtraSpace = 0;
  49833. // first figure out how many comps want a slice of the extra space..
  49834. for (i = startIndex; i < endIndex; ++i)
  49835. {
  49836. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49837. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49838. const int bestSize = jlimit (layout->currentSize,
  49839. jmax (layout->currentSize,
  49840. sizeToRealSize (layout->maxSize, totalSize)),
  49841. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49842. if (bestSize > layout->currentSize)
  49843. ++numWantingMoreSpace;
  49844. }
  49845. // ..share out the extra space..
  49846. for (i = startIndex; i < endIndex; ++i)
  49847. {
  49848. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49849. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49850. int bestSize = jlimit (layout->currentSize,
  49851. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49852. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49853. const int extraWanted = bestSize - layout->currentSize;
  49854. if (extraWanted > 0)
  49855. {
  49856. const int extraAllowed = jmin (extraWanted,
  49857. extraSpace / jmax (1, numWantingMoreSpace));
  49858. if (extraAllowed > 0)
  49859. {
  49860. ++numHavingTakenExtraSpace;
  49861. --numWantingMoreSpace;
  49862. layout->currentSize += extraAllowed;
  49863. extraSpace -= extraAllowed;
  49864. }
  49865. }
  49866. }
  49867. if (numHavingTakenExtraSpace <= 0)
  49868. break;
  49869. }
  49870. // ..and calculate the end position
  49871. for (i = startIndex; i < endIndex; ++i)
  49872. {
  49873. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49874. startPos += layout->currentSize;
  49875. }
  49876. return startPos;
  49877. }
  49878. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49879. const int endIndex) const
  49880. {
  49881. int totalMinimums = 0;
  49882. for (int i = startIndex; i < endIndex; ++i)
  49883. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49884. return totalMinimums;
  49885. }
  49886. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49887. {
  49888. int totalMaximums = 0;
  49889. for (int i = startIndex; i < endIndex; ++i)
  49890. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49891. return totalMaximums;
  49892. }
  49893. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49894. {
  49895. for (int i = 0; i < items.size(); ++i)
  49896. {
  49897. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49898. layout->preferredSize
  49899. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49900. : getItemCurrentAbsoluteSize (i);
  49901. }
  49902. }
  49903. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49904. {
  49905. if (size < 0)
  49906. size *= -totalSpace;
  49907. return roundToInt (size);
  49908. }
  49909. END_JUCE_NAMESPACE
  49910. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49911. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49912. BEGIN_JUCE_NAMESPACE
  49913. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49914. const int itemIndex_,
  49915. const bool isVertical_)
  49916. : layout (layout_),
  49917. itemIndex (itemIndex_),
  49918. isVertical (isVertical_)
  49919. {
  49920. setRepaintsOnMouseActivity (true);
  49921. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49922. : MouseCursor::UpDownResizeCursor));
  49923. }
  49924. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49925. {
  49926. }
  49927. void StretchableLayoutResizerBar::paint (Graphics& g)
  49928. {
  49929. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49930. getWidth(), getHeight(),
  49931. isVertical,
  49932. isMouseOver(),
  49933. isMouseButtonDown());
  49934. }
  49935. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49936. {
  49937. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49938. }
  49939. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49940. {
  49941. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49942. : e.getDistanceFromDragStartY());
  49943. layout->setItemPosition (itemIndex, desiredPos);
  49944. hasBeenMoved();
  49945. }
  49946. void StretchableLayoutResizerBar::hasBeenMoved()
  49947. {
  49948. if (getParentComponent() != 0)
  49949. getParentComponent()->resized();
  49950. }
  49951. END_JUCE_NAMESPACE
  49952. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49953. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49954. BEGIN_JUCE_NAMESPACE
  49955. StretchableObjectResizer::StretchableObjectResizer()
  49956. {
  49957. }
  49958. StretchableObjectResizer::~StretchableObjectResizer()
  49959. {
  49960. }
  49961. void StretchableObjectResizer::addItem (const double size,
  49962. const double minSize, const double maxSize,
  49963. const int order)
  49964. {
  49965. // the order must be >= 0 but less than the maximum integer value.
  49966. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49967. Item* const item = new Item();
  49968. item->size = size;
  49969. item->minSize = minSize;
  49970. item->maxSize = maxSize;
  49971. item->order = order;
  49972. items.add (item);
  49973. }
  49974. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49975. {
  49976. const Item* const it = items [index];
  49977. return it != 0 ? it->size : 0;
  49978. }
  49979. void StretchableObjectResizer::resizeToFit (const double targetSize)
  49980. {
  49981. int order = 0;
  49982. for (;;)
  49983. {
  49984. double currentSize = 0;
  49985. double minSize = 0;
  49986. double maxSize = 0;
  49987. int nextHighestOrder = std::numeric_limits<int>::max();
  49988. for (int i = 0; i < items.size(); ++i)
  49989. {
  49990. const Item* const it = items.getUnchecked(i);
  49991. currentSize += it->size;
  49992. if (it->order <= order)
  49993. {
  49994. minSize += it->minSize;
  49995. maxSize += it->maxSize;
  49996. }
  49997. else
  49998. {
  49999. minSize += it->size;
  50000. maxSize += it->size;
  50001. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50002. }
  50003. }
  50004. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50005. if (thisIterationTarget >= currentSize)
  50006. {
  50007. const double availableExtraSpace = maxSize - currentSize;
  50008. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50009. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50010. for (int i = 0; i < items.size(); ++i)
  50011. {
  50012. Item* const it = items.getUnchecked(i);
  50013. if (it->order <= order)
  50014. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50015. }
  50016. }
  50017. else
  50018. {
  50019. const double amountOfSlack = currentSize - minSize;
  50020. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50021. const double scale = targetAmountOfSlack / amountOfSlack;
  50022. for (int i = 0; i < items.size(); ++i)
  50023. {
  50024. Item* const it = items.getUnchecked(i);
  50025. if (it->order <= order)
  50026. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50027. }
  50028. }
  50029. if (nextHighestOrder < std::numeric_limits<int>::max())
  50030. order = nextHighestOrder;
  50031. else
  50032. break;
  50033. }
  50034. }
  50035. END_JUCE_NAMESPACE
  50036. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50037. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50038. BEGIN_JUCE_NAMESPACE
  50039. TabBarButton::TabBarButton (const String& name,
  50040. TabbedButtonBar* const owner_,
  50041. const int index)
  50042. : Button (name),
  50043. owner (owner_),
  50044. tabIndex (index),
  50045. overlapPixels (0)
  50046. {
  50047. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50048. setComponentEffect (&shadow);
  50049. setWantsKeyboardFocus (false);
  50050. }
  50051. TabBarButton::~TabBarButton()
  50052. {
  50053. }
  50054. void TabBarButton::paintButton (Graphics& g,
  50055. bool isMouseOverButton,
  50056. bool isButtonDown)
  50057. {
  50058. int x, y, w, h;
  50059. getActiveArea (x, y, w, h);
  50060. g.setOrigin (x, y);
  50061. getLookAndFeel()
  50062. .drawTabButton (g, w, h,
  50063. owner->getTabBackgroundColour (tabIndex),
  50064. tabIndex, getButtonText(), *this,
  50065. owner->getOrientation(),
  50066. isMouseOverButton, isButtonDown,
  50067. getToggleState());
  50068. }
  50069. void TabBarButton::clicked (const ModifierKeys& mods)
  50070. {
  50071. if (mods.isPopupMenu())
  50072. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50073. else
  50074. owner->setCurrentTabIndex (tabIndex);
  50075. }
  50076. bool TabBarButton::hitTest (int mx, int my)
  50077. {
  50078. int x, y, w, h;
  50079. getActiveArea (x, y, w, h);
  50080. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50081. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50082. {
  50083. if (((unsigned int) mx) < (unsigned int) getWidth()
  50084. && my >= y + overlapPixels
  50085. && my < y + h - overlapPixels)
  50086. return true;
  50087. }
  50088. else
  50089. {
  50090. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50091. && ((unsigned int) my) < (unsigned int) getHeight())
  50092. return true;
  50093. }
  50094. Path p;
  50095. getLookAndFeel()
  50096. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50097. owner->getOrientation(),
  50098. false, false, getToggleState());
  50099. return p.contains ((float) (mx - x),
  50100. (float) (my - y));
  50101. }
  50102. int TabBarButton::getBestTabLength (const int depth)
  50103. {
  50104. return jlimit (depth * 2,
  50105. depth * 7,
  50106. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50107. }
  50108. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50109. {
  50110. x = 0;
  50111. y = 0;
  50112. int r = getWidth();
  50113. int b = getHeight();
  50114. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50115. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50116. r -= spaceAroundImage;
  50117. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50118. x += spaceAroundImage;
  50119. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50120. y += spaceAroundImage;
  50121. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50122. b -= spaceAroundImage;
  50123. w = r - x;
  50124. h = b - y;
  50125. }
  50126. class TabAreaBehindFrontButtonComponent : public Component
  50127. {
  50128. public:
  50129. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50130. : owner (owner_)
  50131. {
  50132. setInterceptsMouseClicks (false, false);
  50133. }
  50134. ~TabAreaBehindFrontButtonComponent()
  50135. {
  50136. }
  50137. void paint (Graphics& g)
  50138. {
  50139. getLookAndFeel()
  50140. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50141. *owner, owner->getOrientation());
  50142. }
  50143. void enablementChanged()
  50144. {
  50145. repaint();
  50146. }
  50147. private:
  50148. TabbedButtonBar* const owner;
  50149. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50150. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50151. };
  50152. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50153. : orientation (orientation_),
  50154. currentTabIndex (-1),
  50155. extraTabsButton (0)
  50156. {
  50157. setInterceptsMouseClicks (false, true);
  50158. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50159. setFocusContainer (true);
  50160. }
  50161. TabbedButtonBar::~TabbedButtonBar()
  50162. {
  50163. deleteAllChildren();
  50164. }
  50165. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50166. {
  50167. orientation = newOrientation;
  50168. for (int i = getNumChildComponents(); --i >= 0;)
  50169. getChildComponent (i)->resized();
  50170. resized();
  50171. }
  50172. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50173. {
  50174. return new TabBarButton (name, this, index);
  50175. }
  50176. void TabbedButtonBar::clearTabs()
  50177. {
  50178. tabs.clear();
  50179. tabColours.clear();
  50180. currentTabIndex = -1;
  50181. deleteAndZero (extraTabsButton);
  50182. removeChildComponent (behindFrontTab);
  50183. deleteAllChildren();
  50184. addChildComponent (behindFrontTab);
  50185. setCurrentTabIndex (-1);
  50186. }
  50187. void TabbedButtonBar::addTab (const String& tabName,
  50188. const Colour& tabBackgroundColour,
  50189. int insertIndex)
  50190. {
  50191. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50192. if (tabName.isNotEmpty())
  50193. {
  50194. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50195. insertIndex = tabs.size();
  50196. for (int i = tabs.size(); --i >= insertIndex;)
  50197. {
  50198. TabBarButton* const tb = getTabButton (i);
  50199. if (tb != 0)
  50200. tb->tabIndex++;
  50201. }
  50202. tabs.insert (insertIndex, tabName);
  50203. tabColours.insert (insertIndex, tabBackgroundColour);
  50204. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50205. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50206. addAndMakeVisible (tb, insertIndex);
  50207. resized();
  50208. if (currentTabIndex < 0)
  50209. setCurrentTabIndex (0);
  50210. }
  50211. }
  50212. void TabbedButtonBar::setTabName (const int tabIndex,
  50213. const String& newName)
  50214. {
  50215. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50216. && tabs[tabIndex] != newName)
  50217. {
  50218. tabs.set (tabIndex, newName);
  50219. TabBarButton* const tb = getTabButton (tabIndex);
  50220. if (tb != 0)
  50221. tb->setButtonText (newName);
  50222. resized();
  50223. }
  50224. }
  50225. void TabbedButtonBar::removeTab (const int tabIndex)
  50226. {
  50227. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50228. {
  50229. const int oldTabIndex = currentTabIndex;
  50230. if (currentTabIndex == tabIndex)
  50231. currentTabIndex = -1;
  50232. tabs.remove (tabIndex);
  50233. tabColours.remove (tabIndex);
  50234. delete getTabButton (tabIndex);
  50235. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50236. {
  50237. TabBarButton* const tb = getTabButton (i);
  50238. if (tb != 0)
  50239. tb->tabIndex--;
  50240. }
  50241. resized();
  50242. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50243. }
  50244. }
  50245. void TabbedButtonBar::moveTab (const int currentIndex,
  50246. const int newIndex)
  50247. {
  50248. tabs.move (currentIndex, newIndex);
  50249. tabColours.move (currentIndex, newIndex);
  50250. resized();
  50251. }
  50252. int TabbedButtonBar::getNumTabs() const
  50253. {
  50254. return tabs.size();
  50255. }
  50256. const StringArray TabbedButtonBar::getTabNames() const
  50257. {
  50258. return tabs;
  50259. }
  50260. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50261. {
  50262. if (currentTabIndex != newIndex)
  50263. {
  50264. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50265. newIndex = -1;
  50266. currentTabIndex = newIndex;
  50267. for (int i = 0; i < getNumChildComponents(); ++i)
  50268. {
  50269. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50270. if (tb != 0)
  50271. tb->setToggleState (tb->tabIndex == newIndex, false);
  50272. }
  50273. resized();
  50274. if (sendChangeMessage_)
  50275. sendChangeMessage (this);
  50276. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50277. }
  50278. }
  50279. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50280. {
  50281. for (int i = getNumChildComponents(); --i >= 0;)
  50282. {
  50283. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50284. if (tb != 0 && tb->tabIndex == index)
  50285. return tb;
  50286. }
  50287. return 0;
  50288. }
  50289. void TabbedButtonBar::lookAndFeelChanged()
  50290. {
  50291. deleteAndZero (extraTabsButton);
  50292. resized();
  50293. }
  50294. void TabbedButtonBar::resized()
  50295. {
  50296. const double minimumScale = 0.7;
  50297. int depth = getWidth();
  50298. int length = getHeight();
  50299. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50300. swapVariables (depth, length);
  50301. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50302. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50303. int i, totalLength = overlap;
  50304. int numVisibleButtons = tabs.size();
  50305. for (i = 0; i < getNumChildComponents(); ++i)
  50306. {
  50307. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50308. if (tb != 0)
  50309. {
  50310. totalLength += tb->getBestTabLength (depth) - overlap;
  50311. tb->overlapPixels = overlap / 2;
  50312. }
  50313. }
  50314. double scale = 1.0;
  50315. if (totalLength > length)
  50316. scale = jmax (minimumScale, length / (double) totalLength);
  50317. const bool isTooBig = totalLength * scale > length;
  50318. int tabsButtonPos = 0;
  50319. if (isTooBig)
  50320. {
  50321. if (extraTabsButton == 0)
  50322. {
  50323. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50324. extraTabsButton->addButtonListener (this);
  50325. extraTabsButton->setAlwaysOnTop (true);
  50326. extraTabsButton->setTriggeredOnMouseDown (true);
  50327. }
  50328. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50329. extraTabsButton->setSize (buttonSize, buttonSize);
  50330. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50331. {
  50332. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50333. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50334. }
  50335. else
  50336. {
  50337. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50338. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50339. }
  50340. totalLength = 0;
  50341. for (i = 0; i < tabs.size(); ++i)
  50342. {
  50343. TabBarButton* const tb = getTabButton (i);
  50344. if (tb != 0)
  50345. {
  50346. const int newLength = totalLength + tb->getBestTabLength (depth);
  50347. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50348. {
  50349. totalLength += overlap;
  50350. break;
  50351. }
  50352. numVisibleButtons = i + 1;
  50353. totalLength = newLength - overlap;
  50354. }
  50355. }
  50356. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50357. }
  50358. else
  50359. {
  50360. deleteAndZero (extraTabsButton);
  50361. }
  50362. int pos = 0;
  50363. TabBarButton* frontTab = 0;
  50364. for (i = 0; i < tabs.size(); ++i)
  50365. {
  50366. TabBarButton* const tb = getTabButton (i);
  50367. if (tb != 0)
  50368. {
  50369. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50370. if (i < numVisibleButtons)
  50371. {
  50372. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50373. tb->setBounds (pos, 0, bestLength, getHeight());
  50374. else
  50375. tb->setBounds (0, pos, getWidth(), bestLength);
  50376. tb->toBack();
  50377. if (tb->tabIndex == currentTabIndex)
  50378. frontTab = tb;
  50379. tb->setVisible (true);
  50380. }
  50381. else
  50382. {
  50383. tb->setVisible (false);
  50384. }
  50385. pos += bestLength - overlap;
  50386. }
  50387. }
  50388. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50389. if (frontTab != 0)
  50390. {
  50391. frontTab->toFront (false);
  50392. behindFrontTab->toBehind (frontTab);
  50393. }
  50394. }
  50395. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50396. {
  50397. return tabColours [tabIndex];
  50398. }
  50399. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50400. {
  50401. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50402. && tabColours [tabIndex] != newColour)
  50403. {
  50404. tabColours.set (tabIndex, newColour);
  50405. repaint();
  50406. }
  50407. }
  50408. void TabbedButtonBar::buttonClicked (Button* button)
  50409. {
  50410. if (extraTabsButton == button)
  50411. {
  50412. PopupMenu m;
  50413. for (int i = 0; i < tabs.size(); ++i)
  50414. {
  50415. TabBarButton* const tb = getTabButton (i);
  50416. if (tb != 0 && ! tb->isVisible())
  50417. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50418. }
  50419. const int res = m.showAt (extraTabsButton);
  50420. if (res != 0)
  50421. setCurrentTabIndex (res - 1);
  50422. }
  50423. }
  50424. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50425. {
  50426. }
  50427. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50428. {
  50429. }
  50430. END_JUCE_NAMESPACE
  50431. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50432. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50433. BEGIN_JUCE_NAMESPACE
  50434. class TabCompButtonBar : public TabbedButtonBar
  50435. {
  50436. public:
  50437. TabCompButtonBar (TabbedComponent* const owner_,
  50438. const TabbedButtonBar::Orientation orientation)
  50439. : TabbedButtonBar (orientation),
  50440. owner (owner_)
  50441. {
  50442. }
  50443. ~TabCompButtonBar()
  50444. {
  50445. }
  50446. void currentTabChanged (int newCurrentTabIndex,
  50447. const String& newTabName)
  50448. {
  50449. owner->changeCallback (newCurrentTabIndex, newTabName);
  50450. }
  50451. void popupMenuClickOnTab (int tabIndex,
  50452. const String& tabName)
  50453. {
  50454. owner->popupMenuClickOnTab (tabIndex, tabName);
  50455. }
  50456. const Colour getTabBackgroundColour (const int tabIndex)
  50457. {
  50458. return owner->tabs->getTabBackgroundColour (tabIndex);
  50459. }
  50460. TabBarButton* createTabButton (const String& tabName, int tabIndex)
  50461. {
  50462. return owner->createTabButton (tabName, tabIndex);
  50463. }
  50464. juce_UseDebuggingNewOperator
  50465. private:
  50466. TabbedComponent* const owner;
  50467. TabCompButtonBar (const TabCompButtonBar&);
  50468. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50469. };
  50470. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50471. : panelComponent (0),
  50472. tabDepth (30),
  50473. outlineThickness (1),
  50474. edgeIndent (0)
  50475. {
  50476. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50477. }
  50478. TabbedComponent::~TabbedComponent()
  50479. {
  50480. clearTabs();
  50481. delete tabs;
  50482. }
  50483. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50484. {
  50485. tabs->setOrientation (orientation);
  50486. resized();
  50487. }
  50488. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50489. {
  50490. return tabs->getOrientation();
  50491. }
  50492. void TabbedComponent::setTabBarDepth (const int newDepth)
  50493. {
  50494. if (tabDepth != newDepth)
  50495. {
  50496. tabDepth = newDepth;
  50497. resized();
  50498. }
  50499. }
  50500. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50501. {
  50502. return new TabBarButton (tabName, tabs, tabIndex);
  50503. }
  50504. void TabbedComponent::clearTabs()
  50505. {
  50506. if (panelComponent != 0)
  50507. {
  50508. panelComponent->setVisible (false);
  50509. removeChildComponent (panelComponent);
  50510. panelComponent = 0;
  50511. }
  50512. tabs->clearTabs();
  50513. for (int i = contentComponents.size(); --i >= 0;)
  50514. {
  50515. Component* const c = contentComponents.getUnchecked(i);
  50516. // be careful not to delete these components until they've been removed from the tab component
  50517. jassert (c == 0 || c->isValidComponent());
  50518. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50519. delete c;
  50520. }
  50521. contentComponents.clear();
  50522. }
  50523. void TabbedComponent::addTab (const String& tabName,
  50524. const Colour& tabBackgroundColour,
  50525. Component* const contentComponent,
  50526. const bool deleteComponentWhenNotNeeded,
  50527. const int insertIndex)
  50528. {
  50529. contentComponents.insert (insertIndex, contentComponent);
  50530. if (contentComponent != 0)
  50531. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50532. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50533. }
  50534. void TabbedComponent::setTabName (const int tabIndex,
  50535. const String& newName)
  50536. {
  50537. tabs->setTabName (tabIndex, newName);
  50538. }
  50539. void TabbedComponent::removeTab (const int tabIndex)
  50540. {
  50541. Component* const c = contentComponents [tabIndex];
  50542. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50543. {
  50544. if (c == panelComponent)
  50545. panelComponent = 0;
  50546. delete c;
  50547. }
  50548. contentComponents.remove (tabIndex);
  50549. tabs->removeTab (tabIndex);
  50550. }
  50551. int TabbedComponent::getNumTabs() const
  50552. {
  50553. return tabs->getNumTabs();
  50554. }
  50555. const StringArray TabbedComponent::getTabNames() const
  50556. {
  50557. return tabs->getTabNames();
  50558. }
  50559. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50560. {
  50561. return contentComponents [tabIndex];
  50562. }
  50563. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50564. {
  50565. return tabs->getTabBackgroundColour (tabIndex);
  50566. }
  50567. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50568. {
  50569. tabs->setTabBackgroundColour (tabIndex, newColour);
  50570. if (getCurrentTabIndex() == tabIndex)
  50571. repaint();
  50572. }
  50573. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50574. {
  50575. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50576. }
  50577. int TabbedComponent::getCurrentTabIndex() const
  50578. {
  50579. return tabs->getCurrentTabIndex();
  50580. }
  50581. const String& TabbedComponent::getCurrentTabName() const
  50582. {
  50583. return tabs->getCurrentTabName();
  50584. }
  50585. void TabbedComponent::setOutline (int thickness)
  50586. {
  50587. outlineThickness = thickness;
  50588. repaint();
  50589. }
  50590. void TabbedComponent::setIndent (const int indentThickness)
  50591. {
  50592. edgeIndent = indentThickness;
  50593. }
  50594. void TabbedComponent::paint (Graphics& g)
  50595. {
  50596. g.fillAll (findColour (backgroundColourId));
  50597. const TabbedButtonBar::Orientation o = getOrientation();
  50598. int x = 0;
  50599. int y = 0;
  50600. int r = getWidth();
  50601. int b = getHeight();
  50602. if (o == TabbedButtonBar::TabsAtTop)
  50603. y += tabDepth;
  50604. else if (o == TabbedButtonBar::TabsAtBottom)
  50605. b -= tabDepth;
  50606. else if (o == TabbedButtonBar::TabsAtLeft)
  50607. x += tabDepth;
  50608. else if (o == TabbedButtonBar::TabsAtRight)
  50609. r -= tabDepth;
  50610. g.reduceClipRegion (x, y, r - x, b - y);
  50611. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50612. if (outlineThickness > 0)
  50613. {
  50614. if (o == TabbedButtonBar::TabsAtTop)
  50615. --y;
  50616. else if (o == TabbedButtonBar::TabsAtBottom)
  50617. ++b;
  50618. else if (o == TabbedButtonBar::TabsAtLeft)
  50619. --x;
  50620. else if (o == TabbedButtonBar::TabsAtRight)
  50621. ++r;
  50622. g.setColour (findColour (outlineColourId));
  50623. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50624. }
  50625. }
  50626. void TabbedComponent::resized()
  50627. {
  50628. const TabbedButtonBar::Orientation o = getOrientation();
  50629. const int indent = edgeIndent + outlineThickness;
  50630. BorderSize indents (indent);
  50631. if (o == TabbedButtonBar::TabsAtTop)
  50632. {
  50633. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50634. indents.setTop (tabDepth + edgeIndent);
  50635. }
  50636. else if (o == TabbedButtonBar::TabsAtBottom)
  50637. {
  50638. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50639. indents.setBottom (tabDepth + edgeIndent);
  50640. }
  50641. else if (o == TabbedButtonBar::TabsAtLeft)
  50642. {
  50643. tabs->setBounds (0, 0, tabDepth, getHeight());
  50644. indents.setLeft (tabDepth + edgeIndent);
  50645. }
  50646. else if (o == TabbedButtonBar::TabsAtRight)
  50647. {
  50648. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50649. indents.setRight (tabDepth + edgeIndent);
  50650. }
  50651. const Rectangle<int> bounds (indents.subtractedFrom (getLocalBounds()));
  50652. for (int i = contentComponents.size(); --i >= 0;)
  50653. if (contentComponents.getUnchecked (i) != 0)
  50654. contentComponents.getUnchecked (i)->setBounds (bounds);
  50655. }
  50656. void TabbedComponent::lookAndFeelChanged()
  50657. {
  50658. for (int i = contentComponents.size(); --i >= 0;)
  50659. if (contentComponents.getUnchecked (i) != 0)
  50660. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50661. }
  50662. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50663. const String& newTabName)
  50664. {
  50665. if (panelComponent != 0)
  50666. {
  50667. panelComponent->setVisible (false);
  50668. removeChildComponent (panelComponent);
  50669. panelComponent = 0;
  50670. }
  50671. if (getCurrentTabIndex() >= 0)
  50672. {
  50673. panelComponent = contentComponents [getCurrentTabIndex()];
  50674. if (panelComponent != 0)
  50675. {
  50676. // do these ops as two stages instead of addAndMakeVisible() so that the
  50677. // component has always got a parent when it gets the visibilityChanged() callback
  50678. addChildComponent (panelComponent);
  50679. panelComponent->setVisible (true);
  50680. panelComponent->toFront (true);
  50681. }
  50682. repaint();
  50683. }
  50684. resized();
  50685. currentTabChanged (newCurrentTabIndex, newTabName);
  50686. }
  50687. void TabbedComponent::currentTabChanged (const int, const String&)
  50688. {
  50689. }
  50690. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50691. {
  50692. }
  50693. END_JUCE_NAMESPACE
  50694. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50695. /*** Start of inlined file: juce_Viewport.cpp ***/
  50696. BEGIN_JUCE_NAMESPACE
  50697. Viewport::Viewport (const String& componentName)
  50698. : Component (componentName),
  50699. contentComp (0),
  50700. lastVX (0),
  50701. lastVY (0),
  50702. lastVW (0),
  50703. lastVH (0),
  50704. scrollBarThickness (0),
  50705. singleStepX (16),
  50706. singleStepY (16),
  50707. showHScrollbar (true),
  50708. showVScrollbar (true)
  50709. {
  50710. // content holder is used to clip the contents so they don't overlap the scrollbars
  50711. addAndMakeVisible (contentHolder = new Component());
  50712. contentHolder->setInterceptsMouseClicks (false, true);
  50713. verticalScrollBar = new ScrollBar (true);
  50714. horizontalScrollBar = new ScrollBar (false);
  50715. addChildComponent (verticalScrollBar);
  50716. addChildComponent (horizontalScrollBar);
  50717. verticalScrollBar->addListener (this);
  50718. horizontalScrollBar->addListener (this);
  50719. setInterceptsMouseClicks (false, true);
  50720. setWantsKeyboardFocus (true);
  50721. }
  50722. Viewport::~Viewport()
  50723. {
  50724. contentHolder->deleteAllChildren();
  50725. deleteAllChildren();
  50726. }
  50727. void Viewport::visibleAreaChanged (int, int, int, int)
  50728. {
  50729. }
  50730. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50731. {
  50732. if (contentComp.getComponent() != newViewedComponent)
  50733. {
  50734. {
  50735. ScopedPointer<Component> oldCompDeleter (contentComp);
  50736. contentComp = 0;
  50737. }
  50738. contentComp = newViewedComponent;
  50739. if (contentComp != 0)
  50740. {
  50741. contentComp->setTopLeftPosition (0, 0);
  50742. contentHolder->addAndMakeVisible (contentComp);
  50743. contentComp->addComponentListener (this);
  50744. }
  50745. updateVisibleRegion();
  50746. }
  50747. }
  50748. int Viewport::getMaximumVisibleWidth() const throw()
  50749. {
  50750. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50751. }
  50752. int Viewport::getMaximumVisibleHeight() const throw()
  50753. {
  50754. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50755. }
  50756. void Viewport::setViewPosition (const int xPixelsOffset,
  50757. const int yPixelsOffset)
  50758. {
  50759. if (contentComp != 0)
  50760. contentComp->setTopLeftPosition (-xPixelsOffset,
  50761. -yPixelsOffset);
  50762. }
  50763. void Viewport::setViewPositionProportionately (const double x,
  50764. const double y)
  50765. {
  50766. if (contentComp != 0)
  50767. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50768. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50769. }
  50770. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50771. {
  50772. if (contentComp != 0)
  50773. {
  50774. int dx = 0, dy = 0;
  50775. if (mouseX < activeBorderThickness)
  50776. dx = activeBorderThickness - mouseX;
  50777. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50778. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50779. if (dx < 0)
  50780. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50781. else
  50782. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50783. if (mouseY < activeBorderThickness)
  50784. dy = activeBorderThickness - mouseY;
  50785. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50786. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50787. if (dy < 0)
  50788. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50789. else
  50790. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50791. if (dx != 0 || dy != 0)
  50792. {
  50793. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50794. contentComp->getY() + dy);
  50795. return true;
  50796. }
  50797. }
  50798. return false;
  50799. }
  50800. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50801. {
  50802. updateVisibleRegion();
  50803. }
  50804. void Viewport::resized()
  50805. {
  50806. updateVisibleRegion();
  50807. }
  50808. void Viewport::updateVisibleRegion()
  50809. {
  50810. if (contentComp != 0)
  50811. {
  50812. const int newVX = -contentComp->getX();
  50813. const int newVY = -contentComp->getY();
  50814. if (newVX == 0 && newVY == 0
  50815. && contentComp->getWidth() <= getWidth()
  50816. && contentComp->getHeight() <= getHeight())
  50817. {
  50818. horizontalScrollBar->setVisible (false);
  50819. verticalScrollBar->setVisible (false);
  50820. }
  50821. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50822. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50823. horizontalScrollBar->setSingleStepSize (singleStepX);
  50824. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50825. horizontalScrollBar->setVisible (false);
  50826. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50827. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50828. verticalScrollBar->setSingleStepSize (singleStepY);
  50829. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50830. verticalScrollBar->setVisible (false);
  50831. if (verticalScrollBar->isVisible())
  50832. {
  50833. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50834. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50835. verticalScrollBar
  50836. ->setBounds (getMaximumVisibleWidth(), 0,
  50837. getScrollBarThickness(), getMaximumVisibleHeight());
  50838. }
  50839. if (horizontalScrollBar->isVisible())
  50840. {
  50841. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50842. horizontalScrollBar
  50843. ->setBounds (0, getMaximumVisibleHeight(),
  50844. getMaximumVisibleWidth(), getScrollBarThickness());
  50845. }
  50846. contentHolder->setSize (getMaximumVisibleWidth(),
  50847. getMaximumVisibleHeight());
  50848. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50849. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50850. if (newVX != lastVX
  50851. || newVY != lastVY
  50852. || newVW != lastVW
  50853. || newVH != lastVH)
  50854. {
  50855. lastVX = newVX;
  50856. lastVY = newVY;
  50857. lastVW = newVW;
  50858. lastVH = newVH;
  50859. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50860. }
  50861. horizontalScrollBar->handleUpdateNowIfNeeded();
  50862. verticalScrollBar->handleUpdateNowIfNeeded();
  50863. }
  50864. else
  50865. {
  50866. horizontalScrollBar->setVisible (false);
  50867. verticalScrollBar->setVisible (false);
  50868. }
  50869. }
  50870. void Viewport::setSingleStepSizes (const int stepX,
  50871. const int stepY)
  50872. {
  50873. singleStepX = stepX;
  50874. singleStepY = stepY;
  50875. updateVisibleRegion();
  50876. }
  50877. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50878. const bool showHorizontalScrollbarIfNeeded)
  50879. {
  50880. showVScrollbar = showVerticalScrollbarIfNeeded;
  50881. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50882. updateVisibleRegion();
  50883. }
  50884. void Viewport::setScrollBarThickness (const int thickness)
  50885. {
  50886. scrollBarThickness = thickness;
  50887. updateVisibleRegion();
  50888. }
  50889. int Viewport::getScrollBarThickness() const throw()
  50890. {
  50891. return (scrollBarThickness > 0) ? scrollBarThickness
  50892. : getLookAndFeel().getDefaultScrollbarWidth();
  50893. }
  50894. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50895. {
  50896. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50897. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50898. }
  50899. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50900. {
  50901. if (scrollBarThatHasMoved == horizontalScrollBar)
  50902. {
  50903. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50904. }
  50905. else if (scrollBarThatHasMoved == verticalScrollBar)
  50906. {
  50907. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50908. }
  50909. }
  50910. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50911. {
  50912. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50913. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50914. }
  50915. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50916. {
  50917. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50918. {
  50919. const bool hasVertBar = verticalScrollBar->isVisible();
  50920. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50921. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50922. {
  50923. if (wheelIncrementX == 0 && ! hasVertBar)
  50924. wheelIncrementX = wheelIncrementY;
  50925. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50926. wheelIncrementX, wheelIncrementY);
  50927. return true;
  50928. }
  50929. else if (hasVertBar && wheelIncrementY != 0)
  50930. {
  50931. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50932. wheelIncrementX, wheelIncrementY);
  50933. return true;
  50934. }
  50935. }
  50936. return false;
  50937. }
  50938. bool Viewport::keyPressed (const KeyPress& key)
  50939. {
  50940. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50941. || key.isKeyCode (KeyPress::downKey)
  50942. || key.isKeyCode (KeyPress::pageUpKey)
  50943. || key.isKeyCode (KeyPress::pageDownKey)
  50944. || key.isKeyCode (KeyPress::homeKey)
  50945. || key.isKeyCode (KeyPress::endKey);
  50946. if (verticalScrollBar->isVisible() && isUpDownKey)
  50947. return verticalScrollBar->keyPressed (key);
  50948. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50949. || key.isKeyCode (KeyPress::rightKey);
  50950. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50951. return horizontalScrollBar->keyPressed (key);
  50952. return false;
  50953. }
  50954. END_JUCE_NAMESPACE
  50955. /*** End of inlined file: juce_Viewport.cpp ***/
  50956. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50957. BEGIN_JUCE_NAMESPACE
  50958. static const Colour createBaseColour (const Colour& buttonColour,
  50959. const bool hasKeyboardFocus,
  50960. const bool isMouseOverButton,
  50961. const bool isButtonDown) throw()
  50962. {
  50963. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50964. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50965. if (isButtonDown)
  50966. return baseColour.contrasting (0.2f);
  50967. else if (isMouseOverButton)
  50968. return baseColour.contrasting (0.1f);
  50969. return baseColour;
  50970. }
  50971. LookAndFeel::LookAndFeel()
  50972. {
  50973. /* if this fails it means you're trying to create a LookAndFeel object before
  50974. the static Colours have been initialised. That ain't gonna work. It probably
  50975. means that you're using a static LookAndFeel object and that your compiler has
  50976. decided to intialise it before the Colours class.
  50977. */
  50978. jassert (Colours::white == Colour (0xffffffff));
  50979. // set up the standard set of colours..
  50980. const int textButtonColour = 0xffbbbbff;
  50981. const int textHighlightColour = 0x401111ee;
  50982. const int standardOutlineColour = 0xb2808080;
  50983. static const int standardColours[] =
  50984. {
  50985. TextButton::buttonColourId, textButtonColour,
  50986. TextButton::buttonOnColourId, 0xff4444ff,
  50987. TextButton::textColourOnId, 0xff000000,
  50988. TextButton::textColourOffId, 0xff000000,
  50989. ComboBox::buttonColourId, 0xffbbbbff,
  50990. ComboBox::outlineColourId, standardOutlineColour,
  50991. ToggleButton::textColourId, 0xff000000,
  50992. TextEditor::backgroundColourId, 0xffffffff,
  50993. TextEditor::textColourId, 0xff000000,
  50994. TextEditor::highlightColourId, textHighlightColour,
  50995. TextEditor::highlightedTextColourId, 0xff000000,
  50996. TextEditor::caretColourId, 0xff000000,
  50997. TextEditor::outlineColourId, 0x00000000,
  50998. TextEditor::focusedOutlineColourId, textButtonColour,
  50999. TextEditor::shadowColourId, 0x38000000,
  51000. Label::backgroundColourId, 0x00000000,
  51001. Label::textColourId, 0xff000000,
  51002. Label::outlineColourId, 0x00000000,
  51003. ScrollBar::backgroundColourId, 0x00000000,
  51004. ScrollBar::thumbColourId, 0xffffffff,
  51005. ScrollBar::trackColourId, 0xffffffff,
  51006. TreeView::linesColourId, 0x4c000000,
  51007. TreeView::backgroundColourId, 0x00000000,
  51008. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51009. PopupMenu::backgroundColourId, 0xffffffff,
  51010. PopupMenu::textColourId, 0xff000000,
  51011. PopupMenu::headerTextColourId, 0xff000000,
  51012. PopupMenu::highlightedTextColourId, 0xffffffff,
  51013. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51014. ComboBox::textColourId, 0xff000000,
  51015. ComboBox::backgroundColourId, 0xffffffff,
  51016. ComboBox::arrowColourId, 0x99000000,
  51017. ListBox::backgroundColourId, 0xffffffff,
  51018. ListBox::outlineColourId, standardOutlineColour,
  51019. ListBox::textColourId, 0xff000000,
  51020. Slider::backgroundColourId, 0x00000000,
  51021. Slider::thumbColourId, textButtonColour,
  51022. Slider::trackColourId, 0x7fffffff,
  51023. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51024. Slider::rotarySliderOutlineColourId, 0x66000000,
  51025. Slider::textBoxTextColourId, 0xff000000,
  51026. Slider::textBoxBackgroundColourId, 0xffffffff,
  51027. Slider::textBoxHighlightColourId, textHighlightColour,
  51028. Slider::textBoxOutlineColourId, standardOutlineColour,
  51029. ResizableWindow::backgroundColourId, 0xff777777,
  51030. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51031. AlertWindow::backgroundColourId, 0xffededed,
  51032. AlertWindow::textColourId, 0xff000000,
  51033. AlertWindow::outlineColourId, 0xff666666,
  51034. ProgressBar::backgroundColourId, 0xffeeeeee,
  51035. ProgressBar::foregroundColourId, 0xffaaaaee,
  51036. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51037. TooltipWindow::textColourId, 0xff000000,
  51038. TooltipWindow::outlineColourId, 0x4c000000,
  51039. TabbedComponent::backgroundColourId, 0x00000000,
  51040. TabbedComponent::outlineColourId, 0xff777777,
  51041. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51042. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51043. Toolbar::backgroundColourId, 0xfff6f8f9,
  51044. Toolbar::separatorColourId, 0x4c000000,
  51045. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51046. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51047. Toolbar::labelTextColourId, 0xff000000,
  51048. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51049. HyperlinkButton::textColourId, 0xcc1111ee,
  51050. GroupComponent::outlineColourId, 0x66000000,
  51051. GroupComponent::textColourId, 0xff000000,
  51052. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51053. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51054. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51055. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51056. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51057. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51058. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51059. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51060. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51061. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51062. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51063. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51064. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51065. CodeEditorComponent::caretColourId, 0xff000000,
  51066. CodeEditorComponent::highlightColourId, textHighlightColour,
  51067. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51068. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51069. ColourSelector::labelTextColourId, 0xff000000,
  51070. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51071. KeyMappingEditorComponent::textColourId, 0xff000000,
  51072. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51073. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51074. };
  51075. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51076. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51077. static String defaultSansName, defaultSerifName, defaultFixedName;
  51078. if (defaultSansName.isEmpty())
  51079. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51080. defaultSans = defaultSansName;
  51081. defaultSerif = defaultSerifName;
  51082. defaultFixed = defaultFixedName;
  51083. }
  51084. LookAndFeel::~LookAndFeel()
  51085. {
  51086. }
  51087. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51088. {
  51089. const int index = colourIds.indexOf (colourId);
  51090. if (index >= 0)
  51091. return colours [index];
  51092. jassertfalse
  51093. return Colours::black;
  51094. }
  51095. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51096. {
  51097. const int index = colourIds.indexOf (colourId);
  51098. if (index >= 0)
  51099. colours.set (index, colour);
  51100. colourIds.add (colourId);
  51101. colours.add (colour);
  51102. }
  51103. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51104. {
  51105. return colourIds.contains (colourId);
  51106. }
  51107. static LookAndFeel* defaultLF = 0;
  51108. static LookAndFeel* currentDefaultLF = 0;
  51109. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51110. {
  51111. // if this happens, your app hasn't initialised itself properly.. if you're
  51112. // trying to hack your own main() function, have a look at
  51113. // JUCEApplication::initialiseForGUI()
  51114. jassert (currentDefaultLF != 0);
  51115. return *currentDefaultLF;
  51116. }
  51117. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51118. {
  51119. if (newDefaultLookAndFeel == 0)
  51120. {
  51121. if (defaultLF == 0)
  51122. defaultLF = new LookAndFeel();
  51123. newDefaultLookAndFeel = defaultLF;
  51124. }
  51125. currentDefaultLF = newDefaultLookAndFeel;
  51126. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51127. {
  51128. Component* const c = Desktop::getInstance().getComponent (i);
  51129. if (c != 0)
  51130. c->sendLookAndFeelChange();
  51131. }
  51132. }
  51133. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51134. {
  51135. if (currentDefaultLF == defaultLF)
  51136. currentDefaultLF = 0;
  51137. deleteAndZero (defaultLF);
  51138. }
  51139. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51140. {
  51141. String faceName (font.getTypefaceName());
  51142. if (faceName == Font::getDefaultSansSerifFontName())
  51143. faceName = defaultSans;
  51144. else if (faceName == Font::getDefaultSerifFontName())
  51145. faceName = defaultSerif;
  51146. else if (faceName == Font::getDefaultMonospacedFontName())
  51147. faceName = defaultFixed;
  51148. Font f (font);
  51149. f.setTypefaceName (faceName);
  51150. return Typeface::createSystemTypefaceFor (f);
  51151. }
  51152. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51153. {
  51154. defaultSans = newName;
  51155. }
  51156. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51157. {
  51158. return component.getMouseCursor();
  51159. }
  51160. void LookAndFeel::drawButtonBackground (Graphics& g,
  51161. Button& button,
  51162. const Colour& backgroundColour,
  51163. bool isMouseOverButton,
  51164. bool isButtonDown)
  51165. {
  51166. const int width = button.getWidth();
  51167. const int height = button.getHeight();
  51168. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51169. const float halfThickness = outlineThickness * 0.5f;
  51170. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51171. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51172. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51173. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51174. const Colour baseColour (createBaseColour (backgroundColour,
  51175. button.hasKeyboardFocus (true),
  51176. isMouseOverButton, isButtonDown)
  51177. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51178. drawGlassLozenge (g,
  51179. indentL,
  51180. indentT,
  51181. width - indentL - indentR,
  51182. height - indentT - indentB,
  51183. baseColour, outlineThickness, -1.0f,
  51184. button.isConnectedOnLeft(),
  51185. button.isConnectedOnRight(),
  51186. button.isConnectedOnTop(),
  51187. button.isConnectedOnBottom());
  51188. }
  51189. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51190. {
  51191. return button.getFont();
  51192. }
  51193. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51194. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51195. {
  51196. Font font (getFontForTextButton (button));
  51197. g.setFont (font);
  51198. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51199. : TextButton::textColourOffId)
  51200. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51201. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51202. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51203. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51204. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51205. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51206. g.drawFittedText (button.getButtonText(),
  51207. leftIndent,
  51208. yIndent,
  51209. button.getWidth() - leftIndent - rightIndent,
  51210. button.getHeight() - yIndent * 2,
  51211. Justification::centred, 2);
  51212. }
  51213. void LookAndFeel::drawTickBox (Graphics& g,
  51214. Component& component,
  51215. float x, float y, float w, float h,
  51216. const bool ticked,
  51217. const bool isEnabled,
  51218. const bool isMouseOverButton,
  51219. const bool isButtonDown)
  51220. {
  51221. const float boxSize = w * 0.7f;
  51222. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51223. createBaseColour (component.findColour (TextButton::buttonColourId)
  51224. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51225. true,
  51226. isMouseOverButton,
  51227. isButtonDown),
  51228. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51229. if (ticked)
  51230. {
  51231. Path tick;
  51232. tick.startNewSubPath (1.5f, 3.0f);
  51233. tick.lineTo (3.0f, 6.0f);
  51234. tick.lineTo (6.0f, 0.0f);
  51235. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51236. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51237. .translated (x, y));
  51238. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51239. }
  51240. }
  51241. void LookAndFeel::drawToggleButton (Graphics& g,
  51242. ToggleButton& button,
  51243. bool isMouseOverButton,
  51244. bool isButtonDown)
  51245. {
  51246. if (button.hasKeyboardFocus (true))
  51247. {
  51248. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51249. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51250. }
  51251. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51252. const float tickWidth = fontSize * 1.1f;
  51253. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51254. tickWidth, tickWidth,
  51255. button.getToggleState(),
  51256. button.isEnabled(),
  51257. isMouseOverButton,
  51258. isButtonDown);
  51259. g.setColour (button.findColour (ToggleButton::textColourId));
  51260. g.setFont (fontSize);
  51261. if (! button.isEnabled())
  51262. g.setOpacity (0.5f);
  51263. const int textX = (int) tickWidth + 5;
  51264. g.drawFittedText (button.getButtonText(),
  51265. textX, 0,
  51266. button.getWidth() - textX - 2, button.getHeight(),
  51267. Justification::centredLeft, 10);
  51268. }
  51269. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51270. {
  51271. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51272. const int tickWidth = jmin (24, button.getHeight());
  51273. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51274. button.getHeight());
  51275. }
  51276. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51277. const String& message,
  51278. const String& button1,
  51279. const String& button2,
  51280. const String& button3,
  51281. AlertWindow::AlertIconType iconType,
  51282. int numButtons,
  51283. Component* associatedComponent)
  51284. {
  51285. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51286. if (numButtons == 1)
  51287. {
  51288. aw->addButton (button1, 0,
  51289. KeyPress (KeyPress::escapeKey, 0, 0),
  51290. KeyPress (KeyPress::returnKey, 0, 0));
  51291. }
  51292. else
  51293. {
  51294. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51295. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51296. if (button1ShortCut == button2ShortCut)
  51297. button2ShortCut = KeyPress();
  51298. if (numButtons == 2)
  51299. {
  51300. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51301. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51302. }
  51303. else if (numButtons == 3)
  51304. {
  51305. aw->addButton (button1, 1, button1ShortCut);
  51306. aw->addButton (button2, 2, button2ShortCut);
  51307. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51308. }
  51309. }
  51310. return aw;
  51311. }
  51312. void LookAndFeel::drawAlertBox (Graphics& g,
  51313. AlertWindow& alert,
  51314. const Rectangle<int>& textArea,
  51315. TextLayout& textLayout)
  51316. {
  51317. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51318. int iconSpaceUsed = 0;
  51319. Justification alignment (Justification::horizontallyCentred);
  51320. const int iconWidth = 80;
  51321. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51322. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51323. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51324. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51325. iconSize, iconSize);
  51326. if (alert.getAlertType() != AlertWindow::NoIcon)
  51327. {
  51328. Path icon;
  51329. uint32 colour;
  51330. char character;
  51331. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51332. {
  51333. colour = 0x55ff5555;
  51334. character = '!';
  51335. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51336. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51337. (float) iconRect.getX(), (float) iconRect.getBottom());
  51338. icon = icon.createPathWithRoundedCorners (5.0f);
  51339. }
  51340. else
  51341. {
  51342. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51343. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51344. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51345. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51346. }
  51347. GlyphArrangement ga;
  51348. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51349. String::charToString (character),
  51350. (float) iconRect.getX(), (float) iconRect.getY(),
  51351. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51352. Justification::centred, false);
  51353. ga.createPath (icon);
  51354. icon.setUsingNonZeroWinding (false);
  51355. g.setColour (Colour (colour));
  51356. g.fillPath (icon);
  51357. iconSpaceUsed = iconWidth;
  51358. alignment = Justification::left;
  51359. }
  51360. g.setColour (alert.findColour (AlertWindow::textColourId));
  51361. textLayout.drawWithin (g,
  51362. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51363. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51364. alignment.getFlags() | Justification::top);
  51365. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51366. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51367. }
  51368. int LookAndFeel::getAlertBoxWindowFlags()
  51369. {
  51370. return ComponentPeer::windowAppearsOnTaskbar
  51371. | ComponentPeer::windowHasDropShadow;
  51372. }
  51373. int LookAndFeel::getAlertWindowButtonHeight()
  51374. {
  51375. return 28;
  51376. }
  51377. const Font LookAndFeel::getAlertWindowFont()
  51378. {
  51379. return Font (12.0f);
  51380. }
  51381. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51382. int width, int height,
  51383. double progress, const String& textToShow)
  51384. {
  51385. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51386. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51387. g.fillAll (background);
  51388. if (progress >= 0.0f && progress < 1.0f)
  51389. {
  51390. drawGlassLozenge (g, 1.0f, 1.0f,
  51391. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51392. (float) (height - 2),
  51393. foreground,
  51394. 0.5f, 0.0f,
  51395. true, true, true, true);
  51396. }
  51397. else
  51398. {
  51399. // spinning bar..
  51400. g.setColour (foreground);
  51401. const int stripeWidth = height * 2;
  51402. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51403. Path p;
  51404. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51405. p.addQuadrilateral (x, 0.0f,
  51406. x + stripeWidth * 0.5f, 0.0f,
  51407. x, (float) height,
  51408. x - stripeWidth * 0.5f, (float) height);
  51409. Image im (Image::ARGB, width, height, true);
  51410. {
  51411. Graphics g2 (im);
  51412. drawGlassLozenge (g2, 1.0f, 1.0f,
  51413. (float) (width - 2),
  51414. (float) (height - 2),
  51415. foreground,
  51416. 0.5f, 0.0f,
  51417. true, true, true, true);
  51418. }
  51419. g.setTiledImageFill (im, 0, 0, 0.85f);
  51420. g.fillPath (p);
  51421. }
  51422. if (textToShow.isNotEmpty())
  51423. {
  51424. g.setColour (Colour::contrasting (background, foreground));
  51425. g.setFont (height * 0.6f);
  51426. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51427. }
  51428. }
  51429. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51430. {
  51431. const float radius = jmin (w, h) * 0.4f;
  51432. const float thickness = radius * 0.15f;
  51433. Path p;
  51434. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51435. radius * 0.6f, thickness,
  51436. thickness * 0.5f);
  51437. const float cx = x + w * 0.5f;
  51438. const float cy = y + h * 0.5f;
  51439. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51440. for (int i = 0; i < 12; ++i)
  51441. {
  51442. const int n = (i + 12 - animationIndex) % 12;
  51443. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51444. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51445. .translated (cx, cy));
  51446. }
  51447. }
  51448. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51449. ScrollBar& scrollbar,
  51450. int width, int height,
  51451. int buttonDirection,
  51452. bool /*isScrollbarVertical*/,
  51453. bool /*isMouseOverButton*/,
  51454. bool isButtonDown)
  51455. {
  51456. Path p;
  51457. if (buttonDirection == 0)
  51458. p.addTriangle (width * 0.5f, height * 0.2f,
  51459. width * 0.1f, height * 0.7f,
  51460. width * 0.9f, height * 0.7f);
  51461. else if (buttonDirection == 1)
  51462. p.addTriangle (width * 0.8f, height * 0.5f,
  51463. width * 0.3f, height * 0.1f,
  51464. width * 0.3f, height * 0.9f);
  51465. else if (buttonDirection == 2)
  51466. p.addTriangle (width * 0.5f, height * 0.8f,
  51467. width * 0.1f, height * 0.3f,
  51468. width * 0.9f, height * 0.3f);
  51469. else if (buttonDirection == 3)
  51470. p.addTriangle (width * 0.2f, height * 0.5f,
  51471. width * 0.7f, height * 0.1f,
  51472. width * 0.7f, height * 0.9f);
  51473. if (isButtonDown)
  51474. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51475. else
  51476. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51477. g.fillPath (p);
  51478. g.setColour (Colour (0x80000000));
  51479. g.strokePath (p, PathStrokeType (0.5f));
  51480. }
  51481. void LookAndFeel::drawScrollbar (Graphics& g,
  51482. ScrollBar& scrollbar,
  51483. int x, int y,
  51484. int width, int height,
  51485. bool isScrollbarVertical,
  51486. int thumbStartPosition,
  51487. int thumbSize,
  51488. bool /*isMouseOver*/,
  51489. bool /*isMouseDown*/)
  51490. {
  51491. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51492. Path slotPath, thumbPath;
  51493. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51494. const float slotIndentx2 = slotIndent * 2.0f;
  51495. const float thumbIndent = slotIndent + 1.0f;
  51496. const float thumbIndentx2 = thumbIndent * 2.0f;
  51497. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51498. if (isScrollbarVertical)
  51499. {
  51500. slotPath.addRoundedRectangle (x + slotIndent,
  51501. y + slotIndent,
  51502. width - slotIndentx2,
  51503. height - slotIndentx2,
  51504. (width - slotIndentx2) * 0.5f);
  51505. if (thumbSize > 0)
  51506. thumbPath.addRoundedRectangle (x + thumbIndent,
  51507. thumbStartPosition + thumbIndent,
  51508. width - thumbIndentx2,
  51509. thumbSize - thumbIndentx2,
  51510. (width - thumbIndentx2) * 0.5f);
  51511. gx1 = (float) x;
  51512. gx2 = x + width * 0.7f;
  51513. }
  51514. else
  51515. {
  51516. slotPath.addRoundedRectangle (x + slotIndent,
  51517. y + slotIndent,
  51518. width - slotIndentx2,
  51519. height - slotIndentx2,
  51520. (height - slotIndentx2) * 0.5f);
  51521. if (thumbSize > 0)
  51522. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51523. y + thumbIndent,
  51524. thumbSize - thumbIndentx2,
  51525. height - thumbIndentx2,
  51526. (height - thumbIndentx2) * 0.5f);
  51527. gy1 = (float) y;
  51528. gy2 = y + height * 0.7f;
  51529. }
  51530. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51531. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51532. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51533. g.fillPath (slotPath);
  51534. if (isScrollbarVertical)
  51535. {
  51536. gx1 = x + width * 0.6f;
  51537. gx2 = (float) x + width;
  51538. }
  51539. else
  51540. {
  51541. gy1 = y + height * 0.6f;
  51542. gy2 = (float) y + height;
  51543. }
  51544. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51545. Colour (0x19000000), gx2, gy2, false));
  51546. g.fillPath (slotPath);
  51547. g.setColour (thumbColour);
  51548. g.fillPath (thumbPath);
  51549. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51550. Colours::transparentBlack, gx2, gy2, false));
  51551. g.saveState();
  51552. if (isScrollbarVertical)
  51553. g.reduceClipRegion (x + width / 2, y, width, height);
  51554. else
  51555. g.reduceClipRegion (x, y + height / 2, width, height);
  51556. g.fillPath (thumbPath);
  51557. g.restoreState();
  51558. g.setColour (Colour (0x4c000000));
  51559. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51560. }
  51561. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51562. {
  51563. return 0;
  51564. }
  51565. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51566. {
  51567. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51568. }
  51569. int LookAndFeel::getDefaultScrollbarWidth()
  51570. {
  51571. return 18;
  51572. }
  51573. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51574. {
  51575. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51576. : scrollbar.getHeight());
  51577. }
  51578. const Path LookAndFeel::getTickShape (const float height)
  51579. {
  51580. static const unsigned char tickShapeData[] =
  51581. {
  51582. 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,
  51583. 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,
  51584. 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,
  51585. 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,
  51586. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51587. };
  51588. Path p;
  51589. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51590. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51591. return p;
  51592. }
  51593. const Path LookAndFeel::getCrossShape (const float height)
  51594. {
  51595. static const unsigned char crossShapeData[] =
  51596. {
  51597. 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,
  51598. 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,
  51599. 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,
  51600. 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,
  51601. 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,
  51602. 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,
  51603. 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
  51604. };
  51605. Path p;
  51606. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51607. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51608. return p;
  51609. }
  51610. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51611. {
  51612. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51613. x += (w - boxSize) >> 1;
  51614. y += (h - boxSize) >> 1;
  51615. w = boxSize;
  51616. h = boxSize;
  51617. g.setColour (Colour (0xe5ffffff));
  51618. g.fillRect (x, y, w, h);
  51619. g.setColour (Colour (0x80000000));
  51620. g.drawRect (x, y, w, h);
  51621. const float size = boxSize / 2 + 1.0f;
  51622. const float centre = (float) (boxSize / 2);
  51623. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51624. if (isPlus)
  51625. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51626. }
  51627. void LookAndFeel::drawBubble (Graphics& g,
  51628. float tipX, float tipY,
  51629. float boxX, float boxY,
  51630. float boxW, float boxH)
  51631. {
  51632. int side = 0;
  51633. if (tipX < boxX)
  51634. side = 1;
  51635. else if (tipX > boxX + boxW)
  51636. side = 3;
  51637. else if (tipY > boxY + boxH)
  51638. side = 2;
  51639. const float indent = 2.0f;
  51640. Path p;
  51641. p.addBubble (boxX + indent,
  51642. boxY + indent,
  51643. boxW - indent * 2.0f,
  51644. boxH - indent * 2.0f,
  51645. 5.0f,
  51646. tipX, tipY,
  51647. side,
  51648. 0.5f,
  51649. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51650. //xxx need to take comp as param for colour
  51651. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51652. g.fillPath (p);
  51653. //xxx as above
  51654. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51655. g.strokePath (p, PathStrokeType (1.33f));
  51656. }
  51657. const Font LookAndFeel::getPopupMenuFont()
  51658. {
  51659. return Font (17.0f);
  51660. }
  51661. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51662. const bool isSeparator,
  51663. int standardMenuItemHeight,
  51664. int& idealWidth,
  51665. int& idealHeight)
  51666. {
  51667. if (isSeparator)
  51668. {
  51669. idealWidth = 50;
  51670. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51671. }
  51672. else
  51673. {
  51674. Font font (getPopupMenuFont());
  51675. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51676. font.setHeight (standardMenuItemHeight / 1.3f);
  51677. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51678. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51679. }
  51680. }
  51681. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51682. {
  51683. const Colour background (findColour (PopupMenu::backgroundColourId));
  51684. g.fillAll (background);
  51685. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51686. for (int i = 0; i < height; i += 3)
  51687. g.fillRect (0, i, width, 1);
  51688. #if ! JUCE_MAC
  51689. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51690. g.drawRect (0, 0, width, height);
  51691. #endif
  51692. }
  51693. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51694. int width, int height,
  51695. bool isScrollUpArrow)
  51696. {
  51697. const Colour background (findColour (PopupMenu::backgroundColourId));
  51698. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51699. background.withAlpha (0.0f),
  51700. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51701. false));
  51702. g.fillRect (1, 1, width - 2, height - 2);
  51703. const float hw = width * 0.5f;
  51704. const float arrowW = height * 0.3f;
  51705. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51706. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51707. Path p;
  51708. p.addTriangle (hw - arrowW, y1,
  51709. hw + arrowW, y1,
  51710. hw, y2);
  51711. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51712. g.fillPath (p);
  51713. }
  51714. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51715. int width, int height,
  51716. const bool isSeparator,
  51717. const bool isActive,
  51718. const bool isHighlighted,
  51719. const bool isTicked,
  51720. const bool hasSubMenu,
  51721. const String& text,
  51722. const String& shortcutKeyText,
  51723. Image* image,
  51724. const Colour* const textColourToUse)
  51725. {
  51726. const float halfH = height * 0.5f;
  51727. if (isSeparator)
  51728. {
  51729. const float separatorIndent = 5.5f;
  51730. g.setColour (Colour (0x33000000));
  51731. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51732. g.setColour (Colour (0x66ffffff));
  51733. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51734. }
  51735. else
  51736. {
  51737. Colour textColour (findColour (PopupMenu::textColourId));
  51738. if (textColourToUse != 0)
  51739. textColour = *textColourToUse;
  51740. if (isHighlighted)
  51741. {
  51742. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51743. g.fillRect (1, 1, width - 2, height - 2);
  51744. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51745. }
  51746. else
  51747. {
  51748. g.setColour (textColour);
  51749. }
  51750. if (! isActive)
  51751. g.setOpacity (0.3f);
  51752. Font font (getPopupMenuFont());
  51753. if (font.getHeight() > height / 1.3f)
  51754. font.setHeight (height / 1.3f);
  51755. g.setFont (font);
  51756. const int leftBorder = (height * 5) / 4;
  51757. const int rightBorder = 4;
  51758. if (image != 0)
  51759. {
  51760. g.drawImageWithin (image,
  51761. 2, 1, leftBorder - 4, height - 2,
  51762. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51763. }
  51764. else if (isTicked)
  51765. {
  51766. const Path tick (getTickShape (1.0f));
  51767. const float th = font.getAscent();
  51768. const float ty = halfH - th * 0.5f;
  51769. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51770. th, true));
  51771. }
  51772. g.drawFittedText (text,
  51773. leftBorder, 0,
  51774. width - (leftBorder + rightBorder), height,
  51775. Justification::centredLeft, 1);
  51776. if (shortcutKeyText.isNotEmpty())
  51777. {
  51778. Font f2 (font);
  51779. f2.setHeight (f2.getHeight() * 0.75f);
  51780. f2.setHorizontalScale (0.95f);
  51781. g.setFont (f2);
  51782. g.drawText (shortcutKeyText,
  51783. leftBorder,
  51784. 0,
  51785. width - (leftBorder + rightBorder + 4),
  51786. height,
  51787. Justification::centredRight,
  51788. true);
  51789. }
  51790. if (hasSubMenu)
  51791. {
  51792. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51793. const float x = width - height * 0.6f;
  51794. Path p;
  51795. p.addTriangle (x, halfH - arrowH * 0.5f,
  51796. x, halfH + arrowH * 0.5f,
  51797. x + arrowH * 0.6f, halfH);
  51798. g.fillPath (p);
  51799. }
  51800. }
  51801. }
  51802. int LookAndFeel::getMenuWindowFlags()
  51803. {
  51804. return ComponentPeer::windowHasDropShadow;
  51805. }
  51806. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51807. bool, MenuBarComponent& menuBar)
  51808. {
  51809. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51810. if (menuBar.isEnabled())
  51811. {
  51812. drawShinyButtonShape (g,
  51813. -4.0f, 0.0f,
  51814. width + 8.0f, (float) height,
  51815. 0.0f,
  51816. baseColour,
  51817. 0.4f,
  51818. true, true, true, true);
  51819. }
  51820. else
  51821. {
  51822. g.fillAll (baseColour);
  51823. }
  51824. }
  51825. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51826. {
  51827. return Font (menuBar.getHeight() * 0.7f);
  51828. }
  51829. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51830. {
  51831. return getMenuBarFont (menuBar, itemIndex, itemText)
  51832. .getStringWidth (itemText) + menuBar.getHeight();
  51833. }
  51834. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51835. int width, int height,
  51836. int itemIndex,
  51837. const String& itemText,
  51838. bool isMouseOverItem,
  51839. bool isMenuOpen,
  51840. bool /*isMouseOverBar*/,
  51841. MenuBarComponent& menuBar)
  51842. {
  51843. if (! menuBar.isEnabled())
  51844. {
  51845. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51846. .withMultipliedAlpha (0.5f));
  51847. }
  51848. else if (isMenuOpen || isMouseOverItem)
  51849. {
  51850. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51851. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51852. }
  51853. else
  51854. {
  51855. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51856. }
  51857. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51858. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51859. }
  51860. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51861. TextEditor& textEditor)
  51862. {
  51863. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51864. }
  51865. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51866. {
  51867. if (textEditor.isEnabled())
  51868. {
  51869. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51870. {
  51871. const int border = 2;
  51872. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51873. g.drawRect (0, 0, width, height, border);
  51874. g.setOpacity (1.0f);
  51875. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51876. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51877. }
  51878. else
  51879. {
  51880. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51881. g.drawRect (0, 0, width, height);
  51882. g.setOpacity (1.0f);
  51883. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51884. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51885. }
  51886. }
  51887. }
  51888. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51889. const bool isButtonDown,
  51890. int buttonX, int buttonY,
  51891. int buttonW, int buttonH,
  51892. ComboBox& box)
  51893. {
  51894. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51895. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51896. {
  51897. g.setColour (box.findColour (TextButton::buttonColourId));
  51898. g.drawRect (0, 0, width, height, 2);
  51899. }
  51900. else
  51901. {
  51902. g.setColour (box.findColour (ComboBox::outlineColourId));
  51903. g.drawRect (0, 0, width, height);
  51904. }
  51905. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51906. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51907. box.hasKeyboardFocus (true),
  51908. false, isButtonDown)
  51909. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51910. drawGlassLozenge (g,
  51911. buttonX + outlineThickness, buttonY + outlineThickness,
  51912. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51913. baseColour, outlineThickness, -1.0f,
  51914. true, true, true, true);
  51915. if (box.isEnabled())
  51916. {
  51917. const float arrowX = 0.3f;
  51918. const float arrowH = 0.2f;
  51919. Path p;
  51920. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51921. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51922. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51923. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51924. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51925. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51926. g.setColour (box.findColour (ComboBox::arrowColourId));
  51927. g.fillPath (p);
  51928. }
  51929. }
  51930. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51931. {
  51932. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51933. }
  51934. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51935. {
  51936. return new Label (String::empty, String::empty);
  51937. }
  51938. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51939. {
  51940. label.setBounds (1, 1,
  51941. box.getWidth() + 3 - box.getHeight(),
  51942. box.getHeight() - 2);
  51943. label.setFont (getComboBoxFont (box));
  51944. }
  51945. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51946. {
  51947. g.fillAll (label.findColour (Label::backgroundColourId));
  51948. if (! label.isBeingEdited())
  51949. {
  51950. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51951. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51952. g.setFont (label.getFont());
  51953. g.drawFittedText (label.getText(),
  51954. label.getHorizontalBorderSize(),
  51955. label.getVerticalBorderSize(),
  51956. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51957. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51958. label.getJustificationType(),
  51959. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51960. label.getMinimumHorizontalScale());
  51961. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51962. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51963. }
  51964. else if (label.isEnabled())
  51965. {
  51966. g.setColour (label.findColour (Label::outlineColourId));
  51967. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51968. }
  51969. }
  51970. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51971. int x, int y,
  51972. int width, int height,
  51973. float /*sliderPos*/,
  51974. float /*minSliderPos*/,
  51975. float /*maxSliderPos*/,
  51976. const Slider::SliderStyle /*style*/,
  51977. Slider& slider)
  51978. {
  51979. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51980. const Colour trackColour (slider.findColour (Slider::trackColourId));
  51981. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  51982. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  51983. Path indent;
  51984. if (slider.isHorizontal())
  51985. {
  51986. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  51987. const float ih = sliderRadius;
  51988. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  51989. gradCol2, 0.0f, iy + ih, false));
  51990. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  51991. width + sliderRadius, ih,
  51992. 5.0f);
  51993. g.fillPath (indent);
  51994. }
  51995. else
  51996. {
  51997. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  51998. const float iw = sliderRadius;
  51999. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52000. gradCol2, ix + iw, 0.0f, false));
  52001. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52002. iw, height + sliderRadius,
  52003. 5.0f);
  52004. g.fillPath (indent);
  52005. }
  52006. g.setColour (Colour (0x4c000000));
  52007. g.strokePath (indent, PathStrokeType (0.5f));
  52008. }
  52009. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52010. int x, int y,
  52011. int width, int height,
  52012. float sliderPos,
  52013. float minSliderPos,
  52014. float maxSliderPos,
  52015. const Slider::SliderStyle style,
  52016. Slider& slider)
  52017. {
  52018. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52019. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52020. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52021. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52022. slider.isMouseButtonDown() && slider.isEnabled()));
  52023. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52024. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52025. {
  52026. float kx, ky;
  52027. if (style == Slider::LinearVertical)
  52028. {
  52029. kx = x + width * 0.5f;
  52030. ky = sliderPos;
  52031. }
  52032. else
  52033. {
  52034. kx = sliderPos;
  52035. ky = y + height * 0.5f;
  52036. }
  52037. drawGlassSphere (g,
  52038. kx - sliderRadius,
  52039. ky - sliderRadius,
  52040. sliderRadius * 2.0f,
  52041. knobColour, outlineThickness);
  52042. }
  52043. else
  52044. {
  52045. if (style == Slider::ThreeValueVertical)
  52046. {
  52047. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52048. sliderPos - sliderRadius,
  52049. sliderRadius * 2.0f,
  52050. knobColour, outlineThickness);
  52051. }
  52052. else if (style == Slider::ThreeValueHorizontal)
  52053. {
  52054. drawGlassSphere (g,sliderPos - sliderRadius,
  52055. y + height * 0.5f - sliderRadius,
  52056. sliderRadius * 2.0f,
  52057. knobColour, outlineThickness);
  52058. }
  52059. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52060. {
  52061. const float sr = jmin (sliderRadius, width * 0.4f);
  52062. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52063. minSliderPos - sliderRadius,
  52064. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52065. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52066. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52067. }
  52068. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52069. {
  52070. const float sr = jmin (sliderRadius, height * 0.4f);
  52071. drawGlassPointer (g, minSliderPos - sr,
  52072. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52073. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52074. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52075. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52076. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52077. }
  52078. }
  52079. }
  52080. void LookAndFeel::drawLinearSlider (Graphics& g,
  52081. int x, int y,
  52082. int width, int height,
  52083. float sliderPos,
  52084. float minSliderPos,
  52085. float maxSliderPos,
  52086. const Slider::SliderStyle style,
  52087. Slider& slider)
  52088. {
  52089. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52090. if (style == Slider::LinearBar)
  52091. {
  52092. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52093. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52094. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52095. false,
  52096. isMouseOver,
  52097. isMouseOver || slider.isMouseButtonDown()));
  52098. drawShinyButtonShape (g,
  52099. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52100. baseColour,
  52101. slider.isEnabled() ? 0.9f : 0.3f,
  52102. true, true, true, true);
  52103. }
  52104. else
  52105. {
  52106. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52107. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52108. }
  52109. }
  52110. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52111. {
  52112. return jmin (7,
  52113. slider.getHeight() / 2,
  52114. slider.getWidth() / 2) + 2;
  52115. }
  52116. void LookAndFeel::drawRotarySlider (Graphics& g,
  52117. int x, int y,
  52118. int width, int height,
  52119. float sliderPos,
  52120. const float rotaryStartAngle,
  52121. const float rotaryEndAngle,
  52122. Slider& slider)
  52123. {
  52124. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52125. const float centreX = x + width * 0.5f;
  52126. const float centreY = y + height * 0.5f;
  52127. const float rx = centreX - radius;
  52128. const float ry = centreY - radius;
  52129. const float rw = radius * 2.0f;
  52130. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52131. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52132. if (radius > 12.0f)
  52133. {
  52134. if (slider.isEnabled())
  52135. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52136. else
  52137. g.setColour (Colour (0x80808080));
  52138. const float thickness = 0.7f;
  52139. {
  52140. Path filledArc;
  52141. filledArc.addPieSegment (rx, ry, rw, rw,
  52142. rotaryStartAngle,
  52143. angle,
  52144. thickness);
  52145. g.fillPath (filledArc);
  52146. }
  52147. if (thickness > 0)
  52148. {
  52149. const float innerRadius = radius * 0.2f;
  52150. Path p;
  52151. p.addTriangle (-innerRadius, 0.0f,
  52152. 0.0f, -radius * thickness * 1.1f,
  52153. innerRadius, 0.0f);
  52154. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52155. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52156. }
  52157. if (slider.isEnabled())
  52158. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52159. else
  52160. g.setColour (Colour (0x80808080));
  52161. Path outlineArc;
  52162. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52163. outlineArc.closeSubPath();
  52164. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52165. }
  52166. else
  52167. {
  52168. if (slider.isEnabled())
  52169. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52170. else
  52171. g.setColour (Colour (0x80808080));
  52172. Path p;
  52173. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52174. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52175. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52176. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52177. }
  52178. }
  52179. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52180. {
  52181. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52182. }
  52183. class SliderLabelComp : public Label
  52184. {
  52185. public:
  52186. SliderLabelComp() : Label (String::empty, String::empty) {}
  52187. ~SliderLabelComp() {}
  52188. void mouseWheelMove (const MouseEvent&, float, float) {}
  52189. };
  52190. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52191. {
  52192. Label* const l = new SliderLabelComp();
  52193. l->setJustificationType (Justification::centred);
  52194. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52195. l->setColour (Label::backgroundColourId,
  52196. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52197. : slider.findColour (Slider::textBoxBackgroundColourId));
  52198. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52199. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52200. l->setColour (TextEditor::backgroundColourId,
  52201. slider.findColour (Slider::textBoxBackgroundColourId)
  52202. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52203. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52204. return l;
  52205. }
  52206. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52207. {
  52208. return 0;
  52209. }
  52210. static const TextLayout layoutTooltipText (const String& text) throw()
  52211. {
  52212. const float tooltipFontSize = 12.0f;
  52213. const int maxToolTipWidth = 400;
  52214. const Font f (tooltipFontSize, Font::bold);
  52215. TextLayout tl (text, f);
  52216. tl.layout (maxToolTipWidth, Justification::left, true);
  52217. return tl;
  52218. }
  52219. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52220. {
  52221. const TextLayout tl (layoutTooltipText (tipText));
  52222. width = tl.getWidth() + 14;
  52223. height = tl.getHeight() + 6;
  52224. }
  52225. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52226. {
  52227. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52228. const Colour textCol (findColour (TooltipWindow::textColourId));
  52229. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52230. g.setColour (findColour (TooltipWindow::outlineColourId));
  52231. g.drawRect (0, 0, width, height, 1);
  52232. #endif
  52233. const TextLayout tl (layoutTooltipText (text));
  52234. g.setColour (findColour (TooltipWindow::textColourId));
  52235. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52236. }
  52237. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52238. {
  52239. return new TextButton (text, TRANS("click to browse for a different file"));
  52240. }
  52241. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52242. ComboBox* filenameBox,
  52243. Button* browseButton)
  52244. {
  52245. browseButton->setSize (80, filenameComp.getHeight());
  52246. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52247. if (tb != 0)
  52248. tb->changeWidthToFitText();
  52249. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52250. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52251. }
  52252. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52253. int imageX, int imageY, int imageW, int imageH,
  52254. const Colour& overlayColour,
  52255. float imageOpacity,
  52256. ImageButton& button)
  52257. {
  52258. if (! button.isEnabled())
  52259. imageOpacity *= 0.3f;
  52260. if (! overlayColour.isOpaque())
  52261. {
  52262. g.setOpacity (imageOpacity);
  52263. g.drawImage (image, imageX, imageY, imageW, imageH,
  52264. 0, 0, image->getWidth(), image->getHeight(), false);
  52265. }
  52266. if (! overlayColour.isTransparent())
  52267. {
  52268. g.setColour (overlayColour);
  52269. g.drawImage (image, imageX, imageY, imageW, imageH,
  52270. 0, 0, image->getWidth(), image->getHeight(), true);
  52271. }
  52272. }
  52273. void LookAndFeel::drawCornerResizer (Graphics& g,
  52274. int w, int h,
  52275. bool /*isMouseOver*/,
  52276. bool /*isMouseDragging*/)
  52277. {
  52278. const float lineThickness = jmin (w, h) * 0.075f;
  52279. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52280. {
  52281. g.setColour (Colours::lightgrey);
  52282. g.drawLine (w * i,
  52283. h + 1.0f,
  52284. w + 1.0f,
  52285. h * i,
  52286. lineThickness);
  52287. g.setColour (Colours::darkgrey);
  52288. g.drawLine (w * i + lineThickness,
  52289. h + 1.0f,
  52290. w + 1.0f,
  52291. h * i + lineThickness,
  52292. lineThickness);
  52293. }
  52294. }
  52295. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52296. const BorderSize& /*borders*/)
  52297. {
  52298. }
  52299. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52300. const BorderSize& /*border*/, ResizableWindow& window)
  52301. {
  52302. g.fillAll (window.getBackgroundColour());
  52303. }
  52304. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52305. const BorderSize& border, ResizableWindow&)
  52306. {
  52307. g.setColour (Colour (0x80000000));
  52308. g.drawRect (0, 0, w, h);
  52309. g.setColour (Colour (0x19000000));
  52310. g.drawRect (border.getLeft() - 1,
  52311. border.getTop() - 1,
  52312. w + 2 - border.getLeftAndRight(),
  52313. h + 2 - border.getTopAndBottom());
  52314. }
  52315. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52316. Graphics& g, int w, int h,
  52317. int titleSpaceX, int titleSpaceW,
  52318. const Image* icon,
  52319. bool drawTitleTextOnLeft)
  52320. {
  52321. const bool isActive = window.isActiveWindow();
  52322. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52323. 0.0f, 0.0f,
  52324. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52325. 0.0f, (float) h, false));
  52326. g.fillAll();
  52327. Font font (h * 0.65f, Font::bold);
  52328. g.setFont (font);
  52329. int textW = font.getStringWidth (window.getName());
  52330. int iconW = 0;
  52331. int iconH = 0;
  52332. if (icon != 0)
  52333. {
  52334. iconH = (int) font.getHeight();
  52335. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52336. }
  52337. textW = jmin (titleSpaceW, textW + iconW);
  52338. int textX = drawTitleTextOnLeft ? titleSpaceX
  52339. : jmax (titleSpaceX, (w - textW) / 2);
  52340. if (textX + textW > titleSpaceX + titleSpaceW)
  52341. textX = titleSpaceX + titleSpaceW - textW;
  52342. if (icon != 0)
  52343. {
  52344. g.setOpacity (isActive ? 1.0f : 0.6f);
  52345. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52346. RectanglePlacement::centred, false);
  52347. textX += iconW;
  52348. textW -= iconW;
  52349. }
  52350. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52351. g.setColour (findColour (DocumentWindow::textColourId));
  52352. else
  52353. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52354. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52355. }
  52356. class GlassWindowButton : public Button
  52357. {
  52358. public:
  52359. GlassWindowButton (const String& name, const Colour& col,
  52360. const Path& normalShape_,
  52361. const Path& toggledShape_) throw()
  52362. : Button (name),
  52363. colour (col),
  52364. normalShape (normalShape_),
  52365. toggledShape (toggledShape_)
  52366. {
  52367. }
  52368. ~GlassWindowButton()
  52369. {
  52370. }
  52371. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52372. {
  52373. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52374. if (! isEnabled())
  52375. alpha *= 0.5f;
  52376. float x = 0, y = 0, diam;
  52377. if (getWidth() < getHeight())
  52378. {
  52379. diam = (float) getWidth();
  52380. y = (getHeight() - getWidth()) * 0.5f;
  52381. }
  52382. else
  52383. {
  52384. diam = (float) getHeight();
  52385. y = (getWidth() - getHeight()) * 0.5f;
  52386. }
  52387. x += diam * 0.05f;
  52388. y += diam * 0.05f;
  52389. diam *= 0.9f;
  52390. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52391. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52392. g.fillEllipse (x, y, diam, diam);
  52393. x += 2.0f;
  52394. y += 2.0f;
  52395. diam -= 4.0f;
  52396. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52397. Path& p = getToggleState() ? toggledShape : normalShape;
  52398. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52399. diam * 0.4f, diam * 0.4f, true));
  52400. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52401. g.fillPath (p, t);
  52402. }
  52403. juce_UseDebuggingNewOperator
  52404. private:
  52405. Colour colour;
  52406. Path normalShape, toggledShape;
  52407. GlassWindowButton (const GlassWindowButton&);
  52408. GlassWindowButton& operator= (const GlassWindowButton&);
  52409. };
  52410. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52411. {
  52412. Path shape;
  52413. const float crossThickness = 0.25f;
  52414. if (buttonType == DocumentWindow::closeButton)
  52415. {
  52416. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52417. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52418. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52419. }
  52420. else if (buttonType == DocumentWindow::minimiseButton)
  52421. {
  52422. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52423. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52424. }
  52425. else if (buttonType == DocumentWindow::maximiseButton)
  52426. {
  52427. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52428. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52429. Path fullscreenShape;
  52430. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52431. fullscreenShape.lineTo (0.0f, 100.0f);
  52432. fullscreenShape.lineTo (0.0f, 0.0f);
  52433. fullscreenShape.lineTo (100.0f, 0.0f);
  52434. fullscreenShape.lineTo (100.0f, 45.0f);
  52435. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52436. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52437. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52438. }
  52439. jassertfalse
  52440. return 0;
  52441. }
  52442. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52443. int titleBarX,
  52444. int titleBarY,
  52445. int titleBarW,
  52446. int titleBarH,
  52447. Button* minimiseButton,
  52448. Button* maximiseButton,
  52449. Button* closeButton,
  52450. bool positionTitleBarButtonsOnLeft)
  52451. {
  52452. const int buttonW = titleBarH - titleBarH / 8;
  52453. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52454. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52455. if (closeButton != 0)
  52456. {
  52457. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52458. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52459. }
  52460. if (positionTitleBarButtonsOnLeft)
  52461. swapVariables (minimiseButton, maximiseButton);
  52462. if (maximiseButton != 0)
  52463. {
  52464. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52465. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52466. }
  52467. if (minimiseButton != 0)
  52468. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52469. }
  52470. int LookAndFeel::getDefaultMenuBarHeight()
  52471. {
  52472. return 24;
  52473. }
  52474. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52475. {
  52476. return new DropShadower (0.4f, 1, 5, 10);
  52477. }
  52478. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52479. int w, int h,
  52480. bool /*isVerticalBar*/,
  52481. bool isMouseOver,
  52482. bool isMouseDragging)
  52483. {
  52484. float alpha = 0.5f;
  52485. if (isMouseOver || isMouseDragging)
  52486. {
  52487. g.fillAll (Colour (0x190000ff));
  52488. alpha = 1.0f;
  52489. }
  52490. const float cx = w * 0.5f;
  52491. const float cy = h * 0.5f;
  52492. const float cr = jmin (w, h) * 0.4f;
  52493. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52494. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52495. true));
  52496. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52497. }
  52498. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52499. const String& text,
  52500. const Justification& position,
  52501. GroupComponent& group)
  52502. {
  52503. const float textH = 15.0f;
  52504. const float indent = 3.0f;
  52505. const float textEdgeGap = 4.0f;
  52506. float cs = 5.0f;
  52507. Font f (textH);
  52508. Path p;
  52509. float x = indent;
  52510. float y = f.getAscent() - 3.0f;
  52511. float w = jmax (0.0f, width - x * 2.0f);
  52512. float h = jmax (0.0f, height - y - indent);
  52513. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52514. const float cs2 = 2.0f * cs;
  52515. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52516. float textX = cs + textEdgeGap;
  52517. if (position.testFlags (Justification::horizontallyCentred))
  52518. textX = cs + (w - cs2 - textW) * 0.5f;
  52519. else if (position.testFlags (Justification::right))
  52520. textX = w - cs - textW - textEdgeGap;
  52521. p.startNewSubPath (x + textX + textW, y);
  52522. p.lineTo (x + w - cs, y);
  52523. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52524. p.lineTo (x + w, y + h - cs);
  52525. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52526. p.lineTo (x + cs, y + h);
  52527. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52528. p.lineTo (x, y + cs);
  52529. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52530. p.lineTo (x + textX, y);
  52531. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52532. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52533. .withMultipliedAlpha (alpha));
  52534. g.strokePath (p, PathStrokeType (2.0f));
  52535. g.setColour (group.findColour (GroupComponent::textColourId)
  52536. .withMultipliedAlpha (alpha));
  52537. g.setFont (f);
  52538. g.drawText (text,
  52539. roundToInt (x + textX), 0,
  52540. roundToInt (textW),
  52541. roundToInt (textH),
  52542. Justification::centred, true);
  52543. }
  52544. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52545. {
  52546. return 1 + tabDepth / 3;
  52547. }
  52548. int LookAndFeel::getTabButtonSpaceAroundImage()
  52549. {
  52550. return 4;
  52551. }
  52552. void LookAndFeel::createTabButtonShape (Path& p,
  52553. int width, int height,
  52554. int /*tabIndex*/,
  52555. const String& /*text*/,
  52556. Button& /*button*/,
  52557. TabbedButtonBar::Orientation orientation,
  52558. const bool /*isMouseOver*/,
  52559. const bool /*isMouseDown*/,
  52560. const bool /*isFrontTab*/)
  52561. {
  52562. const float w = (float) width;
  52563. const float h = (float) height;
  52564. float length = w;
  52565. float depth = h;
  52566. if (orientation == TabbedButtonBar::TabsAtLeft
  52567. || orientation == TabbedButtonBar::TabsAtRight)
  52568. {
  52569. swapVariables (length, depth);
  52570. }
  52571. const float indent = (float) getTabButtonOverlap ((int) depth);
  52572. const float overhang = 4.0f;
  52573. if (orientation == TabbedButtonBar::TabsAtLeft)
  52574. {
  52575. p.startNewSubPath (w, 0.0f);
  52576. p.lineTo (0.0f, indent);
  52577. p.lineTo (0.0f, h - indent);
  52578. p.lineTo (w, h);
  52579. p.lineTo (w + overhang, h + overhang);
  52580. p.lineTo (w + overhang, -overhang);
  52581. }
  52582. else if (orientation == TabbedButtonBar::TabsAtRight)
  52583. {
  52584. p.startNewSubPath (0.0f, 0.0f);
  52585. p.lineTo (w, indent);
  52586. p.lineTo (w, h - indent);
  52587. p.lineTo (0.0f, h);
  52588. p.lineTo (-overhang, h + overhang);
  52589. p.lineTo (-overhang, -overhang);
  52590. }
  52591. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52592. {
  52593. p.startNewSubPath (0.0f, 0.0f);
  52594. p.lineTo (indent, h);
  52595. p.lineTo (w - indent, h);
  52596. p.lineTo (w, 0.0f);
  52597. p.lineTo (w + overhang, -overhang);
  52598. p.lineTo (-overhang, -overhang);
  52599. }
  52600. else
  52601. {
  52602. p.startNewSubPath (0.0f, h);
  52603. p.lineTo (indent, 0.0f);
  52604. p.lineTo (w - indent, 0.0f);
  52605. p.lineTo (w, h);
  52606. p.lineTo (w + overhang, h + overhang);
  52607. p.lineTo (-overhang, h + overhang);
  52608. }
  52609. p.closeSubPath();
  52610. p = p.createPathWithRoundedCorners (3.0f);
  52611. }
  52612. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52613. const Path& path,
  52614. const Colour& preferredColour,
  52615. int /*tabIndex*/,
  52616. const String& /*text*/,
  52617. Button& button,
  52618. TabbedButtonBar::Orientation /*orientation*/,
  52619. const bool /*isMouseOver*/,
  52620. const bool /*isMouseDown*/,
  52621. const bool isFrontTab)
  52622. {
  52623. g.setColour (isFrontTab ? preferredColour
  52624. : preferredColour.withMultipliedAlpha (0.9f));
  52625. g.fillPath (path);
  52626. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52627. : TabbedButtonBar::tabOutlineColourId, false)
  52628. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52629. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52630. }
  52631. void LookAndFeel::drawTabButtonText (Graphics& g,
  52632. int x, int y, int w, int h,
  52633. const Colour& preferredBackgroundColour,
  52634. int /*tabIndex*/,
  52635. const String& text,
  52636. Button& button,
  52637. TabbedButtonBar::Orientation orientation,
  52638. const bool isMouseOver,
  52639. const bool isMouseDown,
  52640. const bool isFrontTab)
  52641. {
  52642. int length = w;
  52643. int depth = h;
  52644. if (orientation == TabbedButtonBar::TabsAtLeft
  52645. || orientation == TabbedButtonBar::TabsAtRight)
  52646. {
  52647. swapVariables (length, depth);
  52648. }
  52649. Font font (depth * 0.6f);
  52650. font.setUnderline (button.hasKeyboardFocus (false));
  52651. GlyphArrangement textLayout;
  52652. textLayout.addFittedText (font, text.trim(),
  52653. 0.0f, 0.0f, (float) length, (float) depth,
  52654. Justification::centred,
  52655. jmax (1, depth / 12));
  52656. AffineTransform transform;
  52657. if (orientation == TabbedButtonBar::TabsAtLeft)
  52658. {
  52659. transform = transform.rotated (float_Pi * -0.5f)
  52660. .translated ((float) x, (float) (y + h));
  52661. }
  52662. else if (orientation == TabbedButtonBar::TabsAtRight)
  52663. {
  52664. transform = transform.rotated (float_Pi * 0.5f)
  52665. .translated ((float) (x + w), (float) y);
  52666. }
  52667. else
  52668. {
  52669. transform = transform.translated ((float) x, (float) y);
  52670. }
  52671. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52672. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52673. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52674. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52675. else
  52676. g.setColour (preferredBackgroundColour.contrasting());
  52677. if (! (isMouseOver || isMouseDown))
  52678. g.setOpacity (0.8f);
  52679. if (! button.isEnabled())
  52680. g.setOpacity (0.3f);
  52681. textLayout.draw (g, transform);
  52682. }
  52683. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52684. const String& text,
  52685. int tabDepth,
  52686. Button&)
  52687. {
  52688. Font f (tabDepth * 0.6f);
  52689. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52690. }
  52691. void LookAndFeel::drawTabButton (Graphics& g,
  52692. int w, int h,
  52693. const Colour& preferredColour,
  52694. int tabIndex,
  52695. const String& text,
  52696. Button& button,
  52697. TabbedButtonBar::Orientation orientation,
  52698. const bool isMouseOver,
  52699. const bool isMouseDown,
  52700. const bool isFrontTab)
  52701. {
  52702. int length = w;
  52703. int depth = h;
  52704. if (orientation == TabbedButtonBar::TabsAtLeft
  52705. || orientation == TabbedButtonBar::TabsAtRight)
  52706. {
  52707. swapVariables (length, depth);
  52708. }
  52709. Path tabShape;
  52710. createTabButtonShape (tabShape, w, h,
  52711. tabIndex, text, button, orientation,
  52712. isMouseOver, isMouseDown, isFrontTab);
  52713. fillTabButtonShape (g, tabShape, preferredColour,
  52714. tabIndex, text, button, orientation,
  52715. isMouseOver, isMouseDown, isFrontTab);
  52716. const int indent = getTabButtonOverlap (depth);
  52717. int x = 0, y = 0;
  52718. if (orientation == TabbedButtonBar::TabsAtLeft
  52719. || orientation == TabbedButtonBar::TabsAtRight)
  52720. {
  52721. y += indent;
  52722. h -= indent * 2;
  52723. }
  52724. else
  52725. {
  52726. x += indent;
  52727. w -= indent * 2;
  52728. }
  52729. drawTabButtonText (g, x, y, w, h, preferredColour,
  52730. tabIndex, text, button, orientation,
  52731. isMouseOver, isMouseDown, isFrontTab);
  52732. }
  52733. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52734. int w, int h,
  52735. TabbedButtonBar& tabBar,
  52736. TabbedButtonBar::Orientation orientation)
  52737. {
  52738. const float shadowSize = 0.2f;
  52739. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52740. Rectangle<int> shadowRect;
  52741. if (orientation == TabbedButtonBar::TabsAtLeft)
  52742. {
  52743. x1 = (float) w;
  52744. x2 = w * (1.0f - shadowSize);
  52745. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52746. }
  52747. else if (orientation == TabbedButtonBar::TabsAtRight)
  52748. {
  52749. x2 = w * shadowSize;
  52750. shadowRect.setBounds (0, 0, (int) x2, h);
  52751. }
  52752. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52753. {
  52754. y2 = h * shadowSize;
  52755. shadowRect.setBounds (0, 0, w, (int) y2);
  52756. }
  52757. else
  52758. {
  52759. y1 = (float) h;
  52760. y2 = h * (1.0f - shadowSize);
  52761. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52762. }
  52763. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52764. Colours::transparentBlack, x2, y2, false));
  52765. shadowRect.expand (2, 2);
  52766. g.fillRect (shadowRect);
  52767. g.setColour (Colour (0x80000000));
  52768. if (orientation == TabbedButtonBar::TabsAtLeft)
  52769. {
  52770. g.fillRect (w - 1, 0, 1, h);
  52771. }
  52772. else if (orientation == TabbedButtonBar::TabsAtRight)
  52773. {
  52774. g.fillRect (0, 0, 1, h);
  52775. }
  52776. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52777. {
  52778. g.fillRect (0, 0, w, 1);
  52779. }
  52780. else
  52781. {
  52782. g.fillRect (0, h - 1, w, 1);
  52783. }
  52784. }
  52785. Button* LookAndFeel::createTabBarExtrasButton()
  52786. {
  52787. const float thickness = 7.0f;
  52788. const float indent = 22.0f;
  52789. Path p;
  52790. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52791. DrawablePath ellipse;
  52792. ellipse.setPath (p);
  52793. ellipse.setFill (Colour (0x99ffffff));
  52794. p.clear();
  52795. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52796. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52797. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52798. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52799. p.setUsingNonZeroWinding (false);
  52800. DrawablePath dp;
  52801. dp.setPath (p);
  52802. dp.setFill (Colour (0x59000000));
  52803. DrawableComposite normalImage;
  52804. normalImage.insertDrawable (ellipse);
  52805. normalImage.insertDrawable (dp);
  52806. dp.setFill (Colour (0xcc000000));
  52807. DrawableComposite overImage;
  52808. overImage.insertDrawable (ellipse);
  52809. overImage.insertDrawable (dp);
  52810. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52811. db->setImages (&normalImage, &overImage, 0);
  52812. return db;
  52813. }
  52814. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52815. {
  52816. g.fillAll (Colours::white);
  52817. const int w = header.getWidth();
  52818. const int h = header.getHeight();
  52819. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52820. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52821. false));
  52822. g.fillRect (0, h / 2, w, h);
  52823. g.setColour (Colour (0x33000000));
  52824. g.fillRect (0, h - 1, w, 1);
  52825. for (int i = header.getNumColumns (true); --i >= 0;)
  52826. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52827. }
  52828. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52829. int width, int height,
  52830. bool isMouseOver, bool isMouseDown,
  52831. int columnFlags)
  52832. {
  52833. if (isMouseDown)
  52834. g.fillAll (Colour (0x8899aadd));
  52835. else if (isMouseOver)
  52836. g.fillAll (Colour (0x5599aadd));
  52837. int rightOfText = width - 4;
  52838. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52839. {
  52840. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52841. const float bottom = height - top;
  52842. const float w = height * 0.5f;
  52843. const float x = rightOfText - (w * 1.25f);
  52844. rightOfText = (int) x;
  52845. Path sortArrow;
  52846. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52847. g.setColour (Colour (0x99000000));
  52848. g.fillPath (sortArrow);
  52849. }
  52850. g.setColour (Colours::black);
  52851. g.setFont (height * 0.5f, Font::bold);
  52852. const int textX = 4;
  52853. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52854. }
  52855. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52856. {
  52857. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52858. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52859. background.darker (0.1f),
  52860. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52861. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52862. false));
  52863. g.fillAll();
  52864. }
  52865. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52866. {
  52867. return createTabBarExtrasButton();
  52868. }
  52869. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52870. bool isMouseOver, bool isMouseDown,
  52871. ToolbarItemComponent& component)
  52872. {
  52873. if (isMouseDown)
  52874. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52875. else if (isMouseOver)
  52876. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52877. }
  52878. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52879. const String& text, ToolbarItemComponent& component)
  52880. {
  52881. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52882. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52883. const float fontHeight = jmin (14.0f, height * 0.85f);
  52884. g.setFont (fontHeight);
  52885. g.drawFittedText (text,
  52886. x, y, width, height,
  52887. Justification::centred,
  52888. jmax (1, height / (int) fontHeight));
  52889. }
  52890. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52891. bool isOpen, int width, int height)
  52892. {
  52893. const int buttonSize = (height * 3) / 4;
  52894. const int buttonIndent = (height - buttonSize) / 2;
  52895. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52896. const int textX = buttonIndent * 2 + buttonSize + 2;
  52897. g.setColour (Colours::black);
  52898. g.setFont (height * 0.7f, Font::bold);
  52899. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52900. }
  52901. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52902. PropertyComponent&)
  52903. {
  52904. g.setColour (Colour (0x66ffffff));
  52905. g.fillRect (0, 0, width, height - 1);
  52906. }
  52907. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52908. PropertyComponent& component)
  52909. {
  52910. g.setColour (Colours::black);
  52911. if (! component.isEnabled())
  52912. g.setOpacity (0.6f);
  52913. g.setFont (jmin (height, 24) * 0.65f);
  52914. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52915. g.drawFittedText (component.getName(),
  52916. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52917. Justification::centredLeft, 2);
  52918. }
  52919. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52920. {
  52921. return Rectangle<int> (component.getWidth() / 3, 1,
  52922. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52923. }
  52924. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52925. const String& instructions,
  52926. GlyphArrangement& text,
  52927. int width)
  52928. {
  52929. text.clear();
  52930. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52931. 8.0f, 22.0f, width - 16.0f,
  52932. Justification::centred);
  52933. text.addJustifiedText (Font (14.0f), instructions,
  52934. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52935. Justification::centred);
  52936. }
  52937. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52938. const String& filename, Image* icon,
  52939. const String& fileSizeDescription,
  52940. const String& fileTimeDescription,
  52941. const bool isDirectory,
  52942. const bool isItemSelected,
  52943. const int /*itemIndex*/)
  52944. {
  52945. if (isItemSelected)
  52946. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52947. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52948. g.setFont (height * 0.7f);
  52949. Image* im = icon;
  52950. Image* toRelease = 0;
  52951. if (im == 0)
  52952. {
  52953. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52954. : getDefaultDocumentFileImage());
  52955. }
  52956. const int x = 32;
  52957. if (im != 0)
  52958. {
  52959. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52960. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52961. false);
  52962. ImageCache::release (toRelease);
  52963. }
  52964. if (width > 450 && ! isDirectory)
  52965. {
  52966. const int sizeX = roundToInt (width * 0.7f);
  52967. const int dateX = roundToInt (width * 0.8f);
  52968. g.drawFittedText (filename,
  52969. x, 0, sizeX - x, height,
  52970. Justification::centredLeft, 1);
  52971. g.setFont (height * 0.5f);
  52972. g.setColour (Colours::darkgrey);
  52973. if (! isDirectory)
  52974. {
  52975. g.drawFittedText (fileSizeDescription,
  52976. sizeX, 0, dateX - sizeX - 8, height,
  52977. Justification::centredRight, 1);
  52978. g.drawFittedText (fileTimeDescription,
  52979. dateX, 0, width - 8 - dateX, height,
  52980. Justification::centredRight, 1);
  52981. }
  52982. }
  52983. else
  52984. {
  52985. g.drawFittedText (filename,
  52986. x, 0, width - x, height,
  52987. Justification::centredLeft, 1);
  52988. }
  52989. }
  52990. Button* LookAndFeel::createFileBrowserGoUpButton()
  52991. {
  52992. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  52993. Path arrowPath;
  52994. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  52995. DrawablePath arrowImage;
  52996. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  52997. arrowImage.setPath (arrowPath);
  52998. goUpButton->setImages (&arrowImage);
  52999. return goUpButton;
  53000. }
  53001. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53002. DirectoryContentsDisplayComponent* fileListComponent,
  53003. FilePreviewComponent* previewComp,
  53004. ComboBox* currentPathBox,
  53005. TextEditor* filenameBox,
  53006. Button* goUpButton)
  53007. {
  53008. const int x = 8;
  53009. int w = browserComp.getWidth() - x - x;
  53010. if (previewComp != 0)
  53011. {
  53012. const int previewWidth = w / 3;
  53013. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53014. w -= previewWidth + 4;
  53015. }
  53016. int y = 4;
  53017. const int controlsHeight = 22;
  53018. const int bottomSectionHeight = controlsHeight + 8;
  53019. const int upButtonWidth = 50;
  53020. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53021. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53022. y += controlsHeight + 4;
  53023. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53024. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53025. y = listAsComp->getBottom() + 4;
  53026. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53027. }
  53028. Image* LookAndFeel::getDefaultFolderImage()
  53029. {
  53030. 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,
  53031. 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,
  53032. 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,
  53033. 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,
  53034. 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,
  53035. 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,
  53036. 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,
  53037. 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,
  53038. 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,
  53039. 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,
  53040. 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,
  53041. 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,
  53042. 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,
  53043. 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,
  53044. 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,
  53045. 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,
  53046. 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,
  53047. 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,
  53048. 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,
  53049. 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,
  53050. 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,
  53051. 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,
  53052. 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,
  53053. 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,
  53054. 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,
  53055. 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,
  53056. 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,
  53057. 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,
  53058. 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,
  53059. 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,
  53060. 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,
  53061. 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,
  53062. 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,
  53063. 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,
  53064. 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,
  53065. 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,
  53066. 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,
  53067. 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,
  53068. 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,
  53069. 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,
  53070. 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,
  53071. 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,
  53072. 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,
  53073. 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};
  53074. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53075. }
  53076. Image* LookAndFeel::getDefaultDocumentFileImage()
  53077. {
  53078. 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,
  53079. 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,
  53080. 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,
  53081. 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,
  53082. 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,
  53083. 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,
  53084. 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,
  53085. 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,
  53086. 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,
  53087. 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,
  53088. 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,
  53089. 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,
  53090. 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,
  53091. 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,
  53092. 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,
  53093. 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,
  53094. 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,
  53095. 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,
  53096. 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,
  53097. 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,
  53098. 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,
  53099. 174,66,96,130,0,0};
  53100. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53101. }
  53102. void LookAndFeel::playAlertSound()
  53103. {
  53104. PlatformUtilities::beep();
  53105. }
  53106. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53107. {
  53108. g.setColour (Colours::white.withAlpha (0.7f));
  53109. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53110. g.setColour (Colours::black.withAlpha (0.2f));
  53111. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53112. const int totalBlocks = 7;
  53113. const int numBlocks = roundToInt (totalBlocks * level);
  53114. const float w = (width - 6.0f) / (float) totalBlocks;
  53115. for (int i = 0; i < totalBlocks; ++i)
  53116. {
  53117. if (i >= numBlocks)
  53118. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53119. else
  53120. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53121. : Colours::red);
  53122. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53123. }
  53124. }
  53125. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53126. {
  53127. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53128. if (keyDescription.isNotEmpty())
  53129. {
  53130. if (button.isEnabled())
  53131. {
  53132. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53133. g.fillAll (textColour.withAlpha (alpha));
  53134. g.setOpacity (0.3f);
  53135. g.drawBevel (0, 0, width, height, 2);
  53136. }
  53137. g.setColour (textColour);
  53138. g.setFont (height * 0.6f);
  53139. g.drawFittedText (keyDescription,
  53140. 3, 0, width - 6, height,
  53141. Justification::centred, 1);
  53142. }
  53143. else
  53144. {
  53145. const float thickness = 7.0f;
  53146. const float indent = 22.0f;
  53147. Path p;
  53148. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53149. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53150. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53151. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53152. p.setUsingNonZeroWinding (false);
  53153. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53154. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53155. }
  53156. if (button.hasKeyboardFocus (false))
  53157. {
  53158. g.setColour (textColour.withAlpha (0.4f));
  53159. g.drawRect (0, 0, width, height);
  53160. }
  53161. }
  53162. static void createRoundedPath (Path& p,
  53163. const float x, const float y,
  53164. const float w, const float h,
  53165. const float cs,
  53166. const bool curveTopLeft, const bool curveTopRight,
  53167. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53168. {
  53169. const float cs2 = 2.0f * cs;
  53170. if (curveTopLeft)
  53171. {
  53172. p.startNewSubPath (x, y + cs);
  53173. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53174. }
  53175. else
  53176. {
  53177. p.startNewSubPath (x, y);
  53178. }
  53179. if (curveTopRight)
  53180. {
  53181. p.lineTo (x + w - cs, y);
  53182. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53183. }
  53184. else
  53185. {
  53186. p.lineTo (x + w, y);
  53187. }
  53188. if (curveBottomRight)
  53189. {
  53190. p.lineTo (x + w, y + h - cs);
  53191. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53192. }
  53193. else
  53194. {
  53195. p.lineTo (x + w, y + h);
  53196. }
  53197. if (curveBottomLeft)
  53198. {
  53199. p.lineTo (x + cs, y + h);
  53200. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53201. }
  53202. else
  53203. {
  53204. p.lineTo (x, y + h);
  53205. }
  53206. p.closeSubPath();
  53207. }
  53208. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53209. float x, float y, float w, float h,
  53210. float maxCornerSize,
  53211. const Colour& baseColour,
  53212. const float strokeWidth,
  53213. const bool flatOnLeft,
  53214. const bool flatOnRight,
  53215. const bool flatOnTop,
  53216. const bool flatOnBottom) throw()
  53217. {
  53218. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53219. return;
  53220. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53221. Path outline;
  53222. createRoundedPath (outline, x, y, w, h, cs,
  53223. ! (flatOnLeft || flatOnTop),
  53224. ! (flatOnRight || flatOnTop),
  53225. ! (flatOnLeft || flatOnBottom),
  53226. ! (flatOnRight || flatOnBottom));
  53227. ColourGradient cg (baseColour, 0.0f, y,
  53228. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53229. false);
  53230. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53231. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53232. g.setGradientFill (cg);
  53233. g.fillPath (outline);
  53234. g.setColour (Colour (0x80000000));
  53235. g.strokePath (outline, PathStrokeType (strokeWidth));
  53236. }
  53237. void LookAndFeel::drawGlassSphere (Graphics& g,
  53238. const float x, const float y,
  53239. const float diameter,
  53240. const Colour& colour,
  53241. const float outlineThickness) throw()
  53242. {
  53243. if (diameter <= outlineThickness)
  53244. return;
  53245. Path p;
  53246. p.addEllipse (x, y, diameter, diameter);
  53247. {
  53248. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53249. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53250. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53251. g.setGradientFill (cg);
  53252. g.fillPath (p);
  53253. }
  53254. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53255. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53256. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53257. ColourGradient cg (Colours::transparentBlack,
  53258. x + diameter * 0.5f, y + diameter * 0.5f,
  53259. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53260. x, y + diameter * 0.5f, true);
  53261. cg.addColour (0.7, Colours::transparentBlack);
  53262. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53263. g.setGradientFill (cg);
  53264. g.fillPath (p);
  53265. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53266. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53267. }
  53268. void LookAndFeel::drawGlassPointer (Graphics& g,
  53269. const float x, const float y,
  53270. const float diameter,
  53271. const Colour& colour, const float outlineThickness,
  53272. const int direction) throw()
  53273. {
  53274. if (diameter <= outlineThickness)
  53275. return;
  53276. Path p;
  53277. p.startNewSubPath (x + diameter * 0.5f, y);
  53278. p.lineTo (x + diameter, y + diameter * 0.6f);
  53279. p.lineTo (x + diameter, y + diameter);
  53280. p.lineTo (x, y + diameter);
  53281. p.lineTo (x, y + diameter * 0.6f);
  53282. p.closeSubPath();
  53283. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53284. {
  53285. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53286. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53287. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53288. g.setGradientFill (cg);
  53289. g.fillPath (p);
  53290. }
  53291. ColourGradient cg (Colours::transparentBlack,
  53292. x + diameter * 0.5f, y + diameter * 0.5f,
  53293. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53294. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53295. cg.addColour (0.5, Colours::transparentBlack);
  53296. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53297. g.setGradientFill (cg);
  53298. g.fillPath (p);
  53299. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53300. g.strokePath (p, PathStrokeType (outlineThickness));
  53301. }
  53302. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53303. const float x, const float y,
  53304. const float width, const float height,
  53305. const Colour& colour,
  53306. const float outlineThickness,
  53307. const float cornerSize,
  53308. const bool flatOnLeft,
  53309. const bool flatOnRight,
  53310. const bool flatOnTop,
  53311. const bool flatOnBottom) throw()
  53312. {
  53313. if (width <= outlineThickness || height <= outlineThickness)
  53314. return;
  53315. const int intX = (int) x;
  53316. const int intY = (int) y;
  53317. const int intW = (int) width;
  53318. const int intH = (int) height;
  53319. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53320. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53321. const int intEdge = (int) edgeBlurRadius;
  53322. Path outline;
  53323. createRoundedPath (outline, x, y, width, height, cs,
  53324. ! (flatOnLeft || flatOnTop),
  53325. ! (flatOnRight || flatOnTop),
  53326. ! (flatOnLeft || flatOnBottom),
  53327. ! (flatOnRight || flatOnBottom));
  53328. {
  53329. ColourGradient cg (colour.darker (0.2f), 0, y,
  53330. colour.darker (0.2f), 0, y + height, false);
  53331. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53332. cg.addColour (0.4, colour);
  53333. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53334. g.setGradientFill (cg);
  53335. g.fillPath (outline);
  53336. }
  53337. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53338. colour.darker (0.2f), x, y + height * 0.5f, true);
  53339. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53340. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53341. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53342. {
  53343. g.saveState();
  53344. g.setGradientFill (cg);
  53345. g.reduceClipRegion (intX, intY, intEdge, intH);
  53346. g.fillPath (outline);
  53347. g.restoreState();
  53348. }
  53349. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53350. {
  53351. cg.x1 = x + width - edgeBlurRadius;
  53352. cg.x2 = x + width;
  53353. g.saveState();
  53354. g.setGradientFill (cg);
  53355. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53356. g.fillPath (outline);
  53357. g.restoreState();
  53358. }
  53359. {
  53360. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53361. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53362. Path highlight;
  53363. createRoundedPath (highlight,
  53364. x + leftIndent,
  53365. y + cs * 0.1f,
  53366. width - (leftIndent + rightIndent),
  53367. height * 0.4f, cs * 0.4f,
  53368. ! (flatOnLeft || flatOnTop),
  53369. ! (flatOnRight || flatOnTop),
  53370. ! (flatOnLeft || flatOnBottom),
  53371. ! (flatOnRight || flatOnBottom));
  53372. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53373. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53374. g.fillPath (highlight);
  53375. }
  53376. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53377. g.strokePath (outline, PathStrokeType (outlineThickness));
  53378. }
  53379. END_JUCE_NAMESPACE
  53380. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53381. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53382. BEGIN_JUCE_NAMESPACE
  53383. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53384. {
  53385. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53386. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53387. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53388. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53389. setColour (Slider::thumbColourId, Colours::white);
  53390. setColour (Slider::trackColourId, Colour (0x7f000000));
  53391. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53392. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53393. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53394. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53395. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53396. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53397. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53398. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53399. }
  53400. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53401. {
  53402. }
  53403. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53404. Button& button,
  53405. const Colour& backgroundColour,
  53406. bool isMouseOverButton,
  53407. bool isButtonDown)
  53408. {
  53409. const int width = button.getWidth();
  53410. const int height = button.getHeight();
  53411. const float indent = 2.0f;
  53412. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53413. roundToInt (height * 0.4f));
  53414. Path p;
  53415. p.addRoundedRectangle (indent, indent,
  53416. width - indent * 2.0f,
  53417. height - indent * 2.0f,
  53418. (float) cornerSize);
  53419. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53420. if (isMouseOverButton)
  53421. {
  53422. if (isButtonDown)
  53423. bc = bc.brighter();
  53424. else if (bc.getBrightness() > 0.5f)
  53425. bc = bc.darker (0.1f);
  53426. else
  53427. bc = bc.brighter (0.1f);
  53428. }
  53429. g.setColour (bc);
  53430. g.fillPath (p);
  53431. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53432. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53433. }
  53434. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53435. Component& /*component*/,
  53436. float x, float y, float w, float h,
  53437. const bool ticked,
  53438. const bool isEnabled,
  53439. const bool /*isMouseOverButton*/,
  53440. const bool isButtonDown)
  53441. {
  53442. Path box;
  53443. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53444. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53445. : Colours::lightgrey.withAlpha (0.1f));
  53446. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53447. g.fillPath (box, trans);
  53448. g.setColour (Colours::black.withAlpha (0.6f));
  53449. g.strokePath (box, PathStrokeType (0.9f), trans);
  53450. if (ticked)
  53451. {
  53452. Path tick;
  53453. tick.startNewSubPath (1.5f, 3.0f);
  53454. tick.lineTo (3.0f, 6.0f);
  53455. tick.lineTo (6.0f, 0.0f);
  53456. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53457. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53458. }
  53459. }
  53460. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53461. ToggleButton& button,
  53462. bool isMouseOverButton,
  53463. bool isButtonDown)
  53464. {
  53465. if (button.hasKeyboardFocus (true))
  53466. {
  53467. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53468. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53469. }
  53470. const int tickWidth = jmin (20, button.getHeight() - 4);
  53471. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53472. (float) tickWidth, (float) tickWidth,
  53473. button.getToggleState(),
  53474. button.isEnabled(),
  53475. isMouseOverButton,
  53476. isButtonDown);
  53477. g.setColour (button.findColour (ToggleButton::textColourId));
  53478. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53479. if (! button.isEnabled())
  53480. g.setOpacity (0.5f);
  53481. const int textX = tickWidth + 5;
  53482. g.drawFittedText (button.getButtonText(),
  53483. textX, 4,
  53484. button.getWidth() - textX - 2, button.getHeight() - 8,
  53485. Justification::centredLeft, 10);
  53486. }
  53487. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53488. int width, int height,
  53489. double progress, const String& textToShow)
  53490. {
  53491. if (progress < 0 || progress >= 1.0)
  53492. {
  53493. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53494. }
  53495. else
  53496. {
  53497. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53498. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53499. g.fillAll (background);
  53500. g.setColour (foreground);
  53501. g.fillRect (1, 1,
  53502. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53503. height - 2);
  53504. if (textToShow.isNotEmpty())
  53505. {
  53506. g.setColour (Colour::contrasting (background, foreground));
  53507. g.setFont (height * 0.6f);
  53508. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53509. }
  53510. }
  53511. }
  53512. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53513. ScrollBar& bar,
  53514. int width, int height,
  53515. int buttonDirection,
  53516. bool isScrollbarVertical,
  53517. bool isMouseOverButton,
  53518. bool isButtonDown)
  53519. {
  53520. if (isScrollbarVertical)
  53521. width -= 2;
  53522. else
  53523. height -= 2;
  53524. Path p;
  53525. if (buttonDirection == 0)
  53526. p.addTriangle (width * 0.5f, height * 0.2f,
  53527. width * 0.1f, height * 0.7f,
  53528. width * 0.9f, height * 0.7f);
  53529. else if (buttonDirection == 1)
  53530. p.addTriangle (width * 0.8f, height * 0.5f,
  53531. width * 0.3f, height * 0.1f,
  53532. width * 0.3f, height * 0.9f);
  53533. else if (buttonDirection == 2)
  53534. p.addTriangle (width * 0.5f, height * 0.8f,
  53535. width * 0.1f, height * 0.3f,
  53536. width * 0.9f, height * 0.3f);
  53537. else if (buttonDirection == 3)
  53538. p.addTriangle (width * 0.2f, height * 0.5f,
  53539. width * 0.7f, height * 0.1f,
  53540. width * 0.7f, height * 0.9f);
  53541. if (isButtonDown)
  53542. g.setColour (Colours::white);
  53543. else if (isMouseOverButton)
  53544. g.setColour (Colours::white.withAlpha (0.7f));
  53545. else
  53546. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53547. g.fillPath (p);
  53548. g.setColour (Colours::black.withAlpha (0.5f));
  53549. g.strokePath (p, PathStrokeType (0.5f));
  53550. }
  53551. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53552. ScrollBar& bar,
  53553. int x, int y,
  53554. int width, int height,
  53555. bool isScrollbarVertical,
  53556. int thumbStartPosition,
  53557. int thumbSize,
  53558. bool isMouseOver,
  53559. bool isMouseDown)
  53560. {
  53561. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53562. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53563. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53564. if (thumbSize > 0.0f)
  53565. {
  53566. Rectangle<int> thumb;
  53567. if (isScrollbarVertical)
  53568. {
  53569. width -= 2;
  53570. g.fillRect (x + roundToInt (width * 0.35f), y,
  53571. roundToInt (width * 0.3f), height);
  53572. thumb.setBounds (x + 1, thumbStartPosition,
  53573. width - 2, thumbSize);
  53574. }
  53575. else
  53576. {
  53577. height -= 2;
  53578. g.fillRect (x, y + roundToInt (height * 0.35f),
  53579. width, roundToInt (height * 0.3f));
  53580. thumb.setBounds (thumbStartPosition, y + 1,
  53581. thumbSize, height - 2);
  53582. }
  53583. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53584. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53585. g.fillRect (thumb);
  53586. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53587. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53588. if (thumbSize > 16)
  53589. {
  53590. for (int i = 3; --i >= 0;)
  53591. {
  53592. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53593. g.setColour (Colours::black.withAlpha (0.15f));
  53594. if (isScrollbarVertical)
  53595. {
  53596. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53597. g.setColour (Colours::white.withAlpha (0.15f));
  53598. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53599. }
  53600. else
  53601. {
  53602. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53603. g.setColour (Colours::white.withAlpha (0.15f));
  53604. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53605. }
  53606. }
  53607. }
  53608. }
  53609. }
  53610. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53611. {
  53612. return &scrollbarShadow;
  53613. }
  53614. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53615. {
  53616. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53617. g.setColour (Colours::black.withAlpha (0.6f));
  53618. g.drawRect (0, 0, width, height);
  53619. }
  53620. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53621. bool, MenuBarComponent& menuBar)
  53622. {
  53623. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53624. }
  53625. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53626. {
  53627. if (textEditor.isEnabled())
  53628. {
  53629. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53630. g.drawRect (0, 0, width, height);
  53631. }
  53632. }
  53633. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53634. const bool isButtonDown,
  53635. int buttonX, int buttonY,
  53636. int buttonW, int buttonH,
  53637. ComboBox& box)
  53638. {
  53639. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53640. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53641. : ComboBox::backgroundColourId));
  53642. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53643. g.setColour (box.findColour (ComboBox::outlineColourId));
  53644. g.drawRect (0, 0, width, height);
  53645. const float arrowX = 0.2f;
  53646. const float arrowH = 0.3f;
  53647. if (box.isEnabled())
  53648. {
  53649. Path p;
  53650. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53651. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53652. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53653. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53654. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53655. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53656. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53657. : ComboBox::buttonColourId));
  53658. g.fillPath (p);
  53659. }
  53660. }
  53661. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53662. {
  53663. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53664. f.setHorizontalScale (0.9f);
  53665. return f;
  53666. }
  53667. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53668. {
  53669. Path p;
  53670. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53671. g.setColour (fill);
  53672. g.fillPath (p);
  53673. g.setColour (outline);
  53674. g.strokePath (p, PathStrokeType (0.3f));
  53675. }
  53676. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53677. int x, int y,
  53678. int w, int h,
  53679. float sliderPos,
  53680. float minSliderPos,
  53681. float maxSliderPos,
  53682. const Slider::SliderStyle style,
  53683. Slider& slider)
  53684. {
  53685. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53686. if (style == Slider::LinearBar)
  53687. {
  53688. g.setColour (slider.findColour (Slider::thumbColourId));
  53689. g.fillRect (x, y, (int) sliderPos - x, h);
  53690. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53691. g.drawRect (x, y, (int) sliderPos - x, h);
  53692. }
  53693. else
  53694. {
  53695. g.setColour (slider.findColour (Slider::trackColourId)
  53696. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53697. if (slider.isHorizontal())
  53698. {
  53699. g.fillRect (x, y + roundToInt (h * 0.6f),
  53700. w, roundToInt (h * 0.2f));
  53701. }
  53702. else
  53703. {
  53704. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53705. jmin (4, roundToInt (w * 0.2f)), h);
  53706. }
  53707. float alpha = 0.35f;
  53708. if (slider.isEnabled())
  53709. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53710. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53711. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53712. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53713. {
  53714. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53715. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53716. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53717. fill, outline);
  53718. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53719. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53720. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53721. fill, outline);
  53722. }
  53723. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53724. {
  53725. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53726. minSliderPos - 7.0f, y + h * 0.9f ,
  53727. minSliderPos, y + h * 0.9f,
  53728. fill, outline);
  53729. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53730. maxSliderPos, y + h * 0.9f,
  53731. maxSliderPos + 7.0f, y + h * 0.9f,
  53732. fill, outline);
  53733. }
  53734. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53735. {
  53736. drawTriangle (g, sliderPos, y + h * 0.9f,
  53737. sliderPos - 7.0f, y + h * 0.2f,
  53738. sliderPos + 7.0f, y + h * 0.2f,
  53739. fill, outline);
  53740. }
  53741. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53742. {
  53743. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53744. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53745. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53746. fill, outline);
  53747. }
  53748. }
  53749. }
  53750. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53751. {
  53752. if (isIncrement)
  53753. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53754. else
  53755. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53756. }
  53757. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53758. {
  53759. return &scrollbarShadow;
  53760. }
  53761. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53762. {
  53763. return 8;
  53764. }
  53765. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53766. int w, int h,
  53767. bool isMouseOver,
  53768. bool isMouseDragging)
  53769. {
  53770. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53771. : Colours::darkgrey);
  53772. const float lineThickness = jmin (w, h) * 0.1f;
  53773. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53774. {
  53775. g.drawLine (w * i,
  53776. h + 1.0f,
  53777. w + 1.0f,
  53778. h * i,
  53779. lineThickness);
  53780. }
  53781. }
  53782. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53783. {
  53784. Path shape;
  53785. if (buttonType == DocumentWindow::closeButton)
  53786. {
  53787. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53788. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53789. ShapeButton* const b = new ShapeButton ("close",
  53790. Colour (0x7fff3333),
  53791. Colour (0xd7ff3333),
  53792. Colour (0xf7ff3333));
  53793. b->setShape (shape, true, true, true);
  53794. return b;
  53795. }
  53796. else if (buttonType == DocumentWindow::minimiseButton)
  53797. {
  53798. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53799. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53800. DrawablePath dp;
  53801. dp.setPath (shape);
  53802. dp.setFill (Colours::black.withAlpha (0.3f));
  53803. b->setImages (&dp);
  53804. return b;
  53805. }
  53806. else if (buttonType == DocumentWindow::maximiseButton)
  53807. {
  53808. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53809. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53810. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53811. DrawablePath dp;
  53812. dp.setPath (shape);
  53813. dp.setFill (Colours::black.withAlpha (0.3f));
  53814. b->setImages (&dp);
  53815. return b;
  53816. }
  53817. jassertfalse
  53818. return 0;
  53819. }
  53820. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53821. int titleBarX,
  53822. int titleBarY,
  53823. int titleBarW,
  53824. int titleBarH,
  53825. Button* minimiseButton,
  53826. Button* maximiseButton,
  53827. Button* closeButton,
  53828. bool positionTitleBarButtonsOnLeft)
  53829. {
  53830. titleBarY += titleBarH / 8;
  53831. titleBarH -= titleBarH / 4;
  53832. const int buttonW = titleBarH;
  53833. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53834. : titleBarX + titleBarW - buttonW - 4;
  53835. if (closeButton != 0)
  53836. {
  53837. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53838. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53839. : -(buttonW + buttonW / 5);
  53840. }
  53841. if (positionTitleBarButtonsOnLeft)
  53842. swapVariables (minimiseButton, maximiseButton);
  53843. if (maximiseButton != 0)
  53844. {
  53845. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53846. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53847. }
  53848. if (minimiseButton != 0)
  53849. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53850. }
  53851. END_JUCE_NAMESPACE
  53852. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53853. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53854. BEGIN_JUCE_NAMESPACE
  53855. class DummyMenuComponent : public Component
  53856. {
  53857. DummyMenuComponent (const DummyMenuComponent&);
  53858. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53859. public:
  53860. DummyMenuComponent() {}
  53861. ~DummyMenuComponent() {}
  53862. void inputAttemptWhenModal()
  53863. {
  53864. exitModalState (0);
  53865. }
  53866. };
  53867. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53868. : model (0),
  53869. itemUnderMouse (-1),
  53870. currentPopupIndex (-1),
  53871. indexToShowAgain (-1),
  53872. lastMouseX (0),
  53873. lastMouseY (0),
  53874. inModalState (false)
  53875. {
  53876. setRepaintsOnMouseActivity (true);
  53877. setWantsKeyboardFocus (false);
  53878. setMouseClickGrabsKeyboardFocus (false);
  53879. setModel (model_);
  53880. }
  53881. MenuBarComponent::~MenuBarComponent()
  53882. {
  53883. setModel (0);
  53884. Desktop::getInstance().removeGlobalMouseListener (this);
  53885. currentPopup = 0;
  53886. }
  53887. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53888. {
  53889. if (model != newModel)
  53890. {
  53891. if (model != 0)
  53892. model->removeListener (this);
  53893. model = newModel;
  53894. if (model != 0)
  53895. model->addListener (this);
  53896. repaint();
  53897. menuBarItemsChanged (0);
  53898. }
  53899. }
  53900. void MenuBarComponent::paint (Graphics& g)
  53901. {
  53902. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53903. getLookAndFeel().drawMenuBarBackground (g,
  53904. getWidth(),
  53905. getHeight(),
  53906. isMouseOverBar,
  53907. *this);
  53908. if (model != 0)
  53909. {
  53910. for (int i = 0; i < menuNames.size(); ++i)
  53911. {
  53912. g.saveState();
  53913. g.setOrigin (xPositions [i], 0);
  53914. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53915. getLookAndFeel().drawMenuBarItem (g,
  53916. xPositions[i + 1] - xPositions[i],
  53917. getHeight(),
  53918. i,
  53919. menuNames[i],
  53920. i == itemUnderMouse,
  53921. i == currentPopupIndex,
  53922. isMouseOverBar,
  53923. *this);
  53924. g.restoreState();
  53925. }
  53926. }
  53927. }
  53928. void MenuBarComponent::resized()
  53929. {
  53930. xPositions.clear();
  53931. int x = 2;
  53932. xPositions.add (x);
  53933. for (int i = 0; i < menuNames.size(); ++i)
  53934. {
  53935. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53936. xPositions.add (x);
  53937. }
  53938. }
  53939. int MenuBarComponent::getItemAt (const int x, const int y)
  53940. {
  53941. for (int i = 0; i < xPositions.size(); ++i)
  53942. if (x >= xPositions[i] && x < xPositions[i + 1])
  53943. return reallyContains (x, y, true) ? i : -1;
  53944. return -1;
  53945. }
  53946. void MenuBarComponent::repaintMenuItem (int index)
  53947. {
  53948. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53949. {
  53950. const int x1 = xPositions [index];
  53951. const int x2 = xPositions [index + 1];
  53952. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53953. }
  53954. }
  53955. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53956. {
  53957. const int newItem = getItemAt (x, y);
  53958. if (itemUnderMouse != newItem)
  53959. {
  53960. repaintMenuItem (itemUnderMouse);
  53961. itemUnderMouse = newItem;
  53962. repaintMenuItem (itemUnderMouse);
  53963. }
  53964. }
  53965. void MenuBarComponent::hideCurrentMenu()
  53966. {
  53967. currentPopup = 0;
  53968. repaint();
  53969. }
  53970. void MenuBarComponent::showMenu (int index)
  53971. {
  53972. if (index != currentPopupIndex)
  53973. {
  53974. if (inModalState)
  53975. {
  53976. hideCurrentMenu();
  53977. indexToShowAgain = index;
  53978. return;
  53979. }
  53980. indexToShowAgain = -1;
  53981. currentPopupIndex = -1;
  53982. itemUnderMouse = index;
  53983. currentPopup = 0;
  53984. menuBarItemsChanged (0);
  53985. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  53986. Component::SafePointer<Component> deletionChecker (this);
  53987. enterModalState (false);
  53988. inModalState = true;
  53989. int result = 0;
  53990. ApplicationCommandManager* managerOfChosenCommand = 0;
  53991. Desktop::getInstance().addGlobalMouseListener (this);
  53992. for (;;)
  53993. {
  53994. const int x = getScreenX() + xPositions [itemUnderMouse];
  53995. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  53996. currentPopupIndex = itemUnderMouse;
  53997. indexToShowAgain = -1;
  53998. repaint();
  53999. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54000. {
  54001. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54002. menuNames [itemUnderMouse]));
  54003. if (m.lookAndFeel == 0)
  54004. m.setLookAndFeel (&getLookAndFeel());
  54005. currentPopup = m.createMenuComponent (x, getScreenY(),
  54006. w, getHeight(),
  54007. 0, w, 0, 0,
  54008. true, this,
  54009. &managerOfChosenCommand,
  54010. this);
  54011. }
  54012. if (currentPopup == 0)
  54013. {
  54014. currentPopup = new DummyMenuComponent();
  54015. addAndMakeVisible (currentPopup);
  54016. }
  54017. currentPopup->enterModalState (false);
  54018. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54019. // be stuck behind other comps that are already modal..
  54020. result = currentPopup->runModalLoop();
  54021. if (deletionChecker == 0)
  54022. return;
  54023. const int lastPopupIndex = currentPopupIndex;
  54024. currentPopup = 0;
  54025. currentPopupIndex = -1;
  54026. if (result != 0)
  54027. {
  54028. topLevelIndexClicked = lastPopupIndex;
  54029. break;
  54030. }
  54031. else if (indexToShowAgain >= 0)
  54032. {
  54033. menuBarItemsChanged (0);
  54034. repaint();
  54035. itemUnderMouse = indexToShowAgain;
  54036. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54037. break;
  54038. }
  54039. else
  54040. {
  54041. break;
  54042. }
  54043. }
  54044. Desktop::getInstance().removeGlobalMouseListener (this);
  54045. inModalState = false;
  54046. exitModalState (0);
  54047. if (prevFocused != 0)
  54048. prevFocused->grabKeyboardFocus();
  54049. const Point<int> mousePos (getMouseXYRelative());
  54050. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54051. repaint();
  54052. if (result != 0)
  54053. {
  54054. if (managerOfChosenCommand != 0)
  54055. {
  54056. ApplicationCommandTarget::InvocationInfo info (result);
  54057. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54058. managerOfChosenCommand->invoke (info, true);
  54059. }
  54060. postCommandMessage (result);
  54061. }
  54062. }
  54063. }
  54064. void MenuBarComponent::handleCommandMessage (int commandId)
  54065. {
  54066. if (model != 0)
  54067. model->menuItemSelected (commandId, topLevelIndexClicked);
  54068. }
  54069. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54070. {
  54071. if (e.eventComponent == this)
  54072. updateItemUnderMouse (e.x, e.y);
  54073. }
  54074. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54075. {
  54076. if (e.eventComponent == this)
  54077. updateItemUnderMouse (e.x, e.y);
  54078. }
  54079. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54080. {
  54081. if (currentPopupIndex < 0)
  54082. {
  54083. const MouseEvent e2 (e.getEventRelativeTo (this));
  54084. updateItemUnderMouse (e2.x, e2.y);
  54085. currentPopupIndex = -2;
  54086. showMenu (itemUnderMouse);
  54087. }
  54088. }
  54089. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54090. {
  54091. const MouseEvent e2 (e.getEventRelativeTo (this));
  54092. const int item = getItemAt (e2.x, e2.y);
  54093. if (item >= 0)
  54094. showMenu (item);
  54095. }
  54096. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54097. {
  54098. const MouseEvent e2 (e.getEventRelativeTo (this));
  54099. updateItemUnderMouse (e2.x, e2.y);
  54100. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> (static_cast <Component*> (currentPopup)) != 0)
  54101. hideCurrentMenu();
  54102. }
  54103. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54104. {
  54105. const MouseEvent e2 (e.getEventRelativeTo (this));
  54106. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54107. {
  54108. if (currentPopupIndex >= 0)
  54109. {
  54110. const int item = getItemAt (e2.x, e2.y);
  54111. if (item >= 0)
  54112. showMenu (item);
  54113. }
  54114. else
  54115. {
  54116. updateItemUnderMouse (e2.x, e2.y);
  54117. }
  54118. lastMouseX = e2.x;
  54119. lastMouseY = e2.y;
  54120. }
  54121. }
  54122. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54123. {
  54124. bool used = false;
  54125. const int numMenus = menuNames.size();
  54126. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54127. if (key.isKeyCode (KeyPress::leftKey))
  54128. {
  54129. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54130. used = true;
  54131. }
  54132. else if (key.isKeyCode (KeyPress::rightKey))
  54133. {
  54134. showMenu ((currentIndex + 1) % numMenus);
  54135. used = true;
  54136. }
  54137. return used;
  54138. }
  54139. void MenuBarComponent::inputAttemptWhenModal()
  54140. {
  54141. hideCurrentMenu();
  54142. }
  54143. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54144. {
  54145. StringArray newNames;
  54146. if (model != 0)
  54147. newNames = model->getMenuBarNames();
  54148. if (newNames != menuNames)
  54149. {
  54150. menuNames = newNames;
  54151. repaint();
  54152. resized();
  54153. }
  54154. }
  54155. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54156. const ApplicationCommandTarget::InvocationInfo& info)
  54157. {
  54158. if (model == 0
  54159. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54160. return;
  54161. for (int i = 0; i < menuNames.size(); ++i)
  54162. {
  54163. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54164. if (menu.containsCommandItem (info.commandID))
  54165. {
  54166. itemUnderMouse = i;
  54167. repaintMenuItem (i);
  54168. startTimer (200);
  54169. break;
  54170. }
  54171. }
  54172. }
  54173. void MenuBarComponent::timerCallback()
  54174. {
  54175. stopTimer();
  54176. const Point<int> mousePos (getMouseXYRelative());
  54177. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54178. }
  54179. END_JUCE_NAMESPACE
  54180. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54181. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54182. BEGIN_JUCE_NAMESPACE
  54183. MenuBarModel::MenuBarModel() throw()
  54184. : manager (0)
  54185. {
  54186. }
  54187. MenuBarModel::~MenuBarModel()
  54188. {
  54189. setApplicationCommandManagerToWatch (0);
  54190. }
  54191. void MenuBarModel::menuItemsChanged()
  54192. {
  54193. triggerAsyncUpdate();
  54194. }
  54195. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54196. {
  54197. if (manager != newManager)
  54198. {
  54199. if (manager != 0)
  54200. manager->removeListener (this);
  54201. manager = newManager;
  54202. if (manager != 0)
  54203. manager->addListener (this);
  54204. }
  54205. }
  54206. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54207. {
  54208. listeners.add (newListener);
  54209. }
  54210. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54211. {
  54212. // Trying to remove a listener that isn't on the list!
  54213. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54214. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54215. jassert (listeners.contains (listenerToRemove));
  54216. listeners.remove (listenerToRemove);
  54217. }
  54218. void MenuBarModel::handleAsyncUpdate()
  54219. {
  54220. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54221. }
  54222. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54223. {
  54224. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54225. }
  54226. void MenuBarModel::applicationCommandListChanged()
  54227. {
  54228. menuItemsChanged();
  54229. }
  54230. END_JUCE_NAMESPACE
  54231. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54232. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54233. BEGIN_JUCE_NAMESPACE
  54234. class PopupMenu::Item
  54235. {
  54236. public:
  54237. Item()
  54238. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54239. usesColour (false), customComp (0), commandManager (0)
  54240. {
  54241. }
  54242. Item (const int itemId_,
  54243. const String& text_,
  54244. const bool active_,
  54245. const bool isTicked_,
  54246. const Image* im,
  54247. const Colour& textColour_,
  54248. const bool usesColour_,
  54249. PopupMenuCustomComponent* const customComp_,
  54250. const PopupMenu* const subMenu_,
  54251. ApplicationCommandManager* const commandManager_)
  54252. : itemId (itemId_), text (text_), textColour (textColour_),
  54253. active (active_), isSeparator (false), isTicked (isTicked_),
  54254. usesColour (usesColour_), customComp (customComp_),
  54255. commandManager (commandManager_)
  54256. {
  54257. if (subMenu_ != 0)
  54258. subMenu = new PopupMenu (*subMenu_);
  54259. if (im != 0)
  54260. image = im->createCopy();
  54261. if (commandManager_ != 0 && itemId_ != 0)
  54262. {
  54263. String shortcutKey;
  54264. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54265. ->getKeyPressesAssignedToCommand (itemId_));
  54266. for (int i = 0; i < keyPresses.size(); ++i)
  54267. {
  54268. const String key (keyPresses.getReference(i).getTextDescription());
  54269. if (shortcutKey.isNotEmpty())
  54270. shortcutKey << ", ";
  54271. if (key.length() == 1)
  54272. shortcutKey << "shortcut: '" << key << '\'';
  54273. else
  54274. shortcutKey << key;
  54275. }
  54276. shortcutKey = shortcutKey.trim();
  54277. if (shortcutKey.isNotEmpty())
  54278. text << "<end>" << shortcutKey;
  54279. }
  54280. }
  54281. Item (const Item& other)
  54282. : itemId (other.itemId),
  54283. text (other.text),
  54284. textColour (other.textColour),
  54285. active (other.active),
  54286. isSeparator (other.isSeparator),
  54287. isTicked (other.isTicked),
  54288. usesColour (other.usesColour),
  54289. customComp (other.customComp),
  54290. commandManager (other.commandManager)
  54291. {
  54292. if (other.subMenu != 0)
  54293. subMenu = new PopupMenu (*(other.subMenu));
  54294. if (other.image != 0)
  54295. image = other.image->createCopy();
  54296. }
  54297. ~Item()
  54298. {
  54299. customComp = 0;
  54300. }
  54301. bool canBeTriggered() const throw()
  54302. {
  54303. return active && ! (isSeparator || (subMenu != 0));
  54304. }
  54305. bool hasActiveSubMenu() const throw()
  54306. {
  54307. return active && (subMenu != 0);
  54308. }
  54309. const int itemId;
  54310. String text;
  54311. const Colour textColour;
  54312. const bool active, isSeparator, isTicked, usesColour;
  54313. ScopedPointer <Image> image;
  54314. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54315. ScopedPointer <PopupMenu> subMenu;
  54316. ApplicationCommandManager* const commandManager;
  54317. juce_UseDebuggingNewOperator
  54318. private:
  54319. Item& operator= (const Item&);
  54320. };
  54321. class PopupMenu::ItemComponent : public Component
  54322. {
  54323. public:
  54324. ItemComponent (const PopupMenu::Item& itemInfo_)
  54325. : itemInfo (itemInfo_),
  54326. isHighlighted (false)
  54327. {
  54328. if (itemInfo.customComp != 0)
  54329. addAndMakeVisible (itemInfo.customComp);
  54330. }
  54331. ~ItemComponent()
  54332. {
  54333. if (itemInfo.customComp != 0)
  54334. removeChildComponent (itemInfo.customComp);
  54335. }
  54336. void getIdealSize (int& idealWidth,
  54337. int& idealHeight,
  54338. const int standardItemHeight)
  54339. {
  54340. if (itemInfo.customComp != 0)
  54341. {
  54342. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54343. }
  54344. else
  54345. {
  54346. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54347. itemInfo.isSeparator,
  54348. standardItemHeight,
  54349. idealWidth,
  54350. idealHeight);
  54351. }
  54352. }
  54353. void paint (Graphics& g)
  54354. {
  54355. if (itemInfo.customComp == 0)
  54356. {
  54357. String mainText (itemInfo.text);
  54358. String endText;
  54359. const int endIndex = mainText.indexOf ("<end>");
  54360. if (endIndex >= 0)
  54361. {
  54362. endText = mainText.substring (endIndex + 5).trim();
  54363. mainText = mainText.substring (0, endIndex);
  54364. }
  54365. getLookAndFeel()
  54366. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54367. itemInfo.isSeparator,
  54368. itemInfo.active,
  54369. isHighlighted,
  54370. itemInfo.isTicked,
  54371. itemInfo.subMenu != 0,
  54372. mainText, endText,
  54373. itemInfo.image,
  54374. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54375. }
  54376. }
  54377. void resized()
  54378. {
  54379. if (getNumChildComponents() > 0)
  54380. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54381. }
  54382. void setHighlighted (bool shouldBeHighlighted)
  54383. {
  54384. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54385. if (isHighlighted != shouldBeHighlighted)
  54386. {
  54387. isHighlighted = shouldBeHighlighted;
  54388. if (itemInfo.customComp != 0)
  54389. {
  54390. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54391. itemInfo.customComp->repaint();
  54392. }
  54393. repaint();
  54394. }
  54395. }
  54396. PopupMenu::Item itemInfo;
  54397. juce_UseDebuggingNewOperator
  54398. private:
  54399. bool isHighlighted;
  54400. ItemComponent (const ItemComponent&);
  54401. ItemComponent& operator= (const ItemComponent&);
  54402. };
  54403. namespace PopupMenuSettings
  54404. {
  54405. static const int scrollZone = 24;
  54406. static const int borderSize = 2;
  54407. static const int timerInterval = 50;
  54408. static const int dismissCommandId = 0x6287345f;
  54409. }
  54410. class PopupMenu::Window : public Component,
  54411. private Timer
  54412. {
  54413. public:
  54414. Window()
  54415. : Component ("menu"),
  54416. owner (0),
  54417. currentChild (0),
  54418. activeSubMenu (0),
  54419. menuBarComponent (0),
  54420. managerOfChosenCommand (0),
  54421. minimumWidth (0),
  54422. maximumNumColumns (7),
  54423. standardItemHeight (0),
  54424. isOver (false),
  54425. hasBeenOver (false),
  54426. isDown (false),
  54427. needsToScroll (false),
  54428. hideOnExit (false),
  54429. disableMouseMoves (false),
  54430. hasAnyJuceCompHadFocus (false),
  54431. numColumns (0),
  54432. contentHeight (0),
  54433. childYOffset (0),
  54434. timeEnteredCurrentChildComp (0),
  54435. scrollAcceleration (1.0)
  54436. {
  54437. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54438. setWantsKeyboardFocus (true);
  54439. setMouseClickGrabsKeyboardFocus (false);
  54440. setOpaque (true);
  54441. setAlwaysOnTop (true);
  54442. Desktop::getInstance().addGlobalMouseListener (this);
  54443. getActiveWindows().add (this);
  54444. }
  54445. ~Window()
  54446. {
  54447. getActiveWindows().removeValue (this);
  54448. Desktop::getInstance().removeGlobalMouseListener (this);
  54449. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54450. activeSubMenu = 0;
  54451. deleteAllChildren();
  54452. }
  54453. static Window* create (const PopupMenu& menu,
  54454. const bool dismissOnMouseUp,
  54455. Window* const owner_,
  54456. const int minX, const int maxX,
  54457. const int minY, const int maxY,
  54458. const int minimumWidth,
  54459. const int maximumNumColumns,
  54460. const int standardItemHeight,
  54461. const bool alignToRectangle,
  54462. const int itemIdThatMustBeVisible,
  54463. Component* const menuBarComponent,
  54464. ApplicationCommandManager** managerOfChosenCommand,
  54465. Component* const componentAttachedTo)
  54466. {
  54467. if (menu.items.size() > 0)
  54468. {
  54469. int totalItems = 0;
  54470. ScopedPointer <Window> mw (new Window());
  54471. mw->setLookAndFeel (menu.lookAndFeel);
  54472. mw->setWantsKeyboardFocus (false);
  54473. mw->minimumWidth = minimumWidth;
  54474. mw->maximumNumColumns = maximumNumColumns;
  54475. mw->standardItemHeight = standardItemHeight;
  54476. mw->dismissOnMouseUp = dismissOnMouseUp;
  54477. for (int i = 0; i < menu.items.size(); ++i)
  54478. {
  54479. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54480. mw->addItem (*item);
  54481. ++totalItems;
  54482. }
  54483. if (totalItems > 0)
  54484. {
  54485. mw->owner = owner_;
  54486. mw->menuBarComponent = menuBarComponent;
  54487. mw->managerOfChosenCommand = managerOfChosenCommand;
  54488. mw->componentAttachedTo = componentAttachedTo;
  54489. mw->componentAttachedToOriginal = componentAttachedTo;
  54490. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54491. mw->setTopLeftPosition (mw->windowPos.getX(),
  54492. mw->windowPos.getY());
  54493. mw->updateYPositions();
  54494. if (itemIdThatMustBeVisible != 0)
  54495. {
  54496. const int y = minY - mw->windowPos.getY();
  54497. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54498. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54499. }
  54500. mw->resizeToBestWindowPos();
  54501. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54502. | mw->getLookAndFeel().getMenuWindowFlags());
  54503. return mw.release();
  54504. }
  54505. }
  54506. return 0;
  54507. }
  54508. void paint (Graphics& g)
  54509. {
  54510. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54511. }
  54512. void paintOverChildren (Graphics& g)
  54513. {
  54514. if (isScrolling())
  54515. {
  54516. LookAndFeel& lf = getLookAndFeel();
  54517. if (isScrollZoneActive (false))
  54518. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54519. if (isScrollZoneActive (true))
  54520. {
  54521. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54522. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54523. }
  54524. }
  54525. }
  54526. bool isScrollZoneActive (bool bottomOne) const
  54527. {
  54528. return isScrolling()
  54529. && (bottomOne
  54530. ? childYOffset < contentHeight - windowPos.getHeight()
  54531. : childYOffset > 0);
  54532. }
  54533. void addItem (const PopupMenu::Item& item)
  54534. {
  54535. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54536. addAndMakeVisible (mic);
  54537. int itemW = 80;
  54538. int itemH = 16;
  54539. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54540. mic->setSize (itemW, jlimit (2, 600, itemH));
  54541. mic->addMouseListener (this, false);
  54542. }
  54543. // hide this and all sub-comps
  54544. void hide (const PopupMenu::Item* const item)
  54545. {
  54546. if (isVisible())
  54547. {
  54548. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54549. activeSubMenu = 0;
  54550. currentChild = 0;
  54551. exitModalState (item != 0 ? item->itemId : 0);
  54552. setVisible (false);
  54553. if (item != 0
  54554. && item->commandManager != 0
  54555. && item->itemId != 0)
  54556. {
  54557. *managerOfChosenCommand = item->commandManager;
  54558. }
  54559. }
  54560. }
  54561. void dismissMenu (const PopupMenu::Item* const item)
  54562. {
  54563. if (owner != 0)
  54564. {
  54565. owner->dismissMenu (item);
  54566. }
  54567. else
  54568. {
  54569. if (item != 0)
  54570. {
  54571. // need a copy of this on the stack as the one passed in will get deleted during this call
  54572. const PopupMenu::Item mi (*item);
  54573. hide (&mi);
  54574. }
  54575. else
  54576. {
  54577. hide (0);
  54578. }
  54579. }
  54580. }
  54581. void mouseMove (const MouseEvent&)
  54582. {
  54583. timerCallback();
  54584. }
  54585. void mouseDown (const MouseEvent&)
  54586. {
  54587. timerCallback();
  54588. }
  54589. void mouseDrag (const MouseEvent&)
  54590. {
  54591. timerCallback();
  54592. }
  54593. void mouseUp (const MouseEvent&)
  54594. {
  54595. timerCallback();
  54596. }
  54597. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54598. {
  54599. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54600. lastMouse = Point<int> (-1, -1);
  54601. }
  54602. bool keyPressed (const KeyPress& key)
  54603. {
  54604. if (key.isKeyCode (KeyPress::downKey))
  54605. {
  54606. selectNextItem (1);
  54607. }
  54608. else if (key.isKeyCode (KeyPress::upKey))
  54609. {
  54610. selectNextItem (-1);
  54611. }
  54612. else if (key.isKeyCode (KeyPress::leftKey))
  54613. {
  54614. if (owner != 0)
  54615. {
  54616. Component::SafePointer<Window> parentWindow (owner);
  54617. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54618. hide (0);
  54619. if (parentWindow != 0)
  54620. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54621. disableTimerUntilMouseMoves();
  54622. }
  54623. else if (menuBarComponent != 0)
  54624. {
  54625. menuBarComponent->keyPressed (key);
  54626. }
  54627. }
  54628. else if (key.isKeyCode (KeyPress::rightKey))
  54629. {
  54630. disableTimerUntilMouseMoves();
  54631. if (showSubMenuFor (currentChild))
  54632. {
  54633. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54634. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54635. activeSubMenu->selectNextItem (1);
  54636. }
  54637. else if (menuBarComponent != 0)
  54638. {
  54639. menuBarComponent->keyPressed (key);
  54640. }
  54641. }
  54642. else if (key.isKeyCode (KeyPress::returnKey))
  54643. {
  54644. triggerCurrentlyHighlightedItem();
  54645. }
  54646. else if (key.isKeyCode (KeyPress::escapeKey))
  54647. {
  54648. dismissMenu (0);
  54649. }
  54650. else
  54651. {
  54652. return false;
  54653. }
  54654. return true;
  54655. }
  54656. void inputAttemptWhenModal()
  54657. {
  54658. timerCallback();
  54659. if (! isOverAnyMenu())
  54660. {
  54661. if (componentAttachedTo != 0)
  54662. {
  54663. // we want to dismiss the menu, but if we do it synchronously, then
  54664. // the mouse-click will be allowed to pass through. That's good, except
  54665. // when the user clicks on the button that orginally popped the menu up,
  54666. // as they'll expect the menu to go away, and in fact it'll just
  54667. // come back. So only dismiss synchronously if they're not on the original
  54668. // comp that we're attached to.
  54669. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54670. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54671. {
  54672. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54673. return;
  54674. }
  54675. }
  54676. dismissMenu (0);
  54677. }
  54678. }
  54679. void handleCommandMessage (int commandId)
  54680. {
  54681. Component::handleCommandMessage (commandId);
  54682. if (commandId == PopupMenuSettings::dismissCommandId)
  54683. dismissMenu (0);
  54684. }
  54685. void timerCallback()
  54686. {
  54687. if (! isVisible())
  54688. return;
  54689. if (componentAttachedTo != componentAttachedToOriginal)
  54690. {
  54691. dismissMenu (0);
  54692. return;
  54693. }
  54694. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54695. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54696. return;
  54697. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54698. // move rather than a real timer callback
  54699. const Point<int> globalMousePos (Desktop::getMousePosition());
  54700. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54701. const uint32 now = Time::getMillisecondCounter();
  54702. if (now > timeEnteredCurrentChildComp + 100
  54703. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54704. && currentChild->isValidComponent()
  54705. && (! disableMouseMoves)
  54706. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54707. {
  54708. showSubMenuFor (currentChild);
  54709. }
  54710. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54711. {
  54712. highlightItemUnderMouse (globalMousePos, localMousePos);
  54713. }
  54714. bool overScrollArea = false;
  54715. if (isScrolling()
  54716. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54717. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54718. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54719. {
  54720. if (now > lastScroll + 20)
  54721. {
  54722. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54723. int amount = 0;
  54724. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54725. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54726. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54727. lastScroll = now;
  54728. }
  54729. overScrollArea = true;
  54730. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54731. }
  54732. else
  54733. {
  54734. scrollAcceleration = 1.0;
  54735. }
  54736. const bool wasDown = isDown;
  54737. bool isOverAny = isOverAnyMenu();
  54738. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54739. {
  54740. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54741. isOverAny = isOverAnyMenu();
  54742. }
  54743. if (hideOnExit && hasBeenOver && ! isOverAny)
  54744. {
  54745. hide (0);
  54746. }
  54747. else
  54748. {
  54749. isDown = hasBeenOver
  54750. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54751. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54752. bool anyFocused = Process::isForegroundProcess();
  54753. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54754. {
  54755. // because no component at all may have focus, our test here will
  54756. // only be triggered when something has focus and then loses it.
  54757. anyFocused = ! hasAnyJuceCompHadFocus;
  54758. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54759. {
  54760. if (ComponentPeer::getPeer (i)->isFocused())
  54761. {
  54762. anyFocused = true;
  54763. hasAnyJuceCompHadFocus = true;
  54764. break;
  54765. }
  54766. }
  54767. }
  54768. if (! anyFocused)
  54769. {
  54770. if (now > lastFocused + 10)
  54771. {
  54772. wasHiddenBecauseOfAppChange() = true;
  54773. dismissMenu (0);
  54774. return; // may have been deleted by the previous call..
  54775. }
  54776. }
  54777. else if (wasDown && now > menuCreationTime + 250
  54778. && ! (isDown || overScrollArea))
  54779. {
  54780. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54781. if (isOver)
  54782. {
  54783. triggerCurrentlyHighlightedItem();
  54784. }
  54785. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54786. {
  54787. dismissMenu (0);
  54788. }
  54789. return; // may have been deleted by the previous calls..
  54790. }
  54791. else
  54792. {
  54793. lastFocused = now;
  54794. }
  54795. }
  54796. }
  54797. static Array<Window*>& getActiveWindows()
  54798. {
  54799. static Array<Window*> activeMenuWindows;
  54800. return activeMenuWindows;
  54801. }
  54802. static bool& wasHiddenBecauseOfAppChange() throw()
  54803. {
  54804. static bool b = false;
  54805. return b;
  54806. }
  54807. juce_UseDebuggingNewOperator
  54808. private:
  54809. Window* owner;
  54810. PopupMenu::ItemComponent* currentChild;
  54811. ScopedPointer <Window> activeSubMenu;
  54812. Component* menuBarComponent;
  54813. ApplicationCommandManager** managerOfChosenCommand;
  54814. Component::SafePointer<Component> componentAttachedTo;
  54815. Component* componentAttachedToOriginal;
  54816. Rectangle<int> windowPos;
  54817. Point<int> lastMouse;
  54818. int minimumWidth, maximumNumColumns, standardItemHeight;
  54819. bool isOver, hasBeenOver, isDown, needsToScroll;
  54820. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54821. int numColumns, contentHeight, childYOffset;
  54822. Array <int> columnWidths;
  54823. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54824. double scrollAcceleration;
  54825. bool overlaps (const Rectangle<int>& r) const
  54826. {
  54827. return r.intersects (getBounds())
  54828. || (owner != 0 && owner->overlaps (r));
  54829. }
  54830. bool isOverAnyMenu() const
  54831. {
  54832. return (owner != 0) ? owner->isOverAnyMenu()
  54833. : isOverChildren();
  54834. }
  54835. bool isOverChildren() const
  54836. {
  54837. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54838. return isVisible()
  54839. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54840. }
  54841. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54842. {
  54843. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54844. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54845. if (activeSubMenu != 0)
  54846. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54847. }
  54848. bool treeContains (const Window* const window) const throw()
  54849. {
  54850. const Window* mw = this;
  54851. while (mw->owner != 0)
  54852. mw = mw->owner;
  54853. while (mw != 0)
  54854. {
  54855. if (mw == window)
  54856. return true;
  54857. mw = mw->activeSubMenu;
  54858. }
  54859. return false;
  54860. }
  54861. void calculateWindowPos (const int minX, const int maxX,
  54862. const int minY, const int maxY,
  54863. const bool alignToRectangle)
  54864. {
  54865. const Rectangle<int> mon (Desktop::getInstance()
  54866. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54867. (minY + maxY) / 2),
  54868. #if JUCE_MAC
  54869. true));
  54870. #else
  54871. false)); // on windows, don't stop the menu overlapping the taskbar
  54872. #endif
  54873. int x, y, widthToUse, heightToUse;
  54874. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54875. if (alignToRectangle)
  54876. {
  54877. x = minX;
  54878. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54879. const int spaceOver = minY - mon.getY();
  54880. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54881. y = maxY;
  54882. else
  54883. y = minY - heightToUse;
  54884. }
  54885. else
  54886. {
  54887. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54888. if (owner != 0)
  54889. {
  54890. if (owner->owner != 0)
  54891. {
  54892. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54893. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54894. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54895. tendTowardsRight = true;
  54896. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54897. tendTowardsRight = false;
  54898. }
  54899. else if (maxX + widthToUse < mon.getRight() - 32)
  54900. {
  54901. tendTowardsRight = true;
  54902. }
  54903. }
  54904. const int biggestSpace = jmax (mon.getRight() - maxX,
  54905. minX - mon.getX()) - 32;
  54906. if (biggestSpace < widthToUse)
  54907. {
  54908. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54909. if (numColumns > 1)
  54910. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54911. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54912. }
  54913. if (tendTowardsRight)
  54914. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54915. else
  54916. x = jmax (mon.getX() + 4, minX - widthToUse);
  54917. y = minY;
  54918. if ((minY + maxY) / 2 > mon.getCentreY())
  54919. y = jmax (mon.getY(), maxY - heightToUse);
  54920. }
  54921. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54922. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54923. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54924. // sets this flag if it's big enough to obscure any of its parent menus
  54925. hideOnExit = (owner != 0)
  54926. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54927. }
  54928. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54929. {
  54930. numColumns = 0;
  54931. contentHeight = 0;
  54932. const int maxMenuH = getParentHeight() - 24;
  54933. int totalW;
  54934. do
  54935. {
  54936. ++numColumns;
  54937. totalW = workOutBestSize (maxMenuW);
  54938. if (totalW > maxMenuW)
  54939. {
  54940. numColumns = jmax (1, numColumns - 1);
  54941. totalW = workOutBestSize (maxMenuW); // to update col widths
  54942. break;
  54943. }
  54944. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54945. {
  54946. break;
  54947. }
  54948. } while (numColumns < maximumNumColumns);
  54949. const int actualH = jmin (contentHeight, maxMenuH);
  54950. needsToScroll = contentHeight > actualH;
  54951. width = updateYPositions();
  54952. height = actualH + PopupMenuSettings::borderSize * 2;
  54953. }
  54954. int workOutBestSize (const int maxMenuW)
  54955. {
  54956. int totalW = 0;
  54957. contentHeight = 0;
  54958. int childNum = 0;
  54959. for (int col = 0; col < numColumns; ++col)
  54960. {
  54961. int i, colW = 50, colH = 0;
  54962. const int numChildren = jmin (getNumChildComponents() - childNum,
  54963. (getNumChildComponents() + numColumns - 1) / numColumns);
  54964. for (i = numChildren; --i >= 0;)
  54965. {
  54966. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54967. colH += getChildComponent (childNum + i)->getHeight();
  54968. }
  54969. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54970. columnWidths.set (col, colW);
  54971. totalW += colW;
  54972. contentHeight = jmax (contentHeight, colH);
  54973. childNum += numChildren;
  54974. }
  54975. if (totalW < minimumWidth)
  54976. {
  54977. totalW = minimumWidth;
  54978. for (int col = 0; col < numColumns; ++col)
  54979. columnWidths.set (0, totalW / numColumns);
  54980. }
  54981. return totalW;
  54982. }
  54983. void ensureItemIsVisible (const int itemId, int wantedY)
  54984. {
  54985. jassert (itemId != 0)
  54986. for (int i = getNumChildComponents(); --i >= 0;)
  54987. {
  54988. PopupMenu::ItemComponent* const m = static_cast <PopupMenu::ItemComponent*> (getChildComponent (i));
  54989. if (m != 0
  54990. && m->itemInfo.itemId == itemId
  54991. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  54992. {
  54993. const int currentY = m->getY();
  54994. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  54995. {
  54996. if (wantedY < 0)
  54997. wantedY = jlimit (PopupMenuSettings::scrollZone,
  54998. jmax (PopupMenuSettings::scrollZone,
  54999. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55000. currentY);
  55001. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55002. int deltaY = wantedY - currentY;
  55003. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55004. jmin (windowPos.getHeight(), mon.getHeight()));
  55005. const int newY = jlimit (mon.getY(),
  55006. mon.getBottom() - windowPos.getHeight(),
  55007. windowPos.getY() + deltaY);
  55008. deltaY -= newY - windowPos.getY();
  55009. childYOffset -= deltaY;
  55010. windowPos.setPosition (windowPos.getX(), newY);
  55011. updateYPositions();
  55012. }
  55013. break;
  55014. }
  55015. }
  55016. }
  55017. void resizeToBestWindowPos()
  55018. {
  55019. Rectangle<int> r (windowPos);
  55020. if (childYOffset < 0)
  55021. {
  55022. r.setBounds (r.getX(), r.getY() - childYOffset,
  55023. r.getWidth(), r.getHeight() + childYOffset);
  55024. }
  55025. else if (childYOffset > 0)
  55026. {
  55027. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55028. if (spaceAtBottom > 0)
  55029. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55030. }
  55031. setBounds (r);
  55032. updateYPositions();
  55033. }
  55034. void alterChildYPos (const int delta)
  55035. {
  55036. if (isScrolling())
  55037. {
  55038. childYOffset += delta;
  55039. if (delta < 0)
  55040. {
  55041. childYOffset = jmax (childYOffset, 0);
  55042. }
  55043. else if (delta > 0)
  55044. {
  55045. childYOffset = jmin (childYOffset,
  55046. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55047. }
  55048. updateYPositions();
  55049. }
  55050. else
  55051. {
  55052. childYOffset = 0;
  55053. }
  55054. resizeToBestWindowPos();
  55055. repaint();
  55056. }
  55057. int updateYPositions()
  55058. {
  55059. int x = 0;
  55060. int childNum = 0;
  55061. for (int col = 0; col < numColumns; ++col)
  55062. {
  55063. const int numChildren = jmin (getNumChildComponents() - childNum,
  55064. (getNumChildComponents() + numColumns - 1) / numColumns);
  55065. const int colW = columnWidths [col];
  55066. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55067. for (int i = 0; i < numChildren; ++i)
  55068. {
  55069. Component* const c = getChildComponent (childNum + i);
  55070. c->setBounds (x, y, colW, c->getHeight());
  55071. y += c->getHeight();
  55072. }
  55073. x += colW;
  55074. childNum += numChildren;
  55075. }
  55076. return x;
  55077. }
  55078. bool isScrolling() const throw()
  55079. {
  55080. return childYOffset != 0 || needsToScroll;
  55081. }
  55082. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55083. {
  55084. if (currentChild->isValidComponent())
  55085. currentChild->setHighlighted (false);
  55086. currentChild = child;
  55087. if (currentChild != 0)
  55088. {
  55089. currentChild->setHighlighted (true);
  55090. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55091. }
  55092. }
  55093. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55094. {
  55095. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55096. activeSubMenu = 0;
  55097. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55098. {
  55099. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55100. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55101. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55102. dismissOnMouseUp,
  55103. this,
  55104. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55105. 0, maximumNumColumns,
  55106. standardItemHeight,
  55107. false, 0, menuBarComponent,
  55108. managerOfChosenCommand,
  55109. componentAttachedTo);
  55110. if (activeSubMenu != 0)
  55111. {
  55112. activeSubMenu->setVisible (true);
  55113. activeSubMenu->enterModalState (false);
  55114. activeSubMenu->toFront (false);
  55115. return true;
  55116. }
  55117. }
  55118. return false;
  55119. }
  55120. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55121. {
  55122. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55123. if (isOver)
  55124. hasBeenOver = true;
  55125. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55126. {
  55127. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55128. if (disableMouseMoves && isOver)
  55129. disableMouseMoves = false;
  55130. }
  55131. if (disableMouseMoves || (activeSubMenu != 0 && activeSubMenu->isOverChildren()))
  55132. return;
  55133. bool isMovingTowardsMenu = false;
  55134. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55135. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55136. {
  55137. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55138. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55139. // extends from the last mouse pos to the submenu's rectangle..
  55140. float subX = (float) activeSubMenu->getScreenX();
  55141. if (activeSubMenu->getX() > getX())
  55142. {
  55143. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55144. }
  55145. else
  55146. {
  55147. lastMouse += Point<int> (2, 0);
  55148. subX += activeSubMenu->getWidth();
  55149. }
  55150. Path areaTowardsSubMenu;
  55151. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55152. (float) lastMouse.getY(),
  55153. subX,
  55154. (float) activeSubMenu->getScreenY(),
  55155. subX,
  55156. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55157. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55158. }
  55159. lastMouse = globalMousePos;
  55160. if (! isMovingTowardsMenu)
  55161. {
  55162. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55163. if (c == this)
  55164. c = 0;
  55165. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55166. if (mic == 0 && c != 0)
  55167. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55168. if (mic != currentChild
  55169. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55170. {
  55171. if (isOver && (c != 0) && (activeSubMenu != 0))
  55172. {
  55173. activeSubMenu->hide (0);
  55174. }
  55175. if (! isOver)
  55176. mic = 0;
  55177. setCurrentlyHighlightedChild (mic);
  55178. }
  55179. }
  55180. }
  55181. void triggerCurrentlyHighlightedItem()
  55182. {
  55183. if (currentChild->isValidComponent()
  55184. && currentChild->itemInfo.canBeTriggered()
  55185. && (currentChild->itemInfo.customComp == 0
  55186. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55187. {
  55188. dismissMenu (&currentChild->itemInfo);
  55189. }
  55190. }
  55191. void selectNextItem (const int delta)
  55192. {
  55193. disableTimerUntilMouseMoves();
  55194. PopupMenu::ItemComponent* mic = 0;
  55195. bool wasLastOne = (currentChild == 0);
  55196. const int numItems = getNumChildComponents();
  55197. for (int i = 0; i < numItems + 1; ++i)
  55198. {
  55199. int index = (delta > 0) ? i : (numItems - 1 - i);
  55200. index = (index + numItems) % numItems;
  55201. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55202. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55203. && wasLastOne)
  55204. break;
  55205. if (mic == currentChild)
  55206. wasLastOne = true;
  55207. }
  55208. setCurrentlyHighlightedChild (mic);
  55209. }
  55210. void disableTimerUntilMouseMoves()
  55211. {
  55212. disableMouseMoves = true;
  55213. if (owner != 0)
  55214. owner->disableTimerUntilMouseMoves();
  55215. }
  55216. Window (const Window&);
  55217. Window& operator= (const Window&);
  55218. };
  55219. PopupMenu::PopupMenu()
  55220. : lookAndFeel (0),
  55221. separatorPending (false)
  55222. {
  55223. }
  55224. PopupMenu::PopupMenu (const PopupMenu& other)
  55225. : lookAndFeel (other.lookAndFeel),
  55226. separatorPending (false)
  55227. {
  55228. items.ensureStorageAllocated (other.items.size());
  55229. for (int i = 0; i < other.items.size(); ++i)
  55230. items.add (new Item (*other.items.getUnchecked(i)));
  55231. }
  55232. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55233. {
  55234. if (this != &other)
  55235. {
  55236. lookAndFeel = other.lookAndFeel;
  55237. clear();
  55238. items.ensureStorageAllocated (other.items.size());
  55239. for (int i = 0; i < other.items.size(); ++i)
  55240. items.add (new Item (*other.items.getUnchecked(i)));
  55241. }
  55242. return *this;
  55243. }
  55244. PopupMenu::~PopupMenu()
  55245. {
  55246. clear();
  55247. }
  55248. void PopupMenu::clear()
  55249. {
  55250. items.clear();
  55251. separatorPending = false;
  55252. }
  55253. void PopupMenu::addSeparatorIfPending()
  55254. {
  55255. if (separatorPending)
  55256. {
  55257. separatorPending = false;
  55258. if (items.size() > 0)
  55259. items.add (new Item());
  55260. }
  55261. }
  55262. void PopupMenu::addItem (const int itemResultId,
  55263. const String& itemText,
  55264. const bool isActive,
  55265. const bool isTicked,
  55266. const Image* const iconToUse)
  55267. {
  55268. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55269. // didn't pick anything, so you shouldn't use it as the id
  55270. // for an item..
  55271. addSeparatorIfPending();
  55272. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55273. iconToUse, Colours::black, false, 0, 0, 0));
  55274. }
  55275. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55276. const int commandID,
  55277. const String& displayName)
  55278. {
  55279. jassert (commandManager != 0 && commandID != 0);
  55280. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55281. if (registeredInfo != 0)
  55282. {
  55283. ApplicationCommandInfo info (*registeredInfo);
  55284. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55285. addSeparatorIfPending();
  55286. items.add (new Item (commandID,
  55287. displayName.isNotEmpty() ? displayName
  55288. : info.shortName,
  55289. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55290. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55291. 0,
  55292. Colours::black,
  55293. false,
  55294. 0, 0,
  55295. commandManager));
  55296. }
  55297. }
  55298. void PopupMenu::addColouredItem (const int itemResultId,
  55299. const String& itemText,
  55300. const Colour& itemTextColour,
  55301. const bool isActive,
  55302. const bool isTicked,
  55303. const Image* const iconToUse)
  55304. {
  55305. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55306. // didn't pick anything, so you shouldn't use it as the id
  55307. // for an item..
  55308. addSeparatorIfPending();
  55309. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55310. iconToUse, itemTextColour, true, 0, 0, 0));
  55311. }
  55312. void PopupMenu::addCustomItem (const int itemResultId,
  55313. PopupMenuCustomComponent* const customComponent)
  55314. {
  55315. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55316. // didn't pick anything, so you shouldn't use it as the id
  55317. // for an item..
  55318. addSeparatorIfPending();
  55319. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55320. Colours::black, false, customComponent, 0, 0));
  55321. }
  55322. class NormalComponentWrapper : public PopupMenuCustomComponent
  55323. {
  55324. public:
  55325. NormalComponentWrapper (Component* const comp,
  55326. const int w, const int h,
  55327. const bool triggerMenuItemAutomaticallyWhenClicked)
  55328. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55329. width (w),
  55330. height (h)
  55331. {
  55332. addAndMakeVisible (comp);
  55333. }
  55334. ~NormalComponentWrapper() {}
  55335. void getIdealSize (int& idealWidth, int& idealHeight)
  55336. {
  55337. idealWidth = width;
  55338. idealHeight = height;
  55339. }
  55340. void resized()
  55341. {
  55342. if (getChildComponent(0) != 0)
  55343. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55344. }
  55345. juce_UseDebuggingNewOperator
  55346. private:
  55347. const int width, height;
  55348. NormalComponentWrapper (const NormalComponentWrapper&);
  55349. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55350. };
  55351. void PopupMenu::addCustomItem (const int itemResultId,
  55352. Component* customComponent,
  55353. int idealWidth, int idealHeight,
  55354. const bool triggerMenuItemAutomaticallyWhenClicked)
  55355. {
  55356. addCustomItem (itemResultId,
  55357. new NormalComponentWrapper (customComponent,
  55358. idealWidth, idealHeight,
  55359. triggerMenuItemAutomaticallyWhenClicked));
  55360. }
  55361. void PopupMenu::addSubMenu (const String& subMenuName,
  55362. const PopupMenu& subMenu,
  55363. const bool isActive,
  55364. Image* const iconToUse,
  55365. const bool isTicked)
  55366. {
  55367. addSeparatorIfPending();
  55368. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55369. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55370. }
  55371. void PopupMenu::addSeparator()
  55372. {
  55373. separatorPending = true;
  55374. }
  55375. class HeaderItemComponent : public PopupMenuCustomComponent
  55376. {
  55377. public:
  55378. HeaderItemComponent (const String& name)
  55379. : PopupMenuCustomComponent (false)
  55380. {
  55381. setName (name);
  55382. }
  55383. ~HeaderItemComponent()
  55384. {
  55385. }
  55386. void paint (Graphics& g)
  55387. {
  55388. Font f (getLookAndFeel().getPopupMenuFont());
  55389. f.setBold (true);
  55390. g.setFont (f);
  55391. g.setColour (findColour (PopupMenu::headerTextColourId));
  55392. g.drawFittedText (getName(),
  55393. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55394. Justification::bottomLeft, 1);
  55395. }
  55396. void getIdealSize (int& idealWidth,
  55397. int& idealHeight)
  55398. {
  55399. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55400. idealHeight += idealHeight / 2;
  55401. idealWidth += idealWidth / 4;
  55402. }
  55403. juce_UseDebuggingNewOperator
  55404. };
  55405. void PopupMenu::addSectionHeader (const String& title)
  55406. {
  55407. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55408. }
  55409. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55410. const int itemIdThatMustBeVisible,
  55411. const int minimumWidth,
  55412. const int maximumNumColumns,
  55413. const int standardItemHeight,
  55414. const bool alignToRectangle,
  55415. Component* menuBarComponent,
  55416. ApplicationCommandManager** managerOfChosenCommand,
  55417. Component* const componentAttachedTo)
  55418. {
  55419. Window* const pw
  55420. = Window::create (*this,
  55421. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55422. 0,
  55423. x, x + w,
  55424. y, y + h,
  55425. minimumWidth,
  55426. maximumNumColumns,
  55427. standardItemHeight,
  55428. alignToRectangle,
  55429. itemIdThatMustBeVisible,
  55430. menuBarComponent,
  55431. managerOfChosenCommand,
  55432. componentAttachedTo);
  55433. if (pw != 0)
  55434. pw->setVisible (true);
  55435. return pw;
  55436. }
  55437. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55438. const int itemIdThatMustBeVisible,
  55439. const int minimumWidth,
  55440. const int maximumNumColumns,
  55441. const int standardItemHeight,
  55442. const bool alignToRectangle,
  55443. Component* const componentAttachedTo)
  55444. {
  55445. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55446. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55447. Window::wasHiddenBecauseOfAppChange() = false;
  55448. int result = 0;
  55449. ApplicationCommandManager* managerOfChosenCommand = 0;
  55450. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55451. itemIdThatMustBeVisible,
  55452. minimumWidth,
  55453. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55454. standardItemHeight,
  55455. alignToRectangle, 0,
  55456. &managerOfChosenCommand,
  55457. componentAttachedTo));
  55458. if (popupComp != 0)
  55459. {
  55460. popupComp->enterModalState (false);
  55461. popupComp->toFront (false); // need to do this after making it modal, or it could
  55462. // be stuck behind other comps that are already modal..
  55463. result = popupComp->runModalLoop();
  55464. popupComp = 0;
  55465. if (! Window::wasHiddenBecauseOfAppChange())
  55466. {
  55467. if (prevTopLevel != 0)
  55468. prevTopLevel->toFront (true);
  55469. if (prevFocused != 0)
  55470. prevFocused->grabKeyboardFocus();
  55471. }
  55472. }
  55473. if (managerOfChosenCommand != 0 && result != 0)
  55474. {
  55475. ApplicationCommandTarget::InvocationInfo info (result);
  55476. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55477. managerOfChosenCommand->invoke (info, true);
  55478. }
  55479. return result;
  55480. }
  55481. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55482. const int minimumWidth,
  55483. const int maximumNumColumns,
  55484. const int standardItemHeight)
  55485. {
  55486. const Point<int> mousePos (Desktop::getMousePosition());
  55487. return showAt (mousePos.getX(), mousePos.getY(),
  55488. itemIdThatMustBeVisible,
  55489. minimumWidth,
  55490. maximumNumColumns,
  55491. standardItemHeight);
  55492. }
  55493. int PopupMenu::showAt (const int screenX,
  55494. const int screenY,
  55495. const int itemIdThatMustBeVisible,
  55496. const int minimumWidth,
  55497. const int maximumNumColumns,
  55498. const int standardItemHeight)
  55499. {
  55500. return showMenu (screenX, screenY, 1, 1,
  55501. itemIdThatMustBeVisible,
  55502. minimumWidth, maximumNumColumns,
  55503. standardItemHeight,
  55504. false, 0);
  55505. }
  55506. int PopupMenu::showAt (Component* componentToAttachTo,
  55507. const int itemIdThatMustBeVisible,
  55508. const int minimumWidth,
  55509. const int maximumNumColumns,
  55510. const int standardItemHeight)
  55511. {
  55512. if (componentToAttachTo != 0)
  55513. {
  55514. return showMenu (componentToAttachTo->getScreenX(),
  55515. componentToAttachTo->getScreenY(),
  55516. componentToAttachTo->getWidth(),
  55517. componentToAttachTo->getHeight(),
  55518. itemIdThatMustBeVisible,
  55519. minimumWidth,
  55520. maximumNumColumns,
  55521. standardItemHeight,
  55522. true, componentToAttachTo);
  55523. }
  55524. else
  55525. {
  55526. return show (itemIdThatMustBeVisible,
  55527. minimumWidth,
  55528. maximumNumColumns,
  55529. standardItemHeight);
  55530. }
  55531. }
  55532. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55533. {
  55534. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55535. {
  55536. Window* const pmw = Window::getActiveWindows()[i];
  55537. if (pmw != 0)
  55538. pmw->dismissMenu (0);
  55539. }
  55540. }
  55541. int PopupMenu::getNumItems() const throw()
  55542. {
  55543. int num = 0;
  55544. for (int i = items.size(); --i >= 0;)
  55545. if (! (items.getUnchecked(i))->isSeparator)
  55546. ++num;
  55547. return num;
  55548. }
  55549. bool PopupMenu::containsCommandItem (const int commandID) const
  55550. {
  55551. for (int i = items.size(); --i >= 0;)
  55552. {
  55553. const Item* mi = items.getUnchecked (i);
  55554. if ((mi->itemId == commandID && mi->commandManager != 0)
  55555. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55556. {
  55557. return true;
  55558. }
  55559. }
  55560. return false;
  55561. }
  55562. bool PopupMenu::containsAnyActiveItems() const throw()
  55563. {
  55564. for (int i = items.size(); --i >= 0;)
  55565. {
  55566. const Item* const mi = items.getUnchecked (i);
  55567. if (mi->subMenu != 0)
  55568. {
  55569. if (mi->subMenu->containsAnyActiveItems())
  55570. return true;
  55571. }
  55572. else if (mi->active)
  55573. {
  55574. return true;
  55575. }
  55576. }
  55577. return false;
  55578. }
  55579. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55580. {
  55581. lookAndFeel = newLookAndFeel;
  55582. }
  55583. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55584. : isHighlighted (false),
  55585. isTriggeredAutomatically (isTriggeredAutomatically_)
  55586. {
  55587. }
  55588. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55589. {
  55590. }
  55591. void PopupMenuCustomComponent::triggerMenuItem()
  55592. {
  55593. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55594. if (mic != 0)
  55595. {
  55596. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55597. if (pmw != 0)
  55598. {
  55599. pmw->dismissMenu (&mic->itemInfo);
  55600. }
  55601. else
  55602. {
  55603. // something must have gone wrong with the component hierarchy if this happens..
  55604. jassertfalse
  55605. }
  55606. }
  55607. else
  55608. {
  55609. // why isn't this component inside a menu? Not much point triggering the item if
  55610. // there's no menu.
  55611. jassertfalse
  55612. }
  55613. }
  55614. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55615. : subMenu (0),
  55616. itemId (0),
  55617. isSeparator (false),
  55618. isTicked (false),
  55619. isEnabled (false),
  55620. isCustomComponent (false),
  55621. isSectionHeader (false),
  55622. customColour (0),
  55623. customImage (0),
  55624. menu (menu_),
  55625. index (0)
  55626. {
  55627. }
  55628. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55629. {
  55630. }
  55631. bool PopupMenu::MenuItemIterator::next()
  55632. {
  55633. if (index >= menu.items.size())
  55634. return false;
  55635. const Item* const item = menu.items.getUnchecked (index);
  55636. ++index;
  55637. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55638. subMenu = item->subMenu;
  55639. itemId = item->itemId;
  55640. isSeparator = item->isSeparator;
  55641. isTicked = item->isTicked;
  55642. isEnabled = item->active;
  55643. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55644. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55645. customColour = item->usesColour ? &(item->textColour) : 0;
  55646. customImage = item->image;
  55647. commandManager = item->commandManager;
  55648. return true;
  55649. }
  55650. END_JUCE_NAMESPACE
  55651. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55652. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55653. BEGIN_JUCE_NAMESPACE
  55654. ComponentDragger::ComponentDragger()
  55655. : constrainer (0)
  55656. {
  55657. }
  55658. ComponentDragger::~ComponentDragger()
  55659. {
  55660. }
  55661. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55662. ComponentBoundsConstrainer* const constrainer_)
  55663. {
  55664. jassert (componentToDrag->isValidComponent());
  55665. if (componentToDrag != 0)
  55666. {
  55667. constrainer = constrainer_;
  55668. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55669. }
  55670. }
  55671. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55672. {
  55673. jassert (componentToDrag->isValidComponent());
  55674. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55675. if (componentToDrag != 0)
  55676. {
  55677. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55678. const Component* const parentComp = componentToDrag->getParentComponent();
  55679. if (parentComp != 0)
  55680. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55681. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55682. if (constrainer != 0)
  55683. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55684. else
  55685. componentToDrag->setBounds (bounds);
  55686. }
  55687. }
  55688. END_JUCE_NAMESPACE
  55689. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55690. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55691. BEGIN_JUCE_NAMESPACE
  55692. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55693. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55694. class DragImageComponent : public Component,
  55695. public Timer
  55696. {
  55697. public:
  55698. DragImageComponent (Image* const im,
  55699. const String& desc,
  55700. Component* const sourceComponent,
  55701. Component* const mouseDragSource_,
  55702. DragAndDropContainer* const o,
  55703. const Point<int>& imageOffset_)
  55704. : image (im),
  55705. source (sourceComponent),
  55706. mouseDragSource (mouseDragSource_),
  55707. owner (o),
  55708. dragDesc (desc),
  55709. imageOffset (imageOffset_),
  55710. hasCheckedForExternalDrag (false),
  55711. drawImage (true)
  55712. {
  55713. setSize (im->getWidth(), im->getHeight());
  55714. if (mouseDragSource == 0)
  55715. mouseDragSource = source;
  55716. mouseDragSource->addMouseListener (this, false);
  55717. startTimer (200);
  55718. setInterceptsMouseClicks (false, false);
  55719. setAlwaysOnTop (true);
  55720. }
  55721. ~DragImageComponent()
  55722. {
  55723. if (owner->dragImageComponent == this)
  55724. owner->dragImageComponent.release();
  55725. if (mouseDragSource != 0)
  55726. {
  55727. mouseDragSource->removeMouseListener (this);
  55728. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55729. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55730. }
  55731. }
  55732. void paint (Graphics& g)
  55733. {
  55734. if (isOpaque())
  55735. g.fillAll (Colours::white);
  55736. if (drawImage)
  55737. {
  55738. g.setOpacity (1.0f);
  55739. g.drawImageAt (image, 0, 0);
  55740. }
  55741. }
  55742. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55743. {
  55744. Component* hit = getParentComponent();
  55745. if (hit == 0)
  55746. {
  55747. hit = Desktop::getInstance().findComponentAt (screenPos);
  55748. }
  55749. else
  55750. {
  55751. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55752. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55753. }
  55754. // (note: use a local copy of the dragDesc member in case the callback runs
  55755. // a modal loop and deletes this object before the method completes)
  55756. const String dragDescLocal (dragDesc);
  55757. while (hit != 0)
  55758. {
  55759. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55760. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55761. {
  55762. relativePos = hit->globalPositionToRelative (screenPos);
  55763. return ddt;
  55764. }
  55765. hit = hit->getParentComponent();
  55766. }
  55767. return 0;
  55768. }
  55769. void mouseUp (const MouseEvent& e)
  55770. {
  55771. if (e.originalComponent != this)
  55772. {
  55773. if (mouseDragSource != 0)
  55774. mouseDragSource->removeMouseListener (this);
  55775. bool dropAccepted = false;
  55776. DragAndDropTarget* ddt = 0;
  55777. Point<int> relPos;
  55778. if (isVisible())
  55779. {
  55780. setVisible (false);
  55781. ddt = findTarget (e.getScreenPosition(), relPos);
  55782. // fade this component and remove it - it'll be deleted later by the timer callback
  55783. dropAccepted = ddt != 0;
  55784. setVisible (true);
  55785. if (dropAccepted || source == 0)
  55786. {
  55787. fadeOutComponent (120);
  55788. }
  55789. else
  55790. {
  55791. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55792. source->getHeight() / 2)));
  55793. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55794. getHeight() / 2)));
  55795. fadeOutComponent (120,
  55796. target.getX() - ourCentre.getX(),
  55797. target.getY() - ourCentre.getY());
  55798. }
  55799. }
  55800. if (getParentComponent() != 0)
  55801. getParentComponent()->removeChildComponent (this);
  55802. if (dropAccepted && ddt != 0)
  55803. {
  55804. // (note: use a local copy of the dragDesc member in case the callback runs
  55805. // a modal loop and deletes this object before the method completes)
  55806. const String dragDescLocal (dragDesc);
  55807. currentlyOverComp = 0;
  55808. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55809. }
  55810. // careful - this object could now be deleted..
  55811. }
  55812. }
  55813. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55814. {
  55815. // (note: use a local copy of the dragDesc member in case the callback runs
  55816. // a modal loop and deletes this object before it returns)
  55817. const String dragDescLocal (dragDesc);
  55818. Point<int> newPos (screenPos + imageOffset);
  55819. if (getParentComponent() != 0)
  55820. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55821. //if (newX != getX() || newY != getY())
  55822. {
  55823. setTopLeftPosition (newPos.getX(), newPos.getY());
  55824. Point<int> relPos;
  55825. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55826. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55827. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55828. if (ddtComp != currentlyOverComp)
  55829. {
  55830. if (currentlyOverComp != 0 && source != 0
  55831. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55832. {
  55833. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55834. }
  55835. currentlyOverComp = ddtComp;
  55836. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55837. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55838. }
  55839. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55840. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55841. if (getCurrentlyOver() == 0
  55842. && canDoExternalDrag
  55843. && ! hasCheckedForExternalDrag)
  55844. {
  55845. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55846. {
  55847. hasCheckedForExternalDrag = true;
  55848. StringArray files;
  55849. bool canMoveFiles = false;
  55850. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55851. && files.size() > 0)
  55852. {
  55853. Component::SafePointer<Component> cdw (this);
  55854. setVisible (false);
  55855. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55856. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55857. if (cdw != 0)
  55858. delete this;
  55859. return;
  55860. }
  55861. }
  55862. }
  55863. }
  55864. }
  55865. void mouseDrag (const MouseEvent& e)
  55866. {
  55867. if (e.originalComponent != this)
  55868. updateLocation (true, e.getScreenPosition());
  55869. }
  55870. void timerCallback()
  55871. {
  55872. if (source == 0)
  55873. {
  55874. delete this;
  55875. }
  55876. else if (! isMouseButtonDownAnywhere())
  55877. {
  55878. if (mouseDragSource != 0)
  55879. mouseDragSource->removeMouseListener (this);
  55880. delete this;
  55881. }
  55882. }
  55883. private:
  55884. ScopedPointer<Image> image;
  55885. Component::SafePointer<Component> source;
  55886. Component::SafePointer<Component> mouseDragSource;
  55887. DragAndDropContainer* const owner;
  55888. Component::SafePointer<Component> currentlyOverComp;
  55889. DragAndDropTarget* getCurrentlyOver()
  55890. {
  55891. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55892. }
  55893. String dragDesc;
  55894. const Point<int> imageOffset;
  55895. bool hasCheckedForExternalDrag, drawImage;
  55896. DragImageComponent (const DragImageComponent&);
  55897. DragImageComponent& operator= (const DragImageComponent&);
  55898. };
  55899. DragAndDropContainer::DragAndDropContainer()
  55900. {
  55901. }
  55902. DragAndDropContainer::~DragAndDropContainer()
  55903. {
  55904. dragImageComponent = 0;
  55905. }
  55906. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55907. Component* sourceComponent,
  55908. Image* dragImage_,
  55909. const bool allowDraggingToExternalWindows,
  55910. const Point<int>* imageOffsetFromMouse)
  55911. {
  55912. ScopedPointer <Image> dragImage (dragImage_);
  55913. if (dragImageComponent == 0)
  55914. {
  55915. Component* const thisComp = dynamic_cast <Component*> (this);
  55916. if (thisComp == 0)
  55917. {
  55918. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55919. return;
  55920. }
  55921. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55922. if (draggingSource == 0 || ! draggingSource->isDragging())
  55923. {
  55924. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55925. return;
  55926. }
  55927. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55928. Point<int> imageOffset;
  55929. if (dragImage == 0)
  55930. {
  55931. dragImage = sourceComponent->createComponentSnapshot (sourceComponent->getLocalBounds());
  55932. if (dragImage->getFormat() != Image::ARGB)
  55933. {
  55934. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55935. Graphics g2 (*newIm);
  55936. g2.drawImageAt (dragImage, 0, 0);
  55937. dragImage = newIm;
  55938. }
  55939. dragImage->multiplyAllAlphas (0.6f);
  55940. const int lo = 150;
  55941. const int hi = 400;
  55942. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55943. Point<int> clipped (dragImage->getBounds().getConstrainedPoint (relPos));
  55944. for (int y = dragImage->getHeight(); --y >= 0;)
  55945. {
  55946. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55947. for (int x = dragImage->getWidth(); --x >= 0;)
  55948. {
  55949. const int dx = x - clipped.getX();
  55950. const int distance = roundToInt (sqrt (dx * dx + dy));
  55951. if (distance > lo)
  55952. {
  55953. const float alpha = (distance > hi) ? 0
  55954. : (hi - distance) / (float) (hi - lo)
  55955. + Random::getSystemRandom().nextFloat() * 0.008f;
  55956. dragImage->multiplyAlphaAt (x, y, alpha);
  55957. }
  55958. }
  55959. }
  55960. imageOffset = -clipped;
  55961. }
  55962. else
  55963. {
  55964. if (imageOffsetFromMouse == 0)
  55965. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55966. dragImage->getHeight() / -2);
  55967. else
  55968. imageOffset = *imageOffsetFromMouse;
  55969. }
  55970. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55971. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55972. currentDragDesc = sourceDescription;
  55973. if (allowDraggingToExternalWindows)
  55974. {
  55975. if (! Desktop::canUseSemiTransparentWindows())
  55976. dragImageComponent->setOpaque (true);
  55977. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55978. | ComponentPeer::windowIsTemporary
  55979. | ComponentPeer::windowIgnoresKeyPresses);
  55980. }
  55981. else
  55982. thisComp->addChildComponent (dragImageComponent);
  55983. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  55984. dragImageComponent->setVisible (true);
  55985. }
  55986. }
  55987. bool DragAndDropContainer::isDragAndDropActive() const
  55988. {
  55989. return dragImageComponent != 0;
  55990. }
  55991. const String DragAndDropContainer::getCurrentDragDescription() const
  55992. {
  55993. return (dragImageComponent != 0) ? currentDragDesc
  55994. : String::empty;
  55995. }
  55996. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  55997. {
  55998. if (c == 0)
  55999. return 0;
  56000. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56001. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56002. }
  56003. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56004. {
  56005. return false;
  56006. }
  56007. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56008. {
  56009. }
  56010. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56011. {
  56012. }
  56013. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56014. {
  56015. }
  56016. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56017. {
  56018. return true;
  56019. }
  56020. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56021. {
  56022. }
  56023. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56024. {
  56025. }
  56026. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56027. {
  56028. }
  56029. END_JUCE_NAMESPACE
  56030. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56031. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56032. BEGIN_JUCE_NAMESPACE
  56033. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY);
  56034. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type);
  56035. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard);
  56036. class MouseCursor::SharedCursorHandle
  56037. {
  56038. public:
  56039. explicit SharedCursorHandle (const MouseCursor::StandardCursorType type)
  56040. : handle (juce_createStandardMouseCursor (type)),
  56041. refCount (1),
  56042. standardType (type),
  56043. isStandard (true)
  56044. {
  56045. }
  56046. SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY)
  56047. : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)),
  56048. refCount (1),
  56049. standardType (MouseCursor::NormalCursor),
  56050. isStandard (false)
  56051. {
  56052. }
  56053. static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type)
  56054. {
  56055. const ScopedLock sl (getLock());
  56056. for (int i = getCursors().size(); --i >= 0;)
  56057. {
  56058. SharedCursorHandle* const sc = getCursors().getUnchecked(i);
  56059. if (sc->standardType == type)
  56060. return sc->retain();
  56061. }
  56062. SharedCursorHandle* const sc = new SharedCursorHandle (type);
  56063. getCursors().add (sc);
  56064. return sc;
  56065. }
  56066. SharedCursorHandle* retain() throw()
  56067. {
  56068. Atomic::increment (refCount);
  56069. return this;
  56070. }
  56071. void release()
  56072. {
  56073. if (Atomic::decrementAndReturn (refCount) == 0)
  56074. {
  56075. if (isStandard)
  56076. {
  56077. const ScopedLock sl (getLock());
  56078. getCursors().removeValue (this);
  56079. }
  56080. delete this;
  56081. }
  56082. }
  56083. void* getHandle() const throw() { return handle; }
  56084. juce_UseDebuggingNewOperator
  56085. private:
  56086. void* const handle;
  56087. int32 refCount;
  56088. const MouseCursor::StandardCursorType standardType;
  56089. const bool isStandard;
  56090. static CriticalSection& getLock()
  56091. {
  56092. static CriticalSection lock;
  56093. return lock;
  56094. }
  56095. static Array <SharedCursorHandle*>& getCursors()
  56096. {
  56097. static Array <SharedCursorHandle*> cursors;
  56098. return cursors;
  56099. }
  56100. ~SharedCursorHandle()
  56101. {
  56102. juce_deleteMouseCursor (handle, isStandard);
  56103. }
  56104. SharedCursorHandle& operator= (const SharedCursorHandle&);
  56105. };
  56106. MouseCursor::MouseCursor()
  56107. : cursorHandle (SharedCursorHandle::createStandard (NormalCursor))
  56108. {
  56109. jassert (cursorHandle != 0);
  56110. }
  56111. MouseCursor::MouseCursor (const StandardCursorType type)
  56112. : cursorHandle (SharedCursorHandle::createStandard (type))
  56113. {
  56114. jassert (cursorHandle != 0);
  56115. }
  56116. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY)
  56117. : cursorHandle (new SharedCursorHandle (image, hotSpotX, hotSpotY))
  56118. {
  56119. }
  56120. MouseCursor::MouseCursor (const MouseCursor& other)
  56121. : cursorHandle (other.cursorHandle->retain())
  56122. {
  56123. }
  56124. MouseCursor::~MouseCursor()
  56125. {
  56126. cursorHandle->release();
  56127. }
  56128. MouseCursor& MouseCursor::operator= (const MouseCursor& other)
  56129. {
  56130. other.cursorHandle->retain();
  56131. cursorHandle->release();
  56132. cursorHandle = other.cursorHandle;
  56133. return *this;
  56134. }
  56135. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56136. {
  56137. return getHandle() == other.getHandle();
  56138. }
  56139. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56140. {
  56141. return getHandle() != other.getHandle();
  56142. }
  56143. void* MouseCursor::getHandle() const throw()
  56144. {
  56145. return cursorHandle->getHandle();
  56146. }
  56147. void MouseCursor::showWaitCursor() throw()
  56148. {
  56149. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56150. }
  56151. void MouseCursor::hideWaitCursor() throw()
  56152. {
  56153. Desktop::getInstance().getMainMouseSource().revealCursor();
  56154. }
  56155. END_JUCE_NAMESPACE
  56156. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56157. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56158. BEGIN_JUCE_NAMESPACE
  56159. MouseEvent::MouseEvent (MouseInputSource& source_,
  56160. const Point<int>& position,
  56161. const ModifierKeys& mods_,
  56162. Component* const originator,
  56163. const Time& eventTime_,
  56164. const Point<int> mouseDownPos_,
  56165. const Time& mouseDownTime_,
  56166. const int numberOfClicks_,
  56167. const bool mouseWasDragged) throw()
  56168. : x (position.getX()),
  56169. y (position.getY()),
  56170. mods (mods_),
  56171. eventComponent (originator),
  56172. originalComponent (originator),
  56173. eventTime (eventTime_),
  56174. source (source_),
  56175. mouseDownPos (mouseDownPos_),
  56176. mouseDownTime (mouseDownTime_),
  56177. numberOfClicks (numberOfClicks_),
  56178. wasMovedSinceMouseDown (mouseWasDragged)
  56179. {
  56180. }
  56181. MouseEvent::~MouseEvent() throw()
  56182. {
  56183. }
  56184. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56185. {
  56186. if (otherComponent == 0)
  56187. {
  56188. jassertfalse
  56189. return *this;
  56190. }
  56191. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56192. mods, originalComponent, eventTime,
  56193. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56194. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56195. }
  56196. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56197. {
  56198. return MouseEvent (source, newPosition, mods, originalComponent,
  56199. eventTime, mouseDownPos, mouseDownTime,
  56200. numberOfClicks, wasMovedSinceMouseDown);
  56201. }
  56202. bool MouseEvent::mouseWasClicked() const throw()
  56203. {
  56204. return ! wasMovedSinceMouseDown;
  56205. }
  56206. int MouseEvent::getMouseDownX() const throw()
  56207. {
  56208. return mouseDownPos.getX();
  56209. }
  56210. int MouseEvent::getMouseDownY() const throw()
  56211. {
  56212. return mouseDownPos.getY();
  56213. }
  56214. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56215. {
  56216. return mouseDownPos;
  56217. }
  56218. int MouseEvent::getDistanceFromDragStartX() const throw()
  56219. {
  56220. return x - mouseDownPos.getX();
  56221. }
  56222. int MouseEvent::getDistanceFromDragStartY() const throw()
  56223. {
  56224. return y - mouseDownPos.getY();
  56225. }
  56226. int MouseEvent::getDistanceFromDragStart() const throw()
  56227. {
  56228. return mouseDownPos.getDistanceFrom (getPosition());
  56229. }
  56230. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56231. {
  56232. return getPosition() - mouseDownPos;
  56233. }
  56234. int MouseEvent::getLengthOfMousePress() const throw()
  56235. {
  56236. if (mouseDownTime.toMilliseconds() > 0)
  56237. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56238. return 0;
  56239. }
  56240. const Point<int> MouseEvent::getPosition() const throw()
  56241. {
  56242. return Point<int> (x, y);
  56243. }
  56244. int MouseEvent::getScreenX() const
  56245. {
  56246. return getScreenPosition().getX();
  56247. }
  56248. int MouseEvent::getScreenY() const
  56249. {
  56250. return getScreenPosition().getY();
  56251. }
  56252. const Point<int> MouseEvent::getScreenPosition() const
  56253. {
  56254. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56255. }
  56256. int MouseEvent::getMouseDownScreenX() const
  56257. {
  56258. return getMouseDownScreenPosition().getX();
  56259. }
  56260. int MouseEvent::getMouseDownScreenY() const
  56261. {
  56262. return getMouseDownScreenPosition().getY();
  56263. }
  56264. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56265. {
  56266. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56267. }
  56268. static int doubleClickTimeOutMs = 400;
  56269. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56270. {
  56271. doubleClickTimeOutMs = newTime;
  56272. }
  56273. int MouseEvent::getDoubleClickTimeout() throw()
  56274. {
  56275. return doubleClickTimeOutMs;
  56276. }
  56277. END_JUCE_NAMESPACE
  56278. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56279. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56280. BEGIN_JUCE_NAMESPACE
  56281. class MouseInputSourceInternal : public AsyncUpdater
  56282. {
  56283. public:
  56284. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56285. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56286. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56287. {
  56288. zerostruct (mouseDowns);
  56289. }
  56290. ~MouseInputSourceInternal()
  56291. {
  56292. }
  56293. bool isDragging() const throw()
  56294. {
  56295. return buttonState.isAnyMouseButtonDown();
  56296. }
  56297. Component* getComponentUnderMouse() const
  56298. {
  56299. return static_cast <Component*> (componentUnderMouse);
  56300. }
  56301. const ModifierKeys getCurrentModifiers() const
  56302. {
  56303. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56304. }
  56305. ComponentPeer* getPeer()
  56306. {
  56307. if (! ComponentPeer::isValidPeer (lastPeer))
  56308. lastPeer = 0;
  56309. return lastPeer;
  56310. }
  56311. Component* findComponentAt (const Point<int>& screenPos)
  56312. {
  56313. ComponentPeer* const peer = getPeer();
  56314. if (peer != 0)
  56315. {
  56316. Component* const comp = peer->getComponent();
  56317. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56318. // (the contains() call is needed to test for overlapping desktop windows)
  56319. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56320. return comp->getComponentAt (relativePos);
  56321. }
  56322. return 0;
  56323. }
  56324. const Point<int> getScreenPosition() const throw()
  56325. {
  56326. return lastScreenPos + unboundedMouseOffset;
  56327. }
  56328. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56329. {
  56330. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56331. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56332. }
  56333. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56334. {
  56335. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56336. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56337. }
  56338. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56339. {
  56340. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56341. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56342. }
  56343. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56344. {
  56345. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56346. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56347. }
  56348. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56349. {
  56350. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56351. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56352. }
  56353. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56354. {
  56355. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56356. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56357. }
  56358. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56359. {
  56360. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56361. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56362. }
  56363. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56364. {
  56365. if (buttonState != newButtonState)
  56366. {
  56367. // (ignore secondary clicks when there's already a button down)
  56368. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56369. {
  56370. buttonState = newButtonState;
  56371. return;
  56372. }
  56373. if (buttonState.isAnyMouseButtonDown())
  56374. {
  56375. Component* const current = getComponentUnderMouse();
  56376. if (current != 0)
  56377. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56378. enableUnboundedMouseMovement (false, false);
  56379. }
  56380. buttonState = newButtonState;
  56381. if (buttonState.isAnyMouseButtonDown())
  56382. {
  56383. Desktop::getInstance().incrementMouseClickCounter();
  56384. Component* const current = getComponentUnderMouse();
  56385. if (current != 0)
  56386. {
  56387. registerMouseDown (screenPos, time, current);
  56388. sendMouseDown (current, screenPos, time);
  56389. }
  56390. }
  56391. }
  56392. }
  56393. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56394. {
  56395. Component* current = getComponentUnderMouse();
  56396. if (newComponent != current)
  56397. {
  56398. Component::SafePointer<Component> safeNewComp (newComponent);
  56399. const ModifierKeys originalButtonState (buttonState);
  56400. if (current != 0)
  56401. {
  56402. setButtons (screenPos, time, ModifierKeys());
  56403. sendMouseExit (current, screenPos, time);
  56404. buttonState = originalButtonState;
  56405. }
  56406. componentUnderMouse = safeNewComp;
  56407. current = getComponentUnderMouse();
  56408. if (current != 0)
  56409. sendMouseEnter (current, screenPos, time);
  56410. revealCursor (false);
  56411. setButtons (screenPos, time, originalButtonState);
  56412. }
  56413. }
  56414. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56415. {
  56416. ModifierKeys::updateCurrentModifiers();
  56417. if (newPeer != lastPeer)
  56418. {
  56419. setComponentUnderMouse (0, screenPos, time);
  56420. lastPeer = newPeer;
  56421. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56422. }
  56423. }
  56424. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56425. {
  56426. if (! isDragging())
  56427. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56428. if (newScreenPos != lastScreenPos || forceUpdate)
  56429. {
  56430. cancelPendingUpdate();
  56431. lastScreenPos = newScreenPos;
  56432. Component* const current = getComponentUnderMouse();
  56433. if (current != 0)
  56434. {
  56435. if (isDragging())
  56436. {
  56437. registerMouseDrag (newScreenPos);
  56438. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56439. if (isUnboundedMouseModeOn)
  56440. handleUnboundedDrag (current);
  56441. }
  56442. else
  56443. {
  56444. sendMouseMove (current, newScreenPos, time);
  56445. }
  56446. }
  56447. revealCursor (false);
  56448. }
  56449. }
  56450. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56451. {
  56452. jassert (newPeer != 0);
  56453. lastTime = time;
  56454. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56455. if (isDragging() && newMods.isAnyMouseButtonDown())
  56456. {
  56457. setScreenPos (screenPos, time, false);
  56458. }
  56459. else
  56460. {
  56461. setPeer (newPeer, screenPos, time);
  56462. ComponentPeer* peer = getPeer();
  56463. if (peer != 0)
  56464. {
  56465. setButtons (screenPos, time, newMods);
  56466. peer = getPeer();
  56467. if (peer != 0)
  56468. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56469. }
  56470. }
  56471. }
  56472. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56473. {
  56474. jassert (peer != 0);
  56475. lastTime = time;
  56476. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56477. setPeer (peer, screenPos, time);
  56478. setScreenPos (screenPos, time, false);
  56479. triggerFakeMove();
  56480. if (! isDragging())
  56481. {
  56482. Component* current = getComponentUnderMouse();
  56483. if (current != 0)
  56484. sendMouseWheel (current, screenPos, time, x, y);
  56485. }
  56486. }
  56487. const Time getLastMouseDownTime() const throw()
  56488. {
  56489. return Time (mouseDowns[0].time);
  56490. }
  56491. const Point<int> getLastMouseDownPosition() const throw()
  56492. {
  56493. return mouseDowns[0].position;
  56494. }
  56495. int getNumberOfMultipleClicks() const throw()
  56496. {
  56497. int numClicks = 0;
  56498. if (mouseDowns[0].time != 0)
  56499. {
  56500. if (! mouseMovedSignificantlySincePressed)
  56501. ++numClicks;
  56502. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56503. {
  56504. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56505. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56506. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56507. && mouseDowns[0].component == mouseDowns[i].component)
  56508. {
  56509. ++numClicks;
  56510. }
  56511. else
  56512. {
  56513. break;
  56514. }
  56515. }
  56516. }
  56517. return numClicks;
  56518. }
  56519. bool hasMouseMovedSignificantlySincePressed() const throw()
  56520. {
  56521. return mouseMovedSignificantlySincePressed
  56522. || lastTime > mouseDowns[0].time + 300;
  56523. }
  56524. void triggerFakeMove()
  56525. {
  56526. triggerAsyncUpdate();
  56527. }
  56528. void handleAsyncUpdate()
  56529. {
  56530. if (! isDragging())
  56531. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56532. }
  56533. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56534. {
  56535. enable = enable && isDragging();
  56536. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56537. if (enable != isUnboundedMouseModeOn)
  56538. {
  56539. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56540. {
  56541. // when released, return the mouse to within the component's bounds
  56542. Component* current = getComponentUnderMouse();
  56543. if (current != 0)
  56544. Desktop::setMousePosition (current->getScreenBounds()
  56545. .getConstrainedPoint (current->getMouseXYRelative()));
  56546. }
  56547. isUnboundedMouseModeOn = enable;
  56548. unboundedMouseOffset = Point<int>();
  56549. revealCursor (true);
  56550. }
  56551. }
  56552. void handleUnboundedDrag (Component* current)
  56553. {
  56554. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56555. if (! screenArea.contains (lastScreenPos))
  56556. {
  56557. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56558. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56559. Desktop::setMousePosition (componentCentre);
  56560. }
  56561. else if (isCursorVisibleUntilOffscreen
  56562. && (! unboundedMouseOffset.isOrigin())
  56563. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56564. {
  56565. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56566. unboundedMouseOffset = Point<int>();
  56567. }
  56568. }
  56569. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56570. {
  56571. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56572. {
  56573. cursor = MouseCursor::NoCursor;
  56574. forcedUpdate = true;
  56575. }
  56576. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56577. {
  56578. currentCursorHandle = cursor.getHandle();
  56579. cursor.showInWindow (getPeer());
  56580. }
  56581. }
  56582. void hideCursor()
  56583. {
  56584. showMouseCursor (MouseCursor::NoCursor, true);
  56585. }
  56586. void revealCursor (bool forcedUpdate)
  56587. {
  56588. MouseCursor mc (MouseCursor::NormalCursor);
  56589. Component* current = getComponentUnderMouse();
  56590. if (current != 0)
  56591. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56592. showMouseCursor (mc, forcedUpdate);
  56593. }
  56594. int index;
  56595. bool isMouseDevice;
  56596. Point<int> lastScreenPos;
  56597. ModifierKeys buttonState;
  56598. private:
  56599. MouseInputSource& source;
  56600. Component::SafePointer<Component> componentUnderMouse;
  56601. ComponentPeer* lastPeer;
  56602. Point<int> unboundedMouseOffset;
  56603. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56604. void* currentCursorHandle;
  56605. struct RecentMouseDown
  56606. {
  56607. Point<int> position;
  56608. int64 time;
  56609. Component* component;
  56610. };
  56611. RecentMouseDown mouseDowns[4];
  56612. bool mouseMovedSignificantlySincePressed;
  56613. int64 lastTime;
  56614. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56615. {
  56616. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56617. mouseDowns[i] = mouseDowns[i - 1];
  56618. mouseDowns[0].position = screenPos;
  56619. mouseDowns[0].time = time;
  56620. mouseDowns[0].component = component;
  56621. mouseMovedSignificantlySincePressed = false;
  56622. }
  56623. void registerMouseDrag (const Point<int>& screenPos) throw()
  56624. {
  56625. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56626. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56627. }
  56628. MouseInputSourceInternal (const MouseInputSourceInternal&);
  56629. MouseInputSourceInternal& operator= (const MouseInputSourceInternal&);
  56630. };
  56631. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56632. {
  56633. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56634. }
  56635. MouseInputSource::~MouseInputSource()
  56636. {
  56637. }
  56638. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56639. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56640. bool MouseInputSource::canHover() const { return isMouse(); }
  56641. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56642. int MouseInputSource::getIndex() const { return pimpl->index; }
  56643. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56644. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56645. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56646. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56647. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56648. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56649. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56650. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56651. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56652. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56653. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56654. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56655. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56656. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56657. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56658. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56659. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56660. {
  56661. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56662. }
  56663. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56664. {
  56665. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56666. }
  56667. END_JUCE_NAMESPACE
  56668. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56669. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56670. BEGIN_JUCE_NAMESPACE
  56671. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56672. : source (0),
  56673. hoverTimeMillisecs (hoverTimeMillisecs_),
  56674. hasJustHovered (false)
  56675. {
  56676. internalTimer.owner = this;
  56677. }
  56678. MouseHoverDetector::~MouseHoverDetector()
  56679. {
  56680. setHoverComponent (0);
  56681. }
  56682. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56683. {
  56684. hoverTimeMillisecs = newTimeInMillisecs;
  56685. }
  56686. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56687. {
  56688. if (source != newSourceComponent)
  56689. {
  56690. internalTimer.stopTimer();
  56691. hasJustHovered = false;
  56692. if (source != 0)
  56693. {
  56694. // ! you need to delete the hover detector before deleting its component
  56695. jassert (source->isValidComponent());
  56696. source->removeMouseListener (&internalTimer);
  56697. }
  56698. source = newSourceComponent;
  56699. if (newSourceComponent != 0)
  56700. newSourceComponent->addMouseListener (&internalTimer, false);
  56701. }
  56702. }
  56703. void MouseHoverDetector::hoverTimerCallback()
  56704. {
  56705. internalTimer.stopTimer();
  56706. if (source != 0)
  56707. {
  56708. const Point<int> pos (source->getMouseXYRelative());
  56709. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56710. {
  56711. hasJustHovered = true;
  56712. mouseHovered (pos.getX(), pos.getY());
  56713. }
  56714. }
  56715. }
  56716. void MouseHoverDetector::checkJustHoveredCallback()
  56717. {
  56718. if (hasJustHovered)
  56719. {
  56720. hasJustHovered = false;
  56721. mouseMovedAfterHover();
  56722. }
  56723. }
  56724. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56725. {
  56726. owner->hoverTimerCallback();
  56727. }
  56728. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56729. {
  56730. stopTimer();
  56731. owner->checkJustHoveredCallback();
  56732. }
  56733. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56734. {
  56735. stopTimer();
  56736. owner->checkJustHoveredCallback();
  56737. }
  56738. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56739. {
  56740. stopTimer();
  56741. owner->checkJustHoveredCallback();
  56742. }
  56743. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56744. {
  56745. stopTimer();
  56746. owner->checkJustHoveredCallback();
  56747. }
  56748. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56749. {
  56750. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56751. {
  56752. lastX = e.x;
  56753. lastY = e.y;
  56754. if (owner->source != 0)
  56755. startTimer (owner->hoverTimeMillisecs);
  56756. owner->checkJustHoveredCallback();
  56757. }
  56758. }
  56759. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56760. {
  56761. stopTimer();
  56762. owner->checkJustHoveredCallback();
  56763. }
  56764. END_JUCE_NAMESPACE
  56765. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56766. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56767. BEGIN_JUCE_NAMESPACE
  56768. void MouseListener::mouseEnter (const MouseEvent&)
  56769. {
  56770. }
  56771. void MouseListener::mouseExit (const MouseEvent&)
  56772. {
  56773. }
  56774. void MouseListener::mouseDown (const MouseEvent&)
  56775. {
  56776. }
  56777. void MouseListener::mouseUp (const MouseEvent&)
  56778. {
  56779. }
  56780. void MouseListener::mouseDrag (const MouseEvent&)
  56781. {
  56782. }
  56783. void MouseListener::mouseMove (const MouseEvent&)
  56784. {
  56785. }
  56786. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56787. {
  56788. }
  56789. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56790. {
  56791. }
  56792. END_JUCE_NAMESPACE
  56793. /*** End of inlined file: juce_MouseListener.cpp ***/
  56794. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56795. BEGIN_JUCE_NAMESPACE
  56796. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56797. const String& buttonTextWhenTrue,
  56798. const String& buttonTextWhenFalse)
  56799. : PropertyComponent (name),
  56800. onText (buttonTextWhenTrue),
  56801. offText (buttonTextWhenFalse)
  56802. {
  56803. createButton();
  56804. button->addButtonListener (this);
  56805. }
  56806. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56807. const String& name,
  56808. const String& buttonText)
  56809. : PropertyComponent (name),
  56810. onText (buttonText),
  56811. offText (buttonText)
  56812. {
  56813. createButton();
  56814. button->setButtonText (buttonText);
  56815. button->getToggleStateValue().referTo (valueToControl);
  56816. button->setClickingTogglesState (true);
  56817. }
  56818. BooleanPropertyComponent::~BooleanPropertyComponent()
  56819. {
  56820. deleteAllChildren();
  56821. }
  56822. void BooleanPropertyComponent::createButton()
  56823. {
  56824. addAndMakeVisible (button = new ToggleButton (String::empty));
  56825. button->setClickingTogglesState (false);
  56826. }
  56827. void BooleanPropertyComponent::setState (const bool newState)
  56828. {
  56829. button->setToggleState (newState, true);
  56830. }
  56831. bool BooleanPropertyComponent::getState() const
  56832. {
  56833. return button->getToggleState();
  56834. }
  56835. void BooleanPropertyComponent::paint (Graphics& g)
  56836. {
  56837. PropertyComponent::paint (g);
  56838. const Rectangle<int> r (button->getBounds());
  56839. g.setColour (Colours::white);
  56840. g.fillRect (r);
  56841. g.setColour (findColour (ComboBox::outlineColourId));
  56842. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56843. }
  56844. void BooleanPropertyComponent::refresh()
  56845. {
  56846. button->setToggleState (getState(), false);
  56847. button->setButtonText (button->getToggleState() ? onText : offText);
  56848. }
  56849. void BooleanPropertyComponent::buttonClicked (Button*)
  56850. {
  56851. setState (! getState());
  56852. }
  56853. END_JUCE_NAMESPACE
  56854. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56855. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56856. BEGIN_JUCE_NAMESPACE
  56857. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56858. const bool triggerOnMouseDown)
  56859. : PropertyComponent (name)
  56860. {
  56861. addAndMakeVisible (button = new TextButton (String::empty));
  56862. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56863. button->addButtonListener (this);
  56864. }
  56865. ButtonPropertyComponent::~ButtonPropertyComponent()
  56866. {
  56867. deleteAllChildren();
  56868. }
  56869. void ButtonPropertyComponent::refresh()
  56870. {
  56871. button->setButtonText (getButtonText());
  56872. }
  56873. void ButtonPropertyComponent::buttonClicked (Button*)
  56874. {
  56875. buttonClicked();
  56876. }
  56877. END_JUCE_NAMESPACE
  56878. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56879. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56880. BEGIN_JUCE_NAMESPACE
  56881. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56882. : PropertyComponent (name),
  56883. comboBox (0)
  56884. {
  56885. }
  56886. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56887. const String& name,
  56888. const StringArray& choices_,
  56889. const Array <int>* choiceIDs)
  56890. : PropertyComponent (name),
  56891. choices (choices_),
  56892. comboBox (0)
  56893. {
  56894. createComboBox (choiceIDs);
  56895. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56896. }
  56897. ChoicePropertyComponent::~ChoicePropertyComponent()
  56898. {
  56899. deleteAllChildren();
  56900. }
  56901. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56902. {
  56903. // The array of IDs must contain the same number of values as the choices list!
  56904. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56905. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56906. for (int i = 0; i < choices.size(); ++i)
  56907. {
  56908. if (choices[i].isNotEmpty())
  56909. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56910. : ((*choiceIDs)[i]));
  56911. else
  56912. comboBox->addSeparator();
  56913. }
  56914. comboBox->setEditableText (false);
  56915. }
  56916. void ChoicePropertyComponent::setIndex (const int newIndex)
  56917. {
  56918. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56919. }
  56920. int ChoicePropertyComponent::getIndex() const
  56921. {
  56922. return comboBox->getSelectedItemIndex();
  56923. }
  56924. const StringArray& ChoicePropertyComponent::getChoices() const
  56925. {
  56926. return choices;
  56927. }
  56928. void ChoicePropertyComponent::refresh()
  56929. {
  56930. if (comboBox == 0)
  56931. {
  56932. createComboBox (0);
  56933. comboBox->addListener (this);
  56934. }
  56935. comboBox->setSelectedId (getIndex() + 1, true);
  56936. }
  56937. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56938. {
  56939. const int newIndex = comboBox->getSelectedId() - 1;
  56940. if (newIndex != getIndex())
  56941. setIndex (newIndex);
  56942. }
  56943. END_JUCE_NAMESPACE
  56944. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56945. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56946. BEGIN_JUCE_NAMESPACE
  56947. PropertyComponent::PropertyComponent (const String& name,
  56948. const int preferredHeight_)
  56949. : Component (name),
  56950. preferredHeight (preferredHeight_)
  56951. {
  56952. jassert (name.isNotEmpty());
  56953. }
  56954. PropertyComponent::~PropertyComponent()
  56955. {
  56956. }
  56957. void PropertyComponent::paint (Graphics& g)
  56958. {
  56959. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56960. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56961. }
  56962. void PropertyComponent::resized()
  56963. {
  56964. if (getNumChildComponents() > 0)
  56965. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56966. }
  56967. void PropertyComponent::enablementChanged()
  56968. {
  56969. repaint();
  56970. }
  56971. END_JUCE_NAMESPACE
  56972. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56973. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56974. BEGIN_JUCE_NAMESPACE
  56975. class PropertyPanel::PropertyHolderComponent : public Component
  56976. {
  56977. public:
  56978. PropertyHolderComponent()
  56979. {
  56980. }
  56981. ~PropertyHolderComponent()
  56982. {
  56983. deleteAllChildren();
  56984. }
  56985. void paint (Graphics&)
  56986. {
  56987. }
  56988. void updateLayout (int width);
  56989. void refreshAll() const;
  56990. private:
  56991. PropertyHolderComponent (const PropertyHolderComponent&);
  56992. PropertyHolderComponent& operator= (const PropertyHolderComponent&);
  56993. };
  56994. class PropertySectionComponent : public Component
  56995. {
  56996. public:
  56997. PropertySectionComponent (const String& sectionTitle,
  56998. const Array <PropertyComponent*>& newProperties,
  56999. const bool open)
  57000. : Component (sectionTitle),
  57001. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57002. isOpen_ (open)
  57003. {
  57004. for (int i = newProperties.size(); --i >= 0;)
  57005. {
  57006. addAndMakeVisible (newProperties.getUnchecked(i));
  57007. newProperties.getUnchecked(i)->refresh();
  57008. }
  57009. }
  57010. ~PropertySectionComponent()
  57011. {
  57012. deleteAllChildren();
  57013. }
  57014. void paint (Graphics& g)
  57015. {
  57016. if (titleHeight > 0)
  57017. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57018. }
  57019. void resized()
  57020. {
  57021. int y = titleHeight;
  57022. for (int i = getNumChildComponents(); --i >= 0;)
  57023. {
  57024. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57025. if (pec != 0)
  57026. {
  57027. const int prefH = pec->getPreferredHeight();
  57028. pec->setBounds (1, y, getWidth() - 2, prefH);
  57029. y += prefH;
  57030. }
  57031. }
  57032. }
  57033. int getPreferredHeight() const
  57034. {
  57035. int y = titleHeight;
  57036. if (isOpen())
  57037. {
  57038. for (int i = 0; i < getNumChildComponents(); ++i)
  57039. {
  57040. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57041. if (pec != 0)
  57042. y += pec->getPreferredHeight();
  57043. }
  57044. }
  57045. return y;
  57046. }
  57047. void setOpen (const bool open)
  57048. {
  57049. if (isOpen_ != open)
  57050. {
  57051. isOpen_ = open;
  57052. for (int i = 0; i < getNumChildComponents(); ++i)
  57053. {
  57054. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57055. if (pec != 0)
  57056. pec->setVisible (open);
  57057. }
  57058. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57059. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57060. if (pp != 0)
  57061. pp->resized();
  57062. }
  57063. }
  57064. bool isOpen() const
  57065. {
  57066. return isOpen_;
  57067. }
  57068. void refreshAll() const
  57069. {
  57070. for (int i = 0; i < getNumChildComponents(); ++i)
  57071. {
  57072. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57073. if (pec != 0)
  57074. pec->refresh();
  57075. }
  57076. }
  57077. void mouseDown (const MouseEvent&)
  57078. {
  57079. }
  57080. void mouseUp (const MouseEvent& e)
  57081. {
  57082. if (e.getMouseDownX() < titleHeight
  57083. && e.x < titleHeight
  57084. && e.y < titleHeight
  57085. && e.getNumberOfClicks() != 2)
  57086. {
  57087. setOpen (! isOpen());
  57088. }
  57089. }
  57090. void mouseDoubleClick (const MouseEvent& e)
  57091. {
  57092. if (e.y < titleHeight)
  57093. setOpen (! isOpen());
  57094. }
  57095. private:
  57096. int titleHeight;
  57097. bool isOpen_;
  57098. PropertySectionComponent (const PropertySectionComponent&);
  57099. PropertySectionComponent& operator= (const PropertySectionComponent&);
  57100. };
  57101. void PropertyPanel::PropertyHolderComponent::updateLayout (const int width)
  57102. {
  57103. int y = 0;
  57104. for (int i = getNumChildComponents(); --i >= 0;)
  57105. {
  57106. PropertySectionComponent* const section
  57107. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57108. if (section != 0)
  57109. {
  57110. const int prefH = section->getPreferredHeight();
  57111. section->setBounds (0, y, width, prefH);
  57112. y += prefH;
  57113. }
  57114. }
  57115. setSize (width, y);
  57116. repaint();
  57117. }
  57118. void PropertyPanel::PropertyHolderComponent::refreshAll() const
  57119. {
  57120. for (int i = getNumChildComponents(); --i >= 0;)
  57121. {
  57122. PropertySectionComponent* const section
  57123. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57124. if (section != 0)
  57125. section->refreshAll();
  57126. }
  57127. }
  57128. PropertyPanel::PropertyPanel()
  57129. {
  57130. messageWhenEmpty = TRANS("(nothing selected)");
  57131. addAndMakeVisible (viewport = new Viewport());
  57132. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57133. viewport->setFocusContainer (true);
  57134. }
  57135. PropertyPanel::~PropertyPanel()
  57136. {
  57137. clear();
  57138. deleteAllChildren();
  57139. }
  57140. void PropertyPanel::paint (Graphics& g)
  57141. {
  57142. if (propertyHolderComponent->getNumChildComponents() == 0)
  57143. {
  57144. g.setColour (Colours::black.withAlpha (0.5f));
  57145. g.setFont (14.0f);
  57146. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57147. Justification::centred, true);
  57148. }
  57149. }
  57150. void PropertyPanel::resized()
  57151. {
  57152. viewport->setBounds (0, 0, getWidth(), getHeight());
  57153. updatePropHolderLayout();
  57154. }
  57155. void PropertyPanel::clear()
  57156. {
  57157. if (propertyHolderComponent->getNumChildComponents() > 0)
  57158. {
  57159. propertyHolderComponent->deleteAllChildren();
  57160. repaint();
  57161. }
  57162. }
  57163. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57164. {
  57165. if (propertyHolderComponent->getNumChildComponents() == 0)
  57166. repaint();
  57167. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57168. newProperties,
  57169. true), 0);
  57170. updatePropHolderLayout();
  57171. }
  57172. void PropertyPanel::addSection (const String& sectionTitle,
  57173. const Array <PropertyComponent*>& newProperties,
  57174. const bool shouldBeOpen)
  57175. {
  57176. jassert (sectionTitle.isNotEmpty());
  57177. if (propertyHolderComponent->getNumChildComponents() == 0)
  57178. repaint();
  57179. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57180. newProperties,
  57181. shouldBeOpen), 0);
  57182. updatePropHolderLayout();
  57183. }
  57184. void PropertyPanel::updatePropHolderLayout() const
  57185. {
  57186. const int maxWidth = viewport->getMaximumVisibleWidth();
  57187. propertyHolderComponent->updateLayout (maxWidth);
  57188. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57189. if (maxWidth != newMaxWidth)
  57190. {
  57191. // need to do this twice because of scrollbars changing the size, etc.
  57192. propertyHolderComponent->updateLayout (newMaxWidth);
  57193. }
  57194. }
  57195. void PropertyPanel::refreshAll() const
  57196. {
  57197. propertyHolderComponent->refreshAll();
  57198. }
  57199. const StringArray PropertyPanel::getSectionNames() const
  57200. {
  57201. StringArray s;
  57202. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57203. {
  57204. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57205. if (section != 0 && section->getName().isNotEmpty())
  57206. s.add (section->getName());
  57207. }
  57208. return s;
  57209. }
  57210. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57211. {
  57212. int index = 0;
  57213. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57214. {
  57215. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57216. if (section != 0 && section->getName().isNotEmpty())
  57217. {
  57218. if (index == sectionIndex)
  57219. return section->isOpen();
  57220. ++index;
  57221. }
  57222. }
  57223. return false;
  57224. }
  57225. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57226. {
  57227. int index = 0;
  57228. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57229. {
  57230. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57231. if (section != 0 && section->getName().isNotEmpty())
  57232. {
  57233. if (index == sectionIndex)
  57234. {
  57235. section->setOpen (shouldBeOpen);
  57236. break;
  57237. }
  57238. ++index;
  57239. }
  57240. }
  57241. }
  57242. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57243. {
  57244. int index = 0;
  57245. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57246. {
  57247. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57248. if (section != 0 && section->getName().isNotEmpty())
  57249. {
  57250. if (index == sectionIndex)
  57251. {
  57252. section->setEnabled (shouldBeEnabled);
  57253. break;
  57254. }
  57255. ++index;
  57256. }
  57257. }
  57258. }
  57259. XmlElement* PropertyPanel::getOpennessState() const
  57260. {
  57261. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57262. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57263. const StringArray sections (getSectionNames());
  57264. for (int i = 0; i < sections.size(); ++i)
  57265. {
  57266. if (sections[i].isNotEmpty())
  57267. {
  57268. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57269. e->setAttribute ("name", sections[i]);
  57270. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57271. }
  57272. }
  57273. return xml;
  57274. }
  57275. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57276. {
  57277. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57278. {
  57279. const StringArray sections (getSectionNames());
  57280. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57281. {
  57282. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57283. e->getBoolAttribute ("open"));
  57284. }
  57285. viewport->setViewPosition (viewport->getViewPositionX(),
  57286. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57287. }
  57288. }
  57289. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57290. {
  57291. if (messageWhenEmpty != newMessage)
  57292. {
  57293. messageWhenEmpty = newMessage;
  57294. repaint();
  57295. }
  57296. }
  57297. const String& PropertyPanel::getMessageWhenEmpty() const
  57298. {
  57299. return messageWhenEmpty;
  57300. }
  57301. END_JUCE_NAMESPACE
  57302. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57303. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57304. BEGIN_JUCE_NAMESPACE
  57305. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57306. const double rangeMin,
  57307. const double rangeMax,
  57308. const double interval,
  57309. const double skewFactor)
  57310. : PropertyComponent (name)
  57311. {
  57312. addAndMakeVisible (slider = new Slider (name));
  57313. slider->setRange (rangeMin, rangeMax, interval);
  57314. slider->setSkewFactor (skewFactor);
  57315. slider->setSliderStyle (Slider::LinearBar);
  57316. slider->addListener (this);
  57317. }
  57318. SliderPropertyComponent::SliderPropertyComponent (const Value& valueToControl,
  57319. const String& name,
  57320. const double rangeMin,
  57321. const double rangeMax,
  57322. const double interval,
  57323. const double skewFactor)
  57324. : PropertyComponent (name)
  57325. {
  57326. addAndMakeVisible (slider = new Slider (name));
  57327. slider->setRange (rangeMin, rangeMax, interval);
  57328. slider->setSkewFactor (skewFactor);
  57329. slider->setSliderStyle (Slider::LinearBar);
  57330. slider->getValueObject().referTo (valueToControl);
  57331. }
  57332. SliderPropertyComponent::~SliderPropertyComponent()
  57333. {
  57334. deleteAllChildren();
  57335. }
  57336. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57337. {
  57338. }
  57339. double SliderPropertyComponent::getValue() const
  57340. {
  57341. return slider->getValue();
  57342. }
  57343. void SliderPropertyComponent::refresh()
  57344. {
  57345. slider->setValue (getValue(), false);
  57346. }
  57347. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57348. {
  57349. if (getValue() != slider->getValue())
  57350. setValue (slider->getValue());
  57351. }
  57352. END_JUCE_NAMESPACE
  57353. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57354. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57355. BEGIN_JUCE_NAMESPACE
  57356. class TextPropLabel : public Label
  57357. {
  57358. TextPropertyComponent& owner;
  57359. int maxChars;
  57360. bool isMultiline;
  57361. public:
  57362. TextPropLabel (TextPropertyComponent& owner_,
  57363. const int maxChars_, const bool isMultiline_)
  57364. : Label (String::empty, String::empty),
  57365. owner (owner_),
  57366. maxChars (maxChars_),
  57367. isMultiline (isMultiline_)
  57368. {
  57369. setEditable (true, true, false);
  57370. setColour (backgroundColourId, Colours::white);
  57371. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57372. }
  57373. ~TextPropLabel()
  57374. {
  57375. }
  57376. TextEditor* createEditorComponent()
  57377. {
  57378. TextEditor* const textEditor = Label::createEditorComponent();
  57379. textEditor->setInputRestrictions (maxChars);
  57380. if (isMultiline)
  57381. {
  57382. textEditor->setMultiLine (true, true);
  57383. textEditor->setReturnKeyStartsNewLine (true);
  57384. }
  57385. return textEditor;
  57386. }
  57387. void textWasEdited()
  57388. {
  57389. owner.textWasEdited();
  57390. }
  57391. };
  57392. TextPropertyComponent::TextPropertyComponent (const String& name,
  57393. const int maxNumChars,
  57394. const bool isMultiLine)
  57395. : PropertyComponent (name)
  57396. {
  57397. createEditor (maxNumChars, isMultiLine);
  57398. }
  57399. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57400. const String& name,
  57401. const int maxNumChars,
  57402. const bool isMultiLine)
  57403. : PropertyComponent (name)
  57404. {
  57405. createEditor (maxNumChars, isMultiLine);
  57406. textEditor->getTextValue().referTo (valueToControl);
  57407. }
  57408. TextPropertyComponent::~TextPropertyComponent()
  57409. {
  57410. deleteAllChildren();
  57411. }
  57412. void TextPropertyComponent::setText (const String& newText)
  57413. {
  57414. textEditor->setText (newText, true);
  57415. }
  57416. const String TextPropertyComponent::getText() const
  57417. {
  57418. return textEditor->getText();
  57419. }
  57420. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57421. {
  57422. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57423. if (isMultiLine)
  57424. {
  57425. textEditor->setJustificationType (Justification::topLeft);
  57426. preferredHeight = 120;
  57427. }
  57428. }
  57429. void TextPropertyComponent::refresh()
  57430. {
  57431. textEditor->setText (getText(), false);
  57432. }
  57433. void TextPropertyComponent::textWasEdited()
  57434. {
  57435. const String newText (textEditor->getText());
  57436. if (getText() != newText)
  57437. setText (newText);
  57438. }
  57439. END_JUCE_NAMESPACE
  57440. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57441. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57442. BEGIN_JUCE_NAMESPACE
  57443. class SimpleDeviceManagerInputLevelMeter : public Component,
  57444. public Timer
  57445. {
  57446. public:
  57447. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57448. : manager (manager_),
  57449. level (0)
  57450. {
  57451. startTimer (50);
  57452. manager->enableInputLevelMeasurement (true);
  57453. }
  57454. ~SimpleDeviceManagerInputLevelMeter()
  57455. {
  57456. manager->enableInputLevelMeasurement (false);
  57457. }
  57458. void timerCallback()
  57459. {
  57460. const float newLevel = (float) manager->getCurrentInputLevel();
  57461. if (fabsf (level - newLevel) > 0.005f)
  57462. {
  57463. level = newLevel;
  57464. repaint();
  57465. }
  57466. }
  57467. void paint (Graphics& g)
  57468. {
  57469. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57470. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57471. }
  57472. private:
  57473. AudioDeviceManager* const manager;
  57474. float level;
  57475. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57476. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57477. };
  57478. class AudioDeviceSelectorComponent::MidiInputSelectorComponentListBox : public ListBox,
  57479. public ListBoxModel
  57480. {
  57481. public:
  57482. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57483. const String& noItemsMessage_,
  57484. const int minNumber_,
  57485. const int maxNumber_)
  57486. : ListBox (String::empty, 0),
  57487. deviceManager (deviceManager_),
  57488. noItemsMessage (noItemsMessage_),
  57489. minNumber (minNumber_),
  57490. maxNumber (maxNumber_)
  57491. {
  57492. items = MidiInput::getDevices();
  57493. setModel (this);
  57494. setOutlineThickness (1);
  57495. }
  57496. ~MidiInputSelectorComponentListBox()
  57497. {
  57498. }
  57499. int getNumRows()
  57500. {
  57501. return items.size();
  57502. }
  57503. void paintListBoxItem (int row,
  57504. Graphics& g,
  57505. int width, int height,
  57506. bool rowIsSelected)
  57507. {
  57508. if (((unsigned int) row) < (unsigned int) items.size())
  57509. {
  57510. if (rowIsSelected)
  57511. g.fillAll (findColour (TextEditor::highlightColourId)
  57512. .withMultipliedAlpha (0.3f));
  57513. const String item (items [row]);
  57514. bool enabled = deviceManager.isMidiInputEnabled (item);
  57515. const int x = getTickX();
  57516. const float tickW = height * 0.75f;
  57517. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57518. enabled, true, true, false);
  57519. g.setFont (height * 0.6f);
  57520. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57521. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57522. }
  57523. }
  57524. void listBoxItemClicked (int row, const MouseEvent& e)
  57525. {
  57526. selectRow (row);
  57527. if (e.x < getTickX())
  57528. flipEnablement (row);
  57529. }
  57530. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57531. {
  57532. flipEnablement (row);
  57533. }
  57534. void returnKeyPressed (int row)
  57535. {
  57536. flipEnablement (row);
  57537. }
  57538. void paint (Graphics& g)
  57539. {
  57540. ListBox::paint (g);
  57541. if (items.size() == 0)
  57542. {
  57543. g.setColour (Colours::grey);
  57544. g.setFont (13.0f);
  57545. g.drawText (noItemsMessage,
  57546. 0, 0, getWidth(), getHeight() / 2,
  57547. Justification::centred, true);
  57548. }
  57549. }
  57550. int getBestHeight (const int preferredHeight)
  57551. {
  57552. const int extra = getOutlineThickness() * 2;
  57553. return jmax (getRowHeight() * 2 + extra,
  57554. jmin (getRowHeight() * getNumRows() + extra,
  57555. preferredHeight));
  57556. }
  57557. juce_UseDebuggingNewOperator
  57558. private:
  57559. AudioDeviceManager& deviceManager;
  57560. const String noItemsMessage;
  57561. StringArray items;
  57562. int minNumber, maxNumber;
  57563. void flipEnablement (const int row)
  57564. {
  57565. if (((unsigned int) row) < (unsigned int) items.size())
  57566. {
  57567. const String item (items [row]);
  57568. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57569. }
  57570. }
  57571. int getTickX() const
  57572. {
  57573. return getRowHeight() + 5;
  57574. }
  57575. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57576. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57577. };
  57578. class AudioDeviceSettingsPanel : public Component,
  57579. public ComboBoxListener,
  57580. public ChangeListener,
  57581. public ButtonListener
  57582. {
  57583. public:
  57584. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57585. AudioIODeviceType::DeviceSetupDetails& setup_,
  57586. const bool hideAdvancedOptionsWithButton)
  57587. : type (type_),
  57588. setup (setup_)
  57589. {
  57590. sampleRateDropDown = 0;
  57591. sampleRateLabel = 0;
  57592. bufferSizeDropDown = 0;
  57593. bufferSizeLabel = 0;
  57594. outputDeviceDropDown = 0;
  57595. outputDeviceLabel = 0;
  57596. inputDeviceDropDown = 0;
  57597. inputDeviceLabel = 0;
  57598. testButton = 0;
  57599. inputLevelMeter = 0;
  57600. showUIButton = 0;
  57601. inputChanList = 0;
  57602. outputChanList = 0;
  57603. inputChanLabel = 0;
  57604. outputChanLabel = 0;
  57605. showAdvancedSettingsButton = 0;
  57606. if (hideAdvancedOptionsWithButton)
  57607. {
  57608. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57609. showAdvancedSettingsButton->addButtonListener (this);
  57610. }
  57611. type->scanForDevices();
  57612. setup.manager->addChangeListener (this);
  57613. changeListenerCallback (0);
  57614. }
  57615. ~AudioDeviceSettingsPanel()
  57616. {
  57617. setup.manager->removeChangeListener (this);
  57618. deleteAndZero (outputDeviceLabel);
  57619. deleteAndZero (inputDeviceLabel);
  57620. deleteAndZero (sampleRateLabel);
  57621. deleteAndZero (bufferSizeLabel);
  57622. deleteAndZero (showUIButton);
  57623. deleteAndZero (inputChanLabel);
  57624. deleteAndZero (outputChanLabel);
  57625. deleteAndZero (showAdvancedSettingsButton);
  57626. deleteAllChildren();
  57627. }
  57628. void resized()
  57629. {
  57630. const int lx = proportionOfWidth (0.35f);
  57631. const int w = proportionOfWidth (0.4f);
  57632. const int h = 24;
  57633. const int space = 6;
  57634. const int dh = h + space;
  57635. int y = 0;
  57636. if (outputDeviceDropDown != 0)
  57637. {
  57638. outputDeviceDropDown->setBounds (lx, y, w, h);
  57639. if (testButton != 0)
  57640. testButton->setBounds (proportionOfWidth (0.77f),
  57641. outputDeviceDropDown->getY(),
  57642. proportionOfWidth (0.18f),
  57643. h);
  57644. y += dh;
  57645. }
  57646. if (inputDeviceDropDown != 0)
  57647. {
  57648. inputDeviceDropDown->setBounds (lx, y, w, h);
  57649. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57650. inputDeviceDropDown->getY(),
  57651. proportionOfWidth (0.18f),
  57652. h);
  57653. y += dh;
  57654. }
  57655. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57656. if (outputChanList != 0)
  57657. {
  57658. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57659. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57660. y += bh + space;
  57661. }
  57662. if (inputChanList != 0)
  57663. {
  57664. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57665. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57666. y += bh + space;
  57667. }
  57668. y += space * 2;
  57669. if (showAdvancedSettingsButton != 0)
  57670. {
  57671. showAdvancedSettingsButton->changeWidthToFitText (h);
  57672. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57673. }
  57674. if (sampleRateDropDown != 0)
  57675. {
  57676. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57677. || ! showAdvancedSettingsButton->isVisible());
  57678. sampleRateDropDown->setBounds (lx, y, w, h);
  57679. y += dh;
  57680. }
  57681. if (bufferSizeDropDown != 0)
  57682. {
  57683. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57684. || ! showAdvancedSettingsButton->isVisible());
  57685. bufferSizeDropDown->setBounds (lx, y, w, h);
  57686. y += dh;
  57687. }
  57688. if (showUIButton != 0)
  57689. {
  57690. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57691. || ! showAdvancedSettingsButton->isVisible());
  57692. showUIButton->changeWidthToFitText (h);
  57693. showUIButton->setTopLeftPosition (lx, y);
  57694. }
  57695. }
  57696. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57697. {
  57698. if (comboBoxThatHasChanged == 0)
  57699. return;
  57700. AudioDeviceManager::AudioDeviceSetup config;
  57701. setup.manager->getAudioDeviceSetup (config);
  57702. String error;
  57703. if (comboBoxThatHasChanged == outputDeviceDropDown
  57704. || comboBoxThatHasChanged == inputDeviceDropDown)
  57705. {
  57706. if (outputDeviceDropDown != 0)
  57707. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57708. : outputDeviceDropDown->getText();
  57709. if (inputDeviceDropDown != 0)
  57710. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57711. : inputDeviceDropDown->getText();
  57712. if (! type->hasSeparateInputsAndOutputs())
  57713. config.inputDeviceName = config.outputDeviceName;
  57714. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57715. config.useDefaultInputChannels = true;
  57716. else
  57717. config.useDefaultOutputChannels = true;
  57718. error = setup.manager->setAudioDeviceSetup (config, true);
  57719. showCorrectDeviceName (inputDeviceDropDown, true);
  57720. showCorrectDeviceName (outputDeviceDropDown, false);
  57721. updateControlPanelButton();
  57722. resized();
  57723. }
  57724. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57725. {
  57726. if (sampleRateDropDown->getSelectedId() > 0)
  57727. {
  57728. config.sampleRate = sampleRateDropDown->getSelectedId();
  57729. error = setup.manager->setAudioDeviceSetup (config, true);
  57730. }
  57731. }
  57732. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57733. {
  57734. if (bufferSizeDropDown->getSelectedId() > 0)
  57735. {
  57736. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57737. error = setup.manager->setAudioDeviceSetup (config, true);
  57738. }
  57739. }
  57740. if (error.isNotEmpty())
  57741. {
  57742. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57743. "Error when trying to open audio device!",
  57744. error);
  57745. }
  57746. }
  57747. void buttonClicked (Button* button)
  57748. {
  57749. if (button == showAdvancedSettingsButton)
  57750. {
  57751. showAdvancedSettingsButton->setVisible (false);
  57752. resized();
  57753. }
  57754. else if (button == showUIButton)
  57755. {
  57756. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57757. if (device != 0 && device->showControlPanel())
  57758. {
  57759. setup.manager->closeAudioDevice();
  57760. setup.manager->restartLastAudioDevice();
  57761. getTopLevelComponent()->toFront (true);
  57762. }
  57763. }
  57764. else if (button == testButton && testButton != 0)
  57765. {
  57766. setup.manager->playTestSound();
  57767. }
  57768. }
  57769. void updateControlPanelButton()
  57770. {
  57771. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57772. deleteAndZero (showUIButton);
  57773. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57774. {
  57775. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57776. TRANS ("opens the device's own control panel")));
  57777. showUIButton->addButtonListener (this);
  57778. }
  57779. resized();
  57780. }
  57781. void changeListenerCallback (void*)
  57782. {
  57783. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57784. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57785. {
  57786. if (outputDeviceDropDown == 0)
  57787. {
  57788. outputDeviceDropDown = new ComboBox (String::empty);
  57789. outputDeviceDropDown->addListener (this);
  57790. addAndMakeVisible (outputDeviceDropDown);
  57791. outputDeviceLabel = new Label (String::empty,
  57792. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57793. : TRANS ("device:"));
  57794. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57795. if (setup.maxNumOutputChannels > 0)
  57796. {
  57797. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57798. testButton->addButtonListener (this);
  57799. }
  57800. }
  57801. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57802. }
  57803. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57804. {
  57805. if (inputDeviceDropDown == 0)
  57806. {
  57807. inputDeviceDropDown = new ComboBox (String::empty);
  57808. inputDeviceDropDown->addListener (this);
  57809. addAndMakeVisible (inputDeviceDropDown);
  57810. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57811. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57812. addAndMakeVisible (inputLevelMeter
  57813. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57814. }
  57815. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57816. }
  57817. updateControlPanelButton();
  57818. showCorrectDeviceName (inputDeviceDropDown, true);
  57819. showCorrectDeviceName (outputDeviceDropDown, false);
  57820. if (currentDevice != 0)
  57821. {
  57822. if (setup.maxNumOutputChannels > 0
  57823. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57824. {
  57825. if (outputChanList == 0)
  57826. {
  57827. addAndMakeVisible (outputChanList
  57828. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57829. TRANS ("(no audio output channels found)")));
  57830. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57831. outputChanLabel->attachToComponent (outputChanList, true);
  57832. }
  57833. outputChanList->refresh();
  57834. }
  57835. else
  57836. {
  57837. deleteAndZero (outputChanLabel);
  57838. deleteAndZero (outputChanList);
  57839. }
  57840. if (setup.maxNumInputChannels > 0
  57841. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57842. {
  57843. if (inputChanList == 0)
  57844. {
  57845. addAndMakeVisible (inputChanList
  57846. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57847. TRANS ("(no audio input channels found)")));
  57848. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57849. inputChanLabel->attachToComponent (inputChanList, true);
  57850. }
  57851. inputChanList->refresh();
  57852. }
  57853. else
  57854. {
  57855. deleteAndZero (inputChanLabel);
  57856. deleteAndZero (inputChanList);
  57857. }
  57858. // sample rate..
  57859. {
  57860. if (sampleRateDropDown == 0)
  57861. {
  57862. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57863. sampleRateDropDown->addListener (this);
  57864. delete sampleRateLabel;
  57865. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57866. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57867. }
  57868. else
  57869. {
  57870. sampleRateDropDown->clear();
  57871. sampleRateDropDown->removeListener (this);
  57872. }
  57873. const int numRates = currentDevice->getNumSampleRates();
  57874. for (int i = 0; i < numRates; ++i)
  57875. {
  57876. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57877. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57878. }
  57879. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57880. sampleRateDropDown->addListener (this);
  57881. }
  57882. // buffer size
  57883. {
  57884. if (bufferSizeDropDown == 0)
  57885. {
  57886. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57887. bufferSizeDropDown->addListener (this);
  57888. delete bufferSizeLabel;
  57889. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57890. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57891. }
  57892. else
  57893. {
  57894. bufferSizeDropDown->clear();
  57895. }
  57896. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57897. double currentRate = currentDevice->getCurrentSampleRate();
  57898. if (currentRate == 0)
  57899. currentRate = 48000.0;
  57900. for (int i = 0; i < numBufferSizes; ++i)
  57901. {
  57902. const int bs = currentDevice->getBufferSizeSamples (i);
  57903. bufferSizeDropDown->addItem (String (bs)
  57904. + " samples ("
  57905. + String (bs * 1000.0 / currentRate, 1)
  57906. + " ms)",
  57907. bs);
  57908. }
  57909. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57910. }
  57911. }
  57912. else
  57913. {
  57914. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57915. deleteAndZero (sampleRateLabel);
  57916. deleteAndZero (bufferSizeLabel);
  57917. deleteAndZero (sampleRateDropDown);
  57918. deleteAndZero (bufferSizeDropDown);
  57919. if (outputDeviceDropDown != 0)
  57920. outputDeviceDropDown->setSelectedId (-1, true);
  57921. if (inputDeviceDropDown != 0)
  57922. inputDeviceDropDown->setSelectedId (-1, true);
  57923. }
  57924. resized();
  57925. setSize (getWidth(), getLowestY() + 4);
  57926. }
  57927. private:
  57928. AudioIODeviceType* const type;
  57929. const AudioIODeviceType::DeviceSetupDetails setup;
  57930. ComboBox* outputDeviceDropDown;
  57931. ComboBox* inputDeviceDropDown;
  57932. ComboBox* sampleRateDropDown;
  57933. ComboBox* bufferSizeDropDown;
  57934. Label* outputDeviceLabel;
  57935. Label* inputDeviceLabel;
  57936. Label* sampleRateLabel;
  57937. Label* bufferSizeLabel;
  57938. Label* inputChanLabel;
  57939. Label* outputChanLabel;
  57940. TextButton* testButton;
  57941. Component* inputLevelMeter;
  57942. TextButton* showUIButton;
  57943. TextButton* showAdvancedSettingsButton;
  57944. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57945. {
  57946. if (box != 0)
  57947. {
  57948. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57949. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57950. box->setSelectedId (index + 1, true);
  57951. if (testButton != 0 && ! isInput)
  57952. testButton->setEnabled (index >= 0);
  57953. }
  57954. }
  57955. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57956. {
  57957. const StringArray devs (type->getDeviceNames (isInputs));
  57958. combo.clear (true);
  57959. for (int i = 0; i < devs.size(); ++i)
  57960. combo.addItem (devs[i], i + 1);
  57961. combo.addItem (TRANS("<< none >>"), -1);
  57962. combo.setSelectedId (-1, true);
  57963. }
  57964. int getLowestY() const
  57965. {
  57966. int y = 0;
  57967. for (int i = getNumChildComponents(); --i >= 0;)
  57968. y = jmax (y, getChildComponent (i)->getBottom());
  57969. return y;
  57970. }
  57971. public:
  57972. class ChannelSelectorListBox : public ListBox,
  57973. public ListBoxModel
  57974. {
  57975. public:
  57976. enum BoxType
  57977. {
  57978. audioInputType,
  57979. audioOutputType
  57980. };
  57981. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57982. const BoxType type_,
  57983. const String& noItemsMessage_)
  57984. : ListBox (String::empty, 0),
  57985. setup (setup_),
  57986. type (type_),
  57987. noItemsMessage (noItemsMessage_)
  57988. {
  57989. refresh();
  57990. setModel (this);
  57991. setOutlineThickness (1);
  57992. }
  57993. ~ChannelSelectorListBox()
  57994. {
  57995. }
  57996. void refresh()
  57997. {
  57998. items.clear();
  57999. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58000. if (currentDevice != 0)
  58001. {
  58002. if (type == audioInputType)
  58003. items = currentDevice->getInputChannelNames();
  58004. else if (type == audioOutputType)
  58005. items = currentDevice->getOutputChannelNames();
  58006. if (setup.useStereoPairs)
  58007. {
  58008. StringArray pairs;
  58009. for (int i = 0; i < items.size(); i += 2)
  58010. {
  58011. const String name (items[i]);
  58012. const String name2 (items[i + 1]);
  58013. String commonBit;
  58014. for (int j = 0; j < name.length(); ++j)
  58015. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58016. commonBit = name.substring (0, j);
  58017. // Make sure we only split the name at a space, because otherwise, things
  58018. // like "input 11" + "input 12" would become "input 11 + 2"
  58019. while (commonBit.isNotEmpty() && ! CharacterFunctions::isWhitespace (commonBit.getLastCharacter()))
  58020. commonBit = commonBit.dropLastCharacters (1);
  58021. pairs.add (name.trim() + " + " + name2.substring (commonBit.length()).trim());
  58022. }
  58023. items = pairs;
  58024. }
  58025. }
  58026. updateContent();
  58027. repaint();
  58028. }
  58029. int getNumRows()
  58030. {
  58031. return items.size();
  58032. }
  58033. void paintListBoxItem (int row,
  58034. Graphics& g,
  58035. int width, int height,
  58036. bool rowIsSelected)
  58037. {
  58038. if (((unsigned int) row) < (unsigned int) items.size())
  58039. {
  58040. if (rowIsSelected)
  58041. g.fillAll (findColour (TextEditor::highlightColourId)
  58042. .withMultipliedAlpha (0.3f));
  58043. const String item (items [row]);
  58044. bool enabled = false;
  58045. AudioDeviceManager::AudioDeviceSetup config;
  58046. setup.manager->getAudioDeviceSetup (config);
  58047. if (setup.useStereoPairs)
  58048. {
  58049. if (type == audioInputType)
  58050. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58051. else if (type == audioOutputType)
  58052. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58053. }
  58054. else
  58055. {
  58056. if (type == audioInputType)
  58057. enabled = config.inputChannels [row];
  58058. else if (type == audioOutputType)
  58059. enabled = config.outputChannels [row];
  58060. }
  58061. const int x = getTickX();
  58062. const float tickW = height * 0.75f;
  58063. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58064. enabled, true, true, false);
  58065. g.setFont (height * 0.6f);
  58066. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58067. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58068. }
  58069. }
  58070. void listBoxItemClicked (int row, const MouseEvent& e)
  58071. {
  58072. selectRow (row);
  58073. if (e.x < getTickX())
  58074. flipEnablement (row);
  58075. }
  58076. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58077. {
  58078. flipEnablement (row);
  58079. }
  58080. void returnKeyPressed (int row)
  58081. {
  58082. flipEnablement (row);
  58083. }
  58084. void paint (Graphics& g)
  58085. {
  58086. ListBox::paint (g);
  58087. if (items.size() == 0)
  58088. {
  58089. g.setColour (Colours::grey);
  58090. g.setFont (13.0f);
  58091. g.drawText (noItemsMessage,
  58092. 0, 0, getWidth(), getHeight() / 2,
  58093. Justification::centred, true);
  58094. }
  58095. }
  58096. int getBestHeight (int maxHeight)
  58097. {
  58098. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58099. getNumRows())
  58100. + getOutlineThickness() * 2;
  58101. }
  58102. juce_UseDebuggingNewOperator
  58103. private:
  58104. const AudioIODeviceType::DeviceSetupDetails setup;
  58105. const BoxType type;
  58106. const String noItemsMessage;
  58107. StringArray items;
  58108. void flipEnablement (const int row)
  58109. {
  58110. jassert (type == audioInputType || type == audioOutputType);
  58111. if (((unsigned int) row) < (unsigned int) items.size())
  58112. {
  58113. AudioDeviceManager::AudioDeviceSetup config;
  58114. setup.manager->getAudioDeviceSetup (config);
  58115. if (setup.useStereoPairs)
  58116. {
  58117. BigInteger bits;
  58118. BigInteger& original = (type == audioInputType ? config.inputChannels
  58119. : config.outputChannels);
  58120. int i;
  58121. for (i = 0; i < 256; i += 2)
  58122. bits.setBit (i / 2, original [i] || original [i + 1]);
  58123. if (type == audioInputType)
  58124. {
  58125. config.useDefaultInputChannels = false;
  58126. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58127. }
  58128. else
  58129. {
  58130. config.useDefaultOutputChannels = false;
  58131. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58132. }
  58133. for (i = 0; i < 256; ++i)
  58134. original.setBit (i, bits [i / 2]);
  58135. }
  58136. else
  58137. {
  58138. if (type == audioInputType)
  58139. {
  58140. config.useDefaultInputChannels = false;
  58141. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58142. }
  58143. else
  58144. {
  58145. config.useDefaultOutputChannels = false;
  58146. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58147. }
  58148. }
  58149. String error (setup.manager->setAudioDeviceSetup (config, true));
  58150. if (! error.isEmpty())
  58151. {
  58152. //xxx
  58153. }
  58154. }
  58155. }
  58156. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58157. {
  58158. const int numActive = chans.countNumberOfSetBits();
  58159. if (chans [index])
  58160. {
  58161. if (numActive > minNumber)
  58162. chans.setBit (index, false);
  58163. }
  58164. else
  58165. {
  58166. if (numActive >= maxNumber)
  58167. {
  58168. const int firstActiveChan = chans.findNextSetBit();
  58169. chans.setBit (index > firstActiveChan
  58170. ? firstActiveChan : chans.getHighestBit(),
  58171. false);
  58172. }
  58173. chans.setBit (index, true);
  58174. }
  58175. }
  58176. int getTickX() const
  58177. {
  58178. return getRowHeight() + 5;
  58179. }
  58180. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58181. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58182. };
  58183. private:
  58184. ChannelSelectorListBox* inputChanList;
  58185. ChannelSelectorListBox* outputChanList;
  58186. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58187. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58188. };
  58189. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58190. const int minInputChannels_,
  58191. const int maxInputChannels_,
  58192. const int minOutputChannels_,
  58193. const int maxOutputChannels_,
  58194. const bool showMidiInputOptions,
  58195. const bool showMidiOutputSelector,
  58196. const bool showChannelsAsStereoPairs_,
  58197. const bool hideAdvancedOptionsWithButton_)
  58198. : deviceManager (deviceManager_),
  58199. deviceTypeDropDown (0),
  58200. deviceTypeDropDownLabel (0),
  58201. audioDeviceSettingsComp (0),
  58202. minOutputChannels (minOutputChannels_),
  58203. maxOutputChannels (maxOutputChannels_),
  58204. minInputChannels (minInputChannels_),
  58205. maxInputChannels (maxInputChannels_),
  58206. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58207. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58208. {
  58209. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58210. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58211. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58212. {
  58213. deviceTypeDropDown = new ComboBox (String::empty);
  58214. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58215. {
  58216. deviceTypeDropDown
  58217. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58218. i + 1);
  58219. }
  58220. addAndMakeVisible (deviceTypeDropDown);
  58221. deviceTypeDropDown->addListener (this);
  58222. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58223. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58224. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58225. }
  58226. if (showMidiInputOptions)
  58227. {
  58228. addAndMakeVisible (midiInputsList
  58229. = new MidiInputSelectorComponentListBox (deviceManager,
  58230. TRANS("(no midi inputs available)"),
  58231. 0, 0));
  58232. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58233. midiInputsLabel->setJustificationType (Justification::topRight);
  58234. midiInputsLabel->attachToComponent (midiInputsList, true);
  58235. }
  58236. else
  58237. {
  58238. midiInputsList = 0;
  58239. midiInputsLabel = 0;
  58240. }
  58241. if (showMidiOutputSelector)
  58242. {
  58243. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58244. midiOutputSelector->addListener (this);
  58245. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58246. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58247. }
  58248. else
  58249. {
  58250. midiOutputSelector = 0;
  58251. midiOutputLabel = 0;
  58252. }
  58253. deviceManager_.addChangeListener (this);
  58254. changeListenerCallback (0);
  58255. }
  58256. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58257. {
  58258. deviceManager.removeChangeListener (this);
  58259. deleteAllChildren();
  58260. }
  58261. void AudioDeviceSelectorComponent::resized()
  58262. {
  58263. const int lx = proportionOfWidth (0.35f);
  58264. const int w = proportionOfWidth (0.4f);
  58265. const int h = 24;
  58266. const int space = 6;
  58267. const int dh = h + space;
  58268. int y = 15;
  58269. if (deviceTypeDropDown != 0)
  58270. {
  58271. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58272. y += dh + space * 2;
  58273. }
  58274. if (audioDeviceSettingsComp != 0)
  58275. {
  58276. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58277. y += audioDeviceSettingsComp->getHeight() + space;
  58278. }
  58279. if (midiInputsList != 0)
  58280. {
  58281. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58282. midiInputsList->setBounds (lx, y, w, bh);
  58283. y += bh + space;
  58284. }
  58285. if (midiOutputSelector != 0)
  58286. midiOutputSelector->setBounds (lx, y, w, h);
  58287. }
  58288. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58289. {
  58290. if (child == audioDeviceSettingsComp)
  58291. resized();
  58292. }
  58293. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58294. {
  58295. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58296. if (device != 0 && device->hasControlPanel())
  58297. {
  58298. if (device->showControlPanel())
  58299. deviceManager.restartLastAudioDevice();
  58300. getTopLevelComponent()->toFront (true);
  58301. }
  58302. }
  58303. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58304. {
  58305. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58306. {
  58307. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58308. if (type != 0)
  58309. {
  58310. deleteAndZero (audioDeviceSettingsComp);
  58311. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58312. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58313. }
  58314. }
  58315. else if (comboBoxThatHasChanged == midiOutputSelector)
  58316. {
  58317. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58318. }
  58319. }
  58320. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58321. {
  58322. if (deviceTypeDropDown != 0)
  58323. {
  58324. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58325. }
  58326. if (audioDeviceSettingsComp == 0
  58327. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58328. {
  58329. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58330. deleteAndZero (audioDeviceSettingsComp);
  58331. AudioIODeviceType* const type
  58332. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58333. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58334. if (type != 0)
  58335. {
  58336. AudioIODeviceType::DeviceSetupDetails details;
  58337. details.manager = &deviceManager;
  58338. details.minNumInputChannels = minInputChannels;
  58339. details.maxNumInputChannels = maxInputChannels;
  58340. details.minNumOutputChannels = minOutputChannels;
  58341. details.maxNumOutputChannels = maxOutputChannels;
  58342. details.useStereoPairs = showChannelsAsStereoPairs;
  58343. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58344. if (audioDeviceSettingsComp != 0)
  58345. {
  58346. addAndMakeVisible (audioDeviceSettingsComp);
  58347. audioDeviceSettingsComp->resized();
  58348. }
  58349. }
  58350. }
  58351. if (midiInputsList != 0)
  58352. {
  58353. midiInputsList->updateContent();
  58354. midiInputsList->repaint();
  58355. }
  58356. if (midiOutputSelector != 0)
  58357. {
  58358. midiOutputSelector->clear();
  58359. const StringArray midiOuts (MidiOutput::getDevices());
  58360. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58361. midiOutputSelector->addSeparator();
  58362. for (int i = 0; i < midiOuts.size(); ++i)
  58363. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58364. int current = -1;
  58365. if (deviceManager.getDefaultMidiOutput() != 0)
  58366. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58367. midiOutputSelector->setSelectedId (current, true);
  58368. }
  58369. resized();
  58370. }
  58371. END_JUCE_NAMESPACE
  58372. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58373. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58374. BEGIN_JUCE_NAMESPACE
  58375. BubbleComponent::BubbleComponent()
  58376. : side (0),
  58377. allowablePlacements (above | below | left | right),
  58378. arrowTipX (0.0f),
  58379. arrowTipY (0.0f)
  58380. {
  58381. setInterceptsMouseClicks (false, false);
  58382. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58383. setComponentEffect (&shadow);
  58384. }
  58385. BubbleComponent::~BubbleComponent()
  58386. {
  58387. }
  58388. void BubbleComponent::paint (Graphics& g)
  58389. {
  58390. int x = content.getX();
  58391. int y = content.getY();
  58392. int w = content.getWidth();
  58393. int h = content.getHeight();
  58394. int cw, ch;
  58395. getContentSize (cw, ch);
  58396. if (side == 3)
  58397. x += w - cw;
  58398. else if (side != 1)
  58399. x += (w - cw) / 2;
  58400. w = cw;
  58401. if (side == 2)
  58402. y += h - ch;
  58403. else if (side != 0)
  58404. y += (h - ch) / 2;
  58405. h = ch;
  58406. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58407. (float) x, (float) y,
  58408. (float) w, (float) h);
  58409. const int cx = x + (w - cw) / 2;
  58410. const int cy = y + (h - ch) / 2;
  58411. const int indent = 3;
  58412. g.setOrigin (cx + indent, cy + indent);
  58413. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58414. paintContent (g, cw - indent * 2, ch - indent * 2);
  58415. }
  58416. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58417. {
  58418. allowablePlacements = newPlacement;
  58419. }
  58420. void BubbleComponent::setPosition (Component* componentToPointTo)
  58421. {
  58422. jassert (componentToPointTo->isValidComponent());
  58423. Point<int> pos;
  58424. if (getParentComponent() != 0)
  58425. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58426. else
  58427. pos = componentToPointTo->relativePositionToGlobal (pos);
  58428. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58429. }
  58430. void BubbleComponent::setPosition (const int arrowTipX_,
  58431. const int arrowTipY_)
  58432. {
  58433. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58434. }
  58435. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58436. {
  58437. Rectangle<int> availableSpace;
  58438. if (getParentComponent() != 0)
  58439. {
  58440. availableSpace.setSize (getParentComponent()->getWidth(),
  58441. getParentComponent()->getHeight());
  58442. }
  58443. else
  58444. {
  58445. availableSpace = getParentMonitorArea();
  58446. }
  58447. int x = 0;
  58448. int y = 0;
  58449. int w = 150;
  58450. int h = 30;
  58451. getContentSize (w, h);
  58452. w += 30;
  58453. h += 30;
  58454. const float edgeIndent = 2.0f;
  58455. const int arrowLength = jmin (10, h / 3, w / 3);
  58456. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58457. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58458. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58459. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58460. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58461. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58462. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58463. {
  58464. spaceLeft = spaceRight = 0;
  58465. }
  58466. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58467. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58468. {
  58469. spaceAbove = spaceBelow = 0;
  58470. }
  58471. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58472. {
  58473. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58474. arrowTipX = w * 0.5f;
  58475. content.setSize (w, h - arrowLength);
  58476. if (spaceAbove >= spaceBelow)
  58477. {
  58478. // above
  58479. y = rectangleToPointTo.getY() - h;
  58480. content.setPosition (0, 0);
  58481. arrowTipY = h - edgeIndent;
  58482. side = 2;
  58483. }
  58484. else
  58485. {
  58486. // below
  58487. y = rectangleToPointTo.getBottom();
  58488. content.setPosition (0, arrowLength);
  58489. arrowTipY = edgeIndent;
  58490. side = 0;
  58491. }
  58492. }
  58493. else
  58494. {
  58495. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58496. arrowTipY = h * 0.5f;
  58497. content.setSize (w - arrowLength, h);
  58498. if (spaceLeft > spaceRight)
  58499. {
  58500. // on the left
  58501. x = rectangleToPointTo.getX() - w;
  58502. content.setPosition (0, 0);
  58503. arrowTipX = w - edgeIndent;
  58504. side = 3;
  58505. }
  58506. else
  58507. {
  58508. // on the right
  58509. x = rectangleToPointTo.getRight();
  58510. content.setPosition (arrowLength, 0);
  58511. arrowTipX = edgeIndent;
  58512. side = 1;
  58513. }
  58514. }
  58515. setBounds (x, y, w, h);
  58516. }
  58517. END_JUCE_NAMESPACE
  58518. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58519. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58520. BEGIN_JUCE_NAMESPACE
  58521. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58522. : fadeOutLength (fadeOutLengthMs),
  58523. deleteAfterUse (false)
  58524. {
  58525. }
  58526. BubbleMessageComponent::~BubbleMessageComponent()
  58527. {
  58528. fadeOutComponent (fadeOutLength);
  58529. }
  58530. void BubbleMessageComponent::showAt (int x, int y,
  58531. const String& text,
  58532. const int numMillisecondsBeforeRemoving,
  58533. const bool removeWhenMouseClicked,
  58534. const bool deleteSelfAfterUse)
  58535. {
  58536. textLayout.clear();
  58537. textLayout.setText (text, Font (14.0f));
  58538. textLayout.layout (256, Justification::centredLeft, true);
  58539. setPosition (x, y);
  58540. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58541. }
  58542. void BubbleMessageComponent::showAt (Component* const component,
  58543. const String& text,
  58544. const int numMillisecondsBeforeRemoving,
  58545. const bool removeWhenMouseClicked,
  58546. const bool deleteSelfAfterUse)
  58547. {
  58548. textLayout.clear();
  58549. textLayout.setText (text, Font (14.0f));
  58550. textLayout.layout (256, Justification::centredLeft, true);
  58551. setPosition (component);
  58552. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58553. }
  58554. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58555. const bool removeWhenMouseClicked,
  58556. const bool deleteSelfAfterUse)
  58557. {
  58558. setVisible (true);
  58559. deleteAfterUse = deleteSelfAfterUse;
  58560. if (numMillisecondsBeforeRemoving > 0)
  58561. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58562. else
  58563. expiryTime = 0;
  58564. startTimer (77);
  58565. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58566. if (! (removeWhenMouseClicked && isShowing()))
  58567. mouseClickCounter += 0xfffff;
  58568. repaint();
  58569. }
  58570. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58571. {
  58572. w = textLayout.getWidth() + 16;
  58573. h = textLayout.getHeight() + 16;
  58574. }
  58575. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58576. {
  58577. g.setColour (findColour (TooltipWindow::textColourId));
  58578. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58579. }
  58580. void BubbleMessageComponent::timerCallback()
  58581. {
  58582. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58583. {
  58584. stopTimer();
  58585. setVisible (false);
  58586. if (deleteAfterUse)
  58587. delete this;
  58588. }
  58589. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58590. {
  58591. stopTimer();
  58592. fadeOutComponent (fadeOutLength);
  58593. if (deleteAfterUse)
  58594. delete this;
  58595. }
  58596. }
  58597. END_JUCE_NAMESPACE
  58598. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58599. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58600. BEGIN_JUCE_NAMESPACE
  58601. static const int swatchesPerRow = 8;
  58602. static const int swatchHeight = 22;
  58603. class ColourComponentSlider : public Slider
  58604. {
  58605. public:
  58606. ColourComponentSlider (const String& name)
  58607. : Slider (name)
  58608. {
  58609. setRange (0.0, 255.0, 1.0);
  58610. }
  58611. ~ColourComponentSlider()
  58612. {
  58613. }
  58614. const String getTextFromValue (double value)
  58615. {
  58616. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58617. }
  58618. double getValueFromText (const String& text)
  58619. {
  58620. return (double) text.getHexValue32();
  58621. }
  58622. private:
  58623. ColourComponentSlider (const ColourComponentSlider&);
  58624. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58625. };
  58626. class ColourSpaceMarker : public Component
  58627. {
  58628. public:
  58629. ColourSpaceMarker()
  58630. {
  58631. setInterceptsMouseClicks (false, false);
  58632. }
  58633. ~ColourSpaceMarker()
  58634. {
  58635. }
  58636. void paint (Graphics& g)
  58637. {
  58638. g.setColour (Colour::greyLevel (0.1f));
  58639. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58640. g.setColour (Colour::greyLevel (0.9f));
  58641. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58642. }
  58643. private:
  58644. ColourSpaceMarker (const ColourSpaceMarker&);
  58645. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58646. };
  58647. class ColourSelector::ColourSpaceView : public Component
  58648. {
  58649. public:
  58650. ColourSpaceView (ColourSelector* owner_,
  58651. float& h_, float& s_, float& v_,
  58652. const int edgeSize)
  58653. : owner (owner_),
  58654. h (h_), s (s_), v (v_),
  58655. lastHue (0.0f),
  58656. edge (edgeSize)
  58657. {
  58658. addAndMakeVisible (marker = new ColourSpaceMarker());
  58659. setMouseCursor (MouseCursor::CrosshairCursor);
  58660. }
  58661. ~ColourSpaceView()
  58662. {
  58663. deleteAllChildren();
  58664. }
  58665. void paint (Graphics& g)
  58666. {
  58667. if (colours == 0)
  58668. {
  58669. const int width = getWidth() / 2;
  58670. const int height = getHeight() / 2;
  58671. colours = new Image (Image::RGB, width, height, false);
  58672. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58673. for (int y = 0; y < height; ++y)
  58674. {
  58675. const float v = 1.0f - y / (float) height;
  58676. for (int x = 0; x < width; ++x)
  58677. {
  58678. const float s = x / (float) width;
  58679. const Colour col (h, s, v, 1.0f);
  58680. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58681. pix->set (col.getPixelARGB());
  58682. }
  58683. }
  58684. }
  58685. g.setOpacity (1.0f);
  58686. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58687. 0, 0, colours->getWidth(), colours->getHeight());
  58688. }
  58689. void mouseDown (const MouseEvent& e)
  58690. {
  58691. mouseDrag (e);
  58692. }
  58693. void mouseDrag (const MouseEvent& e)
  58694. {
  58695. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58696. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58697. owner->setSV (s, v);
  58698. }
  58699. void updateIfNeeded()
  58700. {
  58701. if (lastHue != h)
  58702. {
  58703. lastHue = h;
  58704. colours = 0;
  58705. repaint();
  58706. }
  58707. updateMarker();
  58708. }
  58709. void resized()
  58710. {
  58711. colours = 0;
  58712. updateMarker();
  58713. }
  58714. private:
  58715. ColourSelector* const owner;
  58716. float& h;
  58717. float& s;
  58718. float& v;
  58719. float lastHue;
  58720. ColourSpaceMarker* marker;
  58721. const int edge;
  58722. ScopedPointer <Image> colours;
  58723. void updateMarker() const throw()
  58724. {
  58725. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58726. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58727. edge * 2, edge * 2);
  58728. }
  58729. ColourSpaceView (const ColourSpaceView&);
  58730. ColourSpaceView& operator= (const ColourSpaceView&);
  58731. };
  58732. class HueSelectorMarker : public Component
  58733. {
  58734. public:
  58735. HueSelectorMarker()
  58736. {
  58737. setInterceptsMouseClicks (false, false);
  58738. }
  58739. ~HueSelectorMarker()
  58740. {
  58741. }
  58742. void paint (Graphics& g)
  58743. {
  58744. Path p;
  58745. p.addTriangle (1.0f, 1.0f,
  58746. getWidth() * 0.3f, getHeight() * 0.5f,
  58747. 1.0f, getHeight() - 1.0f);
  58748. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58749. getWidth() * 0.7f, getHeight() * 0.5f,
  58750. getWidth() - 1.0f, getHeight() - 1.0f);
  58751. g.setColour (Colours::white.withAlpha (0.75f));
  58752. g.fillPath (p);
  58753. g.setColour (Colours::black.withAlpha (0.75f));
  58754. g.strokePath (p, PathStrokeType (1.2f));
  58755. }
  58756. private:
  58757. HueSelectorMarker (const HueSelectorMarker&);
  58758. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58759. };
  58760. class ColourSelector::HueSelectorComp : public Component
  58761. {
  58762. public:
  58763. HueSelectorComp (ColourSelector* owner_,
  58764. float& h_, float& s_, float& v_,
  58765. const int edgeSize)
  58766. : owner (owner_),
  58767. h (h_), s (s_), v (v_),
  58768. lastHue (0.0f),
  58769. edge (edgeSize)
  58770. {
  58771. addAndMakeVisible (marker = new HueSelectorMarker());
  58772. }
  58773. ~HueSelectorComp()
  58774. {
  58775. deleteAllChildren();
  58776. }
  58777. void paint (Graphics& g)
  58778. {
  58779. const float yScale = 1.0f / (getHeight() - edge * 2);
  58780. const Rectangle<int> clip (g.getClipBounds());
  58781. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58782. {
  58783. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58784. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58785. }
  58786. }
  58787. void resized()
  58788. {
  58789. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58790. getWidth(), edge * 2);
  58791. }
  58792. void mouseDown (const MouseEvent& e)
  58793. {
  58794. mouseDrag (e);
  58795. }
  58796. void mouseDrag (const MouseEvent& e)
  58797. {
  58798. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58799. owner->setHue (hue);
  58800. }
  58801. void updateIfNeeded()
  58802. {
  58803. resized();
  58804. }
  58805. private:
  58806. ColourSelector* const owner;
  58807. float& h;
  58808. float& s;
  58809. float& v;
  58810. float lastHue;
  58811. HueSelectorMarker* marker;
  58812. const int edge;
  58813. HueSelectorComp (const HueSelectorComp&);
  58814. HueSelectorComp& operator= (const HueSelectorComp&);
  58815. };
  58816. class ColourSelector::SwatchComponent : public Component
  58817. {
  58818. public:
  58819. SwatchComponent (ColourSelector* owner_, int index_)
  58820. : owner (owner_),
  58821. index (index_)
  58822. {
  58823. }
  58824. ~SwatchComponent()
  58825. {
  58826. }
  58827. void paint (Graphics& g)
  58828. {
  58829. const Colour colour (owner->getSwatchColour (index));
  58830. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58831. 6, 6,
  58832. Colour (0xffdddddd).overlaidWith (colour),
  58833. Colour (0xffffffff).overlaidWith (colour));
  58834. }
  58835. void mouseDown (const MouseEvent&)
  58836. {
  58837. PopupMenu m;
  58838. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58839. m.addSeparator();
  58840. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58841. const int r = m.showAt (this);
  58842. if (r == 1)
  58843. {
  58844. owner->setCurrentColour (owner->getSwatchColour (index));
  58845. }
  58846. else if (r == 2)
  58847. {
  58848. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58849. {
  58850. owner->setSwatchColour (index, owner->getCurrentColour());
  58851. repaint();
  58852. }
  58853. }
  58854. }
  58855. private:
  58856. ColourSelector* const owner;
  58857. const int index;
  58858. SwatchComponent (const SwatchComponent&);
  58859. SwatchComponent& operator= (const SwatchComponent&);
  58860. };
  58861. ColourSelector::ColourSelector (const int flags_,
  58862. const int edgeGap_,
  58863. const int gapAroundColourSpaceComponent)
  58864. : colour (Colours::white),
  58865. flags (flags_),
  58866. topSpace (0),
  58867. edgeGap (edgeGap_)
  58868. {
  58869. // not much point having a selector with no components in it!
  58870. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58871. updateHSV();
  58872. if ((flags & showSliders) != 0)
  58873. {
  58874. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58875. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58876. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58877. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58878. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58879. for (int i = 4; --i >= 0;)
  58880. sliders[i]->addListener (this);
  58881. }
  58882. else
  58883. {
  58884. zeromem (sliders, sizeof (sliders));
  58885. }
  58886. if ((flags & showColourspace) != 0)
  58887. {
  58888. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58889. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58890. }
  58891. else
  58892. {
  58893. colourSpace = 0;
  58894. hueSelector = 0;
  58895. }
  58896. update();
  58897. }
  58898. ColourSelector::~ColourSelector()
  58899. {
  58900. dispatchPendingMessages();
  58901. swatchComponents.clear();
  58902. deleteAllChildren();
  58903. }
  58904. const Colour ColourSelector::getCurrentColour() const
  58905. {
  58906. return ((flags & showAlphaChannel) != 0) ? colour
  58907. : colour.withAlpha ((uint8) 0xff);
  58908. }
  58909. void ColourSelector::setCurrentColour (const Colour& c)
  58910. {
  58911. if (c != colour)
  58912. {
  58913. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58914. updateHSV();
  58915. update();
  58916. }
  58917. }
  58918. void ColourSelector::setHue (float newH)
  58919. {
  58920. newH = jlimit (0.0f, 1.0f, newH);
  58921. if (h != newH)
  58922. {
  58923. h = newH;
  58924. colour = Colour (h, s, v, colour.getFloatAlpha());
  58925. update();
  58926. }
  58927. }
  58928. void ColourSelector::setSV (float newS, float newV)
  58929. {
  58930. newS = jlimit (0.0f, 1.0f, newS);
  58931. newV = jlimit (0.0f, 1.0f, newV);
  58932. if (s != newS || v != newV)
  58933. {
  58934. s = newS;
  58935. v = newV;
  58936. colour = Colour (h, s, v, colour.getFloatAlpha());
  58937. update();
  58938. }
  58939. }
  58940. void ColourSelector::updateHSV()
  58941. {
  58942. colour.getHSB (h, s, v);
  58943. }
  58944. void ColourSelector::update()
  58945. {
  58946. if (sliders[0] != 0)
  58947. {
  58948. sliders[0]->setValue ((int) colour.getRed());
  58949. sliders[1]->setValue ((int) colour.getGreen());
  58950. sliders[2]->setValue ((int) colour.getBlue());
  58951. sliders[3]->setValue ((int) colour.getAlpha());
  58952. }
  58953. if (colourSpace != 0)
  58954. {
  58955. colourSpace->updateIfNeeded();
  58956. hueSelector->updateIfNeeded();
  58957. }
  58958. if ((flags & showColourAtTop) != 0)
  58959. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58960. sendChangeMessage (this);
  58961. }
  58962. void ColourSelector::paint (Graphics& g)
  58963. {
  58964. g.fillAll (findColour (backgroundColourId));
  58965. if ((flags & showColourAtTop) != 0)
  58966. {
  58967. const Colour colour (getCurrentColour());
  58968. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58969. 10, 10,
  58970. Colour (0xffdddddd).overlaidWith (colour),
  58971. Colour (0xffffffff).overlaidWith (colour));
  58972. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58973. g.setFont (14.0f, true);
  58974. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58975. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58976. Justification::centred, false);
  58977. }
  58978. if ((flags & showSliders) != 0)
  58979. {
  58980. g.setColour (findColour (labelTextColourId));
  58981. g.setFont (11.0f);
  58982. for (int i = 4; --i >= 0;)
  58983. {
  58984. if (sliders[i]->isVisible())
  58985. g.drawText (sliders[i]->getName() + ":",
  58986. 0, sliders[i]->getY(),
  58987. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58988. Justification::centredRight, false);
  58989. }
  58990. }
  58991. }
  58992. void ColourSelector::resized()
  58993. {
  58994. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58995. const int numSwatches = getNumSwatches();
  58996. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58997. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58998. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58999. int y = topSpace;
  59000. if ((flags & showColourspace) != 0)
  59001. {
  59002. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59003. colourSpace->setBounds (edgeGap, y,
  59004. getWidth() - hueWidth - edgeGap - 4,
  59005. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59006. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59007. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59008. colourSpace->getHeight());
  59009. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59010. }
  59011. if ((flags & showSliders) != 0)
  59012. {
  59013. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59014. for (int i = 0; i < numSliders; ++i)
  59015. {
  59016. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59017. proportionOfWidth (0.72f), sliderHeight - 2);
  59018. y += sliderHeight;
  59019. }
  59020. }
  59021. if (numSwatches > 0)
  59022. {
  59023. const int startX = 8;
  59024. const int xGap = 4;
  59025. const int yGap = 4;
  59026. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59027. y += edgeGap;
  59028. if (swatchComponents.size() != numSwatches)
  59029. {
  59030. swatchComponents.clear();
  59031. for (int i = 0; i < numSwatches; ++i)
  59032. {
  59033. SwatchComponent* const sc = new SwatchComponent (this, i);
  59034. swatchComponents.add (sc);
  59035. addAndMakeVisible (sc);
  59036. }
  59037. }
  59038. int x = startX;
  59039. for (int i = 0; i < swatchComponents.size(); ++i)
  59040. {
  59041. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59042. sc->setBounds (x + xGap / 2,
  59043. y + yGap / 2,
  59044. swatchWidth - xGap,
  59045. swatchHeight - yGap);
  59046. if (((i + 1) % swatchesPerRow) == 0)
  59047. {
  59048. x = startX;
  59049. y += swatchHeight;
  59050. }
  59051. else
  59052. {
  59053. x += swatchWidth;
  59054. }
  59055. }
  59056. }
  59057. }
  59058. void ColourSelector::sliderValueChanged (Slider*)
  59059. {
  59060. if (sliders[0] != 0)
  59061. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59062. (uint8) sliders[1]->getValue(),
  59063. (uint8) sliders[2]->getValue(),
  59064. (uint8) sliders[3]->getValue()));
  59065. }
  59066. int ColourSelector::getNumSwatches() const
  59067. {
  59068. return 0;
  59069. }
  59070. const Colour ColourSelector::getSwatchColour (const int) const
  59071. {
  59072. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59073. return Colours::black;
  59074. }
  59075. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59076. {
  59077. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59078. }
  59079. END_JUCE_NAMESPACE
  59080. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59081. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59082. BEGIN_JUCE_NAMESPACE
  59083. class ShadowWindow : public Component
  59084. {
  59085. Component* owner;
  59086. Image** shadowImageSections;
  59087. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59088. public:
  59089. ShadowWindow (Component* const owner_,
  59090. const int type_,
  59091. Image** const shadowImageSections_)
  59092. : owner (owner_),
  59093. shadowImageSections (shadowImageSections_),
  59094. type (type_)
  59095. {
  59096. setInterceptsMouseClicks (false, false);
  59097. if (owner_->isOnDesktop())
  59098. {
  59099. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59100. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59101. | ComponentPeer::windowIsTemporary
  59102. | ComponentPeer::windowIgnoresKeyPresses);
  59103. }
  59104. else if (owner_->getParentComponent() != 0)
  59105. {
  59106. owner_->getParentComponent()->addChildComponent (this);
  59107. }
  59108. }
  59109. ~ShadowWindow()
  59110. {
  59111. }
  59112. void paint (Graphics& g)
  59113. {
  59114. Image* const topLeft = shadowImageSections [type * 3];
  59115. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59116. Image* const filler = shadowImageSections [type * 3 + 2];
  59117. g.setOpacity (1.0f);
  59118. if (type < 2)
  59119. {
  59120. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59121. g.drawImage (topLeft,
  59122. 0, 0, topLeft->getWidth(), imH,
  59123. 0, 0, topLeft->getWidth(), imH);
  59124. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59125. g.drawImage (bottomRight,
  59126. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59127. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59128. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59129. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59130. }
  59131. else
  59132. {
  59133. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59134. g.drawImage (topLeft,
  59135. 0, 0, imW, topLeft->getHeight(),
  59136. 0, 0, imW, topLeft->getHeight());
  59137. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59138. g.drawImage (bottomRight,
  59139. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59140. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59141. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59142. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59143. }
  59144. }
  59145. void resized()
  59146. {
  59147. repaint(); // (needed for correct repainting)
  59148. }
  59149. private:
  59150. ShadowWindow (const ShadowWindow&);
  59151. ShadowWindow& operator= (const ShadowWindow&);
  59152. };
  59153. DropShadower::DropShadower (const float alpha_,
  59154. const int xOffset_,
  59155. const int yOffset_,
  59156. const float blurRadius_)
  59157. : owner (0),
  59158. numShadows (0),
  59159. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59160. xOffset (xOffset_),
  59161. yOffset (yOffset_),
  59162. alpha (alpha_),
  59163. blurRadius (blurRadius_),
  59164. inDestructor (false),
  59165. reentrant (false)
  59166. {
  59167. }
  59168. DropShadower::~DropShadower()
  59169. {
  59170. if (owner != 0)
  59171. owner->removeComponentListener (this);
  59172. inDestructor = true;
  59173. deleteShadowWindows();
  59174. }
  59175. void DropShadower::deleteShadowWindows()
  59176. {
  59177. if (numShadows > 0)
  59178. {
  59179. int i;
  59180. for (i = numShadows; --i >= 0;)
  59181. delete shadowWindows[i];
  59182. for (i = 12; --i >= 0;)
  59183. delete shadowImageSections[i];
  59184. numShadows = 0;
  59185. }
  59186. }
  59187. void DropShadower::setOwner (Component* componentToFollow)
  59188. {
  59189. if (componentToFollow != owner)
  59190. {
  59191. if (owner != 0)
  59192. owner->removeComponentListener (this);
  59193. // (the component can't be null)
  59194. jassert (componentToFollow != 0);
  59195. owner = componentToFollow;
  59196. jassert (owner != 0);
  59197. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59198. owner->addComponentListener (this);
  59199. updateShadows();
  59200. }
  59201. }
  59202. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59203. {
  59204. updateShadows();
  59205. }
  59206. void DropShadower::componentBroughtToFront (Component&)
  59207. {
  59208. bringShadowWindowsToFront();
  59209. }
  59210. void DropShadower::componentChildrenChanged (Component&)
  59211. {
  59212. }
  59213. void DropShadower::componentParentHierarchyChanged (Component&)
  59214. {
  59215. deleteShadowWindows();
  59216. updateShadows();
  59217. }
  59218. void DropShadower::componentVisibilityChanged (Component&)
  59219. {
  59220. updateShadows();
  59221. }
  59222. void DropShadower::updateShadows()
  59223. {
  59224. if (reentrant || inDestructor || (owner == 0))
  59225. return;
  59226. reentrant = true;
  59227. ComponentPeer* const nw = owner->getPeer();
  59228. const bool isOwnerVisible = owner->isVisible()
  59229. && (nw == 0 || ! nw->isMinimised());
  59230. const bool createShadowWindows = numShadows == 0
  59231. && owner->getWidth() > 0
  59232. && owner->getHeight() > 0
  59233. && isOwnerVisible
  59234. && (Desktop::canUseSemiTransparentWindows()
  59235. || owner->getParentComponent() != 0);
  59236. if (createShadowWindows)
  59237. {
  59238. // keep a cached version of the image to save doing the gaussian too often
  59239. String imageId;
  59240. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59241. const int hash = imageId.hashCode();
  59242. Image* bigIm = ImageCache::getFromHashCode (hash);
  59243. if (bigIm == 0)
  59244. {
  59245. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59246. Graphics bigG (*bigIm);
  59247. bigG.setColour (Colours::black.withAlpha (alpha));
  59248. bigG.fillRect (shadowEdge + xOffset,
  59249. shadowEdge + yOffset,
  59250. bigIm->getWidth() - (shadowEdge * 2),
  59251. bigIm->getHeight() - (shadowEdge * 2));
  59252. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59253. blurKernel.createGaussianBlur (blurRadius);
  59254. blurKernel.applyToImage (*bigIm, 0,
  59255. Rectangle<int> (xOffset, yOffset,
  59256. bigIm->getWidth(), bigIm->getHeight()));
  59257. ImageCache::addImageToCache (bigIm, hash);
  59258. }
  59259. const int iw = bigIm->getWidth();
  59260. const int ih = bigIm->getHeight();
  59261. const int shadowEdge2 = shadowEdge * 2;
  59262. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59263. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59264. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59265. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59266. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59267. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59268. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59269. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59270. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59271. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59272. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59273. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59274. ImageCache::release (bigIm);
  59275. for (int i = 0; i < 4; ++i)
  59276. {
  59277. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59278. ++numShadows;
  59279. }
  59280. }
  59281. if (numShadows > 0)
  59282. {
  59283. for (int i = numShadows; --i >= 0;)
  59284. {
  59285. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59286. shadowWindows[i]->setVisible (isOwnerVisible);
  59287. }
  59288. const int x = owner->getX();
  59289. const int y = owner->getY() - shadowEdge;
  59290. const int w = owner->getWidth();
  59291. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59292. shadowWindows[0]->setBounds (x - shadowEdge,
  59293. y,
  59294. shadowEdge,
  59295. h);
  59296. shadowWindows[1]->setBounds (x + w,
  59297. y,
  59298. shadowEdge,
  59299. h);
  59300. shadowWindows[2]->setBounds (x,
  59301. y,
  59302. w,
  59303. shadowEdge);
  59304. shadowWindows[3]->setBounds (x,
  59305. owner->getBottom(),
  59306. w,
  59307. shadowEdge);
  59308. }
  59309. reentrant = false;
  59310. if (createShadowWindows)
  59311. bringShadowWindowsToFront();
  59312. }
  59313. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59314. const int sx, const int sy)
  59315. {
  59316. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59317. Graphics g (*shadowImageSections[num]);
  59318. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59319. }
  59320. void DropShadower::bringShadowWindowsToFront()
  59321. {
  59322. if (! (inDestructor || reentrant))
  59323. {
  59324. updateShadows();
  59325. reentrant = true;
  59326. for (int i = numShadows; --i >= 0;)
  59327. shadowWindows[i]->toBehind (owner);
  59328. reentrant = false;
  59329. }
  59330. }
  59331. END_JUCE_NAMESPACE
  59332. /*** End of inlined file: juce_DropShadower.cpp ***/
  59333. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59334. BEGIN_JUCE_NAMESPACE
  59335. class MagnifyingPeer : public ComponentPeer
  59336. {
  59337. public:
  59338. MagnifyingPeer (Component* const component_,
  59339. MagnifierComponent* const magnifierComp_)
  59340. : ComponentPeer (component_, 0),
  59341. magnifierComp (magnifierComp_)
  59342. {
  59343. }
  59344. ~MagnifyingPeer()
  59345. {
  59346. }
  59347. void* getNativeHandle() const { return 0; }
  59348. void setVisible (bool) {}
  59349. void setTitle (const String&) {}
  59350. void setPosition (int, int) {}
  59351. void setSize (int, int) {}
  59352. void setBounds (int, int, int, int, bool) {}
  59353. void setMinimised (bool) {}
  59354. bool isMinimised() const { return false; }
  59355. void setFullScreen (bool) {}
  59356. bool isFullScreen() const { return false; }
  59357. const BorderSize getFrameSize() const { return BorderSize (0); }
  59358. bool setAlwaysOnTop (bool) { return true; }
  59359. void toFront (bool) {}
  59360. void toBehind (ComponentPeer*) {}
  59361. void setIcon (const Image&) {}
  59362. bool isFocused() const
  59363. {
  59364. return magnifierComp->hasKeyboardFocus (true);
  59365. }
  59366. void grabFocus()
  59367. {
  59368. ComponentPeer* peer = magnifierComp->getPeer();
  59369. if (peer != 0)
  59370. peer->grabFocus();
  59371. }
  59372. void textInputRequired (const Point<int>& position)
  59373. {
  59374. ComponentPeer* peer = magnifierComp->getPeer();
  59375. if (peer != 0)
  59376. peer->textInputRequired (position);
  59377. }
  59378. const Rectangle<int> getBounds() const
  59379. {
  59380. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59381. component->getWidth(), component->getHeight());
  59382. }
  59383. const Point<int> getScreenPosition() const
  59384. {
  59385. return magnifierComp->getScreenPosition();
  59386. }
  59387. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59388. {
  59389. const double zoom = magnifierComp->getScaleFactor();
  59390. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59391. roundToInt (relativePosition.getY() * zoom)));
  59392. }
  59393. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59394. {
  59395. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59396. const double zoom = magnifierComp->getScaleFactor();
  59397. return Point<int> (roundToInt (p.getX() / zoom),
  59398. roundToInt (p.getY() / zoom));
  59399. }
  59400. bool contains (const Point<int>& position, bool) const
  59401. {
  59402. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59403. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59404. }
  59405. void repaint (int x, int y, int w, int h)
  59406. {
  59407. const double zoom = magnifierComp->getScaleFactor();
  59408. magnifierComp->repaint ((int) (x * zoom),
  59409. (int) (y * zoom),
  59410. roundToInt (w * zoom) + 1,
  59411. roundToInt (h * zoom) + 1);
  59412. }
  59413. void performAnyPendingRepaintsNow()
  59414. {
  59415. }
  59416. juce_UseDebuggingNewOperator
  59417. private:
  59418. MagnifierComponent* const magnifierComp;
  59419. MagnifyingPeer (const MagnifyingPeer&);
  59420. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59421. };
  59422. class PeerHolderComp : public Component
  59423. {
  59424. public:
  59425. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59426. : magnifierComp (magnifierComp_)
  59427. {
  59428. setVisible (true);
  59429. }
  59430. ~PeerHolderComp()
  59431. {
  59432. }
  59433. ComponentPeer* createNewPeer (int, void*)
  59434. {
  59435. return new MagnifyingPeer (this, magnifierComp);
  59436. }
  59437. void childBoundsChanged (Component* c)
  59438. {
  59439. if (c != 0)
  59440. {
  59441. setSize (c->getWidth(), c->getHeight());
  59442. magnifierComp->childBoundsChanged (this);
  59443. }
  59444. }
  59445. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59446. {
  59447. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59448. Component* const p = magnifierComp->getParentComponent();
  59449. if (p != 0)
  59450. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59451. }
  59452. private:
  59453. MagnifierComponent* const magnifierComp;
  59454. PeerHolderComp (const PeerHolderComp&);
  59455. PeerHolderComp& operator= (const PeerHolderComp&);
  59456. };
  59457. MagnifierComponent::MagnifierComponent (Component* const content_,
  59458. const bool deleteContentCompWhenNoLongerNeeded)
  59459. : content (content_),
  59460. scaleFactor (0.0),
  59461. peer (0),
  59462. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59463. quality (Graphics::lowResamplingQuality),
  59464. mouseSource (0, true)
  59465. {
  59466. holderComp = new PeerHolderComp (this);
  59467. setScaleFactor (1.0);
  59468. }
  59469. MagnifierComponent::~MagnifierComponent()
  59470. {
  59471. delete holderComp;
  59472. if (deleteContent)
  59473. delete content;
  59474. }
  59475. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59476. {
  59477. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59478. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59479. if (scaleFactor != newScaleFactor)
  59480. {
  59481. scaleFactor = newScaleFactor;
  59482. if (scaleFactor == 1.0)
  59483. {
  59484. holderComp->removeFromDesktop();
  59485. peer = 0;
  59486. addChildComponent (content);
  59487. childBoundsChanged (content);
  59488. }
  59489. else
  59490. {
  59491. holderComp->addAndMakeVisible (content);
  59492. holderComp->childBoundsChanged (content);
  59493. childBoundsChanged (holderComp);
  59494. holderComp->addToDesktop (0);
  59495. peer = holderComp->getPeer();
  59496. }
  59497. repaint();
  59498. }
  59499. }
  59500. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59501. {
  59502. quality = newQuality;
  59503. }
  59504. void MagnifierComponent::paint (Graphics& g)
  59505. {
  59506. const int w = holderComp->getWidth();
  59507. const int h = holderComp->getHeight();
  59508. if (w == 0 || h == 0)
  59509. return;
  59510. const Rectangle<int> r (g.getClipBounds());
  59511. const int srcX = (int) (r.getX() / scaleFactor);
  59512. const int srcY = (int) (r.getY() / scaleFactor);
  59513. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59514. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59515. if (scaleFactor >= 1.0)
  59516. {
  59517. ++srcW;
  59518. ++srcH;
  59519. }
  59520. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59521. temp.clear (srcX, srcY, srcW, srcH);
  59522. {
  59523. Graphics g2 (temp);
  59524. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59525. holderComp->paintEntireComponent (g2);
  59526. }
  59527. g.setImageResamplingQuality (quality);
  59528. g.drawImageTransformed (&temp, temp.getBounds(),
  59529. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59530. false);
  59531. }
  59532. void MagnifierComponent::childBoundsChanged (Component* c)
  59533. {
  59534. if (c != 0)
  59535. setSize (roundToInt (c->getWidth() * scaleFactor),
  59536. roundToInt (c->getHeight() * scaleFactor));
  59537. }
  59538. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59539. {
  59540. if (peer != 0)
  59541. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59542. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59543. }
  59544. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59545. {
  59546. passOnMouseEventToPeer (e);
  59547. }
  59548. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59549. {
  59550. passOnMouseEventToPeer (e);
  59551. }
  59552. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59553. {
  59554. passOnMouseEventToPeer (e);
  59555. }
  59556. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59557. {
  59558. passOnMouseEventToPeer (e);
  59559. }
  59560. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59561. {
  59562. passOnMouseEventToPeer (e);
  59563. }
  59564. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59565. {
  59566. passOnMouseEventToPeer (e);
  59567. }
  59568. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59569. {
  59570. if (peer != 0)
  59571. peer->handleMouseWheel (e.source.getIndex(),
  59572. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59573. ix * 256.0f, iy * 256.0f);
  59574. else
  59575. Component::mouseWheelMove (e, ix, iy);
  59576. }
  59577. int MagnifierComponent::scaleInt (const int n) const
  59578. {
  59579. return roundToInt (n / scaleFactor);
  59580. }
  59581. END_JUCE_NAMESPACE
  59582. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59583. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59584. BEGIN_JUCE_NAMESPACE
  59585. class MidiKeyboardUpDownButton : public Button
  59586. {
  59587. public:
  59588. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59589. const int delta_)
  59590. : Button (String::empty),
  59591. owner (owner_),
  59592. delta (delta_)
  59593. {
  59594. setOpaque (true);
  59595. }
  59596. ~MidiKeyboardUpDownButton()
  59597. {
  59598. }
  59599. void clicked()
  59600. {
  59601. int note = owner->getLowestVisibleKey();
  59602. if (delta < 0)
  59603. note = (note - 1) / 12;
  59604. else
  59605. note = note / 12 + 1;
  59606. owner->setLowestVisibleKey (note * 12);
  59607. }
  59608. void paintButton (Graphics& g,
  59609. bool isMouseOverButton,
  59610. bool isButtonDown)
  59611. {
  59612. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59613. isMouseOverButton, isButtonDown,
  59614. delta > 0);
  59615. }
  59616. private:
  59617. MidiKeyboardComponent* const owner;
  59618. const int delta;
  59619. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59620. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59621. };
  59622. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59623. const Orientation orientation_)
  59624. : state (state_),
  59625. xOffset (0),
  59626. blackNoteLength (1),
  59627. keyWidth (16.0f),
  59628. orientation (orientation_),
  59629. midiChannel (1),
  59630. midiInChannelMask (0xffff),
  59631. velocity (1.0f),
  59632. noteUnderMouse (-1),
  59633. mouseDownNote (-1),
  59634. rangeStart (0),
  59635. rangeEnd (127),
  59636. firstKey (12 * 4),
  59637. canScroll (true),
  59638. mouseDragging (false),
  59639. useMousePositionForVelocity (true),
  59640. keyMappingOctave (6),
  59641. octaveNumForMiddleC (3)
  59642. {
  59643. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59644. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59645. // initialise with a default set of querty key-mappings..
  59646. const char* const keymap = "awsedftgyhujkolp;";
  59647. for (int i = String (keymap).length(); --i >= 0;)
  59648. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59649. setOpaque (true);
  59650. setWantsKeyboardFocus (true);
  59651. state.addListener (this);
  59652. }
  59653. MidiKeyboardComponent::~MidiKeyboardComponent()
  59654. {
  59655. state.removeListener (this);
  59656. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59657. deleteAllChildren();
  59658. }
  59659. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59660. {
  59661. keyWidth = widthInPixels;
  59662. resized();
  59663. }
  59664. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59665. {
  59666. if (orientation != newOrientation)
  59667. {
  59668. orientation = newOrientation;
  59669. resized();
  59670. }
  59671. }
  59672. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59673. const int highestNote)
  59674. {
  59675. jassert (lowestNote >= 0 && lowestNote <= 127);
  59676. jassert (highestNote >= 0 && highestNote <= 127);
  59677. jassert (lowestNote <= highestNote);
  59678. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59679. {
  59680. rangeStart = jlimit (0, 127, lowestNote);
  59681. rangeEnd = jlimit (0, 127, highestNote);
  59682. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59683. resized();
  59684. }
  59685. }
  59686. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59687. {
  59688. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59689. if (noteNumber != firstKey)
  59690. {
  59691. firstKey = noteNumber;
  59692. sendChangeMessage (this);
  59693. resized();
  59694. }
  59695. }
  59696. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59697. {
  59698. if (canScroll != canScroll_)
  59699. {
  59700. canScroll = canScroll_;
  59701. resized();
  59702. }
  59703. }
  59704. void MidiKeyboardComponent::colourChanged()
  59705. {
  59706. repaint();
  59707. }
  59708. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59709. {
  59710. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59711. if (midiChannel != midiChannelNumber)
  59712. {
  59713. resetAnyKeysInUse();
  59714. midiChannel = jlimit (1, 16, midiChannelNumber);
  59715. }
  59716. }
  59717. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59718. {
  59719. midiInChannelMask = midiChannelMask;
  59720. triggerAsyncUpdate();
  59721. }
  59722. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59723. {
  59724. velocity = jlimit (0.0f, 1.0f, velocity_);
  59725. useMousePositionForVelocity = useMousePositionForVelocity_;
  59726. }
  59727. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59728. {
  59729. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59730. static const float blackNoteWidth = 0.7f;
  59731. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59732. 1.0f, 2 - blackNoteWidth * 0.4f,
  59733. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59734. 4.0f, 5 - blackNoteWidth * 0.5f,
  59735. 5.0f, 6 - blackNoteWidth * 0.3f,
  59736. 6.0f };
  59737. static const float widths[] = { 1.0f, blackNoteWidth,
  59738. 1.0f, blackNoteWidth,
  59739. 1.0f, 1.0f, blackNoteWidth,
  59740. 1.0f, blackNoteWidth,
  59741. 1.0f, blackNoteWidth,
  59742. 1.0f };
  59743. const int octave = midiNoteNumber / 12;
  59744. const int note = midiNoteNumber % 12;
  59745. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59746. w = roundToInt (widths [note] * keyWidth);
  59747. }
  59748. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59749. {
  59750. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59751. int rx, rw;
  59752. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59753. x -= xOffset + rx;
  59754. }
  59755. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59756. {
  59757. int x, y;
  59758. getKeyPos (midiNoteNumber, x, y);
  59759. return x;
  59760. }
  59761. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59762. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59763. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59764. {
  59765. if (! reallyContains (pos.getX(), pos.getY(), false))
  59766. return -1;
  59767. Point<int> p (pos);
  59768. if (orientation != horizontalKeyboard)
  59769. {
  59770. p = Point<int> (p.getY(), p.getX());
  59771. if (orientation == verticalKeyboardFacingLeft)
  59772. p = Point<int> (p.getX(), getWidth() - p.getY());
  59773. else
  59774. p = Point<int> (getHeight() - p.getX(), p.getY());
  59775. }
  59776. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59777. }
  59778. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59779. {
  59780. if (pos.getY() < blackNoteLength)
  59781. {
  59782. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59783. {
  59784. for (int i = 0; i < 5; ++i)
  59785. {
  59786. const int note = octaveStart + blackNotes [i];
  59787. if (note >= rangeStart && note <= rangeEnd)
  59788. {
  59789. int kx, kw;
  59790. getKeyPos (note, kx, kw);
  59791. kx += xOffset;
  59792. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59793. {
  59794. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59795. return note;
  59796. }
  59797. }
  59798. }
  59799. }
  59800. }
  59801. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59802. {
  59803. for (int i = 0; i < 7; ++i)
  59804. {
  59805. const int note = octaveStart + whiteNotes [i];
  59806. if (note >= rangeStart && note <= rangeEnd)
  59807. {
  59808. int kx, kw;
  59809. getKeyPos (note, kx, kw);
  59810. kx += xOffset;
  59811. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59812. {
  59813. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59814. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59815. return note;
  59816. }
  59817. }
  59818. }
  59819. }
  59820. mousePositionVelocity = 0;
  59821. return -1;
  59822. }
  59823. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59824. {
  59825. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59826. {
  59827. int x, w;
  59828. getKeyPos (noteNum, x, w);
  59829. if (orientation == horizontalKeyboard)
  59830. repaint (x, 0, w, getHeight());
  59831. else if (orientation == verticalKeyboardFacingLeft)
  59832. repaint (0, x, getWidth(), w);
  59833. else if (orientation == verticalKeyboardFacingRight)
  59834. repaint (0, getHeight() - x - w, getWidth(), w);
  59835. }
  59836. }
  59837. void MidiKeyboardComponent::paint (Graphics& g)
  59838. {
  59839. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59840. const Colour lineColour (findColour (keySeparatorLineColourId));
  59841. const Colour textColour (findColour (textLabelColourId));
  59842. int x, w, octave;
  59843. for (octave = 0; octave < 128; octave += 12)
  59844. {
  59845. for (int white = 0; white < 7; ++white)
  59846. {
  59847. const int noteNum = octave + whiteNotes [white];
  59848. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59849. {
  59850. getKeyPos (noteNum, x, w);
  59851. if (orientation == horizontalKeyboard)
  59852. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59853. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59854. noteUnderMouse == noteNum,
  59855. lineColour, textColour);
  59856. else if (orientation == verticalKeyboardFacingLeft)
  59857. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59858. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59859. noteUnderMouse == noteNum,
  59860. lineColour, textColour);
  59861. else if (orientation == verticalKeyboardFacingRight)
  59862. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59863. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59864. noteUnderMouse == noteNum,
  59865. lineColour, textColour);
  59866. }
  59867. }
  59868. }
  59869. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59870. if (orientation == verticalKeyboardFacingLeft)
  59871. {
  59872. x1 = getWidth() - 1.0f;
  59873. x2 = getWidth() - 5.0f;
  59874. }
  59875. else if (orientation == verticalKeyboardFacingRight)
  59876. x2 = 5.0f;
  59877. else
  59878. y2 = 5.0f;
  59879. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59880. Colours::transparentBlack, x2, y2, false));
  59881. getKeyPos (rangeEnd, x, w);
  59882. x += w;
  59883. if (orientation == verticalKeyboardFacingLeft)
  59884. g.fillRect (getWidth() - 5, 0, 5, x);
  59885. else if (orientation == verticalKeyboardFacingRight)
  59886. g.fillRect (0, 0, 5, x);
  59887. else
  59888. g.fillRect (0, 0, x, 5);
  59889. g.setColour (lineColour);
  59890. if (orientation == verticalKeyboardFacingLeft)
  59891. g.fillRect (0, 0, 1, x);
  59892. else if (orientation == verticalKeyboardFacingRight)
  59893. g.fillRect (getWidth() - 1, 0, 1, x);
  59894. else
  59895. g.fillRect (0, getHeight() - 1, x, 1);
  59896. const Colour blackNoteColour (findColour (blackNoteColourId));
  59897. for (octave = 0; octave < 128; octave += 12)
  59898. {
  59899. for (int black = 0; black < 5; ++black)
  59900. {
  59901. const int noteNum = octave + blackNotes [black];
  59902. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59903. {
  59904. getKeyPos (noteNum, x, w);
  59905. if (orientation == horizontalKeyboard)
  59906. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59907. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59908. noteUnderMouse == noteNum,
  59909. blackNoteColour);
  59910. else if (orientation == verticalKeyboardFacingLeft)
  59911. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59912. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59913. noteUnderMouse == noteNum,
  59914. blackNoteColour);
  59915. else if (orientation == verticalKeyboardFacingRight)
  59916. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59917. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59918. noteUnderMouse == noteNum,
  59919. blackNoteColour);
  59920. }
  59921. }
  59922. }
  59923. }
  59924. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59925. Graphics& g, int x, int y, int w, int h,
  59926. bool isDown, bool isOver,
  59927. const Colour& lineColour,
  59928. const Colour& textColour)
  59929. {
  59930. Colour c (Colours::transparentWhite);
  59931. if (isDown)
  59932. c = findColour (keyDownOverlayColourId);
  59933. if (isOver)
  59934. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59935. g.setColour (c);
  59936. g.fillRect (x, y, w, h);
  59937. const String text (getWhiteNoteText (midiNoteNumber));
  59938. if (! text.isEmpty())
  59939. {
  59940. g.setColour (textColour);
  59941. Font f (jmin (12.0f, keyWidth * 0.9f));
  59942. f.setHorizontalScale (0.8f);
  59943. g.setFont (f);
  59944. Justification justification (Justification::centredBottom);
  59945. if (orientation == verticalKeyboardFacingLeft)
  59946. justification = Justification::centredLeft;
  59947. else if (orientation == verticalKeyboardFacingRight)
  59948. justification = Justification::centredRight;
  59949. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59950. }
  59951. g.setColour (lineColour);
  59952. if (orientation == horizontalKeyboard)
  59953. g.fillRect (x, y, 1, h);
  59954. else if (orientation == verticalKeyboardFacingLeft)
  59955. g.fillRect (x, y, w, 1);
  59956. else if (orientation == verticalKeyboardFacingRight)
  59957. g.fillRect (x, y + h - 1, w, 1);
  59958. if (midiNoteNumber == rangeEnd)
  59959. {
  59960. if (orientation == horizontalKeyboard)
  59961. g.fillRect (x + w, y, 1, h);
  59962. else if (orientation == verticalKeyboardFacingLeft)
  59963. g.fillRect (x, y + h, w, 1);
  59964. else if (orientation == verticalKeyboardFacingRight)
  59965. g.fillRect (x, y - 1, w, 1);
  59966. }
  59967. }
  59968. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59969. Graphics& g, int x, int y, int w, int h,
  59970. bool isDown, bool isOver,
  59971. const Colour& noteFillColour)
  59972. {
  59973. Colour c (noteFillColour);
  59974. if (isDown)
  59975. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59976. if (isOver)
  59977. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59978. g.setColour (c);
  59979. g.fillRect (x, y, w, h);
  59980. if (isDown)
  59981. {
  59982. g.setColour (noteFillColour);
  59983. g.drawRect (x, y, w, h);
  59984. }
  59985. else
  59986. {
  59987. const int xIndent = jmax (1, jmin (w, h) / 8);
  59988. g.setColour (c.brighter());
  59989. if (orientation == horizontalKeyboard)
  59990. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59991. else if (orientation == verticalKeyboardFacingLeft)
  59992. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59993. else if (orientation == verticalKeyboardFacingRight)
  59994. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59995. }
  59996. }
  59997. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59998. {
  59999. octaveNumForMiddleC = octaveNumForMiddleC_;
  60000. repaint();
  60001. }
  60002. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60003. {
  60004. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60005. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60006. return String::empty;
  60007. }
  60008. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60009. const bool isMouseOver,
  60010. const bool isButtonDown,
  60011. const bool movesOctavesUp)
  60012. {
  60013. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60014. float angle;
  60015. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60016. angle = movesOctavesUp ? 0.0f : 0.5f;
  60017. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60018. angle = movesOctavesUp ? 0.25f : 0.75f;
  60019. else
  60020. angle = movesOctavesUp ? 0.75f : 0.25f;
  60021. Path path;
  60022. path.lineTo (0.0f, 1.0f);
  60023. path.lineTo (1.0f, 0.5f);
  60024. path.closeSubPath();
  60025. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60026. g.setColour (findColour (upDownButtonArrowColourId)
  60027. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60028. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60029. w - 2.0f,
  60030. h - 2.0f,
  60031. true));
  60032. }
  60033. void MidiKeyboardComponent::resized()
  60034. {
  60035. int w = getWidth();
  60036. int h = getHeight();
  60037. if (w > 0 && h > 0)
  60038. {
  60039. if (orientation != horizontalKeyboard)
  60040. swapVariables (w, h);
  60041. blackNoteLength = roundToInt (h * 0.7f);
  60042. int kx2, kw2;
  60043. getKeyPos (rangeEnd, kx2, kw2);
  60044. kx2 += kw2;
  60045. if (firstKey != rangeStart)
  60046. {
  60047. int kx1, kw1;
  60048. getKeyPos (rangeStart, kx1, kw1);
  60049. if (kx2 - kx1 <= w)
  60050. {
  60051. firstKey = rangeStart;
  60052. sendChangeMessage (this);
  60053. repaint();
  60054. }
  60055. }
  60056. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60057. scrollDown->setVisible (showScrollButtons);
  60058. scrollUp->setVisible (showScrollButtons);
  60059. xOffset = 0;
  60060. if (showScrollButtons)
  60061. {
  60062. const int scrollButtonW = jmin (12, w / 2);
  60063. if (orientation == horizontalKeyboard)
  60064. {
  60065. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60066. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60067. }
  60068. else if (orientation == verticalKeyboardFacingLeft)
  60069. {
  60070. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60071. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60072. }
  60073. else if (orientation == verticalKeyboardFacingRight)
  60074. {
  60075. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60076. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60077. }
  60078. int endOfLastKey, kw;
  60079. getKeyPos (rangeEnd, endOfLastKey, kw);
  60080. endOfLastKey += kw;
  60081. float mousePositionVelocity;
  60082. const int spaceAvailable = w - scrollButtonW * 2;
  60083. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60084. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60085. {
  60086. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60087. sendChangeMessage (this);
  60088. }
  60089. int newOffset = 0;
  60090. getKeyPos (firstKey, newOffset, kw);
  60091. xOffset = newOffset - scrollButtonW;
  60092. }
  60093. else
  60094. {
  60095. firstKey = rangeStart;
  60096. }
  60097. timerCallback();
  60098. repaint();
  60099. }
  60100. }
  60101. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60102. {
  60103. triggerAsyncUpdate();
  60104. }
  60105. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60106. {
  60107. triggerAsyncUpdate();
  60108. }
  60109. void MidiKeyboardComponent::handleAsyncUpdate()
  60110. {
  60111. for (int i = rangeStart; i <= rangeEnd; ++i)
  60112. {
  60113. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60114. {
  60115. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60116. repaintNote (i);
  60117. }
  60118. }
  60119. }
  60120. void MidiKeyboardComponent::resetAnyKeysInUse()
  60121. {
  60122. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60123. {
  60124. state.allNotesOff (midiChannel);
  60125. keysPressed.clear();
  60126. mouseDownNote = -1;
  60127. }
  60128. }
  60129. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60130. {
  60131. float mousePositionVelocity = 0.0f;
  60132. const int newNote = (mouseDragging || isMouseOver())
  60133. ? xyToNote (pos, mousePositionVelocity) : -1;
  60134. if (noteUnderMouse != newNote)
  60135. {
  60136. if (mouseDownNote >= 0)
  60137. {
  60138. state.noteOff (midiChannel, mouseDownNote);
  60139. mouseDownNote = -1;
  60140. }
  60141. if (mouseDragging && newNote >= 0)
  60142. {
  60143. if (! useMousePositionForVelocity)
  60144. mousePositionVelocity = 1.0f;
  60145. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60146. mouseDownNote = newNote;
  60147. }
  60148. repaintNote (noteUnderMouse);
  60149. noteUnderMouse = newNote;
  60150. repaintNote (noteUnderMouse);
  60151. }
  60152. else if (mouseDownNote >= 0 && ! mouseDragging)
  60153. {
  60154. state.noteOff (midiChannel, mouseDownNote);
  60155. mouseDownNote = -1;
  60156. }
  60157. }
  60158. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60159. {
  60160. updateNoteUnderMouse (e.getPosition());
  60161. stopTimer();
  60162. }
  60163. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60164. {
  60165. float mousePositionVelocity;
  60166. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60167. if (newNote >= 0)
  60168. mouseDraggedToKey (newNote, e);
  60169. updateNoteUnderMouse (e.getPosition());
  60170. }
  60171. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60172. {
  60173. return true;
  60174. }
  60175. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60176. {
  60177. }
  60178. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60179. {
  60180. float mousePositionVelocity;
  60181. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60182. mouseDragging = false;
  60183. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60184. {
  60185. repaintNote (noteUnderMouse);
  60186. noteUnderMouse = -1;
  60187. mouseDragging = true;
  60188. updateNoteUnderMouse (e.getPosition());
  60189. startTimer (500);
  60190. }
  60191. }
  60192. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60193. {
  60194. mouseDragging = false;
  60195. updateNoteUnderMouse (e.getPosition());
  60196. stopTimer();
  60197. }
  60198. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60199. {
  60200. updateNoteUnderMouse (e.getPosition());
  60201. }
  60202. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60203. {
  60204. updateNoteUnderMouse (e.getPosition());
  60205. }
  60206. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60207. {
  60208. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60209. }
  60210. void MidiKeyboardComponent::timerCallback()
  60211. {
  60212. updateNoteUnderMouse (getMouseXYRelative());
  60213. }
  60214. void MidiKeyboardComponent::clearKeyMappings()
  60215. {
  60216. resetAnyKeysInUse();
  60217. keyPressNotes.clear();
  60218. keyPresses.clear();
  60219. }
  60220. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60221. const int midiNoteOffsetFromC)
  60222. {
  60223. removeKeyPressForNote (midiNoteOffsetFromC);
  60224. keyPressNotes.add (midiNoteOffsetFromC);
  60225. keyPresses.add (key);
  60226. }
  60227. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60228. {
  60229. for (int i = keyPressNotes.size(); --i >= 0;)
  60230. {
  60231. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60232. {
  60233. keyPressNotes.remove (i);
  60234. keyPresses.remove (i);
  60235. }
  60236. }
  60237. }
  60238. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60239. {
  60240. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60241. keyMappingOctave = newOctaveNumber;
  60242. }
  60243. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60244. {
  60245. bool keyPressUsed = false;
  60246. for (int i = keyPresses.size(); --i >= 0;)
  60247. {
  60248. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60249. if (keyPresses.getReference(i).isCurrentlyDown())
  60250. {
  60251. if (! keysPressed [note])
  60252. {
  60253. keysPressed.setBit (note);
  60254. state.noteOn (midiChannel, note, velocity);
  60255. keyPressUsed = true;
  60256. }
  60257. }
  60258. else
  60259. {
  60260. if (keysPressed [note])
  60261. {
  60262. keysPressed.clearBit (note);
  60263. state.noteOff (midiChannel, note);
  60264. keyPressUsed = true;
  60265. }
  60266. }
  60267. }
  60268. return keyPressUsed;
  60269. }
  60270. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60271. {
  60272. resetAnyKeysInUse();
  60273. }
  60274. END_JUCE_NAMESPACE
  60275. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60276. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60277. #if JUCE_OPENGL
  60278. BEGIN_JUCE_NAMESPACE
  60279. extern void juce_glViewport (const int w, const int h);
  60280. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60281. const int alphaBits_,
  60282. const int depthBufferBits_,
  60283. const int stencilBufferBits_)
  60284. : redBits (bitsPerRGBComponent),
  60285. greenBits (bitsPerRGBComponent),
  60286. blueBits (bitsPerRGBComponent),
  60287. alphaBits (alphaBits_),
  60288. depthBufferBits (depthBufferBits_),
  60289. stencilBufferBits (stencilBufferBits_),
  60290. accumulationBufferRedBits (0),
  60291. accumulationBufferGreenBits (0),
  60292. accumulationBufferBlueBits (0),
  60293. accumulationBufferAlphaBits (0),
  60294. fullSceneAntiAliasingNumSamples (0)
  60295. {
  60296. }
  60297. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60298. : redBits (other.redBits),
  60299. greenBits (other.greenBits),
  60300. blueBits (other.blueBits),
  60301. alphaBits (other.alphaBits),
  60302. depthBufferBits (other.depthBufferBits),
  60303. stencilBufferBits (other.stencilBufferBits),
  60304. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60305. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60306. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60307. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60308. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60309. {
  60310. }
  60311. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60312. {
  60313. redBits = other.redBits;
  60314. greenBits = other.greenBits;
  60315. blueBits = other.blueBits;
  60316. alphaBits = other.alphaBits;
  60317. depthBufferBits = other.depthBufferBits;
  60318. stencilBufferBits = other.stencilBufferBits;
  60319. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60320. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60321. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60322. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60323. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60324. return *this;
  60325. }
  60326. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60327. {
  60328. return redBits == other.redBits
  60329. && greenBits == other.greenBits
  60330. && blueBits == other.blueBits
  60331. && alphaBits == other.alphaBits
  60332. && depthBufferBits == other.depthBufferBits
  60333. && stencilBufferBits == other.stencilBufferBits
  60334. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60335. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60336. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60337. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60338. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60339. }
  60340. static VoidArray knownContexts;
  60341. OpenGLContext::OpenGLContext() throw()
  60342. {
  60343. knownContexts.add (this);
  60344. }
  60345. OpenGLContext::~OpenGLContext()
  60346. {
  60347. knownContexts.removeValue (this);
  60348. }
  60349. OpenGLContext* OpenGLContext::getCurrentContext()
  60350. {
  60351. for (int i = knownContexts.size(); --i >= 0;)
  60352. {
  60353. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60354. if (oglc->isActive())
  60355. return oglc;
  60356. }
  60357. return 0;
  60358. }
  60359. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60360. {
  60361. public:
  60362. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60363. : ComponentMovementWatcher (owner_),
  60364. owner (owner_),
  60365. wasShowing (false)
  60366. {
  60367. }
  60368. ~OpenGLComponentWatcher() {}
  60369. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60370. {
  60371. owner->updateContextPosition();
  60372. }
  60373. void componentPeerChanged()
  60374. {
  60375. const ScopedLock sl (owner->getContextLock());
  60376. owner->deleteContext();
  60377. }
  60378. void componentVisibilityChanged (Component&)
  60379. {
  60380. const bool isShowingNow = owner->isShowing();
  60381. if (wasShowing != isShowingNow)
  60382. {
  60383. wasShowing = isShowingNow;
  60384. owner->updateContextPosition();
  60385. }
  60386. }
  60387. juce_UseDebuggingNewOperator
  60388. private:
  60389. OpenGLComponent* const owner;
  60390. bool wasShowing;
  60391. };
  60392. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60393. : type (type_),
  60394. contextToShareListsWith (0),
  60395. needToUpdateViewport (true)
  60396. {
  60397. setOpaque (true);
  60398. componentWatcher = new OpenGLComponentWatcher (this);
  60399. }
  60400. OpenGLComponent::~OpenGLComponent()
  60401. {
  60402. deleteContext();
  60403. componentWatcher = 0;
  60404. }
  60405. void OpenGLComponent::deleteContext()
  60406. {
  60407. const ScopedLock sl (contextLock);
  60408. context = 0;
  60409. }
  60410. void OpenGLComponent::updateContextPosition()
  60411. {
  60412. needToUpdateViewport = true;
  60413. if (getWidth() > 0 && getHeight() > 0)
  60414. {
  60415. Component* const topComp = getTopLevelComponent();
  60416. if (topComp->getPeer() != 0)
  60417. {
  60418. const ScopedLock sl (contextLock);
  60419. if (context != 0)
  60420. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60421. getScreenY() - topComp->getScreenY(),
  60422. getWidth(),
  60423. getHeight(),
  60424. topComp->getHeight());
  60425. }
  60426. }
  60427. }
  60428. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60429. {
  60430. OpenGLPixelFormat pf;
  60431. const ScopedLock sl (contextLock);
  60432. if (context != 0)
  60433. pf = context->getPixelFormat();
  60434. return pf;
  60435. }
  60436. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60437. {
  60438. if (! (preferredPixelFormat == formatToUse))
  60439. {
  60440. const ScopedLock sl (contextLock);
  60441. deleteContext();
  60442. preferredPixelFormat = formatToUse;
  60443. }
  60444. }
  60445. void OpenGLComponent::shareWith (OpenGLContext* c)
  60446. {
  60447. if (contextToShareListsWith != c)
  60448. {
  60449. const ScopedLock sl (contextLock);
  60450. deleteContext();
  60451. contextToShareListsWith = c;
  60452. }
  60453. }
  60454. bool OpenGLComponent::makeCurrentContextActive()
  60455. {
  60456. if (context == 0)
  60457. {
  60458. const ScopedLock sl (contextLock);
  60459. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60460. {
  60461. context = createContext();
  60462. if (context != 0)
  60463. {
  60464. updateContextPosition();
  60465. if (context->makeActive())
  60466. newOpenGLContextCreated();
  60467. }
  60468. }
  60469. }
  60470. return context != 0 && context->makeActive();
  60471. }
  60472. void OpenGLComponent::makeCurrentContextInactive()
  60473. {
  60474. if (context != 0)
  60475. context->makeInactive();
  60476. }
  60477. bool OpenGLComponent::isActiveContext() const throw()
  60478. {
  60479. return context != 0 && context->isActive();
  60480. }
  60481. void OpenGLComponent::swapBuffers()
  60482. {
  60483. if (context != 0)
  60484. context->swapBuffers();
  60485. }
  60486. void OpenGLComponent::paint (Graphics&)
  60487. {
  60488. if (renderAndSwapBuffers())
  60489. {
  60490. ComponentPeer* const peer = getPeer();
  60491. if (peer != 0)
  60492. {
  60493. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60494. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60495. }
  60496. }
  60497. }
  60498. bool OpenGLComponent::renderAndSwapBuffers()
  60499. {
  60500. const ScopedLock sl (contextLock);
  60501. if (! makeCurrentContextActive())
  60502. return false;
  60503. if (needToUpdateViewport)
  60504. {
  60505. needToUpdateViewport = false;
  60506. juce_glViewport (getWidth(), getHeight());
  60507. }
  60508. renderOpenGL();
  60509. swapBuffers();
  60510. return true;
  60511. }
  60512. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60513. {
  60514. Component::internalRepaint (x, y, w, h);
  60515. if (context != 0)
  60516. context->repaint();
  60517. }
  60518. END_JUCE_NAMESPACE
  60519. #endif
  60520. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60521. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60522. BEGIN_JUCE_NAMESPACE
  60523. PreferencesPanel::PreferencesPanel()
  60524. : buttonSize (70)
  60525. {
  60526. }
  60527. PreferencesPanel::~PreferencesPanel()
  60528. {
  60529. currentPage = 0;
  60530. deleteAllChildren();
  60531. }
  60532. void PreferencesPanel::addSettingsPage (const String& title,
  60533. const Drawable* icon,
  60534. const Drawable* overIcon,
  60535. const Drawable* downIcon)
  60536. {
  60537. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60538. button->setImages (icon, overIcon, downIcon);
  60539. button->setRadioGroupId (1);
  60540. button->addButtonListener (this);
  60541. button->setClickingTogglesState (true);
  60542. button->setWantsKeyboardFocus (false);
  60543. addAndMakeVisible (button);
  60544. resized();
  60545. if (currentPage == 0)
  60546. setCurrentPage (title);
  60547. }
  60548. void PreferencesPanel::addSettingsPage (const String& title,
  60549. const char* imageData,
  60550. const int imageDataSize)
  60551. {
  60552. DrawableImage icon, iconOver, iconDown;
  60553. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60554. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60555. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60556. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60557. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60558. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60559. }
  60560. class PrefsDialogWindow : public DialogWindow
  60561. {
  60562. public:
  60563. PrefsDialogWindow (const String& dialogtitle,
  60564. const Colour& backgroundColour)
  60565. : DialogWindow (dialogtitle, backgroundColour, true)
  60566. {
  60567. }
  60568. ~PrefsDialogWindow()
  60569. {
  60570. }
  60571. void closeButtonPressed()
  60572. {
  60573. exitModalState (0);
  60574. }
  60575. private:
  60576. PrefsDialogWindow (const PrefsDialogWindow&);
  60577. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60578. };
  60579. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60580. int dialogWidth,
  60581. int dialogHeight,
  60582. const Colour& backgroundColour)
  60583. {
  60584. setSize (dialogWidth, dialogHeight);
  60585. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60586. dw.setContentComponent (this, true, true);
  60587. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60588. dw.runModalLoop();
  60589. dw.setContentComponent (0, false, false);
  60590. }
  60591. void PreferencesPanel::resized()
  60592. {
  60593. int x = 0;
  60594. for (int i = 0; i < getNumChildComponents(); ++i)
  60595. {
  60596. Component* c = getChildComponent (i);
  60597. if (dynamic_cast <DrawableButton*> (c) == 0)
  60598. {
  60599. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60600. }
  60601. else
  60602. {
  60603. c->setBounds (x, 0, buttonSize, buttonSize);
  60604. x += buttonSize;
  60605. }
  60606. }
  60607. }
  60608. void PreferencesPanel::paint (Graphics& g)
  60609. {
  60610. g.setColour (Colours::grey);
  60611. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60612. }
  60613. void PreferencesPanel::setCurrentPage (const String& pageName)
  60614. {
  60615. if (currentPageName != pageName)
  60616. {
  60617. currentPageName = pageName;
  60618. currentPage = 0;
  60619. currentPage = createComponentForPage (pageName);
  60620. if (currentPage != 0)
  60621. {
  60622. addAndMakeVisible (currentPage);
  60623. currentPage->toBack();
  60624. resized();
  60625. }
  60626. for (int i = 0; i < getNumChildComponents(); ++i)
  60627. {
  60628. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60629. if (db != 0 && db->getName() == pageName)
  60630. {
  60631. db->setToggleState (true, false);
  60632. break;
  60633. }
  60634. }
  60635. }
  60636. }
  60637. void PreferencesPanel::buttonClicked (Button*)
  60638. {
  60639. for (int i = 0; i < getNumChildComponents(); ++i)
  60640. {
  60641. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60642. if (db != 0 && db->getToggleState())
  60643. {
  60644. setCurrentPage (db->getName());
  60645. break;
  60646. }
  60647. }
  60648. }
  60649. END_JUCE_NAMESPACE
  60650. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60651. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60652. #if JUCE_WINDOWS || JUCE_LINUX
  60653. BEGIN_JUCE_NAMESPACE
  60654. SystemTrayIconComponent::SystemTrayIconComponent()
  60655. {
  60656. addToDesktop (0);
  60657. }
  60658. SystemTrayIconComponent::~SystemTrayIconComponent()
  60659. {
  60660. }
  60661. END_JUCE_NAMESPACE
  60662. #endif
  60663. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60664. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60665. BEGIN_JUCE_NAMESPACE
  60666. class AlertWindowTextEditor : public TextEditor
  60667. {
  60668. public:
  60669. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60670. : TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0)
  60671. {
  60672. setSelectAllWhenFocused (true);
  60673. }
  60674. ~AlertWindowTextEditor()
  60675. {
  60676. }
  60677. void returnPressed()
  60678. {
  60679. // pass these up the component hierarchy to be trigger the buttons
  60680. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60681. }
  60682. void escapePressed()
  60683. {
  60684. // pass these up the component hierarchy to be trigger the buttons
  60685. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60686. }
  60687. private:
  60688. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60689. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60690. static juce_wchar getDefaultPasswordChar() throw()
  60691. {
  60692. #if JUCE_LINUX
  60693. return 0x2022;
  60694. #else
  60695. return 0x25cf;
  60696. #endif
  60697. }
  60698. };
  60699. AlertWindow::AlertWindow (const String& title,
  60700. const String& message,
  60701. AlertIconType iconType,
  60702. Component* associatedComponent_)
  60703. : TopLevelWindow (title, true),
  60704. alertIconType (iconType),
  60705. associatedComponent (associatedComponent_)
  60706. {
  60707. if (message.isEmpty())
  60708. text = " "; // to force an update if the message is empty
  60709. setMessage (message);
  60710. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60711. {
  60712. Component* const c = Desktop::getInstance().getComponent (i);
  60713. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60714. {
  60715. setAlwaysOnTop (true);
  60716. break;
  60717. }
  60718. }
  60719. if (JUCEApplication::getInstance() == 0)
  60720. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60721. lookAndFeelChanged();
  60722. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60723. }
  60724. AlertWindow::~AlertWindow()
  60725. {
  60726. for (int i = customComps.size(); --i >= 0;)
  60727. removeChildComponent ((Component*) customComps[i]);
  60728. deleteAllChildren();
  60729. }
  60730. void AlertWindow::userTriedToCloseWindow()
  60731. {
  60732. exitModalState (0);
  60733. }
  60734. void AlertWindow::setMessage (const String& message)
  60735. {
  60736. const String newMessage (message.substring (0, 2048));
  60737. if (text != newMessage)
  60738. {
  60739. text = newMessage;
  60740. font.setHeight (15.0f);
  60741. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60742. textLayout.setText (getName() + "\n\n", titleFont);
  60743. textLayout.appendText (text, font);
  60744. updateLayout (true);
  60745. repaint();
  60746. }
  60747. }
  60748. void AlertWindow::buttonClicked (Button* button)
  60749. {
  60750. for (int i = 0; i < buttons.size(); i++)
  60751. {
  60752. TextButton* const c = (TextButton*) buttons[i];
  60753. if (button->getName() == c->getName())
  60754. {
  60755. if (c->getParentComponent() != 0)
  60756. c->getParentComponent()->exitModalState (c->getCommandID());
  60757. break;
  60758. }
  60759. }
  60760. }
  60761. void AlertWindow::addButton (const String& name,
  60762. const int returnValue,
  60763. const KeyPress& shortcutKey1,
  60764. const KeyPress& shortcutKey2)
  60765. {
  60766. TextButton* const b = new TextButton (name, String::empty);
  60767. b->setWantsKeyboardFocus (true);
  60768. b->setMouseClickGrabsKeyboardFocus (false);
  60769. b->setCommandToTrigger (0, returnValue, false);
  60770. b->addShortcut (shortcutKey1);
  60771. b->addShortcut (shortcutKey2);
  60772. b->addButtonListener (this);
  60773. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60774. addAndMakeVisible (b, 0);
  60775. buttons.add (b);
  60776. updateLayout (false);
  60777. }
  60778. int AlertWindow::getNumButtons() const
  60779. {
  60780. return buttons.size();
  60781. }
  60782. void AlertWindow::addTextEditor (const String& name,
  60783. const String& initialContents,
  60784. const String& onScreenLabel,
  60785. const bool isPasswordBox)
  60786. {
  60787. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60788. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60789. tc->setFont (font);
  60790. tc->setText (initialContents);
  60791. tc->setCaretPosition (initialContents.length());
  60792. addAndMakeVisible (tc);
  60793. textBoxes.add (tc);
  60794. allComps.add (tc);
  60795. textboxNames.add (onScreenLabel);
  60796. updateLayout (false);
  60797. }
  60798. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60799. {
  60800. for (int i = textBoxes.size(); --i >= 0;)
  60801. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60802. return ((TextEditor*)textBoxes[i])->getText();
  60803. return String::empty;
  60804. }
  60805. void AlertWindow::addComboBox (const String& name,
  60806. const StringArray& items,
  60807. const String& onScreenLabel)
  60808. {
  60809. ComboBox* const cb = new ComboBox (name);
  60810. for (int i = 0; i < items.size(); ++i)
  60811. cb->addItem (items[i], i + 1);
  60812. addAndMakeVisible (cb);
  60813. cb->setSelectedItemIndex (0);
  60814. comboBoxes.add (cb);
  60815. allComps.add (cb);
  60816. comboBoxNames.add (onScreenLabel);
  60817. updateLayout (false);
  60818. }
  60819. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60820. {
  60821. for (int i = comboBoxes.size(); --i >= 0;)
  60822. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60823. return (ComboBox*) comboBoxes[i];
  60824. return 0;
  60825. }
  60826. class AlertTextComp : public TextEditor
  60827. {
  60828. public:
  60829. AlertTextComp (const String& message,
  60830. const Font& font)
  60831. {
  60832. setReadOnly (true);
  60833. setMultiLine (true, true);
  60834. setCaretVisible (false);
  60835. setScrollbarsShown (true);
  60836. lookAndFeelChanged();
  60837. setWantsKeyboardFocus (false);
  60838. setFont (font);
  60839. setText (message, false);
  60840. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60841. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60842. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60843. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60844. }
  60845. ~AlertTextComp()
  60846. {
  60847. }
  60848. int getPreferredWidth() const throw() { return bestWidth; }
  60849. void updateLayout (const int width)
  60850. {
  60851. TextLayout text;
  60852. text.appendText (getText(), getFont());
  60853. text.layout (width - 8, Justification::topLeft, true);
  60854. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60855. }
  60856. private:
  60857. int bestWidth;
  60858. AlertTextComp (const AlertTextComp&);
  60859. AlertTextComp& operator= (const AlertTextComp&);
  60860. };
  60861. void AlertWindow::addTextBlock (const String& text)
  60862. {
  60863. AlertTextComp* const c = new AlertTextComp (text, font);
  60864. textBlocks.add (c);
  60865. allComps.add (c);
  60866. addAndMakeVisible (c);
  60867. updateLayout (false);
  60868. }
  60869. void AlertWindow::addProgressBarComponent (double& progressValue)
  60870. {
  60871. ProgressBar* const pb = new ProgressBar (progressValue);
  60872. progressBars.add (pb);
  60873. allComps.add (pb);
  60874. addAndMakeVisible (pb);
  60875. updateLayout (false);
  60876. }
  60877. void AlertWindow::addCustomComponent (Component* const component)
  60878. {
  60879. customComps.add (component);
  60880. allComps.add (component);
  60881. addAndMakeVisible (component);
  60882. updateLayout (false);
  60883. }
  60884. int AlertWindow::getNumCustomComponents() const
  60885. {
  60886. return customComps.size();
  60887. }
  60888. Component* AlertWindow::getCustomComponent (const int index) const
  60889. {
  60890. return (Component*) customComps [index];
  60891. }
  60892. Component* AlertWindow::removeCustomComponent (const int index)
  60893. {
  60894. Component* const c = getCustomComponent (index);
  60895. if (c != 0)
  60896. {
  60897. customComps.removeValue (c);
  60898. allComps.removeValue (c);
  60899. removeChildComponent (c);
  60900. updateLayout (false);
  60901. }
  60902. return c;
  60903. }
  60904. void AlertWindow::paint (Graphics& g)
  60905. {
  60906. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60907. g.setColour (findColour (textColourId));
  60908. g.setFont (getLookAndFeel().getAlertWindowFont());
  60909. int i;
  60910. for (i = textBoxes.size(); --i >= 0;)
  60911. {
  60912. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60913. g.drawFittedText (textboxNames[i],
  60914. te->getX(), te->getY() - 14,
  60915. te->getWidth(), 14,
  60916. Justification::centredLeft, 1);
  60917. }
  60918. for (i = comboBoxNames.size(); --i >= 0;)
  60919. {
  60920. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60921. g.drawFittedText (comboBoxNames[i],
  60922. cb->getX(), cb->getY() - 14,
  60923. cb->getWidth(), 14,
  60924. Justification::centredLeft, 1);
  60925. }
  60926. for (i = customComps.size(); --i >= 0;)
  60927. {
  60928. const Component* const c = (Component*) customComps[i];
  60929. g.drawFittedText (c->getName(),
  60930. c->getX(), c->getY() - 14,
  60931. c->getWidth(), 14,
  60932. Justification::centredLeft, 1);
  60933. }
  60934. }
  60935. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60936. {
  60937. const int titleH = 24;
  60938. const int iconWidth = 80;
  60939. const int wid = jmax (font.getStringWidth (text),
  60940. font.getStringWidth (getName()));
  60941. const int sw = (int) sqrt (font.getHeight() * wid);
  60942. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60943. const int edgeGap = 10;
  60944. const int labelHeight = 18;
  60945. int iconSpace;
  60946. if (alertIconType == NoIcon)
  60947. {
  60948. textLayout.layout (w, Justification::horizontallyCentred, true);
  60949. iconSpace = 0;
  60950. }
  60951. else
  60952. {
  60953. textLayout.layout (w, Justification::left, true);
  60954. iconSpace = iconWidth;
  60955. }
  60956. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60957. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60958. const int textLayoutH = textLayout.getHeight();
  60959. const int textBottom = 16 + titleH + textLayoutH;
  60960. int h = textBottom;
  60961. int buttonW = 40;
  60962. int i;
  60963. for (i = 0; i < buttons.size(); ++i)
  60964. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60965. w = jmax (buttonW, w);
  60966. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60967. if (buttons.size() > 0)
  60968. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60969. for (i = customComps.size(); --i >= 0;)
  60970. {
  60971. Component* c = (Component*) customComps[i];
  60972. w = jmax (w, (c->getWidth() * 100) / 80);
  60973. h += 10 + c->getHeight();
  60974. if (c->getName().isNotEmpty())
  60975. h += labelHeight;
  60976. }
  60977. for (i = textBlocks.size(); --i >= 0;)
  60978. {
  60979. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60980. w = jmax (w, ac->getPreferredWidth());
  60981. }
  60982. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60983. for (i = textBlocks.size(); --i >= 0;)
  60984. {
  60985. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60986. ac->updateLayout ((int) (w * 0.8f));
  60987. h += ac->getHeight() + 10;
  60988. }
  60989. h = jmin (getParentHeight() - 50, h);
  60990. if (onlyIncreaseSize)
  60991. {
  60992. w = jmax (w, getWidth());
  60993. h = jmax (h, getHeight());
  60994. }
  60995. if (! isVisible())
  60996. {
  60997. centreAroundComponent (associatedComponent, w, h);
  60998. }
  60999. else
  61000. {
  61001. const int cx = getX() + getWidth() / 2;
  61002. const int cy = getY() + getHeight() / 2;
  61003. setBounds (cx - w / 2,
  61004. cy - h / 2,
  61005. w, h);
  61006. }
  61007. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61008. const int spacer = 16;
  61009. int totalWidth = -spacer;
  61010. for (i = buttons.size(); --i >= 0;)
  61011. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61012. int x = (w - totalWidth) / 2;
  61013. int y = (int) (getHeight() * 0.95f);
  61014. for (i = 0; i < buttons.size(); ++i)
  61015. {
  61016. TextButton* const c = (TextButton*) buttons[i];
  61017. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61018. c->setTopLeftPosition (x, ny);
  61019. if (ny < y)
  61020. y = ny;
  61021. x += c->getWidth() + spacer;
  61022. c->toFront (false);
  61023. }
  61024. y = textBottom;
  61025. for (i = 0; i < allComps.size(); ++i)
  61026. {
  61027. Component* const c = (Component*) allComps[i];
  61028. int h = 22;
  61029. const int comboIndex = comboBoxes.indexOf (c);
  61030. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61031. y += labelHeight;
  61032. const int tbIndex = textBoxes.indexOf (c);
  61033. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61034. y += labelHeight;
  61035. if (customComps.contains (c))
  61036. {
  61037. if (c->getName().isNotEmpty())
  61038. y += labelHeight;
  61039. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61040. h = c->getHeight();
  61041. }
  61042. else if (textBlocks.contains (c))
  61043. {
  61044. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61045. h = c->getHeight();
  61046. }
  61047. else
  61048. {
  61049. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61050. }
  61051. y += h + 10;
  61052. }
  61053. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61054. }
  61055. bool AlertWindow::containsAnyExtraComponents() const
  61056. {
  61057. return textBoxes.size()
  61058. + comboBoxes.size()
  61059. + progressBars.size()
  61060. + customComps.size() > 0;
  61061. }
  61062. void AlertWindow::mouseDown (const MouseEvent&)
  61063. {
  61064. dragger.startDraggingComponent (this, &constrainer);
  61065. }
  61066. void AlertWindow::mouseDrag (const MouseEvent& e)
  61067. {
  61068. dragger.dragComponent (this, e);
  61069. }
  61070. bool AlertWindow::keyPressed (const KeyPress& key)
  61071. {
  61072. for (int i = buttons.size(); --i >= 0;)
  61073. {
  61074. TextButton* const b = (TextButton*) buttons[i];
  61075. if (b->isRegisteredForShortcut (key))
  61076. {
  61077. b->triggerClick();
  61078. return true;
  61079. }
  61080. }
  61081. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61082. {
  61083. exitModalState (0);
  61084. return true;
  61085. }
  61086. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61087. {
  61088. ((TextButton*) buttons.getFirst())->triggerClick();
  61089. return true;
  61090. }
  61091. return false;
  61092. }
  61093. void AlertWindow::lookAndFeelChanged()
  61094. {
  61095. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61096. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61097. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61098. }
  61099. int AlertWindow::getDesktopWindowStyleFlags() const
  61100. {
  61101. return getLookAndFeel().getAlertBoxWindowFlags();
  61102. }
  61103. struct AlertWindowInfo
  61104. {
  61105. String title, message, button1, button2, button3;
  61106. AlertWindow::AlertIconType iconType;
  61107. int numButtons;
  61108. Component::SafePointer<Component> associatedComponent;
  61109. int run() const
  61110. {
  61111. return (int) (pointer_sized_int)
  61112. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61113. }
  61114. private:
  61115. int show() const
  61116. {
  61117. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61118. : LookAndFeel::getDefaultLookAndFeel();
  61119. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61120. iconType, numButtons, associatedComponent));
  61121. jassert (alertBox != 0); // you have to return one of these!
  61122. return alertBox->runModalLoop();
  61123. }
  61124. static void* showCallback (void* userData)
  61125. {
  61126. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61127. }
  61128. };
  61129. void AlertWindow::showMessageBox (AlertIconType iconType,
  61130. const String& title,
  61131. const String& message,
  61132. const String& buttonText,
  61133. Component* associatedComponent)
  61134. {
  61135. AlertWindowInfo info;
  61136. info.title = title;
  61137. info.message = message;
  61138. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61139. info.iconType = iconType;
  61140. info.numButtons = 1;
  61141. info.associatedComponent = associatedComponent;
  61142. info.run();
  61143. }
  61144. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61145. const String& title,
  61146. const String& message,
  61147. const String& button1Text,
  61148. const String& button2Text,
  61149. Component* associatedComponent)
  61150. {
  61151. AlertWindowInfo info;
  61152. info.title = title;
  61153. info.message = message;
  61154. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61155. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61156. info.iconType = iconType;
  61157. info.numButtons = 2;
  61158. info.associatedComponent = associatedComponent;
  61159. return info.run() != 0;
  61160. }
  61161. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61162. const String& title,
  61163. const String& message,
  61164. const String& button1Text,
  61165. const String& button2Text,
  61166. const String& button3Text,
  61167. Component* associatedComponent)
  61168. {
  61169. AlertWindowInfo info;
  61170. info.title = title;
  61171. info.message = message;
  61172. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61173. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61174. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61175. info.iconType = iconType;
  61176. info.numButtons = 3;
  61177. info.associatedComponent = associatedComponent;
  61178. return info.run();
  61179. }
  61180. END_JUCE_NAMESPACE
  61181. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61182. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61183. BEGIN_JUCE_NAMESPACE
  61184. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61185. static VoidArray heavyweightPeers;
  61186. ComponentPeer::ComponentPeer (Component* const component_,
  61187. const int styleFlags_) throw()
  61188. : component (component_),
  61189. styleFlags (styleFlags_),
  61190. lastPaintTime (0),
  61191. constrainer (0),
  61192. lastDragAndDropCompUnderMouse (0),
  61193. fakeMouseMessageSent (false),
  61194. isWindowMinimised (false)
  61195. {
  61196. heavyweightPeers.add (this);
  61197. }
  61198. ComponentPeer::~ComponentPeer()
  61199. {
  61200. heavyweightPeers.removeValue (this);
  61201. Desktop::getInstance().triggerFocusCallback();
  61202. }
  61203. int ComponentPeer::getNumPeers() throw()
  61204. {
  61205. return heavyweightPeers.size();
  61206. }
  61207. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61208. {
  61209. return (ComponentPeer*) heavyweightPeers [index];
  61210. }
  61211. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61212. {
  61213. for (int i = heavyweightPeers.size(); --i >= 0;)
  61214. {
  61215. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61216. if (peer->getComponent() == component)
  61217. return peer;
  61218. }
  61219. return 0;
  61220. }
  61221. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61222. {
  61223. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61224. }
  61225. void ComponentPeer::updateCurrentModifiers() throw()
  61226. {
  61227. ModifierKeys::updateCurrentModifiers();
  61228. }
  61229. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61230. {
  61231. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61232. jassert (mouse != 0); // not enough sources!
  61233. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61234. }
  61235. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61236. {
  61237. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61238. jassert (mouse != 0); // not enough sources!
  61239. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61240. }
  61241. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61242. {
  61243. Graphics g (&contextToPaintTo);
  61244. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61245. g.saveState();
  61246. #endif
  61247. JUCE_TRY
  61248. {
  61249. component->paintEntireComponent (g);
  61250. }
  61251. JUCE_CATCH_EXCEPTION
  61252. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61253. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61254. // clearly when things are being repainted.
  61255. {
  61256. g.restoreState();
  61257. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61258. (uint8) Random::getSystemRandom().nextInt (255),
  61259. (uint8) Random::getSystemRandom().nextInt (255),
  61260. (uint8) 0x50));
  61261. }
  61262. #endif
  61263. }
  61264. bool ComponentPeer::handleKeyPress (const int keyCode,
  61265. const juce_wchar textCharacter)
  61266. {
  61267. updateCurrentModifiers();
  61268. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61269. ? Component::getCurrentlyFocusedComponent()
  61270. : component;
  61271. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61272. {
  61273. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61274. if (currentModalComp != 0)
  61275. target = currentModalComp;
  61276. }
  61277. const KeyPress keyInfo (keyCode,
  61278. ModifierKeys::getCurrentModifiers().getRawFlags()
  61279. & ModifierKeys::allKeyboardModifiers,
  61280. textCharacter);
  61281. bool keyWasUsed = false;
  61282. while (target != 0)
  61283. {
  61284. const Component::SafePointer<Component> deletionChecker (target);
  61285. if (target->keyListeners_ != 0)
  61286. {
  61287. for (int i = target->keyListeners_->size(); --i >= 0;)
  61288. {
  61289. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61290. if (keyWasUsed || deletionChecker == 0)
  61291. return keyWasUsed;
  61292. i = jmin (i, target->keyListeners_->size());
  61293. }
  61294. }
  61295. keyWasUsed = target->keyPressed (keyInfo);
  61296. if (keyWasUsed || deletionChecker == 0)
  61297. break;
  61298. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61299. {
  61300. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61301. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61302. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61303. break;
  61304. }
  61305. target = target->parentComponent_;
  61306. }
  61307. return keyWasUsed;
  61308. }
  61309. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61310. {
  61311. updateCurrentModifiers();
  61312. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61313. ? Component::getCurrentlyFocusedComponent()
  61314. : component;
  61315. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61316. {
  61317. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61318. if (currentModalComp != 0)
  61319. target = currentModalComp;
  61320. }
  61321. bool keyWasUsed = false;
  61322. while (target != 0)
  61323. {
  61324. const Component::SafePointer<Component> deletionChecker (target);
  61325. keyWasUsed = target->keyStateChanged (isKeyDown);
  61326. if (keyWasUsed || deletionChecker == 0)
  61327. break;
  61328. if (target->keyListeners_ != 0)
  61329. {
  61330. for (int i = target->keyListeners_->size(); --i >= 0;)
  61331. {
  61332. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61333. if (keyWasUsed || deletionChecker == 0)
  61334. return keyWasUsed;
  61335. i = jmin (i, target->keyListeners_->size());
  61336. }
  61337. }
  61338. target = target->parentComponent_;
  61339. }
  61340. return keyWasUsed;
  61341. }
  61342. void ComponentPeer::handleModifierKeysChange()
  61343. {
  61344. updateCurrentModifiers();
  61345. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61346. if (target == 0)
  61347. target = Component::getCurrentlyFocusedComponent();
  61348. if (target == 0)
  61349. target = component;
  61350. if (target != 0)
  61351. target->internalModifierKeysChanged();
  61352. }
  61353. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61354. {
  61355. Component* const c = Component::getCurrentlyFocusedComponent();
  61356. if (component->isParentOf (c))
  61357. return dynamic_cast <TextInputTarget*> (c);
  61358. return 0;
  61359. }
  61360. void ComponentPeer::handleBroughtToFront()
  61361. {
  61362. updateCurrentModifiers();
  61363. if (component != 0)
  61364. component->internalBroughtToFront();
  61365. }
  61366. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61367. {
  61368. constrainer = newConstrainer;
  61369. }
  61370. void ComponentPeer::handleMovedOrResized()
  61371. {
  61372. jassert (component->isValidComponent());
  61373. updateCurrentModifiers();
  61374. const bool nowMinimised = isMinimised();
  61375. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61376. {
  61377. const Component::SafePointer<Component> deletionChecker (component);
  61378. const Rectangle<int> newBounds (getBounds());
  61379. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61380. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61381. if (wasMoved || wasResized)
  61382. {
  61383. component->bounds_ = newBounds;
  61384. if (wasResized)
  61385. component->repaint();
  61386. component->sendMovedResizedMessages (wasMoved, wasResized);
  61387. if (deletionChecker == 0)
  61388. return;
  61389. }
  61390. }
  61391. if (isWindowMinimised != nowMinimised)
  61392. {
  61393. isWindowMinimised = nowMinimised;
  61394. component->minimisationStateChanged (nowMinimised);
  61395. component->sendVisibilityChangeMessage();
  61396. }
  61397. if (! isFullScreen())
  61398. lastNonFullscreenBounds = component->getBounds();
  61399. }
  61400. void ComponentPeer::handleFocusGain()
  61401. {
  61402. updateCurrentModifiers();
  61403. if (component->isParentOf (lastFocusedComponent))
  61404. {
  61405. Component::currentlyFocusedComponent = lastFocusedComponent;
  61406. Desktop::getInstance().triggerFocusCallback();
  61407. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61408. }
  61409. else
  61410. {
  61411. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61412. component->grabKeyboardFocus();
  61413. else
  61414. Component::bringModalComponentToFront();
  61415. }
  61416. }
  61417. void ComponentPeer::handleFocusLoss()
  61418. {
  61419. updateCurrentModifiers();
  61420. if (component->hasKeyboardFocus (true))
  61421. {
  61422. lastFocusedComponent = Component::currentlyFocusedComponent;
  61423. if (lastFocusedComponent != 0)
  61424. {
  61425. Component::currentlyFocusedComponent = 0;
  61426. Desktop::getInstance().triggerFocusCallback();
  61427. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61428. }
  61429. }
  61430. }
  61431. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61432. {
  61433. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61434. ? static_cast <Component*> (lastFocusedComponent)
  61435. : component;
  61436. }
  61437. void ComponentPeer::handleScreenSizeChange()
  61438. {
  61439. updateCurrentModifiers();
  61440. component->parentSizeChanged();
  61441. handleMovedOrResized();
  61442. }
  61443. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61444. {
  61445. lastNonFullscreenBounds = newBounds;
  61446. }
  61447. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61448. {
  61449. return lastNonFullscreenBounds;
  61450. }
  61451. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61452. const StringArray& files,
  61453. FileDragAndDropTarget* const lastOne)
  61454. {
  61455. while (c != 0)
  61456. {
  61457. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61458. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61459. return t;
  61460. c = c->getParentComponent();
  61461. }
  61462. return 0;
  61463. }
  61464. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61465. {
  61466. updateCurrentModifiers();
  61467. FileDragAndDropTarget* lastTarget
  61468. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61469. FileDragAndDropTarget* newTarget = 0;
  61470. Component* const compUnderMouse = component->getComponentAt (position);
  61471. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61472. {
  61473. lastDragAndDropCompUnderMouse = compUnderMouse;
  61474. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61475. if (newTarget != lastTarget)
  61476. {
  61477. if (lastTarget != 0)
  61478. lastTarget->fileDragExit (files);
  61479. dragAndDropTargetComponent = 0;
  61480. if (newTarget != 0)
  61481. {
  61482. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61483. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61484. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61485. }
  61486. }
  61487. }
  61488. else
  61489. {
  61490. newTarget = lastTarget;
  61491. }
  61492. if (newTarget != 0)
  61493. {
  61494. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61495. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61496. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61497. }
  61498. }
  61499. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61500. {
  61501. handleFileDragMove (files, Point<int> (-1, -1));
  61502. jassert (dragAndDropTargetComponent == 0);
  61503. lastDragAndDropCompUnderMouse = 0;
  61504. }
  61505. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61506. {
  61507. handleFileDragMove (files, position);
  61508. if (dragAndDropTargetComponent != 0)
  61509. {
  61510. FileDragAndDropTarget* const target
  61511. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61512. dragAndDropTargetComponent = 0;
  61513. lastDragAndDropCompUnderMouse = 0;
  61514. if (target != 0)
  61515. {
  61516. Component* const targetComp = dynamic_cast <Component*> (target);
  61517. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61518. {
  61519. targetComp->internalModalInputAttempt();
  61520. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61521. return;
  61522. }
  61523. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61524. target->filesDropped (files, pos.getX(), pos.getY());
  61525. }
  61526. }
  61527. }
  61528. void ComponentPeer::handleUserClosingWindow()
  61529. {
  61530. updateCurrentModifiers();
  61531. component->userTriedToCloseWindow();
  61532. }
  61533. void ComponentPeer::bringModalComponentToFront()
  61534. {
  61535. Component::bringModalComponentToFront();
  61536. }
  61537. void ComponentPeer::clearMaskedRegion() throw()
  61538. {
  61539. maskedRegion.clear();
  61540. }
  61541. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61542. {
  61543. maskedRegion.add (x, y, w, h);
  61544. }
  61545. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61546. {
  61547. StringArray s;
  61548. s.add ("Software Renderer");
  61549. return s;
  61550. }
  61551. int ComponentPeer::getCurrentRenderingEngine() throw()
  61552. {
  61553. return 0;
  61554. }
  61555. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61556. {
  61557. }
  61558. END_JUCE_NAMESPACE
  61559. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61560. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61561. BEGIN_JUCE_NAMESPACE
  61562. DialogWindow::DialogWindow (const String& name,
  61563. const Colour& backgroundColour_,
  61564. const bool escapeKeyTriggersCloseButton_,
  61565. const bool addToDesktop_)
  61566. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61567. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61568. {
  61569. }
  61570. DialogWindow::~DialogWindow()
  61571. {
  61572. }
  61573. void DialogWindow::resized()
  61574. {
  61575. DocumentWindow::resized();
  61576. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61577. if (escapeKeyTriggersCloseButton
  61578. && getCloseButton() != 0
  61579. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61580. {
  61581. getCloseButton()->addShortcut (esc);
  61582. }
  61583. }
  61584. class TempDialogWindow : public DialogWindow
  61585. {
  61586. public:
  61587. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61588. : DialogWindow (title, colour, escapeCloses, true)
  61589. {
  61590. }
  61591. ~TempDialogWindow()
  61592. {
  61593. }
  61594. void closeButtonPressed()
  61595. {
  61596. setVisible (false);
  61597. }
  61598. private:
  61599. TempDialogWindow (const TempDialogWindow&);
  61600. TempDialogWindow& operator= (const TempDialogWindow&);
  61601. };
  61602. int DialogWindow::showModalDialog (const String& dialogTitle,
  61603. Component* contentComponent,
  61604. Component* componentToCentreAround,
  61605. const Colour& colour,
  61606. const bool escapeKeyTriggersCloseButton,
  61607. const bool shouldBeResizable,
  61608. const bool useBottomRightCornerResizer)
  61609. {
  61610. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61611. dw.setContentComponent (contentComponent, true, true);
  61612. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61613. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61614. const int result = dw.runModalLoop();
  61615. dw.setContentComponent (0, false);
  61616. return result;
  61617. }
  61618. END_JUCE_NAMESPACE
  61619. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61620. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61621. BEGIN_JUCE_NAMESPACE
  61622. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61623. {
  61624. public:
  61625. ButtonListenerProxy (DocumentWindow& owner_)
  61626. : owner (owner_)
  61627. {
  61628. }
  61629. void buttonClicked (Button* button)
  61630. {
  61631. if (button == owner.getMinimiseButton())
  61632. owner.minimiseButtonPressed();
  61633. else if (button == owner.getMaximiseButton())
  61634. owner.maximiseButtonPressed();
  61635. else if (button == owner.getCloseButton())
  61636. owner.closeButtonPressed();
  61637. }
  61638. juce_UseDebuggingNewOperator
  61639. private:
  61640. DocumentWindow& owner;
  61641. ButtonListenerProxy (const ButtonListenerProxy&);
  61642. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61643. };
  61644. DocumentWindow::DocumentWindow (const String& title,
  61645. const Colour& backgroundColour,
  61646. const int requiredButtons_,
  61647. const bool addToDesktop_)
  61648. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61649. titleBarHeight (26),
  61650. menuBarHeight (24),
  61651. requiredButtons (requiredButtons_),
  61652. #if JUCE_MAC
  61653. positionTitleBarButtonsOnLeft (true),
  61654. #else
  61655. positionTitleBarButtonsOnLeft (false),
  61656. #endif
  61657. drawTitleTextCentred (true),
  61658. menuBarModel (0)
  61659. {
  61660. setResizeLimits (128, 128, 32768, 32768);
  61661. lookAndFeelChanged();
  61662. }
  61663. DocumentWindow::~DocumentWindow()
  61664. {
  61665. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61666. titleBarButtons[i] = 0;
  61667. menuBar = 0;
  61668. }
  61669. void DocumentWindow::repaintTitleBar()
  61670. {
  61671. const Rectangle<int> titleBarArea (getTitleBarArea());
  61672. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61673. titleBarArea.getWidth(), titleBarArea.getHeight());
  61674. }
  61675. void DocumentWindow::setName (const String& newName)
  61676. {
  61677. if (newName != getName())
  61678. {
  61679. Component::setName (newName);
  61680. repaintTitleBar();
  61681. }
  61682. }
  61683. void DocumentWindow::setIcon (const Image* imageToUse)
  61684. {
  61685. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61686. repaintTitleBar();
  61687. }
  61688. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61689. {
  61690. titleBarHeight = newHeight;
  61691. resized();
  61692. repaintTitleBar();
  61693. }
  61694. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61695. const bool positionTitleBarButtonsOnLeft_)
  61696. {
  61697. requiredButtons = requiredButtons_;
  61698. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61699. lookAndFeelChanged();
  61700. }
  61701. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61702. {
  61703. drawTitleTextCentred = textShouldBeCentred;
  61704. repaintTitleBar();
  61705. }
  61706. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61707. const int menuBarHeight_)
  61708. {
  61709. if (menuBarModel != menuBarModel_)
  61710. {
  61711. menuBar = 0;
  61712. menuBarModel = menuBarModel_;
  61713. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61714. : getLookAndFeel().getDefaultMenuBarHeight();
  61715. if (menuBarModel != 0)
  61716. {
  61717. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61718. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61719. menuBar->setEnabled (isActiveWindow());
  61720. }
  61721. resized();
  61722. }
  61723. }
  61724. void DocumentWindow::closeButtonPressed()
  61725. {
  61726. /* If you've got a close button, you have to override this method to get
  61727. rid of your window!
  61728. If the window is just a pop-up, you should override this method and make
  61729. it delete the window in whatever way is appropriate for your app. E.g. you
  61730. might just want to call "delete this".
  61731. If your app is centred around this window such that the whole app should quit when
  61732. the window is closed, then you will probably want to use this method as an opportunity
  61733. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61734. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61735. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61736. or closing it via the taskbar icon on Windows).
  61737. */
  61738. jassertfalse
  61739. }
  61740. void DocumentWindow::minimiseButtonPressed()
  61741. {
  61742. setMinimised (true);
  61743. }
  61744. void DocumentWindow::maximiseButtonPressed()
  61745. {
  61746. setFullScreen (! isFullScreen());
  61747. }
  61748. void DocumentWindow::paint (Graphics& g)
  61749. {
  61750. ResizableWindow::paint (g);
  61751. if (resizableBorder == 0)
  61752. {
  61753. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61754. const BorderSize border (getBorderThickness());
  61755. g.fillRect (0, 0, getWidth(), border.getTop());
  61756. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61757. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61758. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61759. }
  61760. const Rectangle<int> titleBarArea (getTitleBarArea());
  61761. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61762. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61763. int titleSpaceX1 = 6;
  61764. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61765. for (int i = 0; i < 3; ++i)
  61766. {
  61767. if (titleBarButtons[i] != 0)
  61768. {
  61769. if (positionTitleBarButtonsOnLeft)
  61770. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61771. else
  61772. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61773. }
  61774. }
  61775. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61776. titleBarArea.getWidth(),
  61777. titleBarArea.getHeight(),
  61778. titleSpaceX1,
  61779. jmax (1, titleSpaceX2 - titleSpaceX1),
  61780. titleBarIcon,
  61781. ! drawTitleTextCentred);
  61782. }
  61783. void DocumentWindow::resized()
  61784. {
  61785. ResizableWindow::resized();
  61786. if (titleBarButtons[1] != 0)
  61787. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61788. const Rectangle<int> titleBarArea (getTitleBarArea());
  61789. getLookAndFeel()
  61790. .positionDocumentWindowButtons (*this,
  61791. titleBarArea.getX(), titleBarArea.getY(),
  61792. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61793. titleBarButtons[0],
  61794. titleBarButtons[1],
  61795. titleBarButtons[2],
  61796. positionTitleBarButtonsOnLeft);
  61797. if (menuBar != 0)
  61798. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61799. titleBarArea.getWidth(), menuBarHeight);
  61800. }
  61801. const BorderSize DocumentWindow::getBorderThickness()
  61802. {
  61803. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61804. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61805. }
  61806. const BorderSize DocumentWindow::getContentComponentBorder()
  61807. {
  61808. BorderSize border (getBorderThickness());
  61809. border.setTop (border.getTop()
  61810. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61811. + (menuBar != 0 ? menuBarHeight : 0));
  61812. return border;
  61813. }
  61814. int DocumentWindow::getTitleBarHeight() const
  61815. {
  61816. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61817. }
  61818. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61819. {
  61820. const BorderSize border (getBorderThickness());
  61821. return Rectangle<int> (border.getLeft(), border.getTop(),
  61822. getWidth() - border.getLeftAndRight(),
  61823. getTitleBarHeight());
  61824. }
  61825. Button* DocumentWindow::getCloseButton() const throw()
  61826. {
  61827. return titleBarButtons[2];
  61828. }
  61829. Button* DocumentWindow::getMinimiseButton() const throw()
  61830. {
  61831. return titleBarButtons[0];
  61832. }
  61833. Button* DocumentWindow::getMaximiseButton() const throw()
  61834. {
  61835. return titleBarButtons[1];
  61836. }
  61837. int DocumentWindow::getDesktopWindowStyleFlags() const
  61838. {
  61839. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61840. if ((requiredButtons & minimiseButton) != 0)
  61841. flags |= ComponentPeer::windowHasMinimiseButton;
  61842. if ((requiredButtons & maximiseButton) != 0)
  61843. flags |= ComponentPeer::windowHasMaximiseButton;
  61844. if ((requiredButtons & closeButton) != 0)
  61845. flags |= ComponentPeer::windowHasCloseButton;
  61846. return flags;
  61847. }
  61848. void DocumentWindow::lookAndFeelChanged()
  61849. {
  61850. int i;
  61851. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61852. titleBarButtons[i] = 0;
  61853. if (! isUsingNativeTitleBar())
  61854. {
  61855. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61856. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61857. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61858. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61859. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61860. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61861. for (i = 0; i < 3; ++i)
  61862. {
  61863. if (titleBarButtons[i] != 0)
  61864. {
  61865. if (buttonListener == 0)
  61866. buttonListener = new ButtonListenerProxy (*this);
  61867. titleBarButtons[i]->addButtonListener (buttonListener);
  61868. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61869. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61870. Component::addAndMakeVisible (titleBarButtons[i]);
  61871. }
  61872. }
  61873. if (getCloseButton() != 0)
  61874. {
  61875. #if JUCE_MAC
  61876. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61877. #else
  61878. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61879. #endif
  61880. }
  61881. }
  61882. activeWindowStatusChanged();
  61883. ResizableWindow::lookAndFeelChanged();
  61884. }
  61885. void DocumentWindow::parentHierarchyChanged()
  61886. {
  61887. lookAndFeelChanged();
  61888. }
  61889. void DocumentWindow::activeWindowStatusChanged()
  61890. {
  61891. ResizableWindow::activeWindowStatusChanged();
  61892. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61893. if (titleBarButtons[i] != 0)
  61894. titleBarButtons[i]->setEnabled (isActiveWindow());
  61895. if (menuBar != 0)
  61896. menuBar->setEnabled (isActiveWindow());
  61897. }
  61898. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61899. {
  61900. if (getTitleBarArea().contains (e.x, e.y)
  61901. && getMaximiseButton() != 0)
  61902. {
  61903. getMaximiseButton()->triggerClick();
  61904. }
  61905. }
  61906. void DocumentWindow::userTriedToCloseWindow()
  61907. {
  61908. closeButtonPressed();
  61909. }
  61910. END_JUCE_NAMESPACE
  61911. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61912. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61913. BEGIN_JUCE_NAMESPACE
  61914. ResizableWindow::ResizableWindow (const String& name,
  61915. const bool addToDesktop_)
  61916. : TopLevelWindow (name, addToDesktop_),
  61917. resizeToFitContent (false),
  61918. fullscreen (false),
  61919. lastNonFullScreenPos (50, 50, 256, 256),
  61920. constrainer (0)
  61921. #ifdef JUCE_DEBUG
  61922. , hasBeenResized (false)
  61923. #endif
  61924. {
  61925. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61926. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61927. if (addToDesktop_)
  61928. Component::addToDesktop (getDesktopWindowStyleFlags());
  61929. }
  61930. ResizableWindow::ResizableWindow (const String& name,
  61931. const Colour& backgroundColour_,
  61932. const bool addToDesktop_)
  61933. : TopLevelWindow (name, addToDesktop_),
  61934. resizeToFitContent (false),
  61935. fullscreen (false),
  61936. lastNonFullScreenPos (50, 50, 256, 256),
  61937. constrainer (0)
  61938. #ifdef JUCE_DEBUG
  61939. , hasBeenResized (false)
  61940. #endif
  61941. {
  61942. setBackgroundColour (backgroundColour_);
  61943. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61944. if (addToDesktop_)
  61945. Component::addToDesktop (getDesktopWindowStyleFlags());
  61946. }
  61947. ResizableWindow::~ResizableWindow()
  61948. {
  61949. resizableCorner = 0;
  61950. resizableBorder = 0;
  61951. contentComponent = 0;
  61952. // have you been adding your own components directly to this window..? tut tut tut.
  61953. // Read the instructions for using a ResizableWindow!
  61954. jassert (getNumChildComponents() == 0);
  61955. }
  61956. int ResizableWindow::getDesktopWindowStyleFlags() const
  61957. {
  61958. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61959. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61960. flags |= ComponentPeer::windowIsResizable;
  61961. return flags;
  61962. }
  61963. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61964. const bool deleteOldOne,
  61965. const bool resizeToFit)
  61966. {
  61967. resizeToFitContent = resizeToFit;
  61968. if (newContentComponent != static_cast <Component*> (contentComponent))
  61969. {
  61970. if (! deleteOldOne)
  61971. removeChildComponent (contentComponent.release());
  61972. contentComponent = newContentComponent;
  61973. Component::addAndMakeVisible (contentComponent);
  61974. }
  61975. if (resizeToFit)
  61976. childBoundsChanged (contentComponent);
  61977. resized(); // must always be called to position the new content comp
  61978. }
  61979. void ResizableWindow::setContentComponentSize (int width, int height)
  61980. {
  61981. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61982. const BorderSize border (getContentComponentBorder());
  61983. setSize (width + border.getLeftAndRight(),
  61984. height + border.getTopAndBottom());
  61985. }
  61986. const BorderSize ResizableWindow::getBorderThickness()
  61987. {
  61988. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61989. }
  61990. const BorderSize ResizableWindow::getContentComponentBorder()
  61991. {
  61992. return getBorderThickness();
  61993. }
  61994. void ResizableWindow::moved()
  61995. {
  61996. updateLastPos();
  61997. }
  61998. void ResizableWindow::visibilityChanged()
  61999. {
  62000. TopLevelWindow::visibilityChanged();
  62001. updateLastPos();
  62002. }
  62003. void ResizableWindow::resized()
  62004. {
  62005. if (resizableBorder != 0)
  62006. {
  62007. resizableBorder->setVisible (! isFullScreen());
  62008. resizableBorder->setBorderThickness (getBorderThickness());
  62009. resizableBorder->setSize (getWidth(), getHeight());
  62010. resizableBorder->toBack();
  62011. }
  62012. if (resizableCorner != 0)
  62013. {
  62014. resizableCorner->setVisible (! isFullScreen());
  62015. const int resizerSize = 18;
  62016. resizableCorner->setBounds (getWidth() - resizerSize,
  62017. getHeight() - resizerSize,
  62018. resizerSize, resizerSize);
  62019. }
  62020. if (contentComponent != 0)
  62021. contentComponent->setBoundsInset (getContentComponentBorder());
  62022. updateLastPos();
  62023. #ifdef JUCE_DEBUG
  62024. hasBeenResized = true;
  62025. #endif
  62026. }
  62027. void ResizableWindow::childBoundsChanged (Component* child)
  62028. {
  62029. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62030. {
  62031. // not going to look very good if this component has a zero size..
  62032. jassert (child->getWidth() > 0);
  62033. jassert (child->getHeight() > 0);
  62034. const BorderSize borders (getContentComponentBorder());
  62035. setSize (child->getWidth() + borders.getLeftAndRight(),
  62036. child->getHeight() + borders.getTopAndBottom());
  62037. }
  62038. }
  62039. void ResizableWindow::activeWindowStatusChanged()
  62040. {
  62041. const BorderSize borders (getContentComponentBorder());
  62042. repaint (0, 0, getWidth(), borders.getTop());
  62043. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62044. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62045. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62046. }
  62047. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62048. const bool useBottomRightCornerResizer)
  62049. {
  62050. if (shouldBeResizable)
  62051. {
  62052. if (useBottomRightCornerResizer)
  62053. {
  62054. resizableBorder = 0;
  62055. if (resizableCorner == 0)
  62056. {
  62057. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62058. resizableCorner->setAlwaysOnTop (true);
  62059. }
  62060. }
  62061. else
  62062. {
  62063. resizableCorner = 0;
  62064. if (resizableBorder == 0)
  62065. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62066. }
  62067. }
  62068. else
  62069. {
  62070. resizableCorner = 0;
  62071. resizableBorder = 0;
  62072. }
  62073. if (isUsingNativeTitleBar())
  62074. recreateDesktopWindow();
  62075. childBoundsChanged (contentComponent);
  62076. resized();
  62077. }
  62078. bool ResizableWindow::isResizable() const throw()
  62079. {
  62080. return resizableCorner != 0
  62081. || resizableBorder != 0;
  62082. }
  62083. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62084. const int newMinimumHeight,
  62085. const int newMaximumWidth,
  62086. const int newMaximumHeight) throw()
  62087. {
  62088. // if you've set up a custom constrainer then these settings won't have any effect..
  62089. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62090. if (constrainer == 0)
  62091. setConstrainer (&defaultConstrainer);
  62092. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62093. newMaximumWidth, newMaximumHeight);
  62094. setBoundsConstrained (getBounds());
  62095. }
  62096. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62097. {
  62098. if (constrainer != newConstrainer)
  62099. {
  62100. constrainer = newConstrainer;
  62101. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62102. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62103. resizableCorner = 0;
  62104. resizableBorder = 0;
  62105. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62106. ComponentPeer* const peer = getPeer();
  62107. if (peer != 0)
  62108. peer->setConstrainer (newConstrainer);
  62109. }
  62110. }
  62111. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62112. {
  62113. if (constrainer != 0)
  62114. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62115. else
  62116. setBounds (bounds);
  62117. }
  62118. void ResizableWindow::paint (Graphics& g)
  62119. {
  62120. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62121. getBorderThickness(), *this);
  62122. if (! isFullScreen())
  62123. {
  62124. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62125. getBorderThickness(), *this);
  62126. }
  62127. #ifdef JUCE_DEBUG
  62128. /* If this fails, then you've probably written a subclass with a resized()
  62129. callback but forgotten to make it call its parent class's resized() method.
  62130. It's important when you override methods like resized(), moved(),
  62131. etc., that you make sure the base class methods also get called.
  62132. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62133. because your content should all be inside the content component - and it's the
  62134. content component's resized() method that you should be using to do your
  62135. layout.
  62136. */
  62137. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62138. #endif
  62139. }
  62140. void ResizableWindow::lookAndFeelChanged()
  62141. {
  62142. resized();
  62143. if (isOnDesktop())
  62144. {
  62145. Component::addToDesktop (getDesktopWindowStyleFlags());
  62146. ComponentPeer* const peer = getPeer();
  62147. if (peer != 0)
  62148. peer->setConstrainer (constrainer);
  62149. }
  62150. }
  62151. const Colour ResizableWindow::getBackgroundColour() const throw()
  62152. {
  62153. return findColour (backgroundColourId, false);
  62154. }
  62155. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62156. {
  62157. Colour backgroundColour (newColour);
  62158. if (! Desktop::canUseSemiTransparentWindows())
  62159. backgroundColour = newColour.withAlpha (1.0f);
  62160. setColour (backgroundColourId, backgroundColour);
  62161. setOpaque (backgroundColour.isOpaque());
  62162. repaint();
  62163. }
  62164. bool ResizableWindow::isFullScreen() const
  62165. {
  62166. if (isOnDesktop())
  62167. {
  62168. ComponentPeer* const peer = getPeer();
  62169. return peer != 0 && peer->isFullScreen();
  62170. }
  62171. return fullscreen;
  62172. }
  62173. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62174. {
  62175. if (shouldBeFullScreen != isFullScreen())
  62176. {
  62177. updateLastPos();
  62178. fullscreen = shouldBeFullScreen;
  62179. if (isOnDesktop())
  62180. {
  62181. ComponentPeer* const peer = getPeer();
  62182. if (peer != 0)
  62183. {
  62184. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62185. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62186. peer->setFullScreen (shouldBeFullScreen);
  62187. if (! shouldBeFullScreen)
  62188. setBounds (lastPos);
  62189. }
  62190. else
  62191. {
  62192. jassertfalse
  62193. }
  62194. }
  62195. else
  62196. {
  62197. if (shouldBeFullScreen)
  62198. setBounds (0, 0, getParentWidth(), getParentHeight());
  62199. else
  62200. setBounds (lastNonFullScreenPos);
  62201. }
  62202. resized();
  62203. }
  62204. }
  62205. bool ResizableWindow::isMinimised() const
  62206. {
  62207. ComponentPeer* const peer = getPeer();
  62208. return (peer != 0) && peer->isMinimised();
  62209. }
  62210. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62211. {
  62212. if (shouldMinimise != isMinimised())
  62213. {
  62214. ComponentPeer* const peer = getPeer();
  62215. if (peer != 0)
  62216. {
  62217. updateLastPos();
  62218. peer->setMinimised (shouldMinimise);
  62219. }
  62220. else
  62221. {
  62222. jassertfalse
  62223. }
  62224. }
  62225. }
  62226. void ResizableWindow::updateLastPos()
  62227. {
  62228. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62229. {
  62230. lastNonFullScreenPos = getBounds();
  62231. }
  62232. }
  62233. void ResizableWindow::parentSizeChanged()
  62234. {
  62235. if (isFullScreen() && getParentComponent() != 0)
  62236. {
  62237. setBounds (0, 0, getParentWidth(), getParentHeight());
  62238. }
  62239. }
  62240. const String ResizableWindow::getWindowStateAsString()
  62241. {
  62242. updateLastPos();
  62243. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62244. }
  62245. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62246. {
  62247. StringArray tokens;
  62248. tokens.addTokens (s, false);
  62249. tokens.removeEmptyStrings();
  62250. tokens.trim();
  62251. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62252. const int firstCoord = fs ? 1 : 0;
  62253. if (tokens.size() != firstCoord + 4)
  62254. return false;
  62255. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62256. tokens[firstCoord + 1].getIntValue(),
  62257. tokens[firstCoord + 2].getIntValue(),
  62258. tokens[firstCoord + 3].getIntValue());
  62259. if (newPos.isEmpty())
  62260. return false;
  62261. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62262. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62263. if (peer != 0)
  62264. peer->getFrameSize().addTo (newPos);
  62265. if (! screen.contains (newPos))
  62266. {
  62267. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62268. jmin (newPos.getHeight(), screen.getHeight()));
  62269. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62270. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62271. }
  62272. if (peer != 0)
  62273. {
  62274. peer->getFrameSize().subtractFrom (newPos);
  62275. peer->setNonFullScreenBounds (newPos);
  62276. }
  62277. lastNonFullScreenPos = newPos;
  62278. setFullScreen (fs);
  62279. if (! fs)
  62280. setBoundsConstrained (newPos);
  62281. return true;
  62282. }
  62283. void ResizableWindow::mouseDown (const MouseEvent&)
  62284. {
  62285. if (! isFullScreen())
  62286. dragger.startDraggingComponent (this, constrainer);
  62287. }
  62288. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62289. {
  62290. if (! isFullScreen())
  62291. dragger.dragComponent (this, e);
  62292. }
  62293. #ifdef JUCE_DEBUG
  62294. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62295. {
  62296. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62297. manages its child components automatically, and if you add your own it'll cause
  62298. trouble. Instead, use setContentComponent() to give it a component which
  62299. will be automatically resized and kept in the right place - then you can add
  62300. subcomponents to the content comp. See the notes for the ResizableWindow class
  62301. for more info.
  62302. If you really know what you're doing and want to avoid this assertion, just call
  62303. Component::addChildComponent directly.
  62304. */
  62305. jassertfalse
  62306. Component::addChildComponent (child, zOrder);
  62307. }
  62308. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62309. {
  62310. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62311. manages its child components automatically, and if you add your own it'll cause
  62312. trouble. Instead, use setContentComponent() to give it a component which
  62313. will be automatically resized and kept in the right place - then you can add
  62314. subcomponents to the content comp. See the notes for the ResizableWindow class
  62315. for more info.
  62316. If you really know what you're doing and want to avoid this assertion, just call
  62317. Component::addAndMakeVisible directly.
  62318. */
  62319. jassertfalse
  62320. Component::addAndMakeVisible (child, zOrder);
  62321. }
  62322. #endif
  62323. END_JUCE_NAMESPACE
  62324. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62325. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62326. BEGIN_JUCE_NAMESPACE
  62327. SplashScreen::SplashScreen()
  62328. : backgroundImage (0)
  62329. {
  62330. setOpaque (true);
  62331. }
  62332. SplashScreen::~SplashScreen()
  62333. {
  62334. ImageCache::releaseOrDelete (backgroundImage);
  62335. }
  62336. void SplashScreen::show (const String& title,
  62337. Image* const backgroundImage_,
  62338. const int minimumTimeToDisplayFor,
  62339. const bool useDropShadow,
  62340. const bool removeOnMouseClick)
  62341. {
  62342. backgroundImage = backgroundImage_;
  62343. jassert (backgroundImage_ != 0);
  62344. if (backgroundImage_ != 0)
  62345. {
  62346. setOpaque (! backgroundImage_->hasAlphaChannel());
  62347. show (title,
  62348. backgroundImage_->getWidth(),
  62349. backgroundImage_->getHeight(),
  62350. minimumTimeToDisplayFor,
  62351. useDropShadow,
  62352. removeOnMouseClick);
  62353. }
  62354. }
  62355. void SplashScreen::show (const String& title,
  62356. const int width,
  62357. const int height,
  62358. const int minimumTimeToDisplayFor,
  62359. const bool useDropShadow,
  62360. const bool removeOnMouseClick)
  62361. {
  62362. setName (title);
  62363. setAlwaysOnTop (true);
  62364. setVisible (true);
  62365. centreWithSize (width, height);
  62366. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62367. toFront (false);
  62368. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62369. repaint();
  62370. originalClickCounter = removeOnMouseClick
  62371. ? Desktop::getMouseButtonClickCounter()
  62372. : std::numeric_limits<int>::max();
  62373. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62374. startTimer (50);
  62375. }
  62376. void SplashScreen::paint (Graphics& g)
  62377. {
  62378. if (backgroundImage != 0)
  62379. {
  62380. g.setOpacity (1.0f);
  62381. g.drawImage (backgroundImage,
  62382. 0, 0, getWidth(), getHeight(),
  62383. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62384. }
  62385. }
  62386. void SplashScreen::timerCallback()
  62387. {
  62388. if (Time::getCurrentTime() > earliestTimeToDelete
  62389. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62390. {
  62391. delete this;
  62392. }
  62393. }
  62394. END_JUCE_NAMESPACE
  62395. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62396. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62397. BEGIN_JUCE_NAMESPACE
  62398. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62399. const bool hasProgressBar,
  62400. const bool hasCancelButton,
  62401. const int timeOutMsWhenCancelling_,
  62402. const String& cancelButtonText)
  62403. : Thread ("Juce Progress Window"),
  62404. progress (0.0),
  62405. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62406. {
  62407. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62408. .createAlertWindow (title, String::empty, cancelButtonText,
  62409. String::empty, String::empty,
  62410. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62411. if (hasProgressBar)
  62412. alertWindow->addProgressBarComponent (progress);
  62413. }
  62414. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62415. {
  62416. stopThread (timeOutMsWhenCancelling);
  62417. }
  62418. bool ThreadWithProgressWindow::runThread (const int priority)
  62419. {
  62420. startThread (priority);
  62421. startTimer (100);
  62422. {
  62423. const ScopedLock sl (messageLock);
  62424. alertWindow->setMessage (message);
  62425. }
  62426. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62427. stopThread (timeOutMsWhenCancelling);
  62428. alertWindow->setVisible (false);
  62429. return finishedNaturally;
  62430. }
  62431. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62432. {
  62433. progress = newProgress;
  62434. }
  62435. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62436. {
  62437. const ScopedLock sl (messageLock);
  62438. message = newStatusMessage;
  62439. }
  62440. void ThreadWithProgressWindow::timerCallback()
  62441. {
  62442. if (! isThreadRunning())
  62443. {
  62444. // thread has finished normally..
  62445. alertWindow->exitModalState (1);
  62446. alertWindow->setVisible (false);
  62447. }
  62448. else
  62449. {
  62450. const ScopedLock sl (messageLock);
  62451. alertWindow->setMessage (message);
  62452. }
  62453. }
  62454. END_JUCE_NAMESPACE
  62455. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62456. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62457. BEGIN_JUCE_NAMESPACE
  62458. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62459. const int millisecondsBeforeTipAppears_)
  62460. : Component ("tooltip"),
  62461. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62462. mouseClicks (0),
  62463. lastHideTime (0),
  62464. lastComponentUnderMouse (0),
  62465. changedCompsSinceShown (true)
  62466. {
  62467. if (Desktop::getInstance().getMainMouseSource().canHover())
  62468. startTimer (123);
  62469. setAlwaysOnTop (true);
  62470. setOpaque (true);
  62471. if (parentComponent != 0)
  62472. parentComponent->addChildComponent (this);
  62473. }
  62474. TooltipWindow::~TooltipWindow()
  62475. {
  62476. hide();
  62477. }
  62478. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62479. {
  62480. millisecondsBeforeTipAppears = newTimeMs;
  62481. }
  62482. void TooltipWindow::paint (Graphics& g)
  62483. {
  62484. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62485. }
  62486. void TooltipWindow::mouseEnter (const MouseEvent&)
  62487. {
  62488. hide();
  62489. }
  62490. void TooltipWindow::showFor (const String& tip)
  62491. {
  62492. jassert (tip.isNotEmpty());
  62493. tipShowing = tip;
  62494. Point<int> mousePos (Desktop::getMousePosition());
  62495. if (getParentComponent() != 0)
  62496. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62497. int x, y, w, h;
  62498. getLookAndFeel().getTooltipSize (tip, w, h);
  62499. if (mousePos.getX() > getParentWidth() / 2)
  62500. x = mousePos.getX() - (w + 12);
  62501. else
  62502. x = mousePos.getX() + 24;
  62503. if (mousePos.getY() > getParentHeight() / 2)
  62504. y = mousePos.getY() - (h + 6);
  62505. else
  62506. y = mousePos.getY() + 6;
  62507. setBounds (x, y, w, h);
  62508. setVisible (true);
  62509. if (getParentComponent() == 0)
  62510. {
  62511. addToDesktop (ComponentPeer::windowHasDropShadow
  62512. | ComponentPeer::windowIsTemporary
  62513. | ComponentPeer::windowIgnoresKeyPresses);
  62514. }
  62515. toFront (false);
  62516. }
  62517. const String TooltipWindow::getTipFor (Component* const c)
  62518. {
  62519. if (c != 0
  62520. && Process::isForegroundProcess()
  62521. && ! Component::isMouseButtonDownAnywhere())
  62522. {
  62523. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62524. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62525. return ttc->getTooltip();
  62526. }
  62527. return String::empty;
  62528. }
  62529. void TooltipWindow::hide()
  62530. {
  62531. tipShowing = String::empty;
  62532. removeFromDesktop();
  62533. setVisible (false);
  62534. }
  62535. void TooltipWindow::timerCallback()
  62536. {
  62537. const unsigned int now = Time::getApproximateMillisecondCounter();
  62538. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62539. const String newTip (getTipFor (newComp));
  62540. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62541. lastComponentUnderMouse = newComp;
  62542. lastTipUnderMouse = newTip;
  62543. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62544. const bool mouseWasClicked = clickCount > mouseClicks;
  62545. mouseClicks = clickCount;
  62546. const Point<int> mousePos (Desktop::getMousePosition());
  62547. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62548. lastMousePos = mousePos;
  62549. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62550. lastCompChangeTime = now;
  62551. if (isVisible() || now < lastHideTime + 500)
  62552. {
  62553. // if a tip is currently visible (or has just disappeared), update to a new one
  62554. // immediately if needed..
  62555. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62556. {
  62557. if (isVisible())
  62558. {
  62559. lastHideTime = now;
  62560. hide();
  62561. }
  62562. }
  62563. else if (tipChanged)
  62564. {
  62565. showFor (newTip);
  62566. }
  62567. }
  62568. else
  62569. {
  62570. // if there isn't currently a tip, but one is needed, only let it
  62571. // appear after a timeout..
  62572. if (newTip.isNotEmpty()
  62573. && newTip != tipShowing
  62574. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62575. {
  62576. showFor (newTip);
  62577. }
  62578. }
  62579. }
  62580. END_JUCE_NAMESPACE
  62581. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62582. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62583. BEGIN_JUCE_NAMESPACE
  62584. class TopLevelWindowManager : public Timer,
  62585. public DeletedAtShutdown
  62586. {
  62587. public:
  62588. TopLevelWindowManager()
  62589. : currentActive (0)
  62590. {
  62591. }
  62592. ~TopLevelWindowManager()
  62593. {
  62594. clearSingletonInstance();
  62595. }
  62596. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62597. void timerCallback()
  62598. {
  62599. startTimer (jmin (1731, getTimerInterval() * 2));
  62600. TopLevelWindow* active = 0;
  62601. if (Process::isForegroundProcess())
  62602. {
  62603. active = currentActive;
  62604. Component* const c = Component::getCurrentlyFocusedComponent();
  62605. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62606. if (tlw == 0 && c != 0)
  62607. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62608. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62609. if (tlw != 0)
  62610. active = tlw;
  62611. }
  62612. if (active != currentActive)
  62613. {
  62614. currentActive = active;
  62615. for (int i = windows.size(); --i >= 0;)
  62616. {
  62617. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62618. tlw->setWindowActive (isWindowActive (tlw));
  62619. i = jmin (i, windows.size() - 1);
  62620. }
  62621. Desktop::getInstance().triggerFocusCallback();
  62622. }
  62623. }
  62624. bool addWindow (TopLevelWindow* const w) throw()
  62625. {
  62626. windows.add (w);
  62627. startTimer (10);
  62628. return isWindowActive (w);
  62629. }
  62630. void removeWindow (TopLevelWindow* const w) throw()
  62631. {
  62632. startTimer (10);
  62633. if (currentActive == w)
  62634. currentActive = 0;
  62635. windows.removeValue (w);
  62636. if (windows.size() == 0)
  62637. deleteInstance();
  62638. }
  62639. VoidArray windows;
  62640. private:
  62641. TopLevelWindow* currentActive;
  62642. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62643. {
  62644. return (tlw == currentActive
  62645. || tlw->isParentOf (currentActive)
  62646. || tlw->hasKeyboardFocus (true))
  62647. && tlw->isShowing();
  62648. }
  62649. TopLevelWindowManager (const TopLevelWindowManager&);
  62650. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62651. };
  62652. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62653. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62654. {
  62655. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62656. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62657. }
  62658. TopLevelWindow::TopLevelWindow (const String& name,
  62659. const bool addToDesktop_)
  62660. : Component (name),
  62661. useDropShadow (true),
  62662. useNativeTitleBar (false),
  62663. windowIsActive_ (false)
  62664. {
  62665. setOpaque (true);
  62666. if (addToDesktop_)
  62667. Component::addToDesktop (getDesktopWindowStyleFlags());
  62668. else
  62669. setDropShadowEnabled (true);
  62670. setWantsKeyboardFocus (true);
  62671. setBroughtToFrontOnMouseClick (true);
  62672. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62673. }
  62674. TopLevelWindow::~TopLevelWindow()
  62675. {
  62676. shadower = 0;
  62677. TopLevelWindowManager::getInstance()->removeWindow (this);
  62678. }
  62679. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62680. {
  62681. if (hasKeyboardFocus (true))
  62682. TopLevelWindowManager::getInstance()->timerCallback();
  62683. else
  62684. TopLevelWindowManager::getInstance()->startTimer (10);
  62685. }
  62686. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62687. {
  62688. if (windowIsActive_ != isNowActive)
  62689. {
  62690. windowIsActive_ = isNowActive;
  62691. activeWindowStatusChanged();
  62692. }
  62693. }
  62694. void TopLevelWindow::activeWindowStatusChanged()
  62695. {
  62696. }
  62697. void TopLevelWindow::parentHierarchyChanged()
  62698. {
  62699. setDropShadowEnabled (useDropShadow);
  62700. }
  62701. void TopLevelWindow::visibilityChanged()
  62702. {
  62703. if (isShowing())
  62704. toFront (true);
  62705. }
  62706. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62707. {
  62708. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62709. if (useDropShadow)
  62710. flags |= ComponentPeer::windowHasDropShadow;
  62711. if (useNativeTitleBar)
  62712. flags |= ComponentPeer::windowHasTitleBar;
  62713. return flags;
  62714. }
  62715. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62716. {
  62717. useDropShadow = useShadow;
  62718. if (isOnDesktop())
  62719. {
  62720. shadower = 0;
  62721. Component::addToDesktop (getDesktopWindowStyleFlags());
  62722. }
  62723. else
  62724. {
  62725. if (useShadow && isOpaque())
  62726. {
  62727. if (shadower == 0)
  62728. {
  62729. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62730. if (shadower != 0)
  62731. shadower->setOwner (this);
  62732. }
  62733. }
  62734. else
  62735. {
  62736. shadower = 0;
  62737. }
  62738. }
  62739. }
  62740. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62741. {
  62742. if (useNativeTitleBar != useNativeTitleBar_)
  62743. {
  62744. useNativeTitleBar = useNativeTitleBar_;
  62745. recreateDesktopWindow();
  62746. sendLookAndFeelChange();
  62747. }
  62748. }
  62749. void TopLevelWindow::recreateDesktopWindow()
  62750. {
  62751. if (isOnDesktop())
  62752. {
  62753. Component::addToDesktop (getDesktopWindowStyleFlags());
  62754. toFront (true);
  62755. }
  62756. }
  62757. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62758. {
  62759. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62760. because this class needs to make sure its layout corresponds with settings like whether
  62761. it's got a native title bar or not.
  62762. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62763. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62764. method, then add or remove whatever flags are necessary from this value before returning it.
  62765. */
  62766. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62767. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62768. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62769. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62770. sendLookAndFeelChange();
  62771. }
  62772. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62773. {
  62774. if (c == 0)
  62775. c = TopLevelWindow::getActiveTopLevelWindow();
  62776. if (c == 0)
  62777. {
  62778. centreWithSize (width, height);
  62779. }
  62780. else
  62781. {
  62782. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62783. (c->getHeight() - height) / 2)));
  62784. Rectangle<int> parentArea (c->getParentMonitorArea());
  62785. if (getParentComponent() != 0)
  62786. {
  62787. p = getParentComponent()->globalPositionToRelative (p);
  62788. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62789. }
  62790. parentArea.reduce (12, 12);
  62791. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62792. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62793. width, height);
  62794. }
  62795. }
  62796. int TopLevelWindow::getNumTopLevelWindows() throw()
  62797. {
  62798. return TopLevelWindowManager::getInstance()->windows.size();
  62799. }
  62800. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62801. {
  62802. return static_cast <TopLevelWindow*> (TopLevelWindowManager::getInstance()->windows [index]);
  62803. }
  62804. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62805. {
  62806. TopLevelWindow* best = 0;
  62807. int bestNumTWLParents = -1;
  62808. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62809. {
  62810. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62811. if (tlw->isActiveWindow())
  62812. {
  62813. int numTWLParents = 0;
  62814. const Component* c = tlw->getParentComponent();
  62815. while (c != 0)
  62816. {
  62817. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62818. ++numTWLParents;
  62819. c = c->getParentComponent();
  62820. }
  62821. if (bestNumTWLParents < numTWLParents)
  62822. {
  62823. best = tlw;
  62824. bestNumTWLParents = numTWLParents;
  62825. }
  62826. }
  62827. }
  62828. return best;
  62829. }
  62830. END_JUCE_NAMESPACE
  62831. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62832. /*** Start of inlined file: juce_Colour.cpp ***/
  62833. BEGIN_JUCE_NAMESPACE
  62834. namespace ColourHelpers
  62835. {
  62836. static uint8 floatAlphaToInt (const float alpha) throw()
  62837. {
  62838. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62839. }
  62840. static void convertHSBtoRGB (float h, float s, float v,
  62841. uint8& r, uint8& g, uint8& b) throw()
  62842. {
  62843. v = jlimit (0.0f, 1.0f, v);
  62844. v *= 255.0f;
  62845. const uint8 intV = (uint8) roundToInt (v);
  62846. if (s <= 0)
  62847. {
  62848. r = intV;
  62849. g = intV;
  62850. b = intV;
  62851. }
  62852. else
  62853. {
  62854. s = jmin (1.0f, s);
  62855. h = jlimit (0.0f, 1.0f, h);
  62856. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62857. const float f = h - floorf (h);
  62858. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62859. const float y = v * (1.0f - s * f);
  62860. const float z = v * (1.0f - (s * (1.0f - f)));
  62861. if (h < 1.0f)
  62862. {
  62863. r = intV;
  62864. g = (uint8) roundToInt (z);
  62865. b = x;
  62866. }
  62867. else if (h < 2.0f)
  62868. {
  62869. r = (uint8) roundToInt (y);
  62870. g = intV;
  62871. b = x;
  62872. }
  62873. else if (h < 3.0f)
  62874. {
  62875. r = x;
  62876. g = intV;
  62877. b = (uint8) roundToInt (z);
  62878. }
  62879. else if (h < 4.0f)
  62880. {
  62881. r = x;
  62882. g = (uint8) roundToInt (y);
  62883. b = intV;
  62884. }
  62885. else if (h < 5.0f)
  62886. {
  62887. r = (uint8) roundToInt (z);
  62888. g = x;
  62889. b = intV;
  62890. }
  62891. else if (h < 6.0f)
  62892. {
  62893. r = intV;
  62894. g = x;
  62895. b = (uint8) roundToInt (y);
  62896. }
  62897. else
  62898. {
  62899. r = 0;
  62900. g = 0;
  62901. b = 0;
  62902. }
  62903. }
  62904. }
  62905. }
  62906. Colour::Colour() throw()
  62907. : argb (0)
  62908. {
  62909. }
  62910. Colour::Colour (const Colour& other) throw()
  62911. : argb (other.argb)
  62912. {
  62913. }
  62914. Colour& Colour::operator= (const Colour& other) throw()
  62915. {
  62916. argb = other.argb;
  62917. return *this;
  62918. }
  62919. bool Colour::operator== (const Colour& other) const throw()
  62920. {
  62921. return argb.getARGB() == other.argb.getARGB();
  62922. }
  62923. bool Colour::operator!= (const Colour& other) const throw()
  62924. {
  62925. return argb.getARGB() != other.argb.getARGB();
  62926. }
  62927. Colour::Colour (const uint32 argb_) throw()
  62928. : argb (argb_)
  62929. {
  62930. }
  62931. Colour::Colour (const uint8 red,
  62932. const uint8 green,
  62933. const uint8 blue) throw()
  62934. {
  62935. argb.setARGB (0xff, red, green, blue);
  62936. }
  62937. const Colour Colour::fromRGB (const uint8 red,
  62938. const uint8 green,
  62939. const uint8 blue) throw()
  62940. {
  62941. return Colour (red, green, blue);
  62942. }
  62943. Colour::Colour (const uint8 red,
  62944. const uint8 green,
  62945. const uint8 blue,
  62946. const uint8 alpha) throw()
  62947. {
  62948. argb.setARGB (alpha, red, green, blue);
  62949. }
  62950. const Colour Colour::fromRGBA (const uint8 red,
  62951. const uint8 green,
  62952. const uint8 blue,
  62953. const uint8 alpha) throw()
  62954. {
  62955. return Colour (red, green, blue, alpha);
  62956. }
  62957. Colour::Colour (const uint8 red,
  62958. const uint8 green,
  62959. const uint8 blue,
  62960. const float alpha) throw()
  62961. {
  62962. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62963. }
  62964. const Colour Colour::fromRGBAFloat (const uint8 red,
  62965. const uint8 green,
  62966. const uint8 blue,
  62967. const float alpha) throw()
  62968. {
  62969. return Colour (red, green, blue, alpha);
  62970. }
  62971. Colour::Colour (const float hue,
  62972. const float saturation,
  62973. const float brightness,
  62974. const float alpha) throw()
  62975. {
  62976. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62977. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62978. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62979. }
  62980. const Colour Colour::fromHSV (const float hue,
  62981. const float saturation,
  62982. const float brightness,
  62983. const float alpha) throw()
  62984. {
  62985. return Colour (hue, saturation, brightness, alpha);
  62986. }
  62987. Colour::Colour (const float hue,
  62988. const float saturation,
  62989. const float brightness,
  62990. const uint8 alpha) throw()
  62991. {
  62992. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62993. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62994. argb.setARGB (alpha, r, g, b);
  62995. }
  62996. Colour::~Colour() throw()
  62997. {
  62998. }
  62999. const PixelARGB Colour::getPixelARGB() const throw()
  63000. {
  63001. PixelARGB p (argb);
  63002. p.premultiply();
  63003. return p;
  63004. }
  63005. uint32 Colour::getARGB() const throw()
  63006. {
  63007. return argb.getARGB();
  63008. }
  63009. bool Colour::isTransparent() const throw()
  63010. {
  63011. return getAlpha() == 0;
  63012. }
  63013. bool Colour::isOpaque() const throw()
  63014. {
  63015. return getAlpha() == 0xff;
  63016. }
  63017. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63018. {
  63019. PixelARGB newCol (argb);
  63020. newCol.setAlpha (newAlpha);
  63021. return Colour (newCol.getARGB());
  63022. }
  63023. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63024. {
  63025. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63026. PixelARGB newCol (argb);
  63027. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63028. return Colour (newCol.getARGB());
  63029. }
  63030. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63031. {
  63032. jassert (alphaMultiplier >= 0);
  63033. PixelARGB newCol (argb);
  63034. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63035. return Colour (newCol.getARGB());
  63036. }
  63037. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63038. {
  63039. const int destAlpha = getAlpha();
  63040. if (destAlpha > 0)
  63041. {
  63042. const int invA = 0xff - (int) src.getAlpha();
  63043. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63044. if (resA > 0)
  63045. {
  63046. const int da = (invA * destAlpha) / resA;
  63047. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63048. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63049. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63050. (uint8) resA);
  63051. }
  63052. return *this;
  63053. }
  63054. else
  63055. {
  63056. return src;
  63057. }
  63058. }
  63059. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63060. {
  63061. if (proportionOfOther <= 0)
  63062. return *this;
  63063. if (proportionOfOther >= 1.0f)
  63064. return other;
  63065. PixelARGB c1 (getPixelARGB());
  63066. const PixelARGB c2 (other.getPixelARGB());
  63067. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63068. c1.unpremultiply();
  63069. return Colour (c1.getARGB());
  63070. }
  63071. float Colour::getFloatRed() const throw()
  63072. {
  63073. return getRed() / 255.0f;
  63074. }
  63075. float Colour::getFloatGreen() const throw()
  63076. {
  63077. return getGreen() / 255.0f;
  63078. }
  63079. float Colour::getFloatBlue() const throw()
  63080. {
  63081. return getBlue() / 255.0f;
  63082. }
  63083. float Colour::getFloatAlpha() const throw()
  63084. {
  63085. return getAlpha() / 255.0f;
  63086. }
  63087. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63088. {
  63089. const int r = getRed();
  63090. const int g = getGreen();
  63091. const int b = getBlue();
  63092. const int hi = jmax (r, g, b);
  63093. const int lo = jmin (r, g, b);
  63094. if (hi != 0)
  63095. {
  63096. s = (hi - lo) / (float) hi;
  63097. if (s != 0)
  63098. {
  63099. const float invDiff = 1.0f / (hi - lo);
  63100. const float red = (hi - r) * invDiff;
  63101. const float green = (hi - g) * invDiff;
  63102. const float blue = (hi - b) * invDiff;
  63103. if (r == hi)
  63104. h = blue - green;
  63105. else if (g == hi)
  63106. h = 2.0f + red - blue;
  63107. else
  63108. h = 4.0f + green - red;
  63109. h *= 1.0f / 6.0f;
  63110. if (h < 0)
  63111. ++h;
  63112. }
  63113. else
  63114. {
  63115. h = 0;
  63116. }
  63117. }
  63118. else
  63119. {
  63120. s = 0;
  63121. h = 0;
  63122. }
  63123. v = hi / 255.0f;
  63124. }
  63125. float Colour::getHue() const throw()
  63126. {
  63127. float h, s, b;
  63128. getHSB (h, s, b);
  63129. return h;
  63130. }
  63131. const Colour Colour::withHue (const float hue) const throw()
  63132. {
  63133. float h, s, b;
  63134. getHSB (h, s, b);
  63135. return Colour (hue, s, b, getAlpha());
  63136. }
  63137. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63138. {
  63139. float h, s, b;
  63140. getHSB (h, s, b);
  63141. h += amountToRotate;
  63142. h -= floorf (h);
  63143. return Colour (h, s, b, getAlpha());
  63144. }
  63145. float Colour::getSaturation() const throw()
  63146. {
  63147. float h, s, b;
  63148. getHSB (h, s, b);
  63149. return s;
  63150. }
  63151. const Colour Colour::withSaturation (const float saturation) const throw()
  63152. {
  63153. float h, s, b;
  63154. getHSB (h, s, b);
  63155. return Colour (h, saturation, b, getAlpha());
  63156. }
  63157. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63158. {
  63159. float h, s, b;
  63160. getHSB (h, s, b);
  63161. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63162. }
  63163. float Colour::getBrightness() const throw()
  63164. {
  63165. float h, s, b;
  63166. getHSB (h, s, b);
  63167. return b;
  63168. }
  63169. const Colour Colour::withBrightness (const float brightness) const throw()
  63170. {
  63171. float h, s, b;
  63172. getHSB (h, s, b);
  63173. return Colour (h, s, brightness, getAlpha());
  63174. }
  63175. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63176. {
  63177. float h, s, b;
  63178. getHSB (h, s, b);
  63179. b *= amount;
  63180. if (b > 1.0f)
  63181. b = 1.0f;
  63182. return Colour (h, s, b, getAlpha());
  63183. }
  63184. const Colour Colour::brighter (float amount) const throw()
  63185. {
  63186. amount = 1.0f / (1.0f + amount);
  63187. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63188. (uint8) (255 - (amount * (255 - getGreen()))),
  63189. (uint8) (255 - (amount * (255 - getBlue()))),
  63190. getAlpha());
  63191. }
  63192. const Colour Colour::darker (float amount) const throw()
  63193. {
  63194. amount = 1.0f / (1.0f + amount);
  63195. return Colour ((uint8) (amount * getRed()),
  63196. (uint8) (amount * getGreen()),
  63197. (uint8) (amount * getBlue()),
  63198. getAlpha());
  63199. }
  63200. const Colour Colour::greyLevel (const float brightness) throw()
  63201. {
  63202. const uint8 level
  63203. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63204. return Colour (level, level, level);
  63205. }
  63206. const Colour Colour::contrasting (const float amount) const throw()
  63207. {
  63208. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63209. ? Colours::black
  63210. : Colours::white).withAlpha (amount));
  63211. }
  63212. const Colour Colour::contrasting (const Colour& colour1,
  63213. const Colour& colour2) throw()
  63214. {
  63215. const float b1 = colour1.getBrightness();
  63216. const float b2 = colour2.getBrightness();
  63217. float best = 0.0f;
  63218. float bestDist = 0.0f;
  63219. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63220. {
  63221. const float d1 = fabsf (i - b1);
  63222. const float d2 = fabsf (i - b2);
  63223. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63224. if (dist > bestDist)
  63225. {
  63226. best = i;
  63227. bestDist = dist;
  63228. }
  63229. }
  63230. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63231. .withBrightness (best);
  63232. }
  63233. const String Colour::toString() const
  63234. {
  63235. return String::toHexString ((int) argb.getARGB());
  63236. }
  63237. const Colour Colour::fromString (const String& encodedColourString)
  63238. {
  63239. return Colour ((uint32) encodedColourString.getHexValue32());
  63240. }
  63241. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63242. {
  63243. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63244. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63245. .toUpperCase();
  63246. }
  63247. END_JUCE_NAMESPACE
  63248. /*** End of inlined file: juce_Colour.cpp ***/
  63249. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63250. BEGIN_JUCE_NAMESPACE
  63251. ColourGradient::ColourGradient() throw()
  63252. {
  63253. #ifdef JUCE_DEBUG
  63254. x1 = 987654.0f;
  63255. #endif
  63256. }
  63257. ColourGradient::ColourGradient (const Colour& colour1,
  63258. const float x1_,
  63259. const float y1_,
  63260. const Colour& colour2,
  63261. const float x2_,
  63262. const float y2_,
  63263. const bool isRadial_) throw()
  63264. : x1 (x1_),
  63265. y1 (y1_),
  63266. x2 (x2_),
  63267. y2 (y2_),
  63268. isRadial (isRadial_)
  63269. {
  63270. colours.add (0);
  63271. colours.add (colour1.getARGB());
  63272. colours.add (1 << 16);
  63273. colours.add (colour2.getARGB());
  63274. }
  63275. ColourGradient::~ColourGradient() throw()
  63276. {
  63277. }
  63278. void ColourGradient::clearColours() throw()
  63279. {
  63280. colours.clear();
  63281. }
  63282. void ColourGradient::addColour (const double proportionAlongGradient,
  63283. const Colour& colour) throw()
  63284. {
  63285. // must be within the two end-points
  63286. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63287. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63288. int i;
  63289. for (i = 0; i < colours.size(); i += 2)
  63290. if (colours.getUnchecked(i) > pos)
  63291. break;
  63292. colours.insert (i, pos);
  63293. colours.insert (i + 1, colour.getARGB());
  63294. }
  63295. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63296. {
  63297. for (int i = 1; i < colours.size(); i += 2)
  63298. {
  63299. const Colour c (colours.getUnchecked(i));
  63300. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63301. }
  63302. }
  63303. int ColourGradient::getNumColours() const throw()
  63304. {
  63305. return colours.size() >> 1;
  63306. }
  63307. double ColourGradient::getColourPosition (const int index) const throw()
  63308. {
  63309. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63310. }
  63311. const Colour ColourGradient::getColour (const int index) const throw()
  63312. {
  63313. return Colour (colours [(index << 1) + 1]);
  63314. }
  63315. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63316. {
  63317. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63318. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63319. if (integerPos <= 0 || colours.size() <= 2)
  63320. return getColour (0);
  63321. int i = colours.size() - 2;
  63322. while (integerPos < (int) colours.getUnchecked(i))
  63323. i -= 2;
  63324. if (i >= colours.size() - 2)
  63325. return Colour (colours.getUnchecked(i));
  63326. const int pos1 = colours.getUnchecked (i);
  63327. const Colour col1 (colours.getUnchecked (i + 1));
  63328. const int pos2 = colours.getUnchecked (i + 2);
  63329. const Colour col2 (colours.getUnchecked (i + 3));
  63330. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63331. }
  63332. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63333. {
  63334. #ifdef JUCE_DEBUG
  63335. // trying to use the object without setting its co-ordinates? Have a careful read of
  63336. // the comments for the constructors.
  63337. jassert (x1 != 987654.0f);
  63338. #endif
  63339. const int numColours = colours.size() >> 1;
  63340. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63341. transform.transformPoint (tx1, ty1);
  63342. transform.transformPoint (tx2, ty2);
  63343. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63344. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63345. lookupTable.malloc (numEntries);
  63346. if (numColours >= 2)
  63347. {
  63348. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63349. PixelARGB pix1 (colours.getUnchecked (1));
  63350. pix1.premultiply();
  63351. int index = 0;
  63352. for (int j = 2; j < colours.size(); j += 2)
  63353. {
  63354. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63355. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63356. pix2.premultiply();
  63357. for (int i = 0; i < numToDo; ++i)
  63358. {
  63359. jassert (index >= 0 && index < numEntries);
  63360. lookupTable[index] = pix1;
  63361. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63362. ++index;
  63363. }
  63364. pix1 = pix2;
  63365. }
  63366. while (index < numEntries)
  63367. lookupTable [index++] = pix1;
  63368. }
  63369. else
  63370. {
  63371. jassertfalse // no colours specified!
  63372. }
  63373. return numEntries;
  63374. }
  63375. bool ColourGradient::isOpaque() const throw()
  63376. {
  63377. for (int i = 1; i < colours.size(); i += 2)
  63378. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63379. return false;
  63380. return true;
  63381. }
  63382. bool ColourGradient::isInvisible() const throw()
  63383. {
  63384. for (int i = 1; i < colours.size(); i += 2)
  63385. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63386. return false;
  63387. return true;
  63388. }
  63389. END_JUCE_NAMESPACE
  63390. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63391. /*** Start of inlined file: juce_Colours.cpp ***/
  63392. BEGIN_JUCE_NAMESPACE
  63393. const Colour Colours::transparentBlack (0);
  63394. const Colour Colours::transparentWhite (0x00ffffff);
  63395. const Colour Colours::aliceblue (0xfff0f8ff);
  63396. const Colour Colours::antiquewhite (0xfffaebd7);
  63397. const Colour Colours::aqua (0xff00ffff);
  63398. const Colour Colours::aquamarine (0xff7fffd4);
  63399. const Colour Colours::azure (0xfff0ffff);
  63400. const Colour Colours::beige (0xfff5f5dc);
  63401. const Colour Colours::bisque (0xffffe4c4);
  63402. const Colour Colours::black (0xff000000);
  63403. const Colour Colours::blanchedalmond (0xffffebcd);
  63404. const Colour Colours::blue (0xff0000ff);
  63405. const Colour Colours::blueviolet (0xff8a2be2);
  63406. const Colour Colours::brown (0xffa52a2a);
  63407. const Colour Colours::burlywood (0xffdeb887);
  63408. const Colour Colours::cadetblue (0xff5f9ea0);
  63409. const Colour Colours::chartreuse (0xff7fff00);
  63410. const Colour Colours::chocolate (0xffd2691e);
  63411. const Colour Colours::coral (0xffff7f50);
  63412. const Colour Colours::cornflowerblue (0xff6495ed);
  63413. const Colour Colours::cornsilk (0xfffff8dc);
  63414. const Colour Colours::crimson (0xffdc143c);
  63415. const Colour Colours::cyan (0xff00ffff);
  63416. const Colour Colours::darkblue (0xff00008b);
  63417. const Colour Colours::darkcyan (0xff008b8b);
  63418. const Colour Colours::darkgoldenrod (0xffb8860b);
  63419. const Colour Colours::darkgrey (0xff555555);
  63420. const Colour Colours::darkgreen (0xff006400);
  63421. const Colour Colours::darkkhaki (0xffbdb76b);
  63422. const Colour Colours::darkmagenta (0xff8b008b);
  63423. const Colour Colours::darkolivegreen (0xff556b2f);
  63424. const Colour Colours::darkorange (0xffff8c00);
  63425. const Colour Colours::darkorchid (0xff9932cc);
  63426. const Colour Colours::darkred (0xff8b0000);
  63427. const Colour Colours::darksalmon (0xffe9967a);
  63428. const Colour Colours::darkseagreen (0xff8fbc8f);
  63429. const Colour Colours::darkslateblue (0xff483d8b);
  63430. const Colour Colours::darkslategrey (0xff2f4f4f);
  63431. const Colour Colours::darkturquoise (0xff00ced1);
  63432. const Colour Colours::darkviolet (0xff9400d3);
  63433. const Colour Colours::deeppink (0xffff1493);
  63434. const Colour Colours::deepskyblue (0xff00bfff);
  63435. const Colour Colours::dimgrey (0xff696969);
  63436. const Colour Colours::dodgerblue (0xff1e90ff);
  63437. const Colour Colours::firebrick (0xffb22222);
  63438. const Colour Colours::floralwhite (0xfffffaf0);
  63439. const Colour Colours::forestgreen (0xff228b22);
  63440. const Colour Colours::fuchsia (0xffff00ff);
  63441. const Colour Colours::gainsboro (0xffdcdcdc);
  63442. const Colour Colours::gold (0xffffd700);
  63443. const Colour Colours::goldenrod (0xffdaa520);
  63444. const Colour Colours::grey (0xff808080);
  63445. const Colour Colours::green (0xff008000);
  63446. const Colour Colours::greenyellow (0xffadff2f);
  63447. const Colour Colours::honeydew (0xfff0fff0);
  63448. const Colour Colours::hotpink (0xffff69b4);
  63449. const Colour Colours::indianred (0xffcd5c5c);
  63450. const Colour Colours::indigo (0xff4b0082);
  63451. const Colour Colours::ivory (0xfffffff0);
  63452. const Colour Colours::khaki (0xfff0e68c);
  63453. const Colour Colours::lavender (0xffe6e6fa);
  63454. const Colour Colours::lavenderblush (0xfffff0f5);
  63455. const Colour Colours::lemonchiffon (0xfffffacd);
  63456. const Colour Colours::lightblue (0xffadd8e6);
  63457. const Colour Colours::lightcoral (0xfff08080);
  63458. const Colour Colours::lightcyan (0xffe0ffff);
  63459. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63460. const Colour Colours::lightgreen (0xff90ee90);
  63461. const Colour Colours::lightgrey (0xffd3d3d3);
  63462. const Colour Colours::lightpink (0xffffb6c1);
  63463. const Colour Colours::lightsalmon (0xffffa07a);
  63464. const Colour Colours::lightseagreen (0xff20b2aa);
  63465. const Colour Colours::lightskyblue (0xff87cefa);
  63466. const Colour Colours::lightslategrey (0xff778899);
  63467. const Colour Colours::lightsteelblue (0xffb0c4de);
  63468. const Colour Colours::lightyellow (0xffffffe0);
  63469. const Colour Colours::lime (0xff00ff00);
  63470. const Colour Colours::limegreen (0xff32cd32);
  63471. const Colour Colours::linen (0xfffaf0e6);
  63472. const Colour Colours::magenta (0xffff00ff);
  63473. const Colour Colours::maroon (0xff800000);
  63474. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63475. const Colour Colours::mediumblue (0xff0000cd);
  63476. const Colour Colours::mediumorchid (0xffba55d3);
  63477. const Colour Colours::mediumpurple (0xff9370db);
  63478. const Colour Colours::mediumseagreen (0xff3cb371);
  63479. const Colour Colours::mediumslateblue (0xff7b68ee);
  63480. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63481. const Colour Colours::mediumturquoise (0xff48d1cc);
  63482. const Colour Colours::mediumvioletred (0xffc71585);
  63483. const Colour Colours::midnightblue (0xff191970);
  63484. const Colour Colours::mintcream (0xfff5fffa);
  63485. const Colour Colours::mistyrose (0xffffe4e1);
  63486. const Colour Colours::navajowhite (0xffffdead);
  63487. const Colour Colours::navy (0xff000080);
  63488. const Colour Colours::oldlace (0xfffdf5e6);
  63489. const Colour Colours::olive (0xff808000);
  63490. const Colour Colours::olivedrab (0xff6b8e23);
  63491. const Colour Colours::orange (0xffffa500);
  63492. const Colour Colours::orangered (0xffff4500);
  63493. const Colour Colours::orchid (0xffda70d6);
  63494. const Colour Colours::palegoldenrod (0xffeee8aa);
  63495. const Colour Colours::palegreen (0xff98fb98);
  63496. const Colour Colours::paleturquoise (0xffafeeee);
  63497. const Colour Colours::palevioletred (0xffdb7093);
  63498. const Colour Colours::papayawhip (0xffffefd5);
  63499. const Colour Colours::peachpuff (0xffffdab9);
  63500. const Colour Colours::peru (0xffcd853f);
  63501. const Colour Colours::pink (0xffffc0cb);
  63502. const Colour Colours::plum (0xffdda0dd);
  63503. const Colour Colours::powderblue (0xffb0e0e6);
  63504. const Colour Colours::purple (0xff800080);
  63505. const Colour Colours::red (0xffff0000);
  63506. const Colour Colours::rosybrown (0xffbc8f8f);
  63507. const Colour Colours::royalblue (0xff4169e1);
  63508. const Colour Colours::saddlebrown (0xff8b4513);
  63509. const Colour Colours::salmon (0xfffa8072);
  63510. const Colour Colours::sandybrown (0xfff4a460);
  63511. const Colour Colours::seagreen (0xff2e8b57);
  63512. const Colour Colours::seashell (0xfffff5ee);
  63513. const Colour Colours::sienna (0xffa0522d);
  63514. const Colour Colours::silver (0xffc0c0c0);
  63515. const Colour Colours::skyblue (0xff87ceeb);
  63516. const Colour Colours::slateblue (0xff6a5acd);
  63517. const Colour Colours::slategrey (0xff708090);
  63518. const Colour Colours::snow (0xfffffafa);
  63519. const Colour Colours::springgreen (0xff00ff7f);
  63520. const Colour Colours::steelblue (0xff4682b4);
  63521. const Colour Colours::tan (0xffd2b48c);
  63522. const Colour Colours::teal (0xff008080);
  63523. const Colour Colours::thistle (0xffd8bfd8);
  63524. const Colour Colours::tomato (0xffff6347);
  63525. const Colour Colours::turquoise (0xff40e0d0);
  63526. const Colour Colours::violet (0xffee82ee);
  63527. const Colour Colours::wheat (0xfff5deb3);
  63528. const Colour Colours::white (0xffffffff);
  63529. const Colour Colours::whitesmoke (0xfff5f5f5);
  63530. const Colour Colours::yellow (0xffffff00);
  63531. const Colour Colours::yellowgreen (0xff9acd32);
  63532. const Colour Colours::findColourForName (const String& colourName,
  63533. const Colour& defaultColour)
  63534. {
  63535. static const int presets[] =
  63536. {
  63537. // (first value is the string's hashcode, second is ARGB)
  63538. 0x05978fff, 0xff000000, /* black */
  63539. 0x06bdcc29, 0xffffffff, /* white */
  63540. 0x002e305a, 0xff0000ff, /* blue */
  63541. 0x00308adf, 0xff808080, /* grey */
  63542. 0x05e0cf03, 0xff008000, /* green */
  63543. 0x0001b891, 0xffff0000, /* red */
  63544. 0xd43c6474, 0xffffff00, /* yellow */
  63545. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63546. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63547. 0x002dcebc, 0xff00ffff, /* aqua */
  63548. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63549. 0x0590228f, 0xfff0ffff, /* azure */
  63550. 0x05947fe4, 0xfff5f5dc, /* beige */
  63551. 0xad388e35, 0xffffe4c4, /* bisque */
  63552. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63553. 0x39129959, 0xff8a2be2, /* blueviolet */
  63554. 0x059a8136, 0xffa52a2a, /* brown */
  63555. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63556. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63557. 0x6b748956, 0xff7fff00, /* chartreuse */
  63558. 0x2903623c, 0xffd2691e, /* chocolate */
  63559. 0x05a74431, 0xffff7f50, /* coral */
  63560. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63561. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63562. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63563. 0x002ed323, 0xff00ffff, /* cyan */
  63564. 0x67cc74d0, 0xff00008b, /* darkblue */
  63565. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63566. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63567. 0x67cecf55, 0xff555555, /* darkgrey */
  63568. 0x920b194d, 0xff006400, /* darkgreen */
  63569. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63570. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63571. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63572. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63573. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63574. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63575. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63576. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63577. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63578. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63579. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63580. 0xc8769375, 0xff9400d3, /* darkviolet */
  63581. 0x25832862, 0xffff1493, /* deeppink */
  63582. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63583. 0x634c8b67, 0xff696969, /* dimgrey */
  63584. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63585. 0xef19e3cb, 0xffb22222, /* firebrick */
  63586. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63587. 0xd086fd06, 0xff228b22, /* forestgreen */
  63588. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63589. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63590. 0x00308060, 0xffffd700, /* gold */
  63591. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63592. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63593. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63594. 0x41892743, 0xffff69b4, /* hotpink */
  63595. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63596. 0xb969fed2, 0xff4b0082, /* indigo */
  63597. 0x05fef6a9, 0xfffffff0, /* ivory */
  63598. 0x06149302, 0xfff0e68c, /* khaki */
  63599. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63600. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63601. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63602. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63603. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63604. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63605. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63606. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63607. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63608. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63609. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63610. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63611. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63612. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63613. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63614. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63615. 0x0032afd5, 0xff00ff00, /* lime */
  63616. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63617. 0x06234efa, 0xfffaf0e6, /* linen */
  63618. 0x316858a9, 0xffff00ff, /* magenta */
  63619. 0xbf8ca470, 0xff800000, /* maroon */
  63620. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63621. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63622. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63623. 0x07556b71, 0xff9370db, /* mediumpurple */
  63624. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63625. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63626. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63627. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63628. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63629. 0x168eb32a, 0xff191970, /* midnightblue */
  63630. 0x4306b960, 0xfff5fffa, /* mintcream */
  63631. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63632. 0xe97218a6, 0xffffdead, /* navajowhite */
  63633. 0x00337bb6, 0xff000080, /* navy */
  63634. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63635. 0x064ee1db, 0xff808000, /* olive */
  63636. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63637. 0xc3de262e, 0xffffa500, /* orange */
  63638. 0x58bebba3, 0xffff4500, /* orangered */
  63639. 0xc3def8a3, 0xffda70d6, /* orchid */
  63640. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63641. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63642. 0x74022737, 0xffafeeee, /* paleturquoise */
  63643. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63644. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63645. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63646. 0x003472f8, 0xffcd853f, /* peru */
  63647. 0x00348176, 0xffffc0cb, /* pink */
  63648. 0x00348d94, 0xffdda0dd, /* plum */
  63649. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63650. 0xc5c507bc, 0xff800080, /* purple */
  63651. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63652. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63653. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63654. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63655. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63656. 0x34636c14, 0xff2e8b57, /* seagreen */
  63657. 0x3507fb41, 0xfffff5ee, /* seashell */
  63658. 0xca348772, 0xffa0522d, /* sienna */
  63659. 0xca37d30d, 0xffc0c0c0, /* silver */
  63660. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63661. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63662. 0x44ab37f8, 0xff708090, /* slategrey */
  63663. 0x0035f183, 0xfffffafa, /* snow */
  63664. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63665. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63666. 0x0001bfa1, 0xffd2b48c, /* tan */
  63667. 0x0036425c, 0xff008080, /* teal */
  63668. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63669. 0xcc41600a, 0xffff6347, /* tomato */
  63670. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63671. 0xcf57947f, 0xffee82ee, /* violet */
  63672. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63673. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63674. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63675. };
  63676. const int hash = colourName.trim().toLowerCase().hashCode();
  63677. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63678. if (presets [i] == hash)
  63679. return Colour (presets [i + 1]);
  63680. return defaultColour;
  63681. }
  63682. END_JUCE_NAMESPACE
  63683. /*** End of inlined file: juce_Colours.cpp ***/
  63684. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63685. BEGIN_JUCE_NAMESPACE
  63686. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63687. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63688. const Path& path, const AffineTransform& transform)
  63689. : bounds (bounds_),
  63690. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63691. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63692. needToCheckEmptinesss (true)
  63693. {
  63694. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63695. int* t = table;
  63696. for (int i = bounds.getHeight(); --i >= 0;)
  63697. {
  63698. *t = 0;
  63699. t += lineStrideElements;
  63700. }
  63701. const int topLimit = bounds.getY() << 8;
  63702. const int heightLimit = bounds.getHeight() << 8;
  63703. const int leftLimit = bounds.getX() << 8;
  63704. const int rightLimit = bounds.getRight() << 8;
  63705. PathFlatteningIterator iter (path, transform);
  63706. while (iter.next())
  63707. {
  63708. int y1 = roundToInt (iter.y1 * 256.0f);
  63709. int y2 = roundToInt (iter.y2 * 256.0f);
  63710. if (y1 != y2)
  63711. {
  63712. y1 -= topLimit;
  63713. y2 -= topLimit;
  63714. const int startY = y1;
  63715. int direction = -1;
  63716. if (y1 > y2)
  63717. {
  63718. swapVariables (y1, y2);
  63719. direction = 1;
  63720. }
  63721. if (y1 < 0)
  63722. y1 = 0;
  63723. if (y2 > heightLimit)
  63724. y2 = heightLimit;
  63725. if (y1 < y2)
  63726. {
  63727. const double startX = 256.0f * iter.x1;
  63728. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63729. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63730. do
  63731. {
  63732. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63733. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63734. if (x < leftLimit)
  63735. x = leftLimit;
  63736. else if (x >= rightLimit)
  63737. x = rightLimit - 1;
  63738. addEdgePoint (x, y1 >> 8, direction * step);
  63739. y1 += step;
  63740. }
  63741. while (y1 < y2);
  63742. }
  63743. }
  63744. }
  63745. sanitiseLevels (path.isUsingNonZeroWinding());
  63746. }
  63747. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63748. : bounds (rectangleToAdd),
  63749. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63750. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63751. needToCheckEmptinesss (true)
  63752. {
  63753. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63754. table[0] = 0;
  63755. const int x1 = rectangleToAdd.getX() << 8;
  63756. const int x2 = rectangleToAdd.getRight() << 8;
  63757. int* t = table;
  63758. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63759. {
  63760. t[0] = 2;
  63761. t[1] = x1;
  63762. t[2] = 255;
  63763. t[3] = x2;
  63764. t[4] = 0;
  63765. t += lineStrideElements;
  63766. }
  63767. }
  63768. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63769. : bounds (rectanglesToAdd.getBounds()),
  63770. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63771. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63772. needToCheckEmptinesss (true)
  63773. {
  63774. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63775. int* t = table;
  63776. for (int i = bounds.getHeight(); --i >= 0;)
  63777. {
  63778. *t = 0;
  63779. t += lineStrideElements;
  63780. }
  63781. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63782. {
  63783. const Rectangle<int>* const r = iter.getRectangle();
  63784. const int x1 = r->getX() << 8;
  63785. const int x2 = r->getRight() << 8;
  63786. int y = r->getY() - bounds.getY();
  63787. for (int j = r->getHeight(); --j >= 0;)
  63788. {
  63789. addEdgePoint (x1, y, 255);
  63790. addEdgePoint (x2, y, -255);
  63791. ++y;
  63792. }
  63793. }
  63794. sanitiseLevels (true);
  63795. }
  63796. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63797. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63798. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63799. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63800. needToCheckEmptinesss (true)
  63801. {
  63802. jassert (w > 0 && h > 0);
  63803. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63804. table[0] = 0;
  63805. const int x1 = roundToInt (x * 256.0f);
  63806. const int x2 = roundToInt ((x + w) * 256.0f);
  63807. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63808. jassert (y1 < 256);
  63809. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63810. if (x2 <= x1 || y2 <= y1)
  63811. {
  63812. bounds.setHeight (0);
  63813. return;
  63814. }
  63815. int lineY = 0;
  63816. int* t = table;
  63817. if ((y1 >> 8) == (y2 >> 8))
  63818. {
  63819. t[0] = 2;
  63820. t[1] = x1;
  63821. t[2] = y2 - y1;
  63822. t[3] = x2;
  63823. t[4] = 0;
  63824. ++lineY;
  63825. t += lineStrideElements;
  63826. }
  63827. else
  63828. {
  63829. t[0] = 2;
  63830. t[1] = x1;
  63831. t[2] = 255 - (y1 & 255);
  63832. t[3] = x2;
  63833. t[4] = 0;
  63834. ++lineY;
  63835. t += lineStrideElements;
  63836. while (lineY < (y2 >> 8))
  63837. {
  63838. t[0] = 2;
  63839. t[1] = x1;
  63840. t[2] = 255;
  63841. t[3] = x2;
  63842. t[4] = 0;
  63843. ++lineY;
  63844. t += lineStrideElements;
  63845. }
  63846. jassert (lineY < bounds.getHeight());
  63847. t[0] = 2;
  63848. t[1] = x1;
  63849. t[2] = y2 & 255;
  63850. t[3] = x2;
  63851. t[4] = 0;
  63852. ++lineY;
  63853. t += lineStrideElements;
  63854. }
  63855. while (lineY < bounds.getHeight())
  63856. {
  63857. t[0] = 0;
  63858. t += lineStrideElements;
  63859. ++lineY;
  63860. }
  63861. }
  63862. EdgeTable::EdgeTable (const EdgeTable& other)
  63863. : table (0)
  63864. {
  63865. operator= (other);
  63866. }
  63867. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63868. {
  63869. bounds = other.bounds;
  63870. maxEdgesPerLine = other.maxEdgesPerLine;
  63871. lineStrideElements = other.lineStrideElements;
  63872. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63873. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63874. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63875. return *this;
  63876. }
  63877. EdgeTable::~EdgeTable()
  63878. {
  63879. }
  63880. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63881. {
  63882. while (--numLines >= 0)
  63883. {
  63884. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63885. src += srcLineStride;
  63886. dest += destLineStride;
  63887. }
  63888. }
  63889. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63890. {
  63891. // Convert the table from relative windings to absolute levels..
  63892. int* lineStart = table;
  63893. for (int i = bounds.getHeight(); --i >= 0;)
  63894. {
  63895. int* line = lineStart;
  63896. lineStart += lineStrideElements;
  63897. int num = *line;
  63898. if (num == 0)
  63899. continue;
  63900. int level = 0;
  63901. if (useNonZeroWinding)
  63902. {
  63903. while (--num > 0)
  63904. {
  63905. line += 2;
  63906. level += *line;
  63907. int corrected = abs (level);
  63908. if (corrected >> 8)
  63909. corrected = 255;
  63910. *line = corrected;
  63911. }
  63912. }
  63913. else
  63914. {
  63915. while (--num > 0)
  63916. {
  63917. line += 2;
  63918. level += *line;
  63919. int corrected = abs (level);
  63920. if (corrected >> 8)
  63921. {
  63922. corrected &= 511;
  63923. if (corrected >> 8)
  63924. corrected = 511 - corrected;
  63925. }
  63926. *line = corrected;
  63927. }
  63928. }
  63929. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63930. }
  63931. }
  63932. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63933. {
  63934. if (newNumEdgesPerLine != maxEdgesPerLine)
  63935. {
  63936. maxEdgesPerLine = newNumEdgesPerLine;
  63937. jassert (bounds.getHeight() > 0);
  63938. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63939. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63940. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63941. table.swapWith (newTable);
  63942. lineStrideElements = newLineStrideElements;
  63943. }
  63944. }
  63945. void EdgeTable::optimiseTable() throw()
  63946. {
  63947. int maxLineElements = 0;
  63948. for (int i = bounds.getHeight(); --i >= 0;)
  63949. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63950. remapTableForNumEdges (maxLineElements);
  63951. }
  63952. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63953. {
  63954. jassert (y >= 0 && y < bounds.getHeight());
  63955. int* line = table + lineStrideElements * y;
  63956. const int numPoints = line[0];
  63957. int n = numPoints << 1;
  63958. if (n > 0)
  63959. {
  63960. while (n > 0)
  63961. {
  63962. const int cx = line [n - 1];
  63963. if (cx <= x)
  63964. {
  63965. if (cx == x)
  63966. {
  63967. line [n] += winding;
  63968. return;
  63969. }
  63970. break;
  63971. }
  63972. n -= 2;
  63973. }
  63974. if (numPoints >= maxEdgesPerLine)
  63975. {
  63976. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63977. jassert (numPoints < maxEdgesPerLine);
  63978. line = table + lineStrideElements * y;
  63979. }
  63980. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63981. }
  63982. line [n + 1] = x;
  63983. line [n + 2] = winding;
  63984. line[0]++;
  63985. }
  63986. void EdgeTable::translate (float dx, int dy) throw()
  63987. {
  63988. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63989. int* lineStart = table;
  63990. const int intDx = (int) (dx * 256.0f);
  63991. for (int i = bounds.getHeight(); --i >= 0;)
  63992. {
  63993. int* line = lineStart;
  63994. lineStart += lineStrideElements;
  63995. int num = *line++;
  63996. while (--num >= 0)
  63997. {
  63998. *line += intDx;
  63999. line += 2;
  64000. }
  64001. }
  64002. }
  64003. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64004. {
  64005. jassert (y >= 0 && y < bounds.getHeight());
  64006. int* dest = table + lineStrideElements * y;
  64007. if (dest[0] == 0)
  64008. return;
  64009. int otherNumPoints = *otherLine;
  64010. if (otherNumPoints == 0)
  64011. {
  64012. *dest = 0;
  64013. return;
  64014. }
  64015. const int right = bounds.getRight() << 8;
  64016. // optimise for the common case where our line lies entirely within a
  64017. // single pair of points, as happens when clipping to a simple rect.
  64018. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64019. {
  64020. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64021. return;
  64022. }
  64023. ++otherLine;
  64024. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64025. int* temp = (int*) alloca (lineSizeBytes);
  64026. memcpy (temp, dest, lineSizeBytes);
  64027. const int* src1 = temp;
  64028. int srcNum1 = *src1++;
  64029. int x1 = *src1++;
  64030. const int* src2 = otherLine;
  64031. int srcNum2 = otherNumPoints;
  64032. int x2 = *src2++;
  64033. int destIndex = 0, destTotal = 0;
  64034. int level1 = 0, level2 = 0;
  64035. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64036. while (srcNum1 > 0 && srcNum2 > 0)
  64037. {
  64038. int nextX;
  64039. if (x1 < x2)
  64040. {
  64041. nextX = x1;
  64042. level1 = *src1++;
  64043. x1 = *src1++;
  64044. --srcNum1;
  64045. }
  64046. else if (x1 == x2)
  64047. {
  64048. nextX = x1;
  64049. level1 = *src1++;
  64050. level2 = *src2++;
  64051. x1 = *src1++;
  64052. x2 = *src2++;
  64053. --srcNum1;
  64054. --srcNum2;
  64055. }
  64056. else
  64057. {
  64058. nextX = x2;
  64059. level2 = *src2++;
  64060. x2 = *src2++;
  64061. --srcNum2;
  64062. }
  64063. if (nextX > lastX)
  64064. {
  64065. if (nextX >= right)
  64066. break;
  64067. lastX = nextX;
  64068. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64069. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64070. if (nextLevel != lastLevel)
  64071. {
  64072. if (destTotal >= maxEdgesPerLine)
  64073. {
  64074. dest[0] = destTotal;
  64075. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64076. dest = table + lineStrideElements * y;
  64077. }
  64078. ++destTotal;
  64079. lastLevel = nextLevel;
  64080. dest[++destIndex] = nextX;
  64081. dest[++destIndex] = nextLevel;
  64082. }
  64083. }
  64084. }
  64085. if (lastLevel > 0)
  64086. {
  64087. if (destTotal >= maxEdgesPerLine)
  64088. {
  64089. dest[0] = destTotal;
  64090. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64091. dest = table + lineStrideElements * y;
  64092. }
  64093. ++destTotal;
  64094. dest[++destIndex] = right;
  64095. dest[++destIndex] = 0;
  64096. }
  64097. dest[0] = destTotal;
  64098. #if JUCE_DEBUG
  64099. int last = std::numeric_limits<int>::min();
  64100. for (int i = 0; i < dest[0]; ++i)
  64101. {
  64102. jassert (dest[i * 2 + 1] > last);
  64103. last = dest[i * 2 + 1];
  64104. }
  64105. jassert (dest [dest[0] * 2] == 0);
  64106. #endif
  64107. }
  64108. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64109. {
  64110. int* lastItem = dest + (dest[0] * 2 - 1);
  64111. if (x2 < lastItem[0])
  64112. {
  64113. if (x2 <= dest[1])
  64114. {
  64115. dest[0] = 0;
  64116. return;
  64117. }
  64118. while (x2 < lastItem[-2])
  64119. {
  64120. --(dest[0]);
  64121. lastItem -= 2;
  64122. }
  64123. lastItem[0] = x2;
  64124. lastItem[1] = 0;
  64125. }
  64126. if (x1 > dest[1])
  64127. {
  64128. while (lastItem[0] > x1)
  64129. lastItem -= 2;
  64130. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64131. if (itemsRemoved > 0)
  64132. {
  64133. dest[0] -= itemsRemoved;
  64134. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64135. }
  64136. dest[1] = x1;
  64137. }
  64138. }
  64139. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64140. {
  64141. const Rectangle<int> clipped (r.getIntersection (bounds));
  64142. if (clipped.isEmpty())
  64143. {
  64144. needToCheckEmptinesss = false;
  64145. bounds.setHeight (0);
  64146. }
  64147. else
  64148. {
  64149. const int top = clipped.getY() - bounds.getY();
  64150. const int bottom = clipped.getBottom() - bounds.getY();
  64151. if (bottom < bounds.getHeight())
  64152. bounds.setHeight (bottom);
  64153. if (clipped.getRight() < bounds.getRight())
  64154. bounds.setRight (clipped.getRight());
  64155. for (int i = top; --i >= 0;)
  64156. table [lineStrideElements * i] = 0;
  64157. if (clipped.getX() > bounds.getX())
  64158. {
  64159. const int x1 = clipped.getX() << 8;
  64160. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64161. int* line = table + lineStrideElements * top;
  64162. for (int i = bottom - top; --i >= 0;)
  64163. {
  64164. if (line[0] != 0)
  64165. clipEdgeTableLineToRange (line, x1, x2);
  64166. line += lineStrideElements;
  64167. }
  64168. }
  64169. needToCheckEmptinesss = true;
  64170. }
  64171. }
  64172. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64173. {
  64174. const Rectangle<int> clipped (r.getIntersection (bounds));
  64175. if (! clipped.isEmpty())
  64176. {
  64177. const int top = clipped.getY() - bounds.getY();
  64178. const int bottom = clipped.getBottom() - bounds.getY();
  64179. //XXX optimise here by shortening the table if it fills top or bottom
  64180. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64181. clipped.getX() << 8, 0,
  64182. clipped.getRight() << 8, 255,
  64183. std::numeric_limits<int>::max(), 0 };
  64184. for (int i = top; i < bottom; ++i)
  64185. intersectWithEdgeTableLine (i, rectLine);
  64186. needToCheckEmptinesss = true;
  64187. }
  64188. }
  64189. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64190. {
  64191. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64192. if (clipped.isEmpty())
  64193. {
  64194. needToCheckEmptinesss = false;
  64195. bounds.setHeight (0);
  64196. }
  64197. else
  64198. {
  64199. const int top = clipped.getY() - bounds.getY();
  64200. const int bottom = clipped.getBottom() - bounds.getY();
  64201. if (bottom < bounds.getHeight())
  64202. bounds.setHeight (bottom);
  64203. if (clipped.getRight() < bounds.getRight())
  64204. bounds.setRight (clipped.getRight());
  64205. int i = 0;
  64206. for (i = top; --i >= 0;)
  64207. table [lineStrideElements * i] = 0;
  64208. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64209. for (i = top; i < bottom; ++i)
  64210. {
  64211. intersectWithEdgeTableLine (i, otherLine);
  64212. otherLine += other.lineStrideElements;
  64213. }
  64214. needToCheckEmptinesss = true;
  64215. }
  64216. }
  64217. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64218. {
  64219. y -= bounds.getY();
  64220. if (y < 0 || y >= bounds.getHeight())
  64221. return;
  64222. needToCheckEmptinesss = true;
  64223. if (numPixels <= 0)
  64224. {
  64225. table [lineStrideElements * y] = 0;
  64226. return;
  64227. }
  64228. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64229. int destIndex = 0, lastLevel = 0;
  64230. while (--numPixels >= 0)
  64231. {
  64232. const int alpha = *mask;
  64233. mask += maskStride;
  64234. if (alpha != lastLevel)
  64235. {
  64236. tempLine[++destIndex] = (x << 8);
  64237. tempLine[++destIndex] = alpha;
  64238. lastLevel = alpha;
  64239. }
  64240. ++x;
  64241. }
  64242. if (lastLevel > 0)
  64243. {
  64244. tempLine[++destIndex] = (x << 8);
  64245. tempLine[++destIndex] = 0;
  64246. }
  64247. tempLine[0] = destIndex >> 1;
  64248. intersectWithEdgeTableLine (y, tempLine);
  64249. }
  64250. bool EdgeTable::isEmpty() throw()
  64251. {
  64252. if (needToCheckEmptinesss)
  64253. {
  64254. needToCheckEmptinesss = false;
  64255. int* t = table;
  64256. for (int i = bounds.getHeight(); --i >= 0;)
  64257. {
  64258. if (t[0] > 1)
  64259. return false;
  64260. t += lineStrideElements;
  64261. }
  64262. bounds.setHeight (0);
  64263. }
  64264. return bounds.getHeight() == 0;
  64265. }
  64266. END_JUCE_NAMESPACE
  64267. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64268. /*** Start of inlined file: juce_FillType.cpp ***/
  64269. BEGIN_JUCE_NAMESPACE
  64270. FillType::FillType() throw()
  64271. : colour (0xff000000), image (0)
  64272. {
  64273. }
  64274. FillType::FillType (const Colour& colour_) throw()
  64275. : colour (colour_), image (0)
  64276. {
  64277. }
  64278. FillType::FillType (const ColourGradient& gradient_) throw()
  64279. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64280. {
  64281. }
  64282. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64283. : colour (0xff000000), image (&image_), transform (transform_)
  64284. {
  64285. }
  64286. FillType::FillType (const FillType& other) throw()
  64287. : colour (other.colour),
  64288. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64289. image (other.image), transform (other.transform)
  64290. {
  64291. }
  64292. FillType& FillType::operator= (const FillType& other) throw()
  64293. {
  64294. if (this != &other)
  64295. {
  64296. colour = other.colour;
  64297. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64298. image = other.image;
  64299. transform = other.transform;
  64300. }
  64301. return *this;
  64302. }
  64303. FillType::~FillType() throw()
  64304. {
  64305. }
  64306. void FillType::setColour (const Colour& newColour) throw()
  64307. {
  64308. gradient = 0;
  64309. image = 0;
  64310. colour = newColour;
  64311. }
  64312. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64313. {
  64314. if (gradient != 0)
  64315. {
  64316. *gradient = newGradient;
  64317. }
  64318. else
  64319. {
  64320. image = 0;
  64321. gradient = new ColourGradient (newGradient);
  64322. colour = Colours::black;
  64323. }
  64324. }
  64325. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64326. {
  64327. gradient = 0;
  64328. image = &image_;
  64329. transform = transform_;
  64330. colour = Colours::black;
  64331. }
  64332. void FillType::setOpacity (const float newOpacity) throw()
  64333. {
  64334. colour = colour.withAlpha (newOpacity);
  64335. }
  64336. END_JUCE_NAMESPACE
  64337. /*** End of inlined file: juce_FillType.cpp ***/
  64338. /*** Start of inlined file: juce_Graphics.cpp ***/
  64339. BEGIN_JUCE_NAMESPACE
  64340. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64341. template <typename Type>
  64342. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64343. {
  64344. const int maxVal = 0x3fffffff;
  64345. return (int) x >= -maxVal && (int) x <= maxVal
  64346. && (int) y >= -maxVal && (int) y <= maxVal
  64347. && (int) w >= -maxVal && (int) w <= maxVal
  64348. && (int) h >= -maxVal && (int) h <= maxVal;
  64349. }
  64350. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64351. {
  64352. }
  64353. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64354. {
  64355. }
  64356. Graphics::Graphics (Image& imageToDrawOnto)
  64357. : context (imageToDrawOnto.createLowLevelContext()),
  64358. contextToDelete (context),
  64359. saveStatePending (false)
  64360. {
  64361. }
  64362. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64363. : context (internalContext),
  64364. saveStatePending (false)
  64365. {
  64366. }
  64367. Graphics::~Graphics()
  64368. {
  64369. }
  64370. void Graphics::resetToDefaultState()
  64371. {
  64372. saveStateIfPending();
  64373. context->setFill (FillType());
  64374. context->setFont (Font());
  64375. context->setInterpolationQuality (defaultQuality);
  64376. }
  64377. bool Graphics::isVectorDevice() const
  64378. {
  64379. return context->isVectorDevice();
  64380. }
  64381. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  64382. {
  64383. saveStateIfPending();
  64384. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64385. }
  64386. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  64387. {
  64388. saveStateIfPending();
  64389. return context->clipToRectangleList (clipRegion);
  64390. }
  64391. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  64392. {
  64393. saveStateIfPending();
  64394. context->clipToPath (path, transform);
  64395. return ! context->isClipEmpty();
  64396. }
  64397. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform)
  64398. {
  64399. saveStateIfPending();
  64400. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64401. return ! context->isClipEmpty();
  64402. }
  64403. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  64404. {
  64405. saveStateIfPending();
  64406. context->excludeClipRectangle (rectangleToExclude);
  64407. }
  64408. bool Graphics::isClipEmpty() const
  64409. {
  64410. return context->isClipEmpty();
  64411. }
  64412. const Rectangle<int> Graphics::getClipBounds() const
  64413. {
  64414. return context->getClipBounds();
  64415. }
  64416. void Graphics::saveState()
  64417. {
  64418. saveStateIfPending();
  64419. saveStatePending = true;
  64420. }
  64421. void Graphics::restoreState()
  64422. {
  64423. if (saveStatePending)
  64424. saveStatePending = false;
  64425. else
  64426. context->restoreState();
  64427. }
  64428. void Graphics::saveStateIfPending()
  64429. {
  64430. if (saveStatePending)
  64431. {
  64432. saveStatePending = false;
  64433. context->saveState();
  64434. }
  64435. }
  64436. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  64437. {
  64438. saveStateIfPending();
  64439. context->setOrigin (newOriginX, newOriginY);
  64440. }
  64441. bool Graphics::clipRegionIntersects (const int x, const int y, const int w, const int h) const
  64442. {
  64443. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64444. }
  64445. void Graphics::setColour (const Colour& newColour)
  64446. {
  64447. saveStateIfPending();
  64448. context->setFill (newColour);
  64449. }
  64450. void Graphics::setOpacity (const float newOpacity)
  64451. {
  64452. saveStateIfPending();
  64453. context->setOpacity (newOpacity);
  64454. }
  64455. void Graphics::setGradientFill (const ColourGradient& gradient)
  64456. {
  64457. setFillType (gradient);
  64458. }
  64459. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  64460. {
  64461. saveStateIfPending();
  64462. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64463. context->setOpacity (opacity);
  64464. }
  64465. void Graphics::setFillType (const FillType& newFill)
  64466. {
  64467. saveStateIfPending();
  64468. context->setFill (newFill);
  64469. }
  64470. void Graphics::setFont (const Font& newFont)
  64471. {
  64472. saveStateIfPending();
  64473. context->setFont (newFont);
  64474. }
  64475. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  64476. {
  64477. saveStateIfPending();
  64478. Font f (context->getFont());
  64479. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64480. context->setFont (f);
  64481. }
  64482. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const
  64483. {
  64484. if (text.isNotEmpty()
  64485. && startX < context->getClipBounds().getRight())
  64486. {
  64487. GlyphArrangement arr;
  64488. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64489. arr.draw (*this);
  64490. }
  64491. }
  64492. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  64493. {
  64494. if (text.isNotEmpty())
  64495. {
  64496. GlyphArrangement arr;
  64497. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64498. arr.draw (*this, transform);
  64499. }
  64500. }
  64501. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  64502. {
  64503. if (text.isNotEmpty()
  64504. && startX < context->getClipBounds().getRight())
  64505. {
  64506. GlyphArrangement arr;
  64507. arr.addJustifiedText (context->getFont(), text,
  64508. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64509. Justification::left);
  64510. arr.draw (*this);
  64511. }
  64512. }
  64513. void Graphics::drawText (const String& text,
  64514. const int x, const int y, const int width, const int height,
  64515. const Justification& justificationType,
  64516. const bool useEllipsesIfTooBig) const
  64517. {
  64518. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64519. {
  64520. GlyphArrangement arr;
  64521. arr.addCurtailedLineOfText (context->getFont(), text,
  64522. 0.0f, 0.0f, (float) width,
  64523. useEllipsesIfTooBig);
  64524. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64525. (float) x, (float) y, (float) width, (float) height,
  64526. justificationType);
  64527. arr.draw (*this);
  64528. }
  64529. }
  64530. void Graphics::drawFittedText (const String& text,
  64531. const int x, const int y, const int width, const int height,
  64532. const Justification& justification,
  64533. const int maximumNumberOfLines,
  64534. const float minimumHorizontalScale) const
  64535. {
  64536. if (text.isNotEmpty()
  64537. && width > 0 && height > 0
  64538. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64539. {
  64540. GlyphArrangement arr;
  64541. arr.addFittedText (context->getFont(), text,
  64542. (float) x, (float) y, (float) width, (float) height,
  64543. justification,
  64544. maximumNumberOfLines,
  64545. minimumHorizontalScale);
  64546. arr.draw (*this);
  64547. }
  64548. }
  64549. void Graphics::fillRect (int x, int y, int width, int height) const
  64550. {
  64551. // passing in a silly number can cause maths problems in rendering!
  64552. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64553. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64554. }
  64555. void Graphics::fillRect (const Rectangle<int>& r) const
  64556. {
  64557. context->fillRect (r, false);
  64558. }
  64559. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  64560. {
  64561. // passing in a silly number can cause maths problems in rendering!
  64562. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64563. Path p;
  64564. p.addRectangle (x, y, width, height);
  64565. fillPath (p);
  64566. }
  64567. void Graphics::setPixel (int x, int y) const
  64568. {
  64569. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64570. }
  64571. void Graphics::fillAll() const
  64572. {
  64573. fillRect (context->getClipBounds());
  64574. }
  64575. void Graphics::fillAll (const Colour& colourToUse) const
  64576. {
  64577. if (! colourToUse.isTransparent())
  64578. {
  64579. const Rectangle<int> clip (context->getClipBounds());
  64580. context->saveState();
  64581. context->setFill (colourToUse);
  64582. context->fillRect (clip, false);
  64583. context->restoreState();
  64584. }
  64585. }
  64586. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  64587. {
  64588. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64589. context->fillPath (path, transform);
  64590. }
  64591. void Graphics::strokePath (const Path& path,
  64592. const PathStrokeType& strokeType,
  64593. const AffineTransform& transform) const
  64594. {
  64595. Path stroke;
  64596. strokeType.createStrokedPath (stroke, path, transform);
  64597. fillPath (stroke);
  64598. }
  64599. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  64600. const int lineThickness) const
  64601. {
  64602. // passing in a silly number can cause maths problems in rendering!
  64603. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64604. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64605. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64606. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64607. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64608. }
  64609. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  64610. {
  64611. // passing in a silly number can cause maths problems in rendering!
  64612. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64613. Path p;
  64614. p.addRectangle (x, y, width, lineThickness);
  64615. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64616. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64617. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64618. fillPath (p);
  64619. }
  64620. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  64621. {
  64622. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  64623. }
  64624. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  64625. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  64626. const bool useGradient, const bool sharpEdgeOnOutside) const
  64627. {
  64628. // passing in a silly number can cause maths problems in rendering!
  64629. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64630. if (clipRegionIntersects (x, y, width, height))
  64631. {
  64632. context->saveState();
  64633. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64634. const float ramp = oldOpacity / bevelThickness;
  64635. for (int i = bevelThickness; --i >= 0;)
  64636. {
  64637. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64638. : oldOpacity;
  64639. context->setFill (topLeftColour.withMultipliedAlpha (op));
  64640. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64641. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  64642. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64643. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  64644. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64645. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  64646. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64647. }
  64648. context->restoreState();
  64649. }
  64650. }
  64651. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  64652. {
  64653. // passing in a silly number can cause maths problems in rendering!
  64654. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64655. Path p;
  64656. p.addEllipse (x, y, width, height);
  64657. fillPath (p);
  64658. }
  64659. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  64660. const float lineThickness) const
  64661. {
  64662. // passing in a silly number can cause maths problems in rendering!
  64663. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64664. Path p;
  64665. p.addEllipse (x, y, width, height);
  64666. strokePath (p, PathStrokeType (lineThickness));
  64667. }
  64668. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  64669. {
  64670. // passing in a silly number can cause maths problems in rendering!
  64671. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64672. Path p;
  64673. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64674. fillPath (p);
  64675. }
  64676. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  64677. {
  64678. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  64679. }
  64680. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  64681. const float cornerSize, const float lineThickness) const
  64682. {
  64683. // passing in a silly number can cause maths problems in rendering!
  64684. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64685. Path p;
  64686. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64687. strokePath (p, PathStrokeType (lineThickness));
  64688. }
  64689. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  64690. {
  64691. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  64692. }
  64693. void Graphics::drawArrow (const float startX, const float startY, const float endX, const float endY,
  64694. const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  64695. {
  64696. Path p;
  64697. p.addArrow (startX, startY, endX, endY,
  64698. lineThickness, arrowheadWidth, arrowheadLength);
  64699. fillPath (p);
  64700. }
  64701. void Graphics::fillCheckerBoard (int x, int y, int width, int height,
  64702. const int checkWidth, const int checkHeight,
  64703. const Colour& colour1, const Colour& colour2) const
  64704. {
  64705. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64706. if (checkWidth > 0 && checkHeight > 0)
  64707. {
  64708. context->saveState();
  64709. if (colour1 == colour2)
  64710. {
  64711. context->setFill (colour1);
  64712. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64713. }
  64714. else
  64715. {
  64716. const Rectangle<int> clip (context->getClipBounds());
  64717. const int right = jmin (x + width, clip.getRight());
  64718. const int bottom = jmin (y + height, clip.getBottom());
  64719. int cy = 0;
  64720. while (y < bottom)
  64721. {
  64722. int cx = cy;
  64723. for (int xx = x; xx < right; xx += checkWidth)
  64724. {
  64725. context->setFill (((cx++ & 1) == 0) ? colour1 : colour2);
  64726. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64727. false);
  64728. }
  64729. ++cy;
  64730. y += checkHeight;
  64731. }
  64732. }
  64733. context->restoreState();
  64734. }
  64735. }
  64736. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  64737. {
  64738. context->drawVerticalLine (x, top, bottom);
  64739. }
  64740. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  64741. {
  64742. context->drawHorizontalLine (y, left, right);
  64743. }
  64744. void Graphics::drawLine (float x1, float y1, float x2, float y2) const
  64745. {
  64746. context->drawLine (x1, y1, x2, y2);
  64747. }
  64748. void Graphics::drawLine (const float startX, const float startY,
  64749. const float endX, const float endY,
  64750. const float lineThickness) const
  64751. {
  64752. Path p;
  64753. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64754. fillPath (p);
  64755. }
  64756. void Graphics::drawLine (const Line& line) const
  64757. {
  64758. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64759. }
  64760. void Graphics::drawLine (const Line& line, const float lineThickness) const
  64761. {
  64762. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64763. }
  64764. void Graphics::drawDashedLine (const float startX, const float startY,
  64765. const float endX, const float endY,
  64766. const float* const dashLengths,
  64767. const int numDashLengths,
  64768. const float lineThickness) const
  64769. {
  64770. const double dx = endX - startX;
  64771. const double dy = endY - startY;
  64772. const double totalLen = juce_hypot (dx, dy);
  64773. if (totalLen >= 0.5)
  64774. {
  64775. const double onePixAlpha = 1.0 / totalLen;
  64776. double alpha = 0.0;
  64777. float x = startX;
  64778. float y = startY;
  64779. int n = 0;
  64780. while (alpha < 1.0f)
  64781. {
  64782. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64783. n = n % numDashLengths;
  64784. const float oldX = x;
  64785. const float oldY = y;
  64786. x = (float) (startX + dx * alpha);
  64787. y = (float) (startY + dy * alpha);
  64788. if ((n & 1) != 0)
  64789. {
  64790. if (lineThickness != 1.0f)
  64791. drawLine (oldX, oldY, x, y, lineThickness);
  64792. else
  64793. drawLine (oldX, oldY, x, y);
  64794. }
  64795. }
  64796. }
  64797. }
  64798. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  64799. {
  64800. saveStateIfPending();
  64801. context->setInterpolationQuality (newQuality);
  64802. }
  64803. void Graphics::drawImageAt (const Image* const imageToDraw,
  64804. const int topLeftX, const int topLeftY,
  64805. const bool fillAlphaChannelWithCurrentBrush) const
  64806. {
  64807. if (imageToDraw != 0)
  64808. {
  64809. const int imageW = imageToDraw->getWidth();
  64810. const int imageH = imageToDraw->getHeight();
  64811. drawImage (imageToDraw,
  64812. topLeftX, topLeftY, imageW, imageH,
  64813. 0, 0, imageW, imageH,
  64814. fillAlphaChannelWithCurrentBrush);
  64815. }
  64816. }
  64817. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64818. const int destX, const int destY,
  64819. const int destW, const int destH,
  64820. const RectanglePlacement& placementWithinTarget,
  64821. const bool fillAlphaChannelWithCurrentBrush) const
  64822. {
  64823. // passing in a silly number can cause maths problems in rendering!
  64824. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64825. if (imageToDraw != 0)
  64826. {
  64827. const int imageW = imageToDraw->getWidth();
  64828. const int imageH = imageToDraw->getHeight();
  64829. if (imageW > 0 && imageH > 0)
  64830. {
  64831. double newX = 0.0, newY = 0.0;
  64832. double newW = imageW;
  64833. double newH = imageH;
  64834. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64835. destX, destY, destW, destH);
  64836. if (newW > 0 && newH > 0)
  64837. {
  64838. drawImage (imageToDraw,
  64839. roundToInt (newX), roundToInt (newY),
  64840. roundToInt (newW), roundToInt (newH),
  64841. 0, 0, imageW, imageH,
  64842. fillAlphaChannelWithCurrentBrush);
  64843. }
  64844. }
  64845. }
  64846. }
  64847. void Graphics::drawImage (const Image* const imageToDraw,
  64848. int dx, int dy, int dw, int dh,
  64849. int sx, int sy, int sw, int sh,
  64850. const bool fillAlphaChannelWithCurrentBrush) const
  64851. {
  64852. // passing in a silly number can cause maths problems in rendering!
  64853. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64854. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64855. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64856. {
  64857. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64858. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64859. .translated ((float) dx, (float) dy),
  64860. fillAlphaChannelWithCurrentBrush);
  64861. }
  64862. }
  64863. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64864. const Rectangle<int>& imageSubRegion,
  64865. const AffineTransform& transform,
  64866. const bool fillAlphaChannelWithCurrentBrush) const
  64867. {
  64868. if (imageToDraw != 0 && ! context->isClipEmpty())
  64869. {
  64870. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64871. if (fillAlphaChannelWithCurrentBrush)
  64872. {
  64873. context->saveState();
  64874. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64875. fillAll();
  64876. context->restoreState();
  64877. }
  64878. else
  64879. {
  64880. context->drawImage (*imageToDraw, srcClip, transform, false);
  64881. }
  64882. }
  64883. }
  64884. END_JUCE_NAMESPACE
  64885. /*** End of inlined file: juce_Graphics.cpp ***/
  64886. /*** Start of inlined file: juce_Justification.cpp ***/
  64887. BEGIN_JUCE_NAMESPACE
  64888. Justification::Justification (const Justification& other) throw()
  64889. : flags (other.flags)
  64890. {
  64891. }
  64892. Justification& Justification::operator= (const Justification& other) throw()
  64893. {
  64894. flags = other.flags;
  64895. return *this;
  64896. }
  64897. int Justification::getOnlyVerticalFlags() const throw()
  64898. {
  64899. return flags & (top | bottom | verticallyCentred);
  64900. }
  64901. int Justification::getOnlyHorizontalFlags() const throw()
  64902. {
  64903. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64904. }
  64905. void Justification::applyToRectangle (int& x, int& y,
  64906. const int w, const int h,
  64907. const int spaceX, const int spaceY,
  64908. const int spaceW, const int spaceH) const throw()
  64909. {
  64910. if ((flags & horizontallyCentred) != 0)
  64911. {
  64912. x = spaceX + ((spaceW - w) >> 1);
  64913. }
  64914. else if ((flags & right) != 0)
  64915. {
  64916. x = spaceX + spaceW - w;
  64917. }
  64918. else
  64919. {
  64920. x = spaceX;
  64921. }
  64922. if ((flags & verticallyCentred) != 0)
  64923. {
  64924. y = spaceY + ((spaceH - h) >> 1);
  64925. }
  64926. else if ((flags & bottom) != 0)
  64927. {
  64928. y = spaceY + spaceH - h;
  64929. }
  64930. else
  64931. {
  64932. y = spaceY;
  64933. }
  64934. }
  64935. END_JUCE_NAMESPACE
  64936. /*** End of inlined file: juce_Justification.cpp ***/
  64937. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  64938. BEGIN_JUCE_NAMESPACE
  64939. // this will throw an assertion if you try to draw something that's not
  64940. // possible in postscript
  64941. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  64942. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  64943. #define notPossibleInPostscriptAssert jassertfalse
  64944. #else
  64945. #define notPossibleInPostscriptAssert
  64946. #endif
  64947. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  64948. const String& documentTitle,
  64949. const int totalWidth_,
  64950. const int totalHeight_)
  64951. : out (resultingPostScript),
  64952. totalWidth (totalWidth_),
  64953. totalHeight (totalHeight_),
  64954. needToClip (true)
  64955. {
  64956. stateStack.add (new SavedState());
  64957. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  64958. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  64959. out << "%!PS-Adobe-3.0 EPSF-3.0"
  64960. "\n%%BoundingBox: 0 0 600 824"
  64961. "\n%%Pages: 0"
  64962. "\n%%Creator: Raw Material Software JUCE"
  64963. "\n%%Title: " << documentTitle <<
  64964. "\n%%CreationDate: none"
  64965. "\n%%LanguageLevel: 2"
  64966. "\n%%EndComments"
  64967. "\n%%BeginProlog"
  64968. "\n%%BeginResource: JRes"
  64969. "\n/bd {bind def} bind def"
  64970. "\n/c {setrgbcolor} bd"
  64971. "\n/m {moveto} bd"
  64972. "\n/l {lineto} bd"
  64973. "\n/rl {rlineto} bd"
  64974. "\n/ct {curveto} bd"
  64975. "\n/cp {closepath} bd"
  64976. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  64977. "\n/doclip {initclip newpath} bd"
  64978. "\n/endclip {clip newpath} bd"
  64979. "\n%%EndResource"
  64980. "\n%%EndProlog"
  64981. "\n%%BeginSetup"
  64982. "\n%%EndSetup"
  64983. "\n%%Page: 1 1"
  64984. "\n%%BeginPageSetup"
  64985. "\n%%EndPageSetup\n\n"
  64986. << "40 800 translate\n"
  64987. << scale << ' ' << scale << " scale\n\n";
  64988. }
  64989. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  64990. {
  64991. }
  64992. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  64993. {
  64994. return true;
  64995. }
  64996. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  64997. {
  64998. if (x != 0 || y != 0)
  64999. {
  65000. stateStack.getLast()->xOffset += x;
  65001. stateStack.getLast()->yOffset += y;
  65002. needToClip = true;
  65003. }
  65004. }
  65005. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65006. {
  65007. needToClip = true;
  65008. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65009. }
  65010. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65011. {
  65012. needToClip = true;
  65013. return stateStack.getLast()->clip.clipTo (clipRegion);
  65014. }
  65015. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65016. {
  65017. needToClip = true;
  65018. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65019. }
  65020. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65021. {
  65022. writeClip();
  65023. Path p (path);
  65024. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65025. writePath (p);
  65026. out << "clip\n";
  65027. }
  65028. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65029. {
  65030. needToClip = true;
  65031. jassertfalse // xxx
  65032. }
  65033. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65034. {
  65035. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65036. }
  65037. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65038. {
  65039. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65040. -stateStack.getLast()->yOffset);
  65041. }
  65042. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65043. {
  65044. return stateStack.getLast()->clip.isEmpty();
  65045. }
  65046. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65047. : xOffset (0),
  65048. yOffset (0)
  65049. {
  65050. }
  65051. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65052. {
  65053. }
  65054. void LowLevelGraphicsPostScriptRenderer::saveState()
  65055. {
  65056. stateStack.add (new SavedState (*stateStack.getLast()));
  65057. }
  65058. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65059. {
  65060. jassert (stateStack.size() > 0);
  65061. if (stateStack.size() > 0)
  65062. stateStack.removeLast();
  65063. }
  65064. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65065. {
  65066. if (needToClip)
  65067. {
  65068. needToClip = false;
  65069. out << "doclip ";
  65070. int itemsOnLine = 0;
  65071. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65072. {
  65073. if (++itemsOnLine == 6)
  65074. {
  65075. itemsOnLine = 0;
  65076. out << '\n';
  65077. }
  65078. const Rectangle<int>& r = *i.getRectangle();
  65079. out << r.getX() << ' ' << -r.getY() << ' '
  65080. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65081. }
  65082. out << "endclip\n";
  65083. }
  65084. }
  65085. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65086. {
  65087. Colour c (Colours::white.overlaidWith (colour));
  65088. if (lastColour != c)
  65089. {
  65090. lastColour = c;
  65091. out << String (c.getFloatRed(), 3) << ' '
  65092. << String (c.getFloatGreen(), 3) << ' '
  65093. << String (c.getFloatBlue(), 3) << " c\n";
  65094. }
  65095. }
  65096. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65097. {
  65098. out << String (x, 2) << ' '
  65099. << String (-y, 2) << ' ';
  65100. }
  65101. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65102. {
  65103. out << "newpath ";
  65104. float lastX = 0.0f;
  65105. float lastY = 0.0f;
  65106. int itemsOnLine = 0;
  65107. Path::Iterator i (path);
  65108. while (i.next())
  65109. {
  65110. if (++itemsOnLine == 4)
  65111. {
  65112. itemsOnLine = 0;
  65113. out << '\n';
  65114. }
  65115. switch (i.elementType)
  65116. {
  65117. case Path::Iterator::startNewSubPath:
  65118. writeXY (i.x1, i.y1);
  65119. lastX = i.x1;
  65120. lastY = i.y1;
  65121. out << "m ";
  65122. break;
  65123. case Path::Iterator::lineTo:
  65124. writeXY (i.x1, i.y1);
  65125. lastX = i.x1;
  65126. lastY = i.y1;
  65127. out << "l ";
  65128. break;
  65129. case Path::Iterator::quadraticTo:
  65130. {
  65131. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65132. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65133. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65134. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65135. writeXY (cp1x, cp1y);
  65136. writeXY (cp2x, cp2y);
  65137. writeXY (i.x2, i.y2);
  65138. out << "ct ";
  65139. lastX = i.x2;
  65140. lastY = i.y2;
  65141. }
  65142. break;
  65143. case Path::Iterator::cubicTo:
  65144. writeXY (i.x1, i.y1);
  65145. writeXY (i.x2, i.y2);
  65146. writeXY (i.x3, i.y3);
  65147. out << "ct ";
  65148. lastX = i.x3;
  65149. lastY = i.y3;
  65150. break;
  65151. case Path::Iterator::closePath:
  65152. out << "cp ";
  65153. break;
  65154. default:
  65155. jassertfalse
  65156. break;
  65157. }
  65158. }
  65159. out << '\n';
  65160. }
  65161. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65162. {
  65163. out << "[ "
  65164. << trans.mat00 << ' '
  65165. << trans.mat10 << ' '
  65166. << trans.mat01 << ' '
  65167. << trans.mat11 << ' '
  65168. << trans.mat02 << ' '
  65169. << trans.mat12 << " ] concat ";
  65170. }
  65171. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65172. {
  65173. stateStack.getLast()->fillType = fillType;
  65174. }
  65175. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65176. {
  65177. }
  65178. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65179. {
  65180. }
  65181. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65182. {
  65183. if (stateStack.getLast()->fillType.isColour())
  65184. {
  65185. writeClip();
  65186. writeColour (stateStack.getLast()->fillType.colour);
  65187. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65188. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65189. }
  65190. else
  65191. {
  65192. Path p;
  65193. p.addRectangle (r);
  65194. fillPath (p, AffineTransform::identity);
  65195. }
  65196. }
  65197. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65198. {
  65199. if (stateStack.getLast()->fillType.isColour())
  65200. {
  65201. writeClip();
  65202. Path p (path);
  65203. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65204. (float) stateStack.getLast()->yOffset));
  65205. writePath (p);
  65206. writeColour (stateStack.getLast()->fillType.colour);
  65207. out << "fill\n";
  65208. }
  65209. else if (stateStack.getLast()->fillType.isGradient())
  65210. {
  65211. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65212. // postscript can't do semi-transparent ones.
  65213. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65214. writeClip();
  65215. out << "gsave ";
  65216. {
  65217. Path p (path);
  65218. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65219. writePath (p);
  65220. out << "clip\n";
  65221. }
  65222. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65223. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65224. // time-being, this just fills it with the average colour..
  65225. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65226. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65227. out << "grestore\n";
  65228. }
  65229. }
  65230. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65231. const int sx, const int sy,
  65232. const int maxW, const int maxH) const
  65233. {
  65234. out << "{<\n";
  65235. const int w = jmin (maxW, im.getWidth());
  65236. const int h = jmin (maxH, im.getHeight());
  65237. int charsOnLine = 0;
  65238. const Image::BitmapData srcData (im, 0, 0, w, h);
  65239. Colour pixel;
  65240. for (int y = h; --y >= 0;)
  65241. {
  65242. for (int x = 0; x < w; ++x)
  65243. {
  65244. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65245. if (x >= sx && y >= sy)
  65246. {
  65247. if (im.isARGB())
  65248. {
  65249. PixelARGB p (*(const PixelARGB*) pixelData);
  65250. p.unpremultiply();
  65251. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65252. }
  65253. else if (im.isRGB())
  65254. {
  65255. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65256. }
  65257. else
  65258. {
  65259. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65260. }
  65261. }
  65262. else
  65263. {
  65264. pixel = Colours::transparentWhite;
  65265. }
  65266. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65267. out << String::toHexString (pixelValues, 3, 0);
  65268. charsOnLine += 3;
  65269. if (charsOnLine > 100)
  65270. {
  65271. out << '\n';
  65272. charsOnLine = 0;
  65273. }
  65274. }
  65275. }
  65276. out << "\n>}\n";
  65277. }
  65278. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65279. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65280. {
  65281. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65282. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65283. writeClip();
  65284. out << "gsave ";
  65285. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65286. .scaled (1.0f, -1.0f));
  65287. RectangleList imageClip;
  65288. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65289. imageClip.clipTo (srcClip);
  65290. out << "newpath ";
  65291. int itemsOnLine = 0;
  65292. for (RectangleList::Iterator i (imageClip); i.next();)
  65293. {
  65294. if (++itemsOnLine == 6)
  65295. {
  65296. out << '\n';
  65297. itemsOnLine = 0;
  65298. }
  65299. const Rectangle<int>& r = *i.getRectangle();
  65300. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65301. }
  65302. out << " clip newpath\n";
  65303. out << w << ' ' << h << " scale\n";
  65304. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65305. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65306. out << "false 3 colorimage grestore\n";
  65307. needToClip = true;
  65308. }
  65309. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65310. {
  65311. Path p;
  65312. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65313. fillPath (p, AffineTransform::identity);
  65314. }
  65315. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65316. {
  65317. drawLine (x, top, x, bottom);
  65318. }
  65319. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65320. {
  65321. drawLine (left, y, right, y);
  65322. }
  65323. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65324. {
  65325. stateStack.getLast()->font = newFont;
  65326. }
  65327. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65328. {
  65329. return stateStack.getLast()->font;
  65330. }
  65331. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65332. {
  65333. Path p;
  65334. Font& font = stateStack.getLast()->font;
  65335. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65336. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65337. }
  65338. END_JUCE_NAMESPACE
  65339. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65340. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65341. BEGIN_JUCE_NAMESPACE
  65342. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65343. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65344. #endif
  65345. #if JUCE_MSVC
  65346. #if JUCE_DEBUG
  65347. #pragma optimize ("t", on) // optimise just this file, to avoid sluggish graphics when debugging
  65348. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65349. #endif
  65350. #pragma warning (push)
  65351. #pragma warning (disable: 4127) // "expression is constant" warning
  65352. #endif
  65353. template <class PixelType, bool replaceExisting = false>
  65354. class SolidColourEdgeTableRenderer
  65355. {
  65356. public:
  65357. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65358. : data (data_),
  65359. sourceColour (colour)
  65360. {
  65361. if (sizeof (PixelType) == 3)
  65362. {
  65363. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65364. && sourceColour.getGreen() == sourceColour.getBlue();
  65365. filler[0].set (sourceColour);
  65366. filler[1].set (sourceColour);
  65367. filler[2].set (sourceColour);
  65368. filler[3].set (sourceColour);
  65369. }
  65370. }
  65371. forcedinline void setEdgeTableYPos (const int y) throw()
  65372. {
  65373. linePixels = (PixelType*) data.getLinePointer (y);
  65374. }
  65375. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65376. {
  65377. if (replaceExisting)
  65378. linePixels[x].set (sourceColour);
  65379. else
  65380. linePixels[x].blend (sourceColour, alphaLevel);
  65381. }
  65382. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65383. {
  65384. PixelARGB p (sourceColour);
  65385. p.multiplyAlpha (alphaLevel);
  65386. PixelType* dest = linePixels + x;
  65387. if (replaceExisting || p.getAlpha() >= 0xff)
  65388. replaceLine (dest, p, width);
  65389. else
  65390. blendLine (dest, p, width);
  65391. }
  65392. private:
  65393. const Image::BitmapData& data;
  65394. PixelType* linePixels;
  65395. PixelARGB sourceColour;
  65396. PixelRGB filler [4];
  65397. bool areRGBComponentsEqual;
  65398. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65399. {
  65400. do
  65401. {
  65402. dest->blend (colour);
  65403. ++dest;
  65404. } while (--width > 0);
  65405. }
  65406. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65407. {
  65408. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65409. {
  65410. memset (dest, colour.getRed(), width * 3);
  65411. }
  65412. else
  65413. {
  65414. if (width >> 5)
  65415. {
  65416. const int* const intFiller = (const int*) filler;
  65417. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65418. {
  65419. dest->set (colour);
  65420. ++dest;
  65421. --width;
  65422. }
  65423. while (width > 4)
  65424. {
  65425. ((int*) dest) [0] = intFiller[0];
  65426. ((int*) dest) [1] = intFiller[1];
  65427. ((int*) dest) [2] = intFiller[2];
  65428. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65429. width -= 4;
  65430. }
  65431. }
  65432. while (--width >= 0)
  65433. {
  65434. dest->set (colour);
  65435. ++dest;
  65436. }
  65437. }
  65438. }
  65439. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65440. {
  65441. memset (dest, colour.getAlpha(), width);
  65442. }
  65443. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65444. {
  65445. do
  65446. {
  65447. dest->set (colour);
  65448. ++dest;
  65449. } while (--width > 0);
  65450. }
  65451. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65452. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65453. };
  65454. class LinearGradientPixelGenerator
  65455. {
  65456. public:
  65457. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65458. : lookupTable (lookupTable_), numEntries (numEntries_)
  65459. {
  65460. jassert (numEntries_ >= 0);
  65461. float x1 = gradient.x1;
  65462. float y1 = gradient.y1;
  65463. float x2 = gradient.x2;
  65464. float y2 = gradient.y2;
  65465. if (! transform.isIdentity())
  65466. {
  65467. const Line l (x2, y2, x1, y1);
  65468. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65469. float x3 = p3.getX();
  65470. float y3 = p3.getY();
  65471. transform.transformPoint (x1, y1);
  65472. transform.transformPoint (x2, y2);
  65473. transform.transformPoint (x3, y3);
  65474. const Line l2 (x2, y2, x3, y3);
  65475. const float prop = l2.findNearestPointTo (x1, y1);
  65476. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65477. x2 = newP2.getX();
  65478. y2 = newP2.getY();
  65479. }
  65480. vertical = fabs (x1 - x2) < 0.001f;
  65481. horizontal = fabs (y1 - y2) < 0.001f;
  65482. if (vertical)
  65483. {
  65484. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65485. start = roundToInt (y1 * scale);
  65486. }
  65487. else if (horizontal)
  65488. {
  65489. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65490. start = roundToInt (x1 * scale);
  65491. }
  65492. else
  65493. {
  65494. grad = (y2 - y1) / (double) (x1 - x2);
  65495. yTerm = y1 - x1 / grad;
  65496. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65497. grad *= scale;
  65498. }
  65499. }
  65500. forcedinline void setY (const int y) throw()
  65501. {
  65502. if (vertical)
  65503. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65504. else if (! horizontal)
  65505. start = roundToInt ((y - yTerm) * grad);
  65506. }
  65507. inline const PixelARGB getPixel (const int x) const throw()
  65508. {
  65509. return vertical ? linePix
  65510. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65511. }
  65512. private:
  65513. const PixelARGB* const lookupTable;
  65514. const int numEntries;
  65515. PixelARGB linePix;
  65516. int start, scale;
  65517. double grad, yTerm;
  65518. bool vertical, horizontal;
  65519. enum { numScaleBits = 12 };
  65520. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65521. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65522. };
  65523. class RadialGradientPixelGenerator
  65524. {
  65525. public:
  65526. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65527. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65528. : lookupTable (lookupTable_),
  65529. numEntries (numEntries_),
  65530. gx1 (gradient.x1),
  65531. gy1 (gradient.y1)
  65532. {
  65533. jassert (numEntries_ >= 0);
  65534. const float gdx = gradient.x1 - gradient.x2;
  65535. const float gdy = gradient.y1 - gradient.y2;
  65536. maxDist = gdx * gdx + gdy * gdy;
  65537. invScale = numEntries / sqrt (maxDist);
  65538. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65539. }
  65540. forcedinline void setY (const int y) throw()
  65541. {
  65542. dy = y - gy1;
  65543. dy *= dy;
  65544. }
  65545. inline const PixelARGB getPixel (const int px) const throw()
  65546. {
  65547. double x = px - gx1;
  65548. x *= x;
  65549. x += dy;
  65550. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65551. }
  65552. protected:
  65553. const PixelARGB* const lookupTable;
  65554. const int numEntries;
  65555. const double gx1, gy1;
  65556. double maxDist, invScale, dy;
  65557. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65558. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65559. };
  65560. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65561. {
  65562. public:
  65563. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65564. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65565. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65566. inverseTransform (transform.inverted())
  65567. {
  65568. tM10 = inverseTransform.mat10;
  65569. tM00 = inverseTransform.mat00;
  65570. }
  65571. forcedinline void setY (const int y) throw()
  65572. {
  65573. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65574. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65575. }
  65576. inline const PixelARGB getPixel (const int px) const throw()
  65577. {
  65578. double x = px;
  65579. const double y = tM10 * x + lineYM11;
  65580. x = tM00 * x + lineYM01;
  65581. x *= x;
  65582. x += y * y;
  65583. if (x >= maxDist)
  65584. return lookupTable [numEntries];
  65585. else
  65586. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65587. }
  65588. private:
  65589. double tM10, tM00, lineYM01, lineYM11;
  65590. const AffineTransform inverseTransform;
  65591. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65592. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65593. };
  65594. template <class PixelType, class GradientType>
  65595. class GradientEdgeTableRenderer : public GradientType
  65596. {
  65597. public:
  65598. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65599. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65600. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65601. destData (destData_)
  65602. {
  65603. }
  65604. forcedinline void setEdgeTableYPos (const int y) throw()
  65605. {
  65606. linePixels = (PixelType*) destData.getLinePointer (y);
  65607. GradientType::setY (y);
  65608. }
  65609. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65610. {
  65611. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65612. }
  65613. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65614. {
  65615. PixelType* dest = linePixels + x;
  65616. if (alphaLevel < 0xff)
  65617. {
  65618. do
  65619. {
  65620. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65621. } while (--width > 0);
  65622. }
  65623. else
  65624. {
  65625. do
  65626. {
  65627. (dest++)->blend (GradientType::getPixel (x++));
  65628. } while (--width > 0);
  65629. }
  65630. }
  65631. private:
  65632. const Image::BitmapData& destData;
  65633. PixelType* linePixels;
  65634. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65635. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65636. };
  65637. static forcedinline int safeModulo (int n, const int divisor) throw()
  65638. {
  65639. jassert (divisor > 0);
  65640. n %= divisor;
  65641. return (n < 0) ? (n + divisor) : n;
  65642. }
  65643. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65644. class ImageFillEdgeTableRenderer
  65645. {
  65646. public:
  65647. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65648. const Image::BitmapData& srcData_,
  65649. const int extraAlpha_,
  65650. const int x, const int y) throw()
  65651. : destData (destData_),
  65652. srcData (srcData_),
  65653. extraAlpha (extraAlpha_ + 1),
  65654. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65655. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65656. {
  65657. }
  65658. forcedinline void setEdgeTableYPos (int y) throw()
  65659. {
  65660. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65661. y -= yOffset;
  65662. if (repeatPattern)
  65663. {
  65664. jassert (y >= 0);
  65665. y %= srcData.height;
  65666. }
  65667. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65668. }
  65669. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65670. {
  65671. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65672. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65673. }
  65674. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65675. {
  65676. DestPixelType* dest = linePixels + x;
  65677. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65678. x -= xOffset;
  65679. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65680. if (alphaLevel < 0xfe)
  65681. {
  65682. do
  65683. {
  65684. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65685. } while (--width > 0);
  65686. }
  65687. else
  65688. {
  65689. if (repeatPattern)
  65690. {
  65691. do
  65692. {
  65693. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65694. } while (--width > 0);
  65695. }
  65696. else
  65697. {
  65698. copyRow (dest, sourceLineStart + x, width);
  65699. }
  65700. }
  65701. }
  65702. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65703. {
  65704. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65705. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65706. uint8* mask = (uint8*) (s + x - xOffset);
  65707. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65708. mask += PixelARGB::indexA;
  65709. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65710. }
  65711. private:
  65712. const Image::BitmapData& destData;
  65713. const Image::BitmapData& srcData;
  65714. const int extraAlpha, xOffset, yOffset;
  65715. DestPixelType* linePixels;
  65716. SrcPixelType* sourceLineStart;
  65717. template <class PixelType1, class PixelType2>
  65718. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65719. {
  65720. do
  65721. {
  65722. dest++ ->blend (*src++);
  65723. } while (--width > 0);
  65724. }
  65725. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65726. {
  65727. memcpy (dest, src, width * sizeof (PixelRGB));
  65728. }
  65729. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65730. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65731. };
  65732. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65733. class TransformedImageFillEdgeTableRenderer
  65734. {
  65735. public:
  65736. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65737. const Image::BitmapData& srcData_,
  65738. const AffineTransform& transform,
  65739. const int extraAlpha_,
  65740. const bool betterQuality_) throw()
  65741. : interpolator (transform),
  65742. destData (destData_),
  65743. srcData (srcData_),
  65744. extraAlpha (extraAlpha_ + 1),
  65745. betterQuality (betterQuality_),
  65746. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65747. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65748. maxX (srcData_.width - 1),
  65749. maxY (srcData_.height - 1),
  65750. scratchSize (2048)
  65751. {
  65752. scratchBuffer.malloc (scratchSize);
  65753. }
  65754. ~TransformedImageFillEdgeTableRenderer() throw()
  65755. {
  65756. }
  65757. forcedinline void setEdgeTableYPos (const int newY) throw()
  65758. {
  65759. y = newY;
  65760. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65761. }
  65762. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65763. {
  65764. alphaLevel *= extraAlpha;
  65765. alphaLevel >>= 8;
  65766. SrcPixelType p;
  65767. generate (&p, x, 1);
  65768. linePixels[x].blend (p, alphaLevel);
  65769. }
  65770. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65771. {
  65772. if (width > scratchSize)
  65773. {
  65774. scratchSize = width;
  65775. scratchBuffer.malloc (scratchSize);
  65776. }
  65777. SrcPixelType* span = scratchBuffer;
  65778. generate (span, x, width);
  65779. DestPixelType* dest = linePixels + x;
  65780. alphaLevel *= extraAlpha;
  65781. alphaLevel >>= 8;
  65782. if (alphaLevel < 0xfe)
  65783. {
  65784. do
  65785. {
  65786. dest++ ->blend (*span++, alphaLevel);
  65787. } while (--width > 0);
  65788. }
  65789. else
  65790. {
  65791. do
  65792. {
  65793. dest++ ->blend (*span++);
  65794. } while (--width > 0);
  65795. }
  65796. }
  65797. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65798. {
  65799. if (width > scratchSize)
  65800. {
  65801. scratchSize = width;
  65802. scratchBuffer.malloc (scratchSize);
  65803. }
  65804. y = y_;
  65805. generate (scratchBuffer, x, width);
  65806. et.clipLineToMask (x, y_,
  65807. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65808. sizeof (SrcPixelType), width);
  65809. }
  65810. private:
  65811. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65812. {
  65813. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65814. do
  65815. {
  65816. int hiResX, hiResY;
  65817. this->interpolator.next (hiResX, hiResY);
  65818. hiResX += pixelOffsetInt;
  65819. hiResY += pixelOffsetInt;
  65820. int loResX = hiResX >> 8;
  65821. int loResY = hiResY >> 8;
  65822. if (repeatPattern)
  65823. {
  65824. loResX = safeModulo (loResX, srcData.width);
  65825. loResY = safeModulo (loResY, srcData.height);
  65826. }
  65827. if (betterQuality
  65828. && ((unsigned int) loResX) < (unsigned int) maxX
  65829. && ((unsigned int) loResY) < (unsigned int) maxY)
  65830. {
  65831. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65832. hiResX &= 255;
  65833. hiResY &= 255;
  65834. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65835. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65836. c[0] += weight * src[0];
  65837. c[1] += weight * src[1];
  65838. c[2] += weight * src[2];
  65839. c[3] += weight * src[3];
  65840. weight = hiResX * (256 - hiResY);
  65841. c[0] += weight * src[4];
  65842. c[1] += weight * src[5];
  65843. c[2] += weight * src[6];
  65844. c[3] += weight * src[7];
  65845. src += this->srcData.lineStride;
  65846. weight = (256 - hiResX) * hiResY;
  65847. c[0] += weight * src[0];
  65848. c[1] += weight * src[1];
  65849. c[2] += weight * src[2];
  65850. c[3] += weight * src[3];
  65851. weight = hiResX * hiResY;
  65852. c[0] += weight * src[4];
  65853. c[1] += weight * src[5];
  65854. c[2] += weight * src[6];
  65855. c[3] += weight * src[7];
  65856. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65857. (uint8) (c[PixelARGB::indexR] >> 16),
  65858. (uint8) (c[PixelARGB::indexG] >> 16),
  65859. (uint8) (c[PixelARGB::indexB] >> 16));
  65860. }
  65861. else
  65862. {
  65863. if (! repeatPattern)
  65864. {
  65865. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65866. if (loResX < 0) loResX = 0;
  65867. if (loResY < 0) loResY = 0;
  65868. if (loResX > maxX) loResX = maxX;
  65869. if (loResY > maxY) loResY = maxY;
  65870. }
  65871. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65872. }
  65873. ++dest;
  65874. } while (--numPixels > 0);
  65875. }
  65876. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65877. {
  65878. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65879. do
  65880. {
  65881. int hiResX, hiResY;
  65882. this->interpolator.next (hiResX, hiResY);
  65883. hiResX += pixelOffsetInt;
  65884. hiResY += pixelOffsetInt;
  65885. int loResX = hiResX >> 8;
  65886. int loResY = hiResY >> 8;
  65887. if (repeatPattern)
  65888. {
  65889. loResX = safeModulo (loResX, srcData.width);
  65890. loResY = safeModulo (loResY, srcData.height);
  65891. }
  65892. if (betterQuality
  65893. && ((unsigned int) loResX) < (unsigned int) maxX
  65894. && ((unsigned int) loResY) < (unsigned int) maxY)
  65895. {
  65896. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65897. hiResX &= 255;
  65898. hiResY &= 255;
  65899. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65900. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65901. c[0] += weight * src[0];
  65902. c[1] += weight * src[1];
  65903. c[2] += weight * src[2];
  65904. weight = hiResX * (256 - hiResY);
  65905. c[0] += weight * src[3];
  65906. c[1] += weight * src[4];
  65907. c[2] += weight * src[5];
  65908. src += this->srcData.lineStride;
  65909. weight = (256 - hiResX) * hiResY;
  65910. c[0] += weight * src[0];
  65911. c[1] += weight * src[1];
  65912. c[2] += weight * src[2];
  65913. weight = hiResX * hiResY;
  65914. c[0] += weight * src[3];
  65915. c[1] += weight * src[4];
  65916. c[2] += weight * src[5];
  65917. dest->setARGB ((uint8) 255,
  65918. (uint8) (c[PixelRGB::indexR] >> 16),
  65919. (uint8) (c[PixelRGB::indexG] >> 16),
  65920. (uint8) (c[PixelRGB::indexB] >> 16));
  65921. }
  65922. else
  65923. {
  65924. if (! repeatPattern)
  65925. {
  65926. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65927. if (loResX < 0) loResX = 0;
  65928. if (loResY < 0) loResY = 0;
  65929. if (loResX > maxX) loResX = maxX;
  65930. if (loResY > maxY) loResY = maxY;
  65931. }
  65932. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  65933. }
  65934. ++dest;
  65935. } while (--numPixels > 0);
  65936. }
  65937. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  65938. {
  65939. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65940. do
  65941. {
  65942. int hiResX, hiResY;
  65943. this->interpolator.next (hiResX, hiResY);
  65944. hiResX += pixelOffsetInt;
  65945. hiResY += pixelOffsetInt;
  65946. int loResX = hiResX >> 8;
  65947. int loResY = hiResY >> 8;
  65948. if (repeatPattern)
  65949. {
  65950. loResX = safeModulo (loResX, srcData.width);
  65951. loResY = safeModulo (loResY, srcData.height);
  65952. }
  65953. if (betterQuality
  65954. && ((unsigned int) loResX) < (unsigned int) maxX
  65955. && ((unsigned int) loResY) < (unsigned int) maxY)
  65956. {
  65957. hiResX &= 255;
  65958. hiResY &= 255;
  65959. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65960. uint32 c = 256 * 128;
  65961. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  65962. c += src[1] * (hiResX * (256 - hiResY));
  65963. src += this->srcData.lineStride;
  65964. c += src[0] * ((256 - hiResX) * hiResY);
  65965. c += src[1] * (hiResX * hiResY);
  65966. *((uint8*) dest) = (uint8) c;
  65967. }
  65968. else
  65969. {
  65970. if (! repeatPattern)
  65971. {
  65972. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65973. if (loResX < 0) loResX = 0;
  65974. if (loResY < 0) loResY = 0;
  65975. if (loResX > maxX) loResX = maxX;
  65976. if (loResY > maxY) loResY = maxY;
  65977. }
  65978. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  65979. }
  65980. ++dest;
  65981. } while (--numPixels > 0);
  65982. }
  65983. class TransformedImageSpanInterpolator
  65984. {
  65985. public:
  65986. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  65987. : inverseTransform (transform.inverted())
  65988. {}
  65989. void setStartOfLine (float x, float y, const int numPixels) throw()
  65990. {
  65991. float x1 = x, y1 = y;
  65992. inverseTransform.transformPoint (x1, y1);
  65993. x += numPixels;
  65994. inverseTransform.transformPoint (x, y);
  65995. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  65996. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  65997. }
  65998. void next (int& x, int& y) throw()
  65999. {
  66000. x = xBresenham.n;
  66001. xBresenham.stepToNext();
  66002. y = yBresenham.n;
  66003. yBresenham.stepToNext();
  66004. }
  66005. private:
  66006. class BresenhamInterpolator
  66007. {
  66008. public:
  66009. BresenhamInterpolator() throw() {}
  66010. void set (const int n1, const int n2, const int numSteps_) throw()
  66011. {
  66012. numSteps = jmax (1, numSteps_);
  66013. step = (n2 - n1) / numSteps;
  66014. remainder = modulo = (n2 - n1) % numSteps;
  66015. n = n1;
  66016. if (modulo <= 0)
  66017. {
  66018. modulo += numSteps;
  66019. remainder += numSteps;
  66020. --step;
  66021. }
  66022. modulo -= numSteps;
  66023. }
  66024. forcedinline void stepToNext() throw()
  66025. {
  66026. modulo += remainder;
  66027. n += step;
  66028. if (modulo > 0)
  66029. {
  66030. modulo -= numSteps;
  66031. ++n;
  66032. }
  66033. }
  66034. int n;
  66035. private:
  66036. int numSteps, step, modulo, remainder;
  66037. };
  66038. const AffineTransform inverseTransform;
  66039. BresenhamInterpolator xBresenham, yBresenham;
  66040. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66041. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66042. };
  66043. TransformedImageSpanInterpolator interpolator;
  66044. const Image::BitmapData& destData;
  66045. const Image::BitmapData& srcData;
  66046. const int extraAlpha;
  66047. const bool betterQuality;
  66048. const float pixelOffset;
  66049. const int pixelOffsetInt, maxX, maxY;
  66050. int y;
  66051. DestPixelType* linePixels;
  66052. HeapBlock <SrcPixelType> scratchBuffer;
  66053. int scratchSize;
  66054. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66055. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66056. };
  66057. class LLGCSavedState
  66058. {
  66059. public:
  66060. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66061. const Font& font_, const FillType& fillType_,
  66062. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66063. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66064. xOffset (xOffset_), yOffset (yOffset_),
  66065. font (font_), fillType (fillType_),
  66066. interpolationQuality (interpolationQuality_)
  66067. {
  66068. }
  66069. LLGCSavedState (const LLGCSavedState& other) throw()
  66070. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66071. yOffset (other.yOffset), font (other.font),
  66072. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66073. {
  66074. }
  66075. ~LLGCSavedState() throw()
  66076. {
  66077. }
  66078. bool clipToRectangle (const Rectangle<int>& r) throw()
  66079. {
  66080. dupeEdgeTableIfMultiplyReferenced();
  66081. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66082. return ! edgeTable->edgeTable.isEmpty();
  66083. }
  66084. bool clipToRectangleList (const RectangleList& r) throw()
  66085. {
  66086. dupeEdgeTableIfMultiplyReferenced();
  66087. RectangleList offsetList (r);
  66088. offsetList.offsetAll (xOffset, yOffset);
  66089. EdgeTable e2 (offsetList);
  66090. edgeTable->edgeTable.clipToEdgeTable (e2);
  66091. return ! edgeTable->edgeTable.isEmpty();
  66092. }
  66093. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66094. {
  66095. dupeEdgeTableIfMultiplyReferenced();
  66096. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66097. return ! edgeTable->edgeTable.isEmpty();
  66098. }
  66099. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66100. {
  66101. dupeEdgeTableIfMultiplyReferenced();
  66102. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66103. edgeTable->edgeTable.clipToEdgeTable (et);
  66104. }
  66105. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66106. {
  66107. et.clipToEdgeTable (edgeTable->edgeTable);
  66108. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66109. if (fillType.isGradient())
  66110. {
  66111. jassert (! replaceContents); // that option is just for solid colours
  66112. ColourGradient g2 (*(fillType.gradient));
  66113. g2.multiplyOpacity (fillType.getOpacity());
  66114. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66115. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66116. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66117. const bool isIdentity = transform.isOnlyTranslation();
  66118. if (isIdentity)
  66119. {
  66120. // If our translation doesn't involve any distortion, we can speed it up..
  66121. transform.transformPoint (g2.x1, g2.y1);
  66122. transform.transformPoint (g2.x2, g2.y2);
  66123. transform = AffineTransform::identity;
  66124. }
  66125. HeapBlock <PixelARGB> lookupTable;
  66126. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66127. jassert (numLookupEntries > 0);
  66128. switch (image.getFormat())
  66129. {
  66130. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66131. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66132. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66133. }
  66134. }
  66135. else if (fillType.isTiledImage())
  66136. {
  66137. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66138. }
  66139. else
  66140. {
  66141. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66142. switch (image.getFormat())
  66143. {
  66144. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66145. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66146. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66147. }
  66148. }
  66149. }
  66150. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66151. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66152. {
  66153. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66154. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66155. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66156. const int alpha = fillType.colour.getAlpha();
  66157. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66158. if (transform.isOnlyTranslation())
  66159. {
  66160. // If our translation doesn't involve any distortion, just use a simple blit..
  66161. int tx = (int) (transform.getTranslationX() * 256.0f);
  66162. int ty = (int) (transform.getTranslationY() * 256.0f);
  66163. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66164. {
  66165. tx = ((tx + 128) >> 8);
  66166. ty = ((ty + 128) >> 8);
  66167. if (tiledFillClipRegion != 0)
  66168. {
  66169. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66170. }
  66171. else
  66172. {
  66173. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66174. et.clipToEdgeTable (edgeTable->edgeTable);
  66175. if (! et.isEmpty())
  66176. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66177. }
  66178. return;
  66179. }
  66180. }
  66181. if (transform.isSingularity())
  66182. return;
  66183. if (tiledFillClipRegion != 0)
  66184. {
  66185. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66186. }
  66187. else
  66188. {
  66189. Path p;
  66190. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66191. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66192. et.clipToEdgeTable (edgeTable->edgeTable);
  66193. if (! et.isEmpty())
  66194. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66195. }
  66196. }
  66197. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66198. {
  66199. if (! image.hasAlphaChannel())
  66200. {
  66201. Path p;
  66202. p.addRectangle (srcClip);
  66203. clipToPath (p, t);
  66204. return;
  66205. }
  66206. dupeEdgeTableIfMultiplyReferenced();
  66207. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66208. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66209. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66210. EdgeTable& et = edgeTable->edgeTable;
  66211. if (transform.isOnlyTranslation())
  66212. {
  66213. // If our translation doesn't involve any distortion, just use a simple blit..
  66214. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66215. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66216. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66217. {
  66218. const int imageX = ((tx + 128) >> 8);
  66219. const int imageY = ((ty + 128) >> 8);
  66220. if (image.getFormat() == Image::ARGB)
  66221. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66222. else
  66223. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66224. return;
  66225. }
  66226. }
  66227. if (transform.isSingularity())
  66228. {
  66229. et.clipToRectangle (Rectangle<int>());
  66230. return;
  66231. }
  66232. {
  66233. Path p;
  66234. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66235. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66236. et.clipToEdgeTable (et2);
  66237. }
  66238. if (! et.isEmpty())
  66239. {
  66240. if (image.getFormat() == Image::ARGB)
  66241. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66242. else
  66243. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66244. }
  66245. }
  66246. template <class SrcPixelType>
  66247. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66248. {
  66249. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66250. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66251. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66252. et.getMaximumBounds().getWidth());
  66253. }
  66254. template <class SrcPixelType>
  66255. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66256. {
  66257. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66258. et.clipToRectangle (r);
  66259. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66260. for (int y = 0; y < r.getHeight(); ++y)
  66261. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66262. }
  66263. class EdgeTableHolder : public ReferenceCountedObject
  66264. {
  66265. public:
  66266. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66267. EdgeTable edgeTable;
  66268. };
  66269. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66270. int xOffset, yOffset;
  66271. Font font;
  66272. FillType fillType;
  66273. Graphics::ResamplingQuality interpolationQuality;
  66274. private:
  66275. LLGCSavedState& operator= (const LLGCSavedState&);
  66276. void dupeEdgeTableIfMultiplyReferenced() throw()
  66277. {
  66278. if (edgeTable->getReferenceCount() > 1)
  66279. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66280. }
  66281. template <class DestPixelType>
  66282. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66283. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66284. {
  66285. jassert (destData.pixelStride == sizeof (DestPixelType));
  66286. if (g.isRadial)
  66287. {
  66288. if (isIdentity)
  66289. {
  66290. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66291. et.iterate (renderer);
  66292. }
  66293. else
  66294. {
  66295. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66296. et.iterate (renderer);
  66297. }
  66298. }
  66299. else
  66300. {
  66301. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66302. et.iterate (renderer);
  66303. }
  66304. }
  66305. template <class DestPixelType>
  66306. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66307. {
  66308. jassert (destData.pixelStride == sizeof (DestPixelType));
  66309. if (replaceContents)
  66310. {
  66311. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66312. et.iterate (r);
  66313. }
  66314. else
  66315. {
  66316. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66317. et.iterate (r);
  66318. }
  66319. }
  66320. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66321. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66322. {
  66323. switch (destImage.getFormat())
  66324. {
  66325. case Image::ARGB:
  66326. switch (srcImage.getFormat())
  66327. {
  66328. case Image::ARGB:
  66329. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66330. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66331. break;
  66332. case Image::RGB:
  66333. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66334. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66335. break;
  66336. default:
  66337. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66338. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66339. break;
  66340. }
  66341. break;
  66342. case Image::RGB:
  66343. switch (srcImage.getFormat())
  66344. {
  66345. case Image::ARGB:
  66346. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66347. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66348. break;
  66349. case Image::RGB:
  66350. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66351. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66352. break;
  66353. default:
  66354. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66355. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66356. break;
  66357. }
  66358. break;
  66359. default:
  66360. switch (srcImage.getFormat())
  66361. {
  66362. case Image::ARGB:
  66363. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66364. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66365. break;
  66366. case Image::RGB:
  66367. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66368. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66369. break;
  66370. default:
  66371. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66372. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66373. break;
  66374. }
  66375. break;
  66376. }
  66377. }
  66378. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66379. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66380. {
  66381. switch (destImage.getFormat())
  66382. {
  66383. case Image::ARGB:
  66384. switch (srcImage.getFormat())
  66385. {
  66386. case Image::ARGB:
  66387. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66388. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66389. break;
  66390. case Image::RGB:
  66391. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66392. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66393. break;
  66394. default:
  66395. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66396. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66397. break;
  66398. }
  66399. break;
  66400. case Image::RGB:
  66401. switch (srcImage.getFormat())
  66402. {
  66403. case Image::ARGB:
  66404. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66405. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66406. break;
  66407. case Image::RGB:
  66408. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66409. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66410. break;
  66411. default:
  66412. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66413. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66414. break;
  66415. }
  66416. break;
  66417. default:
  66418. switch (srcImage.getFormat())
  66419. {
  66420. case Image::ARGB:
  66421. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66422. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66423. break;
  66424. case Image::RGB:
  66425. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66426. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66427. break;
  66428. default:
  66429. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66430. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66431. break;
  66432. }
  66433. break;
  66434. }
  66435. }
  66436. };
  66437. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66438. : image (image_)
  66439. {
  66440. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66441. FillType(), Graphics::mediumResamplingQuality);
  66442. }
  66443. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66444. {
  66445. }
  66446. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66447. {
  66448. return false;
  66449. }
  66450. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66451. {
  66452. currentState->xOffset += x;
  66453. currentState->yOffset += y;
  66454. }
  66455. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66456. {
  66457. return currentState->clipToRectangle (r);
  66458. }
  66459. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66460. {
  66461. return currentState->clipToRectangleList (clipRegion);
  66462. }
  66463. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66464. {
  66465. currentState->excludeClipRectangle (r);
  66466. }
  66467. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66468. {
  66469. currentState->clipToPath (path, transform);
  66470. }
  66471. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66472. {
  66473. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66474. }
  66475. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66476. {
  66477. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66478. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66479. }
  66480. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66481. {
  66482. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66483. }
  66484. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66485. {
  66486. return currentState->edgeTable->edgeTable.isEmpty();
  66487. }
  66488. void LowLevelGraphicsSoftwareRenderer::saveState()
  66489. {
  66490. stateStack.add (new LLGCSavedState (*currentState));
  66491. }
  66492. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66493. {
  66494. LLGCSavedState* const top = stateStack.getLast();
  66495. if (top != 0)
  66496. {
  66497. currentState = top;
  66498. stateStack.removeLast (1, false);
  66499. }
  66500. else
  66501. {
  66502. jassertfalse // trying to pop with an empty stack!
  66503. }
  66504. }
  66505. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66506. {
  66507. currentState->fillType = fillType;
  66508. }
  66509. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66510. {
  66511. currentState->fillType.setOpacity (newOpacity);
  66512. }
  66513. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66514. {
  66515. currentState->interpolationQuality = quality;
  66516. }
  66517. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66518. {
  66519. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66520. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66521. if (! clipped.isEmpty())
  66522. {
  66523. EdgeTable et (clipped);
  66524. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66525. }
  66526. }
  66527. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66528. {
  66529. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66530. path, transform.translated ((float) currentState->xOffset,
  66531. (float) currentState->yOffset));
  66532. currentState->fillEdgeTable (image, et);
  66533. }
  66534. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66535. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66536. {
  66537. jassert (sourceImage.getBounds().contains (srcClip));
  66538. currentState->renderImage (image, sourceImage, srcClip, transform,
  66539. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66540. }
  66541. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66542. {
  66543. Path p;
  66544. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66545. fillPath (p, AffineTransform::identity);
  66546. }
  66547. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66548. {
  66549. if (bottom > top)
  66550. {
  66551. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66552. currentState->fillEdgeTable (image, et);
  66553. }
  66554. }
  66555. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66556. {
  66557. if (right > left)
  66558. {
  66559. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66560. (float) (right - left), 1.0f);
  66561. currentState->fillEdgeTable (image, et);
  66562. }
  66563. }
  66564. class GlyphCache : private DeletedAtShutdown
  66565. {
  66566. public:
  66567. GlyphCache() throw()
  66568. : accessCounter (0), hits (0), misses (0)
  66569. {
  66570. for (int i = 120; --i >= 0;)
  66571. glyphs.add (new CachedGlyph());
  66572. }
  66573. ~GlyphCache() throw()
  66574. {
  66575. clearSingletonInstance();
  66576. }
  66577. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66578. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66579. {
  66580. ++accessCounter;
  66581. int oldestCounter = std::numeric_limits<int>::max();
  66582. CachedGlyph* oldest = 0;
  66583. for (int i = glyphs.size(); --i >= 0;)
  66584. {
  66585. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66586. if (glyph->glyph == glyphNumber && glyph->font == font)
  66587. {
  66588. ++hits;
  66589. glyph->lastAccessCount = accessCounter;
  66590. glyph->draw (state, image, x, y);
  66591. return;
  66592. }
  66593. if (glyph->lastAccessCount <= oldestCounter)
  66594. {
  66595. oldestCounter = glyph->lastAccessCount;
  66596. oldest = glyph;
  66597. }
  66598. }
  66599. if (hits + ++misses > (glyphs.size() << 4))
  66600. {
  66601. if (misses * 2 > hits)
  66602. {
  66603. for (int i = 32; --i >= 0;)
  66604. glyphs.add (new CachedGlyph());
  66605. }
  66606. hits = misses = 0;
  66607. oldest = glyphs.getLast();
  66608. }
  66609. jassert (oldest != 0);
  66610. oldest->lastAccessCount = accessCounter;
  66611. oldest->generate (font, glyphNumber);
  66612. oldest->draw (state, image, x, y);
  66613. }
  66614. class CachedGlyph
  66615. {
  66616. public:
  66617. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66618. ~CachedGlyph() {}
  66619. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66620. {
  66621. if (edgeTable != 0)
  66622. {
  66623. EdgeTable et (*edgeTable);
  66624. et.translate (x, roundToInt (y));
  66625. state.fillEdgeTable (image, et, false);
  66626. }
  66627. }
  66628. void generate (const Font& newFont, const int glyphNumber) throw()
  66629. {
  66630. font = newFont;
  66631. glyph = glyphNumber;
  66632. edgeTable = 0;
  66633. Path glyphPath;
  66634. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66635. if (! glyphPath.isEmpty())
  66636. {
  66637. const float fontHeight = font.getHeight();
  66638. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66639. .translated (0.0f, -0.5f));
  66640. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66641. glyphPath, transform);
  66642. }
  66643. }
  66644. int glyph, lastAccessCount;
  66645. Font font;
  66646. juce_UseDebuggingNewOperator
  66647. private:
  66648. ScopedPointer <EdgeTable> edgeTable;
  66649. CachedGlyph (const CachedGlyph&);
  66650. CachedGlyph& operator= (const CachedGlyph&);
  66651. };
  66652. juce_UseDebuggingNewOperator
  66653. private:
  66654. OwnedArray <CachedGlyph> glyphs;
  66655. int accessCounter, hits, misses;
  66656. GlyphCache (const GlyphCache&);
  66657. GlyphCache& operator= (const GlyphCache&);
  66658. };
  66659. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66660. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66661. {
  66662. currentState->font = newFont;
  66663. }
  66664. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66665. {
  66666. return currentState->font;
  66667. }
  66668. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66669. {
  66670. Font& f = currentState->font;
  66671. if (transform.isOnlyTranslation())
  66672. {
  66673. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66674. transform.getTranslationX() + (float) currentState->xOffset,
  66675. transform.getTranslationY() + (float) currentState->yOffset);
  66676. }
  66677. else
  66678. {
  66679. Path p;
  66680. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66681. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66682. }
  66683. }
  66684. #if JUCE_MSVC
  66685. #pragma warning (pop)
  66686. #if JUCE_DEBUG
  66687. #pragma optimize ("", on) // resets optimisations to the project defaults
  66688. #endif
  66689. #endif
  66690. END_JUCE_NAMESPACE
  66691. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66692. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66693. BEGIN_JUCE_NAMESPACE
  66694. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66695. : flags (other.flags)
  66696. {
  66697. }
  66698. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66699. {
  66700. flags = other.flags;
  66701. return *this;
  66702. }
  66703. void RectanglePlacement::applyTo (double& x, double& y,
  66704. double& w, double& h,
  66705. const double dx, const double dy,
  66706. const double dw, const double dh) const throw()
  66707. {
  66708. if (w == 0 || h == 0)
  66709. return;
  66710. if ((flags & stretchToFit) != 0)
  66711. {
  66712. x = dx;
  66713. y = dy;
  66714. w = dw;
  66715. h = dh;
  66716. }
  66717. else
  66718. {
  66719. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66720. : jmin (dw / w, dh / h);
  66721. if ((flags & onlyReduceInSize) != 0)
  66722. scale = jmin (scale, 1.0);
  66723. if ((flags & onlyIncreaseInSize) != 0)
  66724. scale = jmax (scale, 1.0);
  66725. w *= scale;
  66726. h *= scale;
  66727. if ((flags & xLeft) != 0)
  66728. x = dx;
  66729. else if ((flags & xRight) != 0)
  66730. x = dx + dw - w;
  66731. else
  66732. x = dx + (dw - w) * 0.5;
  66733. if ((flags & yTop) != 0)
  66734. y = dy;
  66735. else if ((flags & yBottom) != 0)
  66736. y = dy + dh - h;
  66737. else
  66738. y = dy + (dh - h) * 0.5;
  66739. }
  66740. }
  66741. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66742. float w, float h,
  66743. const float dx, const float dy,
  66744. const float dw, const float dh) const throw()
  66745. {
  66746. if (w == 0 || h == 0)
  66747. return AffineTransform::identity;
  66748. const float scaleX = dw / w;
  66749. const float scaleY = dh / h;
  66750. if ((flags & stretchToFit) != 0)
  66751. return AffineTransform::translation (-x, -y)
  66752. .scaled (scaleX, scaleY)
  66753. .translated (dx, dy);
  66754. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66755. : jmin (scaleX, scaleY);
  66756. if ((flags & onlyReduceInSize) != 0)
  66757. scale = jmin (scale, 1.0f);
  66758. if ((flags & onlyIncreaseInSize) != 0)
  66759. scale = jmax (scale, 1.0f);
  66760. w *= scale;
  66761. h *= scale;
  66762. float newX = dx;
  66763. if ((flags & xRight) != 0)
  66764. newX += dw - w; // right
  66765. else if ((flags & xLeft) == 0)
  66766. newX += (dw - w) / 2.0f; // centre
  66767. float newY = dy;
  66768. if ((flags & yBottom) != 0)
  66769. newY += dh - h; // bottom
  66770. else if ((flags & yTop) == 0)
  66771. newY += (dh - h) / 2.0f; // centre
  66772. return AffineTransform::translation (-x, -y)
  66773. .scaled (scale, scale)
  66774. .translated (newX, newY);
  66775. }
  66776. END_JUCE_NAMESPACE
  66777. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66778. /*** Start of inlined file: juce_Drawable.cpp ***/
  66779. BEGIN_JUCE_NAMESPACE
  66780. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66781. const AffineTransform& transform_,
  66782. const float opacity_) throw()
  66783. : g (g_),
  66784. transform (transform_),
  66785. opacity (opacity_)
  66786. {
  66787. }
  66788. Drawable::Drawable()
  66789. {
  66790. }
  66791. Drawable::~Drawable()
  66792. {
  66793. }
  66794. void Drawable::draw (Graphics& g, const float opacity,
  66795. const AffineTransform& transform) const
  66796. {
  66797. render (RenderingContext (g, transform, opacity));
  66798. }
  66799. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66800. {
  66801. draw (g, opacity, AffineTransform::translation (x, y));
  66802. }
  66803. void Drawable::drawWithin (Graphics& g,
  66804. const int destX,
  66805. const int destY,
  66806. const int destW,
  66807. const int destH,
  66808. const RectanglePlacement& placement,
  66809. const float opacity) const
  66810. {
  66811. if (destW > 0 && destH > 0)
  66812. {
  66813. Rectangle<float> bounds (getBounds());
  66814. draw (g, opacity,
  66815. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66816. (float) destX, (float) destY,
  66817. (float) destW, (float) destH));
  66818. }
  66819. }
  66820. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66821. {
  66822. Drawable* result = 0;
  66823. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66824. if (image != 0)
  66825. {
  66826. DrawableImage* const di = new DrawableImage();
  66827. di->setImage (image, true);
  66828. result = di;
  66829. }
  66830. else
  66831. {
  66832. const String asString (String::createStringFromData (data, (int) numBytes));
  66833. XmlDocument doc (asString);
  66834. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66835. if (outer != 0 && outer->hasTagName ("svg"))
  66836. {
  66837. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66838. if (svg != 0)
  66839. result = Drawable::createFromSVG (*svg);
  66840. }
  66841. }
  66842. return result;
  66843. }
  66844. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66845. {
  66846. MemoryBlock mb;
  66847. dataSource.readIntoMemoryBlock (mb);
  66848. return createFromImageData (mb.getData(), mb.getSize());
  66849. }
  66850. Drawable* Drawable::createFromImageFile (const File& file)
  66851. {
  66852. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66853. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66854. }
  66855. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66856. {
  66857. Drawable* d = DrawablePath::createFromValueTree (tree);
  66858. if (d == 0)
  66859. {
  66860. d = DrawableComposite::createFromValueTree (tree);
  66861. if (d == 0)
  66862. {
  66863. d = DrawableImage::createFromValueTree (tree);
  66864. if (d == 0)
  66865. d = DrawableText::createFromValueTree (tree);
  66866. }
  66867. }
  66868. return d;
  66869. }
  66870. END_JUCE_NAMESPACE
  66871. /*** End of inlined file: juce_Drawable.cpp ***/
  66872. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66873. BEGIN_JUCE_NAMESPACE
  66874. DrawableComposite::DrawableComposite()
  66875. {
  66876. }
  66877. DrawableComposite::~DrawableComposite()
  66878. {
  66879. }
  66880. void DrawableComposite::insertDrawable (Drawable* drawable,
  66881. const AffineTransform& transform,
  66882. const int index)
  66883. {
  66884. if (drawable != 0)
  66885. {
  66886. if (! drawables.contains (drawable))
  66887. {
  66888. drawables.insert (index, drawable);
  66889. if (transform.isIdentity())
  66890. transforms.insert (index, 0);
  66891. else
  66892. transforms.insert (index, new AffineTransform (transform));
  66893. }
  66894. else
  66895. {
  66896. jassertfalse // trying to add a drawable that's already in here!
  66897. }
  66898. }
  66899. }
  66900. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66901. const AffineTransform& transform,
  66902. const int index)
  66903. {
  66904. insertDrawable (drawable.createCopy(), transform, index);
  66905. }
  66906. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66907. {
  66908. drawables.remove (index, deleteDrawable);
  66909. transforms.remove (index);
  66910. }
  66911. void DrawableComposite::bringToFront (const int index)
  66912. {
  66913. if (index >= 0 && index < drawables.size() - 1)
  66914. {
  66915. drawables.move (index, -1);
  66916. transforms.move (index, -1);
  66917. }
  66918. }
  66919. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66920. {
  66921. if (drawables.size() > 0 && context.opacity > 0)
  66922. {
  66923. if (context.opacity >= 1.0f || drawables.size() == 1)
  66924. {
  66925. Drawable::RenderingContext contextCopy (context);
  66926. for (int i = 0; i < drawables.size(); ++i)
  66927. {
  66928. const AffineTransform* const t = transforms.getUnchecked(i);
  66929. contextCopy.transform = (t == 0) ? context.transform
  66930. : t->followedBy (context.transform);
  66931. drawables.getUnchecked(i)->render (contextCopy);
  66932. }
  66933. }
  66934. else
  66935. {
  66936. // To correctly render a whole composite layer with an overall transparency,
  66937. // we need to render everything opaquely into a temp buffer, then blend that
  66938. // with the target opacity...
  66939. const Rectangle<int> clipBounds (context.g.getClipBounds());
  66940. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  66941. {
  66942. Graphics tempG (tempImage);
  66943. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  66944. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  66945. render (tempContext);
  66946. }
  66947. context.g.setOpacity (context.opacity);
  66948. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  66949. }
  66950. }
  66951. }
  66952. const Rectangle<float> DrawableComposite::getBounds() const
  66953. {
  66954. Rectangle<float> bounds;
  66955. for (int i = 0; i < drawables.size(); ++i)
  66956. {
  66957. const Drawable* const d = drawables.getUnchecked(i);
  66958. const AffineTransform* const t = transforms.getUnchecked(i);
  66959. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  66960. : d->getBounds().transformed (*t));
  66961. if (bounds.isEmpty())
  66962. bounds = childBounds;
  66963. else if (! childBounds.isEmpty())
  66964. bounds = bounds.getUnion (childBounds);
  66965. }
  66966. return bounds;
  66967. }
  66968. bool DrawableComposite::hitTest (float x, float y) const
  66969. {
  66970. for (int i = 0; i < drawables.size(); ++i)
  66971. {
  66972. float tx = x;
  66973. float ty = y;
  66974. const AffineTransform* const t = transforms.getUnchecked(i);
  66975. if (t != 0)
  66976. t->inverted().transformPoint (tx, ty);
  66977. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  66978. return true;
  66979. }
  66980. return false;
  66981. }
  66982. Drawable* DrawableComposite::createCopy() const
  66983. {
  66984. DrawableComposite* const dc = new DrawableComposite();
  66985. for (int i = 0; i < drawables.size(); ++i)
  66986. {
  66987. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  66988. const AffineTransform* const t = transforms.getUnchecked(i);
  66989. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  66990. }
  66991. return dc;
  66992. }
  66993. ValueTree DrawableComposite::createValueTree() const throw()
  66994. {
  66995. ValueTree v ("Group");
  66996. if (getName().isNotEmpty())
  66997. v.setProperty ("id", getName(), 0);
  66998. for (int i = 0; i < drawables.size(); ++i)
  66999. {
  67000. Drawable* const d = drawables.getUnchecked(i);
  67001. ValueTree child (d->createValueTree());
  67002. AffineTransform* transform = transforms.getUnchecked(i);
  67003. if (transform != 0)
  67004. {
  67005. String t;
  67006. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67007. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67008. child.setProperty ("transform", t, 0);
  67009. }
  67010. v.addChild (child, -1, 0);
  67011. }
  67012. return v;
  67013. }
  67014. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67015. {
  67016. if (! tree.hasType ("Group"))
  67017. return 0;
  67018. DrawableComposite* dc = new DrawableComposite();
  67019. dc->setName (tree ["id"]);
  67020. for (int i = 0; i < tree.getNumChildren(); ++i)
  67021. {
  67022. ValueTree childTree (tree.getChild (i));
  67023. Drawable* d = Drawable::createFromValueTree (childTree);
  67024. if (d != 0)
  67025. {
  67026. AffineTransform transform;
  67027. const String transformAtt (childTree ["transform"].toString());
  67028. if (transformAtt.isNotEmpty())
  67029. {
  67030. StringArray tokens;
  67031. tokens.addTokens (transformAtt.trim(), false);
  67032. tokens.removeEmptyStrings (true);
  67033. if (tokens.size() == 6)
  67034. {
  67035. float f[6];
  67036. for (int j = 0; j < 6; ++j)
  67037. f[j] = (float) tokens[j].getDoubleValue();
  67038. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67039. }
  67040. }
  67041. dc->insertDrawable (d, transform);
  67042. }
  67043. }
  67044. return dc;
  67045. }
  67046. END_JUCE_NAMESPACE
  67047. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67048. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67049. BEGIN_JUCE_NAMESPACE
  67050. DrawableImage::DrawableImage()
  67051. : image (0),
  67052. canDeleteImage (false),
  67053. opacity (1.0f),
  67054. overlayColour (0x00000000)
  67055. {
  67056. }
  67057. DrawableImage::~DrawableImage()
  67058. {
  67059. clearImage();
  67060. }
  67061. void DrawableImage::clearImage()
  67062. {
  67063. if (canDeleteImage && image != 0)
  67064. ImageCache::releaseOrDelete (image);
  67065. image = 0;
  67066. }
  67067. void DrawableImage::setImage (const Image& imageToCopy)
  67068. {
  67069. clearImage();
  67070. image = new Image (imageToCopy);
  67071. canDeleteImage = true;
  67072. }
  67073. void DrawableImage::setImage (Image* imageToUse,
  67074. const bool releaseWhenNotNeeded)
  67075. {
  67076. clearImage();
  67077. image = imageToUse;
  67078. canDeleteImage = releaseWhenNotNeeded;
  67079. }
  67080. void DrawableImage::setOpacity (const float newOpacity)
  67081. {
  67082. opacity = newOpacity;
  67083. }
  67084. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67085. {
  67086. overlayColour = newOverlayColour;
  67087. }
  67088. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67089. {
  67090. if (image != 0)
  67091. {
  67092. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67093. {
  67094. context.g.setOpacity (context.opacity * opacity);
  67095. context.g.drawImageTransformed (image, image->getBounds(),
  67096. context.transform, false);
  67097. }
  67098. if (! overlayColour.isTransparent())
  67099. {
  67100. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67101. context.g.drawImageTransformed (image, image->getBounds(),
  67102. context.transform, true);
  67103. }
  67104. }
  67105. }
  67106. const Rectangle<float> DrawableImage::getBounds() const
  67107. {
  67108. if (image == 0)
  67109. return Rectangle<float>();
  67110. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67111. }
  67112. bool DrawableImage::hitTest (float x, float y) const
  67113. {
  67114. return image != 0
  67115. && x >= 0.0f
  67116. && y >= 0.0f
  67117. && x < image->getWidth()
  67118. && y < image->getHeight()
  67119. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67120. }
  67121. Drawable* DrawableImage::createCopy() const
  67122. {
  67123. DrawableImage* const di = new DrawableImage();
  67124. di->opacity = opacity;
  67125. di->overlayColour = overlayColour;
  67126. if (image != 0)
  67127. {
  67128. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67129. {
  67130. di->setImage (*image);
  67131. }
  67132. else
  67133. {
  67134. ImageCache::incReferenceCount (image);
  67135. di->setImage (image, true);
  67136. }
  67137. }
  67138. return di;
  67139. }
  67140. ValueTree DrawableImage::createValueTree() const throw()
  67141. {
  67142. ValueTree v ("Image");
  67143. if (getName().isNotEmpty())
  67144. v.setProperty ("id", getName(), 0);
  67145. if (opacity < 1.0f)
  67146. v.setProperty ("opacity", (double) opacity, 0);
  67147. if (! overlayColour.isTransparent())
  67148. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67149. if (image != 0)
  67150. {
  67151. MemoryOutputStream imageData;
  67152. PNGImageFormat pngFormat;
  67153. if (pngFormat.writeImageToStream (*image, imageData))
  67154. {
  67155. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67156. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67157. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67158. v.setProperty ("data", base64, 0);
  67159. }
  67160. }
  67161. return v;
  67162. }
  67163. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67164. {
  67165. if (! tree.hasType ("Image"))
  67166. return 0;
  67167. DrawableImage* di = new DrawableImage();
  67168. di->setName (tree ["id"]);
  67169. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67170. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67171. MemoryBlock imageData;
  67172. if (imageData.fromBase64Encoding (tree ["data"]))
  67173. {
  67174. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67175. if (im == 0)
  67176. return false;
  67177. di->setImage (im, true);
  67178. }
  67179. return di;
  67180. }
  67181. END_JUCE_NAMESPACE
  67182. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67183. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67184. BEGIN_JUCE_NAMESPACE
  67185. DrawablePath::DrawablePath()
  67186. : mainFill (Colours::black),
  67187. strokeFill (Colours::transparentBlack),
  67188. strokeType (0.0f)
  67189. {
  67190. }
  67191. DrawablePath::~DrawablePath()
  67192. {
  67193. }
  67194. void DrawablePath::setPath (const Path& newPath) throw()
  67195. {
  67196. path = newPath;
  67197. updateOutline();
  67198. }
  67199. void DrawablePath::setFill (const FillType& newFill) throw()
  67200. {
  67201. mainFill = newFill;
  67202. }
  67203. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67204. {
  67205. strokeFill = newFill;
  67206. }
  67207. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67208. {
  67209. strokeType = newStrokeType;
  67210. updateOutline();
  67211. }
  67212. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67213. {
  67214. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67215. }
  67216. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67217. {
  67218. {
  67219. FillType f (mainFill);
  67220. if (f.isGradient())
  67221. f.gradient->multiplyOpacity (context.opacity);
  67222. f.transform = f.transform.followedBy (context.transform);
  67223. context.g.setFillType (f);
  67224. context.g.fillPath (path, context.transform);
  67225. }
  67226. if (strokeType.getStrokeThickness() > 0.0f)
  67227. {
  67228. FillType f (strokeFill);
  67229. if (f.isGradient())
  67230. f.gradient->multiplyOpacity (context.opacity);
  67231. f.transform = f.transform.followedBy (context.transform);
  67232. context.g.setFillType (f);
  67233. context.g.fillPath (stroke, context.transform);
  67234. }
  67235. }
  67236. void DrawablePath::updateOutline()
  67237. {
  67238. stroke.clear();
  67239. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67240. }
  67241. const Rectangle<float> DrawablePath::getBounds() const
  67242. {
  67243. if (strokeType.getStrokeThickness() > 0.0f)
  67244. return stroke.getBounds();
  67245. else
  67246. return path.getBounds();
  67247. }
  67248. bool DrawablePath::hitTest (float x, float y) const
  67249. {
  67250. return path.contains (x, y)
  67251. || stroke.contains (x, y);
  67252. }
  67253. Drawable* DrawablePath::createCopy() const
  67254. {
  67255. DrawablePath* const dp = new DrawablePath();
  67256. dp->path = path;
  67257. dp->stroke = stroke;
  67258. dp->mainFill = mainFill;
  67259. dp->strokeFill = strokeFill;
  67260. dp->strokeType = strokeType;
  67261. return dp;
  67262. }
  67263. static const FillType readFillTypeFromTree (const ValueTree& v)
  67264. {
  67265. const String type (v["type"].toString());
  67266. if (type.equalsIgnoreCase ("solid"))
  67267. {
  67268. const String colour (v ["colour"].toString());
  67269. return Colour (colour.isEmpty() ? (uint32) 0xff000000
  67270. : (uint32) colour.getHexValue32());
  67271. }
  67272. else if (type.equalsIgnoreCase ("gradient"))
  67273. {
  67274. ColourGradient g;
  67275. g.x1 = v["x1"];
  67276. g.y1 = v["y1"];
  67277. g.x2 = v["x2"];
  67278. g.y2 = v["y2"];
  67279. g.isRadial = v["radial"];
  67280. StringArray colours;
  67281. colours.addTokens (v["colours"].toString(), false);
  67282. for (int i = 0; i < colours.size() / 2; ++i)
  67283. g.addColour (colours[i * 2].getDoubleValue(),
  67284. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67285. return g;
  67286. }
  67287. jassertfalse
  67288. return FillType();
  67289. }
  67290. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67291. {
  67292. ValueTree v (tagName);
  67293. if (fillType.isColour())
  67294. {
  67295. v.setProperty ("type", "solid", 0);
  67296. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67297. }
  67298. else if (fillType.isGradient())
  67299. {
  67300. v.setProperty ("type", "gradient", 0);
  67301. v.setProperty ("x1", fillType.gradient->x1, 0);
  67302. v.setProperty ("y1", fillType.gradient->y1, 0);
  67303. v.setProperty ("x2", fillType.gradient->x2, 0);
  67304. v.setProperty ("y2", fillType.gradient->y2, 0);
  67305. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67306. String s;
  67307. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67308. s << " " << fillType.gradient->getColourPosition (i)
  67309. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67310. v.setProperty ("colours", s.trimStart(), 0);
  67311. }
  67312. else
  67313. {
  67314. jassertfalse //xxx
  67315. }
  67316. return v;
  67317. }
  67318. ValueTree DrawablePath::createValueTree() const throw()
  67319. {
  67320. ValueTree v ("Path");
  67321. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67322. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67323. if (getName().isNotEmpty())
  67324. v.setProperty ("id", getName(), 0);
  67325. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67326. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67327. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67328. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67329. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67330. v.setProperty ("path", path.toString(), 0);
  67331. return v;
  67332. }
  67333. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67334. {
  67335. if (! tree.hasType ("Path"))
  67336. return 0;
  67337. DrawablePath* p = new DrawablePath();
  67338. p->setName (tree ["id"]);
  67339. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67340. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67341. const String jointStyle (tree ["jointStyle"].toString());
  67342. const String endStyle (tree ["capStyle"].toString());
  67343. p->strokeType
  67344. = PathStrokeType (tree ["strokeWidth"],
  67345. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67346. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67347. : PathStrokeType::mitered),
  67348. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67349. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67350. : PathStrokeType::butt));
  67351. p->path.clear();
  67352. p->path.restoreFromString (tree ["path"]);
  67353. p->updateOutline();
  67354. return p;
  67355. }
  67356. END_JUCE_NAMESPACE
  67357. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67358. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67359. BEGIN_JUCE_NAMESPACE
  67360. DrawableText::DrawableText()
  67361. : colour (Colours::white)
  67362. {
  67363. }
  67364. DrawableText::~DrawableText()
  67365. {
  67366. }
  67367. void DrawableText::setText (const GlyphArrangement& newText)
  67368. {
  67369. text = newText;
  67370. }
  67371. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67372. {
  67373. text.clear();
  67374. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67375. }
  67376. void DrawableText::setColour (const Colour& newColour)
  67377. {
  67378. colour = newColour;
  67379. }
  67380. void DrawableText::render (const Drawable::RenderingContext& context) const
  67381. {
  67382. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67383. text.draw (context.g, context.transform);
  67384. }
  67385. const Rectangle<float> DrawableText::getBounds() const
  67386. {
  67387. return text.getBoundingBox (0, -1, false);
  67388. }
  67389. bool DrawableText::hitTest (float x, float y) const
  67390. {
  67391. return text.findGlyphIndexAt (x, y) >= 0;
  67392. }
  67393. Drawable* DrawableText::createCopy() const
  67394. {
  67395. DrawableText* const dt = new DrawableText();
  67396. dt->text = text;
  67397. dt->colour = colour;
  67398. return dt;
  67399. }
  67400. ValueTree DrawableText::createValueTree() const throw()
  67401. {
  67402. ValueTree v ("Text");
  67403. if (getName().isNotEmpty())
  67404. v.setProperty ("id", getName(), 0);
  67405. jassertfalse // xxx not finished!
  67406. return v;
  67407. }
  67408. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67409. {
  67410. if (! tree.hasType ("Text"))
  67411. return 0;
  67412. DrawableText* dt = new DrawableText();
  67413. dt->setName (tree ["id"]);
  67414. jassertfalse // xxx not finished!
  67415. return dt;
  67416. }
  67417. END_JUCE_NAMESPACE
  67418. /*** End of inlined file: juce_DrawableText.cpp ***/
  67419. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67420. BEGIN_JUCE_NAMESPACE
  67421. class SVGState
  67422. {
  67423. public:
  67424. SVGState (const XmlElement* const topLevel)
  67425. : topLevelXml (topLevel),
  67426. elementX (0), elementY (0),
  67427. width (512), height (512),
  67428. viewBoxW (0), viewBoxH (0)
  67429. {
  67430. }
  67431. ~SVGState()
  67432. {
  67433. }
  67434. Drawable* parseSVGElement (const XmlElement& xml)
  67435. {
  67436. if (! xml.hasTagName ("svg"))
  67437. return 0;
  67438. DrawableComposite* const drawable = new DrawableComposite();
  67439. drawable->setName (xml.getStringAttribute ("id"));
  67440. SVGState newState (*this);
  67441. if (xml.hasAttribute ("transform"))
  67442. newState.addTransform (xml);
  67443. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67444. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67445. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67446. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67447. if (xml.hasAttribute ("viewBox"))
  67448. {
  67449. const String viewParams (xml.getStringAttribute ("viewBox"));
  67450. int i = 0;
  67451. float vx, vy, vw, vh;
  67452. if (parseCoords (viewParams, vx, vy, i, true)
  67453. && parseCoords (viewParams, vw, vh, i, true)
  67454. && vw > 0
  67455. && vh > 0)
  67456. {
  67457. newState.viewBoxW = vw;
  67458. newState.viewBoxH = vh;
  67459. int placementFlags = 0;
  67460. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67461. if (aspect.containsIgnoreCase ("none"))
  67462. {
  67463. placementFlags = RectanglePlacement::stretchToFit;
  67464. }
  67465. else
  67466. {
  67467. if (aspect.containsIgnoreCase ("slice"))
  67468. placementFlags |= RectanglePlacement::fillDestination;
  67469. if (aspect.containsIgnoreCase ("xMin"))
  67470. placementFlags |= RectanglePlacement::xLeft;
  67471. else if (aspect.containsIgnoreCase ("xMax"))
  67472. placementFlags |= RectanglePlacement::xRight;
  67473. else
  67474. placementFlags |= RectanglePlacement::xMid;
  67475. if (aspect.containsIgnoreCase ("yMin"))
  67476. placementFlags |= RectanglePlacement::yTop;
  67477. else if (aspect.containsIgnoreCase ("yMax"))
  67478. placementFlags |= RectanglePlacement::yBottom;
  67479. else
  67480. placementFlags |= RectanglePlacement::yMid;
  67481. }
  67482. const RectanglePlacement placement (placementFlags);
  67483. newState.transform
  67484. = placement.getTransformToFit (vx, vy, vw, vh,
  67485. 0.0f, 0.0f, newState.width, newState.height)
  67486. .followedBy (newState.transform);
  67487. }
  67488. }
  67489. else
  67490. {
  67491. if (viewBoxW == 0)
  67492. newState.viewBoxW = newState.width;
  67493. if (viewBoxH == 0)
  67494. newState.viewBoxH = newState.height;
  67495. }
  67496. newState.parseSubElements (xml, drawable);
  67497. return drawable;
  67498. }
  67499. private:
  67500. const XmlElement* const topLevelXml;
  67501. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67502. AffineTransform transform;
  67503. String cssStyleText;
  67504. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67505. {
  67506. forEachXmlChildElement (xml, e)
  67507. {
  67508. Drawable* d = 0;
  67509. if (e->hasTagName ("g"))
  67510. d = parseGroupElement (*e);
  67511. else if (e->hasTagName ("svg"))
  67512. d = parseSVGElement (*e);
  67513. else if (e->hasTagName ("path"))
  67514. d = parsePath (*e);
  67515. else if (e->hasTagName ("rect"))
  67516. d = parseRect (*e);
  67517. else if (e->hasTagName ("circle"))
  67518. d = parseCircle (*e);
  67519. else if (e->hasTagName ("ellipse"))
  67520. d = parseEllipse (*e);
  67521. else if (e->hasTagName ("line"))
  67522. d = parseLine (*e);
  67523. else if (e->hasTagName ("polyline"))
  67524. d = parsePolygon (*e, true);
  67525. else if (e->hasTagName ("polygon"))
  67526. d = parsePolygon (*e, false);
  67527. else if (e->hasTagName ("text"))
  67528. d = parseText (*e);
  67529. else if (e->hasTagName ("switch"))
  67530. d = parseSwitch (*e);
  67531. else if (e->hasTagName ("style"))
  67532. parseCSSStyle (*e);
  67533. parentDrawable->insertDrawable (d);
  67534. }
  67535. }
  67536. DrawableComposite* parseSwitch (const XmlElement& xml)
  67537. {
  67538. const XmlElement* const group = xml.getChildByName ("g");
  67539. if (group != 0)
  67540. return parseGroupElement (*group);
  67541. return 0;
  67542. }
  67543. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67544. {
  67545. DrawableComposite* const drawable = new DrawableComposite();
  67546. drawable->setName (xml.getStringAttribute ("id"));
  67547. if (xml.hasAttribute ("transform"))
  67548. {
  67549. SVGState newState (*this);
  67550. newState.addTransform (xml);
  67551. newState.parseSubElements (xml, drawable);
  67552. }
  67553. else
  67554. {
  67555. parseSubElements (xml, drawable);
  67556. }
  67557. return drawable;
  67558. }
  67559. Drawable* parsePath (const XmlElement& xml) const
  67560. {
  67561. const String d (xml.getStringAttribute ("d").trimStart());
  67562. Path path;
  67563. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67564. path.setUsingNonZeroWinding (false);
  67565. int index = 0;
  67566. float lastX = 0, lastY = 0;
  67567. float lastX2 = 0, lastY2 = 0;
  67568. juce_wchar lastCommandChar = 0;
  67569. bool isRelative = true;
  67570. bool carryOn = true;
  67571. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67572. while (d[index] != 0)
  67573. {
  67574. float x, y, x2, y2, x3, y3;
  67575. if (validCommandChars.containsChar (d[index]))
  67576. {
  67577. lastCommandChar = d [index++];
  67578. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67579. }
  67580. switch (lastCommandChar)
  67581. {
  67582. case 'M':
  67583. case 'm':
  67584. case 'L':
  67585. case 'l':
  67586. if (parseCoords (d, x, y, index, false))
  67587. {
  67588. if (isRelative)
  67589. {
  67590. x += lastX;
  67591. y += lastY;
  67592. }
  67593. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67594. {
  67595. path.startNewSubPath (x, y);
  67596. lastCommandChar = 'l';
  67597. }
  67598. else
  67599. path.lineTo (x, y);
  67600. lastX2 = lastX;
  67601. lastY2 = lastY;
  67602. lastX = x;
  67603. lastY = y;
  67604. }
  67605. else
  67606. {
  67607. ++index;
  67608. }
  67609. break;
  67610. case 'H':
  67611. case 'h':
  67612. if (parseCoord (d, x, index, false, true))
  67613. {
  67614. if (isRelative)
  67615. x += lastX;
  67616. path.lineTo (x, lastY);
  67617. lastX2 = lastX;
  67618. lastX = x;
  67619. }
  67620. else
  67621. {
  67622. ++index;
  67623. }
  67624. break;
  67625. case 'V':
  67626. case 'v':
  67627. if (parseCoord (d, y, index, false, false))
  67628. {
  67629. if (isRelative)
  67630. y += lastY;
  67631. path.lineTo (lastX, y);
  67632. lastY2 = lastY;
  67633. lastY = y;
  67634. }
  67635. else
  67636. {
  67637. ++index;
  67638. }
  67639. break;
  67640. case 'C':
  67641. case 'c':
  67642. if (parseCoords (d, x, y, index, false)
  67643. && parseCoords (d, x2, y2, index, false)
  67644. && parseCoords (d, x3, y3, index, false))
  67645. {
  67646. if (isRelative)
  67647. {
  67648. x += lastX;
  67649. y += lastY;
  67650. x2 += lastX;
  67651. y2 += lastY;
  67652. x3 += lastX;
  67653. y3 += lastY;
  67654. }
  67655. path.cubicTo (x, y, x2, y2, x3, y3);
  67656. lastX2 = x2;
  67657. lastY2 = y2;
  67658. lastX = x3;
  67659. lastY = y3;
  67660. }
  67661. else
  67662. {
  67663. ++index;
  67664. }
  67665. break;
  67666. case 'S':
  67667. case 's':
  67668. if (parseCoords (d, x, y, index, false)
  67669. && parseCoords (d, x3, y3, index, false))
  67670. {
  67671. if (isRelative)
  67672. {
  67673. x += lastX;
  67674. y += lastY;
  67675. x3 += lastX;
  67676. y3 += lastY;
  67677. }
  67678. x2 = lastX + (lastX - lastX2);
  67679. y2 = lastY + (lastY - lastY2);
  67680. path.cubicTo (x2, y2, x, y, x3, y3);
  67681. lastX2 = x;
  67682. lastY2 = y;
  67683. lastX = x3;
  67684. lastY = y3;
  67685. }
  67686. else
  67687. {
  67688. ++index;
  67689. }
  67690. break;
  67691. case 'Q':
  67692. case 'q':
  67693. if (parseCoords (d, x, y, index, false)
  67694. && parseCoords (d, x2, y2, index, false))
  67695. {
  67696. if (isRelative)
  67697. {
  67698. x += lastX;
  67699. y += lastY;
  67700. x2 += lastX;
  67701. y2 += lastY;
  67702. }
  67703. path.quadraticTo (x, y, x2, y2);
  67704. lastX2 = x;
  67705. lastY2 = y;
  67706. lastX = x2;
  67707. lastY = y2;
  67708. }
  67709. else
  67710. {
  67711. ++index;
  67712. }
  67713. break;
  67714. case 'T':
  67715. case 't':
  67716. if (parseCoords (d, x, y, index, false))
  67717. {
  67718. if (isRelative)
  67719. {
  67720. x += lastX;
  67721. y += lastY;
  67722. }
  67723. x2 = lastX + (lastX - lastX2);
  67724. y2 = lastY + (lastY - lastY2);
  67725. path.quadraticTo (x2, y2, x, y);
  67726. lastX2 = x2;
  67727. lastY2 = y2;
  67728. lastX = x;
  67729. lastY = y;
  67730. }
  67731. else
  67732. {
  67733. ++index;
  67734. }
  67735. break;
  67736. case 'A':
  67737. case 'a':
  67738. if (parseCoords (d, x, y, index, false))
  67739. {
  67740. String num;
  67741. if (parseNextNumber (d, num, index, false))
  67742. {
  67743. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67744. if (parseNextNumber (d, num, index, false))
  67745. {
  67746. const bool largeArc = num.getIntValue() != 0;
  67747. if (parseNextNumber (d, num, index, false))
  67748. {
  67749. const bool sweep = num.getIntValue() != 0;
  67750. if (parseCoords (d, x2, y2, index, false))
  67751. {
  67752. if (isRelative)
  67753. {
  67754. x2 += lastX;
  67755. y2 += lastY;
  67756. }
  67757. if (lastX != x2 || lastY != y2)
  67758. {
  67759. double centreX, centreY, startAngle, deltaAngle;
  67760. double rx = x, ry = y;
  67761. endpointToCentreParameters (lastX, lastY, x2, y2,
  67762. angle, largeArc, sweep,
  67763. rx, ry, centreX, centreY,
  67764. startAngle, deltaAngle);
  67765. path.addCentredArc ((float) centreX, (float) centreY,
  67766. (float) rx, (float) ry,
  67767. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67768. false);
  67769. path.lineTo (x2, y2);
  67770. }
  67771. lastX2 = lastX;
  67772. lastY2 = lastY;
  67773. lastX = x2;
  67774. lastY = y2;
  67775. }
  67776. }
  67777. }
  67778. }
  67779. }
  67780. else
  67781. {
  67782. ++index;
  67783. }
  67784. break;
  67785. case 'Z':
  67786. case 'z':
  67787. path.closeSubPath();
  67788. while (CharacterFunctions::isWhitespace (d [index]))
  67789. ++index;
  67790. break;
  67791. default:
  67792. carryOn = false;
  67793. break;
  67794. }
  67795. if (! carryOn)
  67796. break;
  67797. }
  67798. return parseShape (xml, path);
  67799. }
  67800. Drawable* parseRect (const XmlElement& xml) const
  67801. {
  67802. Path rect;
  67803. const bool hasRX = xml.hasAttribute ("rx");
  67804. const bool hasRY = xml.hasAttribute ("ry");
  67805. if (hasRX || hasRY)
  67806. {
  67807. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67808. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67809. if (! hasRX)
  67810. rx = ry;
  67811. else if (! hasRY)
  67812. ry = rx;
  67813. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67814. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67815. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67816. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67817. rx, ry);
  67818. }
  67819. else
  67820. {
  67821. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67822. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67823. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67824. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67825. }
  67826. return parseShape (xml, rect);
  67827. }
  67828. Drawable* parseCircle (const XmlElement& xml) const
  67829. {
  67830. Path circle;
  67831. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67832. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67833. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67834. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67835. return parseShape (xml, circle);
  67836. }
  67837. Drawable* parseEllipse (const XmlElement& xml) const
  67838. {
  67839. Path ellipse;
  67840. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67841. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67842. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67843. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67844. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67845. return parseShape (xml, ellipse);
  67846. }
  67847. Drawable* parseLine (const XmlElement& xml) const
  67848. {
  67849. Path line;
  67850. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67851. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67852. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67853. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67854. line.startNewSubPath (x1, y1);
  67855. line.lineTo (x2, y2);
  67856. return parseShape (xml, line);
  67857. }
  67858. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67859. {
  67860. const String points (xml.getStringAttribute ("points"));
  67861. Path path;
  67862. int index = 0;
  67863. float x, y;
  67864. if (parseCoords (points, x, y, index, true))
  67865. {
  67866. float firstX = x;
  67867. float firstY = y;
  67868. float lastX = 0, lastY = 0;
  67869. path.startNewSubPath (x, y);
  67870. while (parseCoords (points, x, y, index, true))
  67871. {
  67872. lastX = x;
  67873. lastY = y;
  67874. path.lineTo (x, y);
  67875. }
  67876. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67877. path.closeSubPath();
  67878. }
  67879. return parseShape (xml, path);
  67880. }
  67881. Drawable* parseShape (const XmlElement& xml, Path& path,
  67882. const bool shouldParseTransform = true) const
  67883. {
  67884. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67885. {
  67886. SVGState newState (*this);
  67887. newState.addTransform (xml);
  67888. return newState.parseShape (xml, path, false);
  67889. }
  67890. DrawablePath* dp = new DrawablePath();
  67891. dp->setName (xml.getStringAttribute ("id"));
  67892. dp->setFill (Colours::transparentBlack);
  67893. path.applyTransform (transform);
  67894. dp->setPath (path);
  67895. Path::Iterator iter (path);
  67896. bool containsClosedSubPath = false;
  67897. while (iter.next())
  67898. {
  67899. if (iter.elementType == Path::Iterator::closePath)
  67900. {
  67901. containsClosedSubPath = true;
  67902. break;
  67903. }
  67904. }
  67905. dp->setFill (getPathFillType (path,
  67906. getStyleAttribute (&xml, "fill"),
  67907. getStyleAttribute (&xml, "fill-opacity"),
  67908. getStyleAttribute (&xml, "opacity"),
  67909. containsClosedSubPath ? Colours::black
  67910. : Colours::transparentBlack));
  67911. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67912. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67913. {
  67914. dp->setStrokeFill (getPathFillType (path, strokeType,
  67915. getStyleAttribute (&xml, "stroke-opacity"),
  67916. getStyleAttribute (&xml, "opacity"),
  67917. Colours::transparentBlack));
  67918. dp->setStrokeType (getStrokeFor (&xml));
  67919. }
  67920. return dp;
  67921. }
  67922. const XmlElement* findLinkedElement (const XmlElement* e) const
  67923. {
  67924. const String id (e->getStringAttribute ("xlink:href"));
  67925. if (! id.startsWithChar ('#'))
  67926. return 0;
  67927. return findElementForId (topLevelXml, id.substring (1));
  67928. }
  67929. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67930. {
  67931. if (fillXml == 0)
  67932. return;
  67933. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  67934. {
  67935. int index = 0;
  67936. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  67937. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  67938. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  67939. double offset = e->getDoubleAttribute ("offset");
  67940. if (e->getStringAttribute ("offset").containsChar ('%'))
  67941. offset *= 0.01;
  67942. cg.addColour (jlimit (0.0, 1.0, offset), col);
  67943. }
  67944. }
  67945. const FillType getPathFillType (const Path& path,
  67946. const String& fill,
  67947. const String& fillOpacity,
  67948. const String& overallOpacity,
  67949. const Colour& defaultColour) const
  67950. {
  67951. float opacity = 1.0f;
  67952. if (overallOpacity.isNotEmpty())
  67953. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  67954. if (fillOpacity.isNotEmpty())
  67955. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  67956. if (fill.startsWithIgnoreCase ("url"))
  67957. {
  67958. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  67959. .upToLastOccurrenceOf (")", false, false).trim());
  67960. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  67961. if (fillXml != 0
  67962. && (fillXml->hasTagName ("linearGradient")
  67963. || fillXml->hasTagName ("radialGradient")))
  67964. {
  67965. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  67966. ColourGradient gradient;
  67967. addGradientStopsIn (gradient, inheritedFrom);
  67968. addGradientStopsIn (gradient, fillXml);
  67969. if (gradient.getNumColours() > 0)
  67970. {
  67971. gradient.addColour (0.0, gradient.getColour (0));
  67972. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  67973. }
  67974. else
  67975. {
  67976. gradient.addColour (0.0, Colours::black);
  67977. gradient.addColour (1.0, Colours::black);
  67978. }
  67979. if (overallOpacity.isNotEmpty())
  67980. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  67981. jassert (gradient.getNumColours() > 0);
  67982. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  67983. float width = viewBoxW;
  67984. float height = viewBoxH;
  67985. float dx = 0.0f;
  67986. float dy = 0.0f;
  67987. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  67988. if (! userSpace)
  67989. {
  67990. const Rectangle<float> bounds (path.getBounds());
  67991. dx = bounds.getX();
  67992. dy = bounds.getY();
  67993. width = bounds.getWidth();
  67994. height = bounds.getHeight();
  67995. }
  67996. if (gradient.isRadial)
  67997. {
  67998. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  67999. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  68000. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  68001. gradient.x2 = gradient.x1 + radius;
  68002. gradient.y2 = gradient.y1;
  68003. //xxx (the fx, fy focal point isn't handled properly here..)
  68004. }
  68005. else
  68006. {
  68007. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  68008. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  68009. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  68010. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  68011. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68012. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68013. }
  68014. FillType type (gradient);
  68015. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  68016. .followedBy (transform);
  68017. return type;
  68018. }
  68019. }
  68020. if (fill.equalsIgnoreCase ("none"))
  68021. return Colours::transparentBlack;
  68022. int i = 0;
  68023. const Colour colour (parseColour (fill, i, defaultColour));
  68024. return colour.withMultipliedAlpha (opacity);
  68025. }
  68026. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68027. {
  68028. const String width (getStyleAttribute (xml, "stroke-width"));
  68029. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  68030. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  68031. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  68032. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  68033. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  68034. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68035. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68036. if (join.equalsIgnoreCase ("round"))
  68037. joinStyle = PathStrokeType::curved;
  68038. else if (join.equalsIgnoreCase ("bevel"))
  68039. joinStyle = PathStrokeType::beveled;
  68040. if (cap.equalsIgnoreCase ("round"))
  68041. capStyle = PathStrokeType::rounded;
  68042. else if (cap.equalsIgnoreCase ("square"))
  68043. capStyle = PathStrokeType::square;
  68044. float ox = 0.0f, oy = 0.0f;
  68045. transform.transformPoint (ox, oy);
  68046. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68047. transform.transformPoint (x, y);
  68048. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68049. joinStyle, capStyle);
  68050. }
  68051. Drawable* parseText (const XmlElement& xml)
  68052. {
  68053. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68054. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68055. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68056. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68057. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68058. //xxx not done text yet!
  68059. forEachXmlChildElement (xml, e)
  68060. {
  68061. if (e->isTextElement())
  68062. {
  68063. const String text (e->getText());
  68064. Path path;
  68065. Drawable* s = parseShape (*e, path);
  68066. delete s;
  68067. }
  68068. else if (e->hasTagName ("tspan"))
  68069. {
  68070. Drawable* s = parseText (*e);
  68071. delete s;
  68072. }
  68073. }
  68074. return 0;
  68075. }
  68076. void addTransform (const XmlElement& xml)
  68077. {
  68078. transform = parseTransform (xml.getStringAttribute ("transform"))
  68079. .followedBy (transform);
  68080. }
  68081. bool parseCoord (const String& s, float& value, int& index,
  68082. const bool allowUnits, const bool isX) const
  68083. {
  68084. String number;
  68085. if (! parseNextNumber (s, number, index, allowUnits))
  68086. {
  68087. value = 0;
  68088. return false;
  68089. }
  68090. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68091. return true;
  68092. }
  68093. bool parseCoords (const String& s, float& x, float& y,
  68094. int& index, const bool allowUnits) const
  68095. {
  68096. return parseCoord (s, x, index, allowUnits, true)
  68097. && parseCoord (s, y, index, allowUnits, false);
  68098. }
  68099. float getCoordLength (const String& s, const float sizeForProportions) const
  68100. {
  68101. float n = s.getFloatValue();
  68102. const int len = s.length();
  68103. if (len > 2)
  68104. {
  68105. const float dpi = 96.0f;
  68106. const juce_wchar n1 = s [len - 2];
  68107. const juce_wchar n2 = s [len - 1];
  68108. if (n1 == 'i' && n2 == 'n')
  68109. n *= dpi;
  68110. else if (n1 == 'm' && n2 == 'm')
  68111. n *= dpi / 25.4f;
  68112. else if (n1 == 'c' && n2 == 'm')
  68113. n *= dpi / 2.54f;
  68114. else if (n1 == 'p' && n2 == 'c')
  68115. n *= 15.0f;
  68116. else if (n2 == '%')
  68117. n *= 0.01f * sizeForProportions;
  68118. }
  68119. return n;
  68120. }
  68121. void getCoordList (Array <float>& coords, const String& list,
  68122. const bool allowUnits, const bool isX) const
  68123. {
  68124. int index = 0;
  68125. float value;
  68126. while (parseCoord (list, value, index, allowUnits, isX))
  68127. coords.add (value);
  68128. }
  68129. void parseCSSStyle (const XmlElement& xml)
  68130. {
  68131. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68132. }
  68133. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68134. const String& defaultValue = String::empty) const
  68135. {
  68136. if (xml->hasAttribute (attributeName))
  68137. return xml->getStringAttribute (attributeName, defaultValue);
  68138. const String styleAtt (xml->getStringAttribute ("style"));
  68139. if (styleAtt.isNotEmpty())
  68140. {
  68141. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68142. if (value.isNotEmpty())
  68143. return value;
  68144. }
  68145. else if (xml->hasAttribute ("class"))
  68146. {
  68147. const String className ("." + xml->getStringAttribute ("class"));
  68148. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68149. if (index < 0)
  68150. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68151. if (index >= 0)
  68152. {
  68153. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68154. if (openBracket > index)
  68155. {
  68156. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68157. if (closeBracket > openBracket)
  68158. {
  68159. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68160. if (value.isNotEmpty())
  68161. return value;
  68162. }
  68163. }
  68164. }
  68165. }
  68166. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68167. if (xml != 0)
  68168. return getStyleAttribute (xml, attributeName, defaultValue);
  68169. return defaultValue;
  68170. }
  68171. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68172. {
  68173. if (xml->hasAttribute (attributeName))
  68174. return xml->getStringAttribute (attributeName);
  68175. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68176. if (xml != 0)
  68177. return getInheritedAttribute (xml, attributeName);
  68178. return String::empty;
  68179. }
  68180. static bool isIdentifierChar (const juce_wchar c)
  68181. {
  68182. return CharacterFunctions::isLetter (c) || c == '-';
  68183. }
  68184. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68185. {
  68186. int i = 0;
  68187. for (;;)
  68188. {
  68189. i = list.indexOf (i, attributeName);
  68190. if (i < 0)
  68191. break;
  68192. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68193. && ! isIdentifierChar (list [i + attributeName.length()]))
  68194. {
  68195. i = list.indexOfChar (i, ':');
  68196. if (i < 0)
  68197. break;
  68198. int end = list.indexOfChar (i, ';');
  68199. if (end < 0)
  68200. end = 0x7ffff;
  68201. return list.substring (i + 1, end).trim();
  68202. }
  68203. ++i;
  68204. }
  68205. return defaultValue;
  68206. }
  68207. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68208. {
  68209. const juce_wchar* const s = source;
  68210. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68211. ++index;
  68212. int start = index;
  68213. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68214. ++index;
  68215. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68216. ++index;
  68217. if ((s[index] == 'e' || s[index] == 'E')
  68218. && (CharacterFunctions::isDigit (s[index + 1])
  68219. || s[index + 1] == '-'
  68220. || s[index + 1] == '+'))
  68221. {
  68222. index += 2;
  68223. while (CharacterFunctions::isDigit (s[index]))
  68224. ++index;
  68225. }
  68226. if (allowUnits)
  68227. {
  68228. while (CharacterFunctions::isLetter (s[index]))
  68229. ++index;
  68230. }
  68231. if (index == start)
  68232. return false;
  68233. value = String (s + start, index - start);
  68234. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68235. ++index;
  68236. return true;
  68237. }
  68238. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68239. {
  68240. if (s [index] == '#')
  68241. {
  68242. uint32 hex [6];
  68243. zeromem (hex, sizeof (hex));
  68244. int numChars = 0;
  68245. for (int i = 6; --i >= 0;)
  68246. {
  68247. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68248. if (hexValue >= 0)
  68249. hex [numChars++] = hexValue;
  68250. else
  68251. break;
  68252. }
  68253. if (numChars <= 3)
  68254. return Colour ((uint8) (hex [0] * 0x11),
  68255. (uint8) (hex [1] * 0x11),
  68256. (uint8) (hex [2] * 0x11));
  68257. else
  68258. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68259. (uint8) ((hex [2] << 4) + hex [3]),
  68260. (uint8) ((hex [4] << 4) + hex [5]));
  68261. }
  68262. else if (s [index] == 'r'
  68263. && s [index + 1] == 'g'
  68264. && s [index + 2] == 'b')
  68265. {
  68266. const int openBracket = s.indexOfChar (index, '(');
  68267. const int closeBracket = s.indexOfChar (openBracket, ')');
  68268. if (openBracket >= 3 && closeBracket > openBracket)
  68269. {
  68270. index = closeBracket;
  68271. StringArray tokens;
  68272. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68273. tokens.trim();
  68274. tokens.removeEmptyStrings();
  68275. if (tokens[0].containsChar ('%'))
  68276. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68277. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68278. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68279. else
  68280. return Colour ((uint8) tokens[0].getIntValue(),
  68281. (uint8) tokens[1].getIntValue(),
  68282. (uint8) tokens[2].getIntValue());
  68283. }
  68284. }
  68285. return Colours::findColourForName (s, defaultColour);
  68286. }
  68287. static const AffineTransform parseTransform (String t)
  68288. {
  68289. AffineTransform result;
  68290. while (t.isNotEmpty())
  68291. {
  68292. StringArray tokens;
  68293. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68294. .upToFirstOccurrenceOf (")", false, false),
  68295. ", ", String::empty);
  68296. tokens.removeEmptyStrings (true);
  68297. float numbers [6];
  68298. for (int i = 0; i < 6; ++i)
  68299. numbers[i] = tokens[i].getFloatValue();
  68300. AffineTransform trans;
  68301. if (t.startsWithIgnoreCase ("matrix"))
  68302. {
  68303. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68304. numbers[1], numbers[3], numbers[5]);
  68305. }
  68306. else if (t.startsWithIgnoreCase ("translate"))
  68307. {
  68308. jassert (tokens.size() == 2);
  68309. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68310. }
  68311. else if (t.startsWithIgnoreCase ("scale"))
  68312. {
  68313. if (tokens.size() == 1)
  68314. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68315. else
  68316. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68317. }
  68318. else if (t.startsWithIgnoreCase ("rotate"))
  68319. {
  68320. if (tokens.size() != 3)
  68321. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68322. else
  68323. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68324. numbers[1], numbers[2]);
  68325. }
  68326. else if (t.startsWithIgnoreCase ("skewX"))
  68327. {
  68328. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68329. 0.0f, 1.0f, 0.0f);
  68330. }
  68331. else if (t.startsWithIgnoreCase ("skewY"))
  68332. {
  68333. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68334. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68335. }
  68336. result = trans.followedBy (result);
  68337. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68338. }
  68339. return result;
  68340. }
  68341. static void endpointToCentreParameters (const double x1, const double y1,
  68342. const double x2, const double y2,
  68343. const double angle,
  68344. const bool largeArc, const bool sweep,
  68345. double& rx, double& ry,
  68346. double& centreX, double& centreY,
  68347. double& startAngle, double& deltaAngle)
  68348. {
  68349. const double midX = (x1 - x2) * 0.5;
  68350. const double midY = (y1 - y2) * 0.5;
  68351. const double cosAngle = cos (angle);
  68352. const double sinAngle = sin (angle);
  68353. const double xp = cosAngle * midX + sinAngle * midY;
  68354. const double yp = cosAngle * midY - sinAngle * midX;
  68355. const double xp2 = xp * xp;
  68356. const double yp2 = yp * yp;
  68357. double rx2 = rx * rx;
  68358. double ry2 = ry * ry;
  68359. const double s = (xp2 / rx2) + (yp2 / ry2);
  68360. double c;
  68361. if (s <= 1.0)
  68362. {
  68363. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68364. / (( rx2 * yp2) + (ry2 * xp2))));
  68365. if (largeArc == sweep)
  68366. c = -c;
  68367. }
  68368. else
  68369. {
  68370. const double s2 = sqrt (s);
  68371. rx *= s2;
  68372. ry *= s2;
  68373. rx2 = rx * rx;
  68374. ry2 = ry * ry;
  68375. c = 0;
  68376. }
  68377. const double cpx = ((rx * yp) / ry) * c;
  68378. const double cpy = ((-ry * xp) / rx) * c;
  68379. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68380. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68381. const double ux = (xp - cpx) / rx;
  68382. const double uy = (yp - cpy) / ry;
  68383. const double vx = (-xp - cpx) / rx;
  68384. const double vy = (-yp - cpy) / ry;
  68385. const double length = juce_hypot (ux, uy);
  68386. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68387. if (uy < 0)
  68388. startAngle = -startAngle;
  68389. startAngle += double_Pi * 0.5;
  68390. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68391. / (length * juce_hypot (vx, vy))));
  68392. if ((ux * vy) - (uy * vx) < 0)
  68393. deltaAngle = -deltaAngle;
  68394. if (sweep)
  68395. {
  68396. if (deltaAngle < 0)
  68397. deltaAngle += double_Pi * 2.0;
  68398. }
  68399. else
  68400. {
  68401. if (deltaAngle > 0)
  68402. deltaAngle -= double_Pi * 2.0;
  68403. }
  68404. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68405. }
  68406. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68407. {
  68408. forEachXmlChildElement (*parent, e)
  68409. {
  68410. if (e->compareAttribute ("id", id))
  68411. return e;
  68412. const XmlElement* const found = findElementForId (e, id);
  68413. if (found != 0)
  68414. return found;
  68415. }
  68416. return 0;
  68417. }
  68418. SVGState& operator= (const SVGState&);
  68419. };
  68420. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68421. {
  68422. SVGState state (&svgDocument);
  68423. return state.parseSVGElement (svgDocument);
  68424. }
  68425. END_JUCE_NAMESPACE
  68426. /*** End of inlined file: juce_SVGParser.cpp ***/
  68427. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68428. BEGIN_JUCE_NAMESPACE
  68429. #if JUCE_MSVC
  68430. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68431. #endif
  68432. DropShadowEffect::DropShadowEffect()
  68433. : offsetX (0),
  68434. offsetY (0),
  68435. radius (4),
  68436. opacity (0.6f)
  68437. {
  68438. }
  68439. DropShadowEffect::~DropShadowEffect()
  68440. {
  68441. }
  68442. void DropShadowEffect::setShadowProperties (const float newRadius,
  68443. const float newOpacity,
  68444. const int newShadowOffsetX,
  68445. const int newShadowOffsetY)
  68446. {
  68447. radius = jmax (1.1f, newRadius);
  68448. offsetX = newShadowOffsetX;
  68449. offsetY = newShadowOffsetY;
  68450. opacity = newOpacity;
  68451. }
  68452. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68453. {
  68454. const int w = image.getWidth();
  68455. const int h = image.getHeight();
  68456. Image shadowImage (Image::SingleChannel, w, h, false);
  68457. const Image::BitmapData srcData (image, 0, 0, w, h);
  68458. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68459. const int filter = roundToInt (63.0f / radius);
  68460. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68461. for (int x = w; --x >= 0;)
  68462. {
  68463. int shadowAlpha = 0;
  68464. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68465. uint8* shadowPix = destData.data + x;
  68466. for (int y = h; --y >= 0;)
  68467. {
  68468. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68469. *shadowPix = (uint8) shadowAlpha;
  68470. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68471. shadowPix += destData.lineStride;
  68472. }
  68473. }
  68474. for (int y = h; --y >= 0;)
  68475. {
  68476. int shadowAlpha = 0;
  68477. uint8* shadowPix = destData.getLinePointer (y);
  68478. for (int x = w; --x >= 0;)
  68479. {
  68480. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68481. *shadowPix++ = (uint8) shadowAlpha;
  68482. }
  68483. }
  68484. g.setColour (Colours::black.withAlpha (opacity));
  68485. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68486. g.setOpacity (1.0f);
  68487. g.drawImageAt (&image, 0, 0);
  68488. }
  68489. END_JUCE_NAMESPACE
  68490. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68491. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68492. BEGIN_JUCE_NAMESPACE
  68493. GlowEffect::GlowEffect()
  68494. : radius (2.0f),
  68495. colour (Colours::white)
  68496. {
  68497. }
  68498. GlowEffect::~GlowEffect()
  68499. {
  68500. }
  68501. void GlowEffect::setGlowProperties (const float newRadius,
  68502. const Colour& newColour)
  68503. {
  68504. radius = newRadius;
  68505. colour = newColour;
  68506. }
  68507. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68508. {
  68509. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68510. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68511. blurKernel.createGaussianBlur (radius);
  68512. blurKernel.rescaleAllValues (radius);
  68513. blurKernel.applyToImage (temp, &image, image.getBounds());
  68514. g.setColour (colour);
  68515. g.drawImageAt (&temp, 0, 0, true);
  68516. g.setOpacity (1.0f);
  68517. g.drawImageAt (&image, 0, 0, false);
  68518. }
  68519. END_JUCE_NAMESPACE
  68520. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68521. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68522. BEGIN_JUCE_NAMESPACE
  68523. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68524. : opacity (opacity_)
  68525. {
  68526. }
  68527. ReduceOpacityEffect::~ReduceOpacityEffect()
  68528. {
  68529. }
  68530. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68531. {
  68532. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68533. }
  68534. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68535. {
  68536. g.setOpacity (opacity);
  68537. g.drawImageAt (&image, 0, 0);
  68538. }
  68539. END_JUCE_NAMESPACE
  68540. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68541. /*** Start of inlined file: juce_Font.cpp ***/
  68542. BEGIN_JUCE_NAMESPACE
  68543. namespace FontValues
  68544. {
  68545. static float limitFontHeight (const float height) throw()
  68546. {
  68547. return jlimit (0.1f, 10000.0f, height);
  68548. }
  68549. static const float defaultFontHeight = 14.0f;
  68550. }
  68551. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68552. const float kerning_, const float ascent_, const int styleFlags_,
  68553. Typeface* const typeface_) throw()
  68554. : typefaceName (typefaceName_),
  68555. height (height_),
  68556. horizontalScale (horizontalScale_),
  68557. kerning (kerning_),
  68558. ascent (ascent_),
  68559. styleFlags (styleFlags_),
  68560. typeface (typeface_)
  68561. {
  68562. }
  68563. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68564. : typefaceName (other.typefaceName),
  68565. height (other.height),
  68566. horizontalScale (other.horizontalScale),
  68567. kerning (other.kerning),
  68568. ascent (other.ascent),
  68569. styleFlags (other.styleFlags),
  68570. typeface (other.typeface)
  68571. {
  68572. }
  68573. Font::Font() throw()
  68574. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68575. 1.0f, 0, 0, Font::plain, 0))
  68576. {
  68577. }
  68578. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68579. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68580. 1.0f, 0, 0, styleFlags_, 0))
  68581. {
  68582. }
  68583. Font::Font (const String& typefaceName_,
  68584. const float fontHeight,
  68585. const int styleFlags_) throw()
  68586. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68587. 1.0f, 0, 0, styleFlags_, 0))
  68588. {
  68589. }
  68590. Font::Font (const Font& other) throw()
  68591. : font (other.font)
  68592. {
  68593. }
  68594. Font& Font::operator= (const Font& other) throw()
  68595. {
  68596. font = other.font;
  68597. return *this;
  68598. }
  68599. Font::~Font() throw()
  68600. {
  68601. }
  68602. Font::Font (const Typeface::Ptr& typeface) throw()
  68603. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68604. 1.0f, 0, 0, Font::plain, typeface))
  68605. {
  68606. }
  68607. bool Font::operator== (const Font& other) const throw()
  68608. {
  68609. return font == other.font
  68610. || (font->height == other.font->height
  68611. && font->styleFlags == other.font->styleFlags
  68612. && font->horizontalScale == other.font->horizontalScale
  68613. && font->kerning == other.font->kerning
  68614. && font->typefaceName == other.font->typefaceName);
  68615. }
  68616. bool Font::operator!= (const Font& other) const throw()
  68617. {
  68618. return ! operator== (other);
  68619. }
  68620. void Font::dupeInternalIfShared() throw()
  68621. {
  68622. if (font->getReferenceCount() > 1)
  68623. font = new SharedFontInternal (*font);
  68624. }
  68625. const String Font::getDefaultSansSerifFontName() throw()
  68626. {
  68627. static const String name ("<Sans-Serif>");
  68628. return name;
  68629. }
  68630. const String Font::getDefaultSerifFontName() throw()
  68631. {
  68632. static const String name ("<Serif>");
  68633. return name;
  68634. }
  68635. const String Font::getDefaultMonospacedFontName() throw()
  68636. {
  68637. static const String name ("<Monospaced>");
  68638. return name;
  68639. }
  68640. void Font::setTypefaceName (const String& faceName) throw()
  68641. {
  68642. if (faceName != font->typefaceName)
  68643. {
  68644. dupeInternalIfShared();
  68645. font->typefaceName = faceName;
  68646. font->typeface = 0;
  68647. font->ascent = 0;
  68648. }
  68649. }
  68650. static String fallbackFont;
  68651. const String Font::getFallbackFontName() throw()
  68652. {
  68653. return fallbackFont;
  68654. }
  68655. void Font::setFallbackFontName (const String& name) throw()
  68656. {
  68657. fallbackFont = name;
  68658. }
  68659. void Font::setHeight (float newHeight) throw()
  68660. {
  68661. newHeight = FontValues::limitFontHeight (newHeight);
  68662. if (font->height != newHeight)
  68663. {
  68664. dupeInternalIfShared();
  68665. font->height = newHeight;
  68666. }
  68667. }
  68668. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68669. {
  68670. newHeight = FontValues::limitFontHeight (newHeight);
  68671. if (font->height != newHeight)
  68672. {
  68673. dupeInternalIfShared();
  68674. font->horizontalScale *= (font->height / newHeight);
  68675. font->height = newHeight;
  68676. }
  68677. }
  68678. void Font::setStyleFlags (const int newFlags) throw()
  68679. {
  68680. if (font->styleFlags != newFlags)
  68681. {
  68682. dupeInternalIfShared();
  68683. font->styleFlags = newFlags;
  68684. font->typeface = 0;
  68685. font->ascent = 0;
  68686. }
  68687. }
  68688. void Font::setSizeAndStyle (float newHeight,
  68689. const int newStyleFlags,
  68690. const float newHorizontalScale,
  68691. const float newKerningAmount) throw()
  68692. {
  68693. newHeight = FontValues::limitFontHeight (newHeight);
  68694. if (font->height != newHeight
  68695. || font->horizontalScale != newHorizontalScale
  68696. || font->kerning != newKerningAmount)
  68697. {
  68698. dupeInternalIfShared();
  68699. font->height = newHeight;
  68700. font->horizontalScale = newHorizontalScale;
  68701. font->kerning = newKerningAmount;
  68702. }
  68703. setStyleFlags (newStyleFlags);
  68704. }
  68705. void Font::setHorizontalScale (const float scaleFactor) throw()
  68706. {
  68707. dupeInternalIfShared();
  68708. font->horizontalScale = scaleFactor;
  68709. }
  68710. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68711. {
  68712. dupeInternalIfShared();
  68713. font->kerning = extraKerning;
  68714. }
  68715. void Font::setBold (const bool shouldBeBold) throw()
  68716. {
  68717. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68718. : (font->styleFlags & ~bold));
  68719. }
  68720. bool Font::isBold() const throw()
  68721. {
  68722. return (font->styleFlags & bold) != 0;
  68723. }
  68724. void Font::setItalic (const bool shouldBeItalic) throw()
  68725. {
  68726. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68727. : (font->styleFlags & ~italic));
  68728. }
  68729. bool Font::isItalic() const throw()
  68730. {
  68731. return (font->styleFlags & italic) != 0;
  68732. }
  68733. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68734. {
  68735. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68736. : (font->styleFlags & ~underlined));
  68737. }
  68738. bool Font::isUnderlined() const throw()
  68739. {
  68740. return (font->styleFlags & underlined) != 0;
  68741. }
  68742. float Font::getAscent() const throw()
  68743. {
  68744. if (font->ascent == 0)
  68745. font->ascent = getTypeface()->getAscent();
  68746. return font->height * font->ascent;
  68747. }
  68748. float Font::getDescent() const throw()
  68749. {
  68750. return font->height - getAscent();
  68751. }
  68752. int Font::getStringWidth (const String& text) const throw()
  68753. {
  68754. return roundToInt (getStringWidthFloat (text));
  68755. }
  68756. float Font::getStringWidthFloat (const String& text) const throw()
  68757. {
  68758. float w = getTypeface()->getStringWidth (text);
  68759. if (font->kerning != 0)
  68760. w += font->kerning * text.length();
  68761. return w * font->height * font->horizontalScale;
  68762. }
  68763. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68764. {
  68765. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68766. const float scale = font->height * font->horizontalScale;
  68767. const int num = xOffsets.size();
  68768. if (num > 0)
  68769. {
  68770. float* const x = &(xOffsets.getReference(0));
  68771. if (font->kerning != 0)
  68772. {
  68773. for (int i = 0; i < num; ++i)
  68774. x[i] = (x[i] + i * font->kerning) * scale;
  68775. }
  68776. else
  68777. {
  68778. for (int i = 0; i < num; ++i)
  68779. x[i] *= scale;
  68780. }
  68781. }
  68782. }
  68783. void Font::findFonts (Array<Font>& destArray) throw()
  68784. {
  68785. const StringArray names (findAllTypefaceNames());
  68786. for (int i = 0; i < names.size(); ++i)
  68787. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68788. }
  68789. class TypefaceCache : public DeletedAtShutdown
  68790. {
  68791. public:
  68792. TypefaceCache (int numToCache = 10) throw()
  68793. : counter (1)
  68794. {
  68795. while (--numToCache >= 0)
  68796. faces.add (new CachedFace());
  68797. }
  68798. ~TypefaceCache()
  68799. {
  68800. clearSingletonInstance();
  68801. }
  68802. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68803. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68804. {
  68805. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68806. const String faceName (font.getTypefaceName());
  68807. int i;
  68808. for (i = faces.size(); --i >= 0;)
  68809. {
  68810. CachedFace* const face = faces.getUnchecked(i);
  68811. if (face->flags == flags
  68812. && face->typefaceName == faceName)
  68813. {
  68814. face->lastUsageCount = ++counter;
  68815. return face->typeFace;
  68816. }
  68817. }
  68818. int replaceIndex = 0;
  68819. int bestLastUsageCount = std::numeric_limits<int>::max();
  68820. for (i = faces.size(); --i >= 0;)
  68821. {
  68822. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68823. if (bestLastUsageCount > lu)
  68824. {
  68825. bestLastUsageCount = lu;
  68826. replaceIndex = i;
  68827. }
  68828. }
  68829. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68830. face->typefaceName = faceName;
  68831. face->flags = flags;
  68832. face->lastUsageCount = ++counter;
  68833. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68834. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68835. return face->typeFace;
  68836. }
  68837. juce_UseDebuggingNewOperator
  68838. private:
  68839. struct CachedFace
  68840. {
  68841. CachedFace() throw()
  68842. : lastUsageCount (0), flags (-1)
  68843. {
  68844. }
  68845. String typefaceName;
  68846. int lastUsageCount;
  68847. int flags;
  68848. Typeface::Ptr typeFace;
  68849. };
  68850. int counter;
  68851. OwnedArray <CachedFace> faces;
  68852. TypefaceCache (const TypefaceCache&);
  68853. TypefaceCache& operator= (const TypefaceCache&);
  68854. };
  68855. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68856. Typeface* Font::getTypeface() const throw()
  68857. {
  68858. if (font->typeface == 0)
  68859. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68860. return font->typeface;
  68861. }
  68862. END_JUCE_NAMESPACE
  68863. /*** End of inlined file: juce_Font.cpp ***/
  68864. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68865. BEGIN_JUCE_NAMESPACE
  68866. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68867. const juce_wchar character_, const int glyph_)
  68868. : x (x_),
  68869. y (y_),
  68870. w (w_),
  68871. font (font_),
  68872. character (character_),
  68873. glyph (glyph_)
  68874. {
  68875. }
  68876. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68877. : x (other.x),
  68878. y (other.y),
  68879. w (other.w),
  68880. font (other.font),
  68881. character (other.character),
  68882. glyph (other.glyph)
  68883. {
  68884. }
  68885. void PositionedGlyph::draw (const Graphics& g) const
  68886. {
  68887. if (! isWhitespace())
  68888. {
  68889. g.getInternalContext()->setFont (font);
  68890. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68891. }
  68892. }
  68893. void PositionedGlyph::draw (const Graphics& g,
  68894. const AffineTransform& transform) const
  68895. {
  68896. if (! isWhitespace())
  68897. {
  68898. g.getInternalContext()->setFont (font);
  68899. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68900. .followedBy (transform));
  68901. }
  68902. }
  68903. void PositionedGlyph::createPath (Path& path) const
  68904. {
  68905. if (! isWhitespace())
  68906. {
  68907. Typeface* const t = font.getTypeface();
  68908. if (t != 0)
  68909. {
  68910. Path p;
  68911. t->getOutlineForGlyph (glyph, p);
  68912. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68913. .translated (x, y));
  68914. }
  68915. }
  68916. }
  68917. bool PositionedGlyph::hitTest (float px, float py) const
  68918. {
  68919. if (getBounds().contains (px, py) && ! isWhitespace())
  68920. {
  68921. Typeface* const t = font.getTypeface();
  68922. if (t != 0)
  68923. {
  68924. Path p;
  68925. t->getOutlineForGlyph (glyph, p);
  68926. AffineTransform::translation (-x, -y)
  68927. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68928. .transformPoint (px, py);
  68929. return p.contains (px, py);
  68930. }
  68931. }
  68932. return false;
  68933. }
  68934. void PositionedGlyph::moveBy (const float deltaX,
  68935. const float deltaY)
  68936. {
  68937. x += deltaX;
  68938. y += deltaY;
  68939. }
  68940. GlyphArrangement::GlyphArrangement()
  68941. {
  68942. glyphs.ensureStorageAllocated (128);
  68943. }
  68944. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  68945. {
  68946. addGlyphArrangement (other);
  68947. }
  68948. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  68949. {
  68950. if (this != &other)
  68951. {
  68952. clear();
  68953. addGlyphArrangement (other);
  68954. }
  68955. return *this;
  68956. }
  68957. GlyphArrangement::~GlyphArrangement()
  68958. {
  68959. }
  68960. void GlyphArrangement::clear()
  68961. {
  68962. glyphs.clear();
  68963. }
  68964. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  68965. {
  68966. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  68967. return *glyphs [index];
  68968. }
  68969. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  68970. {
  68971. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  68972. for (int i = 0; i < other.glyphs.size(); ++i)
  68973. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  68974. }
  68975. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  68976. {
  68977. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  68978. }
  68979. void GlyphArrangement::addLineOfText (const Font& font,
  68980. const String& text,
  68981. const float xOffset,
  68982. const float yOffset)
  68983. {
  68984. addCurtailedLineOfText (font, text,
  68985. xOffset, yOffset,
  68986. 1.0e10f, false);
  68987. }
  68988. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  68989. const String& text,
  68990. float xOffset,
  68991. const float yOffset,
  68992. const float maxWidthPixels,
  68993. const bool useEllipsis)
  68994. {
  68995. if (text.isNotEmpty())
  68996. {
  68997. Array <int> newGlyphs;
  68998. Array <float> xOffsets;
  68999. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69000. const int textLen = newGlyphs.size();
  69001. const juce_wchar* const unicodeText = text;
  69002. for (int i = 0; i < textLen; ++i)
  69003. {
  69004. const float thisX = xOffsets.getUnchecked (i);
  69005. const float nextX = xOffsets.getUnchecked (i + 1);
  69006. if (nextX > maxWidthPixels + 1.0f)
  69007. {
  69008. // curtail the string if it's too wide..
  69009. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69010. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69011. break;
  69012. }
  69013. else
  69014. {
  69015. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69016. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69017. }
  69018. }
  69019. }
  69020. }
  69021. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69022. const int startIndex, int endIndex)
  69023. {
  69024. int numDeleted = 0;
  69025. if (glyphs.size() > 0)
  69026. {
  69027. Array<int> dotGlyphs;
  69028. Array<float> dotXs;
  69029. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  69030. const float dx = dotXs[1];
  69031. float xOffset = 0.0f, yOffset = 0.0f;
  69032. while (endIndex > startIndex)
  69033. {
  69034. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69035. xOffset = pg->x;
  69036. yOffset = pg->y;
  69037. glyphs.remove (endIndex);
  69038. ++numDeleted;
  69039. if (xOffset + dx * 3 <= maxXPos)
  69040. break;
  69041. }
  69042. for (int i = 3; --i >= 0;)
  69043. {
  69044. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69045. font, '.', dotGlyphs.getFirst()));
  69046. --numDeleted;
  69047. xOffset += dx;
  69048. if (xOffset > maxXPos)
  69049. break;
  69050. }
  69051. }
  69052. return numDeleted;
  69053. }
  69054. void GlyphArrangement::addJustifiedText (const Font& font,
  69055. const String& text,
  69056. float x, float y,
  69057. const float maxLineWidth,
  69058. const Justification& horizontalLayout)
  69059. {
  69060. int lineStartIndex = glyphs.size();
  69061. addLineOfText (font, text, x, y);
  69062. const float originalY = y;
  69063. while (lineStartIndex < glyphs.size())
  69064. {
  69065. int i = lineStartIndex;
  69066. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69067. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69068. ++i;
  69069. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69070. int lastWordBreakIndex = -1;
  69071. while (i < glyphs.size())
  69072. {
  69073. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69074. const juce_wchar c = pg->getCharacter();
  69075. if (c == '\r' || c == '\n')
  69076. {
  69077. ++i;
  69078. if (c == '\r' && i < glyphs.size()
  69079. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69080. ++i;
  69081. break;
  69082. }
  69083. else if (pg->isWhitespace())
  69084. {
  69085. lastWordBreakIndex = i + 1;
  69086. }
  69087. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69088. {
  69089. if (lastWordBreakIndex >= 0)
  69090. i = lastWordBreakIndex;
  69091. break;
  69092. }
  69093. ++i;
  69094. }
  69095. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69096. float currentLineEndX = currentLineStartX;
  69097. for (int j = i; --j >= lineStartIndex;)
  69098. {
  69099. if (! glyphs.getUnchecked (j)->isWhitespace())
  69100. {
  69101. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69102. break;
  69103. }
  69104. }
  69105. float deltaX = 0.0f;
  69106. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69107. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69108. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69109. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69110. else if (horizontalLayout.testFlags (Justification::right))
  69111. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69112. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69113. x + deltaX - currentLineStartX, y - originalY);
  69114. lineStartIndex = i;
  69115. y += font.getHeight();
  69116. }
  69117. }
  69118. void GlyphArrangement::addFittedText (const Font& f,
  69119. const String& text,
  69120. const float x, const float y,
  69121. const float width, const float height,
  69122. const Justification& layout,
  69123. int maximumLines,
  69124. const float minimumHorizontalScale)
  69125. {
  69126. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69127. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69128. if (text.containsAnyOf ("\r\n"))
  69129. {
  69130. GlyphArrangement ga;
  69131. ga.addJustifiedText (f, text, x, y, width, layout);
  69132. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  69133. float dy = y - bb.getY();
  69134. if (layout.testFlags (Justification::verticallyCentred))
  69135. dy += (height - bb.getHeight()) * 0.5f;
  69136. else if (layout.testFlags (Justification::bottom))
  69137. dy += height - bb.getHeight();
  69138. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69139. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69140. for (int i = 0; i < ga.glyphs.size(); ++i)
  69141. glyphs.add (ga.glyphs.getUnchecked (i));
  69142. ga.glyphs.clear (false);
  69143. return;
  69144. }
  69145. int startIndex = glyphs.size();
  69146. addLineOfText (f, text.trim(), x, y);
  69147. if (glyphs.size() > startIndex)
  69148. {
  69149. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69150. - glyphs.getUnchecked (startIndex)->getLeft();
  69151. if (lineWidth <= 0)
  69152. return;
  69153. if (lineWidth * minimumHorizontalScale < width)
  69154. {
  69155. if (lineWidth > width)
  69156. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69157. width / lineWidth);
  69158. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69159. x, y, width, height, layout);
  69160. }
  69161. else if (maximumLines <= 1)
  69162. {
  69163. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69164. x, y, width, height, f, layout, minimumHorizontalScale);
  69165. }
  69166. else
  69167. {
  69168. Font font (f);
  69169. String txt (text.trim());
  69170. const int length = txt.length();
  69171. const int originalStartIndex = startIndex;
  69172. int numLines = 1;
  69173. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69174. maximumLines = 1;
  69175. maximumLines = jmin (maximumLines, length);
  69176. while (numLines < maximumLines)
  69177. {
  69178. ++numLines;
  69179. const float newFontHeight = height / (float) numLines;
  69180. if (newFontHeight < font.getHeight())
  69181. {
  69182. font.setHeight (jmax (8.0f, newFontHeight));
  69183. removeRangeOfGlyphs (startIndex, -1);
  69184. addLineOfText (font, txt, x, y);
  69185. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69186. - glyphs.getUnchecked (startIndex)->getLeft();
  69187. }
  69188. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69189. break;
  69190. }
  69191. if (numLines < 1)
  69192. numLines = 1;
  69193. float lineY = y;
  69194. float widthPerLine = lineWidth / numLines;
  69195. int lastLineStartIndex = 0;
  69196. for (int line = 0; line < numLines; ++line)
  69197. {
  69198. int i = startIndex;
  69199. lastLineStartIndex = i;
  69200. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69201. if (line == numLines - 1)
  69202. {
  69203. widthPerLine = width;
  69204. i = glyphs.size();
  69205. }
  69206. else
  69207. {
  69208. while (i < glyphs.size())
  69209. {
  69210. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69211. if (lineWidth > widthPerLine)
  69212. {
  69213. // got to a point where the line's too long, so skip forward to find a
  69214. // good place to break it..
  69215. const int searchStartIndex = i;
  69216. while (i < glyphs.size())
  69217. {
  69218. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69219. {
  69220. if (glyphs.getUnchecked (i)->isWhitespace()
  69221. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69222. {
  69223. ++i;
  69224. break;
  69225. }
  69226. }
  69227. else
  69228. {
  69229. // can't find a suitable break, so try looking backwards..
  69230. i = searchStartIndex;
  69231. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69232. {
  69233. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69234. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69235. {
  69236. i -= back - 1;
  69237. break;
  69238. }
  69239. }
  69240. break;
  69241. }
  69242. ++i;
  69243. }
  69244. break;
  69245. }
  69246. ++i;
  69247. }
  69248. int wsStart = i;
  69249. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69250. --wsStart;
  69251. int wsEnd = i;
  69252. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69253. ++wsEnd;
  69254. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69255. i = jmax (wsStart, startIndex + 1);
  69256. }
  69257. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69258. x, lineY, width, font.getHeight(), font,
  69259. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69260. minimumHorizontalScale);
  69261. startIndex = i;
  69262. lineY += font.getHeight();
  69263. if (startIndex >= glyphs.size())
  69264. break;
  69265. }
  69266. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69267. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69268. }
  69269. }
  69270. }
  69271. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69272. const float dx, const float dy)
  69273. {
  69274. jassert (startIndex >= 0);
  69275. if (dx != 0.0f || dy != 0.0f)
  69276. {
  69277. if (num < 0 || startIndex + num > glyphs.size())
  69278. num = glyphs.size() - startIndex;
  69279. while (--num >= 0)
  69280. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69281. }
  69282. }
  69283. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69284. const Justification& justification, float minimumHorizontalScale)
  69285. {
  69286. int numDeleted = 0;
  69287. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69288. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69289. if (lineWidth > w)
  69290. {
  69291. if (minimumHorizontalScale < 1.0f)
  69292. {
  69293. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69294. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69295. }
  69296. if (lineWidth > w)
  69297. {
  69298. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69299. numGlyphs -= numDeleted;
  69300. }
  69301. }
  69302. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69303. return numDeleted;
  69304. }
  69305. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69306. const float horizontalScaleFactor)
  69307. {
  69308. jassert (startIndex >= 0);
  69309. if (num < 0 || startIndex + num > glyphs.size())
  69310. num = glyphs.size() - startIndex;
  69311. if (num > 0)
  69312. {
  69313. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69314. while (--num >= 0)
  69315. {
  69316. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69317. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69318. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69319. pg->w *= horizontalScaleFactor;
  69320. }
  69321. }
  69322. }
  69323. const Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  69324. {
  69325. jassert (startIndex >= 0);
  69326. if (num < 0 || startIndex + num > glyphs.size())
  69327. num = glyphs.size() - startIndex;
  69328. Rectangle<float> result;
  69329. bool isFirst = true;
  69330. while (--num >= 0)
  69331. {
  69332. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69333. if (includeWhitespace || ! pg->isWhitespace())
  69334. {
  69335. if (isFirst)
  69336. {
  69337. isFirst = false;
  69338. result = pg->getBounds();
  69339. }
  69340. else
  69341. {
  69342. result = result.getUnion (pg->getBounds());
  69343. }
  69344. }
  69345. }
  69346. return result;
  69347. }
  69348. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  69349. const float x, const float y, const float width, const float height,
  69350. const Justification& justification)
  69351. {
  69352. jassert (num >= 0 && startIndex >= 0);
  69353. if (glyphs.size() > 0 && num > 0)
  69354. {
  69355. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  69356. | Justification::horizontallyCentred)));
  69357. float deltaX = 0.0f;
  69358. if (justification.testFlags (Justification::horizontallyJustified))
  69359. deltaX = x - bb.getX();
  69360. else if (justification.testFlags (Justification::horizontallyCentred))
  69361. deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  69362. else if (justification.testFlags (Justification::right))
  69363. deltaX = (x + width) - bb.getRight();
  69364. else
  69365. deltaX = x - bb.getX();
  69366. float deltaY = 0.0f;
  69367. if (justification.testFlags (Justification::top))
  69368. deltaY = y - bb.getY();
  69369. else if (justification.testFlags (Justification::bottom))
  69370. deltaY = (y + height) - bb.getBottom();
  69371. else
  69372. deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  69373. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69374. if (justification.testFlags (Justification::horizontallyJustified))
  69375. {
  69376. int lineStart = 0;
  69377. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69378. int i;
  69379. for (i = 0; i < num; ++i)
  69380. {
  69381. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69382. if (glyphY != baseY)
  69383. {
  69384. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69385. lineStart = i;
  69386. baseY = glyphY;
  69387. }
  69388. }
  69389. if (i > lineStart)
  69390. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69391. }
  69392. }
  69393. }
  69394. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69395. {
  69396. if (start + num < glyphs.size()
  69397. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69398. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69399. {
  69400. int numSpaces = 0;
  69401. int spacesAtEnd = 0;
  69402. for (int i = 0; i < num; ++i)
  69403. {
  69404. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69405. {
  69406. ++spacesAtEnd;
  69407. ++numSpaces;
  69408. }
  69409. else
  69410. {
  69411. spacesAtEnd = 0;
  69412. }
  69413. }
  69414. numSpaces -= spacesAtEnd;
  69415. if (numSpaces > 0)
  69416. {
  69417. const float startX = glyphs.getUnchecked (start)->getLeft();
  69418. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69419. const float extraPaddingBetweenWords
  69420. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69421. float deltaX = 0.0f;
  69422. for (int i = 0; i < num; ++i)
  69423. {
  69424. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69425. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69426. deltaX += extraPaddingBetweenWords;
  69427. }
  69428. }
  69429. }
  69430. }
  69431. void GlyphArrangement::draw (const Graphics& g) const
  69432. {
  69433. for (int i = 0; i < glyphs.size(); ++i)
  69434. {
  69435. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69436. if (pg->font.isUnderlined())
  69437. {
  69438. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69439. float nextX = pg->x + pg->w;
  69440. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69441. nextX = glyphs.getUnchecked (i + 1)->x;
  69442. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69443. nextX - pg->x, lineThickness);
  69444. }
  69445. pg->draw (g);
  69446. }
  69447. }
  69448. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69449. {
  69450. for (int i = 0; i < glyphs.size(); ++i)
  69451. {
  69452. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69453. if (pg->font.isUnderlined())
  69454. {
  69455. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69456. float nextX = pg->x + pg->w;
  69457. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69458. nextX = glyphs.getUnchecked (i + 1)->x;
  69459. Path p;
  69460. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69461. nextX, pg->y + lineThickness * 2.0f,
  69462. lineThickness);
  69463. g.fillPath (p, transform);
  69464. }
  69465. pg->draw (g, transform);
  69466. }
  69467. }
  69468. void GlyphArrangement::createPath (Path& path) const
  69469. {
  69470. for (int i = 0; i < glyphs.size(); ++i)
  69471. glyphs.getUnchecked (i)->createPath (path);
  69472. }
  69473. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69474. {
  69475. for (int i = 0; i < glyphs.size(); ++i)
  69476. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69477. return i;
  69478. return -1;
  69479. }
  69480. END_JUCE_NAMESPACE
  69481. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69482. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69483. BEGIN_JUCE_NAMESPACE
  69484. class TextLayout::Token
  69485. {
  69486. public:
  69487. String text;
  69488. Font font;
  69489. int x, y, w, h;
  69490. int line, lineHeight;
  69491. bool isWhitespace, isNewLine;
  69492. Token (const String& t,
  69493. const Font& f,
  69494. const bool isWhitespace_)
  69495. : text (t),
  69496. font (f),
  69497. x(0),
  69498. y(0),
  69499. isWhitespace (isWhitespace_)
  69500. {
  69501. w = font.getStringWidth (t);
  69502. h = roundToInt (f.getHeight());
  69503. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69504. }
  69505. Token (const Token& other)
  69506. : text (other.text),
  69507. font (other.font),
  69508. x (other.x),
  69509. y (other.y),
  69510. w (other.w),
  69511. h (other.h),
  69512. line (other.line),
  69513. lineHeight (other.lineHeight),
  69514. isWhitespace (other.isWhitespace),
  69515. isNewLine (other.isNewLine)
  69516. {
  69517. }
  69518. ~Token()
  69519. {
  69520. }
  69521. void draw (Graphics& g,
  69522. const int xOffset,
  69523. const int yOffset)
  69524. {
  69525. if (! isWhitespace)
  69526. {
  69527. g.setFont (font);
  69528. g.drawSingleLineText (text.trimEnd(),
  69529. xOffset + x,
  69530. yOffset + y + (lineHeight - h)
  69531. + roundToInt (font.getAscent()));
  69532. }
  69533. }
  69534. juce_UseDebuggingNewOperator
  69535. };
  69536. TextLayout::TextLayout()
  69537. : totalLines (0)
  69538. {
  69539. tokens.ensureStorageAllocated (64);
  69540. }
  69541. TextLayout::TextLayout (const String& text, const Font& font)
  69542. : totalLines (0)
  69543. {
  69544. tokens.ensureStorageAllocated (64);
  69545. appendText (text, font);
  69546. }
  69547. TextLayout::TextLayout (const TextLayout& other)
  69548. : totalLines (0)
  69549. {
  69550. *this = other;
  69551. }
  69552. TextLayout& TextLayout::operator= (const TextLayout& other)
  69553. {
  69554. if (this != &other)
  69555. {
  69556. clear();
  69557. totalLines = other.totalLines;
  69558. for (int i = 0; i < other.tokens.size(); ++i)
  69559. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69560. }
  69561. return *this;
  69562. }
  69563. TextLayout::~TextLayout()
  69564. {
  69565. clear();
  69566. }
  69567. void TextLayout::clear()
  69568. {
  69569. tokens.clear();
  69570. totalLines = 0;
  69571. }
  69572. void TextLayout::appendText (const String& text, const Font& font)
  69573. {
  69574. const juce_wchar* t = text;
  69575. String currentString;
  69576. int lastCharType = 0;
  69577. for (;;)
  69578. {
  69579. const juce_wchar c = *t++;
  69580. if (c == 0)
  69581. break;
  69582. int charType;
  69583. if (c == '\r' || c == '\n')
  69584. {
  69585. charType = 0;
  69586. }
  69587. else if (CharacterFunctions::isWhitespace (c))
  69588. {
  69589. charType = 2;
  69590. }
  69591. else
  69592. {
  69593. charType = 1;
  69594. }
  69595. if (charType == 0 || charType != lastCharType)
  69596. {
  69597. if (currentString.isNotEmpty())
  69598. {
  69599. tokens.add (new Token (currentString, font,
  69600. lastCharType == 2 || lastCharType == 0));
  69601. }
  69602. currentString = String::charToString (c);
  69603. if (c == '\r' && *t == '\n')
  69604. currentString += *t++;
  69605. }
  69606. else
  69607. {
  69608. currentString += c;
  69609. }
  69610. lastCharType = charType;
  69611. }
  69612. if (currentString.isNotEmpty())
  69613. tokens.add (new Token (currentString, font, lastCharType == 2));
  69614. }
  69615. void TextLayout::setText (const String& text, const Font& font)
  69616. {
  69617. clear();
  69618. appendText (text, font);
  69619. }
  69620. void TextLayout::layout (int maxWidth,
  69621. const Justification& justification,
  69622. const bool attemptToBalanceLineLengths)
  69623. {
  69624. if (attemptToBalanceLineLengths)
  69625. {
  69626. const int originalW = maxWidth;
  69627. int bestWidth = maxWidth;
  69628. float bestLineProportion = 0.0f;
  69629. while (maxWidth > originalW / 2)
  69630. {
  69631. layout (maxWidth, justification, false);
  69632. if (getNumLines() <= 1)
  69633. return;
  69634. const int lastLineW = getLineWidth (getNumLines() - 1);
  69635. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69636. const float prop = lastLineW / (float) lastButOneLineW;
  69637. if (prop > 0.9f)
  69638. return;
  69639. if (prop > bestLineProportion)
  69640. {
  69641. bestLineProportion = prop;
  69642. bestWidth = maxWidth;
  69643. }
  69644. maxWidth -= 10;
  69645. }
  69646. layout (bestWidth, justification, false);
  69647. }
  69648. else
  69649. {
  69650. int x = 0;
  69651. int y = 0;
  69652. int h = 0;
  69653. totalLines = 0;
  69654. int i;
  69655. for (i = 0; i < tokens.size(); ++i)
  69656. {
  69657. Token* const t = tokens.getUnchecked(i);
  69658. t->x = x;
  69659. t->y = y;
  69660. t->line = totalLines;
  69661. x += t->w;
  69662. h = jmax (h, t->h);
  69663. const Token* nextTok = tokens [i + 1];
  69664. if (nextTok == 0)
  69665. break;
  69666. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69667. {
  69668. // finished a line, so go back and update the heights of the things on it
  69669. for (int j = i; j >= 0; --j)
  69670. {
  69671. Token* const tok = tokens.getUnchecked(j);
  69672. if (tok->line == totalLines)
  69673. tok->lineHeight = h;
  69674. else
  69675. break;
  69676. }
  69677. x = 0;
  69678. y += h;
  69679. h = 0;
  69680. ++totalLines;
  69681. }
  69682. }
  69683. // finished a line, so go back and update the heights of the things on it
  69684. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69685. {
  69686. Token* const t = tokens.getUnchecked(j);
  69687. if (t->line == totalLines)
  69688. t->lineHeight = h;
  69689. else
  69690. break;
  69691. }
  69692. ++totalLines;
  69693. if (! justification.testFlags (Justification::left))
  69694. {
  69695. int totalW = getWidth();
  69696. for (i = totalLines; --i >= 0;)
  69697. {
  69698. const int lineW = getLineWidth (i);
  69699. int dx = 0;
  69700. if (justification.testFlags (Justification::horizontallyCentred))
  69701. dx = (totalW - lineW) / 2;
  69702. else if (justification.testFlags (Justification::right))
  69703. dx = totalW - lineW;
  69704. for (int j = tokens.size(); --j >= 0;)
  69705. {
  69706. Token* const t = tokens.getUnchecked(j);
  69707. if (t->line == i)
  69708. t->x += dx;
  69709. }
  69710. }
  69711. }
  69712. }
  69713. }
  69714. int TextLayout::getLineWidth (const int lineNumber) const
  69715. {
  69716. int maxW = 0;
  69717. for (int i = tokens.size(); --i >= 0;)
  69718. {
  69719. const Token* const t = tokens.getUnchecked(i);
  69720. if (t->line == lineNumber && ! t->isWhitespace)
  69721. maxW = jmax (maxW, t->x + t->w);
  69722. }
  69723. return maxW;
  69724. }
  69725. int TextLayout::getWidth() const
  69726. {
  69727. int maxW = 0;
  69728. for (int i = tokens.size(); --i >= 0;)
  69729. {
  69730. const Token* const t = tokens.getUnchecked(i);
  69731. if (! t->isWhitespace)
  69732. maxW = jmax (maxW, t->x + t->w);
  69733. }
  69734. return maxW;
  69735. }
  69736. int TextLayout::getHeight() const
  69737. {
  69738. int maxH = 0;
  69739. for (int i = tokens.size(); --i >= 0;)
  69740. {
  69741. const Token* const t = tokens.getUnchecked(i);
  69742. if (! t->isWhitespace)
  69743. maxH = jmax (maxH, t->y + t->h);
  69744. }
  69745. return maxH;
  69746. }
  69747. void TextLayout::draw (Graphics& g,
  69748. const int xOffset,
  69749. const int yOffset) const
  69750. {
  69751. for (int i = tokens.size(); --i >= 0;)
  69752. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69753. }
  69754. void TextLayout::drawWithin (Graphics& g,
  69755. int x, int y, int w, int h,
  69756. const Justification& justification) const
  69757. {
  69758. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69759. x, y, w, h);
  69760. draw (g, x, y);
  69761. }
  69762. END_JUCE_NAMESPACE
  69763. /*** End of inlined file: juce_TextLayout.cpp ***/
  69764. /*** Start of inlined file: juce_Typeface.cpp ***/
  69765. BEGIN_JUCE_NAMESPACE
  69766. Typeface::Typeface (const String& name_) throw()
  69767. : name (name_)
  69768. {
  69769. }
  69770. Typeface::~Typeface()
  69771. {
  69772. }
  69773. class CustomTypeface::GlyphInfo
  69774. {
  69775. public:
  69776. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69777. : character (character_), path (path_), width (width_)
  69778. {
  69779. }
  69780. ~GlyphInfo() throw()
  69781. {
  69782. }
  69783. struct KerningPair
  69784. {
  69785. juce_wchar character2;
  69786. float kerningAmount;
  69787. };
  69788. void addKerningPair (const juce_wchar subsequentCharacter,
  69789. const float extraKerningAmount) throw()
  69790. {
  69791. KerningPair kp;
  69792. kp.character2 = subsequentCharacter;
  69793. kp.kerningAmount = extraKerningAmount;
  69794. kerningPairs.add (kp);
  69795. }
  69796. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69797. {
  69798. if (subsequentCharacter != 0)
  69799. {
  69800. for (int i = kerningPairs.size(); --i >= 0;)
  69801. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69802. return width + kerningPairs.getReference(i).kerningAmount;
  69803. }
  69804. return width;
  69805. }
  69806. const juce_wchar character;
  69807. const Path path;
  69808. float width;
  69809. Array <KerningPair> kerningPairs;
  69810. juce_UseDebuggingNewOperator
  69811. private:
  69812. GlyphInfo (const GlyphInfo&);
  69813. GlyphInfo& operator= (const GlyphInfo&);
  69814. };
  69815. CustomTypeface::CustomTypeface()
  69816. : Typeface (String::empty)
  69817. {
  69818. clear();
  69819. }
  69820. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69821. : Typeface (String::empty)
  69822. {
  69823. clear();
  69824. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69825. BufferedInputStream in (&gzin, 32768, false);
  69826. name = in.readString();
  69827. isBold = in.readBool();
  69828. isItalic = in.readBool();
  69829. ascent = in.readFloat();
  69830. defaultCharacter = (juce_wchar) in.readShort();
  69831. int i, numChars = in.readInt();
  69832. for (i = 0; i < numChars; ++i)
  69833. {
  69834. const juce_wchar c = (juce_wchar) in.readShort();
  69835. const float width = in.readFloat();
  69836. Path p;
  69837. p.loadPathFromStream (in);
  69838. addGlyph (c, p, width);
  69839. }
  69840. const int numKerningPairs = in.readInt();
  69841. for (i = 0; i < numKerningPairs; ++i)
  69842. {
  69843. const juce_wchar char1 = (juce_wchar) in.readShort();
  69844. const juce_wchar char2 = (juce_wchar) in.readShort();
  69845. addKerningPair (char1, char2, in.readFloat());
  69846. }
  69847. }
  69848. CustomTypeface::~CustomTypeface()
  69849. {
  69850. }
  69851. void CustomTypeface::clear()
  69852. {
  69853. defaultCharacter = 0;
  69854. ascent = 1.0f;
  69855. isBold = isItalic = false;
  69856. zeromem (lookupTable, sizeof (lookupTable));
  69857. glyphs.clear();
  69858. }
  69859. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69860. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69861. {
  69862. name = name_;
  69863. defaultCharacter = defaultCharacter_;
  69864. ascent = ascent_;
  69865. isBold = isBold_;
  69866. isItalic = isItalic_;
  69867. }
  69868. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69869. {
  69870. // Check that you're not trying to add the same character twice..
  69871. jassert (findGlyph (character, false) == 0);
  69872. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69873. lookupTable [character] = (short) glyphs.size();
  69874. glyphs.add (new GlyphInfo (character, path, width));
  69875. }
  69876. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69877. {
  69878. if (extraAmount != 0)
  69879. {
  69880. GlyphInfo* const g = findGlyph (char1, true);
  69881. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69882. if (g != 0)
  69883. g->addKerningPair (char2, extraAmount);
  69884. }
  69885. }
  69886. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69887. {
  69888. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69889. return glyphs [(int) lookupTable [(int) character]];
  69890. for (int i = 0; i < glyphs.size(); ++i)
  69891. {
  69892. GlyphInfo* const g = glyphs.getUnchecked(i);
  69893. if (g->character == character)
  69894. return g;
  69895. }
  69896. if (loadIfNeeded && loadGlyphIfPossible (character))
  69897. return findGlyph (character, false);
  69898. return 0;
  69899. }
  69900. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69901. {
  69902. GlyphInfo* glyph = findGlyph (character, true);
  69903. if (glyph == 0)
  69904. {
  69905. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69906. glyph = findGlyph (L' ', true);
  69907. if (glyph == 0)
  69908. {
  69909. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69910. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69911. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69912. {
  69913. //xxx
  69914. }
  69915. if (glyph == 0)
  69916. glyph = findGlyph (defaultCharacter, true);
  69917. }
  69918. }
  69919. return glyph;
  69920. }
  69921. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  69922. {
  69923. return false;
  69924. }
  69925. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  69926. {
  69927. setCharacteristics (name, typefaceToCopy.getAscent(), isBold, isItalic, defaultCharacter);
  69928. for (int i = 0; i < numCharacters; ++i)
  69929. {
  69930. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  69931. Array <int> glyphIndexes;
  69932. Array <float> offsets;
  69933. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  69934. const int glyphIndex = glyphIndexes.getFirst();
  69935. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  69936. {
  69937. const float glyphWidth = offsets[1];
  69938. Path p;
  69939. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  69940. addGlyph (c, p, glyphWidth);
  69941. for (int j = glyphs.size() - 1; --j >= 0;)
  69942. {
  69943. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  69944. glyphIndexes.clearQuick();
  69945. offsets.clearQuick();
  69946. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  69947. if (offsets.size() > 1)
  69948. addKerningPair (c, char2, offsets[1] - glyphWidth);
  69949. }
  69950. }
  69951. }
  69952. }
  69953. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  69954. {
  69955. GZIPCompressorOutputStream out (&outputStream);
  69956. out.writeString (name);
  69957. out.writeBool (isBold);
  69958. out.writeBool (isItalic);
  69959. out.writeFloat (ascent);
  69960. out.writeShort ((short) (unsigned short) defaultCharacter);
  69961. out.writeInt (glyphs.size());
  69962. int i, numKerningPairs = 0;
  69963. for (i = 0; i < glyphs.size(); ++i)
  69964. {
  69965. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69966. out.writeShort ((short) (unsigned short) g->character);
  69967. out.writeFloat (g->width);
  69968. g->path.writePathToStream (out);
  69969. numKerningPairs += g->kerningPairs.size();
  69970. }
  69971. out.writeInt (numKerningPairs);
  69972. for (i = 0; i < glyphs.size(); ++i)
  69973. {
  69974. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69975. for (int j = 0; j < g->kerningPairs.size(); ++j)
  69976. {
  69977. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  69978. out.writeShort ((short) (unsigned short) g->character);
  69979. out.writeShort ((short) (unsigned short) p.character2);
  69980. out.writeFloat (p.kerningAmount);
  69981. }
  69982. }
  69983. return true;
  69984. }
  69985. float CustomTypeface::getAscent() const
  69986. {
  69987. return ascent;
  69988. }
  69989. float CustomTypeface::getDescent() const
  69990. {
  69991. return 1.0f - ascent;
  69992. }
  69993. float CustomTypeface::getStringWidth (const String& text)
  69994. {
  69995. float x = 0;
  69996. const juce_wchar* t = text;
  69997. while (*t != 0)
  69998. {
  69999. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70000. if (glyph != 0)
  70001. x += glyph->getHorizontalSpacing (*t);
  70002. }
  70003. return x;
  70004. }
  70005. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70006. {
  70007. xOffsets.add (0);
  70008. float x = 0;
  70009. const juce_wchar* t = text;
  70010. while (*t != 0)
  70011. {
  70012. const juce_wchar c = *t++;
  70013. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70014. if (glyph != 0)
  70015. {
  70016. x += glyph->getHorizontalSpacing (*t);
  70017. resultGlyphs.add ((int) glyph->character);
  70018. xOffsets.add (x);
  70019. }
  70020. }
  70021. }
  70022. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70023. {
  70024. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70025. if (glyph != 0)
  70026. {
  70027. path = glyph->path;
  70028. return true;
  70029. }
  70030. return false;
  70031. }
  70032. END_JUCE_NAMESPACE
  70033. /*** End of inlined file: juce_Typeface.cpp ***/
  70034. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70035. BEGIN_JUCE_NAMESPACE
  70036. AffineTransform::AffineTransform() throw()
  70037. : mat00 (1.0f),
  70038. mat01 (0),
  70039. mat02 (0),
  70040. mat10 (0),
  70041. mat11 (1.0f),
  70042. mat12 (0)
  70043. {
  70044. }
  70045. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70046. : mat00 (other.mat00),
  70047. mat01 (other.mat01),
  70048. mat02 (other.mat02),
  70049. mat10 (other.mat10),
  70050. mat11 (other.mat11),
  70051. mat12 (other.mat12)
  70052. {
  70053. }
  70054. AffineTransform::AffineTransform (const float mat00_,
  70055. const float mat01_,
  70056. const float mat02_,
  70057. const float mat10_,
  70058. const float mat11_,
  70059. const float mat12_) throw()
  70060. : mat00 (mat00_),
  70061. mat01 (mat01_),
  70062. mat02 (mat02_),
  70063. mat10 (mat10_),
  70064. mat11 (mat11_),
  70065. mat12 (mat12_)
  70066. {
  70067. }
  70068. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70069. {
  70070. mat00 = other.mat00;
  70071. mat01 = other.mat01;
  70072. mat02 = other.mat02;
  70073. mat10 = other.mat10;
  70074. mat11 = other.mat11;
  70075. mat12 = other.mat12;
  70076. return *this;
  70077. }
  70078. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70079. {
  70080. return mat00 == other.mat00
  70081. && mat01 == other.mat01
  70082. && mat02 == other.mat02
  70083. && mat10 == other.mat10
  70084. && mat11 == other.mat11
  70085. && mat12 == other.mat12;
  70086. }
  70087. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70088. {
  70089. return ! operator== (other);
  70090. }
  70091. bool AffineTransform::isIdentity() const throw()
  70092. {
  70093. return (mat01 == 0)
  70094. && (mat02 == 0)
  70095. && (mat10 == 0)
  70096. && (mat12 == 0)
  70097. && (mat00 == 1.0f)
  70098. && (mat11 == 1.0f);
  70099. }
  70100. const AffineTransform AffineTransform::identity;
  70101. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70102. {
  70103. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70104. other.mat00 * mat01 + other.mat01 * mat11,
  70105. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70106. other.mat10 * mat00 + other.mat11 * mat10,
  70107. other.mat10 * mat01 + other.mat11 * mat11,
  70108. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70109. }
  70110. const AffineTransform AffineTransform::followedBy (const float omat00,
  70111. const float omat01,
  70112. const float omat02,
  70113. const float omat10,
  70114. const float omat11,
  70115. const float omat12) const throw()
  70116. {
  70117. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70118. omat00 * mat01 + omat01 * mat11,
  70119. omat00 * mat02 + omat01 * mat12 + omat02,
  70120. omat10 * mat00 + omat11 * mat10,
  70121. omat10 * mat01 + omat11 * mat11,
  70122. omat10 * mat02 + omat11 * mat12 + omat12);
  70123. }
  70124. const AffineTransform AffineTransform::translated (const float dx,
  70125. const float dy) const throw()
  70126. {
  70127. return AffineTransform (mat00, mat01, mat02 + dx,
  70128. mat10, mat11, mat12 + dy);
  70129. }
  70130. const AffineTransform AffineTransform::translation (const float dx,
  70131. const float dy) throw()
  70132. {
  70133. return AffineTransform (1.0f, 0, dx,
  70134. 0, 1.0f, dy);
  70135. }
  70136. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70137. {
  70138. const float cosRad = cosf (rad);
  70139. const float sinRad = sinf (rad);
  70140. return followedBy (cosRad, -sinRad, 0,
  70141. sinRad, cosRad, 0);
  70142. }
  70143. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70144. {
  70145. const float cosRad = cosf (rad);
  70146. const float sinRad = sinf (rad);
  70147. return AffineTransform (cosRad, -sinRad, 0,
  70148. sinRad, cosRad, 0);
  70149. }
  70150. const AffineTransform AffineTransform::rotated (const float angle,
  70151. const float pivotX,
  70152. const float pivotY) const throw()
  70153. {
  70154. return translated (-pivotX, -pivotY)
  70155. .rotated (angle)
  70156. .translated (pivotX, pivotY);
  70157. }
  70158. const AffineTransform AffineTransform::rotation (const float angle,
  70159. const float pivotX,
  70160. const float pivotY) throw()
  70161. {
  70162. return translation (-pivotX, -pivotY)
  70163. .rotated (angle)
  70164. .translated (pivotX, pivotY);
  70165. }
  70166. const AffineTransform AffineTransform::scaled (const float factorX,
  70167. const float factorY) const throw()
  70168. {
  70169. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70170. factorY * mat10, factorY * mat11, factorY * mat12);
  70171. }
  70172. const AffineTransform AffineTransform::scale (const float factorX,
  70173. const float factorY) throw()
  70174. {
  70175. return AffineTransform (factorX, 0, 0,
  70176. 0, factorY, 0);
  70177. }
  70178. const AffineTransform AffineTransform::sheared (const float shearX,
  70179. const float shearY) const throw()
  70180. {
  70181. return followedBy (1.0f, shearX, 0,
  70182. shearY, 1.0f, 0);
  70183. }
  70184. const AffineTransform AffineTransform::inverted() const throw()
  70185. {
  70186. double determinant = (mat00 * mat11 - mat10 * mat01);
  70187. if (determinant != 0.0)
  70188. {
  70189. determinant = 1.0 / determinant;
  70190. const float dst00 = (float) (mat11 * determinant);
  70191. const float dst10 = (float) (-mat10 * determinant);
  70192. const float dst01 = (float) (-mat01 * determinant);
  70193. const float dst11 = (float) (mat00 * determinant);
  70194. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70195. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70196. }
  70197. else
  70198. {
  70199. // singularity..
  70200. return *this;
  70201. }
  70202. }
  70203. bool AffineTransform::isSingularity() const throw()
  70204. {
  70205. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70206. }
  70207. bool AffineTransform::isOnlyTranslation() const throw()
  70208. {
  70209. return (mat01 == 0)
  70210. && (mat10 == 0)
  70211. && (mat00 == 1.0f)
  70212. && (mat11 == 1.0f);
  70213. }
  70214. void AffineTransform::transformPoint (float& x,
  70215. float& y) const throw()
  70216. {
  70217. const float oldX = x;
  70218. x = mat00 * oldX + mat01 * y + mat02;
  70219. y = mat10 * oldX + mat11 * y + mat12;
  70220. }
  70221. void AffineTransform::transformPoint (double& x,
  70222. double& y) const throw()
  70223. {
  70224. const double oldX = x;
  70225. x = mat00 * oldX + mat01 * y + mat02;
  70226. y = mat10 * oldX + mat11 * y + mat12;
  70227. }
  70228. END_JUCE_NAMESPACE
  70229. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70230. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70231. BEGIN_JUCE_NAMESPACE
  70232. BorderSize::BorderSize() throw()
  70233. : top (0),
  70234. left (0),
  70235. bottom (0),
  70236. right (0)
  70237. {
  70238. }
  70239. BorderSize::BorderSize (const BorderSize& other) throw()
  70240. : top (other.top),
  70241. left (other.left),
  70242. bottom (other.bottom),
  70243. right (other.right)
  70244. {
  70245. }
  70246. BorderSize::BorderSize (const int topGap,
  70247. const int leftGap,
  70248. const int bottomGap,
  70249. const int rightGap) throw()
  70250. : top (topGap),
  70251. left (leftGap),
  70252. bottom (bottomGap),
  70253. right (rightGap)
  70254. {
  70255. }
  70256. BorderSize::BorderSize (const int allGaps) throw()
  70257. : top (allGaps),
  70258. left (allGaps),
  70259. bottom (allGaps),
  70260. right (allGaps)
  70261. {
  70262. }
  70263. BorderSize::~BorderSize() throw()
  70264. {
  70265. }
  70266. void BorderSize::setTop (const int newTopGap) throw()
  70267. {
  70268. top = newTopGap;
  70269. }
  70270. void BorderSize::setLeft (const int newLeftGap) throw()
  70271. {
  70272. left = newLeftGap;
  70273. }
  70274. void BorderSize::setBottom (const int newBottomGap) throw()
  70275. {
  70276. bottom = newBottomGap;
  70277. }
  70278. void BorderSize::setRight (const int newRightGap) throw()
  70279. {
  70280. right = newRightGap;
  70281. }
  70282. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70283. {
  70284. return Rectangle<int> (r.getX() + left,
  70285. r.getY() + top,
  70286. r.getWidth() - (left + right),
  70287. r.getHeight() - (top + bottom));
  70288. }
  70289. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70290. {
  70291. r.setBounds (r.getX() + left,
  70292. r.getY() + top,
  70293. r.getWidth() - (left + right),
  70294. r.getHeight() - (top + bottom));
  70295. }
  70296. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70297. {
  70298. return Rectangle<int> (r.getX() - left,
  70299. r.getY() - top,
  70300. r.getWidth() + (left + right),
  70301. r.getHeight() + (top + bottom));
  70302. }
  70303. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70304. {
  70305. r.setBounds (r.getX() - left,
  70306. r.getY() - top,
  70307. r.getWidth() + (left + right),
  70308. r.getHeight() + (top + bottom));
  70309. }
  70310. bool BorderSize::operator== (const BorderSize& other) const throw()
  70311. {
  70312. return top == other.top
  70313. && left == other.left
  70314. && bottom == other.bottom
  70315. && right == other.right;
  70316. }
  70317. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70318. {
  70319. return ! operator== (other);
  70320. }
  70321. END_JUCE_NAMESPACE
  70322. /*** End of inlined file: juce_BorderSize.cpp ***/
  70323. /*** Start of inlined file: juce_Line.cpp ***/
  70324. BEGIN_JUCE_NAMESPACE
  70325. static bool juce_lineIntersection (const float x1, const float y1,
  70326. const float x2, const float y2,
  70327. const float x3, const float y3,
  70328. const float x4, const float y4,
  70329. float& intersectionX,
  70330. float& intersectionY) throw()
  70331. {
  70332. if (x2 != x3 || y2 != y3)
  70333. {
  70334. const float dx1 = x2 - x1;
  70335. const float dy1 = y2 - y1;
  70336. const float dx2 = x4 - x3;
  70337. const float dy2 = y4 - y3;
  70338. const float divisor = dx1 * dy2 - dx2 * dy1;
  70339. if (divisor == 0)
  70340. {
  70341. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70342. {
  70343. if (dy1 == 0 && dy2 != 0)
  70344. {
  70345. const float along = (y1 - y3) / dy2;
  70346. intersectionX = x3 + along * dx2;
  70347. intersectionY = y1;
  70348. return along >= 0 && along <= 1.0f;
  70349. }
  70350. else if (dy2 == 0 && dy1 != 0)
  70351. {
  70352. const float along = (y3 - y1) / dy1;
  70353. intersectionX = x1 + along * dx1;
  70354. intersectionY = y3;
  70355. return along >= 0 && along <= 1.0f;
  70356. }
  70357. else if (dx1 == 0 && dx2 != 0)
  70358. {
  70359. const float along = (x1 - x3) / dx2;
  70360. intersectionX = x1;
  70361. intersectionY = y3 + along * dy2;
  70362. return along >= 0 && along <= 1.0f;
  70363. }
  70364. else if (dx2 == 0 && dx1 != 0)
  70365. {
  70366. const float along = (x3 - x1) / dx1;
  70367. intersectionX = x3;
  70368. intersectionY = y1 + along * dy1;
  70369. return along >= 0 && along <= 1.0f;
  70370. }
  70371. }
  70372. intersectionX = 0.5f * (x2 + x3);
  70373. intersectionY = 0.5f * (y2 + y3);
  70374. return false;
  70375. }
  70376. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70377. intersectionX = x1 + along1 * dx1;
  70378. intersectionY = y1 + along1 * dy1;
  70379. if (along1 < 0 || along1 > 1.0f)
  70380. return false;
  70381. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70382. return along2 >= 0 && along2 <= 1.0f;
  70383. }
  70384. intersectionX = x2;
  70385. intersectionY = y2;
  70386. return true;
  70387. }
  70388. Line::Line() throw()
  70389. : startX (0.0f),
  70390. startY (0.0f),
  70391. endX (0.0f),
  70392. endY (0.0f)
  70393. {
  70394. }
  70395. Line::Line (const Line& other) throw()
  70396. : startX (other.startX),
  70397. startY (other.startY),
  70398. endX (other.endX),
  70399. endY (other.endY)
  70400. {
  70401. }
  70402. Line::Line (const float startX_, const float startY_,
  70403. const float endX_, const float endY_) throw()
  70404. : startX (startX_),
  70405. startY (startY_),
  70406. endX (endX_),
  70407. endY (endY_)
  70408. {
  70409. }
  70410. Line::Line (const Point<float>& start,
  70411. const Point<float>& end) throw()
  70412. : startX (start.getX()),
  70413. startY (start.getY()),
  70414. endX (end.getX()),
  70415. endY (end.getY())
  70416. {
  70417. }
  70418. Line& Line::operator= (const Line& other) throw()
  70419. {
  70420. startX = other.startX;
  70421. startY = other.startY;
  70422. endX = other.endX;
  70423. endY = other.endY;
  70424. return *this;
  70425. }
  70426. Line::~Line() throw()
  70427. {
  70428. }
  70429. const Point<float> Line::getStart() const throw()
  70430. {
  70431. return Point<float> (startX, startY);
  70432. }
  70433. const Point<float> Line::getEnd() const throw()
  70434. {
  70435. return Point<float> (endX, endY);
  70436. }
  70437. void Line::setStart (const float newStartX,
  70438. const float newStartY) throw()
  70439. {
  70440. startX = newStartX;
  70441. startY = newStartY;
  70442. }
  70443. void Line::setStart (const Point<float>& newStart) throw()
  70444. {
  70445. startX = newStart.getX();
  70446. startY = newStart.getY();
  70447. }
  70448. void Line::setEnd (const float newEndX,
  70449. const float newEndY) throw()
  70450. {
  70451. endX = newEndX;
  70452. endY = newEndY;
  70453. }
  70454. void Line::setEnd (const Point<float>& newEnd) throw()
  70455. {
  70456. endX = newEnd.getX();
  70457. endY = newEnd.getY();
  70458. }
  70459. bool Line::operator== (const Line& other) const throw()
  70460. {
  70461. return startX == other.startX
  70462. && startY == other.startY
  70463. && endX == other.endX
  70464. && endY == other.endY;
  70465. }
  70466. bool Line::operator!= (const Line& other) const throw()
  70467. {
  70468. return startX != other.startX
  70469. || startY != other.startY
  70470. || endX != other.endX
  70471. || endY != other.endY;
  70472. }
  70473. void Line::applyTransform (const AffineTransform& transform) throw()
  70474. {
  70475. transform.transformPoint (startX, startY);
  70476. transform.transformPoint (endX, endY);
  70477. }
  70478. float Line::getLength() const throw()
  70479. {
  70480. return (float) juce_hypot (startX - endX,
  70481. startY - endY);
  70482. }
  70483. float Line::getAngle() const throw()
  70484. {
  70485. return atan2f (endX - startX,
  70486. endY - startY);
  70487. }
  70488. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70489. {
  70490. const float alpha = distanceFromStart / getLength();
  70491. return Point<float> (startX + (endX - startX) * alpha,
  70492. startY + (endY - startY) * alpha);
  70493. }
  70494. const Point<float> Line::getPointAlongLine (const float offsetX,
  70495. const float offsetY) const throw()
  70496. {
  70497. const float dx = endX - startX;
  70498. const float dy = endY - startY;
  70499. const double length = juce_hypot (dx, dy);
  70500. if (length == 0)
  70501. return Point<float> (startX, startY);
  70502. else
  70503. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70504. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70505. }
  70506. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70507. {
  70508. return Point<float> (startX + (endX - startX) * alpha,
  70509. startY + (endY - startY) * alpha);
  70510. }
  70511. float Line::getDistanceFromLine (const float x,
  70512. const float y) const throw()
  70513. {
  70514. const double dx = endX - startX;
  70515. const double dy = endY - startY;
  70516. const double length = dx * dx + dy * dy;
  70517. if (length > 0)
  70518. {
  70519. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70520. if (prop >= 0.0f && prop < 1.0f)
  70521. {
  70522. return (float) juce_hypot (x - (startX + prop * dx),
  70523. y - (startY + prop * dy));
  70524. }
  70525. }
  70526. return (float) jmin (juce_hypot (x - startX, y - startY),
  70527. juce_hypot (x - endX, y - endY));
  70528. }
  70529. float Line::findNearestPointTo (const float x,
  70530. const float y) const throw()
  70531. {
  70532. const double dx = endX - startX;
  70533. const double dy = endY - startY;
  70534. const double length = dx * dx + dy * dy;
  70535. if (length <= 0.0)
  70536. return 0.0f;
  70537. return jlimit (0.0f, 1.0f,
  70538. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70539. }
  70540. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70541. {
  70542. const float length = getLength();
  70543. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70544. getEnd());
  70545. }
  70546. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70547. {
  70548. const float length = getLength();
  70549. return Line (getStart(),
  70550. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70551. }
  70552. bool Line::clipToPath (const Path& path,
  70553. const bool keepSectionOutsidePath) throw()
  70554. {
  70555. const bool startInside = path.contains (startX, startY);
  70556. const bool endInside = path.contains (endX, endY);
  70557. if (startInside == endInside)
  70558. {
  70559. if (keepSectionOutsidePath != startInside)
  70560. {
  70561. // entirely outside the path
  70562. return false;
  70563. }
  70564. else
  70565. {
  70566. // entirely inside the path
  70567. startX = 0.0f;
  70568. startY = 0.0f;
  70569. endX = 0.0f;
  70570. endY = 0.0f;
  70571. return true;
  70572. }
  70573. }
  70574. else
  70575. {
  70576. bool changed = false;
  70577. PathFlatteningIterator iter (path, AffineTransform::identity);
  70578. while (iter.next())
  70579. {
  70580. float ix, iy;
  70581. if (intersects (Line (iter.x1, iter.y1,
  70582. iter.x2, iter.y2),
  70583. ix, iy))
  70584. {
  70585. if ((startInside && keepSectionOutsidePath)
  70586. || (endInside && ! keepSectionOutsidePath))
  70587. {
  70588. setStart (ix, iy);
  70589. }
  70590. else
  70591. {
  70592. setEnd (ix, iy);
  70593. }
  70594. changed = true;
  70595. }
  70596. }
  70597. return changed;
  70598. }
  70599. }
  70600. bool Line::intersects (const Line& line,
  70601. float& intersectionX,
  70602. float& intersectionY) const throw()
  70603. {
  70604. return juce_lineIntersection (startX, startY,
  70605. endX, endY,
  70606. line.startX, line.startY,
  70607. line.endX, line.endY,
  70608. intersectionX,
  70609. intersectionY);
  70610. }
  70611. bool Line::isVertical() const throw()
  70612. {
  70613. return startX == endX;
  70614. }
  70615. bool Line::isHorizontal() const throw()
  70616. {
  70617. return startY == endY;
  70618. }
  70619. bool Line::isPointAbove (const float x, const float y) const throw()
  70620. {
  70621. return startX != endX
  70622. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70623. }
  70624. END_JUCE_NAMESPACE
  70625. /*** End of inlined file: juce_Line.cpp ***/
  70626. /*** Start of inlined file: juce_Path.cpp ***/
  70627. BEGIN_JUCE_NAMESPACE
  70628. // tests that some co-ords aren't NaNs
  70629. #define CHECK_COORDS_ARE_VALID(x, y) \
  70630. jassert (x == x && y == y);
  70631. namespace PathHelpers
  70632. {
  70633. static const float ellipseAngularIncrement = 0.05f;
  70634. static void perpendicularOffset (const float x1, const float y1,
  70635. const float x2, const float y2,
  70636. const float offsetX, const float offsetY,
  70637. float& resultX, float& resultY) throw()
  70638. {
  70639. const float dx = x2 - x1;
  70640. const float dy = y2 - y1;
  70641. const float len = juce_hypotf (dx, dy);
  70642. if (len == 0)
  70643. {
  70644. resultX = x1;
  70645. resultY = y1;
  70646. }
  70647. else
  70648. {
  70649. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70650. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70651. }
  70652. }
  70653. static const String nextToken (const juce_wchar*& t)
  70654. {
  70655. while (CharacterFunctions::isWhitespace (*t))
  70656. ++t;
  70657. const juce_wchar* const start = t;
  70658. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70659. ++t;
  70660. const int length = (int) (t - start);
  70661. while (CharacterFunctions::isWhitespace (*t))
  70662. ++t;
  70663. return String (start, length);
  70664. }
  70665. }
  70666. const float Path::lineMarker = 100001.0f;
  70667. const float Path::moveMarker = 100002.0f;
  70668. const float Path::quadMarker = 100003.0f;
  70669. const float Path::cubicMarker = 100004.0f;
  70670. const float Path::closeSubPathMarker = 100005.0f;
  70671. Path::Path()
  70672. : numElements (0),
  70673. pathXMin (0),
  70674. pathXMax (0),
  70675. pathYMin (0),
  70676. pathYMax (0),
  70677. useNonZeroWinding (true)
  70678. {
  70679. }
  70680. Path::~Path()
  70681. {
  70682. }
  70683. Path::Path (const Path& other)
  70684. : numElements (other.numElements),
  70685. pathXMin (other.pathXMin),
  70686. pathXMax (other.pathXMax),
  70687. pathYMin (other.pathYMin),
  70688. pathYMax (other.pathYMax),
  70689. useNonZeroWinding (other.useNonZeroWinding)
  70690. {
  70691. if (numElements > 0)
  70692. {
  70693. data.setAllocatedSize (numElements);
  70694. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70695. }
  70696. }
  70697. Path& Path::operator= (const Path& other)
  70698. {
  70699. if (this != &other)
  70700. {
  70701. data.ensureAllocatedSize (other.numElements);
  70702. numElements = other.numElements;
  70703. pathXMin = other.pathXMin;
  70704. pathXMax = other.pathXMax;
  70705. pathYMin = other.pathYMin;
  70706. pathYMax = other.pathYMax;
  70707. useNonZeroWinding = other.useNonZeroWinding;
  70708. if (numElements > 0)
  70709. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70710. }
  70711. return *this;
  70712. }
  70713. void Path::clear() throw()
  70714. {
  70715. numElements = 0;
  70716. pathXMin = 0;
  70717. pathYMin = 0;
  70718. pathYMax = 0;
  70719. pathXMax = 0;
  70720. }
  70721. void Path::swapWithPath (Path& other)
  70722. {
  70723. data.swapWith (other.data);
  70724. swapVariables <size_t> (numElements, other.numElements);
  70725. swapVariables <float> (pathXMin, other.pathXMin);
  70726. swapVariables <float> (pathXMax, other.pathXMax);
  70727. swapVariables <float> (pathYMin, other.pathYMin);
  70728. swapVariables <float> (pathYMax, other.pathYMax);
  70729. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70730. }
  70731. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70732. {
  70733. useNonZeroWinding = isNonZero;
  70734. }
  70735. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70736. const bool preserveProportions) throw()
  70737. {
  70738. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70739. }
  70740. bool Path::isEmpty() const throw()
  70741. {
  70742. size_t i = 0;
  70743. while (i < numElements)
  70744. {
  70745. const float type = data.elements [i++];
  70746. if (type == moveMarker)
  70747. {
  70748. i += 2;
  70749. }
  70750. else if (type == lineMarker
  70751. || type == quadMarker
  70752. || type == cubicMarker)
  70753. {
  70754. return false;
  70755. }
  70756. }
  70757. return true;
  70758. }
  70759. const Rectangle<float> Path::getBounds() const throw()
  70760. {
  70761. return Rectangle<float> (pathXMin, pathYMin,
  70762. pathXMax - pathXMin,
  70763. pathYMax - pathYMin);
  70764. }
  70765. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70766. {
  70767. return getBounds().transformed (transform);
  70768. }
  70769. void Path::startNewSubPath (const float x, const float y)
  70770. {
  70771. CHECK_COORDS_ARE_VALID (x, y);
  70772. if (numElements == 0)
  70773. {
  70774. pathXMin = pathXMax = x;
  70775. pathYMin = pathYMax = y;
  70776. }
  70777. else
  70778. {
  70779. pathXMin = jmin (pathXMin, x);
  70780. pathXMax = jmax (pathXMax, x);
  70781. pathYMin = jmin (pathYMin, y);
  70782. pathYMax = jmax (pathYMax, y);
  70783. }
  70784. data.ensureAllocatedSize (numElements + 3);
  70785. data.elements [numElements++] = moveMarker;
  70786. data.elements [numElements++] = x;
  70787. data.elements [numElements++] = y;
  70788. }
  70789. void Path::lineTo (const float x, const float y)
  70790. {
  70791. CHECK_COORDS_ARE_VALID (x, y);
  70792. if (numElements == 0)
  70793. startNewSubPath (0, 0);
  70794. data.ensureAllocatedSize (numElements + 3);
  70795. data.elements [numElements++] = lineMarker;
  70796. data.elements [numElements++] = x;
  70797. data.elements [numElements++] = y;
  70798. pathXMin = jmin (pathXMin, x);
  70799. pathXMax = jmax (pathXMax, x);
  70800. pathYMin = jmin (pathYMin, y);
  70801. pathYMax = jmax (pathYMax, y);
  70802. }
  70803. void Path::quadraticTo (const float x1, const float y1,
  70804. const float x2, const float y2)
  70805. {
  70806. CHECK_COORDS_ARE_VALID (x1, y1);
  70807. CHECK_COORDS_ARE_VALID (x2, y2);
  70808. if (numElements == 0)
  70809. startNewSubPath (0, 0);
  70810. data.ensureAllocatedSize (numElements + 5);
  70811. data.elements [numElements++] = quadMarker;
  70812. data.elements [numElements++] = x1;
  70813. data.elements [numElements++] = y1;
  70814. data.elements [numElements++] = x2;
  70815. data.elements [numElements++] = y2;
  70816. pathXMin = jmin (pathXMin, x1, x2);
  70817. pathXMax = jmax (pathXMax, x1, x2);
  70818. pathYMin = jmin (pathYMin, y1, y2);
  70819. pathYMax = jmax (pathYMax, y1, y2);
  70820. }
  70821. void Path::cubicTo (const float x1, const float y1,
  70822. const float x2, const float y2,
  70823. const float x3, const float y3)
  70824. {
  70825. CHECK_COORDS_ARE_VALID (x1, y1);
  70826. CHECK_COORDS_ARE_VALID (x2, y2);
  70827. CHECK_COORDS_ARE_VALID (x3, y3);
  70828. if (numElements == 0)
  70829. startNewSubPath (0, 0);
  70830. data.ensureAllocatedSize (numElements + 7);
  70831. data.elements [numElements++] = cubicMarker;
  70832. data.elements [numElements++] = x1;
  70833. data.elements [numElements++] = y1;
  70834. data.elements [numElements++] = x2;
  70835. data.elements [numElements++] = y2;
  70836. data.elements [numElements++] = x3;
  70837. data.elements [numElements++] = y3;
  70838. pathXMin = jmin (pathXMin, x1, x2, x3);
  70839. pathXMax = jmax (pathXMax, x1, x2, x3);
  70840. pathYMin = jmin (pathYMin, y1, y2, y3);
  70841. pathYMax = jmax (pathYMax, y1, y2, y3);
  70842. }
  70843. void Path::closeSubPath()
  70844. {
  70845. if (numElements > 0
  70846. && data.elements [numElements - 1] != closeSubPathMarker)
  70847. {
  70848. data.ensureAllocatedSize (numElements + 1);
  70849. data.elements [numElements++] = closeSubPathMarker;
  70850. }
  70851. }
  70852. const Point<float> Path::getCurrentPosition() const
  70853. {
  70854. int i = numElements - 1;
  70855. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70856. {
  70857. while (i >= 0)
  70858. {
  70859. if (data.elements[i] == moveMarker)
  70860. {
  70861. i += 2;
  70862. break;
  70863. }
  70864. --i;
  70865. }
  70866. }
  70867. if (i > 0)
  70868. return Point<float> (data.elements [i - 1], data.elements [i]);
  70869. return Point<float>();
  70870. }
  70871. void Path::addRectangle (const float x, const float y,
  70872. const float w, const float h)
  70873. {
  70874. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70875. if (w < 0)
  70876. swapVariables (x1, x2);
  70877. if (h < 0)
  70878. swapVariables (y1, y2);
  70879. data.ensureAllocatedSize (numElements + 13);
  70880. if (numElements == 0)
  70881. {
  70882. pathXMin = x1;
  70883. pathXMax = x2;
  70884. pathYMin = y1;
  70885. pathYMax = y2;
  70886. }
  70887. else
  70888. {
  70889. pathXMin = jmin (pathXMin, x1);
  70890. pathXMax = jmax (pathXMax, x2);
  70891. pathYMin = jmin (pathYMin, y1);
  70892. pathYMax = jmax (pathYMax, y2);
  70893. }
  70894. data.elements [numElements++] = moveMarker;
  70895. data.elements [numElements++] = x1;
  70896. data.elements [numElements++] = y2;
  70897. data.elements [numElements++] = lineMarker;
  70898. data.elements [numElements++] = x1;
  70899. data.elements [numElements++] = y1;
  70900. data.elements [numElements++] = lineMarker;
  70901. data.elements [numElements++] = x2;
  70902. data.elements [numElements++] = y1;
  70903. data.elements [numElements++] = lineMarker;
  70904. data.elements [numElements++] = x2;
  70905. data.elements [numElements++] = y2;
  70906. data.elements [numElements++] = closeSubPathMarker;
  70907. }
  70908. void Path::addRectangle (const Rectangle<int>& rectangle)
  70909. {
  70910. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70911. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70912. }
  70913. void Path::addRoundedRectangle (const float x, const float y,
  70914. const float w, const float h,
  70915. float csx,
  70916. float csy)
  70917. {
  70918. csx = jmin (csx, w * 0.5f);
  70919. csy = jmin (csy, h * 0.5f);
  70920. const float cs45x = csx * 0.45f;
  70921. const float cs45y = csy * 0.45f;
  70922. const float x2 = x + w;
  70923. const float y2 = y + h;
  70924. startNewSubPath (x + csx, y);
  70925. lineTo (x2 - csx, y);
  70926. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  70927. lineTo (x2, y2 - csy);
  70928. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  70929. lineTo (x + csx, y2);
  70930. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  70931. lineTo (x, y + csy);
  70932. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  70933. closeSubPath();
  70934. }
  70935. void Path::addRoundedRectangle (const float x, const float y,
  70936. const float w, const float h,
  70937. float cs)
  70938. {
  70939. addRoundedRectangle (x, y, w, h, cs, cs);
  70940. }
  70941. void Path::addTriangle (const float x1, const float y1,
  70942. const float x2, const float y2,
  70943. const float x3, const float y3)
  70944. {
  70945. startNewSubPath (x1, y1);
  70946. lineTo (x2, y2);
  70947. lineTo (x3, y3);
  70948. closeSubPath();
  70949. }
  70950. void Path::addQuadrilateral (const float x1, const float y1,
  70951. const float x2, const float y2,
  70952. const float x3, const float y3,
  70953. const float x4, const float y4)
  70954. {
  70955. startNewSubPath (x1, y1);
  70956. lineTo (x2, y2);
  70957. lineTo (x3, y3);
  70958. lineTo (x4, y4);
  70959. closeSubPath();
  70960. }
  70961. void Path::addEllipse (const float x, const float y,
  70962. const float w, const float h)
  70963. {
  70964. const float hw = w * 0.5f;
  70965. const float hw55 = hw * 0.55f;
  70966. const float hh = h * 0.5f;
  70967. const float hh45 = hh * 0.55f;
  70968. const float cx = x + hw;
  70969. const float cy = y + hh;
  70970. startNewSubPath (cx, cy - hh);
  70971. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  70972. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  70973. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  70974. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  70975. closeSubPath();
  70976. }
  70977. void Path::addArc (const float x, const float y,
  70978. const float w, const float h,
  70979. const float fromRadians,
  70980. const float toRadians,
  70981. const bool startAsNewSubPath)
  70982. {
  70983. const float radiusX = w / 2.0f;
  70984. const float radiusY = h / 2.0f;
  70985. addCentredArc (x + radiusX,
  70986. y + radiusY,
  70987. radiusX, radiusY,
  70988. 0.0f,
  70989. fromRadians, toRadians,
  70990. startAsNewSubPath);
  70991. }
  70992. void Path::addCentredArc (const float centreX, const float centreY,
  70993. const float radiusX, const float radiusY,
  70994. const float rotationOfEllipse,
  70995. const float fromRadians,
  70996. const float toRadians,
  70997. const bool startAsNewSubPath)
  70998. {
  70999. if (radiusX > 0.0f && radiusY > 0.0f)
  71000. {
  71001. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71002. float angle = fromRadians;
  71003. if (startAsNewSubPath)
  71004. {
  71005. float x = centreX + radiusX * sinf (angle);
  71006. float y = centreY - radiusY * cosf (angle);
  71007. if (rotationOfEllipse != 0)
  71008. rotation.transformPoint (x, y);
  71009. startNewSubPath (x, y);
  71010. }
  71011. if (fromRadians < toRadians)
  71012. {
  71013. if (startAsNewSubPath)
  71014. angle += PathHelpers::ellipseAngularIncrement;
  71015. while (angle < toRadians)
  71016. {
  71017. float x = centreX + radiusX * sinf (angle);
  71018. float y = centreY - radiusY * cosf (angle);
  71019. if (rotationOfEllipse != 0)
  71020. rotation.transformPoint (x, y);
  71021. lineTo (x, y);
  71022. angle += PathHelpers::ellipseAngularIncrement;
  71023. }
  71024. }
  71025. else
  71026. {
  71027. if (startAsNewSubPath)
  71028. angle -= PathHelpers::ellipseAngularIncrement;
  71029. while (angle > toRadians)
  71030. {
  71031. float x = centreX + radiusX * sinf (angle);
  71032. float y = centreY - radiusY * cosf (angle);
  71033. if (rotationOfEllipse != 0)
  71034. rotation.transformPoint (x, y);
  71035. lineTo (x, y);
  71036. angle -= PathHelpers::ellipseAngularIncrement;
  71037. }
  71038. }
  71039. float x = centreX + radiusX * sinf (toRadians);
  71040. float y = centreY - radiusY * cosf (toRadians);
  71041. if (rotationOfEllipse != 0)
  71042. rotation.transformPoint (x, y);
  71043. lineTo (x, y);
  71044. }
  71045. }
  71046. void Path::addPieSegment (const float x, const float y,
  71047. const float width, const float height,
  71048. const float fromRadians,
  71049. const float toRadians,
  71050. const float innerCircleProportionalSize)
  71051. {
  71052. float hw = width * 0.5f;
  71053. float hh = height * 0.5f;
  71054. const float centreX = x + hw;
  71055. const float centreY = y + hh;
  71056. startNewSubPath (centreX + hw * sinf (fromRadians),
  71057. centreY - hh * cosf (fromRadians));
  71058. addArc (x, y, width, height, fromRadians, toRadians);
  71059. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71060. {
  71061. closeSubPath();
  71062. if (innerCircleProportionalSize > 0)
  71063. {
  71064. hw *= innerCircleProportionalSize;
  71065. hh *= innerCircleProportionalSize;
  71066. startNewSubPath (centreX + hw * sinf (toRadians),
  71067. centreY - hh * cosf (toRadians));
  71068. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71069. toRadians, fromRadians);
  71070. }
  71071. }
  71072. else
  71073. {
  71074. if (innerCircleProportionalSize > 0)
  71075. {
  71076. hw *= innerCircleProportionalSize;
  71077. hh *= innerCircleProportionalSize;
  71078. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71079. toRadians, fromRadians);
  71080. }
  71081. else
  71082. {
  71083. lineTo (centreX, centreY);
  71084. }
  71085. }
  71086. closeSubPath();
  71087. }
  71088. void Path::addLineSegment (const float startX, const float startY,
  71089. const float endX, const float endY,
  71090. float lineThickness)
  71091. {
  71092. lineThickness *= 0.5f;
  71093. float x, y;
  71094. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71095. 0, lineThickness, x, y);
  71096. startNewSubPath (x, y);
  71097. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71098. 0, -lineThickness, x, y);
  71099. lineTo (x, y);
  71100. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71101. 0, lineThickness, x, y);
  71102. lineTo (x, y);
  71103. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71104. 0, -lineThickness, x, y);
  71105. lineTo (x, y);
  71106. closeSubPath();
  71107. }
  71108. void Path::addArrow (const float startX, const float startY,
  71109. const float endX, const float endY,
  71110. float lineThickness,
  71111. float arrowheadWidth,
  71112. float arrowheadLength)
  71113. {
  71114. lineThickness *= 0.5f;
  71115. arrowheadWidth *= 0.5f;
  71116. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71117. startY - endY));
  71118. float x, y;
  71119. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71120. 0, lineThickness, x, y);
  71121. startNewSubPath (x, y);
  71122. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71123. 0, -lineThickness, x, y);
  71124. lineTo (x, y);
  71125. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71126. arrowheadLength, lineThickness, x, y);
  71127. lineTo (x, y);
  71128. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71129. arrowheadLength, arrowheadWidth, x, y);
  71130. lineTo (x, y);
  71131. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71132. 0, 0, x, y);
  71133. lineTo (x, y);
  71134. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71135. arrowheadLength, -arrowheadWidth, x, y);
  71136. lineTo (x, y);
  71137. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71138. arrowheadLength, -lineThickness, x, y);
  71139. lineTo (x, y);
  71140. closeSubPath();
  71141. }
  71142. void Path::addStar (const float centreX,
  71143. const float centreY,
  71144. const int numberOfPoints,
  71145. const float innerRadius,
  71146. const float outerRadius,
  71147. const float startAngle)
  71148. {
  71149. jassert (numberOfPoints > 1); // this would be silly.
  71150. if (numberOfPoints > 1)
  71151. {
  71152. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71153. for (int i = 0; i < numberOfPoints; ++i)
  71154. {
  71155. float angle = startAngle + i * angleBetweenPoints;
  71156. const float x = centreX + outerRadius * sinf (angle);
  71157. const float y = centreY - outerRadius * cosf (angle);
  71158. if (i == 0)
  71159. startNewSubPath (x, y);
  71160. else
  71161. lineTo (x, y);
  71162. angle += angleBetweenPoints * 0.5f;
  71163. lineTo (centreX + innerRadius * sinf (angle),
  71164. centreY - innerRadius * cosf (angle));
  71165. }
  71166. closeSubPath();
  71167. }
  71168. }
  71169. void Path::addBubble (float x, float y,
  71170. float w, float h,
  71171. float cs,
  71172. float tipX,
  71173. float tipY,
  71174. int whichSide,
  71175. float arrowPos,
  71176. float arrowWidth)
  71177. {
  71178. if (w > 1.0f && h > 1.0f)
  71179. {
  71180. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71181. const float cs2 = 2.0f * cs;
  71182. startNewSubPath (x + cs, y);
  71183. if (whichSide == 0)
  71184. {
  71185. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71186. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71187. lineTo (arrowX1, y);
  71188. lineTo (tipX, tipY);
  71189. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71190. }
  71191. lineTo (x + w - cs, y);
  71192. if (cs > 0.0f)
  71193. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71194. if (whichSide == 3)
  71195. {
  71196. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71197. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71198. lineTo (x + w, arrowY1);
  71199. lineTo (tipX, tipY);
  71200. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71201. }
  71202. lineTo (x + w, y + h - cs);
  71203. if (cs > 0.0f)
  71204. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71205. if (whichSide == 2)
  71206. {
  71207. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71208. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71209. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71210. lineTo (tipX, tipY);
  71211. lineTo (arrowX1, y + h);
  71212. }
  71213. lineTo (x + cs, y + h);
  71214. if (cs > 0.0f)
  71215. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71216. if (whichSide == 1)
  71217. {
  71218. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71219. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71220. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71221. lineTo (tipX, tipY);
  71222. lineTo (x, arrowY1);
  71223. }
  71224. lineTo (x, y + cs);
  71225. if (cs > 0.0f)
  71226. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71227. closeSubPath();
  71228. }
  71229. }
  71230. void Path::addPath (const Path& other)
  71231. {
  71232. size_t i = 0;
  71233. while (i < other.numElements)
  71234. {
  71235. const float type = other.data.elements [i++];
  71236. if (type == moveMarker)
  71237. {
  71238. startNewSubPath (other.data.elements [i],
  71239. other.data.elements [i + 1]);
  71240. i += 2;
  71241. }
  71242. else if (type == lineMarker)
  71243. {
  71244. lineTo (other.data.elements [i],
  71245. other.data.elements [i + 1]);
  71246. i += 2;
  71247. }
  71248. else if (type == quadMarker)
  71249. {
  71250. quadraticTo (other.data.elements [i],
  71251. other.data.elements [i + 1],
  71252. other.data.elements [i + 2],
  71253. other.data.elements [i + 3]);
  71254. i += 4;
  71255. }
  71256. else if (type == cubicMarker)
  71257. {
  71258. cubicTo (other.data.elements [i],
  71259. other.data.elements [i + 1],
  71260. other.data.elements [i + 2],
  71261. other.data.elements [i + 3],
  71262. other.data.elements [i + 4],
  71263. other.data.elements [i + 5]);
  71264. i += 6;
  71265. }
  71266. else if (type == closeSubPathMarker)
  71267. {
  71268. closeSubPath();
  71269. }
  71270. else
  71271. {
  71272. // something's gone wrong with the element list!
  71273. jassertfalse
  71274. }
  71275. }
  71276. }
  71277. void Path::addPath (const Path& other,
  71278. const AffineTransform& transformToApply)
  71279. {
  71280. size_t i = 0;
  71281. while (i < other.numElements)
  71282. {
  71283. const float type = other.data.elements [i++];
  71284. if (type == closeSubPathMarker)
  71285. {
  71286. closeSubPath();
  71287. }
  71288. else
  71289. {
  71290. float x = other.data.elements [i++];
  71291. float y = other.data.elements [i++];
  71292. transformToApply.transformPoint (x, y);
  71293. if (type == moveMarker)
  71294. {
  71295. startNewSubPath (x, y);
  71296. }
  71297. else if (type == lineMarker)
  71298. {
  71299. lineTo (x, y);
  71300. }
  71301. else if (type == quadMarker)
  71302. {
  71303. float x2 = other.data.elements [i++];
  71304. float y2 = other.data.elements [i++];
  71305. transformToApply.transformPoint (x2, y2);
  71306. quadraticTo (x, y, x2, y2);
  71307. }
  71308. else if (type == cubicMarker)
  71309. {
  71310. float x2 = other.data.elements [i++];
  71311. float y2 = other.data.elements [i++];
  71312. float x3 = other.data.elements [i++];
  71313. float y3 = other.data.elements [i++];
  71314. transformToApply.transformPoint (x2, y2);
  71315. transformToApply.transformPoint (x3, y3);
  71316. cubicTo (x, y, x2, y2, x3, y3);
  71317. }
  71318. else
  71319. {
  71320. // something's gone wrong with the element list!
  71321. jassertfalse
  71322. }
  71323. }
  71324. }
  71325. }
  71326. void Path::applyTransform (const AffineTransform& transform) throw()
  71327. {
  71328. size_t i = 0;
  71329. pathYMin = pathXMin = 0;
  71330. pathYMax = pathXMax = 0;
  71331. bool setMaxMin = false;
  71332. while (i < numElements)
  71333. {
  71334. const float type = data.elements [i++];
  71335. if (type == moveMarker)
  71336. {
  71337. transform.transformPoint (data.elements [i],
  71338. data.elements [i + 1]);
  71339. if (setMaxMin)
  71340. {
  71341. pathXMin = jmin (pathXMin, data.elements [i]);
  71342. pathXMax = jmax (pathXMax, data.elements [i]);
  71343. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71344. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71345. }
  71346. else
  71347. {
  71348. pathXMin = pathXMax = data.elements [i];
  71349. pathYMin = pathYMax = data.elements [i + 1];
  71350. setMaxMin = true;
  71351. }
  71352. i += 2;
  71353. }
  71354. else if (type == lineMarker)
  71355. {
  71356. transform.transformPoint (data.elements [i],
  71357. data.elements [i + 1]);
  71358. pathXMin = jmin (pathXMin, data.elements [i]);
  71359. pathXMax = jmax (pathXMax, data.elements [i]);
  71360. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71361. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71362. i += 2;
  71363. }
  71364. else if (type == quadMarker)
  71365. {
  71366. transform.transformPoint (data.elements [i],
  71367. data.elements [i + 1]);
  71368. transform.transformPoint (data.elements [i + 2],
  71369. data.elements [i + 3]);
  71370. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71371. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71372. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71373. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71374. i += 4;
  71375. }
  71376. else if (type == cubicMarker)
  71377. {
  71378. transform.transformPoint (data.elements [i],
  71379. data.elements [i + 1]);
  71380. transform.transformPoint (data.elements [i + 2],
  71381. data.elements [i + 3]);
  71382. transform.transformPoint (data.elements [i + 4],
  71383. data.elements [i + 5]);
  71384. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71385. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71386. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71387. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71388. i += 6;
  71389. }
  71390. }
  71391. }
  71392. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71393. const float w, const float h,
  71394. const bool preserveProportions,
  71395. const Justification& justification) const
  71396. {
  71397. Rectangle<float> bounds (getBounds());
  71398. if (preserveProportions)
  71399. {
  71400. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71401. return AffineTransform::identity;
  71402. float newW, newH;
  71403. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71404. if (srcRatio > h / w)
  71405. {
  71406. newW = h / srcRatio;
  71407. newH = h;
  71408. }
  71409. else
  71410. {
  71411. newW = w;
  71412. newH = w * srcRatio;
  71413. }
  71414. float newXCentre = x;
  71415. float newYCentre = y;
  71416. if (justification.testFlags (Justification::left))
  71417. newXCentre += newW * 0.5f;
  71418. else if (justification.testFlags (Justification::right))
  71419. newXCentre += w - newW * 0.5f;
  71420. else
  71421. newXCentre += w * 0.5f;
  71422. if (justification.testFlags (Justification::top))
  71423. newYCentre += newH * 0.5f;
  71424. else if (justification.testFlags (Justification::bottom))
  71425. newYCentre += h - newH * 0.5f;
  71426. else
  71427. newYCentre += h * 0.5f;
  71428. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71429. bounds.getHeight() * -0.5f - bounds.getY())
  71430. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71431. .translated (newXCentre, newYCentre);
  71432. }
  71433. else
  71434. {
  71435. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71436. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71437. .translated (x, y);
  71438. }
  71439. }
  71440. bool Path::contains (const float x, const float y, const float tolerence) const
  71441. {
  71442. if (x <= pathXMin || x >= pathXMax
  71443. || y <= pathYMin || y >= pathYMax)
  71444. return false;
  71445. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71446. int positiveCrossings = 0;
  71447. int negativeCrossings = 0;
  71448. while (i.next())
  71449. {
  71450. if ((i.y1 <= y && i.y2 > y)
  71451. || (i.y2 <= y && i.y1 > y))
  71452. {
  71453. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71454. if (intersectX <= x)
  71455. {
  71456. if (i.y1 < i.y2)
  71457. ++positiveCrossings;
  71458. else
  71459. ++negativeCrossings;
  71460. }
  71461. }
  71462. }
  71463. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71464. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71465. }
  71466. bool Path::intersectsLine (const float x1, const float y1,
  71467. const float x2, const float y2,
  71468. const float tolerence)
  71469. {
  71470. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71471. const Line line1 (x1, y1, x2, y2);
  71472. while (i.next())
  71473. {
  71474. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71475. float ix, iy;
  71476. if (line1.intersects (line2, ix, iy))
  71477. return true;
  71478. }
  71479. return false;
  71480. }
  71481. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71482. {
  71483. if (cornerRadius <= 0.01f)
  71484. return *this;
  71485. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71486. size_t n = 0;
  71487. bool lastWasLine = false, firstWasLine = false;
  71488. Path p;
  71489. while (n < numElements)
  71490. {
  71491. const float type = data.elements [n++];
  71492. if (type == moveMarker)
  71493. {
  71494. indexOfPathStart = p.numElements;
  71495. indexOfPathStartThis = n - 1;
  71496. const float x = data.elements [n++];
  71497. const float y = data.elements [n++];
  71498. p.startNewSubPath (x, y);
  71499. lastWasLine = false;
  71500. firstWasLine = (data.elements [n] == lineMarker);
  71501. }
  71502. else if (type == lineMarker || type == closeSubPathMarker)
  71503. {
  71504. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71505. if (type == lineMarker)
  71506. {
  71507. endX = data.elements [n++];
  71508. endY = data.elements [n++];
  71509. if (n > 8)
  71510. {
  71511. startX = data.elements [n - 8];
  71512. startY = data.elements [n - 7];
  71513. joinX = data.elements [n - 5];
  71514. joinY = data.elements [n - 4];
  71515. }
  71516. }
  71517. else
  71518. {
  71519. endX = data.elements [indexOfPathStartThis + 1];
  71520. endY = data.elements [indexOfPathStartThis + 2];
  71521. if (n > 6)
  71522. {
  71523. startX = data.elements [n - 6];
  71524. startY = data.elements [n - 5];
  71525. joinX = data.elements [n - 3];
  71526. joinY = data.elements [n - 2];
  71527. }
  71528. }
  71529. if (lastWasLine)
  71530. {
  71531. const double len1 = juce_hypot (startX - joinX,
  71532. startY - joinY);
  71533. if (len1 > 0)
  71534. {
  71535. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71536. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71537. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71538. }
  71539. const double len2 = juce_hypot (endX - joinX,
  71540. endY - joinY);
  71541. if (len2 > 0)
  71542. {
  71543. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71544. p.quadraticTo (joinX, joinY,
  71545. (float) (joinX + (endX - joinX) * propNeeded),
  71546. (float) (joinY + (endY - joinY) * propNeeded));
  71547. }
  71548. p.lineTo (endX, endY);
  71549. }
  71550. else if (type == lineMarker)
  71551. {
  71552. p.lineTo (endX, endY);
  71553. lastWasLine = true;
  71554. }
  71555. if (type == closeSubPathMarker)
  71556. {
  71557. if (firstWasLine)
  71558. {
  71559. startX = data.elements [n - 3];
  71560. startY = data.elements [n - 2];
  71561. joinX = endX;
  71562. joinY = endY;
  71563. endX = data.elements [indexOfPathStartThis + 4];
  71564. endY = data.elements [indexOfPathStartThis + 5];
  71565. const double len1 = juce_hypot (startX - joinX,
  71566. startY - joinY);
  71567. if (len1 > 0)
  71568. {
  71569. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71570. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71571. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71572. }
  71573. const double len2 = juce_hypot (endX - joinX,
  71574. endY - joinY);
  71575. if (len2 > 0)
  71576. {
  71577. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71578. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71579. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71580. p.quadraticTo (joinX, joinY, endX, endY);
  71581. p.data.elements [indexOfPathStart + 1] = endX;
  71582. p.data.elements [indexOfPathStart + 2] = endY;
  71583. }
  71584. }
  71585. p.closeSubPath();
  71586. }
  71587. }
  71588. else if (type == quadMarker)
  71589. {
  71590. lastWasLine = false;
  71591. const float x1 = data.elements [n++];
  71592. const float y1 = data.elements [n++];
  71593. const float x2 = data.elements [n++];
  71594. const float y2 = data.elements [n++];
  71595. p.quadraticTo (x1, y1, x2, y2);
  71596. }
  71597. else if (type == cubicMarker)
  71598. {
  71599. lastWasLine = false;
  71600. const float x1 = data.elements [n++];
  71601. const float y1 = data.elements [n++];
  71602. const float x2 = data.elements [n++];
  71603. const float y2 = data.elements [n++];
  71604. const float x3 = data.elements [n++];
  71605. const float y3 = data.elements [n++];
  71606. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71607. }
  71608. }
  71609. return p;
  71610. }
  71611. void Path::loadPathFromStream (InputStream& source)
  71612. {
  71613. while (! source.isExhausted())
  71614. {
  71615. switch (source.readByte())
  71616. {
  71617. case 'm':
  71618. {
  71619. const float x = source.readFloat();
  71620. const float y = source.readFloat();
  71621. startNewSubPath (x, y);
  71622. break;
  71623. }
  71624. case 'l':
  71625. {
  71626. const float x = source.readFloat();
  71627. const float y = source.readFloat();
  71628. lineTo (x, y);
  71629. break;
  71630. }
  71631. case 'q':
  71632. {
  71633. const float x1 = source.readFloat();
  71634. const float y1 = source.readFloat();
  71635. const float x2 = source.readFloat();
  71636. const float y2 = source.readFloat();
  71637. quadraticTo (x1, y1, x2, y2);
  71638. break;
  71639. }
  71640. case 'b':
  71641. {
  71642. const float x1 = source.readFloat();
  71643. const float y1 = source.readFloat();
  71644. const float x2 = source.readFloat();
  71645. const float y2 = source.readFloat();
  71646. const float x3 = source.readFloat();
  71647. const float y3 = source.readFloat();
  71648. cubicTo (x1, y1, x2, y2, x3, y3);
  71649. break;
  71650. }
  71651. case 'c':
  71652. closeSubPath();
  71653. break;
  71654. case 'n':
  71655. useNonZeroWinding = true;
  71656. break;
  71657. case 'z':
  71658. useNonZeroWinding = false;
  71659. break;
  71660. case 'e':
  71661. return; // end of path marker
  71662. default:
  71663. jassertfalse // illegal char in the stream
  71664. break;
  71665. }
  71666. }
  71667. }
  71668. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71669. {
  71670. MemoryInputStream in (data, numberOfBytes, false);
  71671. loadPathFromStream (in);
  71672. }
  71673. void Path::writePathToStream (OutputStream& dest) const
  71674. {
  71675. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71676. size_t i = 0;
  71677. while (i < numElements)
  71678. {
  71679. const float type = data.elements [i++];
  71680. if (type == moveMarker)
  71681. {
  71682. dest.writeByte ('m');
  71683. dest.writeFloat (data.elements [i++]);
  71684. dest.writeFloat (data.elements [i++]);
  71685. }
  71686. else if (type == lineMarker)
  71687. {
  71688. dest.writeByte ('l');
  71689. dest.writeFloat (data.elements [i++]);
  71690. dest.writeFloat (data.elements [i++]);
  71691. }
  71692. else if (type == quadMarker)
  71693. {
  71694. dest.writeByte ('q');
  71695. dest.writeFloat (data.elements [i++]);
  71696. dest.writeFloat (data.elements [i++]);
  71697. dest.writeFloat (data.elements [i++]);
  71698. dest.writeFloat (data.elements [i++]);
  71699. }
  71700. else if (type == cubicMarker)
  71701. {
  71702. dest.writeByte ('b');
  71703. dest.writeFloat (data.elements [i++]);
  71704. dest.writeFloat (data.elements [i++]);
  71705. dest.writeFloat (data.elements [i++]);
  71706. dest.writeFloat (data.elements [i++]);
  71707. dest.writeFloat (data.elements [i++]);
  71708. dest.writeFloat (data.elements [i++]);
  71709. }
  71710. else if (type == closeSubPathMarker)
  71711. {
  71712. dest.writeByte ('c');
  71713. }
  71714. }
  71715. dest.writeByte ('e'); // marks the end-of-path
  71716. }
  71717. const String Path::toString() const
  71718. {
  71719. MemoryOutputStream s (2048, 2048);
  71720. if (! useNonZeroWinding)
  71721. s << 'a';
  71722. size_t i = 0;
  71723. float lastMarker = 0.0f;
  71724. while (i < numElements)
  71725. {
  71726. const float marker = data.elements [i++];
  71727. char markerChar = 0;
  71728. int numCoords = 0;
  71729. if (marker == moveMarker)
  71730. {
  71731. markerChar = 'm';
  71732. numCoords = 2;
  71733. }
  71734. else if (marker == lineMarker)
  71735. {
  71736. markerChar = 'l';
  71737. numCoords = 2;
  71738. }
  71739. else if (marker == quadMarker)
  71740. {
  71741. markerChar = 'q';
  71742. numCoords = 4;
  71743. }
  71744. else if (marker == cubicMarker)
  71745. {
  71746. markerChar = 'c';
  71747. numCoords = 6;
  71748. }
  71749. else
  71750. {
  71751. jassert (marker == closeSubPathMarker);
  71752. markerChar = 'z';
  71753. }
  71754. if (marker != lastMarker)
  71755. {
  71756. if (s.getDataSize() != 0)
  71757. s << ' ';
  71758. s << markerChar;
  71759. lastMarker = marker;
  71760. }
  71761. while (--numCoords >= 0 && i < numElements)
  71762. {
  71763. String coord (data.elements [i++], 3);
  71764. while (coord.endsWithChar ('0') && coord != "0")
  71765. coord = coord.dropLastCharacters (1);
  71766. if (coord.endsWithChar ('.'))
  71767. coord = coord.dropLastCharacters (1);
  71768. if (s.getDataSize() != 0)
  71769. s << ' ';
  71770. s << coord;
  71771. }
  71772. }
  71773. return s.toUTF8();
  71774. }
  71775. void Path::restoreFromString (const String& stringVersion)
  71776. {
  71777. clear();
  71778. setUsingNonZeroWinding (true);
  71779. const juce_wchar* t = stringVersion;
  71780. juce_wchar marker = 'm';
  71781. int numValues = 2;
  71782. float values [6];
  71783. while (*t != 0)
  71784. {
  71785. const String token (PathHelpers::nextToken (t));
  71786. const juce_wchar firstChar = token[0];
  71787. int startNum = 0;
  71788. if (firstChar == 'm' || firstChar == 'l')
  71789. {
  71790. marker = firstChar;
  71791. numValues = 2;
  71792. }
  71793. else if (firstChar == 'q')
  71794. {
  71795. marker = firstChar;
  71796. numValues = 4;
  71797. }
  71798. else if (firstChar == 'c')
  71799. {
  71800. marker = firstChar;
  71801. numValues = 6;
  71802. }
  71803. else if (firstChar == 'z')
  71804. {
  71805. marker = firstChar;
  71806. numValues = 0;
  71807. }
  71808. else if (firstChar == 'a')
  71809. {
  71810. setUsingNonZeroWinding (false);
  71811. continue;
  71812. }
  71813. else
  71814. {
  71815. ++startNum;
  71816. values [0] = token.getFloatValue();
  71817. }
  71818. for (int i = startNum; i < numValues; ++i)
  71819. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71820. switch (marker)
  71821. {
  71822. case 'm':
  71823. startNewSubPath (values[0], values[1]);
  71824. break;
  71825. case 'l':
  71826. lineTo (values[0], values[1]);
  71827. break;
  71828. case 'q':
  71829. quadraticTo (values[0], values[1],
  71830. values[2], values[3]);
  71831. break;
  71832. case 'c':
  71833. cubicTo (values[0], values[1],
  71834. values[2], values[3],
  71835. values[4], values[5]);
  71836. break;
  71837. case 'z':
  71838. closeSubPath();
  71839. break;
  71840. default:
  71841. jassertfalse // illegal string format?
  71842. break;
  71843. }
  71844. }
  71845. }
  71846. Path::Iterator::Iterator (const Path& path_)
  71847. : path (path_),
  71848. index (0)
  71849. {
  71850. }
  71851. Path::Iterator::~Iterator()
  71852. {
  71853. }
  71854. bool Path::Iterator::next()
  71855. {
  71856. const float* const elements = path.data.elements;
  71857. if (index < path.numElements)
  71858. {
  71859. const float type = elements [index++];
  71860. if (type == moveMarker)
  71861. {
  71862. elementType = startNewSubPath;
  71863. x1 = elements [index++];
  71864. y1 = elements [index++];
  71865. }
  71866. else if (type == lineMarker)
  71867. {
  71868. elementType = lineTo;
  71869. x1 = elements [index++];
  71870. y1 = elements [index++];
  71871. }
  71872. else if (type == quadMarker)
  71873. {
  71874. elementType = quadraticTo;
  71875. x1 = elements [index++];
  71876. y1 = elements [index++];
  71877. x2 = elements [index++];
  71878. y2 = elements [index++];
  71879. }
  71880. else if (type == cubicMarker)
  71881. {
  71882. elementType = cubicTo;
  71883. x1 = elements [index++];
  71884. y1 = elements [index++];
  71885. x2 = elements [index++];
  71886. y2 = elements [index++];
  71887. x3 = elements [index++];
  71888. y3 = elements [index++];
  71889. }
  71890. else if (type == closeSubPathMarker)
  71891. {
  71892. elementType = closePath;
  71893. }
  71894. return true;
  71895. }
  71896. return false;
  71897. }
  71898. END_JUCE_NAMESPACE
  71899. /*** End of inlined file: juce_Path.cpp ***/
  71900. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71901. BEGIN_JUCE_NAMESPACE
  71902. #if JUCE_MSVC
  71903. #pragma optimize ("t", on)
  71904. #endif
  71905. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71906. const AffineTransform& transform_,
  71907. float tolerence_)
  71908. : x2 (0),
  71909. y2 (0),
  71910. closesSubPath (false),
  71911. subPathIndex (-1),
  71912. path (path_),
  71913. transform (transform_),
  71914. points (path_.data.elements),
  71915. tolerence (tolerence_ * tolerence_),
  71916. subPathCloseX (0),
  71917. subPathCloseY (0),
  71918. isIdentityTransform (transform_.isIdentity()),
  71919. stackBase (32),
  71920. index (0),
  71921. stackSize (32)
  71922. {
  71923. stackPos = stackBase;
  71924. }
  71925. PathFlatteningIterator::~PathFlatteningIterator()
  71926. {
  71927. }
  71928. bool PathFlatteningIterator::next()
  71929. {
  71930. x1 = x2;
  71931. y1 = y2;
  71932. float x3 = 0;
  71933. float y3 = 0;
  71934. float x4 = 0;
  71935. float y4 = 0;
  71936. float type;
  71937. for (;;)
  71938. {
  71939. if (stackPos == stackBase)
  71940. {
  71941. if (index >= path.numElements)
  71942. {
  71943. return false;
  71944. }
  71945. else
  71946. {
  71947. type = points [index++];
  71948. if (type != Path::closeSubPathMarker)
  71949. {
  71950. x2 = points [index++];
  71951. y2 = points [index++];
  71952. if (! isIdentityTransform)
  71953. transform.transformPoint (x2, y2);
  71954. if (type == Path::quadMarker)
  71955. {
  71956. x3 = points [index++];
  71957. y3 = points [index++];
  71958. if (! isIdentityTransform)
  71959. transform.transformPoint (x3, y3);
  71960. }
  71961. else if (type == Path::cubicMarker)
  71962. {
  71963. x3 = points [index++];
  71964. y3 = points [index++];
  71965. x4 = points [index++];
  71966. y4 = points [index++];
  71967. if (! isIdentityTransform)
  71968. {
  71969. transform.transformPoint (x3, y3);
  71970. transform.transformPoint (x4, y4);
  71971. }
  71972. }
  71973. }
  71974. }
  71975. }
  71976. else
  71977. {
  71978. type = *--stackPos;
  71979. if (type != Path::closeSubPathMarker)
  71980. {
  71981. x2 = *--stackPos;
  71982. y2 = *--stackPos;
  71983. if (type == Path::quadMarker)
  71984. {
  71985. x3 = *--stackPos;
  71986. y3 = *--stackPos;
  71987. }
  71988. else if (type == Path::cubicMarker)
  71989. {
  71990. x3 = *--stackPos;
  71991. y3 = *--stackPos;
  71992. x4 = *--stackPos;
  71993. y4 = *--stackPos;
  71994. }
  71995. }
  71996. }
  71997. if (type == Path::lineMarker)
  71998. {
  71999. ++subPathIndex;
  72000. closesSubPath = (stackPos == stackBase)
  72001. && (index < path.numElements)
  72002. && (points [index] == Path::closeSubPathMarker)
  72003. && x2 == subPathCloseX
  72004. && y2 == subPathCloseY;
  72005. return true;
  72006. }
  72007. else if (type == Path::quadMarker)
  72008. {
  72009. const size_t offset = (size_t) (stackPos - stackBase);
  72010. if (offset >= stackSize - 10)
  72011. {
  72012. stackSize <<= 1;
  72013. stackBase.realloc (stackSize);
  72014. stackPos = stackBase + offset;
  72015. }
  72016. const float dx1 = x1 - x2;
  72017. const float dy1 = y1 - y2;
  72018. const float dx2 = x2 - x3;
  72019. const float dy2 = y2 - y3;
  72020. const float m1x = (x1 + x2) * 0.5f;
  72021. const float m1y = (y1 + y2) * 0.5f;
  72022. const float m2x = (x2 + x3) * 0.5f;
  72023. const float m2y = (y2 + y3) * 0.5f;
  72024. const float m3x = (m1x + m2x) * 0.5f;
  72025. const float m3y = (m1y + m2y) * 0.5f;
  72026. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72027. {
  72028. *stackPos++ = y3;
  72029. *stackPos++ = x3;
  72030. *stackPos++ = m2y;
  72031. *stackPos++ = m2x;
  72032. *stackPos++ = Path::quadMarker;
  72033. *stackPos++ = m3y;
  72034. *stackPos++ = m3x;
  72035. *stackPos++ = m1y;
  72036. *stackPos++ = m1x;
  72037. *stackPos++ = Path::quadMarker;
  72038. }
  72039. else
  72040. {
  72041. *stackPos++ = y3;
  72042. *stackPos++ = x3;
  72043. *stackPos++ = Path::lineMarker;
  72044. *stackPos++ = m3y;
  72045. *stackPos++ = m3x;
  72046. *stackPos++ = Path::lineMarker;
  72047. }
  72048. jassert (stackPos < stackBase + stackSize);
  72049. }
  72050. else if (type == Path::cubicMarker)
  72051. {
  72052. const size_t offset = (size_t) (stackPos - stackBase);
  72053. if (offset >= stackSize - 16)
  72054. {
  72055. stackSize <<= 1;
  72056. stackBase.realloc (stackSize);
  72057. stackPos = stackBase + offset;
  72058. }
  72059. const float dx1 = x1 - x2;
  72060. const float dy1 = y1 - y2;
  72061. const float dx2 = x2 - x3;
  72062. const float dy2 = y2 - y3;
  72063. const float dx3 = x3 - x4;
  72064. const float dy3 = y3 - y4;
  72065. const float m1x = (x1 + x2) * 0.5f;
  72066. const float m1y = (y1 + y2) * 0.5f;
  72067. const float m2x = (x3 + x2) * 0.5f;
  72068. const float m2y = (y3 + y2) * 0.5f;
  72069. const float m3x = (x3 + x4) * 0.5f;
  72070. const float m3y = (y3 + y4) * 0.5f;
  72071. const float m4x = (m1x + m2x) * 0.5f;
  72072. const float m4y = (m1y + m2y) * 0.5f;
  72073. const float m5x = (m3x + m2x) * 0.5f;
  72074. const float m5y = (m3y + m2y) * 0.5f;
  72075. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72076. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72077. {
  72078. *stackPos++ = y4;
  72079. *stackPos++ = x4;
  72080. *stackPos++ = m3y;
  72081. *stackPos++ = m3x;
  72082. *stackPos++ = m5y;
  72083. *stackPos++ = m5x;
  72084. *stackPos++ = Path::cubicMarker;
  72085. *stackPos++ = (m4y + m5y) * 0.5f;
  72086. *stackPos++ = (m4x + m5x) * 0.5f;
  72087. *stackPos++ = m4y;
  72088. *stackPos++ = m4x;
  72089. *stackPos++ = m1y;
  72090. *stackPos++ = m1x;
  72091. *stackPos++ = Path::cubicMarker;
  72092. }
  72093. else
  72094. {
  72095. *stackPos++ = y4;
  72096. *stackPos++ = x4;
  72097. *stackPos++ = Path::lineMarker;
  72098. *stackPos++ = m5y;
  72099. *stackPos++ = m5x;
  72100. *stackPos++ = Path::lineMarker;
  72101. *stackPos++ = m4y;
  72102. *stackPos++ = m4x;
  72103. *stackPos++ = Path::lineMarker;
  72104. }
  72105. }
  72106. else if (type == Path::closeSubPathMarker)
  72107. {
  72108. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72109. {
  72110. x1 = x2;
  72111. y1 = y2;
  72112. x2 = subPathCloseX;
  72113. y2 = subPathCloseY;
  72114. closesSubPath = true;
  72115. return true;
  72116. }
  72117. }
  72118. else
  72119. {
  72120. jassert (type == Path::moveMarker);
  72121. subPathIndex = -1;
  72122. subPathCloseX = x1 = x2;
  72123. subPathCloseY = y1 = y2;
  72124. }
  72125. }
  72126. }
  72127. END_JUCE_NAMESPACE
  72128. /*** End of inlined file: juce_PathIterator.cpp ***/
  72129. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72130. BEGIN_JUCE_NAMESPACE
  72131. PathStrokeType::PathStrokeType (const float strokeThickness,
  72132. const JointStyle jointStyle_,
  72133. const EndCapStyle endStyle_) throw()
  72134. : thickness (strokeThickness),
  72135. jointStyle (jointStyle_),
  72136. endStyle (endStyle_)
  72137. {
  72138. }
  72139. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72140. : thickness (other.thickness),
  72141. jointStyle (other.jointStyle),
  72142. endStyle (other.endStyle)
  72143. {
  72144. }
  72145. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72146. {
  72147. thickness = other.thickness;
  72148. jointStyle = other.jointStyle;
  72149. endStyle = other.endStyle;
  72150. return *this;
  72151. }
  72152. PathStrokeType::~PathStrokeType() throw()
  72153. {
  72154. }
  72155. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72156. {
  72157. return thickness == other.thickness
  72158. && jointStyle == other.jointStyle
  72159. && endStyle == other.endStyle;
  72160. }
  72161. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72162. {
  72163. return ! operator== (other);
  72164. }
  72165. static bool lineIntersection (const float x1, const float y1,
  72166. const float x2, const float y2,
  72167. const float x3, const float y3,
  72168. const float x4, const float y4,
  72169. float& intersectionX,
  72170. float& intersectionY,
  72171. float& distanceBeyondLine1EndSquared) throw()
  72172. {
  72173. if (x2 != x3 || y2 != y3)
  72174. {
  72175. const float dx1 = x2 - x1;
  72176. const float dy1 = y2 - y1;
  72177. const float dx2 = x4 - x3;
  72178. const float dy2 = y4 - y3;
  72179. const float divisor = dx1 * dy2 - dx2 * dy1;
  72180. if (divisor == 0)
  72181. {
  72182. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72183. {
  72184. if (dy1 == 0 && dy2 != 0)
  72185. {
  72186. const float along = (y1 - y3) / dy2;
  72187. intersectionX = x3 + along * dx2;
  72188. intersectionY = y1;
  72189. distanceBeyondLine1EndSquared = intersectionX - x2;
  72190. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72191. if ((x2 > x1) == (intersectionX < x2))
  72192. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72193. return along >= 0 && along <= 1.0f;
  72194. }
  72195. else if (dy2 == 0 && dy1 != 0)
  72196. {
  72197. const float along = (y3 - y1) / dy1;
  72198. intersectionX = x1 + along * dx1;
  72199. intersectionY = y3;
  72200. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72201. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72202. if (along < 1.0f)
  72203. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72204. return along >= 0 && along <= 1.0f;
  72205. }
  72206. else if (dx1 == 0 && dx2 != 0)
  72207. {
  72208. const float along = (x1 - x3) / dx2;
  72209. intersectionX = x1;
  72210. intersectionY = y3 + along * dy2;
  72211. distanceBeyondLine1EndSquared = intersectionY - y2;
  72212. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72213. if ((y2 > y1) == (intersectionY < y2))
  72214. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72215. return along >= 0 && along <= 1.0f;
  72216. }
  72217. else if (dx2 == 0 && dx1 != 0)
  72218. {
  72219. const float along = (x3 - x1) / dx1;
  72220. intersectionX = x3;
  72221. intersectionY = y1 + along * dy1;
  72222. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72223. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72224. if (along < 1.0f)
  72225. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72226. return along >= 0 && along <= 1.0f;
  72227. }
  72228. }
  72229. intersectionX = 0.5f * (x2 + x3);
  72230. intersectionY = 0.5f * (y2 + y3);
  72231. distanceBeyondLine1EndSquared = 0.0f;
  72232. return false;
  72233. }
  72234. else
  72235. {
  72236. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72237. intersectionX = x1 + along1 * dx1;
  72238. intersectionY = y1 + along1 * dy1;
  72239. if (along1 >= 0 && along1 <= 1.0f)
  72240. {
  72241. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72242. if (along2 >= 0 && along2 <= divisor)
  72243. {
  72244. distanceBeyondLine1EndSquared = 0.0f;
  72245. return true;
  72246. }
  72247. }
  72248. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72249. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72250. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72251. if (along1 < 1.0f)
  72252. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72253. return false;
  72254. }
  72255. }
  72256. intersectionX = x2;
  72257. intersectionY = y2;
  72258. distanceBeyondLine1EndSquared = 0.0f;
  72259. return true;
  72260. }
  72261. namespace PathFunctions
  72262. {
  72263. // part of stroke drawing stuff
  72264. static void addEdgeAndJoint (Path& destPath,
  72265. const PathStrokeType::JointStyle style,
  72266. const float maxMiterExtensionSquared, const float width,
  72267. const float x1, const float y1,
  72268. const float x2, const float y2,
  72269. const float x3, const float y3,
  72270. const float x4, const float y4,
  72271. const float midX, const float midY)
  72272. {
  72273. if (style == PathStrokeType::beveled
  72274. || (x3 == x4 && y3 == y4)
  72275. || (x1 == x2 && y1 == y2))
  72276. {
  72277. destPath.lineTo (x2, y2);
  72278. destPath.lineTo (x3, y3);
  72279. }
  72280. else
  72281. {
  72282. float jx, jy, distanceBeyondLine1EndSquared;
  72283. // if they intersect, use this point..
  72284. if (lineIntersection (x1, y1, x2, y2,
  72285. x3, y3, x4, y4,
  72286. jx, jy, distanceBeyondLine1EndSquared))
  72287. {
  72288. destPath.lineTo (jx, jy);
  72289. }
  72290. else
  72291. {
  72292. if (style == PathStrokeType::mitered)
  72293. {
  72294. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72295. && distanceBeyondLine1EndSquared > 0.0f)
  72296. {
  72297. destPath.lineTo (jx, jy);
  72298. }
  72299. else
  72300. {
  72301. // the end sticks out too far, so just use a blunt joint
  72302. destPath.lineTo (x2, y2);
  72303. destPath.lineTo (x3, y3);
  72304. }
  72305. }
  72306. else
  72307. {
  72308. // curved joints
  72309. float angle1 = atan2f (x2 - midX, y2 - midY);
  72310. float angle2 = atan2f (x3 - midX, y3 - midY);
  72311. const float angleIncrement = 0.1f;
  72312. destPath.lineTo (x2, y2);
  72313. if (fabs (angle1 - angle2) > angleIncrement)
  72314. {
  72315. if (angle2 > angle1 + float_Pi
  72316. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72317. {
  72318. if (angle2 > angle1)
  72319. angle2 -= float_Pi * 2.0f;
  72320. jassert (angle1 <= angle2 + float_Pi);
  72321. angle1 -= angleIncrement;
  72322. while (angle1 > angle2)
  72323. {
  72324. destPath.lineTo (midX + width * sinf (angle1),
  72325. midY + width * cosf (angle1));
  72326. angle1 -= angleIncrement;
  72327. }
  72328. }
  72329. else
  72330. {
  72331. if (angle1 > angle2)
  72332. angle1 -= float_Pi * 2.0f;
  72333. jassert (angle1 >= angle2 - float_Pi);
  72334. angle1 += angleIncrement;
  72335. while (angle1 < angle2)
  72336. {
  72337. destPath.lineTo (midX + width * sinf (angle1),
  72338. midY + width * cosf (angle1));
  72339. angle1 += angleIncrement;
  72340. }
  72341. }
  72342. }
  72343. destPath.lineTo (x3, y3);
  72344. }
  72345. }
  72346. }
  72347. }
  72348. static void addLineEnd (Path& destPath,
  72349. const PathStrokeType::EndCapStyle style,
  72350. const float x1, const float y1,
  72351. const float x2, const float y2,
  72352. const float width)
  72353. {
  72354. if (style == PathStrokeType::butt)
  72355. {
  72356. destPath.lineTo (x2, y2);
  72357. }
  72358. else
  72359. {
  72360. float offx1, offy1, offx2, offy2;
  72361. float dx = x2 - x1;
  72362. float dy = y2 - y1;
  72363. const float len = juce_hypotf (dx, dy);
  72364. if (len == 0)
  72365. {
  72366. offx1 = offx2 = x1;
  72367. offy1 = offy2 = y1;
  72368. }
  72369. else
  72370. {
  72371. const float offset = width / len;
  72372. dx *= offset;
  72373. dy *= offset;
  72374. offx1 = x1 + dy;
  72375. offy1 = y1 - dx;
  72376. offx2 = x2 + dy;
  72377. offy2 = y2 - dx;
  72378. }
  72379. if (style == PathStrokeType::square)
  72380. {
  72381. // sqaure ends
  72382. destPath.lineTo (offx1, offy1);
  72383. destPath.lineTo (offx2, offy2);
  72384. destPath.lineTo (x2, y2);
  72385. }
  72386. else
  72387. {
  72388. // rounded ends
  72389. const float midx = (offx1 + offx2) * 0.5f;
  72390. const float midy = (offy1 + offy2) * 0.5f;
  72391. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72392. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72393. midx, midy);
  72394. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72395. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72396. x2, y2);
  72397. }
  72398. }
  72399. }
  72400. struct LineSection
  72401. {
  72402. LineSection() {}
  72403. LineSection (int) {}
  72404. float x1, y1, x2, y2; // original line
  72405. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72406. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72407. };
  72408. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72409. const bool isClosed,
  72410. const float width, const float maxMiterExtensionSquared,
  72411. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72412. {
  72413. jassert (subPath.size() > 0);
  72414. const LineSection& firstLine = subPath.getReference (0);
  72415. float lastX1 = firstLine.lx1;
  72416. float lastY1 = firstLine.ly1;
  72417. float lastX2 = firstLine.lx2;
  72418. float lastY2 = firstLine.ly2;
  72419. if (isClosed)
  72420. {
  72421. destPath.startNewSubPath (lastX1, lastY1);
  72422. }
  72423. else
  72424. {
  72425. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72426. addLineEnd (destPath, endStyle,
  72427. firstLine.rx2, firstLine.ry2,
  72428. lastX1, lastY1,
  72429. width);
  72430. }
  72431. int i;
  72432. for (i = 1; i < subPath.size(); ++i)
  72433. {
  72434. const LineSection& l = subPath.getReference (i);
  72435. addEdgeAndJoint (destPath, jointStyle,
  72436. maxMiterExtensionSquared, width,
  72437. lastX1, lastY1, lastX2, lastY2,
  72438. l.lx1, l.ly1, l.lx2, l.ly2,
  72439. l.x1, l.y1);
  72440. lastX1 = l.lx1;
  72441. lastY1 = l.ly1;
  72442. lastX2 = l.lx2;
  72443. lastY2 = l.ly2;
  72444. }
  72445. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72446. if (isClosed)
  72447. {
  72448. const LineSection& l = subPath.getReference (0);
  72449. addEdgeAndJoint (destPath, jointStyle,
  72450. maxMiterExtensionSquared, width,
  72451. lastX1, lastY1, lastX2, lastY2,
  72452. l.lx1, l.ly1, l.lx2, l.ly2,
  72453. l.x1, l.y1);
  72454. destPath.closeSubPath();
  72455. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72456. }
  72457. else
  72458. {
  72459. destPath.lineTo (lastX2, lastY2);
  72460. addLineEnd (destPath, endStyle,
  72461. lastX2, lastY2,
  72462. lastLine.rx1, lastLine.ry1,
  72463. width);
  72464. }
  72465. lastX1 = lastLine.rx1;
  72466. lastY1 = lastLine.ry1;
  72467. lastX2 = lastLine.rx2;
  72468. lastY2 = lastLine.ry2;
  72469. for (i = subPath.size() - 1; --i >= 0;)
  72470. {
  72471. const LineSection& l = subPath.getReference (i);
  72472. addEdgeAndJoint (destPath, jointStyle,
  72473. maxMiterExtensionSquared, width,
  72474. lastX1, lastY1, lastX2, lastY2,
  72475. l.rx1, l.ry1, l.rx2, l.ry2,
  72476. l.x2, l.y2);
  72477. lastX1 = l.rx1;
  72478. lastY1 = l.ry1;
  72479. lastX2 = l.rx2;
  72480. lastY2 = l.ry2;
  72481. }
  72482. if (isClosed)
  72483. {
  72484. addEdgeAndJoint (destPath, jointStyle,
  72485. maxMiterExtensionSquared, width,
  72486. lastX1, lastY1, lastX2, lastY2,
  72487. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72488. lastLine.x2, lastLine.y2);
  72489. }
  72490. else
  72491. {
  72492. // do the last line
  72493. destPath.lineTo (lastX2, lastY2);
  72494. }
  72495. destPath.closeSubPath();
  72496. }
  72497. }
  72498. void PathStrokeType::createStrokedPath (Path& destPath,
  72499. const Path& source,
  72500. const AffineTransform& transform,
  72501. const float extraAccuracy) const
  72502. {
  72503. if (thickness <= 0)
  72504. {
  72505. destPath.clear();
  72506. return;
  72507. }
  72508. const Path* sourcePath = &source;
  72509. Path temp;
  72510. if (sourcePath == &destPath)
  72511. {
  72512. destPath.swapWithPath (temp);
  72513. sourcePath = &temp;
  72514. }
  72515. else
  72516. {
  72517. destPath.clear();
  72518. }
  72519. destPath.setUsingNonZeroWinding (true);
  72520. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72521. const float width = 0.5f * thickness;
  72522. // Iterate the path, creating a list of the
  72523. // left/right-hand lines along either side of it...
  72524. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72525. using namespace PathFunctions;
  72526. Array <LineSection> subPath;
  72527. LineSection l;
  72528. l.x1 = 0;
  72529. l.y1 = 0;
  72530. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72531. while (it.next())
  72532. {
  72533. if (it.subPathIndex == 0)
  72534. {
  72535. if (subPath.size() > 0)
  72536. {
  72537. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72538. subPath.clearQuick();
  72539. }
  72540. l.x1 = it.x1;
  72541. l.y1 = it.y1;
  72542. }
  72543. l.x2 = it.x2;
  72544. l.y2 = it.y2;
  72545. float dx = l.x2 - l.x1;
  72546. float dy = l.y2 - l.y1;
  72547. const float hypotSquared = dx*dx + dy*dy;
  72548. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72549. {
  72550. const float len = sqrtf (hypotSquared);
  72551. if (len == 0)
  72552. {
  72553. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72554. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72555. }
  72556. else
  72557. {
  72558. const float offset = width / len;
  72559. dx *= offset;
  72560. dy *= offset;
  72561. l.rx2 = l.x1 - dy;
  72562. l.ry2 = l.y1 + dx;
  72563. l.lx1 = l.x1 + dy;
  72564. l.ly1 = l.y1 - dx;
  72565. l.lx2 = l.x2 + dy;
  72566. l.ly2 = l.y2 - dx;
  72567. l.rx1 = l.x2 - dy;
  72568. l.ry1 = l.y2 + dx;
  72569. }
  72570. subPath.add (l);
  72571. if (it.closesSubPath)
  72572. {
  72573. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72574. subPath.clearQuick();
  72575. }
  72576. else
  72577. {
  72578. l.x1 = it.x2;
  72579. l.y1 = it.y2;
  72580. }
  72581. }
  72582. }
  72583. if (subPath.size() > 0)
  72584. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72585. }
  72586. void PathStrokeType::createDashedStroke (Path& destPath,
  72587. const Path& sourcePath,
  72588. const float* dashLengths,
  72589. int numDashLengths,
  72590. const AffineTransform& transform,
  72591. const float extraAccuracy) const
  72592. {
  72593. if (thickness <= 0)
  72594. return;
  72595. // this should really be an even number..
  72596. jassert ((numDashLengths & 1) == 0);
  72597. Path newDestPath;
  72598. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72599. bool first = true;
  72600. int dashNum = 0;
  72601. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72602. float dx = 0.0f, dy = 0.0f;
  72603. for (;;)
  72604. {
  72605. const bool isSolid = ((dashNum & 1) == 0);
  72606. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72607. jassert (dashLen > 0); // must be a positive increment!
  72608. if (dashLen <= 0)
  72609. break;
  72610. pos += dashLen;
  72611. while (pos > lineEndPos)
  72612. {
  72613. if (! it.next())
  72614. {
  72615. if (isSolid && ! first)
  72616. newDestPath.lineTo (it.x2, it.y2);
  72617. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72618. return;
  72619. }
  72620. if (isSolid && ! first)
  72621. newDestPath.lineTo (it.x1, it.y1);
  72622. else
  72623. newDestPath.startNewSubPath (it.x1, it.y1);
  72624. dx = it.x2 - it.x1;
  72625. dy = it.y2 - it.y1;
  72626. lineLen = juce_hypotf (dx, dy);
  72627. lineEndPos += lineLen;
  72628. first = it.closesSubPath;
  72629. }
  72630. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72631. if (isSolid)
  72632. newDestPath.lineTo (it.x1 + dx * alpha,
  72633. it.y1 + dy * alpha);
  72634. else
  72635. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72636. it.y1 + dy * alpha);
  72637. }
  72638. }
  72639. END_JUCE_NAMESPACE
  72640. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72641. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72642. BEGIN_JUCE_NAMESPACE
  72643. PositionedRectangle::PositionedRectangle() throw()
  72644. : x (0.0),
  72645. y (0.0),
  72646. w (0.0),
  72647. h (0.0),
  72648. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72649. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72650. wMode (absoluteSize),
  72651. hMode (absoluteSize)
  72652. {
  72653. }
  72654. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72655. : x (other.x),
  72656. y (other.y),
  72657. w (other.w),
  72658. h (other.h),
  72659. xMode (other.xMode),
  72660. yMode (other.yMode),
  72661. wMode (other.wMode),
  72662. hMode (other.hMode)
  72663. {
  72664. }
  72665. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72666. {
  72667. x = other.x;
  72668. y = other.y;
  72669. w = other.w;
  72670. h = other.h;
  72671. xMode = other.xMode;
  72672. yMode = other.yMode;
  72673. wMode = other.wMode;
  72674. hMode = other.hMode;
  72675. return *this;
  72676. }
  72677. PositionedRectangle::~PositionedRectangle() throw()
  72678. {
  72679. }
  72680. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72681. {
  72682. return x == other.x
  72683. && y == other.y
  72684. && w == other.w
  72685. && h == other.h
  72686. && xMode == other.xMode
  72687. && yMode == other.yMode
  72688. && wMode == other.wMode
  72689. && hMode == other.hMode;
  72690. }
  72691. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72692. {
  72693. return ! operator== (other);
  72694. }
  72695. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72696. {
  72697. StringArray tokens;
  72698. tokens.addTokens (stringVersion, false);
  72699. decodePosString (tokens [0], xMode, x);
  72700. decodePosString (tokens [1], yMode, y);
  72701. decodeSizeString (tokens [2], wMode, w);
  72702. decodeSizeString (tokens [3], hMode, h);
  72703. }
  72704. const String PositionedRectangle::toString() const throw()
  72705. {
  72706. String s;
  72707. s.preallocateStorage (12);
  72708. addPosDescription (s, xMode, x);
  72709. s << ' ';
  72710. addPosDescription (s, yMode, y);
  72711. s << ' ';
  72712. addSizeDescription (s, wMode, w);
  72713. s << ' ';
  72714. addSizeDescription (s, hMode, h);
  72715. return s;
  72716. }
  72717. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72718. {
  72719. jassert (! target.isEmpty());
  72720. double x_, y_, w_, h_;
  72721. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72722. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72723. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72724. roundToInt (w_), roundToInt (h_));
  72725. }
  72726. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72727. double& x_, double& y_,
  72728. double& w_, double& h_) const throw()
  72729. {
  72730. jassert (! target.isEmpty());
  72731. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72732. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72733. }
  72734. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72735. {
  72736. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72737. }
  72738. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72739. const Rectangle<int>& target) throw()
  72740. {
  72741. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72742. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72743. }
  72744. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72745. const double newW, const double newH,
  72746. const Rectangle<int>& target) throw()
  72747. {
  72748. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72749. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72750. }
  72751. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72752. {
  72753. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72754. updateFrom (comp.getBounds(), Rectangle<int>());
  72755. else
  72756. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72757. }
  72758. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72759. {
  72760. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72761. }
  72762. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72763. {
  72764. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72765. | absoluteFromParentBottomRight
  72766. | absoluteFromParentCentre
  72767. | proportionOfParentSize));
  72768. }
  72769. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72770. {
  72771. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72772. }
  72773. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72774. {
  72775. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72776. | absoluteFromParentBottomRight
  72777. | absoluteFromParentCentre
  72778. | proportionOfParentSize));
  72779. }
  72780. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72781. {
  72782. return (SizeMode) wMode;
  72783. }
  72784. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72785. {
  72786. return (SizeMode) hMode;
  72787. }
  72788. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72789. const PositionMode xMode_,
  72790. const AnchorPoint yAnchor,
  72791. const PositionMode yMode_,
  72792. const SizeMode widthMode,
  72793. const SizeMode heightMode,
  72794. const Rectangle<int>& target) throw()
  72795. {
  72796. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72797. {
  72798. double tx, tw;
  72799. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72800. xMode = (uint8) (xAnchor | xMode_);
  72801. wMode = (uint8) widthMode;
  72802. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72803. }
  72804. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72805. {
  72806. double ty, th;
  72807. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72808. yMode = (uint8) (yAnchor | yMode_);
  72809. hMode = (uint8) heightMode;
  72810. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72811. }
  72812. }
  72813. bool PositionedRectangle::isPositionAbsolute() const throw()
  72814. {
  72815. return xMode == absoluteFromParentTopLeft
  72816. && yMode == absoluteFromParentTopLeft
  72817. && wMode == absoluteSize
  72818. && hMode == absoluteSize;
  72819. }
  72820. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72821. {
  72822. if ((mode & proportionOfParentSize) != 0)
  72823. {
  72824. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72825. }
  72826. else
  72827. {
  72828. s << (roundToInt (value * 100.0) / 100.0);
  72829. if ((mode & absoluteFromParentBottomRight) != 0)
  72830. s << 'R';
  72831. else if ((mode & absoluteFromParentCentre) != 0)
  72832. s << 'C';
  72833. }
  72834. if ((mode & anchorAtRightOrBottom) != 0)
  72835. s << 'r';
  72836. else if ((mode & anchorAtCentre) != 0)
  72837. s << 'c';
  72838. }
  72839. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72840. {
  72841. if (mode == proportionalSize)
  72842. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72843. else if (mode == parentSizeMinusAbsolute)
  72844. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72845. else
  72846. s << (roundToInt (value * 100.0) / 100.0);
  72847. }
  72848. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72849. {
  72850. if (s.containsChar ('r'))
  72851. mode = anchorAtRightOrBottom;
  72852. else if (s.containsChar ('c'))
  72853. mode = anchorAtCentre;
  72854. else
  72855. mode = anchorAtLeftOrTop;
  72856. if (s.containsChar ('%'))
  72857. {
  72858. mode |= proportionOfParentSize;
  72859. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72860. }
  72861. else
  72862. {
  72863. if (s.containsChar ('R'))
  72864. mode |= absoluteFromParentBottomRight;
  72865. else if (s.containsChar ('C'))
  72866. mode |= absoluteFromParentCentre;
  72867. else
  72868. mode |= absoluteFromParentTopLeft;
  72869. value = s.removeCharacters ("rcRC").getDoubleValue();
  72870. }
  72871. }
  72872. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72873. {
  72874. if (s.containsChar ('%'))
  72875. {
  72876. mode = proportionalSize;
  72877. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72878. }
  72879. else if (s.containsChar ('M'))
  72880. {
  72881. mode = parentSizeMinusAbsolute;
  72882. value = s.getDoubleValue();
  72883. }
  72884. else
  72885. {
  72886. mode = absoluteSize;
  72887. value = s.getDoubleValue();
  72888. }
  72889. }
  72890. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72891. const double x_, const double w_,
  72892. const uint8 xMode_, const uint8 wMode_,
  72893. const int parentPos,
  72894. const int parentSize) const throw()
  72895. {
  72896. if (wMode_ == proportionalSize)
  72897. wOut = roundToInt (w_ * parentSize);
  72898. else if (wMode_ == parentSizeMinusAbsolute)
  72899. wOut = jmax (0, parentSize - roundToInt (w_));
  72900. else
  72901. wOut = roundToInt (w_);
  72902. if ((xMode_ & proportionOfParentSize) != 0)
  72903. xOut = parentPos + x_ * parentSize;
  72904. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72905. xOut = (parentPos + parentSize) - x_;
  72906. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72907. xOut = x_ + (parentPos + parentSize / 2);
  72908. else
  72909. xOut = x_ + parentPos;
  72910. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72911. xOut -= wOut;
  72912. else if ((xMode_ & anchorAtCentre) != 0)
  72913. xOut -= wOut / 2;
  72914. }
  72915. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  72916. double x_, const double w_,
  72917. const uint8 xMode_, const uint8 wMode_,
  72918. const int parentPos,
  72919. const int parentSize) const throw()
  72920. {
  72921. if (wMode_ == proportionalSize)
  72922. {
  72923. if (parentSize > 0)
  72924. wOut = w_ / parentSize;
  72925. }
  72926. else if (wMode_ == parentSizeMinusAbsolute)
  72927. wOut = parentSize - w_;
  72928. else
  72929. wOut = w_;
  72930. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72931. x_ += w_;
  72932. else if ((xMode_ & anchorAtCentre) != 0)
  72933. x_ += w_ / 2;
  72934. if ((xMode_ & proportionOfParentSize) != 0)
  72935. {
  72936. if (parentSize > 0)
  72937. xOut = (x_ - parentPos) / parentSize;
  72938. }
  72939. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72940. xOut = (parentPos + parentSize) - x_;
  72941. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72942. xOut = x_ - (parentPos + parentSize / 2);
  72943. else
  72944. xOut = x_ - parentPos;
  72945. }
  72946. END_JUCE_NAMESPACE
  72947. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  72948. /*** Start of inlined file: juce_RectangleList.cpp ***/
  72949. BEGIN_JUCE_NAMESPACE
  72950. RectangleList::RectangleList() throw()
  72951. {
  72952. }
  72953. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  72954. {
  72955. if (! rect.isEmpty())
  72956. rects.add (rect);
  72957. }
  72958. RectangleList::RectangleList (const RectangleList& other) throw()
  72959. : rects (other.rects)
  72960. {
  72961. }
  72962. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  72963. {
  72964. rects = other.rects;
  72965. return *this;
  72966. }
  72967. RectangleList::~RectangleList() throw()
  72968. {
  72969. }
  72970. void RectangleList::clear() throw()
  72971. {
  72972. rects.clearQuick();
  72973. }
  72974. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  72975. {
  72976. if (((unsigned int) index) < (unsigned int) rects.size())
  72977. return rects.getReference (index);
  72978. return Rectangle<int>();
  72979. }
  72980. bool RectangleList::isEmpty() const throw()
  72981. {
  72982. return rects.size() == 0;
  72983. }
  72984. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  72985. : current (0),
  72986. owner (list),
  72987. index (list.rects.size())
  72988. {
  72989. }
  72990. RectangleList::Iterator::~Iterator() throw()
  72991. {
  72992. }
  72993. bool RectangleList::Iterator::next() throw()
  72994. {
  72995. if (--index >= 0)
  72996. {
  72997. current = & (owner.rects.getReference (index));
  72998. return true;
  72999. }
  73000. return false;
  73001. }
  73002. void RectangleList::add (const Rectangle<int>& rect) throw()
  73003. {
  73004. if (! rect.isEmpty())
  73005. {
  73006. if (rects.size() == 0)
  73007. {
  73008. rects.add (rect);
  73009. }
  73010. else
  73011. {
  73012. bool anyOverlaps = false;
  73013. int i;
  73014. for (i = rects.size(); --i >= 0;)
  73015. {
  73016. Rectangle<int>& ourRect = rects.getReference (i);
  73017. if (rect.intersects (ourRect))
  73018. {
  73019. if (rect.contains (ourRect))
  73020. rects.remove (i);
  73021. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73022. anyOverlaps = true;
  73023. }
  73024. }
  73025. if (anyOverlaps && rects.size() > 0)
  73026. {
  73027. RectangleList r (rect);
  73028. for (i = rects.size(); --i >= 0;)
  73029. {
  73030. const Rectangle<int>& ourRect = rects.getReference (i);
  73031. if (rect.intersects (ourRect))
  73032. {
  73033. r.subtract (ourRect);
  73034. if (r.rects.size() == 0)
  73035. return;
  73036. }
  73037. }
  73038. for (i = r.getNumRectangles(); --i >= 0;)
  73039. rects.add (r.rects.getReference (i));
  73040. }
  73041. else
  73042. {
  73043. rects.add (rect);
  73044. }
  73045. }
  73046. }
  73047. }
  73048. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73049. {
  73050. rects.add (rect);
  73051. }
  73052. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73053. {
  73054. if (rects.size() == 0)
  73055. {
  73056. if (w > 0 && h > 0)
  73057. rects.add (Rectangle<int> (x, y, w, h));
  73058. }
  73059. else
  73060. {
  73061. add (Rectangle<int> (x, y, w, h));
  73062. }
  73063. }
  73064. void RectangleList::add (const RectangleList& other) throw()
  73065. {
  73066. for (int i = 0; i < other.rects.size(); ++i)
  73067. add (other.rects.getReference (i));
  73068. }
  73069. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73070. {
  73071. const int originalNumRects = rects.size();
  73072. if (originalNumRects > 0)
  73073. {
  73074. const int x1 = rect.x;
  73075. const int y1 = rect.y;
  73076. const int x2 = x1 + rect.w;
  73077. const int y2 = y1 + rect.h;
  73078. for (int i = getNumRectangles(); --i >= 0;)
  73079. {
  73080. Rectangle<int>& r = rects.getReference (i);
  73081. const int rx1 = r.x;
  73082. const int ry1 = r.y;
  73083. const int rx2 = rx1 + r.w;
  73084. const int ry2 = ry1 + r.h;
  73085. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73086. {
  73087. if (x1 > rx1 && x1 < rx2)
  73088. {
  73089. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73090. {
  73091. r.w = x1 - rx1;
  73092. }
  73093. else
  73094. {
  73095. r.x = x1;
  73096. r.w = rx2 - x1;
  73097. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73098. i += 2;
  73099. }
  73100. }
  73101. else if (x2 > rx1 && x2 < rx2)
  73102. {
  73103. r.x = x2;
  73104. r.w = rx2 - x2;
  73105. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73106. {
  73107. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73108. i += 2;
  73109. }
  73110. }
  73111. else if (y1 > ry1 && y1 < ry2)
  73112. {
  73113. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73114. {
  73115. r.h = y1 - ry1;
  73116. }
  73117. else
  73118. {
  73119. r.y = y1;
  73120. r.h = ry2 - y1;
  73121. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73122. i += 2;
  73123. }
  73124. }
  73125. else if (y2 > ry1 && y2 < ry2)
  73126. {
  73127. r.y = y2;
  73128. r.h = ry2 - y2;
  73129. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73130. {
  73131. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73132. i += 2;
  73133. }
  73134. }
  73135. else
  73136. {
  73137. rects.remove (i);
  73138. }
  73139. }
  73140. }
  73141. if (rects.size() > originalNumRects + 10)
  73142. consolidate();
  73143. }
  73144. }
  73145. void RectangleList::subtract (const RectangleList& otherList) throw()
  73146. {
  73147. for (int i = otherList.rects.size(); --i >= 0;)
  73148. subtract (otherList.rects.getReference (i));
  73149. }
  73150. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73151. {
  73152. bool notEmpty = false;
  73153. if (rect.isEmpty())
  73154. {
  73155. clear();
  73156. }
  73157. else
  73158. {
  73159. for (int i = rects.size(); --i >= 0;)
  73160. {
  73161. Rectangle<int>& r = rects.getReference (i);
  73162. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73163. rects.remove (i);
  73164. else
  73165. notEmpty = true;
  73166. }
  73167. }
  73168. return notEmpty;
  73169. }
  73170. bool RectangleList::clipTo (const RectangleList& other) throw()
  73171. {
  73172. if (rects.size() == 0)
  73173. return false;
  73174. RectangleList result;
  73175. for (int j = 0; j < rects.size(); ++j)
  73176. {
  73177. const Rectangle<int>& rect = rects.getReference (j);
  73178. for (int i = other.rects.size(); --i >= 0;)
  73179. {
  73180. Rectangle<int> r (other.rects.getReference (i));
  73181. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73182. result.rects.add (r);
  73183. }
  73184. }
  73185. swapWith (result);
  73186. return ! isEmpty();
  73187. }
  73188. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73189. {
  73190. destRegion.clear();
  73191. if (! rect.isEmpty())
  73192. {
  73193. for (int i = rects.size(); --i >= 0;)
  73194. {
  73195. Rectangle<int> r (rects.getReference (i));
  73196. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73197. destRegion.rects.add (r);
  73198. }
  73199. }
  73200. return destRegion.rects.size() > 0;
  73201. }
  73202. void RectangleList::swapWith (RectangleList& otherList) throw()
  73203. {
  73204. rects.swapWithArray (otherList.rects);
  73205. }
  73206. void RectangleList::consolidate() throw()
  73207. {
  73208. int i;
  73209. for (i = 0; i < getNumRectangles() - 1; ++i)
  73210. {
  73211. Rectangle<int>& r = rects.getReference (i);
  73212. const int rx1 = r.x;
  73213. const int ry1 = r.y;
  73214. const int rx2 = rx1 + r.w;
  73215. const int ry2 = ry1 + r.h;
  73216. for (int j = rects.size(); --j > i;)
  73217. {
  73218. Rectangle<int>& r2 = rects.getReference (j);
  73219. const int jrx1 = r2.x;
  73220. const int jry1 = r2.y;
  73221. const int jrx2 = jrx1 + r2.w;
  73222. const int jry2 = jry1 + r2.h;
  73223. // if the vertical edges of any blocks are touching and their horizontals don't
  73224. // line up, split them horizontally..
  73225. if (jrx1 == rx2 || jrx2 == rx1)
  73226. {
  73227. if (jry1 > ry1 && jry1 < ry2)
  73228. {
  73229. r.h = jry1 - ry1;
  73230. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73231. i = -1;
  73232. break;
  73233. }
  73234. if (jry2 > ry1 && jry2 < ry2)
  73235. {
  73236. r.h = jry2 - ry1;
  73237. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73238. i = -1;
  73239. break;
  73240. }
  73241. else if (ry1 > jry1 && ry1 < jry2)
  73242. {
  73243. r2.h = ry1 - jry1;
  73244. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73245. i = -1;
  73246. break;
  73247. }
  73248. else if (ry2 > jry1 && ry2 < jry2)
  73249. {
  73250. r2.h = ry2 - jry1;
  73251. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73252. i = -1;
  73253. break;
  73254. }
  73255. }
  73256. }
  73257. }
  73258. for (i = 0; i < rects.size() - 1; ++i)
  73259. {
  73260. Rectangle<int>& r = rects.getReference (i);
  73261. for (int j = rects.size(); --j > i;)
  73262. {
  73263. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73264. {
  73265. rects.remove (j);
  73266. i = -1;
  73267. break;
  73268. }
  73269. }
  73270. }
  73271. }
  73272. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73273. {
  73274. for (int i = getNumRectangles(); --i >= 0;)
  73275. if (rects.getReference (i).contains (x, y))
  73276. return true;
  73277. return false;
  73278. }
  73279. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73280. {
  73281. if (rects.size() > 1)
  73282. {
  73283. RectangleList r (rectangleToCheck);
  73284. for (int i = rects.size(); --i >= 0;)
  73285. {
  73286. r.subtract (rects.getReference (i));
  73287. if (r.rects.size() == 0)
  73288. return true;
  73289. }
  73290. }
  73291. else if (rects.size() > 0)
  73292. {
  73293. return rects.getReference (0).contains (rectangleToCheck);
  73294. }
  73295. return false;
  73296. }
  73297. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73298. {
  73299. for (int i = rects.size(); --i >= 0;)
  73300. if (rects.getReference (i).intersects (rectangleToCheck))
  73301. return true;
  73302. return false;
  73303. }
  73304. bool RectangleList::intersects (const RectangleList& other) const throw()
  73305. {
  73306. for (int i = rects.size(); --i >= 0;)
  73307. if (other.intersectsRectangle (rects.getReference (i)))
  73308. return true;
  73309. return false;
  73310. }
  73311. const Rectangle<int> RectangleList::getBounds() const throw()
  73312. {
  73313. if (rects.size() <= 1)
  73314. {
  73315. if (rects.size() == 0)
  73316. return Rectangle<int>();
  73317. else
  73318. return rects.getReference (0);
  73319. }
  73320. else
  73321. {
  73322. const Rectangle<int>& r = rects.getReference (0);
  73323. int minX = r.x;
  73324. int minY = r.y;
  73325. int maxX = minX + r.w;
  73326. int maxY = minY + r.h;
  73327. for (int i = rects.size(); --i > 0;)
  73328. {
  73329. const Rectangle<int>& r2 = rects.getReference (i);
  73330. minX = jmin (minX, r2.x);
  73331. minY = jmin (minY, r2.y);
  73332. maxX = jmax (maxX, r2.getRight());
  73333. maxY = jmax (maxY, r2.getBottom());
  73334. }
  73335. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73336. }
  73337. }
  73338. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73339. {
  73340. for (int i = rects.size(); --i >= 0;)
  73341. {
  73342. Rectangle<int>& r = rects.getReference (i);
  73343. r.x += dx;
  73344. r.y += dy;
  73345. }
  73346. }
  73347. const Path RectangleList::toPath() const throw()
  73348. {
  73349. Path p;
  73350. for (int i = rects.size(); --i >= 0;)
  73351. {
  73352. const Rectangle<int>& r = rects.getReference (i);
  73353. p.addRectangle ((float) r.x,
  73354. (float) r.y,
  73355. (float) r.w,
  73356. (float) r.h);
  73357. }
  73358. return p;
  73359. }
  73360. END_JUCE_NAMESPACE
  73361. /*** End of inlined file: juce_RectangleList.cpp ***/
  73362. /*** Start of inlined file: juce_Image.cpp ***/
  73363. BEGIN_JUCE_NAMESPACE
  73364. static const int fullAlphaThreshold = 253;
  73365. Image::Image (const PixelFormat format_,
  73366. const int imageWidth_,
  73367. const int imageHeight_)
  73368. : format (format_),
  73369. imageWidth (imageWidth_),
  73370. imageHeight (imageHeight_),
  73371. imageData (0)
  73372. {
  73373. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73374. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73375. // actual image will be at least 1x1.
  73376. }
  73377. Image::Image (const PixelFormat format_,
  73378. const int imageWidth_,
  73379. const int imageHeight_,
  73380. const bool clearImage)
  73381. : format (format_),
  73382. imageWidth (imageWidth_),
  73383. imageHeight (imageHeight_)
  73384. {
  73385. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73386. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73387. // actual image will be at least 1x1.
  73388. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73389. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73390. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73391. imageData = imageDataAllocated;
  73392. }
  73393. Image::Image (const Image& other)
  73394. : format (other.format),
  73395. imageWidth (other.imageWidth),
  73396. imageHeight (other.imageHeight)
  73397. {
  73398. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73399. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73400. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73401. imageData = imageDataAllocated;
  73402. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73403. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73404. }
  73405. Image::~Image()
  73406. {
  73407. }
  73408. LowLevelGraphicsContext* Image::createLowLevelContext()
  73409. {
  73410. return new LowLevelGraphicsSoftwareRenderer (*this);
  73411. }
  73412. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73413. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73414. lineStride (image.lineStride),
  73415. pixelStride (image.pixelStride),
  73416. width (w),
  73417. height (h)
  73418. {
  73419. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73420. }
  73421. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73422. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73423. lineStride (image.lineStride),
  73424. pixelStride (image.pixelStride),
  73425. width (w),
  73426. height (h)
  73427. {
  73428. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73429. }
  73430. Image::BitmapData::~BitmapData()
  73431. {
  73432. }
  73433. void Image::setPixelData (int x, int y, int w, int h,
  73434. const uint8* sourcePixelData, int sourceLineStride)
  73435. {
  73436. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73437. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73438. {
  73439. const BitmapData dest (*this, x, y, w, h, true);
  73440. for (int i = 0; i < h; ++i)
  73441. {
  73442. memcpy (dest.getLinePointer(i),
  73443. sourcePixelData + sourceLineStride * i,
  73444. w * dest.pixelStride);
  73445. }
  73446. }
  73447. }
  73448. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73449. {
  73450. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73451. {
  73452. const PixelARGB col (colourToClearTo.getPixelARGB());
  73453. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73454. uint8* dest = destData.data;
  73455. while (--dh >= 0)
  73456. {
  73457. uint8* line = dest;
  73458. dest += destData.lineStride;
  73459. if (isARGB())
  73460. {
  73461. for (int x = dw; --x >= 0;)
  73462. {
  73463. ((PixelARGB*) line)->set (col);
  73464. line += destData.pixelStride;
  73465. }
  73466. }
  73467. else if (isRGB())
  73468. {
  73469. for (int x = dw; --x >= 0;)
  73470. {
  73471. ((PixelRGB*) line)->set (col);
  73472. line += destData.pixelStride;
  73473. }
  73474. }
  73475. else
  73476. {
  73477. for (int x = dw; --x >= 0;)
  73478. {
  73479. *line = col.getAlpha();
  73480. line += destData.pixelStride;
  73481. }
  73482. }
  73483. }
  73484. }
  73485. }
  73486. Image* Image::createCopy (int newWidth, int newHeight,
  73487. const Graphics::ResamplingQuality quality) const
  73488. {
  73489. if (newWidth < 0)
  73490. newWidth = imageWidth;
  73491. if (newHeight < 0)
  73492. newHeight = imageHeight;
  73493. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73494. Graphics g (*newImage);
  73495. g.setImageResamplingQuality (quality);
  73496. g.drawImage (this,
  73497. 0, 0, newWidth, newHeight,
  73498. 0, 0, imageWidth, imageHeight,
  73499. false);
  73500. return newImage;
  73501. }
  73502. Image* Image::createCopyOfAlphaChannel() const
  73503. {
  73504. jassert (format != SingleChannel);
  73505. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73506. if (! hasAlphaChannel())
  73507. {
  73508. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73509. }
  73510. else
  73511. {
  73512. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73513. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73514. for (int y = 0; y < imageHeight; ++y)
  73515. {
  73516. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73517. uint8* dst = destData.getLinePointer (y);
  73518. for (int x = imageWidth; --x >= 0;)
  73519. {
  73520. *dst++ = src->getAlpha();
  73521. ++src;
  73522. }
  73523. }
  73524. }
  73525. return newImage;
  73526. }
  73527. const Colour Image::getPixelAt (const int x, const int y) const
  73528. {
  73529. Colour c;
  73530. if (((unsigned int) x) < (unsigned int) imageWidth
  73531. && ((unsigned int) y) < (unsigned int) imageHeight)
  73532. {
  73533. const BitmapData srcData (*this, x, y, 1, 1);
  73534. if (isARGB())
  73535. {
  73536. PixelARGB p (*(const PixelARGB*) srcData.data);
  73537. p.unpremultiply();
  73538. c = Colour (p.getARGB());
  73539. }
  73540. else if (isRGB())
  73541. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73542. else
  73543. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73544. }
  73545. return c;
  73546. }
  73547. void Image::setPixelAt (const int x, const int y,
  73548. const Colour& colour)
  73549. {
  73550. if (((unsigned int) x) < (unsigned int) imageWidth
  73551. && ((unsigned int) y) < (unsigned int) imageHeight)
  73552. {
  73553. const BitmapData destData (*this, x, y, 1, 1, true);
  73554. const PixelARGB col (colour.getPixelARGB());
  73555. if (isARGB())
  73556. ((PixelARGB*) destData.data)->set (col);
  73557. else if (isRGB())
  73558. ((PixelRGB*) destData.data)->set (col);
  73559. else
  73560. *(destData.data) = col.getAlpha();
  73561. }
  73562. }
  73563. void Image::multiplyAlphaAt (const int x, const int y,
  73564. const float multiplier)
  73565. {
  73566. if (((unsigned int) x) < (unsigned int) imageWidth
  73567. && ((unsigned int) y) < (unsigned int) imageHeight
  73568. && hasAlphaChannel())
  73569. {
  73570. const BitmapData destData (*this, x, y, 1, 1, true);
  73571. if (isARGB())
  73572. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73573. else
  73574. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73575. }
  73576. }
  73577. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73578. {
  73579. if (hasAlphaChannel())
  73580. {
  73581. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73582. if (isARGB())
  73583. {
  73584. for (int y = 0; y < imageHeight; ++y)
  73585. {
  73586. uint8* p = destData.getLinePointer (y);
  73587. for (int x = 0; x < imageWidth; ++x)
  73588. {
  73589. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73590. p += destData.pixelStride;
  73591. }
  73592. }
  73593. }
  73594. else
  73595. {
  73596. for (int y = 0; y < imageHeight; ++y)
  73597. {
  73598. uint8* p = destData.getLinePointer (y);
  73599. for (int x = 0; x < imageWidth; ++x)
  73600. {
  73601. *p = (uint8) (*p * amountToMultiplyBy);
  73602. p += destData.pixelStride;
  73603. }
  73604. }
  73605. }
  73606. }
  73607. else
  73608. {
  73609. jassertfalse // can't do this without an alpha-channel!
  73610. }
  73611. }
  73612. void Image::desaturate()
  73613. {
  73614. if (isARGB() || isRGB())
  73615. {
  73616. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73617. if (isARGB())
  73618. {
  73619. for (int y = 0; y < imageHeight; ++y)
  73620. {
  73621. uint8* p = destData.getLinePointer (y);
  73622. for (int x = 0; x < imageWidth; ++x)
  73623. {
  73624. ((PixelARGB*) p)->desaturate();
  73625. p += destData.pixelStride;
  73626. }
  73627. }
  73628. }
  73629. else
  73630. {
  73631. for (int y = 0; y < imageHeight; ++y)
  73632. {
  73633. uint8* p = destData.getLinePointer (y);
  73634. for (int x = 0; x < imageWidth; ++x)
  73635. {
  73636. ((PixelRGB*) p)->desaturate();
  73637. p += destData.pixelStride;
  73638. }
  73639. }
  73640. }
  73641. }
  73642. }
  73643. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73644. {
  73645. if (hasAlphaChannel())
  73646. {
  73647. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73648. SparseSet <int> pixelsOnRow;
  73649. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73650. for (int y = 0; y < imageHeight; ++y)
  73651. {
  73652. pixelsOnRow.clear();
  73653. const uint8* lineData = srcData.getLinePointer (y);
  73654. if (isARGB())
  73655. {
  73656. for (int x = 0; x < imageWidth; ++x)
  73657. {
  73658. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73659. pixelsOnRow.addRange (x, 1);
  73660. lineData += srcData.pixelStride;
  73661. }
  73662. }
  73663. else
  73664. {
  73665. for (int x = 0; x < imageWidth; ++x)
  73666. {
  73667. if (*lineData >= threshold)
  73668. pixelsOnRow.addRange (x, 1);
  73669. lineData += srcData.pixelStride;
  73670. }
  73671. }
  73672. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73673. {
  73674. int x, w;
  73675. if (pixelsOnRow.getRange (i, x, w))
  73676. result.add (Rectangle<int> (x, y, w, 1));
  73677. }
  73678. result.consolidate();
  73679. }
  73680. }
  73681. else
  73682. {
  73683. result.add (0, 0, imageWidth, imageHeight);
  73684. }
  73685. }
  73686. void Image::moveImageSection (int dx, int dy,
  73687. int sx, int sy,
  73688. int w, int h)
  73689. {
  73690. if (dx < 0)
  73691. {
  73692. w += dx;
  73693. sx -= dx;
  73694. dx = 0;
  73695. }
  73696. if (dy < 0)
  73697. {
  73698. h += dy;
  73699. sy -= dy;
  73700. dy = 0;
  73701. }
  73702. if (sx < 0)
  73703. {
  73704. w += sx;
  73705. dx -= sx;
  73706. sx = 0;
  73707. }
  73708. if (sy < 0)
  73709. {
  73710. h += sy;
  73711. dy -= sy;
  73712. sy = 0;
  73713. }
  73714. const int minX = jmin (dx, sx);
  73715. const int minY = jmin (dy, sy);
  73716. w = jmin (w, getWidth() - jmax (sx, dx));
  73717. h = jmin (h, getHeight() - jmax (sy, dy));
  73718. if (w > 0 && h > 0)
  73719. {
  73720. const int maxX = jmax (dx, sx) + w;
  73721. const int maxY = jmax (dy, sy) + h;
  73722. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73723. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73724. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73725. const int lineSize = destData.pixelStride * w;
  73726. if (dy > sy)
  73727. {
  73728. while (--h >= 0)
  73729. {
  73730. const int offset = h * destData.lineStride;
  73731. memmove (dst + offset, src + offset, lineSize);
  73732. }
  73733. }
  73734. else if (dst != src)
  73735. {
  73736. while (--h >= 0)
  73737. {
  73738. memmove (dst, src, lineSize);
  73739. dst += destData.lineStride;
  73740. src += destData.lineStride;
  73741. }
  73742. }
  73743. }
  73744. }
  73745. END_JUCE_NAMESPACE
  73746. /*** End of inlined file: juce_Image.cpp ***/
  73747. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73748. BEGIN_JUCE_NAMESPACE
  73749. struct ImageCache::Item
  73750. {
  73751. ScopedPointer <Image> image;
  73752. int64 hashCode;
  73753. int refCount;
  73754. uint32 releaseTime;
  73755. juce_UseDebuggingNewOperator
  73756. };
  73757. ImageCache* ImageCache::instance = 0;
  73758. int ImageCache::cacheTimeout = 5000;
  73759. ImageCache::ImageCache()
  73760. {
  73761. }
  73762. ImageCache::~ImageCache()
  73763. {
  73764. jassert (instance == this);
  73765. instance = 0;
  73766. }
  73767. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73768. {
  73769. if (instance != 0)
  73770. {
  73771. const ScopedLock sl (instance->lock);
  73772. for (int i = instance->images.size(); --i >= 0;)
  73773. {
  73774. Item* const ci = instance->images.getUnchecked(i);
  73775. if (ci->hashCode == hashCode)
  73776. {
  73777. ci->refCount++;
  73778. return ci->image;
  73779. }
  73780. }
  73781. }
  73782. return 0;
  73783. }
  73784. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73785. {
  73786. if (image != 0)
  73787. {
  73788. if (instance == 0)
  73789. instance = new ImageCache();
  73790. Item* const newC = new Item();
  73791. newC->hashCode = hashCode;
  73792. newC->image = image;
  73793. newC->refCount = 1;
  73794. newC->releaseTime = 0;
  73795. const ScopedLock sl (instance->lock);
  73796. instance->images.add (newC);
  73797. }
  73798. }
  73799. void ImageCache::release (Image* const imageToRelease)
  73800. {
  73801. if (imageToRelease != 0 && instance != 0)
  73802. {
  73803. const ScopedLock sl (instance->lock);
  73804. for (int i = instance->images.size(); --i >= 0;)
  73805. {
  73806. Item* const ci = instance->images.getUnchecked(i);
  73807. if (static_cast <Image*> (ci->image) == imageToRelease)
  73808. {
  73809. if (--(ci->refCount) == 0)
  73810. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73811. if (! instance->isTimerRunning())
  73812. instance->startTimer (999);
  73813. break;
  73814. }
  73815. }
  73816. }
  73817. }
  73818. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73819. {
  73820. if (isImageInCache (imageToRelease))
  73821. release (imageToRelease);
  73822. else
  73823. delete imageToRelease;
  73824. }
  73825. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73826. {
  73827. if (instance != 0)
  73828. {
  73829. const ScopedLock sl (instance->lock);
  73830. for (int i = instance->images.size(); --i >= 0;)
  73831. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73832. return true;
  73833. }
  73834. return false;
  73835. }
  73836. void ImageCache::incReferenceCount (Image* const image)
  73837. {
  73838. if (instance != 0)
  73839. {
  73840. const ScopedLock sl (instance->lock);
  73841. for (int i = instance->images.size(); --i >= 0;)
  73842. {
  73843. Item* const ci = instance->images.getUnchecked(i);
  73844. if (static_cast <Image*> (ci->image) == image)
  73845. {
  73846. ci->refCount++;
  73847. return;
  73848. }
  73849. }
  73850. }
  73851. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73852. }
  73853. void ImageCache::timerCallback()
  73854. {
  73855. int numberStillNeedingReleasing = 0;
  73856. const uint32 now = Time::getApproximateMillisecondCounter();
  73857. const ScopedLock sl (lock);
  73858. for (int i = images.size(); --i >= 0;)
  73859. {
  73860. Item* const ci = images.getUnchecked(i);
  73861. if (ci->refCount <= 0)
  73862. {
  73863. if (now > ci->releaseTime + cacheTimeout
  73864. || now < ci->releaseTime - 1000)
  73865. {
  73866. images.remove (i);
  73867. }
  73868. else
  73869. {
  73870. ++numberStillNeedingReleasing;
  73871. }
  73872. }
  73873. }
  73874. if (numberStillNeedingReleasing == 0)
  73875. stopTimer();
  73876. }
  73877. Image* ImageCache::getFromFile (const File& file)
  73878. {
  73879. const int64 hashCode = file.hashCode64();
  73880. Image* image = getFromHashCode (hashCode);
  73881. if (image == 0)
  73882. {
  73883. image = ImageFileFormat::loadFrom (file);
  73884. addImageToCache (image, hashCode);
  73885. }
  73886. return image;
  73887. }
  73888. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73889. {
  73890. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73891. Image* image = getFromHashCode (hashCode);
  73892. if (image == 0)
  73893. {
  73894. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73895. addImageToCache (image, hashCode);
  73896. }
  73897. return image;
  73898. }
  73899. void ImageCache::setCacheTimeout (const int millisecs)
  73900. {
  73901. cacheTimeout = millisecs;
  73902. }
  73903. END_JUCE_NAMESPACE
  73904. /*** End of inlined file: juce_ImageCache.cpp ***/
  73905. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73906. BEGIN_JUCE_NAMESPACE
  73907. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73908. : values (size_ * size_),
  73909. size (size_)
  73910. {
  73911. clear();
  73912. }
  73913. ImageConvolutionKernel::~ImageConvolutionKernel()
  73914. {
  73915. }
  73916. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  73917. {
  73918. if (((unsigned int) x) < (unsigned int) size
  73919. && ((unsigned int) y) < (unsigned int) size)
  73920. {
  73921. return values [x + y * size];
  73922. }
  73923. else
  73924. {
  73925. jassertfalse;
  73926. return 0;
  73927. }
  73928. }
  73929. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  73930. {
  73931. if (((unsigned int) x) < (unsigned int) size
  73932. && ((unsigned int) y) < (unsigned int) size)
  73933. {
  73934. values [x + y * size] = value;
  73935. }
  73936. else
  73937. {
  73938. jassertfalse;
  73939. }
  73940. }
  73941. void ImageConvolutionKernel::clear()
  73942. {
  73943. for (int i = size * size; --i >= 0;)
  73944. values[i] = 0;
  73945. }
  73946. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  73947. {
  73948. double currentTotal = 0.0;
  73949. for (int i = size * size; --i >= 0;)
  73950. currentTotal += values[i];
  73951. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  73952. }
  73953. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  73954. {
  73955. for (int i = size * size; --i >= 0;)
  73956. values[i] *= multiplier;
  73957. }
  73958. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  73959. {
  73960. const double radiusFactor = -1.0 / (radius * radius * 2);
  73961. const int centre = size >> 1;
  73962. for (int y = size; --y >= 0;)
  73963. {
  73964. for (int x = size; --x >= 0;)
  73965. {
  73966. const int cx = x - centre;
  73967. const int cy = y - centre;
  73968. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  73969. }
  73970. }
  73971. setOverallSum (1.0f);
  73972. }
  73973. void ImageConvolutionKernel::applyToImage (Image& destImage,
  73974. const Image* sourceImage,
  73975. const Rectangle<int>& destinationArea) const
  73976. {
  73977. ScopedPointer <Image> imageCreated;
  73978. if (sourceImage == 0)
  73979. {
  73980. sourceImage = imageCreated = destImage.createCopy();
  73981. }
  73982. else
  73983. {
  73984. jassert (sourceImage->getWidth() == destImage.getWidth()
  73985. && sourceImage->getHeight() == destImage.getHeight()
  73986. && sourceImage->getFormat() == destImage.getFormat());
  73987. if (sourceImage->getWidth() != destImage.getWidth()
  73988. || sourceImage->getHeight() != destImage.getHeight()
  73989. || sourceImage->getFormat() != destImage.getFormat())
  73990. return;
  73991. }
  73992. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  73993. if (area.isEmpty())
  73994. return;
  73995. const int right = area.getRight();
  73996. const int bottom = area.getBottom();
  73997. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  73998. uint8* line = destData.data;
  73999. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74000. if (destData.pixelStride == 4)
  74001. {
  74002. for (int y = area.getY(); y < bottom; ++y)
  74003. {
  74004. uint8* dest = line;
  74005. line += destData.lineStride;
  74006. for (int x = area.getX(); x < right; ++x)
  74007. {
  74008. float c1 = 0;
  74009. float c2 = 0;
  74010. float c3 = 0;
  74011. float c4 = 0;
  74012. for (int yy = 0; yy < size; ++yy)
  74013. {
  74014. const int sy = y + yy - (size >> 1);
  74015. if (sy >= srcData.height)
  74016. break;
  74017. if (sy >= 0)
  74018. {
  74019. int sx = x - (size >> 1);
  74020. const uint8* src = srcData.getPixelPointer (sx, sy);
  74021. for (int xx = 0; xx < size; ++xx)
  74022. {
  74023. if (sx >= srcData.width)
  74024. break;
  74025. if (sx >= 0)
  74026. {
  74027. const float kernelMult = values [xx + yy * size];
  74028. c1 += kernelMult * *src++;
  74029. c2 += kernelMult * *src++;
  74030. c3 += kernelMult * *src++;
  74031. c4 += kernelMult * *src++;
  74032. }
  74033. else
  74034. {
  74035. src += 4;
  74036. }
  74037. ++sx;
  74038. }
  74039. }
  74040. }
  74041. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74042. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74043. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74044. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74045. }
  74046. }
  74047. }
  74048. else if (destData.pixelStride == 3)
  74049. {
  74050. for (int y = area.getY(); y < bottom; ++y)
  74051. {
  74052. uint8* dest = line;
  74053. line += destData.lineStride;
  74054. for (int x = area.getX(); x < right; ++x)
  74055. {
  74056. float c1 = 0;
  74057. float c2 = 0;
  74058. float c3 = 0;
  74059. for (int yy = 0; yy < size; ++yy)
  74060. {
  74061. const int sy = y + yy - (size >> 1);
  74062. if (sy >= srcData.height)
  74063. break;
  74064. if (sy >= 0)
  74065. {
  74066. int sx = x - (size >> 1);
  74067. const uint8* src = srcData.getPixelPointer (sx, sy);
  74068. for (int xx = 0; xx < size; ++xx)
  74069. {
  74070. if (sx >= srcData.width)
  74071. break;
  74072. if (sx >= 0)
  74073. {
  74074. const float kernelMult = values [xx + yy * size];
  74075. c1 += kernelMult * *src++;
  74076. c2 += kernelMult * *src++;
  74077. c3 += kernelMult * *src++;
  74078. }
  74079. else
  74080. {
  74081. src += 3;
  74082. }
  74083. ++sx;
  74084. }
  74085. }
  74086. }
  74087. *dest++ = (uint8) roundToInt (c1);
  74088. *dest++ = (uint8) roundToInt (c2);
  74089. *dest++ = (uint8) roundToInt (c3);
  74090. }
  74091. }
  74092. }
  74093. }
  74094. END_JUCE_NAMESPACE
  74095. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74096. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74097. BEGIN_JUCE_NAMESPACE
  74098. /*** Start of inlined file: juce_GIFLoader.h ***/
  74099. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74100. #define __JUCE_GIFLOADER_JUCEHEADER__
  74101. #ifndef DOXYGEN
  74102. class GIFLoader
  74103. {
  74104. public:
  74105. GIFLoader (InputStream& in);
  74106. ~GIFLoader();
  74107. Image* getImage() const { return image; }
  74108. private:
  74109. Image* image;
  74110. InputStream& input;
  74111. uint8 buffer [300];
  74112. uint8 palette [256][4];
  74113. bool dataBlockIsZero, fresh, finished;
  74114. int currentBit, lastBit, lastByteIndex;
  74115. int codeSize, setCodeSize;
  74116. int maxCode, maxCodeSize;
  74117. int firstcode, oldcode;
  74118. int clearCode, end_code;
  74119. enum { maxGifCode = 1 << 12 };
  74120. int table [2] [maxGifCode];
  74121. int stack [2 * maxGifCode];
  74122. int *sp;
  74123. bool getSizeFromHeader (int& width, int& height);
  74124. bool readPalette (const int numCols);
  74125. int readDataBlock (unsigned char* dest);
  74126. int processExtension (int type, int& transparent);
  74127. int readLZWByte (bool initialise, int input_code_size);
  74128. int getCode (int code_size, bool initialise);
  74129. bool readImage (int width, int height, int interlace, int transparent);
  74130. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74131. GIFLoader (const GIFLoader&);
  74132. GIFLoader& operator= (const GIFLoader&);
  74133. };
  74134. #endif // DOXYGEN
  74135. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74136. /*** End of inlined file: juce_GIFLoader.h ***/
  74137. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74138. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74139. PNGImageFormat::PNGImageFormat() {}
  74140. PNGImageFormat::~PNGImageFormat() {}
  74141. const String PNGImageFormat::getFormatName()
  74142. {
  74143. return "PNG";
  74144. }
  74145. bool PNGImageFormat::canUnderstand (InputStream& in)
  74146. {
  74147. const int bytesNeeded = 4;
  74148. char header [bytesNeeded];
  74149. return in.read (header, bytesNeeded) == bytesNeeded
  74150. && header[1] == 'P'
  74151. && header[2] == 'N'
  74152. && header[3] == 'G';
  74153. }
  74154. Image* PNGImageFormat::decodeImage (InputStream& in)
  74155. {
  74156. return juce_loadPNGImageFromStream (in);
  74157. }
  74158. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74159. OutputStream& destStream)
  74160. {
  74161. return juce_writePNGImageToStream (sourceImage, destStream);
  74162. }
  74163. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74164. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74165. JPEGImageFormat::JPEGImageFormat()
  74166. : quality (-1.0f)
  74167. {
  74168. }
  74169. JPEGImageFormat::~JPEGImageFormat() {}
  74170. void JPEGImageFormat::setQuality (const float newQuality)
  74171. {
  74172. quality = newQuality;
  74173. }
  74174. const String JPEGImageFormat::getFormatName()
  74175. {
  74176. return "JPEG";
  74177. }
  74178. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74179. {
  74180. const int bytesNeeded = 10;
  74181. uint8 header [bytesNeeded];
  74182. if (in.read (header, bytesNeeded) == bytesNeeded)
  74183. {
  74184. return header[0] == 0xff
  74185. && header[1] == 0xd8
  74186. && header[2] == 0xff
  74187. && (header[3] == 0xe0 || header[3] == 0xe1);
  74188. }
  74189. return false;
  74190. }
  74191. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74192. {
  74193. return juce_loadJPEGImageFromStream (in);
  74194. }
  74195. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74196. OutputStream& destStream)
  74197. {
  74198. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74199. }
  74200. class GIFImageFormat : public ImageFileFormat
  74201. {
  74202. public:
  74203. GIFImageFormat() {}
  74204. ~GIFImageFormat() {}
  74205. const String getFormatName()
  74206. {
  74207. return "GIF";
  74208. }
  74209. bool canUnderstand (InputStream& in)
  74210. {
  74211. const int bytesNeeded = 4;
  74212. char header [bytesNeeded];
  74213. return (in.read (header, bytesNeeded) == bytesNeeded)
  74214. && header[0] == 'G'
  74215. && header[1] == 'I'
  74216. && header[2] == 'F';
  74217. }
  74218. Image* decodeImage (InputStream& in)
  74219. {
  74220. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74221. return loader->getImage();
  74222. }
  74223. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74224. {
  74225. return false;
  74226. }
  74227. };
  74228. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74229. {
  74230. static PNGImageFormat png;
  74231. static JPEGImageFormat jpg;
  74232. static GIFImageFormat gif;
  74233. ImageFileFormat* formats[4];
  74234. int numFormats = 0;
  74235. formats [numFormats++] = &png;
  74236. formats [numFormats++] = &jpg;
  74237. formats [numFormats++] = &gif;
  74238. const int64 streamPos = input.getPosition();
  74239. for (int i = 0; i < numFormats; ++i)
  74240. {
  74241. const bool found = formats[i]->canUnderstand (input);
  74242. input.setPosition (streamPos);
  74243. if (found)
  74244. return formats[i];
  74245. }
  74246. return 0;
  74247. }
  74248. Image* ImageFileFormat::loadFrom (InputStream& input)
  74249. {
  74250. ImageFileFormat* const format = findImageFormatForStream (input);
  74251. if (format != 0)
  74252. return format->decodeImage (input);
  74253. return 0;
  74254. }
  74255. Image* ImageFileFormat::loadFrom (const File& file)
  74256. {
  74257. InputStream* const in = file.createInputStream();
  74258. if (in != 0)
  74259. {
  74260. BufferedInputStream b (in, 8192, true);
  74261. return loadFrom (b);
  74262. }
  74263. return 0;
  74264. }
  74265. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74266. {
  74267. if (rawData != 0 && numBytes > 4)
  74268. {
  74269. MemoryInputStream stream (rawData, numBytes, false);
  74270. return loadFrom (stream);
  74271. }
  74272. return 0;
  74273. }
  74274. END_JUCE_NAMESPACE
  74275. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74276. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74277. BEGIN_JUCE_NAMESPACE
  74278. GIFLoader::GIFLoader (InputStream& in)
  74279. : image (0),
  74280. input (in),
  74281. dataBlockIsZero (false),
  74282. fresh (false),
  74283. finished (false)
  74284. {
  74285. currentBit = lastBit = lastByteIndex = 0;
  74286. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74287. firstcode = oldcode = 0;
  74288. clearCode = end_code = 0;
  74289. int imageWidth, imageHeight;
  74290. int transparent = -1;
  74291. if (! getSizeFromHeader (imageWidth, imageHeight))
  74292. return;
  74293. if ((imageWidth <= 0) || (imageHeight <= 0))
  74294. return;
  74295. unsigned char buf [16];
  74296. if (in.read (buf, 3) != 3)
  74297. return;
  74298. int numColours = 2 << (buf[0] & 7);
  74299. if ((buf[0] & 0x80) != 0)
  74300. readPalette (numColours);
  74301. for (;;)
  74302. {
  74303. if (input.read (buf, 1) != 1)
  74304. break;
  74305. if (buf[0] == ';')
  74306. break;
  74307. if (buf[0] == '!')
  74308. {
  74309. if (input.read (buf, 1) != 1)
  74310. break;
  74311. if (processExtension (buf[0], transparent) < 0)
  74312. break;
  74313. continue;
  74314. }
  74315. if (buf[0] != ',')
  74316. continue;
  74317. if (input.read (buf, 9) != 9)
  74318. break;
  74319. imageWidth = makeWord (buf[4], buf[5]);
  74320. imageHeight = makeWord (buf[6], buf[7]);
  74321. numColours = 2 << (buf[8] & 7);
  74322. if ((buf[8] & 0x80) != 0)
  74323. if (! readPalette (numColours))
  74324. break;
  74325. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74326. imageWidth, imageHeight, (transparent >= 0));
  74327. readImage (imageWidth, imageHeight,
  74328. (buf[8] & 0x40) != 0,
  74329. transparent);
  74330. break;
  74331. }
  74332. }
  74333. GIFLoader::~GIFLoader()
  74334. {
  74335. }
  74336. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74337. {
  74338. char b[8];
  74339. if (input.read (b, 6) == 6)
  74340. {
  74341. if ((strncmp ("GIF87a", b, 6) == 0)
  74342. || (strncmp ("GIF89a", b, 6) == 0))
  74343. {
  74344. if (input.read (b, 4) == 4)
  74345. {
  74346. w = makeWord (b[0], b[1]);
  74347. h = makeWord (b[2], b[3]);
  74348. return true;
  74349. }
  74350. }
  74351. }
  74352. return false;
  74353. }
  74354. bool GIFLoader::readPalette (const int numCols)
  74355. {
  74356. unsigned char rgb[4];
  74357. for (int i = 0; i < numCols; ++i)
  74358. {
  74359. input.read (rgb, 3);
  74360. palette [i][0] = rgb[0];
  74361. palette [i][1] = rgb[1];
  74362. palette [i][2] = rgb[2];
  74363. palette [i][3] = 0xff;
  74364. }
  74365. return true;
  74366. }
  74367. int GIFLoader::readDataBlock (unsigned char* const dest)
  74368. {
  74369. unsigned char n;
  74370. if (input.read (&n, 1) == 1)
  74371. {
  74372. dataBlockIsZero = (n == 0);
  74373. if (dataBlockIsZero || (input.read (dest, n) == n))
  74374. return n;
  74375. }
  74376. return -1;
  74377. }
  74378. int GIFLoader::processExtension (const int type, int& transparent)
  74379. {
  74380. unsigned char b [300];
  74381. int n = 0;
  74382. if (type == 0xf9)
  74383. {
  74384. n = readDataBlock (b);
  74385. if (n < 0)
  74386. return 1;
  74387. if ((b[0] & 0x1) != 0)
  74388. transparent = b[3];
  74389. }
  74390. do
  74391. {
  74392. n = readDataBlock (b);
  74393. }
  74394. while (n > 0);
  74395. return n;
  74396. }
  74397. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74398. {
  74399. if (initialise)
  74400. {
  74401. currentBit = 0;
  74402. lastBit = 0;
  74403. finished = false;
  74404. return 0;
  74405. }
  74406. if ((currentBit + codeSize_) >= lastBit)
  74407. {
  74408. if (finished)
  74409. return -1;
  74410. buffer[0] = buffer [lastByteIndex - 2];
  74411. buffer[1] = buffer [lastByteIndex - 1];
  74412. const int n = readDataBlock (&buffer[2]);
  74413. if (n == 0)
  74414. finished = true;
  74415. lastByteIndex = 2 + n;
  74416. currentBit = (currentBit - lastBit) + 16;
  74417. lastBit = (2 + n) * 8 ;
  74418. }
  74419. int result = 0;
  74420. int i = currentBit;
  74421. for (int j = 0; j < codeSize_; ++j)
  74422. {
  74423. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74424. ++i;
  74425. }
  74426. currentBit += codeSize_;
  74427. return result;
  74428. }
  74429. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74430. {
  74431. int code, incode, i;
  74432. if (initialise)
  74433. {
  74434. setCodeSize = inputCodeSize;
  74435. codeSize = setCodeSize + 1;
  74436. clearCode = 1 << setCodeSize;
  74437. end_code = clearCode + 1;
  74438. maxCodeSize = 2 * clearCode;
  74439. maxCode = clearCode + 2;
  74440. getCode (0, true);
  74441. fresh = true;
  74442. for (i = 0; i < clearCode; ++i)
  74443. {
  74444. table[0][i] = 0;
  74445. table[1][i] = i;
  74446. }
  74447. for (; i < maxGifCode; ++i)
  74448. {
  74449. table[0][i] = 0;
  74450. table[1][i] = 0;
  74451. }
  74452. sp = stack;
  74453. return 0;
  74454. }
  74455. else if (fresh)
  74456. {
  74457. fresh = false;
  74458. do
  74459. {
  74460. firstcode = oldcode
  74461. = getCode (codeSize, false);
  74462. }
  74463. while (firstcode == clearCode);
  74464. return firstcode;
  74465. }
  74466. if (sp > stack)
  74467. return *--sp;
  74468. while ((code = getCode (codeSize, false)) >= 0)
  74469. {
  74470. if (code == clearCode)
  74471. {
  74472. for (i = 0; i < clearCode; ++i)
  74473. {
  74474. table[0][i] = 0;
  74475. table[1][i] = i;
  74476. }
  74477. for (; i < maxGifCode; ++i)
  74478. {
  74479. table[0][i] = 0;
  74480. table[1][i] = 0;
  74481. }
  74482. codeSize = setCodeSize + 1;
  74483. maxCodeSize = 2 * clearCode;
  74484. maxCode = clearCode + 2;
  74485. sp = stack;
  74486. firstcode = oldcode = getCode (codeSize, false);
  74487. return firstcode;
  74488. }
  74489. else if (code == end_code)
  74490. {
  74491. if (dataBlockIsZero)
  74492. return -2;
  74493. unsigned char buf [260];
  74494. int n;
  74495. while ((n = readDataBlock (buf)) > 0)
  74496. {}
  74497. if (n != 0)
  74498. return -2;
  74499. }
  74500. incode = code;
  74501. if (code >= maxCode)
  74502. {
  74503. *sp++ = firstcode;
  74504. code = oldcode;
  74505. }
  74506. while (code >= clearCode)
  74507. {
  74508. *sp++ = table[1][code];
  74509. if (code == table[0][code])
  74510. return -2;
  74511. code = table[0][code];
  74512. }
  74513. *sp++ = firstcode = table[1][code];
  74514. if ((code = maxCode) < maxGifCode)
  74515. {
  74516. table[0][code] = oldcode;
  74517. table[1][code] = firstcode;
  74518. ++maxCode;
  74519. if ((maxCode >= maxCodeSize)
  74520. && (maxCodeSize < maxGifCode))
  74521. {
  74522. maxCodeSize <<= 1;
  74523. ++codeSize;
  74524. }
  74525. }
  74526. oldcode = incode;
  74527. if (sp > stack)
  74528. return *--sp;
  74529. }
  74530. return code;
  74531. }
  74532. bool GIFLoader::readImage (const int width, const int height,
  74533. const int interlace, const int transparent)
  74534. {
  74535. unsigned char c;
  74536. if (input.read (&c, 1) != 1
  74537. || readLZWByte (true, c) < 0)
  74538. return false;
  74539. if (transparent >= 0)
  74540. {
  74541. palette [transparent][0] = 0;
  74542. palette [transparent][1] = 0;
  74543. palette [transparent][2] = 0;
  74544. palette [transparent][3] = 0;
  74545. }
  74546. int index;
  74547. int xpos = 0, ypos = 0, pass = 0;
  74548. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74549. uint8* p = destData.data;
  74550. const bool hasAlpha = image->hasAlphaChannel();
  74551. while ((index = readLZWByte (false, c)) >= 0)
  74552. {
  74553. const uint8* const paletteEntry = palette [index];
  74554. if (hasAlpha)
  74555. {
  74556. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74557. paletteEntry[0],
  74558. paletteEntry[1],
  74559. paletteEntry[2]);
  74560. ((PixelARGB*) p)->premultiply();
  74561. }
  74562. else
  74563. {
  74564. ((PixelRGB*) p)->setARGB (0,
  74565. paletteEntry[0],
  74566. paletteEntry[1],
  74567. paletteEntry[2]);
  74568. }
  74569. p += destData.pixelStride;
  74570. ++xpos;
  74571. if (xpos == width)
  74572. {
  74573. xpos = 0;
  74574. if (interlace)
  74575. {
  74576. switch (pass)
  74577. {
  74578. case 0:
  74579. case 1:
  74580. ypos += 8;
  74581. break;
  74582. case 2:
  74583. ypos += 4;
  74584. break;
  74585. case 3:
  74586. ypos += 2;
  74587. break;
  74588. }
  74589. while (ypos >= height)
  74590. {
  74591. ++pass;
  74592. switch (pass)
  74593. {
  74594. case 1:
  74595. ypos = 4;
  74596. break;
  74597. case 2:
  74598. ypos = 2;
  74599. break;
  74600. case 3:
  74601. ypos = 1;
  74602. break;
  74603. default:
  74604. return true;
  74605. }
  74606. }
  74607. }
  74608. else
  74609. {
  74610. ++ypos;
  74611. }
  74612. p = destData.getPixelPointer (xpos, ypos);
  74613. }
  74614. if (ypos >= height)
  74615. break;
  74616. }
  74617. return true;
  74618. }
  74619. END_JUCE_NAMESPACE
  74620. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74621. #endif
  74622. //==============================================================================
  74623. // some files include lots of library code, so leave them to the end to avoid cluttering
  74624. // up the build for the clean files.
  74625. #if JUCE_BUILD_CORE
  74626. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74627. namespace zlibNamespace
  74628. {
  74629. #if JUCE_INCLUDE_ZLIB_CODE
  74630. #undef OS_CODE
  74631. #undef fdopen
  74632. /*** Start of inlined file: zlib.h ***/
  74633. #ifndef ZLIB_H
  74634. #define ZLIB_H
  74635. /*** Start of inlined file: zconf.h ***/
  74636. #ifndef ZCONF_H
  74637. #define ZCONF_H
  74638. // *** Just a few hacks here to make it compile nicely with Juce..
  74639. #define Z_PREFIX 1
  74640. #undef __MACTYPES__
  74641. #ifdef _MSC_VER
  74642. #pragma warning (disable : 4131 4127 4244 4267)
  74643. #endif
  74644. #ifdef Z_PREFIX
  74645. # define deflateInit_ z_deflateInit_
  74646. # define deflate z_deflate
  74647. # define deflateEnd z_deflateEnd
  74648. # define inflateInit_ z_inflateInit_
  74649. # define inflate z_inflate
  74650. # define inflateEnd z_inflateEnd
  74651. # define inflatePrime z_inflatePrime
  74652. # define inflateGetHeader z_inflateGetHeader
  74653. # define adler32_combine z_adler32_combine
  74654. # define crc32_combine z_crc32_combine
  74655. # define deflateInit2_ z_deflateInit2_
  74656. # define deflateSetDictionary z_deflateSetDictionary
  74657. # define deflateCopy z_deflateCopy
  74658. # define deflateReset z_deflateReset
  74659. # define deflateParams z_deflateParams
  74660. # define deflateBound z_deflateBound
  74661. # define deflatePrime z_deflatePrime
  74662. # define inflateInit2_ z_inflateInit2_
  74663. # define inflateSetDictionary z_inflateSetDictionary
  74664. # define inflateSync z_inflateSync
  74665. # define inflateSyncPoint z_inflateSyncPoint
  74666. # define inflateCopy z_inflateCopy
  74667. # define inflateReset z_inflateReset
  74668. # define inflateBack z_inflateBack
  74669. # define inflateBackEnd z_inflateBackEnd
  74670. # define compress z_compress
  74671. # define compress2 z_compress2
  74672. # define compressBound z_compressBound
  74673. # define uncompress z_uncompress
  74674. # define adler32 z_adler32
  74675. # define crc32 z_crc32
  74676. # define get_crc_table z_get_crc_table
  74677. # define zError z_zError
  74678. # define alloc_func z_alloc_func
  74679. # define free_func z_free_func
  74680. # define in_func z_in_func
  74681. # define out_func z_out_func
  74682. # define Byte z_Byte
  74683. # define uInt z_uInt
  74684. # define uLong z_uLong
  74685. # define Bytef z_Bytef
  74686. # define charf z_charf
  74687. # define intf z_intf
  74688. # define uIntf z_uIntf
  74689. # define uLongf z_uLongf
  74690. # define voidpf z_voidpf
  74691. # define voidp z_voidp
  74692. #endif
  74693. #if defined(__MSDOS__) && !defined(MSDOS)
  74694. # define MSDOS
  74695. #endif
  74696. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74697. # define OS2
  74698. #endif
  74699. #if defined(_WINDOWS) && !defined(WINDOWS)
  74700. # define WINDOWS
  74701. #endif
  74702. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74703. # ifndef WIN32
  74704. # define WIN32
  74705. # endif
  74706. #endif
  74707. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74708. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74709. # ifndef SYS16BIT
  74710. # define SYS16BIT
  74711. # endif
  74712. # endif
  74713. #endif
  74714. #ifdef SYS16BIT
  74715. # define MAXSEG_64K
  74716. #endif
  74717. #ifdef MSDOS
  74718. # define UNALIGNED_OK
  74719. #endif
  74720. #ifdef __STDC_VERSION__
  74721. # ifndef STDC
  74722. # define STDC
  74723. # endif
  74724. # if __STDC_VERSION__ >= 199901L
  74725. # ifndef STDC99
  74726. # define STDC99
  74727. # endif
  74728. # endif
  74729. #endif
  74730. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74731. # define STDC
  74732. #endif
  74733. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74734. # define STDC
  74735. #endif
  74736. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74737. # define STDC
  74738. #endif
  74739. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74740. # define STDC
  74741. #endif
  74742. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74743. # define STDC
  74744. #endif
  74745. #ifndef STDC
  74746. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74747. # define const /* note: need a more gentle solution here */
  74748. # endif
  74749. #endif
  74750. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74751. # define NO_DUMMY_DECL
  74752. #endif
  74753. #ifndef MAX_MEM_LEVEL
  74754. # ifdef MAXSEG_64K
  74755. # define MAX_MEM_LEVEL 8
  74756. # else
  74757. # define MAX_MEM_LEVEL 9
  74758. # endif
  74759. #endif
  74760. #ifndef MAX_WBITS
  74761. # define MAX_WBITS 15 /* 32K LZ77 window */
  74762. #endif
  74763. #ifndef OF /* function prototypes */
  74764. # ifdef STDC
  74765. # define OF(args) args
  74766. # else
  74767. # define OF(args) ()
  74768. # endif
  74769. #endif
  74770. #ifdef SYS16BIT
  74771. # if defined(M_I86SM) || defined(M_I86MM)
  74772. # define SMALL_MEDIUM
  74773. # ifdef _MSC_VER
  74774. # define FAR _far
  74775. # else
  74776. # define FAR far
  74777. # endif
  74778. # endif
  74779. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74780. # define SMALL_MEDIUM
  74781. # ifdef __BORLANDC__
  74782. # define FAR _far
  74783. # else
  74784. # define FAR far
  74785. # endif
  74786. # endif
  74787. #endif
  74788. #if defined(WINDOWS) || defined(WIN32)
  74789. # ifdef ZLIB_DLL
  74790. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74791. # ifdef ZLIB_INTERNAL
  74792. # define ZEXTERN extern __declspec(dllexport)
  74793. # else
  74794. # define ZEXTERN extern __declspec(dllimport)
  74795. # endif
  74796. # endif
  74797. # endif /* ZLIB_DLL */
  74798. # ifdef ZLIB_WINAPI
  74799. # ifdef FAR
  74800. # undef FAR
  74801. # endif
  74802. # include <windows.h>
  74803. # define ZEXPORT WINAPI
  74804. # ifdef WIN32
  74805. # define ZEXPORTVA WINAPIV
  74806. # else
  74807. # define ZEXPORTVA FAR CDECL
  74808. # endif
  74809. # endif
  74810. #endif
  74811. #if defined (__BEOS__)
  74812. # ifdef ZLIB_DLL
  74813. # ifdef ZLIB_INTERNAL
  74814. # define ZEXPORT __declspec(dllexport)
  74815. # define ZEXPORTVA __declspec(dllexport)
  74816. # else
  74817. # define ZEXPORT __declspec(dllimport)
  74818. # define ZEXPORTVA __declspec(dllimport)
  74819. # endif
  74820. # endif
  74821. #endif
  74822. #ifndef ZEXTERN
  74823. # define ZEXTERN extern
  74824. #endif
  74825. #ifndef ZEXPORT
  74826. # define ZEXPORT
  74827. #endif
  74828. #ifndef ZEXPORTVA
  74829. # define ZEXPORTVA
  74830. #endif
  74831. #ifndef FAR
  74832. # define FAR
  74833. #endif
  74834. #if !defined(__MACTYPES__)
  74835. typedef unsigned char Byte; /* 8 bits */
  74836. #endif
  74837. typedef unsigned int uInt; /* 16 bits or more */
  74838. typedef unsigned long uLong; /* 32 bits or more */
  74839. #ifdef SMALL_MEDIUM
  74840. # define Bytef Byte FAR
  74841. #else
  74842. typedef Byte FAR Bytef;
  74843. #endif
  74844. typedef char FAR charf;
  74845. typedef int FAR intf;
  74846. typedef uInt FAR uIntf;
  74847. typedef uLong FAR uLongf;
  74848. #ifdef STDC
  74849. typedef void const *voidpc;
  74850. typedef void FAR *voidpf;
  74851. typedef void *voidp;
  74852. #else
  74853. typedef Byte const *voidpc;
  74854. typedef Byte FAR *voidpf;
  74855. typedef Byte *voidp;
  74856. #endif
  74857. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74858. # include <sys/types.h> /* for off_t */
  74859. # include <unistd.h> /* for SEEK_* and off_t */
  74860. # ifdef VMS
  74861. # include <unixio.h> /* for off_t */
  74862. # endif
  74863. # define z_off_t off_t
  74864. #endif
  74865. #ifndef SEEK_SET
  74866. # define SEEK_SET 0 /* Seek from beginning of file. */
  74867. # define SEEK_CUR 1 /* Seek from current position. */
  74868. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74869. #endif
  74870. #ifndef z_off_t
  74871. # define z_off_t long
  74872. #endif
  74873. #if defined(__OS400__)
  74874. # define NO_vsnprintf
  74875. #endif
  74876. #if defined(__MVS__)
  74877. # define NO_vsnprintf
  74878. # ifdef FAR
  74879. # undef FAR
  74880. # endif
  74881. #endif
  74882. #if defined(__MVS__)
  74883. # pragma map(deflateInit_,"DEIN")
  74884. # pragma map(deflateInit2_,"DEIN2")
  74885. # pragma map(deflateEnd,"DEEND")
  74886. # pragma map(deflateBound,"DEBND")
  74887. # pragma map(inflateInit_,"ININ")
  74888. # pragma map(inflateInit2_,"ININ2")
  74889. # pragma map(inflateEnd,"INEND")
  74890. # pragma map(inflateSync,"INSY")
  74891. # pragma map(inflateSetDictionary,"INSEDI")
  74892. # pragma map(compressBound,"CMBND")
  74893. # pragma map(inflate_table,"INTABL")
  74894. # pragma map(inflate_fast,"INFA")
  74895. # pragma map(inflate_copyright,"INCOPY")
  74896. #endif
  74897. #endif /* ZCONF_H */
  74898. /*** End of inlined file: zconf.h ***/
  74899. #ifdef __cplusplus
  74900. extern "C" {
  74901. #endif
  74902. #define ZLIB_VERSION "1.2.3"
  74903. #define ZLIB_VERNUM 0x1230
  74904. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74905. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74906. struct internal_state;
  74907. typedef struct z_stream_s {
  74908. Bytef *next_in; /* next input byte */
  74909. uInt avail_in; /* number of bytes available at next_in */
  74910. uLong total_in; /* total nb of input bytes read so far */
  74911. Bytef *next_out; /* next output byte should be put there */
  74912. uInt avail_out; /* remaining free space at next_out */
  74913. uLong total_out; /* total nb of bytes output so far */
  74914. char *msg; /* last error message, NULL if no error */
  74915. struct internal_state FAR *state; /* not visible by applications */
  74916. alloc_func zalloc; /* used to allocate the internal state */
  74917. free_func zfree; /* used to free the internal state */
  74918. voidpf opaque; /* private data object passed to zalloc and zfree */
  74919. int data_type; /* best guess about the data type: binary or text */
  74920. uLong adler; /* adler32 value of the uncompressed data */
  74921. uLong reserved; /* reserved for future use */
  74922. } z_stream;
  74923. typedef z_stream FAR *z_streamp;
  74924. typedef struct gz_header_s {
  74925. int text; /* true if compressed data believed to be text */
  74926. uLong time; /* modification time */
  74927. int xflags; /* extra flags (not used when writing a gzip file) */
  74928. int os; /* operating system */
  74929. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  74930. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  74931. uInt extra_max; /* space at extra (only when reading header) */
  74932. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  74933. uInt name_max; /* space at name (only when reading header) */
  74934. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  74935. uInt comm_max; /* space at comment (only when reading header) */
  74936. int hcrc; /* true if there was or will be a header crc */
  74937. int done; /* true when done reading gzip header (not used
  74938. when writing a gzip file) */
  74939. } gz_header;
  74940. typedef gz_header FAR *gz_headerp;
  74941. #define Z_NO_FLUSH 0
  74942. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  74943. #define Z_SYNC_FLUSH 2
  74944. #define Z_FULL_FLUSH 3
  74945. #define Z_FINISH 4
  74946. #define Z_BLOCK 5
  74947. #define Z_OK 0
  74948. #define Z_STREAM_END 1
  74949. #define Z_NEED_DICT 2
  74950. #define Z_ERRNO (-1)
  74951. #define Z_STREAM_ERROR (-2)
  74952. #define Z_DATA_ERROR (-3)
  74953. #define Z_MEM_ERROR (-4)
  74954. #define Z_BUF_ERROR (-5)
  74955. #define Z_VERSION_ERROR (-6)
  74956. #define Z_NO_COMPRESSION 0
  74957. #define Z_BEST_SPEED 1
  74958. #define Z_BEST_COMPRESSION 9
  74959. #define Z_DEFAULT_COMPRESSION (-1)
  74960. #define Z_FILTERED 1
  74961. #define Z_HUFFMAN_ONLY 2
  74962. #define Z_RLE 3
  74963. #define Z_FIXED 4
  74964. #define Z_DEFAULT_STRATEGY 0
  74965. #define Z_BINARY 0
  74966. #define Z_TEXT 1
  74967. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  74968. #define Z_UNKNOWN 2
  74969. #define Z_DEFLATED 8
  74970. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  74971. #define zlib_version zlibVersion()
  74972. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  74973. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  74974. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  74975. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  74976. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  74977. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  74978. const Bytef *dictionary,
  74979. uInt dictLength));
  74980. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  74981. z_streamp source));
  74982. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  74983. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  74984. int level,
  74985. int strategy));
  74986. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  74987. int good_length,
  74988. int max_lazy,
  74989. int nice_length,
  74990. int max_chain));
  74991. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  74992. uLong sourceLen));
  74993. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  74994. int bits,
  74995. int value));
  74996. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  74997. gz_headerp head));
  74998. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  74999. const Bytef *dictionary,
  75000. uInt dictLength));
  75001. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75002. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75003. z_streamp source));
  75004. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75005. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75006. int bits,
  75007. int value));
  75008. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75009. gz_headerp head));
  75010. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75011. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75012. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75013. in_func in, void FAR *in_desc,
  75014. out_func out, void FAR *out_desc));
  75015. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75016. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75017. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75018. const Bytef *source, uLong sourceLen));
  75019. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75020. const Bytef *source, uLong sourceLen,
  75021. int level));
  75022. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75023. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75024. const Bytef *source, uLong sourceLen));
  75025. typedef voidp gzFile;
  75026. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75027. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75028. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75029. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75030. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75031. voidpc buf, unsigned len));
  75032. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75033. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75034. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75035. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75036. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75037. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75038. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75039. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75040. z_off_t offset, int whence));
  75041. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75042. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75043. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75044. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75045. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75046. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75047. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75048. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75049. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75050. z_off_t len2));
  75051. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75052. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75053. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75054. const char *version, int stream_size));
  75055. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75056. const char *version, int stream_size));
  75057. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75058. int windowBits, int memLevel,
  75059. int strategy, const char *version,
  75060. int stream_size));
  75061. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75062. const char *version, int stream_size));
  75063. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75064. unsigned char FAR *window,
  75065. const char *version,
  75066. int stream_size));
  75067. #define deflateInit(strm, level) \
  75068. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75069. #define inflateInit(strm) \
  75070. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75071. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75072. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75073. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75074. #define inflateInit2(strm, windowBits) \
  75075. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75076. #define inflateBackInit(strm, windowBits, window) \
  75077. inflateBackInit_((strm), (windowBits), (window), \
  75078. ZLIB_VERSION, sizeof(z_stream))
  75079. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75080. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75081. #endif
  75082. ZEXTERN const char * ZEXPORT zError OF((int));
  75083. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75084. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75085. #ifdef __cplusplus
  75086. }
  75087. #endif
  75088. #endif /* ZLIB_H */
  75089. /*** End of inlined file: zlib.h ***/
  75090. #undef OS_CODE
  75091. #else
  75092. #include <zlib.h>
  75093. #endif
  75094. }
  75095. BEGIN_JUCE_NAMESPACE
  75096. // internal helper object that holds the zlib structures so they don't have to be
  75097. // included publicly.
  75098. class GZIPCompressorHelper
  75099. {
  75100. public:
  75101. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75102. : data (0),
  75103. dataSize (0),
  75104. compLevel (compressionLevel),
  75105. strategy (0),
  75106. setParams (true),
  75107. streamIsValid (false),
  75108. finished (false),
  75109. shouldFinish (false)
  75110. {
  75111. using namespace zlibNamespace;
  75112. zerostruct (stream);
  75113. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75114. nowrap ? -MAX_WBITS : MAX_WBITS,
  75115. 8, strategy) == Z_OK);
  75116. }
  75117. ~GZIPCompressorHelper()
  75118. {
  75119. using namespace zlibNamespace;
  75120. if (streamIsValid)
  75121. deflateEnd (&stream);
  75122. }
  75123. bool needsInput() const throw()
  75124. {
  75125. return dataSize <= 0;
  75126. }
  75127. void setInput (const uint8* const newData, const int size) throw()
  75128. {
  75129. data = newData;
  75130. dataSize = size;
  75131. }
  75132. int doNextBlock (uint8* const dest, const int destSize) throw()
  75133. {
  75134. using namespace zlibNamespace;
  75135. if (streamIsValid)
  75136. {
  75137. stream.next_in = const_cast <uint8*> (data);
  75138. stream.next_out = dest;
  75139. stream.avail_in = dataSize;
  75140. stream.avail_out = destSize;
  75141. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75142. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75143. setParams = false;
  75144. switch (result)
  75145. {
  75146. case Z_STREAM_END:
  75147. finished = true;
  75148. // Deliberate fall-through..
  75149. case Z_OK:
  75150. data += dataSize - stream.avail_in;
  75151. dataSize = stream.avail_in;
  75152. return destSize - stream.avail_out;
  75153. default:
  75154. break;
  75155. }
  75156. }
  75157. return 0;
  75158. }
  75159. private:
  75160. zlibNamespace::z_stream stream;
  75161. const uint8* data;
  75162. int dataSize, compLevel, strategy;
  75163. bool setParams, streamIsValid;
  75164. public:
  75165. bool finished, shouldFinish;
  75166. };
  75167. const int gzipCompBufferSize = 32768;
  75168. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75169. int compressionLevel,
  75170. const bool deleteDestStream,
  75171. const bool noWrap)
  75172. : destStream (destStream_),
  75173. streamToDelete (deleteDestStream ? destStream_ : 0),
  75174. buffer (gzipCompBufferSize)
  75175. {
  75176. if (compressionLevel < 1 || compressionLevel > 9)
  75177. compressionLevel = -1;
  75178. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75179. }
  75180. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75181. {
  75182. flush();
  75183. }
  75184. void GZIPCompressorOutputStream::flush()
  75185. {
  75186. if (! helper->finished)
  75187. {
  75188. helper->shouldFinish = true;
  75189. while (! helper->finished)
  75190. doNextBlock();
  75191. }
  75192. destStream->flush();
  75193. }
  75194. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75195. {
  75196. if (! helper->finished)
  75197. {
  75198. helper->setInput (static_cast <const uint8*> (destBuffer), howMany);
  75199. while (! helper->needsInput())
  75200. {
  75201. if (! doNextBlock())
  75202. return false;
  75203. }
  75204. }
  75205. return true;
  75206. }
  75207. bool GZIPCompressorOutputStream::doNextBlock()
  75208. {
  75209. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75210. if (len > 0)
  75211. return destStream->write (buffer, len);
  75212. else
  75213. return true;
  75214. }
  75215. int64 GZIPCompressorOutputStream::getPosition()
  75216. {
  75217. return destStream->getPosition();
  75218. }
  75219. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75220. {
  75221. jassertfalse // can't do it!
  75222. return false;
  75223. }
  75224. END_JUCE_NAMESPACE
  75225. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75226. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75227. #if JUCE_MSVC
  75228. #pragma warning (push)
  75229. #pragma warning (disable: 4309 4305)
  75230. #endif
  75231. namespace zlibNamespace
  75232. {
  75233. #if JUCE_INCLUDE_ZLIB_CODE
  75234. extern "C"
  75235. {
  75236. #undef OS_CODE
  75237. #undef fdopen
  75238. #define ZLIB_INTERNAL
  75239. #define NO_DUMMY_DECL
  75240. /*** Start of inlined file: adler32.c ***/
  75241. #define ZLIB_INTERNAL
  75242. #define BASE 65521UL /* largest prime smaller than 65536 */
  75243. #define NMAX 5552
  75244. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75245. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75246. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75247. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75248. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75249. #ifdef NO_DIVIDE
  75250. # define MOD(a) \
  75251. do { \
  75252. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75253. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75254. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75255. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75256. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75257. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75258. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75259. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75260. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75261. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75262. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75263. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75264. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75265. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75266. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75267. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75268. if (a >= BASE) a -= BASE; \
  75269. } while (0)
  75270. # define MOD4(a) \
  75271. do { \
  75272. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75273. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75274. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75275. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75276. if (a >= BASE) a -= BASE; \
  75277. } while (0)
  75278. #else
  75279. # define MOD(a) a %= BASE
  75280. # define MOD4(a) a %= BASE
  75281. #endif
  75282. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75283. {
  75284. unsigned long sum2;
  75285. unsigned n;
  75286. sum2 = (adler >> 16) & 0xffff;
  75287. adler &= 0xffff;
  75288. if (len == 1) {
  75289. adler += buf[0];
  75290. if (adler >= BASE)
  75291. adler -= BASE;
  75292. sum2 += adler;
  75293. if (sum2 >= BASE)
  75294. sum2 -= BASE;
  75295. return adler | (sum2 << 16);
  75296. }
  75297. if (buf == Z_NULL)
  75298. return 1L;
  75299. if (len < 16) {
  75300. while (len--) {
  75301. adler += *buf++;
  75302. sum2 += adler;
  75303. }
  75304. if (adler >= BASE)
  75305. adler -= BASE;
  75306. MOD4(sum2); /* only added so many BASE's */
  75307. return adler | (sum2 << 16);
  75308. }
  75309. while (len >= NMAX) {
  75310. len -= NMAX;
  75311. n = NMAX / 16; /* NMAX is divisible by 16 */
  75312. do {
  75313. DO16(buf); /* 16 sums unrolled */
  75314. buf += 16;
  75315. } while (--n);
  75316. MOD(adler);
  75317. MOD(sum2);
  75318. }
  75319. if (len) { /* avoid modulos if none remaining */
  75320. while (len >= 16) {
  75321. len -= 16;
  75322. DO16(buf);
  75323. buf += 16;
  75324. }
  75325. while (len--) {
  75326. adler += *buf++;
  75327. sum2 += adler;
  75328. }
  75329. MOD(adler);
  75330. MOD(sum2);
  75331. }
  75332. return adler | (sum2 << 16);
  75333. }
  75334. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75335. {
  75336. unsigned long sum1;
  75337. unsigned long sum2;
  75338. unsigned rem;
  75339. rem = (unsigned)(len2 % BASE);
  75340. sum1 = adler1 & 0xffff;
  75341. sum2 = rem * sum1;
  75342. MOD(sum2);
  75343. sum1 += (adler2 & 0xffff) + BASE - 1;
  75344. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75345. if (sum1 > BASE) sum1 -= BASE;
  75346. if (sum1 > BASE) sum1 -= BASE;
  75347. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75348. if (sum2 > BASE) sum2 -= BASE;
  75349. return sum1 | (sum2 << 16);
  75350. }
  75351. /*** End of inlined file: adler32.c ***/
  75352. /*** Start of inlined file: compress.c ***/
  75353. #define ZLIB_INTERNAL
  75354. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75355. uLong sourceLen, int level)
  75356. {
  75357. z_stream stream;
  75358. int err;
  75359. stream.next_in = (Bytef*)source;
  75360. stream.avail_in = (uInt)sourceLen;
  75361. #ifdef MAXSEG_64K
  75362. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75363. #endif
  75364. stream.next_out = dest;
  75365. stream.avail_out = (uInt)*destLen;
  75366. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75367. stream.zalloc = (alloc_func)0;
  75368. stream.zfree = (free_func)0;
  75369. stream.opaque = (voidpf)0;
  75370. err = deflateInit(&stream, level);
  75371. if (err != Z_OK) return err;
  75372. err = deflate(&stream, Z_FINISH);
  75373. if (err != Z_STREAM_END) {
  75374. deflateEnd(&stream);
  75375. return err == Z_OK ? Z_BUF_ERROR : err;
  75376. }
  75377. *destLen = stream.total_out;
  75378. err = deflateEnd(&stream);
  75379. return err;
  75380. }
  75381. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75382. {
  75383. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75384. }
  75385. uLong ZEXPORT compressBound (uLong sourceLen)
  75386. {
  75387. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75388. }
  75389. /*** End of inlined file: compress.c ***/
  75390. #undef DO1
  75391. #undef DO8
  75392. /*** Start of inlined file: crc32.c ***/
  75393. #ifdef MAKECRCH
  75394. # include <stdio.h>
  75395. # ifndef DYNAMIC_CRC_TABLE
  75396. # define DYNAMIC_CRC_TABLE
  75397. # endif /* !DYNAMIC_CRC_TABLE */
  75398. #endif /* MAKECRCH */
  75399. /*** Start of inlined file: zutil.h ***/
  75400. #ifndef ZUTIL_H
  75401. #define ZUTIL_H
  75402. #define ZLIB_INTERNAL
  75403. #ifdef STDC
  75404. # ifndef _WIN32_WCE
  75405. # include <stddef.h>
  75406. # endif
  75407. # include <string.h>
  75408. # include <stdlib.h>
  75409. #endif
  75410. #ifdef NO_ERRNO_H
  75411. # ifdef _WIN32_WCE
  75412. # define errno z_errno
  75413. # endif
  75414. extern int errno;
  75415. #else
  75416. # ifndef _WIN32_WCE
  75417. # include <errno.h>
  75418. # endif
  75419. #endif
  75420. #ifndef local
  75421. # define local static
  75422. #endif
  75423. typedef unsigned char uch;
  75424. typedef uch FAR uchf;
  75425. typedef unsigned short ush;
  75426. typedef ush FAR ushf;
  75427. typedef unsigned long ulg;
  75428. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75429. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75430. #define ERR_RETURN(strm,err) \
  75431. return (strm->msg = (char*)ERR_MSG(err), (err))
  75432. #ifndef DEF_WBITS
  75433. # define DEF_WBITS MAX_WBITS
  75434. #endif
  75435. #if MAX_MEM_LEVEL >= 8
  75436. # define DEF_MEM_LEVEL 8
  75437. #else
  75438. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75439. #endif
  75440. #define STORED_BLOCK 0
  75441. #define STATIC_TREES 1
  75442. #define DYN_TREES 2
  75443. #define MIN_MATCH 3
  75444. #define MAX_MATCH 258
  75445. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75446. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75447. # define OS_CODE 0x00
  75448. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75449. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75450. void _Cdecl farfree( void *block );
  75451. void *_Cdecl farmalloc( unsigned long nbytes );
  75452. # else
  75453. # include <alloc.h>
  75454. # endif
  75455. # else /* MSC or DJGPP */
  75456. # include <malloc.h>
  75457. # endif
  75458. #endif
  75459. #ifdef AMIGA
  75460. # define OS_CODE 0x01
  75461. #endif
  75462. #if defined(VAXC) || defined(VMS)
  75463. # define OS_CODE 0x02
  75464. # define F_OPEN(name, mode) \
  75465. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75466. #endif
  75467. #if defined(ATARI) || defined(atarist)
  75468. # define OS_CODE 0x05
  75469. #endif
  75470. #ifdef OS2
  75471. # define OS_CODE 0x06
  75472. # ifdef M_I86
  75473. #include <malloc.h>
  75474. # endif
  75475. #endif
  75476. #if defined(MACOS) || TARGET_OS_MAC
  75477. # define OS_CODE 0x07
  75478. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75479. # include <unix.h> /* for fdopen */
  75480. # else
  75481. # ifndef fdopen
  75482. # define fdopen(fd,mode) NULL /* No fdopen() */
  75483. # endif
  75484. # endif
  75485. #endif
  75486. #ifdef TOPS20
  75487. # define OS_CODE 0x0a
  75488. #endif
  75489. #ifdef WIN32
  75490. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75491. # define OS_CODE 0x0b
  75492. # endif
  75493. #endif
  75494. #ifdef __50SERIES /* Prime/PRIMOS */
  75495. # define OS_CODE 0x0f
  75496. #endif
  75497. #if defined(_BEOS_) || defined(RISCOS)
  75498. # define fdopen(fd,mode) NULL /* No fdopen() */
  75499. #endif
  75500. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75501. # if defined(_WIN32_WCE)
  75502. # define fdopen(fd,mode) NULL /* No fdopen() */
  75503. # ifndef _PTRDIFF_T_DEFINED
  75504. typedef int ptrdiff_t;
  75505. # define _PTRDIFF_T_DEFINED
  75506. # endif
  75507. # else
  75508. # define fdopen(fd,type) _fdopen(fd,type)
  75509. # endif
  75510. #endif
  75511. #ifndef OS_CODE
  75512. # define OS_CODE 0x03 /* assume Unix */
  75513. #endif
  75514. #ifndef F_OPEN
  75515. # define F_OPEN(name, mode) fopen((name), (mode))
  75516. #endif
  75517. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75518. # ifndef HAVE_VSNPRINTF
  75519. # define HAVE_VSNPRINTF
  75520. # endif
  75521. #endif
  75522. #if defined(__CYGWIN__)
  75523. # ifndef HAVE_VSNPRINTF
  75524. # define HAVE_VSNPRINTF
  75525. # endif
  75526. #endif
  75527. #ifndef HAVE_VSNPRINTF
  75528. # ifdef MSDOS
  75529. # define NO_vsnprintf
  75530. # endif
  75531. # ifdef __TURBOC__
  75532. # define NO_vsnprintf
  75533. # endif
  75534. # ifdef WIN32
  75535. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75536. # define vsnprintf _vsnprintf
  75537. # endif
  75538. # endif
  75539. # ifdef __SASC
  75540. # define NO_vsnprintf
  75541. # endif
  75542. #endif
  75543. #ifdef VMS
  75544. # define NO_vsnprintf
  75545. #endif
  75546. #if defined(pyr)
  75547. # define NO_MEMCPY
  75548. #endif
  75549. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75550. # define NO_MEMCPY
  75551. #endif
  75552. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75553. # define HAVE_MEMCPY
  75554. #endif
  75555. #ifdef HAVE_MEMCPY
  75556. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75557. # define zmemcpy _fmemcpy
  75558. # define zmemcmp _fmemcmp
  75559. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75560. # else
  75561. # define zmemcpy memcpy
  75562. # define zmemcmp memcmp
  75563. # define zmemzero(dest, len) memset(dest, 0, len)
  75564. # endif
  75565. #else
  75566. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75567. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75568. extern void zmemzero OF((Bytef* dest, uInt len));
  75569. #endif
  75570. #ifdef DEBUG
  75571. # include <stdio.h>
  75572. extern int z_verbose;
  75573. extern void z_error OF((const char *m));
  75574. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75575. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75576. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75577. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75578. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75579. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75580. #else
  75581. # define Assert(cond,msg)
  75582. # define Trace(x)
  75583. # define Tracev(x)
  75584. # define Tracevv(x)
  75585. # define Tracec(c,x)
  75586. # define Tracecv(c,x)
  75587. #endif
  75588. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75589. void zcfree OF((voidpf opaque, voidpf ptr));
  75590. #define ZALLOC(strm, items, size) \
  75591. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75592. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75593. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75594. #endif /* ZUTIL_H */
  75595. /*** End of inlined file: zutil.h ***/
  75596. /* for STDC and FAR definitions */
  75597. #define local static
  75598. #ifndef NOBYFOUR
  75599. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75600. # include <limits.h>
  75601. # define BYFOUR
  75602. # if (UINT_MAX == 0xffffffffUL)
  75603. typedef unsigned int u4;
  75604. # else
  75605. # if (ULONG_MAX == 0xffffffffUL)
  75606. typedef unsigned long u4;
  75607. # else
  75608. # if (USHRT_MAX == 0xffffffffUL)
  75609. typedef unsigned short u4;
  75610. # else
  75611. # undef BYFOUR /* can't find a four-byte integer type! */
  75612. # endif
  75613. # endif
  75614. # endif
  75615. # endif /* STDC */
  75616. #endif /* !NOBYFOUR */
  75617. #ifdef BYFOUR
  75618. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75619. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75620. local unsigned long crc32_little OF((unsigned long,
  75621. const unsigned char FAR *, unsigned));
  75622. local unsigned long crc32_big OF((unsigned long,
  75623. const unsigned char FAR *, unsigned));
  75624. # define TBLS 8
  75625. #else
  75626. # define TBLS 1
  75627. #endif /* BYFOUR */
  75628. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75629. unsigned long vec));
  75630. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75631. #ifdef DYNAMIC_CRC_TABLE
  75632. local volatile int crc_table_empty = 1;
  75633. local unsigned long FAR crc_table[TBLS][256];
  75634. local void make_crc_table OF((void));
  75635. #ifdef MAKECRCH
  75636. local void write_table OF((FILE *, const unsigned long FAR *));
  75637. #endif /* MAKECRCH */
  75638. local void make_crc_table()
  75639. {
  75640. unsigned long c;
  75641. int n, k;
  75642. unsigned long poly; /* polynomial exclusive-or pattern */
  75643. static volatile int first = 1; /* flag to limit concurrent making */
  75644. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75645. if (first) {
  75646. first = 0;
  75647. poly = 0UL;
  75648. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75649. poly |= 1UL << (31 - p[n]);
  75650. for (n = 0; n < 256; n++) {
  75651. c = (unsigned long)n;
  75652. for (k = 0; k < 8; k++)
  75653. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75654. crc_table[0][n] = c;
  75655. }
  75656. #ifdef BYFOUR
  75657. for (n = 0; n < 256; n++) {
  75658. c = crc_table[0][n];
  75659. crc_table[4][n] = REV(c);
  75660. for (k = 1; k < 4; k++) {
  75661. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75662. crc_table[k][n] = c;
  75663. crc_table[k + 4][n] = REV(c);
  75664. }
  75665. }
  75666. #endif /* BYFOUR */
  75667. crc_table_empty = 0;
  75668. }
  75669. else { /* not first */
  75670. while (crc_table_empty)
  75671. ;
  75672. }
  75673. #ifdef MAKECRCH
  75674. {
  75675. FILE *out;
  75676. out = fopen("crc32.h", "w");
  75677. if (out == NULL) return;
  75678. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75679. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75680. fprintf(out, "local const unsigned long FAR ");
  75681. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75682. write_table(out, crc_table[0]);
  75683. # ifdef BYFOUR
  75684. fprintf(out, "#ifdef BYFOUR\n");
  75685. for (k = 1; k < 8; k++) {
  75686. fprintf(out, " },\n {\n");
  75687. write_table(out, crc_table[k]);
  75688. }
  75689. fprintf(out, "#endif\n");
  75690. # endif /* BYFOUR */
  75691. fprintf(out, " }\n};\n");
  75692. fclose(out);
  75693. }
  75694. #endif /* MAKECRCH */
  75695. }
  75696. #ifdef MAKECRCH
  75697. local void write_table(out, table)
  75698. FILE *out;
  75699. const unsigned long FAR *table;
  75700. {
  75701. int n;
  75702. for (n = 0; n < 256; n++)
  75703. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75704. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75705. }
  75706. #endif /* MAKECRCH */
  75707. #else /* !DYNAMIC_CRC_TABLE */
  75708. /*** Start of inlined file: crc32.h ***/
  75709. local const unsigned long FAR crc_table[TBLS][256] =
  75710. {
  75711. {
  75712. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75713. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75714. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75715. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75716. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75717. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75718. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75719. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75720. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75721. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75722. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75723. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75724. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75725. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75726. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75727. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75728. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75729. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75730. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75731. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75732. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75733. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75734. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75735. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75736. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75737. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75738. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75739. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75740. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75741. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75742. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75743. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75744. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75745. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75746. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75747. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75748. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75749. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75750. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75751. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75752. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75753. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75754. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75755. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75756. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75757. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75758. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75759. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75760. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75761. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75762. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75763. 0x2d02ef8dUL
  75764. #ifdef BYFOUR
  75765. },
  75766. {
  75767. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75768. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75769. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75770. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75771. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75772. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75773. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75774. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75775. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75776. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75777. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75778. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75779. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75780. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75781. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75782. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75783. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75784. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75785. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75786. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75787. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75788. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75789. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75790. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75791. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75792. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75793. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75794. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75795. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75796. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75797. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75798. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75799. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75800. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75801. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75802. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75803. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75804. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75805. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75806. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75807. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75808. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75809. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75810. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75811. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75812. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75813. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75814. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75815. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75816. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75817. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75818. 0x9324fd72UL
  75819. },
  75820. {
  75821. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75822. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75823. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75824. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75825. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75826. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75827. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75828. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75829. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75830. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75831. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75832. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75833. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75834. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75835. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75836. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75837. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75838. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75839. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75840. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75841. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75842. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75843. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75844. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75845. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75846. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75847. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75848. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75849. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75850. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75851. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75852. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75853. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75854. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75855. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75856. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75857. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75858. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75859. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75860. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75861. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75862. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75863. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75864. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75865. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75866. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75867. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75868. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75869. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75870. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75871. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75872. 0xbe9834edUL
  75873. },
  75874. {
  75875. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75876. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75877. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75878. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75879. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75880. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75881. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75882. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75883. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75884. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75885. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75886. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75887. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75888. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75889. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75890. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75891. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75892. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75893. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75894. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75895. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75896. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75897. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75898. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75899. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75900. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75901. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75902. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75903. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75904. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75905. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75906. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75907. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75908. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75909. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75910. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75911. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75912. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75913. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75914. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75915. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75916. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  75917. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  75918. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  75919. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  75920. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  75921. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  75922. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  75923. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  75924. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  75925. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  75926. 0xde0506f1UL
  75927. },
  75928. {
  75929. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  75930. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  75931. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  75932. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  75933. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  75934. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  75935. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  75936. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  75937. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  75938. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  75939. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  75940. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  75941. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  75942. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  75943. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  75944. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  75945. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  75946. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  75947. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  75948. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  75949. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  75950. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  75951. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  75952. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  75953. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  75954. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  75955. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  75956. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  75957. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  75958. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  75959. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  75960. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  75961. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  75962. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  75963. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  75964. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  75965. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  75966. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  75967. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  75968. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  75969. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  75970. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  75971. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  75972. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  75973. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  75974. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  75975. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  75976. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  75977. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  75978. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  75979. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  75980. 0x8def022dUL
  75981. },
  75982. {
  75983. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  75984. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  75985. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  75986. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  75987. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  75988. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  75989. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  75990. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  75991. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  75992. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  75993. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  75994. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  75995. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  75996. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  75997. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  75998. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  75999. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76000. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76001. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76002. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76003. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76004. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76005. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76006. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76007. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76008. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76009. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76010. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76011. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76012. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76013. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76014. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76015. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76016. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76017. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76018. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76019. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76020. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76021. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76022. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76023. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76024. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76025. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76026. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76027. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76028. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76029. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76030. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76031. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76032. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76033. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76034. 0x72fd2493UL
  76035. },
  76036. {
  76037. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76038. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76039. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76040. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76041. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76042. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76043. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76044. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76045. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76046. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76047. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76048. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76049. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76050. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76051. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76052. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76053. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76054. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76055. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76056. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76057. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76058. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76059. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76060. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76061. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76062. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76063. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76064. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76065. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76066. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76067. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76068. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76069. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76070. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76071. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76072. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76073. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76074. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76075. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76076. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76077. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76078. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76079. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76080. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76081. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76082. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76083. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76084. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76085. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76086. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76087. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76088. 0xed3498beUL
  76089. },
  76090. {
  76091. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76092. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76093. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76094. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76095. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76096. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76097. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76098. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76099. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76100. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76101. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76102. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76103. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76104. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76105. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76106. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76107. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76108. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76109. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76110. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76111. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76112. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76113. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76114. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76115. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76116. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76117. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76118. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76119. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76120. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76121. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76122. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76123. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76124. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76125. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76126. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76127. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76128. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76129. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76130. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76131. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76132. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76133. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76134. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76135. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76136. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76137. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76138. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76139. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76140. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76141. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76142. 0xf10605deUL
  76143. #endif
  76144. }
  76145. };
  76146. /*** End of inlined file: crc32.h ***/
  76147. #endif /* DYNAMIC_CRC_TABLE */
  76148. const unsigned long FAR * ZEXPORT get_crc_table()
  76149. {
  76150. #ifdef DYNAMIC_CRC_TABLE
  76151. if (crc_table_empty)
  76152. make_crc_table();
  76153. #endif /* DYNAMIC_CRC_TABLE */
  76154. return (const unsigned long FAR *)crc_table;
  76155. }
  76156. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76157. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76158. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76159. {
  76160. if (buf == Z_NULL) return 0UL;
  76161. #ifdef DYNAMIC_CRC_TABLE
  76162. if (crc_table_empty)
  76163. make_crc_table();
  76164. #endif /* DYNAMIC_CRC_TABLE */
  76165. #ifdef BYFOUR
  76166. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76167. u4 endian;
  76168. endian = 1;
  76169. if (*((unsigned char *)(&endian)))
  76170. return crc32_little(crc, buf, len);
  76171. else
  76172. return crc32_big(crc, buf, len);
  76173. }
  76174. #endif /* BYFOUR */
  76175. crc = crc ^ 0xffffffffUL;
  76176. while (len >= 8) {
  76177. DO8;
  76178. len -= 8;
  76179. }
  76180. if (len) do {
  76181. DO1;
  76182. } while (--len);
  76183. return crc ^ 0xffffffffUL;
  76184. }
  76185. #ifdef BYFOUR
  76186. #define DOLIT4 c ^= *buf4++; \
  76187. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76188. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76189. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76190. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76191. {
  76192. register u4 c;
  76193. register const u4 FAR *buf4;
  76194. c = (u4)crc;
  76195. c = ~c;
  76196. while (len && ((ptrdiff_t)buf & 3)) {
  76197. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76198. len--;
  76199. }
  76200. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76201. while (len >= 32) {
  76202. DOLIT32;
  76203. len -= 32;
  76204. }
  76205. while (len >= 4) {
  76206. DOLIT4;
  76207. len -= 4;
  76208. }
  76209. buf = (const unsigned char FAR *)buf4;
  76210. if (len) do {
  76211. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76212. } while (--len);
  76213. c = ~c;
  76214. return (unsigned long)c;
  76215. }
  76216. #define DOBIG4 c ^= *++buf4; \
  76217. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76218. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76219. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76220. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76221. {
  76222. register u4 c;
  76223. register const u4 FAR *buf4;
  76224. c = REV((u4)crc);
  76225. c = ~c;
  76226. while (len && ((ptrdiff_t)buf & 3)) {
  76227. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76228. len--;
  76229. }
  76230. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76231. buf4--;
  76232. while (len >= 32) {
  76233. DOBIG32;
  76234. len -= 32;
  76235. }
  76236. while (len >= 4) {
  76237. DOBIG4;
  76238. len -= 4;
  76239. }
  76240. buf4++;
  76241. buf = (const unsigned char FAR *)buf4;
  76242. if (len) do {
  76243. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76244. } while (--len);
  76245. c = ~c;
  76246. return (unsigned long)(REV(c));
  76247. }
  76248. #endif /* BYFOUR */
  76249. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76250. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76251. {
  76252. unsigned long sum;
  76253. sum = 0;
  76254. while (vec) {
  76255. if (vec & 1)
  76256. sum ^= *mat;
  76257. vec >>= 1;
  76258. mat++;
  76259. }
  76260. return sum;
  76261. }
  76262. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76263. {
  76264. int n;
  76265. for (n = 0; n < GF2_DIM; n++)
  76266. square[n] = gf2_matrix_times(mat, mat[n]);
  76267. }
  76268. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76269. {
  76270. int n;
  76271. unsigned long row;
  76272. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76273. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76274. if (len2 == 0)
  76275. return crc1;
  76276. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76277. row = 1;
  76278. for (n = 1; n < GF2_DIM; n++) {
  76279. odd[n] = row;
  76280. row <<= 1;
  76281. }
  76282. gf2_matrix_square(even, odd);
  76283. gf2_matrix_square(odd, even);
  76284. do {
  76285. gf2_matrix_square(even, odd);
  76286. if (len2 & 1)
  76287. crc1 = gf2_matrix_times(even, crc1);
  76288. len2 >>= 1;
  76289. if (len2 == 0)
  76290. break;
  76291. gf2_matrix_square(odd, even);
  76292. if (len2 & 1)
  76293. crc1 = gf2_matrix_times(odd, crc1);
  76294. len2 >>= 1;
  76295. } while (len2 != 0);
  76296. crc1 ^= crc2;
  76297. return crc1;
  76298. }
  76299. /*** End of inlined file: crc32.c ***/
  76300. /*** Start of inlined file: deflate.c ***/
  76301. /*** Start of inlined file: deflate.h ***/
  76302. #ifndef DEFLATE_H
  76303. #define DEFLATE_H
  76304. #ifndef NO_GZIP
  76305. # define GZIP
  76306. #endif
  76307. #define NO_DUMMY_DECL
  76308. #define LENGTH_CODES 29
  76309. #define LITERALS 256
  76310. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76311. #define D_CODES 30
  76312. #define BL_CODES 19
  76313. #define HEAP_SIZE (2*L_CODES+1)
  76314. #define MAX_BITS 15
  76315. #define INIT_STATE 42
  76316. #define EXTRA_STATE 69
  76317. #define NAME_STATE 73
  76318. #define COMMENT_STATE 91
  76319. #define HCRC_STATE 103
  76320. #define BUSY_STATE 113
  76321. #define FINISH_STATE 666
  76322. typedef struct ct_data_s {
  76323. union {
  76324. ush freq; /* frequency count */
  76325. ush code; /* bit string */
  76326. } fc;
  76327. union {
  76328. ush dad; /* father node in Huffman tree */
  76329. ush len; /* length of bit string */
  76330. } dl;
  76331. } FAR ct_data;
  76332. #define Freq fc.freq
  76333. #define Code fc.code
  76334. #define Dad dl.dad
  76335. #define Len dl.len
  76336. typedef struct static_tree_desc_s static_tree_desc;
  76337. typedef struct tree_desc_s {
  76338. ct_data *dyn_tree; /* the dynamic tree */
  76339. int max_code; /* largest code with non zero frequency */
  76340. static_tree_desc *stat_desc; /* the corresponding static tree */
  76341. } FAR tree_desc;
  76342. typedef ush Pos;
  76343. typedef Pos FAR Posf;
  76344. typedef unsigned IPos;
  76345. typedef struct internal_state {
  76346. z_streamp strm; /* pointer back to this zlib stream */
  76347. int status; /* as the name implies */
  76348. Bytef *pending_buf; /* output still pending */
  76349. ulg pending_buf_size; /* size of pending_buf */
  76350. Bytef *pending_out; /* next pending byte to output to the stream */
  76351. uInt pending; /* nb of bytes in the pending buffer */
  76352. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76353. gz_headerp gzhead; /* gzip header information to write */
  76354. uInt gzindex; /* where in extra, name, or comment */
  76355. Byte method; /* STORED (for zip only) or DEFLATED */
  76356. int last_flush; /* value of flush param for previous deflate call */
  76357. uInt w_size; /* LZ77 window size (32K by default) */
  76358. uInt w_bits; /* log2(w_size) (8..16) */
  76359. uInt w_mask; /* w_size - 1 */
  76360. Bytef *window;
  76361. ulg window_size;
  76362. Posf *prev;
  76363. Posf *head; /* Heads of the hash chains or NIL. */
  76364. uInt ins_h; /* hash index of string to be inserted */
  76365. uInt hash_size; /* number of elements in hash table */
  76366. uInt hash_bits; /* log2(hash_size) */
  76367. uInt hash_mask; /* hash_size-1 */
  76368. uInt hash_shift;
  76369. long block_start;
  76370. uInt match_length; /* length of best match */
  76371. IPos prev_match; /* previous match */
  76372. int match_available; /* set if previous match exists */
  76373. uInt strstart; /* start of string to insert */
  76374. uInt match_start; /* start of matching string */
  76375. uInt lookahead; /* number of valid bytes ahead in window */
  76376. uInt prev_length;
  76377. uInt max_chain_length;
  76378. uInt max_lazy_match;
  76379. # define max_insert_length max_lazy_match
  76380. int level; /* compression level (1..9) */
  76381. int strategy; /* favor or force Huffman coding*/
  76382. uInt good_match;
  76383. int nice_match; /* Stop searching when current match exceeds this */
  76384. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76385. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76386. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76387. struct tree_desc_s l_desc; /* desc. for literal tree */
  76388. struct tree_desc_s d_desc; /* desc. for distance tree */
  76389. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76390. ush bl_count[MAX_BITS+1];
  76391. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76392. int heap_len; /* number of elements in the heap */
  76393. int heap_max; /* element of largest frequency */
  76394. uch depth[2*L_CODES+1];
  76395. uchf *l_buf; /* buffer for literals or lengths */
  76396. uInt lit_bufsize;
  76397. uInt last_lit; /* running index in l_buf */
  76398. ushf *d_buf;
  76399. ulg opt_len; /* bit length of current block with optimal trees */
  76400. ulg static_len; /* bit length of current block with static trees */
  76401. uInt matches; /* number of string matches in current block */
  76402. int last_eob_len; /* bit length of EOB code for last block */
  76403. #ifdef DEBUG
  76404. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76405. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76406. #endif
  76407. ush bi_buf;
  76408. int bi_valid;
  76409. } FAR deflate_state;
  76410. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76411. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76412. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76413. void _tr_init OF((deflate_state *s));
  76414. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76415. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76416. int eof));
  76417. void _tr_align OF((deflate_state *s));
  76418. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76419. int eof));
  76420. #define d_code(dist) \
  76421. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76422. #ifndef DEBUG
  76423. #if defined(GEN_TREES_H) || !defined(STDC)
  76424. extern uch _length_code[];
  76425. extern uch _dist_code[];
  76426. #else
  76427. extern const uch _length_code[];
  76428. extern const uch _dist_code[];
  76429. #endif
  76430. # define _tr_tally_lit(s, c, flush) \
  76431. { uch cc = (c); \
  76432. s->d_buf[s->last_lit] = 0; \
  76433. s->l_buf[s->last_lit++] = cc; \
  76434. s->dyn_ltree[cc].Freq++; \
  76435. flush = (s->last_lit == s->lit_bufsize-1); \
  76436. }
  76437. # define _tr_tally_dist(s, distance, length, flush) \
  76438. { uch len = (length); \
  76439. ush dist = (distance); \
  76440. s->d_buf[s->last_lit] = dist; \
  76441. s->l_buf[s->last_lit++] = len; \
  76442. dist--; \
  76443. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76444. s->dyn_dtree[d_code(dist)].Freq++; \
  76445. flush = (s->last_lit == s->lit_bufsize-1); \
  76446. }
  76447. #else
  76448. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76449. # define _tr_tally_dist(s, distance, length, flush) \
  76450. flush = _tr_tally(s, distance, length)
  76451. #endif
  76452. #endif /* DEFLATE_H */
  76453. /*** End of inlined file: deflate.h ***/
  76454. const char deflate_copyright[] =
  76455. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76456. typedef enum {
  76457. need_more, /* block not completed, need more input or more output */
  76458. block_done, /* block flush performed */
  76459. finish_started, /* finish started, need only more output at next deflate */
  76460. finish_done /* finish done, accept no more input or output */
  76461. } block_state;
  76462. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76463. local void fill_window OF((deflate_state *s));
  76464. local block_state deflate_stored OF((deflate_state *s, int flush));
  76465. local block_state deflate_fast OF((deflate_state *s, int flush));
  76466. #ifndef FASTEST
  76467. local block_state deflate_slow OF((deflate_state *s, int flush));
  76468. #endif
  76469. local void lm_init OF((deflate_state *s));
  76470. local void putShortMSB OF((deflate_state *s, uInt b));
  76471. local void flush_pending OF((z_streamp strm));
  76472. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76473. #ifndef FASTEST
  76474. #ifdef ASMV
  76475. void match_init OF((void)); /* asm code initialization */
  76476. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76477. #else
  76478. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76479. #endif
  76480. #endif
  76481. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76482. #ifdef DEBUG
  76483. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76484. int length));
  76485. #endif
  76486. #define NIL 0
  76487. #ifndef TOO_FAR
  76488. # define TOO_FAR 4096
  76489. #endif
  76490. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76491. typedef struct config_s {
  76492. ush good_length; /* reduce lazy search above this match length */
  76493. ush max_lazy; /* do not perform lazy search above this match length */
  76494. ush nice_length; /* quit search above this match length */
  76495. ush max_chain;
  76496. compress_func func;
  76497. } config;
  76498. #ifdef FASTEST
  76499. local const config configuration_table[2] = {
  76500. {0, 0, 0, 0, deflate_stored}, /* store only */
  76501. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76502. #else
  76503. local const config configuration_table[10] = {
  76504. {0, 0, 0, 0, deflate_stored}, /* store only */
  76505. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76506. {4, 5, 16, 8, deflate_fast},
  76507. {4, 6, 32, 32, deflate_fast},
  76508. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76509. {8, 16, 32, 32, deflate_slow},
  76510. {8, 16, 128, 128, deflate_slow},
  76511. {8, 32, 128, 256, deflate_slow},
  76512. {32, 128, 258, 1024, deflate_slow},
  76513. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76514. #endif
  76515. #define EQUAL 0
  76516. #ifndef NO_DUMMY_DECL
  76517. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76518. #endif
  76519. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76520. #ifdef FASTEST
  76521. #define INSERT_STRING(s, str, match_head) \
  76522. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76523. match_head = s->head[s->ins_h], \
  76524. s->head[s->ins_h] = (Pos)(str))
  76525. #else
  76526. #define INSERT_STRING(s, str, match_head) \
  76527. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76528. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76529. s->head[s->ins_h] = (Pos)(str))
  76530. #endif
  76531. #define CLEAR_HASH(s) \
  76532. s->head[s->hash_size-1] = NIL; \
  76533. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76534. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76535. {
  76536. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76537. Z_DEFAULT_STRATEGY, version, stream_size);
  76538. }
  76539. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76540. {
  76541. deflate_state *s;
  76542. int wrap = 1;
  76543. static const char my_version[] = ZLIB_VERSION;
  76544. ushf *overlay;
  76545. if (version == Z_NULL || version[0] != my_version[0] ||
  76546. stream_size != sizeof(z_stream)) {
  76547. return Z_VERSION_ERROR;
  76548. }
  76549. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76550. strm->msg = Z_NULL;
  76551. if (strm->zalloc == (alloc_func)0) {
  76552. strm->zalloc = zcalloc;
  76553. strm->opaque = (voidpf)0;
  76554. }
  76555. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76556. #ifdef FASTEST
  76557. if (level != 0) level = 1;
  76558. #else
  76559. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76560. #endif
  76561. if (windowBits < 0) { /* suppress zlib wrapper */
  76562. wrap = 0;
  76563. windowBits = -windowBits;
  76564. }
  76565. #ifdef GZIP
  76566. else if (windowBits > 15) {
  76567. wrap = 2; /* write gzip wrapper instead */
  76568. windowBits -= 16;
  76569. }
  76570. #endif
  76571. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76572. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76573. strategy < 0 || strategy > Z_FIXED) {
  76574. return Z_STREAM_ERROR;
  76575. }
  76576. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76577. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76578. if (s == Z_NULL) return Z_MEM_ERROR;
  76579. strm->state = (struct internal_state FAR *)s;
  76580. s->strm = strm;
  76581. s->wrap = wrap;
  76582. s->gzhead = Z_NULL;
  76583. s->w_bits = windowBits;
  76584. s->w_size = 1 << s->w_bits;
  76585. s->w_mask = s->w_size - 1;
  76586. s->hash_bits = memLevel + 7;
  76587. s->hash_size = 1 << s->hash_bits;
  76588. s->hash_mask = s->hash_size - 1;
  76589. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76590. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76591. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76592. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76593. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76594. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76595. s->pending_buf = (uchf *) overlay;
  76596. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76597. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76598. s->pending_buf == Z_NULL) {
  76599. s->status = FINISH_STATE;
  76600. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76601. deflateEnd (strm);
  76602. return Z_MEM_ERROR;
  76603. }
  76604. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76605. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76606. s->level = level;
  76607. s->strategy = strategy;
  76608. s->method = (Byte)method;
  76609. return deflateReset(strm);
  76610. }
  76611. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76612. {
  76613. deflate_state *s;
  76614. uInt length = dictLength;
  76615. uInt n;
  76616. IPos hash_head = 0;
  76617. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76618. strm->state->wrap == 2 ||
  76619. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76620. return Z_STREAM_ERROR;
  76621. s = strm->state;
  76622. if (s->wrap)
  76623. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76624. if (length < MIN_MATCH) return Z_OK;
  76625. if (length > MAX_DIST(s)) {
  76626. length = MAX_DIST(s);
  76627. dictionary += dictLength - length; /* use the tail of the dictionary */
  76628. }
  76629. zmemcpy(s->window, dictionary, length);
  76630. s->strstart = length;
  76631. s->block_start = (long)length;
  76632. s->ins_h = s->window[0];
  76633. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76634. for (n = 0; n <= length - MIN_MATCH; n++) {
  76635. INSERT_STRING(s, n, hash_head);
  76636. }
  76637. if (hash_head) hash_head = 0; /* to make compiler happy */
  76638. return Z_OK;
  76639. }
  76640. int ZEXPORT deflateReset (z_streamp strm)
  76641. {
  76642. deflate_state *s;
  76643. if (strm == Z_NULL || strm->state == Z_NULL ||
  76644. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76645. return Z_STREAM_ERROR;
  76646. }
  76647. strm->total_in = strm->total_out = 0;
  76648. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76649. strm->data_type = Z_UNKNOWN;
  76650. s = (deflate_state *)strm->state;
  76651. s->pending = 0;
  76652. s->pending_out = s->pending_buf;
  76653. if (s->wrap < 0) {
  76654. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76655. }
  76656. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76657. strm->adler =
  76658. #ifdef GZIP
  76659. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76660. #endif
  76661. adler32(0L, Z_NULL, 0);
  76662. s->last_flush = Z_NO_FLUSH;
  76663. _tr_init(s);
  76664. lm_init(s);
  76665. return Z_OK;
  76666. }
  76667. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76668. {
  76669. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76670. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76671. strm->state->gzhead = head;
  76672. return Z_OK;
  76673. }
  76674. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76675. {
  76676. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76677. strm->state->bi_valid = bits;
  76678. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76679. return Z_OK;
  76680. }
  76681. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76682. {
  76683. deflate_state *s;
  76684. compress_func func;
  76685. int err = Z_OK;
  76686. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76687. s = strm->state;
  76688. #ifdef FASTEST
  76689. if (level != 0) level = 1;
  76690. #else
  76691. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76692. #endif
  76693. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76694. return Z_STREAM_ERROR;
  76695. }
  76696. func = configuration_table[s->level].func;
  76697. if (func != configuration_table[level].func && strm->total_in != 0) {
  76698. err = deflate(strm, Z_PARTIAL_FLUSH);
  76699. }
  76700. if (s->level != level) {
  76701. s->level = level;
  76702. s->max_lazy_match = configuration_table[level].max_lazy;
  76703. s->good_match = configuration_table[level].good_length;
  76704. s->nice_match = configuration_table[level].nice_length;
  76705. s->max_chain_length = configuration_table[level].max_chain;
  76706. }
  76707. s->strategy = strategy;
  76708. return err;
  76709. }
  76710. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76711. {
  76712. deflate_state *s;
  76713. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76714. s = strm->state;
  76715. s->good_match = good_length;
  76716. s->max_lazy_match = max_lazy;
  76717. s->nice_match = nice_length;
  76718. s->max_chain_length = max_chain;
  76719. return Z_OK;
  76720. }
  76721. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76722. {
  76723. deflate_state *s;
  76724. uLong destLen;
  76725. destLen = sourceLen +
  76726. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76727. if (strm == Z_NULL || strm->state == Z_NULL)
  76728. return destLen;
  76729. s = strm->state;
  76730. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76731. return destLen;
  76732. return compressBound(sourceLen);
  76733. }
  76734. local void putShortMSB (deflate_state *s, uInt b)
  76735. {
  76736. put_byte(s, (Byte)(b >> 8));
  76737. put_byte(s, (Byte)(b & 0xff));
  76738. }
  76739. local void flush_pending (z_streamp strm)
  76740. {
  76741. unsigned len = strm->state->pending;
  76742. if (len > strm->avail_out) len = strm->avail_out;
  76743. if (len == 0) return;
  76744. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76745. strm->next_out += len;
  76746. strm->state->pending_out += len;
  76747. strm->total_out += len;
  76748. strm->avail_out -= len;
  76749. strm->state->pending -= len;
  76750. if (strm->state->pending == 0) {
  76751. strm->state->pending_out = strm->state->pending_buf;
  76752. }
  76753. }
  76754. int ZEXPORT deflate (z_streamp strm, int flush)
  76755. {
  76756. int old_flush; /* value of flush param for previous deflate call */
  76757. deflate_state *s;
  76758. if (strm == Z_NULL || strm->state == Z_NULL ||
  76759. flush > Z_FINISH || flush < 0) {
  76760. return Z_STREAM_ERROR;
  76761. }
  76762. s = strm->state;
  76763. if (strm->next_out == Z_NULL ||
  76764. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76765. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76766. ERR_RETURN(strm, Z_STREAM_ERROR);
  76767. }
  76768. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76769. s->strm = strm; /* just in case */
  76770. old_flush = s->last_flush;
  76771. s->last_flush = flush;
  76772. if (s->status == INIT_STATE) {
  76773. #ifdef GZIP
  76774. if (s->wrap == 2) {
  76775. strm->adler = crc32(0L, Z_NULL, 0);
  76776. put_byte(s, 31);
  76777. put_byte(s, 139);
  76778. put_byte(s, 8);
  76779. if (s->gzhead == NULL) {
  76780. put_byte(s, 0);
  76781. put_byte(s, 0);
  76782. put_byte(s, 0);
  76783. put_byte(s, 0);
  76784. put_byte(s, 0);
  76785. put_byte(s, s->level == 9 ? 2 :
  76786. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76787. 4 : 0));
  76788. put_byte(s, OS_CODE);
  76789. s->status = BUSY_STATE;
  76790. }
  76791. else {
  76792. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76793. (s->gzhead->hcrc ? 2 : 0) +
  76794. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76795. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76796. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76797. );
  76798. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76799. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76800. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76801. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76802. put_byte(s, s->level == 9 ? 2 :
  76803. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76804. 4 : 0));
  76805. put_byte(s, s->gzhead->os & 0xff);
  76806. if (s->gzhead->extra != NULL) {
  76807. put_byte(s, s->gzhead->extra_len & 0xff);
  76808. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76809. }
  76810. if (s->gzhead->hcrc)
  76811. strm->adler = crc32(strm->adler, s->pending_buf,
  76812. s->pending);
  76813. s->gzindex = 0;
  76814. s->status = EXTRA_STATE;
  76815. }
  76816. }
  76817. else
  76818. #endif
  76819. {
  76820. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76821. uInt level_flags;
  76822. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76823. level_flags = 0;
  76824. else if (s->level < 6)
  76825. level_flags = 1;
  76826. else if (s->level == 6)
  76827. level_flags = 2;
  76828. else
  76829. level_flags = 3;
  76830. header |= (level_flags << 6);
  76831. if (s->strstart != 0) header |= PRESET_DICT;
  76832. header += 31 - (header % 31);
  76833. s->status = BUSY_STATE;
  76834. putShortMSB(s, header);
  76835. if (s->strstart != 0) {
  76836. putShortMSB(s, (uInt)(strm->adler >> 16));
  76837. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76838. }
  76839. strm->adler = adler32(0L, Z_NULL, 0);
  76840. }
  76841. }
  76842. #ifdef GZIP
  76843. if (s->status == EXTRA_STATE) {
  76844. if (s->gzhead->extra != NULL) {
  76845. uInt beg = s->pending; /* start of bytes to update crc */
  76846. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76847. if (s->pending == s->pending_buf_size) {
  76848. if (s->gzhead->hcrc && s->pending > beg)
  76849. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76850. s->pending - beg);
  76851. flush_pending(strm);
  76852. beg = s->pending;
  76853. if (s->pending == s->pending_buf_size)
  76854. break;
  76855. }
  76856. put_byte(s, s->gzhead->extra[s->gzindex]);
  76857. s->gzindex++;
  76858. }
  76859. if (s->gzhead->hcrc && s->pending > beg)
  76860. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76861. s->pending - beg);
  76862. if (s->gzindex == s->gzhead->extra_len) {
  76863. s->gzindex = 0;
  76864. s->status = NAME_STATE;
  76865. }
  76866. }
  76867. else
  76868. s->status = NAME_STATE;
  76869. }
  76870. if (s->status == NAME_STATE) {
  76871. if (s->gzhead->name != NULL) {
  76872. uInt beg = s->pending; /* start of bytes to update crc */
  76873. int val;
  76874. do {
  76875. if (s->pending == s->pending_buf_size) {
  76876. if (s->gzhead->hcrc && s->pending > beg)
  76877. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76878. s->pending - beg);
  76879. flush_pending(strm);
  76880. beg = s->pending;
  76881. if (s->pending == s->pending_buf_size) {
  76882. val = 1;
  76883. break;
  76884. }
  76885. }
  76886. val = s->gzhead->name[s->gzindex++];
  76887. put_byte(s, val);
  76888. } while (val != 0);
  76889. if (s->gzhead->hcrc && s->pending > beg)
  76890. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76891. s->pending - beg);
  76892. if (val == 0) {
  76893. s->gzindex = 0;
  76894. s->status = COMMENT_STATE;
  76895. }
  76896. }
  76897. else
  76898. s->status = COMMENT_STATE;
  76899. }
  76900. if (s->status == COMMENT_STATE) {
  76901. if (s->gzhead->comment != NULL) {
  76902. uInt beg = s->pending; /* start of bytes to update crc */
  76903. int val;
  76904. do {
  76905. if (s->pending == s->pending_buf_size) {
  76906. if (s->gzhead->hcrc && s->pending > beg)
  76907. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76908. s->pending - beg);
  76909. flush_pending(strm);
  76910. beg = s->pending;
  76911. if (s->pending == s->pending_buf_size) {
  76912. val = 1;
  76913. break;
  76914. }
  76915. }
  76916. val = s->gzhead->comment[s->gzindex++];
  76917. put_byte(s, val);
  76918. } while (val != 0);
  76919. if (s->gzhead->hcrc && s->pending > beg)
  76920. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76921. s->pending - beg);
  76922. if (val == 0)
  76923. s->status = HCRC_STATE;
  76924. }
  76925. else
  76926. s->status = HCRC_STATE;
  76927. }
  76928. if (s->status == HCRC_STATE) {
  76929. if (s->gzhead->hcrc) {
  76930. if (s->pending + 2 > s->pending_buf_size)
  76931. flush_pending(strm);
  76932. if (s->pending + 2 <= s->pending_buf_size) {
  76933. put_byte(s, (Byte)(strm->adler & 0xff));
  76934. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76935. strm->adler = crc32(0L, Z_NULL, 0);
  76936. s->status = BUSY_STATE;
  76937. }
  76938. }
  76939. else
  76940. s->status = BUSY_STATE;
  76941. }
  76942. #endif
  76943. if (s->pending != 0) {
  76944. flush_pending(strm);
  76945. if (strm->avail_out == 0) {
  76946. s->last_flush = -1;
  76947. return Z_OK;
  76948. }
  76949. } else if (strm->avail_in == 0 && flush <= old_flush &&
  76950. flush != Z_FINISH) {
  76951. ERR_RETURN(strm, Z_BUF_ERROR);
  76952. }
  76953. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  76954. ERR_RETURN(strm, Z_BUF_ERROR);
  76955. }
  76956. if (strm->avail_in != 0 || s->lookahead != 0 ||
  76957. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  76958. block_state bstate;
  76959. bstate = (*(configuration_table[s->level].func))(s, flush);
  76960. if (bstate == finish_started || bstate == finish_done) {
  76961. s->status = FINISH_STATE;
  76962. }
  76963. if (bstate == need_more || bstate == finish_started) {
  76964. if (strm->avail_out == 0) {
  76965. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  76966. }
  76967. return Z_OK;
  76968. }
  76969. if (bstate == block_done) {
  76970. if (flush == Z_PARTIAL_FLUSH) {
  76971. _tr_align(s);
  76972. } else { /* FULL_FLUSH or SYNC_FLUSH */
  76973. _tr_stored_block(s, (char*)0, 0L, 0);
  76974. if (flush == Z_FULL_FLUSH) {
  76975. CLEAR_HASH(s); /* forget history */
  76976. }
  76977. }
  76978. flush_pending(strm);
  76979. if (strm->avail_out == 0) {
  76980. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  76981. return Z_OK;
  76982. }
  76983. }
  76984. }
  76985. Assert(strm->avail_out > 0, "bug2");
  76986. if (flush != Z_FINISH) return Z_OK;
  76987. if (s->wrap <= 0) return Z_STREAM_END;
  76988. #ifdef GZIP
  76989. if (s->wrap == 2) {
  76990. put_byte(s, (Byte)(strm->adler & 0xff));
  76991. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76992. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  76993. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  76994. put_byte(s, (Byte)(strm->total_in & 0xff));
  76995. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  76996. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  76997. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  76998. }
  76999. else
  77000. #endif
  77001. {
  77002. putShortMSB(s, (uInt)(strm->adler >> 16));
  77003. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77004. }
  77005. flush_pending(strm);
  77006. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77007. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77008. }
  77009. int ZEXPORT deflateEnd (z_streamp strm)
  77010. {
  77011. int status;
  77012. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77013. status = strm->state->status;
  77014. if (status != INIT_STATE &&
  77015. status != EXTRA_STATE &&
  77016. status != NAME_STATE &&
  77017. status != COMMENT_STATE &&
  77018. status != HCRC_STATE &&
  77019. status != BUSY_STATE &&
  77020. status != FINISH_STATE) {
  77021. return Z_STREAM_ERROR;
  77022. }
  77023. TRY_FREE(strm, strm->state->pending_buf);
  77024. TRY_FREE(strm, strm->state->head);
  77025. TRY_FREE(strm, strm->state->prev);
  77026. TRY_FREE(strm, strm->state->window);
  77027. ZFREE(strm, strm->state);
  77028. strm->state = Z_NULL;
  77029. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77030. }
  77031. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77032. {
  77033. #ifdef MAXSEG_64K
  77034. return Z_STREAM_ERROR;
  77035. #else
  77036. deflate_state *ds;
  77037. deflate_state *ss;
  77038. ushf *overlay;
  77039. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77040. return Z_STREAM_ERROR;
  77041. }
  77042. ss = source->state;
  77043. zmemcpy(dest, source, sizeof(z_stream));
  77044. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77045. if (ds == Z_NULL) return Z_MEM_ERROR;
  77046. dest->state = (struct internal_state FAR *) ds;
  77047. zmemcpy(ds, ss, sizeof(deflate_state));
  77048. ds->strm = dest;
  77049. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77050. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77051. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77052. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77053. ds->pending_buf = (uchf *) overlay;
  77054. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77055. ds->pending_buf == Z_NULL) {
  77056. deflateEnd (dest);
  77057. return Z_MEM_ERROR;
  77058. }
  77059. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77060. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77061. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77062. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77063. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77064. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77065. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77066. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77067. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77068. ds->bl_desc.dyn_tree = ds->bl_tree;
  77069. return Z_OK;
  77070. #endif /* MAXSEG_64K */
  77071. }
  77072. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77073. {
  77074. unsigned len = strm->avail_in;
  77075. if (len > size) len = size;
  77076. if (len == 0) return 0;
  77077. strm->avail_in -= len;
  77078. if (strm->state->wrap == 1) {
  77079. strm->adler = adler32(strm->adler, strm->next_in, len);
  77080. }
  77081. #ifdef GZIP
  77082. else if (strm->state->wrap == 2) {
  77083. strm->adler = crc32(strm->adler, strm->next_in, len);
  77084. }
  77085. #endif
  77086. zmemcpy(buf, strm->next_in, len);
  77087. strm->next_in += len;
  77088. strm->total_in += len;
  77089. return (int)len;
  77090. }
  77091. local void lm_init (deflate_state *s)
  77092. {
  77093. s->window_size = (ulg)2L*s->w_size;
  77094. CLEAR_HASH(s);
  77095. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77096. s->good_match = configuration_table[s->level].good_length;
  77097. s->nice_match = configuration_table[s->level].nice_length;
  77098. s->max_chain_length = configuration_table[s->level].max_chain;
  77099. s->strstart = 0;
  77100. s->block_start = 0L;
  77101. s->lookahead = 0;
  77102. s->match_length = s->prev_length = MIN_MATCH-1;
  77103. s->match_available = 0;
  77104. s->ins_h = 0;
  77105. #ifndef FASTEST
  77106. #ifdef ASMV
  77107. match_init(); /* initialize the asm code */
  77108. #endif
  77109. #endif
  77110. }
  77111. #ifndef FASTEST
  77112. #ifndef ASMV
  77113. local uInt longest_match(deflate_state *s, IPos cur_match)
  77114. {
  77115. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77116. register Bytef *scan = s->window + s->strstart; /* current string */
  77117. register Bytef *match; /* matched string */
  77118. register int len; /* length of current match */
  77119. int best_len = s->prev_length; /* best match length so far */
  77120. int nice_match = s->nice_match; /* stop if match long enough */
  77121. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77122. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77123. Posf *prev = s->prev;
  77124. uInt wmask = s->w_mask;
  77125. #ifdef UNALIGNED_OK
  77126. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77127. register ush scan_start = *(ushf*)scan;
  77128. register ush scan_end = *(ushf*)(scan+best_len-1);
  77129. #else
  77130. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77131. register Byte scan_end1 = scan[best_len-1];
  77132. register Byte scan_end = scan[best_len];
  77133. #endif
  77134. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77135. if (s->prev_length >= s->good_match) {
  77136. chain_length >>= 2;
  77137. }
  77138. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77139. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77140. do {
  77141. Assert(cur_match < s->strstart, "no future");
  77142. match = s->window + cur_match;
  77143. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77144. if (*(ushf*)(match+best_len-1) != scan_end ||
  77145. *(ushf*)match != scan_start) continue;
  77146. Assert(scan[2] == match[2], "scan[2]?");
  77147. scan++, match++;
  77148. do {
  77149. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77150. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77151. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77152. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77153. scan < strend);
  77154. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77155. if (*scan == *match) scan++;
  77156. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77157. scan = strend - (MAX_MATCH-1);
  77158. #else /* UNALIGNED_OK */
  77159. if (match[best_len] != scan_end ||
  77160. match[best_len-1] != scan_end1 ||
  77161. *match != *scan ||
  77162. *++match != scan[1]) continue;
  77163. scan += 2, match++;
  77164. Assert(*scan == *match, "match[2]?");
  77165. do {
  77166. } while (*++scan == *++match && *++scan == *++match &&
  77167. *++scan == *++match && *++scan == *++match &&
  77168. *++scan == *++match && *++scan == *++match &&
  77169. *++scan == *++match && *++scan == *++match &&
  77170. scan < strend);
  77171. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77172. len = MAX_MATCH - (int)(strend - scan);
  77173. scan = strend - MAX_MATCH;
  77174. #endif /* UNALIGNED_OK */
  77175. if (len > best_len) {
  77176. s->match_start = cur_match;
  77177. best_len = len;
  77178. if (len >= nice_match) break;
  77179. #ifdef UNALIGNED_OK
  77180. scan_end = *(ushf*)(scan+best_len-1);
  77181. #else
  77182. scan_end1 = scan[best_len-1];
  77183. scan_end = scan[best_len];
  77184. #endif
  77185. }
  77186. } while ((cur_match = prev[cur_match & wmask]) > limit
  77187. && --chain_length != 0);
  77188. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77189. return s->lookahead;
  77190. }
  77191. #endif /* ASMV */
  77192. #endif /* FASTEST */
  77193. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77194. {
  77195. register Bytef *scan = s->window + s->strstart; /* current string */
  77196. register Bytef *match; /* matched string */
  77197. register int len; /* length of current match */
  77198. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77199. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77200. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77201. Assert(cur_match < s->strstart, "no future");
  77202. match = s->window + cur_match;
  77203. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77204. scan += 2, match += 2;
  77205. Assert(*scan == *match, "match[2]?");
  77206. do {
  77207. } while (*++scan == *++match && *++scan == *++match &&
  77208. *++scan == *++match && *++scan == *++match &&
  77209. *++scan == *++match && *++scan == *++match &&
  77210. *++scan == *++match && *++scan == *++match &&
  77211. scan < strend);
  77212. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77213. len = MAX_MATCH - (int)(strend - scan);
  77214. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77215. s->match_start = cur_match;
  77216. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77217. }
  77218. #ifdef DEBUG
  77219. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77220. {
  77221. if (zmemcmp(s->window + match,
  77222. s->window + start, length) != EQUAL) {
  77223. fprintf(stderr, " start %u, match %u, length %d\n",
  77224. start, match, length);
  77225. do {
  77226. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77227. } while (--length != 0);
  77228. z_error("invalid match");
  77229. }
  77230. if (z_verbose > 1) {
  77231. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77232. do { putc(s->window[start++], stderr); } while (--length != 0);
  77233. }
  77234. }
  77235. #else
  77236. # define check_match(s, start, match, length)
  77237. #endif /* DEBUG */
  77238. local void fill_window (deflate_state *s)
  77239. {
  77240. register unsigned n, m;
  77241. register Posf *p;
  77242. unsigned more; /* Amount of free space at the end of the window. */
  77243. uInt wsize = s->w_size;
  77244. do {
  77245. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77246. if (sizeof(int) <= 2) {
  77247. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77248. more = wsize;
  77249. } else if (more == (unsigned)(-1)) {
  77250. more--;
  77251. }
  77252. }
  77253. if (s->strstart >= wsize+MAX_DIST(s)) {
  77254. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77255. s->match_start -= wsize;
  77256. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77257. s->block_start -= (long) wsize;
  77258. n = s->hash_size;
  77259. p = &s->head[n];
  77260. do {
  77261. m = *--p;
  77262. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77263. } while (--n);
  77264. n = wsize;
  77265. #ifndef FASTEST
  77266. p = &s->prev[n];
  77267. do {
  77268. m = *--p;
  77269. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77270. } while (--n);
  77271. #endif
  77272. more += wsize;
  77273. }
  77274. if (s->strm->avail_in == 0) return;
  77275. Assert(more >= 2, "more < 2");
  77276. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77277. s->lookahead += n;
  77278. if (s->lookahead >= MIN_MATCH) {
  77279. s->ins_h = s->window[s->strstart];
  77280. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77281. #if MIN_MATCH != 3
  77282. Call UPDATE_HASH() MIN_MATCH-3 more times
  77283. #endif
  77284. }
  77285. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77286. }
  77287. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77288. _tr_flush_block(s, (s->block_start >= 0L ? \
  77289. (charf *)&s->window[(unsigned)s->block_start] : \
  77290. (charf *)Z_NULL), \
  77291. (ulg)((long)s->strstart - s->block_start), \
  77292. (eof)); \
  77293. s->block_start = s->strstart; \
  77294. flush_pending(s->strm); \
  77295. Tracev((stderr,"[FLUSH]")); \
  77296. }
  77297. #define FLUSH_BLOCK(s, eof) { \
  77298. FLUSH_BLOCK_ONLY(s, eof); \
  77299. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77300. }
  77301. local block_state deflate_stored(deflate_state *s, int flush)
  77302. {
  77303. ulg max_block_size = 0xffff;
  77304. ulg max_start;
  77305. if (max_block_size > s->pending_buf_size - 5) {
  77306. max_block_size = s->pending_buf_size - 5;
  77307. }
  77308. for (;;) {
  77309. if (s->lookahead <= 1) {
  77310. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77311. s->block_start >= (long)s->w_size, "slide too late");
  77312. fill_window(s);
  77313. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77314. if (s->lookahead == 0) break; /* flush the current block */
  77315. }
  77316. Assert(s->block_start >= 0L, "block gone");
  77317. s->strstart += s->lookahead;
  77318. s->lookahead = 0;
  77319. max_start = s->block_start + max_block_size;
  77320. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77321. s->lookahead = (uInt)(s->strstart - max_start);
  77322. s->strstart = (uInt)max_start;
  77323. FLUSH_BLOCK(s, 0);
  77324. }
  77325. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77326. FLUSH_BLOCK(s, 0);
  77327. }
  77328. }
  77329. FLUSH_BLOCK(s, flush == Z_FINISH);
  77330. return flush == Z_FINISH ? finish_done : block_done;
  77331. }
  77332. local block_state deflate_fast(deflate_state *s, int flush)
  77333. {
  77334. IPos hash_head = NIL; /* head of the hash chain */
  77335. int bflush; /* set if current block must be flushed */
  77336. for (;;) {
  77337. if (s->lookahead < MIN_LOOKAHEAD) {
  77338. fill_window(s);
  77339. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77340. return need_more;
  77341. }
  77342. if (s->lookahead == 0) break; /* flush the current block */
  77343. }
  77344. if (s->lookahead >= MIN_MATCH) {
  77345. INSERT_STRING(s, s->strstart, hash_head);
  77346. }
  77347. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77348. #ifdef FASTEST
  77349. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77350. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77351. s->match_length = longest_match_fast (s, hash_head);
  77352. }
  77353. #else
  77354. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77355. s->match_length = longest_match (s, hash_head);
  77356. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77357. s->match_length = longest_match_fast (s, hash_head);
  77358. }
  77359. #endif
  77360. }
  77361. if (s->match_length >= MIN_MATCH) {
  77362. check_match(s, s->strstart, s->match_start, s->match_length);
  77363. _tr_tally_dist(s, s->strstart - s->match_start,
  77364. s->match_length - MIN_MATCH, bflush);
  77365. s->lookahead -= s->match_length;
  77366. #ifndef FASTEST
  77367. if (s->match_length <= s->max_insert_length &&
  77368. s->lookahead >= MIN_MATCH) {
  77369. s->match_length--; /* string at strstart already in table */
  77370. do {
  77371. s->strstart++;
  77372. INSERT_STRING(s, s->strstart, hash_head);
  77373. } while (--s->match_length != 0);
  77374. s->strstart++;
  77375. } else
  77376. #endif
  77377. {
  77378. s->strstart += s->match_length;
  77379. s->match_length = 0;
  77380. s->ins_h = s->window[s->strstart];
  77381. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77382. #if MIN_MATCH != 3
  77383. Call UPDATE_HASH() MIN_MATCH-3 more times
  77384. #endif
  77385. }
  77386. } else {
  77387. Tracevv((stderr,"%c", s->window[s->strstart]));
  77388. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77389. s->lookahead--;
  77390. s->strstart++;
  77391. }
  77392. if (bflush) FLUSH_BLOCK(s, 0);
  77393. }
  77394. FLUSH_BLOCK(s, flush == Z_FINISH);
  77395. return flush == Z_FINISH ? finish_done : block_done;
  77396. }
  77397. #ifndef FASTEST
  77398. local block_state deflate_slow(deflate_state *s, int flush)
  77399. {
  77400. IPos hash_head = NIL; /* head of hash chain */
  77401. int bflush; /* set if current block must be flushed */
  77402. for (;;) {
  77403. if (s->lookahead < MIN_LOOKAHEAD) {
  77404. fill_window(s);
  77405. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77406. return need_more;
  77407. }
  77408. if (s->lookahead == 0) break; /* flush the current block */
  77409. }
  77410. if (s->lookahead >= MIN_MATCH) {
  77411. INSERT_STRING(s, s->strstart, hash_head);
  77412. }
  77413. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77414. s->match_length = MIN_MATCH-1;
  77415. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77416. s->strstart - hash_head <= MAX_DIST(s)) {
  77417. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77418. s->match_length = longest_match (s, hash_head);
  77419. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77420. s->match_length = longest_match_fast (s, hash_head);
  77421. }
  77422. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77423. #if TOO_FAR <= 32767
  77424. || (s->match_length == MIN_MATCH &&
  77425. s->strstart - s->match_start > TOO_FAR)
  77426. #endif
  77427. )) {
  77428. s->match_length = MIN_MATCH-1;
  77429. }
  77430. }
  77431. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77432. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77433. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77434. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77435. s->prev_length - MIN_MATCH, bflush);
  77436. s->lookahead -= s->prev_length-1;
  77437. s->prev_length -= 2;
  77438. do {
  77439. if (++s->strstart <= max_insert) {
  77440. INSERT_STRING(s, s->strstart, hash_head);
  77441. }
  77442. } while (--s->prev_length != 0);
  77443. s->match_available = 0;
  77444. s->match_length = MIN_MATCH-1;
  77445. s->strstart++;
  77446. if (bflush) FLUSH_BLOCK(s, 0);
  77447. } else if (s->match_available) {
  77448. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77449. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77450. if (bflush) {
  77451. FLUSH_BLOCK_ONLY(s, 0);
  77452. }
  77453. s->strstart++;
  77454. s->lookahead--;
  77455. if (s->strm->avail_out == 0) return need_more;
  77456. } else {
  77457. s->match_available = 1;
  77458. s->strstart++;
  77459. s->lookahead--;
  77460. }
  77461. }
  77462. Assert (flush != Z_NO_FLUSH, "no flush?");
  77463. if (s->match_available) {
  77464. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77465. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77466. s->match_available = 0;
  77467. }
  77468. FLUSH_BLOCK(s, flush == Z_FINISH);
  77469. return flush == Z_FINISH ? finish_done : block_done;
  77470. }
  77471. #endif /* FASTEST */
  77472. #if 0
  77473. local block_state deflate_rle(s, flush)
  77474. deflate_state *s;
  77475. int flush;
  77476. {
  77477. int bflush; /* set if current block must be flushed */
  77478. uInt run; /* length of run */
  77479. uInt max; /* maximum length of run */
  77480. uInt prev; /* byte at distance one to match */
  77481. Bytef *scan; /* scan for end of run */
  77482. for (;;) {
  77483. if (s->lookahead < MAX_MATCH) {
  77484. fill_window(s);
  77485. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77486. return need_more;
  77487. }
  77488. if (s->lookahead == 0) break; /* flush the current block */
  77489. }
  77490. run = 0;
  77491. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77492. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77493. scan = s->window + s->strstart - 1;
  77494. prev = *scan++;
  77495. do {
  77496. if (*scan++ != prev)
  77497. break;
  77498. } while (++run < max);
  77499. }
  77500. if (run >= MIN_MATCH) {
  77501. check_match(s, s->strstart, s->strstart - 1, run);
  77502. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77503. s->lookahead -= run;
  77504. s->strstart += run;
  77505. } else {
  77506. Tracevv((stderr,"%c", s->window[s->strstart]));
  77507. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77508. s->lookahead--;
  77509. s->strstart++;
  77510. }
  77511. if (bflush) FLUSH_BLOCK(s, 0);
  77512. }
  77513. FLUSH_BLOCK(s, flush == Z_FINISH);
  77514. return flush == Z_FINISH ? finish_done : block_done;
  77515. }
  77516. #endif
  77517. /*** End of inlined file: deflate.c ***/
  77518. /*** Start of inlined file: inffast.c ***/
  77519. /*** Start of inlined file: inftrees.h ***/
  77520. #ifndef _INFTREES_H_
  77521. #define _INFTREES_H_
  77522. typedef struct {
  77523. unsigned char op; /* operation, extra bits, table bits */
  77524. unsigned char bits; /* bits in this part of the code */
  77525. unsigned short val; /* offset in table or code value */
  77526. } code;
  77527. #define ENOUGH 2048
  77528. #define MAXD 592
  77529. typedef enum {
  77530. CODES,
  77531. LENS,
  77532. DISTS
  77533. } codetype;
  77534. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77535. unsigned codes, code FAR * FAR *table,
  77536. unsigned FAR *bits, unsigned short FAR *work));
  77537. #endif
  77538. /*** End of inlined file: inftrees.h ***/
  77539. /*** Start of inlined file: inflate.h ***/
  77540. #ifndef _INFLATE_H_
  77541. #define _INFLATE_H_
  77542. #ifndef NO_GZIP
  77543. # define GUNZIP
  77544. #endif
  77545. typedef enum {
  77546. HEAD, /* i: waiting for magic header */
  77547. FLAGS, /* i: waiting for method and flags (gzip) */
  77548. TIME, /* i: waiting for modification time (gzip) */
  77549. OS, /* i: waiting for extra flags and operating system (gzip) */
  77550. EXLEN, /* i: waiting for extra length (gzip) */
  77551. EXTRA, /* i: waiting for extra bytes (gzip) */
  77552. NAME, /* i: waiting for end of file name (gzip) */
  77553. COMMENT, /* i: waiting for end of comment (gzip) */
  77554. HCRC, /* i: waiting for header crc (gzip) */
  77555. DICTID, /* i: waiting for dictionary check value */
  77556. DICT, /* waiting for inflateSetDictionary() call */
  77557. TYPE, /* i: waiting for type bits, including last-flag bit */
  77558. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77559. STORED, /* i: waiting for stored size (length and complement) */
  77560. COPY, /* i/o: waiting for input or output to copy stored block */
  77561. TABLE, /* i: waiting for dynamic block table lengths */
  77562. LENLENS, /* i: waiting for code length code lengths */
  77563. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77564. LEN, /* i: waiting for length/lit code */
  77565. LENEXT, /* i: waiting for length extra bits */
  77566. DIST, /* i: waiting for distance code */
  77567. DISTEXT, /* i: waiting for distance extra bits */
  77568. MATCH, /* o: waiting for output space to copy string */
  77569. LIT, /* o: waiting for output space to write literal */
  77570. CHECK, /* i: waiting for 32-bit check value */
  77571. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77572. DONE, /* finished check, done -- remain here until reset */
  77573. BAD, /* got a data error -- remain here until reset */
  77574. MEM, /* got an inflate() memory error -- remain here until reset */
  77575. SYNC /* looking for synchronization bytes to restart inflate() */
  77576. } inflate_mode;
  77577. struct inflate_state {
  77578. inflate_mode mode; /* current inflate mode */
  77579. int last; /* true if processing last block */
  77580. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77581. int havedict; /* true if dictionary provided */
  77582. int flags; /* gzip header method and flags (0 if zlib) */
  77583. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77584. unsigned long check; /* protected copy of check value */
  77585. unsigned long total; /* protected copy of output count */
  77586. gz_headerp head; /* where to save gzip header information */
  77587. unsigned wbits; /* log base 2 of requested window size */
  77588. unsigned wsize; /* window size or zero if not using window */
  77589. unsigned whave; /* valid bytes in the window */
  77590. unsigned write; /* window write index */
  77591. unsigned char FAR *window; /* allocated sliding window, if needed */
  77592. unsigned long hold; /* input bit accumulator */
  77593. unsigned bits; /* number of bits in "in" */
  77594. unsigned length; /* literal or length of data to copy */
  77595. unsigned offset; /* distance back to copy string from */
  77596. unsigned extra; /* extra bits needed */
  77597. code const FAR *lencode; /* starting table for length/literal codes */
  77598. code const FAR *distcode; /* starting table for distance codes */
  77599. unsigned lenbits; /* index bits for lencode */
  77600. unsigned distbits; /* index bits for distcode */
  77601. unsigned ncode; /* number of code length code lengths */
  77602. unsigned nlen; /* number of length code lengths */
  77603. unsigned ndist; /* number of distance code lengths */
  77604. unsigned have; /* number of code lengths in lens[] */
  77605. code FAR *next; /* next available space in codes[] */
  77606. unsigned short lens[320]; /* temporary storage for code lengths */
  77607. unsigned short work[288]; /* work area for code table building */
  77608. code codes[ENOUGH]; /* space for code tables */
  77609. };
  77610. #endif
  77611. /*** End of inlined file: inflate.h ***/
  77612. /*** Start of inlined file: inffast.h ***/
  77613. void inflate_fast OF((z_streamp strm, unsigned start));
  77614. /*** End of inlined file: inffast.h ***/
  77615. #ifndef ASMINF
  77616. #ifdef POSTINC
  77617. # define OFF 0
  77618. # define PUP(a) *(a)++
  77619. #else
  77620. # define OFF 1
  77621. # define PUP(a) *++(a)
  77622. #endif
  77623. void inflate_fast (z_streamp strm, unsigned start)
  77624. {
  77625. struct inflate_state FAR *state;
  77626. unsigned char FAR *in; /* local strm->next_in */
  77627. unsigned char FAR *last; /* while in < last, enough input available */
  77628. unsigned char FAR *out; /* local strm->next_out */
  77629. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77630. unsigned char FAR *end; /* while out < end, enough space available */
  77631. #ifdef INFLATE_STRICT
  77632. unsigned dmax; /* maximum distance from zlib header */
  77633. #endif
  77634. unsigned wsize; /* window size or zero if not using window */
  77635. unsigned whave; /* valid bytes in the window */
  77636. unsigned write; /* window write index */
  77637. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77638. unsigned long hold; /* local strm->hold */
  77639. unsigned bits; /* local strm->bits */
  77640. code const FAR *lcode; /* local strm->lencode */
  77641. code const FAR *dcode; /* local strm->distcode */
  77642. unsigned lmask; /* mask for first level of length codes */
  77643. unsigned dmask; /* mask for first level of distance codes */
  77644. code thisx; /* retrieved table entry */
  77645. unsigned op; /* code bits, operation, extra bits, or */
  77646. unsigned len; /* match length, unused bytes */
  77647. unsigned dist; /* match distance */
  77648. unsigned char FAR *from; /* where to copy match from */
  77649. state = (struct inflate_state FAR *)strm->state;
  77650. in = strm->next_in - OFF;
  77651. last = in + (strm->avail_in - 5);
  77652. out = strm->next_out - OFF;
  77653. beg = out - (start - strm->avail_out);
  77654. end = out + (strm->avail_out - 257);
  77655. #ifdef INFLATE_STRICT
  77656. dmax = state->dmax;
  77657. #endif
  77658. wsize = state->wsize;
  77659. whave = state->whave;
  77660. write = state->write;
  77661. window = state->window;
  77662. hold = state->hold;
  77663. bits = state->bits;
  77664. lcode = state->lencode;
  77665. dcode = state->distcode;
  77666. lmask = (1U << state->lenbits) - 1;
  77667. dmask = (1U << state->distbits) - 1;
  77668. do {
  77669. if (bits < 15) {
  77670. hold += (unsigned long)(PUP(in)) << bits;
  77671. bits += 8;
  77672. hold += (unsigned long)(PUP(in)) << bits;
  77673. bits += 8;
  77674. }
  77675. thisx = lcode[hold & lmask];
  77676. dolen:
  77677. op = (unsigned)(thisx.bits);
  77678. hold >>= op;
  77679. bits -= op;
  77680. op = (unsigned)(thisx.op);
  77681. if (op == 0) { /* literal */
  77682. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77683. "inflate: literal '%c'\n" :
  77684. "inflate: literal 0x%02x\n", thisx.val));
  77685. PUP(out) = (unsigned char)(thisx.val);
  77686. }
  77687. else if (op & 16) { /* length base */
  77688. len = (unsigned)(thisx.val);
  77689. op &= 15; /* number of extra bits */
  77690. if (op) {
  77691. if (bits < op) {
  77692. hold += (unsigned long)(PUP(in)) << bits;
  77693. bits += 8;
  77694. }
  77695. len += (unsigned)hold & ((1U << op) - 1);
  77696. hold >>= op;
  77697. bits -= op;
  77698. }
  77699. Tracevv((stderr, "inflate: length %u\n", len));
  77700. if (bits < 15) {
  77701. hold += (unsigned long)(PUP(in)) << bits;
  77702. bits += 8;
  77703. hold += (unsigned long)(PUP(in)) << bits;
  77704. bits += 8;
  77705. }
  77706. thisx = dcode[hold & dmask];
  77707. dodist:
  77708. op = (unsigned)(thisx.bits);
  77709. hold >>= op;
  77710. bits -= op;
  77711. op = (unsigned)(thisx.op);
  77712. if (op & 16) { /* distance base */
  77713. dist = (unsigned)(thisx.val);
  77714. op &= 15; /* number of extra bits */
  77715. if (bits < op) {
  77716. hold += (unsigned long)(PUP(in)) << bits;
  77717. bits += 8;
  77718. if (bits < op) {
  77719. hold += (unsigned long)(PUP(in)) << bits;
  77720. bits += 8;
  77721. }
  77722. }
  77723. dist += (unsigned)hold & ((1U << op) - 1);
  77724. #ifdef INFLATE_STRICT
  77725. if (dist > dmax) {
  77726. strm->msg = (char *)"invalid distance too far back";
  77727. state->mode = BAD;
  77728. break;
  77729. }
  77730. #endif
  77731. hold >>= op;
  77732. bits -= op;
  77733. Tracevv((stderr, "inflate: distance %u\n", dist));
  77734. op = (unsigned)(out - beg); /* max distance in output */
  77735. if (dist > op) { /* see if copy from window */
  77736. op = dist - op; /* distance back in window */
  77737. if (op > whave) {
  77738. strm->msg = (char *)"invalid distance too far back";
  77739. state->mode = BAD;
  77740. break;
  77741. }
  77742. from = window - OFF;
  77743. if (write == 0) { /* very common case */
  77744. from += wsize - op;
  77745. if (op < len) { /* some from window */
  77746. len -= op;
  77747. do {
  77748. PUP(out) = PUP(from);
  77749. } while (--op);
  77750. from = out - dist; /* rest from output */
  77751. }
  77752. }
  77753. else if (write < op) { /* wrap around window */
  77754. from += wsize + write - op;
  77755. op -= write;
  77756. if (op < len) { /* some from end of window */
  77757. len -= op;
  77758. do {
  77759. PUP(out) = PUP(from);
  77760. } while (--op);
  77761. from = window - OFF;
  77762. if (write < len) { /* some from start of window */
  77763. op = write;
  77764. len -= op;
  77765. do {
  77766. PUP(out) = PUP(from);
  77767. } while (--op);
  77768. from = out - dist; /* rest from output */
  77769. }
  77770. }
  77771. }
  77772. else { /* contiguous in window */
  77773. from += write - op;
  77774. if (op < len) { /* some from window */
  77775. len -= op;
  77776. do {
  77777. PUP(out) = PUP(from);
  77778. } while (--op);
  77779. from = out - dist; /* rest from output */
  77780. }
  77781. }
  77782. while (len > 2) {
  77783. PUP(out) = PUP(from);
  77784. PUP(out) = PUP(from);
  77785. PUP(out) = PUP(from);
  77786. len -= 3;
  77787. }
  77788. if (len) {
  77789. PUP(out) = PUP(from);
  77790. if (len > 1)
  77791. PUP(out) = PUP(from);
  77792. }
  77793. }
  77794. else {
  77795. from = out - dist; /* copy direct from output */
  77796. do { /* minimum length is three */
  77797. PUP(out) = PUP(from);
  77798. PUP(out) = PUP(from);
  77799. PUP(out) = PUP(from);
  77800. len -= 3;
  77801. } while (len > 2);
  77802. if (len) {
  77803. PUP(out) = PUP(from);
  77804. if (len > 1)
  77805. PUP(out) = PUP(from);
  77806. }
  77807. }
  77808. }
  77809. else if ((op & 64) == 0) { /* 2nd level distance code */
  77810. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77811. goto dodist;
  77812. }
  77813. else {
  77814. strm->msg = (char *)"invalid distance code";
  77815. state->mode = BAD;
  77816. break;
  77817. }
  77818. }
  77819. else if ((op & 64) == 0) { /* 2nd level length code */
  77820. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77821. goto dolen;
  77822. }
  77823. else if (op & 32) { /* end-of-block */
  77824. Tracevv((stderr, "inflate: end of block\n"));
  77825. state->mode = TYPE;
  77826. break;
  77827. }
  77828. else {
  77829. strm->msg = (char *)"invalid literal/length code";
  77830. state->mode = BAD;
  77831. break;
  77832. }
  77833. } while (in < last && out < end);
  77834. len = bits >> 3;
  77835. in -= len;
  77836. bits -= len << 3;
  77837. hold &= (1U << bits) - 1;
  77838. strm->next_in = in + OFF;
  77839. strm->next_out = out + OFF;
  77840. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77841. strm->avail_out = (unsigned)(out < end ?
  77842. 257 + (end - out) : 257 - (out - end));
  77843. state->hold = hold;
  77844. state->bits = bits;
  77845. return;
  77846. }
  77847. #endif /* !ASMINF */
  77848. /*** End of inlined file: inffast.c ***/
  77849. #undef PULLBYTE
  77850. #undef LOAD
  77851. #undef RESTORE
  77852. #undef INITBITS
  77853. #undef NEEDBITS
  77854. #undef DROPBITS
  77855. #undef BYTEBITS
  77856. /*** Start of inlined file: inflate.c ***/
  77857. /*** Start of inlined file: inffast.h ***/
  77858. void inflate_fast OF((z_streamp strm, unsigned start));
  77859. /*** End of inlined file: inffast.h ***/
  77860. #ifdef MAKEFIXED
  77861. # ifndef BUILDFIXED
  77862. # define BUILDFIXED
  77863. # endif
  77864. #endif
  77865. local void fixedtables OF((struct inflate_state FAR *state));
  77866. local int updatewindow OF((z_streamp strm, unsigned out));
  77867. #ifdef BUILDFIXED
  77868. void makefixed OF((void));
  77869. #endif
  77870. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77871. unsigned len));
  77872. int ZEXPORT inflateReset (z_streamp strm)
  77873. {
  77874. struct inflate_state FAR *state;
  77875. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77876. state = (struct inflate_state FAR *)strm->state;
  77877. strm->total_in = strm->total_out = state->total = 0;
  77878. strm->msg = Z_NULL;
  77879. strm->adler = 1; /* to support ill-conceived Java test suite */
  77880. state->mode = HEAD;
  77881. state->last = 0;
  77882. state->havedict = 0;
  77883. state->dmax = 32768U;
  77884. state->head = Z_NULL;
  77885. state->wsize = 0;
  77886. state->whave = 0;
  77887. state->write = 0;
  77888. state->hold = 0;
  77889. state->bits = 0;
  77890. state->lencode = state->distcode = state->next = state->codes;
  77891. Tracev((stderr, "inflate: reset\n"));
  77892. return Z_OK;
  77893. }
  77894. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77895. {
  77896. struct inflate_state FAR *state;
  77897. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77898. state = (struct inflate_state FAR *)strm->state;
  77899. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77900. value &= (1L << bits) - 1;
  77901. state->hold += value << state->bits;
  77902. state->bits += bits;
  77903. return Z_OK;
  77904. }
  77905. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77906. {
  77907. struct inflate_state FAR *state;
  77908. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77909. stream_size != (int)(sizeof(z_stream)))
  77910. return Z_VERSION_ERROR;
  77911. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77912. strm->msg = Z_NULL; /* in case we return an error */
  77913. if (strm->zalloc == (alloc_func)0) {
  77914. strm->zalloc = zcalloc;
  77915. strm->opaque = (voidpf)0;
  77916. }
  77917. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77918. state = (struct inflate_state FAR *)
  77919. ZALLOC(strm, 1, sizeof(struct inflate_state));
  77920. if (state == Z_NULL) return Z_MEM_ERROR;
  77921. Tracev((stderr, "inflate: allocated\n"));
  77922. strm->state = (struct internal_state FAR *)state;
  77923. if (windowBits < 0) {
  77924. state->wrap = 0;
  77925. windowBits = -windowBits;
  77926. }
  77927. else {
  77928. state->wrap = (windowBits >> 4) + 1;
  77929. #ifdef GUNZIP
  77930. if (windowBits < 48) windowBits &= 15;
  77931. #endif
  77932. }
  77933. if (windowBits < 8 || windowBits > 15) {
  77934. ZFREE(strm, state);
  77935. strm->state = Z_NULL;
  77936. return Z_STREAM_ERROR;
  77937. }
  77938. state->wbits = (unsigned)windowBits;
  77939. state->window = Z_NULL;
  77940. return inflateReset(strm);
  77941. }
  77942. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  77943. {
  77944. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  77945. }
  77946. local void fixedtables (struct inflate_state FAR *state)
  77947. {
  77948. #ifdef BUILDFIXED
  77949. static int virgin = 1;
  77950. static code *lenfix, *distfix;
  77951. static code fixed[544];
  77952. if (virgin) {
  77953. unsigned sym, bits;
  77954. static code *next;
  77955. sym = 0;
  77956. while (sym < 144) state->lens[sym++] = 8;
  77957. while (sym < 256) state->lens[sym++] = 9;
  77958. while (sym < 280) state->lens[sym++] = 7;
  77959. while (sym < 288) state->lens[sym++] = 8;
  77960. next = fixed;
  77961. lenfix = next;
  77962. bits = 9;
  77963. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  77964. sym = 0;
  77965. while (sym < 32) state->lens[sym++] = 5;
  77966. distfix = next;
  77967. bits = 5;
  77968. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  77969. virgin = 0;
  77970. }
  77971. #else /* !BUILDFIXED */
  77972. /*** Start of inlined file: inffixed.h ***/
  77973. static const code lenfix[512] = {
  77974. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  77975. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  77976. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  77977. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  77978. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  77979. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  77980. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  77981. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  77982. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  77983. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  77984. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  77985. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  77986. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  77987. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  77988. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  77989. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  77990. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  77991. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  77992. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  77993. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  77994. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  77995. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  77996. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  77997. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  77998. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  77999. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78000. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78001. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78002. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78003. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78004. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78005. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78006. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78007. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78008. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78009. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78010. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78011. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78012. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78013. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78014. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78015. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78016. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78017. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78018. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78019. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78020. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78021. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78022. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78023. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78024. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78025. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78026. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78027. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78028. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78029. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78030. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78031. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78032. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78033. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78034. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78035. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78036. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78037. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78038. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78039. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78040. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78041. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78042. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78043. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78044. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78045. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78046. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78047. {0,9,255}
  78048. };
  78049. static const code distfix[32] = {
  78050. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78051. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78052. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78053. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78054. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78055. {22,5,193},{64,5,0}
  78056. };
  78057. /*** End of inlined file: inffixed.h ***/
  78058. #endif /* BUILDFIXED */
  78059. state->lencode = lenfix;
  78060. state->lenbits = 9;
  78061. state->distcode = distfix;
  78062. state->distbits = 5;
  78063. }
  78064. #ifdef MAKEFIXED
  78065. #include <stdio.h>
  78066. void makefixed()
  78067. {
  78068. unsigned low, size;
  78069. struct inflate_state state;
  78070. fixedtables(&state);
  78071. puts(" /* inffixed.h -- table for decoding fixed codes");
  78072. puts(" * Generated automatically by makefixed().");
  78073. puts(" */");
  78074. puts("");
  78075. puts(" /* WARNING: this file should *not* be used by applications.");
  78076. puts(" It is part of the implementation of this library and is");
  78077. puts(" subject to change. Applications should only use zlib.h.");
  78078. puts(" */");
  78079. puts("");
  78080. size = 1U << 9;
  78081. printf(" static const code lenfix[%u] = {", size);
  78082. low = 0;
  78083. for (;;) {
  78084. if ((low % 7) == 0) printf("\n ");
  78085. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78086. state.lencode[low].val);
  78087. if (++low == size) break;
  78088. putchar(',');
  78089. }
  78090. puts("\n };");
  78091. size = 1U << 5;
  78092. printf("\n static const code distfix[%u] = {", size);
  78093. low = 0;
  78094. for (;;) {
  78095. if ((low % 6) == 0) printf("\n ");
  78096. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78097. state.distcode[low].val);
  78098. if (++low == size) break;
  78099. putchar(',');
  78100. }
  78101. puts("\n };");
  78102. }
  78103. #endif /* MAKEFIXED */
  78104. local int updatewindow (z_streamp strm, unsigned out)
  78105. {
  78106. struct inflate_state FAR *state;
  78107. unsigned copy, dist;
  78108. state = (struct inflate_state FAR *)strm->state;
  78109. if (state->window == Z_NULL) {
  78110. state->window = (unsigned char FAR *)
  78111. ZALLOC(strm, 1U << state->wbits,
  78112. sizeof(unsigned char));
  78113. if (state->window == Z_NULL) return 1;
  78114. }
  78115. if (state->wsize == 0) {
  78116. state->wsize = 1U << state->wbits;
  78117. state->write = 0;
  78118. state->whave = 0;
  78119. }
  78120. copy = out - strm->avail_out;
  78121. if (copy >= state->wsize) {
  78122. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78123. state->write = 0;
  78124. state->whave = state->wsize;
  78125. }
  78126. else {
  78127. dist = state->wsize - state->write;
  78128. if (dist > copy) dist = copy;
  78129. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78130. copy -= dist;
  78131. if (copy) {
  78132. zmemcpy(state->window, strm->next_out - copy, copy);
  78133. state->write = copy;
  78134. state->whave = state->wsize;
  78135. }
  78136. else {
  78137. state->write += dist;
  78138. if (state->write == state->wsize) state->write = 0;
  78139. if (state->whave < state->wsize) state->whave += dist;
  78140. }
  78141. }
  78142. return 0;
  78143. }
  78144. #ifdef GUNZIP
  78145. # define UPDATE(check, buf, len) \
  78146. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78147. #else
  78148. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78149. #endif
  78150. #ifdef GUNZIP
  78151. # define CRC2(check, word) \
  78152. do { \
  78153. hbuf[0] = (unsigned char)(word); \
  78154. hbuf[1] = (unsigned char)((word) >> 8); \
  78155. check = crc32(check, hbuf, 2); \
  78156. } while (0)
  78157. # define CRC4(check, word) \
  78158. do { \
  78159. hbuf[0] = (unsigned char)(word); \
  78160. hbuf[1] = (unsigned char)((word) >> 8); \
  78161. hbuf[2] = (unsigned char)((word) >> 16); \
  78162. hbuf[3] = (unsigned char)((word) >> 24); \
  78163. check = crc32(check, hbuf, 4); \
  78164. } while (0)
  78165. #endif
  78166. #define LOAD() \
  78167. do { \
  78168. put = strm->next_out; \
  78169. left = strm->avail_out; \
  78170. next = strm->next_in; \
  78171. have = strm->avail_in; \
  78172. hold = state->hold; \
  78173. bits = state->bits; \
  78174. } while (0)
  78175. #define RESTORE() \
  78176. do { \
  78177. strm->next_out = put; \
  78178. strm->avail_out = left; \
  78179. strm->next_in = next; \
  78180. strm->avail_in = have; \
  78181. state->hold = hold; \
  78182. state->bits = bits; \
  78183. } while (0)
  78184. #define INITBITS() \
  78185. do { \
  78186. hold = 0; \
  78187. bits = 0; \
  78188. } while (0)
  78189. #define PULLBYTE() \
  78190. do { \
  78191. if (have == 0) goto inf_leave; \
  78192. have--; \
  78193. hold += (unsigned long)(*next++) << bits; \
  78194. bits += 8; \
  78195. } while (0)
  78196. #define NEEDBITS(n) \
  78197. do { \
  78198. while (bits < (unsigned)(n)) \
  78199. PULLBYTE(); \
  78200. } while (0)
  78201. #define BITS(n) \
  78202. ((unsigned)hold & ((1U << (n)) - 1))
  78203. #define DROPBITS(n) \
  78204. do { \
  78205. hold >>= (n); \
  78206. bits -= (unsigned)(n); \
  78207. } while (0)
  78208. #define BYTEBITS() \
  78209. do { \
  78210. hold >>= bits & 7; \
  78211. bits -= bits & 7; \
  78212. } while (0)
  78213. #define REVERSE(q) \
  78214. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78215. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78216. int ZEXPORT inflate (z_streamp strm, int flush)
  78217. {
  78218. struct inflate_state FAR *state;
  78219. unsigned char FAR *next; /* next input */
  78220. unsigned char FAR *put; /* next output */
  78221. unsigned have, left; /* available input and output */
  78222. unsigned long hold; /* bit buffer */
  78223. unsigned bits; /* bits in bit buffer */
  78224. unsigned in, out; /* save starting available input and output */
  78225. unsigned copy; /* number of stored or match bytes to copy */
  78226. unsigned char FAR *from; /* where to copy match bytes from */
  78227. code thisx; /* current decoding table entry */
  78228. code last; /* parent table entry */
  78229. unsigned len; /* length to copy for repeats, bits to drop */
  78230. int ret; /* return code */
  78231. #ifdef GUNZIP
  78232. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78233. #endif
  78234. static const unsigned short order[19] = /* permutation of code lengths */
  78235. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78236. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78237. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78238. return Z_STREAM_ERROR;
  78239. state = (struct inflate_state FAR *)strm->state;
  78240. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78241. LOAD();
  78242. in = have;
  78243. out = left;
  78244. ret = Z_OK;
  78245. for (;;)
  78246. switch (state->mode) {
  78247. case HEAD:
  78248. if (state->wrap == 0) {
  78249. state->mode = TYPEDO;
  78250. break;
  78251. }
  78252. NEEDBITS(16);
  78253. #ifdef GUNZIP
  78254. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78255. state->check = crc32(0L, Z_NULL, 0);
  78256. CRC2(state->check, hold);
  78257. INITBITS();
  78258. state->mode = FLAGS;
  78259. break;
  78260. }
  78261. state->flags = 0; /* expect zlib header */
  78262. if (state->head != Z_NULL)
  78263. state->head->done = -1;
  78264. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78265. #else
  78266. if (
  78267. #endif
  78268. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78269. strm->msg = (char *)"incorrect header check";
  78270. state->mode = BAD;
  78271. break;
  78272. }
  78273. if (BITS(4) != Z_DEFLATED) {
  78274. strm->msg = (char *)"unknown compression method";
  78275. state->mode = BAD;
  78276. break;
  78277. }
  78278. DROPBITS(4);
  78279. len = BITS(4) + 8;
  78280. if (len > state->wbits) {
  78281. strm->msg = (char *)"invalid window size";
  78282. state->mode = BAD;
  78283. break;
  78284. }
  78285. state->dmax = 1U << len;
  78286. Tracev((stderr, "inflate: zlib header ok\n"));
  78287. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78288. state->mode = hold & 0x200 ? DICTID : TYPE;
  78289. INITBITS();
  78290. break;
  78291. #ifdef GUNZIP
  78292. case FLAGS:
  78293. NEEDBITS(16);
  78294. state->flags = (int)(hold);
  78295. if ((state->flags & 0xff) != Z_DEFLATED) {
  78296. strm->msg = (char *)"unknown compression method";
  78297. state->mode = BAD;
  78298. break;
  78299. }
  78300. if (state->flags & 0xe000) {
  78301. strm->msg = (char *)"unknown header flags set";
  78302. state->mode = BAD;
  78303. break;
  78304. }
  78305. if (state->head != Z_NULL)
  78306. state->head->text = (int)((hold >> 8) & 1);
  78307. if (state->flags & 0x0200) CRC2(state->check, hold);
  78308. INITBITS();
  78309. state->mode = TIME;
  78310. case TIME:
  78311. NEEDBITS(32);
  78312. if (state->head != Z_NULL)
  78313. state->head->time = hold;
  78314. if (state->flags & 0x0200) CRC4(state->check, hold);
  78315. INITBITS();
  78316. state->mode = OS;
  78317. case OS:
  78318. NEEDBITS(16);
  78319. if (state->head != Z_NULL) {
  78320. state->head->xflags = (int)(hold & 0xff);
  78321. state->head->os = (int)(hold >> 8);
  78322. }
  78323. if (state->flags & 0x0200) CRC2(state->check, hold);
  78324. INITBITS();
  78325. state->mode = EXLEN;
  78326. case EXLEN:
  78327. if (state->flags & 0x0400) {
  78328. NEEDBITS(16);
  78329. state->length = (unsigned)(hold);
  78330. if (state->head != Z_NULL)
  78331. state->head->extra_len = (unsigned)hold;
  78332. if (state->flags & 0x0200) CRC2(state->check, hold);
  78333. INITBITS();
  78334. }
  78335. else if (state->head != Z_NULL)
  78336. state->head->extra = Z_NULL;
  78337. state->mode = EXTRA;
  78338. case EXTRA:
  78339. if (state->flags & 0x0400) {
  78340. copy = state->length;
  78341. if (copy > have) copy = have;
  78342. if (copy) {
  78343. if (state->head != Z_NULL &&
  78344. state->head->extra != Z_NULL) {
  78345. len = state->head->extra_len - state->length;
  78346. zmemcpy(state->head->extra + len, next,
  78347. len + copy > state->head->extra_max ?
  78348. state->head->extra_max - len : copy);
  78349. }
  78350. if (state->flags & 0x0200)
  78351. state->check = crc32(state->check, next, copy);
  78352. have -= copy;
  78353. next += copy;
  78354. state->length -= copy;
  78355. }
  78356. if (state->length) goto inf_leave;
  78357. }
  78358. state->length = 0;
  78359. state->mode = NAME;
  78360. case NAME:
  78361. if (state->flags & 0x0800) {
  78362. if (have == 0) goto inf_leave;
  78363. copy = 0;
  78364. do {
  78365. len = (unsigned)(next[copy++]);
  78366. if (state->head != Z_NULL &&
  78367. state->head->name != Z_NULL &&
  78368. state->length < state->head->name_max)
  78369. state->head->name[state->length++] = len;
  78370. } while (len && copy < have);
  78371. if (state->flags & 0x0200)
  78372. state->check = crc32(state->check, next, copy);
  78373. have -= copy;
  78374. next += copy;
  78375. if (len) goto inf_leave;
  78376. }
  78377. else if (state->head != Z_NULL)
  78378. state->head->name = Z_NULL;
  78379. state->length = 0;
  78380. state->mode = COMMENT;
  78381. case COMMENT:
  78382. if (state->flags & 0x1000) {
  78383. if (have == 0) goto inf_leave;
  78384. copy = 0;
  78385. do {
  78386. len = (unsigned)(next[copy++]);
  78387. if (state->head != Z_NULL &&
  78388. state->head->comment != Z_NULL &&
  78389. state->length < state->head->comm_max)
  78390. state->head->comment[state->length++] = len;
  78391. } while (len && copy < have);
  78392. if (state->flags & 0x0200)
  78393. state->check = crc32(state->check, next, copy);
  78394. have -= copy;
  78395. next += copy;
  78396. if (len) goto inf_leave;
  78397. }
  78398. else if (state->head != Z_NULL)
  78399. state->head->comment = Z_NULL;
  78400. state->mode = HCRC;
  78401. case HCRC:
  78402. if (state->flags & 0x0200) {
  78403. NEEDBITS(16);
  78404. if (hold != (state->check & 0xffff)) {
  78405. strm->msg = (char *)"header crc mismatch";
  78406. state->mode = BAD;
  78407. break;
  78408. }
  78409. INITBITS();
  78410. }
  78411. if (state->head != Z_NULL) {
  78412. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78413. state->head->done = 1;
  78414. }
  78415. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78416. state->mode = TYPE;
  78417. break;
  78418. #endif
  78419. case DICTID:
  78420. NEEDBITS(32);
  78421. strm->adler = state->check = REVERSE(hold);
  78422. INITBITS();
  78423. state->mode = DICT;
  78424. case DICT:
  78425. if (state->havedict == 0) {
  78426. RESTORE();
  78427. return Z_NEED_DICT;
  78428. }
  78429. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78430. state->mode = TYPE;
  78431. case TYPE:
  78432. if (flush == Z_BLOCK) goto inf_leave;
  78433. case TYPEDO:
  78434. if (state->last) {
  78435. BYTEBITS();
  78436. state->mode = CHECK;
  78437. break;
  78438. }
  78439. NEEDBITS(3);
  78440. state->last = BITS(1);
  78441. DROPBITS(1);
  78442. switch (BITS(2)) {
  78443. case 0: /* stored block */
  78444. Tracev((stderr, "inflate: stored block%s\n",
  78445. state->last ? " (last)" : ""));
  78446. state->mode = STORED;
  78447. break;
  78448. case 1: /* fixed block */
  78449. fixedtables(state);
  78450. Tracev((stderr, "inflate: fixed codes block%s\n",
  78451. state->last ? " (last)" : ""));
  78452. state->mode = LEN; /* decode codes */
  78453. break;
  78454. case 2: /* dynamic block */
  78455. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78456. state->last ? " (last)" : ""));
  78457. state->mode = TABLE;
  78458. break;
  78459. case 3:
  78460. strm->msg = (char *)"invalid block type";
  78461. state->mode = BAD;
  78462. }
  78463. DROPBITS(2);
  78464. break;
  78465. case STORED:
  78466. BYTEBITS(); /* go to byte boundary */
  78467. NEEDBITS(32);
  78468. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78469. strm->msg = (char *)"invalid stored block lengths";
  78470. state->mode = BAD;
  78471. break;
  78472. }
  78473. state->length = (unsigned)hold & 0xffff;
  78474. Tracev((stderr, "inflate: stored length %u\n",
  78475. state->length));
  78476. INITBITS();
  78477. state->mode = COPY;
  78478. case COPY:
  78479. copy = state->length;
  78480. if (copy) {
  78481. if (copy > have) copy = have;
  78482. if (copy > left) copy = left;
  78483. if (copy == 0) goto inf_leave;
  78484. zmemcpy(put, next, copy);
  78485. have -= copy;
  78486. next += copy;
  78487. left -= copy;
  78488. put += copy;
  78489. state->length -= copy;
  78490. break;
  78491. }
  78492. Tracev((stderr, "inflate: stored end\n"));
  78493. state->mode = TYPE;
  78494. break;
  78495. case TABLE:
  78496. NEEDBITS(14);
  78497. state->nlen = BITS(5) + 257;
  78498. DROPBITS(5);
  78499. state->ndist = BITS(5) + 1;
  78500. DROPBITS(5);
  78501. state->ncode = BITS(4) + 4;
  78502. DROPBITS(4);
  78503. #ifndef PKZIP_BUG_WORKAROUND
  78504. if (state->nlen > 286 || state->ndist > 30) {
  78505. strm->msg = (char *)"too many length or distance symbols";
  78506. state->mode = BAD;
  78507. break;
  78508. }
  78509. #endif
  78510. Tracev((stderr, "inflate: table sizes ok\n"));
  78511. state->have = 0;
  78512. state->mode = LENLENS;
  78513. case LENLENS:
  78514. while (state->have < state->ncode) {
  78515. NEEDBITS(3);
  78516. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78517. DROPBITS(3);
  78518. }
  78519. while (state->have < 19)
  78520. state->lens[order[state->have++]] = 0;
  78521. state->next = state->codes;
  78522. state->lencode = (code const FAR *)(state->next);
  78523. state->lenbits = 7;
  78524. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78525. &(state->lenbits), state->work);
  78526. if (ret) {
  78527. strm->msg = (char *)"invalid code lengths set";
  78528. state->mode = BAD;
  78529. break;
  78530. }
  78531. Tracev((stderr, "inflate: code lengths ok\n"));
  78532. state->have = 0;
  78533. state->mode = CODELENS;
  78534. case CODELENS:
  78535. while (state->have < state->nlen + state->ndist) {
  78536. for (;;) {
  78537. thisx = state->lencode[BITS(state->lenbits)];
  78538. if ((unsigned)(thisx.bits) <= bits) break;
  78539. PULLBYTE();
  78540. }
  78541. if (thisx.val < 16) {
  78542. NEEDBITS(thisx.bits);
  78543. DROPBITS(thisx.bits);
  78544. state->lens[state->have++] = thisx.val;
  78545. }
  78546. else {
  78547. if (thisx.val == 16) {
  78548. NEEDBITS(thisx.bits + 2);
  78549. DROPBITS(thisx.bits);
  78550. if (state->have == 0) {
  78551. strm->msg = (char *)"invalid bit length repeat";
  78552. state->mode = BAD;
  78553. break;
  78554. }
  78555. len = state->lens[state->have - 1];
  78556. copy = 3 + BITS(2);
  78557. DROPBITS(2);
  78558. }
  78559. else if (thisx.val == 17) {
  78560. NEEDBITS(thisx.bits + 3);
  78561. DROPBITS(thisx.bits);
  78562. len = 0;
  78563. copy = 3 + BITS(3);
  78564. DROPBITS(3);
  78565. }
  78566. else {
  78567. NEEDBITS(thisx.bits + 7);
  78568. DROPBITS(thisx.bits);
  78569. len = 0;
  78570. copy = 11 + BITS(7);
  78571. DROPBITS(7);
  78572. }
  78573. if (state->have + copy > state->nlen + state->ndist) {
  78574. strm->msg = (char *)"invalid bit length repeat";
  78575. state->mode = BAD;
  78576. break;
  78577. }
  78578. while (copy--)
  78579. state->lens[state->have++] = (unsigned short)len;
  78580. }
  78581. }
  78582. if (state->mode == BAD) break;
  78583. state->next = state->codes;
  78584. state->lencode = (code const FAR *)(state->next);
  78585. state->lenbits = 9;
  78586. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78587. &(state->lenbits), state->work);
  78588. if (ret) {
  78589. strm->msg = (char *)"invalid literal/lengths set";
  78590. state->mode = BAD;
  78591. break;
  78592. }
  78593. state->distcode = (code const FAR *)(state->next);
  78594. state->distbits = 6;
  78595. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78596. &(state->next), &(state->distbits), state->work);
  78597. if (ret) {
  78598. strm->msg = (char *)"invalid distances set";
  78599. state->mode = BAD;
  78600. break;
  78601. }
  78602. Tracev((stderr, "inflate: codes ok\n"));
  78603. state->mode = LEN;
  78604. case LEN:
  78605. if (have >= 6 && left >= 258) {
  78606. RESTORE();
  78607. inflate_fast(strm, out);
  78608. LOAD();
  78609. break;
  78610. }
  78611. for (;;) {
  78612. thisx = state->lencode[BITS(state->lenbits)];
  78613. if ((unsigned)(thisx.bits) <= bits) break;
  78614. PULLBYTE();
  78615. }
  78616. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78617. last = thisx;
  78618. for (;;) {
  78619. thisx = state->lencode[last.val +
  78620. (BITS(last.bits + last.op) >> last.bits)];
  78621. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78622. PULLBYTE();
  78623. }
  78624. DROPBITS(last.bits);
  78625. }
  78626. DROPBITS(thisx.bits);
  78627. state->length = (unsigned)thisx.val;
  78628. if ((int)(thisx.op) == 0) {
  78629. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78630. "inflate: literal '%c'\n" :
  78631. "inflate: literal 0x%02x\n", thisx.val));
  78632. state->mode = LIT;
  78633. break;
  78634. }
  78635. if (thisx.op & 32) {
  78636. Tracevv((stderr, "inflate: end of block\n"));
  78637. state->mode = TYPE;
  78638. break;
  78639. }
  78640. if (thisx.op & 64) {
  78641. strm->msg = (char *)"invalid literal/length code";
  78642. state->mode = BAD;
  78643. break;
  78644. }
  78645. state->extra = (unsigned)(thisx.op) & 15;
  78646. state->mode = LENEXT;
  78647. case LENEXT:
  78648. if (state->extra) {
  78649. NEEDBITS(state->extra);
  78650. state->length += BITS(state->extra);
  78651. DROPBITS(state->extra);
  78652. }
  78653. Tracevv((stderr, "inflate: length %u\n", state->length));
  78654. state->mode = DIST;
  78655. case DIST:
  78656. for (;;) {
  78657. thisx = state->distcode[BITS(state->distbits)];
  78658. if ((unsigned)(thisx.bits) <= bits) break;
  78659. PULLBYTE();
  78660. }
  78661. if ((thisx.op & 0xf0) == 0) {
  78662. last = thisx;
  78663. for (;;) {
  78664. thisx = state->distcode[last.val +
  78665. (BITS(last.bits + last.op) >> last.bits)];
  78666. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78667. PULLBYTE();
  78668. }
  78669. DROPBITS(last.bits);
  78670. }
  78671. DROPBITS(thisx.bits);
  78672. if (thisx.op & 64) {
  78673. strm->msg = (char *)"invalid distance code";
  78674. state->mode = BAD;
  78675. break;
  78676. }
  78677. state->offset = (unsigned)thisx.val;
  78678. state->extra = (unsigned)(thisx.op) & 15;
  78679. state->mode = DISTEXT;
  78680. case DISTEXT:
  78681. if (state->extra) {
  78682. NEEDBITS(state->extra);
  78683. state->offset += BITS(state->extra);
  78684. DROPBITS(state->extra);
  78685. }
  78686. #ifdef INFLATE_STRICT
  78687. if (state->offset > state->dmax) {
  78688. strm->msg = (char *)"invalid distance too far back";
  78689. state->mode = BAD;
  78690. break;
  78691. }
  78692. #endif
  78693. if (state->offset > state->whave + out - left) {
  78694. strm->msg = (char *)"invalid distance too far back";
  78695. state->mode = BAD;
  78696. break;
  78697. }
  78698. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78699. state->mode = MATCH;
  78700. case MATCH:
  78701. if (left == 0) goto inf_leave;
  78702. copy = out - left;
  78703. if (state->offset > copy) { /* copy from window */
  78704. copy = state->offset - copy;
  78705. if (copy > state->write) {
  78706. copy -= state->write;
  78707. from = state->window + (state->wsize - copy);
  78708. }
  78709. else
  78710. from = state->window + (state->write - copy);
  78711. if (copy > state->length) copy = state->length;
  78712. }
  78713. else { /* copy from output */
  78714. from = put - state->offset;
  78715. copy = state->length;
  78716. }
  78717. if (copy > left) copy = left;
  78718. left -= copy;
  78719. state->length -= copy;
  78720. do {
  78721. *put++ = *from++;
  78722. } while (--copy);
  78723. if (state->length == 0) state->mode = LEN;
  78724. break;
  78725. case LIT:
  78726. if (left == 0) goto inf_leave;
  78727. *put++ = (unsigned char)(state->length);
  78728. left--;
  78729. state->mode = LEN;
  78730. break;
  78731. case CHECK:
  78732. if (state->wrap) {
  78733. NEEDBITS(32);
  78734. out -= left;
  78735. strm->total_out += out;
  78736. state->total += out;
  78737. if (out)
  78738. strm->adler = state->check =
  78739. UPDATE(state->check, put - out, out);
  78740. out = left;
  78741. if ((
  78742. #ifdef GUNZIP
  78743. state->flags ? hold :
  78744. #endif
  78745. REVERSE(hold)) != state->check) {
  78746. strm->msg = (char *)"incorrect data check";
  78747. state->mode = BAD;
  78748. break;
  78749. }
  78750. INITBITS();
  78751. Tracev((stderr, "inflate: check matches trailer\n"));
  78752. }
  78753. #ifdef GUNZIP
  78754. state->mode = LENGTH;
  78755. case LENGTH:
  78756. if (state->wrap && state->flags) {
  78757. NEEDBITS(32);
  78758. if (hold != (state->total & 0xffffffffUL)) {
  78759. strm->msg = (char *)"incorrect length check";
  78760. state->mode = BAD;
  78761. break;
  78762. }
  78763. INITBITS();
  78764. Tracev((stderr, "inflate: length matches trailer\n"));
  78765. }
  78766. #endif
  78767. state->mode = DONE;
  78768. case DONE:
  78769. ret = Z_STREAM_END;
  78770. goto inf_leave;
  78771. case BAD:
  78772. ret = Z_DATA_ERROR;
  78773. goto inf_leave;
  78774. case MEM:
  78775. return Z_MEM_ERROR;
  78776. case SYNC:
  78777. default:
  78778. return Z_STREAM_ERROR;
  78779. }
  78780. inf_leave:
  78781. RESTORE();
  78782. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78783. if (updatewindow(strm, out)) {
  78784. state->mode = MEM;
  78785. return Z_MEM_ERROR;
  78786. }
  78787. in -= strm->avail_in;
  78788. out -= strm->avail_out;
  78789. strm->total_in += in;
  78790. strm->total_out += out;
  78791. state->total += out;
  78792. if (state->wrap && out)
  78793. strm->adler = state->check =
  78794. UPDATE(state->check, strm->next_out - out, out);
  78795. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78796. (state->mode == TYPE ? 128 : 0);
  78797. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78798. ret = Z_BUF_ERROR;
  78799. return ret;
  78800. }
  78801. int ZEXPORT inflateEnd (z_streamp strm)
  78802. {
  78803. struct inflate_state FAR *state;
  78804. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78805. return Z_STREAM_ERROR;
  78806. state = (struct inflate_state FAR *)strm->state;
  78807. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78808. ZFREE(strm, strm->state);
  78809. strm->state = Z_NULL;
  78810. Tracev((stderr, "inflate: end\n"));
  78811. return Z_OK;
  78812. }
  78813. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78814. {
  78815. struct inflate_state FAR *state;
  78816. unsigned long id_;
  78817. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78818. state = (struct inflate_state FAR *)strm->state;
  78819. if (state->wrap != 0 && state->mode != DICT)
  78820. return Z_STREAM_ERROR;
  78821. if (state->mode == DICT) {
  78822. id_ = adler32(0L, Z_NULL, 0);
  78823. id_ = adler32(id_, dictionary, dictLength);
  78824. if (id_ != state->check)
  78825. return Z_DATA_ERROR;
  78826. }
  78827. if (updatewindow(strm, strm->avail_out)) {
  78828. state->mode = MEM;
  78829. return Z_MEM_ERROR;
  78830. }
  78831. if (dictLength > state->wsize) {
  78832. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78833. state->wsize);
  78834. state->whave = state->wsize;
  78835. }
  78836. else {
  78837. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78838. dictLength);
  78839. state->whave = dictLength;
  78840. }
  78841. state->havedict = 1;
  78842. Tracev((stderr, "inflate: dictionary set\n"));
  78843. return Z_OK;
  78844. }
  78845. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78846. {
  78847. struct inflate_state FAR *state;
  78848. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78849. state = (struct inflate_state FAR *)strm->state;
  78850. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78851. state->head = head;
  78852. head->done = 0;
  78853. return Z_OK;
  78854. }
  78855. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78856. {
  78857. unsigned got;
  78858. unsigned next;
  78859. got = *have;
  78860. next = 0;
  78861. while (next < len && got < 4) {
  78862. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78863. got++;
  78864. else if (buf[next])
  78865. got = 0;
  78866. else
  78867. got = 4 - got;
  78868. next++;
  78869. }
  78870. *have = got;
  78871. return next;
  78872. }
  78873. int ZEXPORT inflateSync (z_streamp strm)
  78874. {
  78875. unsigned len; /* number of bytes to look at or looked at */
  78876. unsigned long in, out; /* temporary to save total_in and total_out */
  78877. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78878. struct inflate_state FAR *state;
  78879. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78880. state = (struct inflate_state FAR *)strm->state;
  78881. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78882. if (state->mode != SYNC) {
  78883. state->mode = SYNC;
  78884. state->hold <<= state->bits & 7;
  78885. state->bits -= state->bits & 7;
  78886. len = 0;
  78887. while (state->bits >= 8) {
  78888. buf[len++] = (unsigned char)(state->hold);
  78889. state->hold >>= 8;
  78890. state->bits -= 8;
  78891. }
  78892. state->have = 0;
  78893. syncsearch(&(state->have), buf, len);
  78894. }
  78895. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78896. strm->avail_in -= len;
  78897. strm->next_in += len;
  78898. strm->total_in += len;
  78899. if (state->have != 4) return Z_DATA_ERROR;
  78900. in = strm->total_in; out = strm->total_out;
  78901. inflateReset(strm);
  78902. strm->total_in = in; strm->total_out = out;
  78903. state->mode = TYPE;
  78904. return Z_OK;
  78905. }
  78906. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78907. {
  78908. struct inflate_state FAR *state;
  78909. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78910. state = (struct inflate_state FAR *)strm->state;
  78911. return state->mode == STORED && state->bits == 0;
  78912. }
  78913. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78914. {
  78915. struct inflate_state FAR *state;
  78916. struct inflate_state FAR *copy;
  78917. unsigned char FAR *window;
  78918. unsigned wsize;
  78919. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  78920. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  78921. return Z_STREAM_ERROR;
  78922. state = (struct inflate_state FAR *)source->state;
  78923. copy = (struct inflate_state FAR *)
  78924. ZALLOC(source, 1, sizeof(struct inflate_state));
  78925. if (copy == Z_NULL) return Z_MEM_ERROR;
  78926. window = Z_NULL;
  78927. if (state->window != Z_NULL) {
  78928. window = (unsigned char FAR *)
  78929. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  78930. if (window == Z_NULL) {
  78931. ZFREE(source, copy);
  78932. return Z_MEM_ERROR;
  78933. }
  78934. }
  78935. zmemcpy(dest, source, sizeof(z_stream));
  78936. zmemcpy(copy, state, sizeof(struct inflate_state));
  78937. if (state->lencode >= state->codes &&
  78938. state->lencode <= state->codes + ENOUGH - 1) {
  78939. copy->lencode = copy->codes + (state->lencode - state->codes);
  78940. copy->distcode = copy->codes + (state->distcode - state->codes);
  78941. }
  78942. copy->next = copy->codes + (state->next - state->codes);
  78943. if (window != Z_NULL) {
  78944. wsize = 1U << state->wbits;
  78945. zmemcpy(window, state->window, wsize);
  78946. }
  78947. copy->window = window;
  78948. dest->state = (struct internal_state FAR *)copy;
  78949. return Z_OK;
  78950. }
  78951. /*** End of inlined file: inflate.c ***/
  78952. /*** Start of inlined file: inftrees.c ***/
  78953. #define MAXBITS 15
  78954. const char inflate_copyright[] =
  78955. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  78956. int inflate_table (codetype type,
  78957. unsigned short FAR *lens,
  78958. unsigned codes,
  78959. code FAR * FAR *table,
  78960. unsigned FAR *bits,
  78961. unsigned short FAR *work)
  78962. {
  78963. unsigned len; /* a code's length in bits */
  78964. unsigned sym; /* index of code symbols */
  78965. unsigned min, max; /* minimum and maximum code lengths */
  78966. unsigned root; /* number of index bits for root table */
  78967. unsigned curr; /* number of index bits for current table */
  78968. unsigned drop; /* code bits to drop for sub-table */
  78969. int left; /* number of prefix codes available */
  78970. unsigned used; /* code entries in table used */
  78971. unsigned huff; /* Huffman code */
  78972. unsigned incr; /* for incrementing code, index */
  78973. unsigned fill; /* index for replicating entries */
  78974. unsigned low; /* low bits for current root entry */
  78975. unsigned mask; /* mask for low root bits */
  78976. code thisx; /* table entry for duplication */
  78977. code FAR *next; /* next available space in table */
  78978. const unsigned short FAR *base; /* base value table to use */
  78979. const unsigned short FAR *extra; /* extra bits table to use */
  78980. int end; /* use base and extra for symbol > end */
  78981. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  78982. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  78983. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  78984. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  78985. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  78986. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  78987. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  78988. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  78989. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  78990. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  78991. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  78992. 8193, 12289, 16385, 24577, 0, 0};
  78993. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  78994. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  78995. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  78996. 28, 28, 29, 29, 64, 64};
  78997. for (len = 0; len <= MAXBITS; len++)
  78998. count[len] = 0;
  78999. for (sym = 0; sym < codes; sym++)
  79000. count[lens[sym]]++;
  79001. root = *bits;
  79002. for (max = MAXBITS; max >= 1; max--)
  79003. if (count[max] != 0) break;
  79004. if (root > max) root = max;
  79005. if (max == 0) { /* no symbols to code at all */
  79006. thisx.op = (unsigned char)64; /* invalid code marker */
  79007. thisx.bits = (unsigned char)1;
  79008. thisx.val = (unsigned short)0;
  79009. *(*table)++ = thisx; /* make a table to force an error */
  79010. *(*table)++ = thisx;
  79011. *bits = 1;
  79012. return 0; /* no symbols, but wait for decoding to report error */
  79013. }
  79014. for (min = 1; min <= MAXBITS; min++)
  79015. if (count[min] != 0) break;
  79016. if (root < min) root = min;
  79017. left = 1;
  79018. for (len = 1; len <= MAXBITS; len++) {
  79019. left <<= 1;
  79020. left -= count[len];
  79021. if (left < 0) return -1; /* over-subscribed */
  79022. }
  79023. if (left > 0 && (type == CODES || max != 1))
  79024. return -1; /* incomplete set */
  79025. offs[1] = 0;
  79026. for (len = 1; len < MAXBITS; len++)
  79027. offs[len + 1] = offs[len] + count[len];
  79028. for (sym = 0; sym < codes; sym++)
  79029. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79030. switch (type) {
  79031. case CODES:
  79032. base = extra = work; /* dummy value--not used */
  79033. end = 19;
  79034. break;
  79035. case LENS:
  79036. base = lbase;
  79037. base -= 257;
  79038. extra = lext;
  79039. extra -= 257;
  79040. end = 256;
  79041. break;
  79042. default: /* DISTS */
  79043. base = dbase;
  79044. extra = dext;
  79045. end = -1;
  79046. }
  79047. huff = 0; /* starting code */
  79048. sym = 0; /* starting code symbol */
  79049. len = min; /* starting code length */
  79050. next = *table; /* current table to fill in */
  79051. curr = root; /* current table index bits */
  79052. drop = 0; /* current bits to drop from code for index */
  79053. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79054. used = 1U << root; /* use root table entries */
  79055. mask = used - 1; /* mask for comparing low */
  79056. if (type == LENS && used >= ENOUGH - MAXD)
  79057. return 1;
  79058. for (;;) {
  79059. thisx.bits = (unsigned char)(len - drop);
  79060. if ((int)(work[sym]) < end) {
  79061. thisx.op = (unsigned char)0;
  79062. thisx.val = work[sym];
  79063. }
  79064. else if ((int)(work[sym]) > end) {
  79065. thisx.op = (unsigned char)(extra[work[sym]]);
  79066. thisx.val = base[work[sym]];
  79067. }
  79068. else {
  79069. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79070. thisx.val = 0;
  79071. }
  79072. incr = 1U << (len - drop);
  79073. fill = 1U << curr;
  79074. min = fill; /* save offset to next table */
  79075. do {
  79076. fill -= incr;
  79077. next[(huff >> drop) + fill] = thisx;
  79078. } while (fill != 0);
  79079. incr = 1U << (len - 1);
  79080. while (huff & incr)
  79081. incr >>= 1;
  79082. if (incr != 0) {
  79083. huff &= incr - 1;
  79084. huff += incr;
  79085. }
  79086. else
  79087. huff = 0;
  79088. sym++;
  79089. if (--(count[len]) == 0) {
  79090. if (len == max) break;
  79091. len = lens[work[sym]];
  79092. }
  79093. if (len > root && (huff & mask) != low) {
  79094. if (drop == 0)
  79095. drop = root;
  79096. next += min; /* here min is 1 << curr */
  79097. curr = len - drop;
  79098. left = (int)(1 << curr);
  79099. while (curr + drop < max) {
  79100. left -= count[curr + drop];
  79101. if (left <= 0) break;
  79102. curr++;
  79103. left <<= 1;
  79104. }
  79105. used += 1U << curr;
  79106. if (type == LENS && used >= ENOUGH - MAXD)
  79107. return 1;
  79108. low = huff & mask;
  79109. (*table)[low].op = (unsigned char)curr;
  79110. (*table)[low].bits = (unsigned char)root;
  79111. (*table)[low].val = (unsigned short)(next - *table);
  79112. }
  79113. }
  79114. thisx.op = (unsigned char)64; /* invalid code marker */
  79115. thisx.bits = (unsigned char)(len - drop);
  79116. thisx.val = (unsigned short)0;
  79117. while (huff != 0) {
  79118. if (drop != 0 && (huff & mask) != low) {
  79119. drop = 0;
  79120. len = root;
  79121. next = *table;
  79122. thisx.bits = (unsigned char)len;
  79123. }
  79124. next[huff >> drop] = thisx;
  79125. incr = 1U << (len - 1);
  79126. while (huff & incr)
  79127. incr >>= 1;
  79128. if (incr != 0) {
  79129. huff &= incr - 1;
  79130. huff += incr;
  79131. }
  79132. else
  79133. huff = 0;
  79134. }
  79135. *table += used;
  79136. *bits = root;
  79137. return 0;
  79138. }
  79139. /*** End of inlined file: inftrees.c ***/
  79140. /*** Start of inlined file: trees.c ***/
  79141. #ifdef DEBUG
  79142. # include <ctype.h>
  79143. #endif
  79144. #define MAX_BL_BITS 7
  79145. #define END_BLOCK 256
  79146. #define REP_3_6 16
  79147. #define REPZ_3_10 17
  79148. #define REPZ_11_138 18
  79149. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79150. = {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};
  79151. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79152. = {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};
  79153. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79154. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79155. local const uch bl_order[BL_CODES]
  79156. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79157. #define Buf_size (8 * 2*sizeof(char))
  79158. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79159. #if defined(GEN_TREES_H) || !defined(STDC)
  79160. local ct_data static_ltree[L_CODES+2];
  79161. local ct_data static_dtree[D_CODES];
  79162. uch _dist_code[DIST_CODE_LEN];
  79163. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79164. local int base_length[LENGTH_CODES];
  79165. local int base_dist[D_CODES];
  79166. #else
  79167. /*** Start of inlined file: trees.h ***/
  79168. local const ct_data static_ltree[L_CODES+2] = {
  79169. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79170. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79171. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79172. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79173. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79174. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79175. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79176. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79177. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79178. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79179. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79180. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79181. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79182. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79183. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79184. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79185. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79186. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79187. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79188. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79189. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79190. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79191. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79192. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79193. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79194. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79195. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79196. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79197. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79198. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79199. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79200. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79201. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79202. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79203. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79204. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79205. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79206. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79207. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79208. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79209. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79210. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79211. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79212. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79213. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79214. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79215. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79216. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79217. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79218. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79219. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79220. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79221. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79222. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79223. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79224. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79225. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79226. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79227. };
  79228. local const ct_data static_dtree[D_CODES] = {
  79229. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79230. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79231. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79232. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79233. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79234. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79235. };
  79236. const uch _dist_code[DIST_CODE_LEN] = {
  79237. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79238. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79239. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79240. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79241. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79242. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79243. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79244. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79245. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79246. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79247. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79248. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79249. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79250. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79251. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79252. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79253. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79254. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79255. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79256. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79257. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79258. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79259. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79260. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79261. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79262. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79263. };
  79264. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79265. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79266. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79267. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79268. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79269. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79270. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79271. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79272. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79273. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79274. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79275. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79276. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79277. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79278. };
  79279. local const int base_length[LENGTH_CODES] = {
  79280. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79281. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79282. };
  79283. local const int base_dist[D_CODES] = {
  79284. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79285. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79286. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79287. };
  79288. /*** End of inlined file: trees.h ***/
  79289. #endif /* GEN_TREES_H */
  79290. struct static_tree_desc_s {
  79291. const ct_data *static_tree; /* static tree or NULL */
  79292. const intf *extra_bits; /* extra bits for each code or NULL */
  79293. int extra_base; /* base index for extra_bits */
  79294. int elems; /* max number of elements in the tree */
  79295. int max_length; /* max bit length for the codes */
  79296. };
  79297. local static_tree_desc static_l_desc =
  79298. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79299. local static_tree_desc static_d_desc =
  79300. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79301. local static_tree_desc static_bl_desc =
  79302. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79303. local void tr_static_init OF((void));
  79304. local void init_block OF((deflate_state *s));
  79305. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79306. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79307. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79308. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79309. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79310. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79311. local int build_bl_tree OF((deflate_state *s));
  79312. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79313. int blcodes));
  79314. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79315. ct_data *dtree));
  79316. local void set_data_type OF((deflate_state *s));
  79317. local unsigned bi_reverse OF((unsigned value, int length));
  79318. local void bi_windup OF((deflate_state *s));
  79319. local void bi_flush OF((deflate_state *s));
  79320. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79321. int header));
  79322. #ifdef GEN_TREES_H
  79323. local void gen_trees_header OF((void));
  79324. #endif
  79325. #ifndef DEBUG
  79326. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79327. #else /* DEBUG */
  79328. # define send_code(s, c, tree) \
  79329. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79330. send_bits(s, tree[c].Code, tree[c].Len); }
  79331. #endif
  79332. #define put_short(s, w) { \
  79333. put_byte(s, (uch)((w) & 0xff)); \
  79334. put_byte(s, (uch)((ush)(w) >> 8)); \
  79335. }
  79336. #ifdef DEBUG
  79337. local void send_bits OF((deflate_state *s, int value, int length));
  79338. local void send_bits (deflate_state *s, int value, int length)
  79339. {
  79340. Tracevv((stderr," l %2d v %4x ", length, value));
  79341. Assert(length > 0 && length <= 15, "invalid length");
  79342. s->bits_sent += (ulg)length;
  79343. if (s->bi_valid > (int)Buf_size - length) {
  79344. s->bi_buf |= (value << s->bi_valid);
  79345. put_short(s, s->bi_buf);
  79346. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79347. s->bi_valid += length - Buf_size;
  79348. } else {
  79349. s->bi_buf |= value << s->bi_valid;
  79350. s->bi_valid += length;
  79351. }
  79352. }
  79353. #else /* !DEBUG */
  79354. #define send_bits(s, value, length) \
  79355. { int len = length;\
  79356. if (s->bi_valid > (int)Buf_size - len) {\
  79357. int val = value;\
  79358. s->bi_buf |= (val << s->bi_valid);\
  79359. put_short(s, s->bi_buf);\
  79360. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79361. s->bi_valid += len - Buf_size;\
  79362. } else {\
  79363. s->bi_buf |= (value) << s->bi_valid;\
  79364. s->bi_valid += len;\
  79365. }\
  79366. }
  79367. #endif /* DEBUG */
  79368. local void tr_static_init()
  79369. {
  79370. #if defined(GEN_TREES_H) || !defined(STDC)
  79371. static int static_init_done = 0;
  79372. int n; /* iterates over tree elements */
  79373. int bits; /* bit counter */
  79374. int length; /* length value */
  79375. int code; /* code value */
  79376. int dist; /* distance index */
  79377. ush bl_count[MAX_BITS+1];
  79378. if (static_init_done) return;
  79379. static_l_desc.static_tree = static_ltree;
  79380. static_l_desc.extra_bits = extra_lbits;
  79381. static_d_desc.static_tree = static_dtree;
  79382. static_d_desc.extra_bits = extra_dbits;
  79383. static_bl_desc.extra_bits = extra_blbits;
  79384. length = 0;
  79385. for (code = 0; code < LENGTH_CODES-1; code++) {
  79386. base_length[code] = length;
  79387. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79388. _length_code[length++] = (uch)code;
  79389. }
  79390. }
  79391. Assert (length == 256, "tr_static_init: length != 256");
  79392. _length_code[length-1] = (uch)code;
  79393. dist = 0;
  79394. for (code = 0 ; code < 16; code++) {
  79395. base_dist[code] = dist;
  79396. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79397. _dist_code[dist++] = (uch)code;
  79398. }
  79399. }
  79400. Assert (dist == 256, "tr_static_init: dist != 256");
  79401. dist >>= 7; /* from now on, all distances are divided by 128 */
  79402. for ( ; code < D_CODES; code++) {
  79403. base_dist[code] = dist << 7;
  79404. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79405. _dist_code[256 + dist++] = (uch)code;
  79406. }
  79407. }
  79408. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79409. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79410. n = 0;
  79411. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79412. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79413. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79414. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79415. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79416. for (n = 0; n < D_CODES; n++) {
  79417. static_dtree[n].Len = 5;
  79418. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79419. }
  79420. static_init_done = 1;
  79421. # ifdef GEN_TREES_H
  79422. gen_trees_header();
  79423. # endif
  79424. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79425. }
  79426. #ifdef GEN_TREES_H
  79427. # ifndef DEBUG
  79428. # include <stdio.h>
  79429. # endif
  79430. # define SEPARATOR(i, last, width) \
  79431. ((i) == (last)? "\n};\n\n" : \
  79432. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79433. void gen_trees_header()
  79434. {
  79435. FILE *header = fopen("trees.h", "w");
  79436. int i;
  79437. Assert (header != NULL, "Can't open trees.h");
  79438. fprintf(header,
  79439. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79440. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79441. for (i = 0; i < L_CODES+2; i++) {
  79442. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79443. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79444. }
  79445. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79446. for (i = 0; i < D_CODES; i++) {
  79447. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79448. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79449. }
  79450. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79451. for (i = 0; i < DIST_CODE_LEN; i++) {
  79452. fprintf(header, "%2u%s", _dist_code[i],
  79453. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79454. }
  79455. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79456. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79457. fprintf(header, "%2u%s", _length_code[i],
  79458. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79459. }
  79460. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79461. for (i = 0; i < LENGTH_CODES; i++) {
  79462. fprintf(header, "%1u%s", base_length[i],
  79463. SEPARATOR(i, LENGTH_CODES-1, 20));
  79464. }
  79465. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79466. for (i = 0; i < D_CODES; i++) {
  79467. fprintf(header, "%5u%s", base_dist[i],
  79468. SEPARATOR(i, D_CODES-1, 10));
  79469. }
  79470. fclose(header);
  79471. }
  79472. #endif /* GEN_TREES_H */
  79473. void _tr_init(deflate_state *s)
  79474. {
  79475. tr_static_init();
  79476. s->l_desc.dyn_tree = s->dyn_ltree;
  79477. s->l_desc.stat_desc = &static_l_desc;
  79478. s->d_desc.dyn_tree = s->dyn_dtree;
  79479. s->d_desc.stat_desc = &static_d_desc;
  79480. s->bl_desc.dyn_tree = s->bl_tree;
  79481. s->bl_desc.stat_desc = &static_bl_desc;
  79482. s->bi_buf = 0;
  79483. s->bi_valid = 0;
  79484. s->last_eob_len = 8; /* enough lookahead for inflate */
  79485. #ifdef DEBUG
  79486. s->compressed_len = 0L;
  79487. s->bits_sent = 0L;
  79488. #endif
  79489. init_block(s);
  79490. }
  79491. local void init_block (deflate_state *s)
  79492. {
  79493. int n; /* iterates over tree elements */
  79494. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79495. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79496. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79497. s->dyn_ltree[END_BLOCK].Freq = 1;
  79498. s->opt_len = s->static_len = 0L;
  79499. s->last_lit = s->matches = 0;
  79500. }
  79501. #define SMALLEST 1
  79502. #define pqremove(s, tree, top) \
  79503. {\
  79504. top = s->heap[SMALLEST]; \
  79505. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79506. pqdownheap(s, tree, SMALLEST); \
  79507. }
  79508. #define smaller(tree, n, m, depth) \
  79509. (tree[n].Freq < tree[m].Freq || \
  79510. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79511. local void pqdownheap (deflate_state *s,
  79512. ct_data *tree, /* the tree to restore */
  79513. int k) /* node to move down */
  79514. {
  79515. int v = s->heap[k];
  79516. int j = k << 1; /* left son of k */
  79517. while (j <= s->heap_len) {
  79518. if (j < s->heap_len &&
  79519. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79520. j++;
  79521. }
  79522. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79523. s->heap[k] = s->heap[j]; k = j;
  79524. j <<= 1;
  79525. }
  79526. s->heap[k] = v;
  79527. }
  79528. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79529. {
  79530. ct_data *tree = desc->dyn_tree;
  79531. int max_code = desc->max_code;
  79532. const ct_data *stree = desc->stat_desc->static_tree;
  79533. const intf *extra = desc->stat_desc->extra_bits;
  79534. int base = desc->stat_desc->extra_base;
  79535. int max_length = desc->stat_desc->max_length;
  79536. int h; /* heap index */
  79537. int n, m; /* iterate over the tree elements */
  79538. int bits; /* bit length */
  79539. int xbits; /* extra bits */
  79540. ush f; /* frequency */
  79541. int overflow = 0; /* number of elements with bit length too large */
  79542. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79543. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79544. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79545. n = s->heap[h];
  79546. bits = tree[tree[n].Dad].Len + 1;
  79547. if (bits > max_length) bits = max_length, overflow++;
  79548. tree[n].Len = (ush)bits;
  79549. if (n > max_code) continue; /* not a leaf node */
  79550. s->bl_count[bits]++;
  79551. xbits = 0;
  79552. if (n >= base) xbits = extra[n-base];
  79553. f = tree[n].Freq;
  79554. s->opt_len += (ulg)f * (bits + xbits);
  79555. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79556. }
  79557. if (overflow == 0) return;
  79558. Trace((stderr,"\nbit length overflow\n"));
  79559. do {
  79560. bits = max_length-1;
  79561. while (s->bl_count[bits] == 0) bits--;
  79562. s->bl_count[bits]--; /* move one leaf down the tree */
  79563. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79564. s->bl_count[max_length]--;
  79565. overflow -= 2;
  79566. } while (overflow > 0);
  79567. for (bits = max_length; bits != 0; bits--) {
  79568. n = s->bl_count[bits];
  79569. while (n != 0) {
  79570. m = s->heap[--h];
  79571. if (m > max_code) continue;
  79572. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79573. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79574. s->opt_len += ((long)bits - (long)tree[m].Len)
  79575. *(long)tree[m].Freq;
  79576. tree[m].Len = (ush)bits;
  79577. }
  79578. n--;
  79579. }
  79580. }
  79581. }
  79582. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79583. int max_code, /* largest code with non zero frequency */
  79584. ushf *bl_count) /* number of codes at each bit length */
  79585. {
  79586. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79587. ush code = 0; /* running code value */
  79588. int bits; /* bit index */
  79589. int n; /* code index */
  79590. for (bits = 1; bits <= MAX_BITS; bits++) {
  79591. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79592. }
  79593. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79594. "inconsistent bit counts");
  79595. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79596. for (n = 0; n <= max_code; n++) {
  79597. int len = tree[n].Len;
  79598. if (len == 0) continue;
  79599. tree[n].Code = bi_reverse(next_code[len]++, len);
  79600. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79601. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79602. }
  79603. }
  79604. local void build_tree (deflate_state *s,
  79605. tree_desc *desc) /* the tree descriptor */
  79606. {
  79607. ct_data *tree = desc->dyn_tree;
  79608. const ct_data *stree = desc->stat_desc->static_tree;
  79609. int elems = desc->stat_desc->elems;
  79610. int n, m; /* iterate over heap elements */
  79611. int max_code = -1; /* largest code with non zero frequency */
  79612. int node; /* new node being created */
  79613. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79614. for (n = 0; n < elems; n++) {
  79615. if (tree[n].Freq != 0) {
  79616. s->heap[++(s->heap_len)] = max_code = n;
  79617. s->depth[n] = 0;
  79618. } else {
  79619. tree[n].Len = 0;
  79620. }
  79621. }
  79622. while (s->heap_len < 2) {
  79623. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79624. tree[node].Freq = 1;
  79625. s->depth[node] = 0;
  79626. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79627. }
  79628. desc->max_code = max_code;
  79629. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79630. node = elems; /* next internal node of the tree */
  79631. do {
  79632. pqremove(s, tree, n); /* n = node of least frequency */
  79633. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79634. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79635. s->heap[--(s->heap_max)] = m;
  79636. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79637. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79638. s->depth[n] : s->depth[m]) + 1);
  79639. tree[n].Dad = tree[m].Dad = (ush)node;
  79640. #ifdef DUMP_BL_TREE
  79641. if (tree == s->bl_tree) {
  79642. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79643. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79644. }
  79645. #endif
  79646. s->heap[SMALLEST] = node++;
  79647. pqdownheap(s, tree, SMALLEST);
  79648. } while (s->heap_len >= 2);
  79649. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79650. gen_bitlen(s, (tree_desc *)desc);
  79651. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79652. }
  79653. local void scan_tree (deflate_state *s,
  79654. ct_data *tree, /* the tree to be scanned */
  79655. int max_code) /* and its largest code of non zero frequency */
  79656. {
  79657. int n; /* iterates over all tree elements */
  79658. int prevlen = -1; /* last emitted length */
  79659. int curlen; /* length of current code */
  79660. int nextlen = tree[0].Len; /* length of next code */
  79661. int count = 0; /* repeat count of the current code */
  79662. int max_count = 7; /* max repeat count */
  79663. int min_count = 4; /* min repeat count */
  79664. if (nextlen == 0) max_count = 138, min_count = 3;
  79665. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79666. for (n = 0; n <= max_code; n++) {
  79667. curlen = nextlen; nextlen = tree[n+1].Len;
  79668. if (++count < max_count && curlen == nextlen) {
  79669. continue;
  79670. } else if (count < min_count) {
  79671. s->bl_tree[curlen].Freq += count;
  79672. } else if (curlen != 0) {
  79673. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79674. s->bl_tree[REP_3_6].Freq++;
  79675. } else if (count <= 10) {
  79676. s->bl_tree[REPZ_3_10].Freq++;
  79677. } else {
  79678. s->bl_tree[REPZ_11_138].Freq++;
  79679. }
  79680. count = 0; prevlen = curlen;
  79681. if (nextlen == 0) {
  79682. max_count = 138, min_count = 3;
  79683. } else if (curlen == nextlen) {
  79684. max_count = 6, min_count = 3;
  79685. } else {
  79686. max_count = 7, min_count = 4;
  79687. }
  79688. }
  79689. }
  79690. local void send_tree (deflate_state *s,
  79691. ct_data *tree, /* the tree to be scanned */
  79692. int max_code) /* and its largest code of non zero frequency */
  79693. {
  79694. int n; /* iterates over all tree elements */
  79695. int prevlen = -1; /* last emitted length */
  79696. int curlen; /* length of current code */
  79697. int nextlen = tree[0].Len; /* length of next code */
  79698. int count = 0; /* repeat count of the current code */
  79699. int max_count = 7; /* max repeat count */
  79700. int min_count = 4; /* min repeat count */
  79701. /* guard already set */
  79702. if (nextlen == 0) max_count = 138, min_count = 3;
  79703. for (n = 0; n <= max_code; n++) {
  79704. curlen = nextlen; nextlen = tree[n+1].Len;
  79705. if (++count < max_count && curlen == nextlen) {
  79706. continue;
  79707. } else if (count < min_count) {
  79708. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79709. } else if (curlen != 0) {
  79710. if (curlen != prevlen) {
  79711. send_code(s, curlen, s->bl_tree); count--;
  79712. }
  79713. Assert(count >= 3 && count <= 6, " 3_6?");
  79714. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79715. } else if (count <= 10) {
  79716. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79717. } else {
  79718. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79719. }
  79720. count = 0; prevlen = curlen;
  79721. if (nextlen == 0) {
  79722. max_count = 138, min_count = 3;
  79723. } else if (curlen == nextlen) {
  79724. max_count = 6, min_count = 3;
  79725. } else {
  79726. max_count = 7, min_count = 4;
  79727. }
  79728. }
  79729. }
  79730. local int build_bl_tree (deflate_state *s)
  79731. {
  79732. int max_blindex; /* index of last bit length code of non zero freq */
  79733. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79734. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79735. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79736. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79737. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79738. }
  79739. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79740. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79741. s->opt_len, s->static_len));
  79742. return max_blindex;
  79743. }
  79744. local void send_all_trees (deflate_state *s,
  79745. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79746. {
  79747. int rank; /* index in bl_order */
  79748. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79749. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79750. "too many codes");
  79751. Tracev((stderr, "\nbl counts: "));
  79752. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79753. send_bits(s, dcodes-1, 5);
  79754. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79755. for (rank = 0; rank < blcodes; rank++) {
  79756. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79757. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79758. }
  79759. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79760. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79761. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79762. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79763. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79764. }
  79765. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79766. {
  79767. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79768. #ifdef DEBUG
  79769. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79770. s->compressed_len += (stored_len + 4) << 3;
  79771. #endif
  79772. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79773. }
  79774. void _tr_align (deflate_state *s)
  79775. {
  79776. send_bits(s, STATIC_TREES<<1, 3);
  79777. send_code(s, END_BLOCK, static_ltree);
  79778. #ifdef DEBUG
  79779. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79780. #endif
  79781. bi_flush(s);
  79782. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79783. send_bits(s, STATIC_TREES<<1, 3);
  79784. send_code(s, END_BLOCK, static_ltree);
  79785. #ifdef DEBUG
  79786. s->compressed_len += 10L;
  79787. #endif
  79788. bi_flush(s);
  79789. }
  79790. s->last_eob_len = 7;
  79791. }
  79792. void _tr_flush_block (deflate_state *s,
  79793. charf *buf, /* input block, or NULL if too old */
  79794. ulg stored_len, /* length of input block */
  79795. int eof) /* true if this is the last block for a file */
  79796. {
  79797. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79798. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79799. if (s->level > 0) {
  79800. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79801. set_data_type(s);
  79802. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79803. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79804. s->static_len));
  79805. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79806. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79807. s->static_len));
  79808. max_blindex = build_bl_tree(s);
  79809. opt_lenb = (s->opt_len+3+7)>>3;
  79810. static_lenb = (s->static_len+3+7)>>3;
  79811. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79812. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79813. s->last_lit));
  79814. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79815. } else {
  79816. Assert(buf != (char*)0, "lost buf");
  79817. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79818. }
  79819. #ifdef FORCE_STORED
  79820. if (buf != (char*)0) { /* force stored block */
  79821. #else
  79822. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79823. #endif
  79824. _tr_stored_block(s, buf, stored_len, eof);
  79825. #ifdef FORCE_STATIC
  79826. } else if (static_lenb >= 0) { /* force static trees */
  79827. #else
  79828. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79829. #endif
  79830. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79831. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79832. #ifdef DEBUG
  79833. s->compressed_len += 3 + s->static_len;
  79834. #endif
  79835. } else {
  79836. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79837. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79838. max_blindex+1);
  79839. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79840. #ifdef DEBUG
  79841. s->compressed_len += 3 + s->opt_len;
  79842. #endif
  79843. }
  79844. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79845. init_block(s);
  79846. if (eof) {
  79847. bi_windup(s);
  79848. #ifdef DEBUG
  79849. s->compressed_len += 7; /* align on byte boundary */
  79850. #endif
  79851. }
  79852. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79853. s->compressed_len-7*eof));
  79854. }
  79855. int _tr_tally (deflate_state *s,
  79856. unsigned dist, /* distance of matched string */
  79857. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79858. {
  79859. s->d_buf[s->last_lit] = (ush)dist;
  79860. s->l_buf[s->last_lit++] = (uch)lc;
  79861. if (dist == 0) {
  79862. s->dyn_ltree[lc].Freq++;
  79863. } else {
  79864. s->matches++;
  79865. dist--; /* dist = match distance - 1 */
  79866. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79867. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79868. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79869. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79870. s->dyn_dtree[d_code(dist)].Freq++;
  79871. }
  79872. #ifdef TRUNCATE_BLOCK
  79873. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79874. ulg out_length = (ulg)s->last_lit*8L;
  79875. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79876. int dcode;
  79877. for (dcode = 0; dcode < D_CODES; dcode++) {
  79878. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79879. (5L+extra_dbits[dcode]);
  79880. }
  79881. out_length >>= 3;
  79882. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79883. s->last_lit, in_length, out_length,
  79884. 100L - out_length*100L/in_length));
  79885. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79886. }
  79887. #endif
  79888. return (s->last_lit == s->lit_bufsize-1);
  79889. }
  79890. local void compress_block (deflate_state *s,
  79891. ct_data *ltree, /* literal tree */
  79892. ct_data *dtree) /* distance tree */
  79893. {
  79894. unsigned dist; /* distance of matched string */
  79895. int lc; /* match length or unmatched char (if dist == 0) */
  79896. unsigned lx = 0; /* running index in l_buf */
  79897. unsigned code; /* the code to send */
  79898. int extra; /* number of extra bits to send */
  79899. if (s->last_lit != 0) do {
  79900. dist = s->d_buf[lx];
  79901. lc = s->l_buf[lx++];
  79902. if (dist == 0) {
  79903. send_code(s, lc, ltree); /* send a literal byte */
  79904. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79905. } else {
  79906. code = _length_code[lc];
  79907. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79908. extra = extra_lbits[code];
  79909. if (extra != 0) {
  79910. lc -= base_length[code];
  79911. send_bits(s, lc, extra); /* send the extra length bits */
  79912. }
  79913. dist--; /* dist is now the match distance - 1 */
  79914. code = d_code(dist);
  79915. Assert (code < D_CODES, "bad d_code");
  79916. send_code(s, code, dtree); /* send the distance code */
  79917. extra = extra_dbits[code];
  79918. if (extra != 0) {
  79919. dist -= base_dist[code];
  79920. send_bits(s, dist, extra); /* send the extra distance bits */
  79921. }
  79922. } /* literal or match pair ? */
  79923. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  79924. "pendingBuf overflow");
  79925. } while (lx < s->last_lit);
  79926. send_code(s, END_BLOCK, ltree);
  79927. s->last_eob_len = ltree[END_BLOCK].Len;
  79928. }
  79929. local void set_data_type (deflate_state *s)
  79930. {
  79931. int n;
  79932. for (n = 0; n < 9; n++)
  79933. if (s->dyn_ltree[n].Freq != 0)
  79934. break;
  79935. if (n == 9)
  79936. for (n = 14; n < 32; n++)
  79937. if (s->dyn_ltree[n].Freq != 0)
  79938. break;
  79939. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  79940. }
  79941. local unsigned bi_reverse (unsigned code, int len)
  79942. {
  79943. register unsigned res = 0;
  79944. do {
  79945. res |= code & 1;
  79946. code >>= 1, res <<= 1;
  79947. } while (--len > 0);
  79948. return res >> 1;
  79949. }
  79950. local void bi_flush (deflate_state *s)
  79951. {
  79952. if (s->bi_valid == 16) {
  79953. put_short(s, s->bi_buf);
  79954. s->bi_buf = 0;
  79955. s->bi_valid = 0;
  79956. } else if (s->bi_valid >= 8) {
  79957. put_byte(s, (Byte)s->bi_buf);
  79958. s->bi_buf >>= 8;
  79959. s->bi_valid -= 8;
  79960. }
  79961. }
  79962. local void bi_windup (deflate_state *s)
  79963. {
  79964. if (s->bi_valid > 8) {
  79965. put_short(s, s->bi_buf);
  79966. } else if (s->bi_valid > 0) {
  79967. put_byte(s, (Byte)s->bi_buf);
  79968. }
  79969. s->bi_buf = 0;
  79970. s->bi_valid = 0;
  79971. #ifdef DEBUG
  79972. s->bits_sent = (s->bits_sent+7) & ~7;
  79973. #endif
  79974. }
  79975. local void copy_block(deflate_state *s,
  79976. charf *buf, /* the input data */
  79977. unsigned len, /* its length */
  79978. int header) /* true if block header must be written */
  79979. {
  79980. bi_windup(s); /* align on byte boundary */
  79981. s->last_eob_len = 8; /* enough lookahead for inflate */
  79982. if (header) {
  79983. put_short(s, (ush)len);
  79984. put_short(s, (ush)~len);
  79985. #ifdef DEBUG
  79986. s->bits_sent += 2*16;
  79987. #endif
  79988. }
  79989. #ifdef DEBUG
  79990. s->bits_sent += (ulg)len<<3;
  79991. #endif
  79992. while (len--) {
  79993. put_byte(s, *buf++);
  79994. }
  79995. }
  79996. /*** End of inlined file: trees.c ***/
  79997. /*** Start of inlined file: zutil.c ***/
  79998. #ifndef NO_DUMMY_DECL
  79999. struct internal_state {int dummy;}; /* for buggy compilers */
  80000. #endif
  80001. const char * const z_errmsg[10] = {
  80002. "need dictionary", /* Z_NEED_DICT 2 */
  80003. "stream end", /* Z_STREAM_END 1 */
  80004. "", /* Z_OK 0 */
  80005. "file error", /* Z_ERRNO (-1) */
  80006. "stream error", /* Z_STREAM_ERROR (-2) */
  80007. "data error", /* Z_DATA_ERROR (-3) */
  80008. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80009. "buffer error", /* Z_BUF_ERROR (-5) */
  80010. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80011. ""};
  80012. #ifdef DEBUG
  80013. # ifndef verbose
  80014. # define verbose 0
  80015. # endif
  80016. int z_verbose = verbose;
  80017. void z_error (const char *m)
  80018. {
  80019. fprintf(stderr, "%s\n", m);
  80020. exit(1);
  80021. }
  80022. #endif
  80023. const char * ZEXPORT zError(int err)
  80024. {
  80025. return ERR_MSG(err);
  80026. }
  80027. #if defined(_WIN32_WCE)
  80028. int errno = 0;
  80029. #endif
  80030. #ifndef HAVE_MEMCPY
  80031. void zmemcpy(dest, source, len)
  80032. Bytef* dest;
  80033. const Bytef* source;
  80034. uInt len;
  80035. {
  80036. if (len == 0) return;
  80037. do {
  80038. *dest++ = *source++; /* ??? to be unrolled */
  80039. } while (--len != 0);
  80040. }
  80041. int zmemcmp(s1, s2, len)
  80042. const Bytef* s1;
  80043. const Bytef* s2;
  80044. uInt len;
  80045. {
  80046. uInt j;
  80047. for (j = 0; j < len; j++) {
  80048. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80049. }
  80050. return 0;
  80051. }
  80052. void zmemzero(dest, len)
  80053. Bytef* dest;
  80054. uInt len;
  80055. {
  80056. if (len == 0) return;
  80057. do {
  80058. *dest++ = 0; /* ??? to be unrolled */
  80059. } while (--len != 0);
  80060. }
  80061. #endif
  80062. #ifdef SYS16BIT
  80063. #ifdef __TURBOC__
  80064. # define MY_ZCALLOC
  80065. #define MAX_PTR 10
  80066. local int next_ptr = 0;
  80067. typedef struct ptr_table_s {
  80068. voidpf org_ptr;
  80069. voidpf new_ptr;
  80070. } ptr_table;
  80071. local ptr_table table[MAX_PTR];
  80072. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80073. {
  80074. voidpf buf = opaque; /* just to make some compilers happy */
  80075. ulg bsize = (ulg)items*size;
  80076. if (bsize < 65520L) {
  80077. buf = farmalloc(bsize);
  80078. if (*(ush*)&buf != 0) return buf;
  80079. } else {
  80080. buf = farmalloc(bsize + 16L);
  80081. }
  80082. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80083. table[next_ptr].org_ptr = buf;
  80084. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80085. *(ush*)&buf = 0;
  80086. table[next_ptr++].new_ptr = buf;
  80087. return buf;
  80088. }
  80089. void zcfree (voidpf opaque, voidpf ptr)
  80090. {
  80091. int n;
  80092. if (*(ush*)&ptr != 0) { /* object < 64K */
  80093. farfree(ptr);
  80094. return;
  80095. }
  80096. for (n = 0; n < next_ptr; n++) {
  80097. if (ptr != table[n].new_ptr) continue;
  80098. farfree(table[n].org_ptr);
  80099. while (++n < next_ptr) {
  80100. table[n-1] = table[n];
  80101. }
  80102. next_ptr--;
  80103. return;
  80104. }
  80105. ptr = opaque; /* just to make some compilers happy */
  80106. Assert(0, "zcfree: ptr not found");
  80107. }
  80108. #endif /* __TURBOC__ */
  80109. #ifdef M_I86
  80110. # define MY_ZCALLOC
  80111. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80112. # define _halloc halloc
  80113. # define _hfree hfree
  80114. #endif
  80115. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80116. {
  80117. if (opaque) opaque = 0; /* to make compiler happy */
  80118. return _halloc((long)items, size);
  80119. }
  80120. void zcfree (voidpf opaque, voidpf ptr)
  80121. {
  80122. if (opaque) opaque = 0; /* to make compiler happy */
  80123. _hfree(ptr);
  80124. }
  80125. #endif /* M_I86 */
  80126. #endif /* SYS16BIT */
  80127. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80128. #ifndef STDC
  80129. extern voidp malloc OF((uInt size));
  80130. extern voidp calloc OF((uInt items, uInt size));
  80131. extern void free OF((voidpf ptr));
  80132. #endif
  80133. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80134. {
  80135. if (opaque) items += size - size; /* make compiler happy */
  80136. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80137. (voidpf)calloc(items, size);
  80138. }
  80139. void zcfree (voidpf opaque, voidpf ptr)
  80140. {
  80141. free(ptr);
  80142. if (opaque) return; /* make compiler happy */
  80143. }
  80144. #endif /* MY_ZCALLOC */
  80145. /*** End of inlined file: zutil.c ***/
  80146. #undef Byte
  80147. }
  80148. #else
  80149. #include <zlib.h>
  80150. #endif
  80151. }
  80152. #if JUCE_MSVC
  80153. #pragma warning (pop)
  80154. #endif
  80155. BEGIN_JUCE_NAMESPACE
  80156. // internal helper object that holds the zlib structures so they don't have to be
  80157. // included publicly.
  80158. class GZIPDecompressHelper
  80159. {
  80160. public:
  80161. GZIPDecompressHelper (const bool noWrap)
  80162. : finished (true),
  80163. needsDictionary (false),
  80164. error (true),
  80165. streamIsValid (false),
  80166. data (0),
  80167. dataSize (0)
  80168. {
  80169. using namespace zlibNamespace;
  80170. zerostruct (stream);
  80171. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80172. finished = error = ! streamIsValid;
  80173. }
  80174. ~GZIPDecompressHelper()
  80175. {
  80176. using namespace zlibNamespace;
  80177. if (streamIsValid)
  80178. inflateEnd (&stream);
  80179. }
  80180. bool needsInput() const throw() { return dataSize <= 0; }
  80181. void setInput (uint8* const data_, const int size) throw()
  80182. {
  80183. data = data_;
  80184. dataSize = size;
  80185. }
  80186. int doNextBlock (uint8* const dest, const int destSize)
  80187. {
  80188. using namespace zlibNamespace;
  80189. if (streamIsValid && data != 0 && ! finished)
  80190. {
  80191. stream.next_in = data;
  80192. stream.next_out = dest;
  80193. stream.avail_in = dataSize;
  80194. stream.avail_out = destSize;
  80195. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80196. {
  80197. case Z_STREAM_END:
  80198. finished = true;
  80199. // deliberate fall-through
  80200. case Z_OK:
  80201. data += dataSize - stream.avail_in;
  80202. dataSize = stream.avail_in;
  80203. return destSize - stream.avail_out;
  80204. case Z_NEED_DICT:
  80205. needsDictionary = true;
  80206. data += dataSize - stream.avail_in;
  80207. dataSize = stream.avail_in;
  80208. break;
  80209. case Z_DATA_ERROR:
  80210. case Z_MEM_ERROR:
  80211. error = true;
  80212. default:
  80213. break;
  80214. }
  80215. }
  80216. return 0;
  80217. }
  80218. bool finished, needsDictionary, error, streamIsValid;
  80219. private:
  80220. zlibNamespace::z_stream stream;
  80221. uint8* data;
  80222. int dataSize;
  80223. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80224. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80225. };
  80226. const int gzipDecompBufferSize = 32768;
  80227. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80228. const bool deleteSourceWhenDestroyed,
  80229. const bool noWrap_,
  80230. const int64 uncompressedStreamLength_)
  80231. : sourceStream (sourceStream_),
  80232. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80233. uncompressedStreamLength (uncompressedStreamLength_),
  80234. noWrap (noWrap_),
  80235. isEof (false),
  80236. activeBufferSize (0),
  80237. originalSourcePos (sourceStream_->getPosition()),
  80238. currentPos (0),
  80239. buffer (gzipDecompBufferSize),
  80240. helper (new GZIPDecompressHelper (noWrap_))
  80241. {
  80242. }
  80243. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80244. {
  80245. }
  80246. int64 GZIPDecompressorInputStream::getTotalLength()
  80247. {
  80248. return uncompressedStreamLength;
  80249. }
  80250. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80251. {
  80252. if ((howMany > 0) && ! isEof)
  80253. {
  80254. jassert (destBuffer != 0);
  80255. if (destBuffer != 0)
  80256. {
  80257. int numRead = 0;
  80258. uint8* d = static_cast <uint8*> (destBuffer);
  80259. while (! helper->error)
  80260. {
  80261. const int n = helper->doNextBlock (d, howMany);
  80262. currentPos += n;
  80263. if (n == 0)
  80264. {
  80265. if (helper->finished || helper->needsDictionary)
  80266. {
  80267. isEof = true;
  80268. return numRead;
  80269. }
  80270. if (helper->needsInput())
  80271. {
  80272. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80273. if (activeBufferSize > 0)
  80274. {
  80275. helper->setInput (buffer, activeBufferSize);
  80276. }
  80277. else
  80278. {
  80279. isEof = true;
  80280. return numRead;
  80281. }
  80282. }
  80283. }
  80284. else
  80285. {
  80286. numRead += n;
  80287. howMany -= n;
  80288. d += n;
  80289. if (howMany <= 0)
  80290. return numRead;
  80291. }
  80292. }
  80293. }
  80294. }
  80295. return 0;
  80296. }
  80297. bool GZIPDecompressorInputStream::isExhausted()
  80298. {
  80299. return helper->error || isEof;
  80300. }
  80301. int64 GZIPDecompressorInputStream::getPosition()
  80302. {
  80303. return currentPos;
  80304. }
  80305. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80306. {
  80307. if (newPos < currentPos)
  80308. {
  80309. // to go backwards, reset the stream and start again..
  80310. isEof = false;
  80311. activeBufferSize = 0;
  80312. currentPos = 0;
  80313. helper = new GZIPDecompressHelper (noWrap);
  80314. sourceStream->setPosition (originalSourcePos);
  80315. }
  80316. skipNextBytes (newPos - currentPos);
  80317. return true;
  80318. }
  80319. END_JUCE_NAMESPACE
  80320. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80321. #endif
  80322. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80323. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80324. #if JUCE_USE_FLAC
  80325. #if JUCE_WINDOWS
  80326. #include <windows.h>
  80327. #endif
  80328. #ifdef _MSC_VER
  80329. #pragma warning (disable : 4505)
  80330. #pragma warning (push)
  80331. #endif
  80332. namespace FlacNamespace
  80333. {
  80334. #if JUCE_INCLUDE_FLAC_CODE
  80335. #define FLAC__NO_DLL 1
  80336. #if ! defined (SIZE_MAX)
  80337. #define SIZE_MAX 0xffffffff
  80338. #endif
  80339. #define __STDC_LIMIT_MACROS 1
  80340. /*** Start of inlined file: all.h ***/
  80341. #ifndef FLAC__ALL_H
  80342. #define FLAC__ALL_H
  80343. /*** Start of inlined file: export.h ***/
  80344. #ifndef FLAC__EXPORT_H
  80345. #define FLAC__EXPORT_H
  80346. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80347. #define FLAC_API
  80348. #else
  80349. #ifdef FLAC_API_EXPORTS
  80350. #define FLAC_API _declspec(dllexport)
  80351. #else
  80352. #define FLAC_API _declspec(dllimport)
  80353. #endif
  80354. #endif
  80355. #define FLAC_API_VERSION_CURRENT 10
  80356. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80357. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80358. #ifdef __cplusplus
  80359. extern "C" {
  80360. #endif
  80361. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80362. #ifdef __cplusplus
  80363. }
  80364. #endif
  80365. #endif
  80366. /*** End of inlined file: export.h ***/
  80367. /*** Start of inlined file: assert.h ***/
  80368. #ifndef FLAC__ASSERT_H
  80369. #define FLAC__ASSERT_H
  80370. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80371. #ifdef DEBUG
  80372. #include <assert.h>
  80373. #define FLAC__ASSERT(x) assert(x)
  80374. #define FLAC__ASSERT_DECLARATION(x) x
  80375. #else
  80376. #define FLAC__ASSERT(x)
  80377. #define FLAC__ASSERT_DECLARATION(x)
  80378. #endif
  80379. #endif
  80380. /*** End of inlined file: assert.h ***/
  80381. /*** Start of inlined file: callback.h ***/
  80382. #ifndef FLAC__CALLBACK_H
  80383. #define FLAC__CALLBACK_H
  80384. /*** Start of inlined file: ordinals.h ***/
  80385. #ifndef FLAC__ORDINALS_H
  80386. #define FLAC__ORDINALS_H
  80387. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80388. #include <inttypes.h>
  80389. #endif
  80390. typedef signed char FLAC__int8;
  80391. typedef unsigned char FLAC__uint8;
  80392. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80393. typedef __int16 FLAC__int16;
  80394. typedef __int32 FLAC__int32;
  80395. typedef __int64 FLAC__int64;
  80396. typedef unsigned __int16 FLAC__uint16;
  80397. typedef unsigned __int32 FLAC__uint32;
  80398. typedef unsigned __int64 FLAC__uint64;
  80399. #elif defined(__EMX__)
  80400. typedef short FLAC__int16;
  80401. typedef long FLAC__int32;
  80402. typedef long long FLAC__int64;
  80403. typedef unsigned short FLAC__uint16;
  80404. typedef unsigned long FLAC__uint32;
  80405. typedef unsigned long long FLAC__uint64;
  80406. #else
  80407. typedef int16_t FLAC__int16;
  80408. typedef int32_t FLAC__int32;
  80409. typedef int64_t FLAC__int64;
  80410. typedef uint16_t FLAC__uint16;
  80411. typedef uint32_t FLAC__uint32;
  80412. typedef uint64_t FLAC__uint64;
  80413. #endif
  80414. typedef int FLAC__bool;
  80415. typedef FLAC__uint8 FLAC__byte;
  80416. #ifdef true
  80417. #undef true
  80418. #endif
  80419. #ifdef false
  80420. #undef false
  80421. #endif
  80422. #ifndef __cplusplus
  80423. #define true 1
  80424. #define false 0
  80425. #endif
  80426. #endif
  80427. /*** End of inlined file: ordinals.h ***/
  80428. #include <stdlib.h> /* for size_t */
  80429. #ifdef __cplusplus
  80430. extern "C" {
  80431. #endif
  80432. typedef void* FLAC__IOHandle;
  80433. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80434. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80435. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80436. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80437. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80438. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80439. typedef struct {
  80440. FLAC__IOCallback_Read read;
  80441. FLAC__IOCallback_Write write;
  80442. FLAC__IOCallback_Seek seek;
  80443. FLAC__IOCallback_Tell tell;
  80444. FLAC__IOCallback_Eof eof;
  80445. FLAC__IOCallback_Close close;
  80446. } FLAC__IOCallbacks;
  80447. #ifdef __cplusplus
  80448. }
  80449. #endif
  80450. #endif
  80451. /*** End of inlined file: callback.h ***/
  80452. /*** Start of inlined file: format.h ***/
  80453. #ifndef FLAC__FORMAT_H
  80454. #define FLAC__FORMAT_H
  80455. #ifdef __cplusplus
  80456. extern "C" {
  80457. #endif
  80458. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80459. #define FLAC__MIN_BLOCK_SIZE (16u)
  80460. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80461. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80462. #define FLAC__MAX_CHANNELS (8u)
  80463. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80464. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80465. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80466. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80467. #define FLAC__MAX_LPC_ORDER (32u)
  80468. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80469. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80470. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80471. #define FLAC__MAX_FIXED_ORDER (4u)
  80472. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80473. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80474. extern FLAC_API const char *FLAC__VERSION_STRING;
  80475. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80476. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80477. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80478. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80479. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80480. typedef enum {
  80481. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80482. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80483. } FLAC__EntropyCodingMethodType;
  80484. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80485. typedef struct {
  80486. unsigned *parameters;
  80487. unsigned *raw_bits;
  80488. unsigned capacity_by_order;
  80489. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80490. typedef struct {
  80491. unsigned order;
  80492. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80493. } FLAC__EntropyCodingMethod_PartitionedRice;
  80494. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80495. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80496. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80497. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80498. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80499. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80500. typedef struct {
  80501. FLAC__EntropyCodingMethodType type;
  80502. union {
  80503. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80504. } data;
  80505. } FLAC__EntropyCodingMethod;
  80506. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80507. typedef enum {
  80508. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80509. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80510. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80511. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80512. } FLAC__SubframeType;
  80513. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80514. typedef struct {
  80515. FLAC__int32 value; /**< The constant signal value. */
  80516. } FLAC__Subframe_Constant;
  80517. typedef struct {
  80518. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80519. } FLAC__Subframe_Verbatim;
  80520. typedef struct {
  80521. FLAC__EntropyCodingMethod entropy_coding_method;
  80522. unsigned order;
  80523. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80524. const FLAC__int32 *residual;
  80525. } FLAC__Subframe_Fixed;
  80526. typedef struct {
  80527. FLAC__EntropyCodingMethod entropy_coding_method;
  80528. unsigned order;
  80529. unsigned qlp_coeff_precision;
  80530. int quantization_level;
  80531. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80532. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80533. const FLAC__int32 *residual;
  80534. } FLAC__Subframe_LPC;
  80535. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80536. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80537. typedef struct {
  80538. FLAC__SubframeType type;
  80539. union {
  80540. FLAC__Subframe_Constant constant;
  80541. FLAC__Subframe_Fixed fixed;
  80542. FLAC__Subframe_LPC lpc;
  80543. FLAC__Subframe_Verbatim verbatim;
  80544. } data;
  80545. unsigned wasted_bits;
  80546. } FLAC__Subframe;
  80547. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80548. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80549. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80550. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80551. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80552. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80553. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80554. typedef enum {
  80555. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80556. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80557. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80558. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80559. } FLAC__ChannelAssignment;
  80560. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80561. typedef enum {
  80562. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80563. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80564. } FLAC__FrameNumberType;
  80565. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80566. typedef struct {
  80567. unsigned blocksize;
  80568. unsigned sample_rate;
  80569. unsigned channels;
  80570. FLAC__ChannelAssignment channel_assignment;
  80571. unsigned bits_per_sample;
  80572. FLAC__FrameNumberType number_type;
  80573. union {
  80574. FLAC__uint32 frame_number;
  80575. FLAC__uint64 sample_number;
  80576. } number;
  80577. FLAC__uint8 crc;
  80578. } FLAC__FrameHeader;
  80579. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80580. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80581. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80582. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80583. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80584. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80585. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80586. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80587. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80588. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80589. typedef struct {
  80590. FLAC__uint16 crc;
  80591. } FLAC__FrameFooter;
  80592. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80593. typedef struct {
  80594. FLAC__FrameHeader header;
  80595. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80596. FLAC__FrameFooter footer;
  80597. } FLAC__Frame;
  80598. typedef enum {
  80599. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80600. FLAC__METADATA_TYPE_PADDING = 1,
  80601. FLAC__METADATA_TYPE_APPLICATION = 2,
  80602. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80603. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80604. FLAC__METADATA_TYPE_CUESHEET = 5,
  80605. FLAC__METADATA_TYPE_PICTURE = 6,
  80606. FLAC__METADATA_TYPE_UNDEFINED = 7
  80607. } FLAC__MetadataType;
  80608. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80609. typedef struct {
  80610. unsigned min_blocksize, max_blocksize;
  80611. unsigned min_framesize, max_framesize;
  80612. unsigned sample_rate;
  80613. unsigned channels;
  80614. unsigned bits_per_sample;
  80615. FLAC__uint64 total_samples;
  80616. FLAC__byte md5sum[16];
  80617. } FLAC__StreamMetadata_StreamInfo;
  80618. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80619. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80620. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80621. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80622. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80623. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80624. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80625. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80626. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80627. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80628. typedef struct {
  80629. int dummy;
  80630. } FLAC__StreamMetadata_Padding;
  80631. typedef struct {
  80632. FLAC__byte id[4];
  80633. FLAC__byte *data;
  80634. } FLAC__StreamMetadata_Application;
  80635. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80636. typedef struct {
  80637. FLAC__uint64 sample_number;
  80638. FLAC__uint64 stream_offset;
  80639. unsigned frame_samples;
  80640. } FLAC__StreamMetadata_SeekPoint;
  80641. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80642. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80643. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80644. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80645. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80646. typedef struct {
  80647. unsigned num_points;
  80648. FLAC__StreamMetadata_SeekPoint *points;
  80649. } FLAC__StreamMetadata_SeekTable;
  80650. typedef struct {
  80651. FLAC__uint32 length;
  80652. FLAC__byte *entry;
  80653. } FLAC__StreamMetadata_VorbisComment_Entry;
  80654. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80655. typedef struct {
  80656. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80657. FLAC__uint32 num_comments;
  80658. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80659. } FLAC__StreamMetadata_VorbisComment;
  80660. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80661. typedef struct {
  80662. FLAC__uint64 offset;
  80663. FLAC__byte number;
  80664. } FLAC__StreamMetadata_CueSheet_Index;
  80665. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80666. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80667. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80668. typedef struct {
  80669. FLAC__uint64 offset;
  80670. FLAC__byte number;
  80671. char isrc[13];
  80672. unsigned type:1;
  80673. unsigned pre_emphasis:1;
  80674. FLAC__byte num_indices;
  80675. FLAC__StreamMetadata_CueSheet_Index *indices;
  80676. } FLAC__StreamMetadata_CueSheet_Track;
  80677. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80678. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80679. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80680. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80681. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80682. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80683. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80684. typedef struct {
  80685. char media_catalog_number[129];
  80686. FLAC__uint64 lead_in;
  80687. FLAC__bool is_cd;
  80688. unsigned num_tracks;
  80689. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80690. } FLAC__StreamMetadata_CueSheet;
  80691. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80692. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80693. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80694. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80695. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80696. typedef enum {
  80697. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80698. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80699. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80700. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80701. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80702. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80703. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80704. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80705. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80706. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80707. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80708. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80709. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80710. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80711. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80712. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80713. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80714. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80715. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80716. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80717. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80718. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80719. } FLAC__StreamMetadata_Picture_Type;
  80720. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80721. typedef struct {
  80722. FLAC__StreamMetadata_Picture_Type type;
  80723. char *mime_type;
  80724. FLAC__byte *description;
  80725. FLAC__uint32 width;
  80726. FLAC__uint32 height;
  80727. FLAC__uint32 depth;
  80728. FLAC__uint32 colors;
  80729. FLAC__uint32 data_length;
  80730. FLAC__byte *data;
  80731. } FLAC__StreamMetadata_Picture;
  80732. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80733. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80734. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80735. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80736. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80737. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80738. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80739. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80740. typedef struct {
  80741. FLAC__byte *data;
  80742. } FLAC__StreamMetadata_Unknown;
  80743. typedef struct {
  80744. FLAC__MetadataType type;
  80745. FLAC__bool is_last;
  80746. unsigned length;
  80747. union {
  80748. FLAC__StreamMetadata_StreamInfo stream_info;
  80749. FLAC__StreamMetadata_Padding padding;
  80750. FLAC__StreamMetadata_Application application;
  80751. FLAC__StreamMetadata_SeekTable seek_table;
  80752. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80753. FLAC__StreamMetadata_CueSheet cue_sheet;
  80754. FLAC__StreamMetadata_Picture picture;
  80755. FLAC__StreamMetadata_Unknown unknown;
  80756. } data;
  80757. } FLAC__StreamMetadata;
  80758. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80759. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80761. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80762. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80763. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80764. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80765. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80766. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80767. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80768. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80769. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80770. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80771. #ifdef __cplusplus
  80772. }
  80773. #endif
  80774. #endif
  80775. /*** End of inlined file: format.h ***/
  80776. /*** Start of inlined file: metadata.h ***/
  80777. #ifndef FLAC__METADATA_H
  80778. #define FLAC__METADATA_H
  80779. #include <sys/types.h> /* for off_t */
  80780. #ifdef __cplusplus
  80781. extern "C" {
  80782. #endif
  80783. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80784. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80785. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80786. 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);
  80787. struct FLAC__Metadata_SimpleIterator;
  80788. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80789. typedef enum {
  80790. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80791. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80792. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80793. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80794. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80795. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80796. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80797. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80798. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80799. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80800. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80801. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80802. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80803. } FLAC__Metadata_SimpleIteratorStatus;
  80804. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80805. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80806. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80807. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80808. 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);
  80809. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80810. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80811. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80812. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80813. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80814. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80815. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80816. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80817. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80818. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80819. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80820. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80821. struct FLAC__Metadata_Chain;
  80822. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80823. struct FLAC__Metadata_Iterator;
  80824. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80825. typedef enum {
  80826. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80827. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80828. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80829. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80830. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80831. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80832. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80833. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80834. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80835. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80836. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80837. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80838. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80839. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80840. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80841. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80842. } FLAC__Metadata_ChainStatus;
  80843. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80844. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80845. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80846. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80847. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80848. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80849. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80850. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80851. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80852. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80853. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80854. 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);
  80855. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80856. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80857. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80858. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80859. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80860. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80861. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80862. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80863. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80864. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80865. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80866. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80867. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80868. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80869. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80870. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80871. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80872. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80873. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80874. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80875. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80876. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80877. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80878. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80879. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80880. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80881. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80882. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80883. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80884. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80885. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80886. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80887. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80888. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80889. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80890. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80891. 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);
  80892. 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);
  80893. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80894. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80895. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80896. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80897. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80898. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80899. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80900. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80901. 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);
  80902. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80903. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80904. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80905. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80906. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80907. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80908. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80909. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80910. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80911. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80912. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80913. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80914. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80915. #ifdef __cplusplus
  80916. }
  80917. #endif
  80918. #endif
  80919. /*** End of inlined file: metadata.h ***/
  80920. /*** Start of inlined file: stream_decoder.h ***/
  80921. #ifndef FLAC__STREAM_DECODER_H
  80922. #define FLAC__STREAM_DECODER_H
  80923. #include <stdio.h> /* for FILE */
  80924. #ifdef __cplusplus
  80925. extern "C" {
  80926. #endif
  80927. typedef enum {
  80928. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  80929. FLAC__STREAM_DECODER_READ_METADATA,
  80930. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  80931. FLAC__STREAM_DECODER_READ_FRAME,
  80932. FLAC__STREAM_DECODER_END_OF_STREAM,
  80933. FLAC__STREAM_DECODER_OGG_ERROR,
  80934. FLAC__STREAM_DECODER_SEEK_ERROR,
  80935. FLAC__STREAM_DECODER_ABORTED,
  80936. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  80937. FLAC__STREAM_DECODER_UNINITIALIZED
  80938. } FLAC__StreamDecoderState;
  80939. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  80940. typedef enum {
  80941. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  80942. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  80943. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  80944. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  80945. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  80946. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  80947. } FLAC__StreamDecoderInitStatus;
  80948. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  80949. typedef enum {
  80950. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  80951. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  80952. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  80953. } FLAC__StreamDecoderReadStatus;
  80954. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  80955. typedef enum {
  80956. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  80957. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  80958. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  80959. } FLAC__StreamDecoderSeekStatus;
  80960. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  80961. typedef enum {
  80962. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  80963. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  80964. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  80965. } FLAC__StreamDecoderTellStatus;
  80966. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  80967. typedef enum {
  80968. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  80969. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  80970. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  80971. } FLAC__StreamDecoderLengthStatus;
  80972. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  80973. typedef enum {
  80974. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  80975. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  80976. } FLAC__StreamDecoderWriteStatus;
  80977. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  80978. typedef enum {
  80979. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  80980. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  80981. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  80982. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  80983. } FLAC__StreamDecoderErrorStatus;
  80984. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  80985. struct FLAC__StreamDecoderProtected;
  80986. struct FLAC__StreamDecoderPrivate;
  80987. typedef struct {
  80988. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  80989. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  80990. } FLAC__StreamDecoder;
  80991. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  80992. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  80993. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  80994. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  80995. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  80996. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  80997. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  80998. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  80999. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81000. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81001. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81002. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81003. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81004. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81005. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81006. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81007. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81008. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81009. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81010. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81011. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81012. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81013. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81014. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81015. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81016. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81017. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81018. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81019. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81020. FLAC__StreamDecoder *decoder,
  81021. FLAC__StreamDecoderReadCallback read_callback,
  81022. FLAC__StreamDecoderSeekCallback seek_callback,
  81023. FLAC__StreamDecoderTellCallback tell_callback,
  81024. FLAC__StreamDecoderLengthCallback length_callback,
  81025. FLAC__StreamDecoderEofCallback eof_callback,
  81026. FLAC__StreamDecoderWriteCallback write_callback,
  81027. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81028. FLAC__StreamDecoderErrorCallback error_callback,
  81029. void *client_data
  81030. );
  81031. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81032. FLAC__StreamDecoder *decoder,
  81033. FLAC__StreamDecoderReadCallback read_callback,
  81034. FLAC__StreamDecoderSeekCallback seek_callback,
  81035. FLAC__StreamDecoderTellCallback tell_callback,
  81036. FLAC__StreamDecoderLengthCallback length_callback,
  81037. FLAC__StreamDecoderEofCallback eof_callback,
  81038. FLAC__StreamDecoderWriteCallback write_callback,
  81039. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81040. FLAC__StreamDecoderErrorCallback error_callback,
  81041. void *client_data
  81042. );
  81043. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81044. FLAC__StreamDecoder *decoder,
  81045. FILE *file,
  81046. FLAC__StreamDecoderWriteCallback write_callback,
  81047. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81048. FLAC__StreamDecoderErrorCallback error_callback,
  81049. void *client_data
  81050. );
  81051. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81052. FLAC__StreamDecoder *decoder,
  81053. FILE *file,
  81054. FLAC__StreamDecoderWriteCallback write_callback,
  81055. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81056. FLAC__StreamDecoderErrorCallback error_callback,
  81057. void *client_data
  81058. );
  81059. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81060. FLAC__StreamDecoder *decoder,
  81061. const char *filename,
  81062. FLAC__StreamDecoderWriteCallback write_callback,
  81063. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81064. FLAC__StreamDecoderErrorCallback error_callback,
  81065. void *client_data
  81066. );
  81067. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81068. FLAC__StreamDecoder *decoder,
  81069. const char *filename,
  81070. FLAC__StreamDecoderWriteCallback write_callback,
  81071. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81072. FLAC__StreamDecoderErrorCallback error_callback,
  81073. void *client_data
  81074. );
  81075. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81076. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81077. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81078. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81079. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81080. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81081. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81082. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81083. #ifdef __cplusplus
  81084. }
  81085. #endif
  81086. #endif
  81087. /*** End of inlined file: stream_decoder.h ***/
  81088. /*** Start of inlined file: stream_encoder.h ***/
  81089. #ifndef FLAC__STREAM_ENCODER_H
  81090. #define FLAC__STREAM_ENCODER_H
  81091. #include <stdio.h> /* for FILE */
  81092. #ifdef __cplusplus
  81093. extern "C" {
  81094. #endif
  81095. typedef enum {
  81096. FLAC__STREAM_ENCODER_OK = 0,
  81097. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81098. FLAC__STREAM_ENCODER_OGG_ERROR,
  81099. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81100. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81101. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81102. FLAC__STREAM_ENCODER_IO_ERROR,
  81103. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81104. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81105. } FLAC__StreamEncoderState;
  81106. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81107. typedef enum {
  81108. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81109. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81110. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81111. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81112. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81113. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81114. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81115. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81116. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81117. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81118. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81119. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81120. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81121. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81122. } FLAC__StreamEncoderInitStatus;
  81123. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81124. typedef enum {
  81125. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81126. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81127. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81128. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81129. } FLAC__StreamEncoderReadStatus;
  81130. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81131. typedef enum {
  81132. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81133. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81134. } FLAC__StreamEncoderWriteStatus;
  81135. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81136. typedef enum {
  81137. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81138. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81139. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81140. } FLAC__StreamEncoderSeekStatus;
  81141. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81142. typedef enum {
  81143. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81144. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81145. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81146. } FLAC__StreamEncoderTellStatus;
  81147. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81148. struct FLAC__StreamEncoderProtected;
  81149. struct FLAC__StreamEncoderPrivate;
  81150. typedef struct {
  81151. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81152. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81153. } FLAC__StreamEncoder;
  81154. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81155. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81156. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81157. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81158. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81159. 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);
  81160. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81161. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81162. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81163. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81164. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81165. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81166. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81167. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81168. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81169. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81170. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81171. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81172. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81173. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81174. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81175. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81176. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81177. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81178. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81179. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81180. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81181. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81182. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81183. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81184. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81185. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81186. 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);
  81187. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81188. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81189. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81190. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81191. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81192. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81193. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81194. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81195. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81196. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81197. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81198. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81199. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81200. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81201. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81202. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81203. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81204. 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);
  81205. 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);
  81206. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81207. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81208. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81209. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81210. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81211. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81212. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81213. #ifdef __cplusplus
  81214. }
  81215. #endif
  81216. #endif
  81217. /*** End of inlined file: stream_encoder.h ***/
  81218. #ifdef _MSC_VER
  81219. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81220. {
  81221. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81222. return (x>>16) | (x<<16);
  81223. }
  81224. #endif
  81225. #if defined(_MSC_VER) && defined(_X86_)
  81226. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81227. {
  81228. __asm {
  81229. mov edx, start
  81230. mov ecx, len
  81231. test ecx, ecx
  81232. loop1:
  81233. jz done1
  81234. mov eax, [edx]
  81235. bswap eax
  81236. mov [edx], eax
  81237. add edx, 4
  81238. dec ecx
  81239. jmp short loop1
  81240. done1:
  81241. }
  81242. }
  81243. #endif
  81244. #endif
  81245. /*** End of inlined file: all.h ***/
  81246. /*** Start of inlined file: bitmath.c ***/
  81247. /*** Start of inlined file: juce_FlacHeader.h ***/
  81248. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81249. // tasks..
  81250. #define VERSION "1.2.1"
  81251. #define FLAC__NO_DLL 1
  81252. #if JUCE_MSVC
  81253. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81254. #endif
  81255. #if JUCE_MAC
  81256. #define FLAC__SYS_DARWIN 1
  81257. #endif
  81258. /*** End of inlined file: juce_FlacHeader.h ***/
  81259. #if JUCE_USE_FLAC
  81260. #if HAVE_CONFIG_H
  81261. # include <config.h>
  81262. #endif
  81263. /*** Start of inlined file: bitmath.h ***/
  81264. #ifndef FLAC__PRIVATE__BITMATH_H
  81265. #define FLAC__PRIVATE__BITMATH_H
  81266. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81267. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81268. unsigned FLAC__bitmath_silog2(int v);
  81269. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81270. #endif
  81271. /*** End of inlined file: bitmath.h ***/
  81272. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81273. {
  81274. unsigned l = 0;
  81275. FLAC__ASSERT(v > 0);
  81276. while(v >>= 1)
  81277. l++;
  81278. return l;
  81279. }
  81280. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81281. {
  81282. unsigned l = 0;
  81283. FLAC__ASSERT(v > 0);
  81284. while(v >>= 1)
  81285. l++;
  81286. return l;
  81287. }
  81288. unsigned FLAC__bitmath_silog2(int v)
  81289. {
  81290. while(1) {
  81291. if(v == 0) {
  81292. return 0;
  81293. }
  81294. else if(v > 0) {
  81295. unsigned l = 0;
  81296. while(v) {
  81297. l++;
  81298. v >>= 1;
  81299. }
  81300. return l+1;
  81301. }
  81302. else if(v == -1) {
  81303. return 2;
  81304. }
  81305. else {
  81306. v++;
  81307. v = -v;
  81308. }
  81309. }
  81310. }
  81311. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81312. {
  81313. while(1) {
  81314. if(v == 0) {
  81315. return 0;
  81316. }
  81317. else if(v > 0) {
  81318. unsigned l = 0;
  81319. while(v) {
  81320. l++;
  81321. v >>= 1;
  81322. }
  81323. return l+1;
  81324. }
  81325. else if(v == -1) {
  81326. return 2;
  81327. }
  81328. else {
  81329. v++;
  81330. v = -v;
  81331. }
  81332. }
  81333. }
  81334. #endif
  81335. /*** End of inlined file: bitmath.c ***/
  81336. /*** Start of inlined file: bitreader.c ***/
  81337. /*** Start of inlined file: juce_FlacHeader.h ***/
  81338. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81339. // tasks..
  81340. #define VERSION "1.2.1"
  81341. #define FLAC__NO_DLL 1
  81342. #if JUCE_MSVC
  81343. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81344. #endif
  81345. #if JUCE_MAC
  81346. #define FLAC__SYS_DARWIN 1
  81347. #endif
  81348. /*** End of inlined file: juce_FlacHeader.h ***/
  81349. #if JUCE_USE_FLAC
  81350. #if HAVE_CONFIG_H
  81351. # include <config.h>
  81352. #endif
  81353. #include <stdlib.h> /* for malloc() */
  81354. #include <string.h> /* for memcpy(), memset() */
  81355. #ifdef _MSC_VER
  81356. #include <winsock.h> /* for ntohl() */
  81357. #elif defined FLAC__SYS_DARWIN
  81358. #include <machine/endian.h> /* for ntohl() */
  81359. #elif defined __MINGW32__
  81360. #include <winsock.h> /* for ntohl() */
  81361. #else
  81362. #include <netinet/in.h> /* for ntohl() */
  81363. #endif
  81364. /*** Start of inlined file: bitreader.h ***/
  81365. #ifndef FLAC__PRIVATE__BITREADER_H
  81366. #define FLAC__PRIVATE__BITREADER_H
  81367. #include <stdio.h> /* for FILE */
  81368. /*** Start of inlined file: cpu.h ***/
  81369. #ifndef FLAC__PRIVATE__CPU_H
  81370. #define FLAC__PRIVATE__CPU_H
  81371. #ifdef HAVE_CONFIG_H
  81372. #include <config.h>
  81373. #endif
  81374. typedef enum {
  81375. FLAC__CPUINFO_TYPE_IA32,
  81376. FLAC__CPUINFO_TYPE_PPC,
  81377. FLAC__CPUINFO_TYPE_UNKNOWN
  81378. } FLAC__CPUInfo_Type;
  81379. typedef struct {
  81380. FLAC__bool cpuid;
  81381. FLAC__bool bswap;
  81382. FLAC__bool cmov;
  81383. FLAC__bool mmx;
  81384. FLAC__bool fxsr;
  81385. FLAC__bool sse;
  81386. FLAC__bool sse2;
  81387. FLAC__bool sse3;
  81388. FLAC__bool ssse3;
  81389. FLAC__bool _3dnow;
  81390. FLAC__bool ext3dnow;
  81391. FLAC__bool extmmx;
  81392. } FLAC__CPUInfo_IA32;
  81393. typedef struct {
  81394. FLAC__bool altivec;
  81395. FLAC__bool ppc64;
  81396. } FLAC__CPUInfo_PPC;
  81397. typedef struct {
  81398. FLAC__bool use_asm;
  81399. FLAC__CPUInfo_Type type;
  81400. union {
  81401. FLAC__CPUInfo_IA32 ia32;
  81402. FLAC__CPUInfo_PPC ppc;
  81403. } data;
  81404. } FLAC__CPUInfo;
  81405. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81406. #ifndef FLAC__NO_ASM
  81407. #ifdef FLAC__CPU_IA32
  81408. #ifdef FLAC__HAS_NASM
  81409. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81410. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81411. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81412. #endif
  81413. #endif
  81414. #endif
  81415. #endif
  81416. /*** End of inlined file: cpu.h ***/
  81417. struct FLAC__BitReader;
  81418. typedef struct FLAC__BitReader FLAC__BitReader;
  81419. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81420. FLAC__BitReader *FLAC__bitreader_new(void);
  81421. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81422. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81423. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81424. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81425. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81426. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81427. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81428. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81429. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81430. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81431. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81432. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81433. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81434. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81435. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81436. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81437. 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! */
  81438. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81439. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81440. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81441. #ifndef FLAC__NO_ASM
  81442. # ifdef FLAC__CPU_IA32
  81443. # ifdef FLAC__HAS_NASM
  81444. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81445. # endif
  81446. # endif
  81447. #endif
  81448. #if 0 /* UNUSED */
  81449. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81450. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81451. #endif
  81452. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81453. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81454. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81455. #endif
  81456. /*** End of inlined file: bitreader.h ***/
  81457. /*** Start of inlined file: crc.h ***/
  81458. #ifndef FLAC__PRIVATE__CRC_H
  81459. #define FLAC__PRIVATE__CRC_H
  81460. extern FLAC__byte const FLAC__crc8_table[256];
  81461. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81462. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81463. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81464. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81465. extern unsigned FLAC__crc16_table[256];
  81466. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81467. #if 0
  81468. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81469. #endif
  81470. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81471. #endif
  81472. /*** End of inlined file: crc.h ***/
  81473. typedef FLAC__uint32 brword;
  81474. #define FLAC__BYTES_PER_WORD 4
  81475. #define FLAC__BITS_PER_WORD 32
  81476. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81477. #if WORDS_BIGENDIAN
  81478. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81479. #else
  81480. #if defined (_MSC_VER) && defined (_X86_)
  81481. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81482. #else
  81483. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81484. #endif
  81485. #endif
  81486. #define COUNT_ZERO_MSBS(word) ( \
  81487. (word) <= 0xffff ? \
  81488. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81489. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81490. )
  81491. #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])) )
  81492. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81493. static const unsigned char byte_to_unary_table[] = {
  81494. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81495. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81496. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81497. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81498. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81499. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81500. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81501. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81510. };
  81511. #ifdef min
  81512. #undef min
  81513. #endif
  81514. #define min(x,y) ((x)<(y)?(x):(y))
  81515. #ifdef max
  81516. #undef max
  81517. #endif
  81518. #define max(x,y) ((x)>(y)?(x):(y))
  81519. #ifdef _MSC_VER
  81520. #define FLAC__U64L(x) x
  81521. #else
  81522. #define FLAC__U64L(x) x##LLU
  81523. #endif
  81524. #ifndef FLaC__INLINE
  81525. #define FLaC__INLINE
  81526. #endif
  81527. struct FLAC__BitReader {
  81528. brword *buffer;
  81529. unsigned capacity; /* in words */
  81530. unsigned words; /* # of completed words in buffer */
  81531. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81532. unsigned consumed_words; /* #words ... */
  81533. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81534. unsigned read_crc16; /* the running frame CRC */
  81535. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81536. FLAC__BitReaderReadCallback read_callback;
  81537. void *client_data;
  81538. FLAC__CPUInfo cpu_info;
  81539. };
  81540. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81541. {
  81542. register unsigned crc = br->read_crc16;
  81543. #if FLAC__BYTES_PER_WORD == 4
  81544. switch(br->crc16_align) {
  81545. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81546. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81547. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81548. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81549. }
  81550. #elif FLAC__BYTES_PER_WORD == 8
  81551. switch(br->crc16_align) {
  81552. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81553. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81554. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81555. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81556. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81557. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81558. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81559. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81560. }
  81561. #else
  81562. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81563. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81564. br->read_crc16 = crc;
  81565. #endif
  81566. br->crc16_align = 0;
  81567. }
  81568. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81569. {
  81570. unsigned start, end;
  81571. size_t bytes;
  81572. FLAC__byte *target;
  81573. if(br->consumed_words > 0) {
  81574. start = br->consumed_words;
  81575. end = br->words + (br->bytes? 1:0);
  81576. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81577. br->words -= start;
  81578. br->consumed_words = 0;
  81579. }
  81580. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81581. if(bytes == 0)
  81582. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81583. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81584. #if WORDS_BIGENDIAN
  81585. #else
  81586. if(br->bytes)
  81587. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81588. #endif
  81589. if(!br->read_callback(target, &bytes, br->client_data))
  81590. return false;
  81591. #if WORDS_BIGENDIAN
  81592. #else
  81593. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81594. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81595. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81596. start = br->words;
  81597. local_swap32_block_(br->buffer + start, end - start);
  81598. }
  81599. else
  81600. # endif
  81601. for(start = br->words; start < end; start++)
  81602. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81603. #endif
  81604. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81605. br->words = end / FLAC__BYTES_PER_WORD;
  81606. br->bytes = end % FLAC__BYTES_PER_WORD;
  81607. return true;
  81608. }
  81609. FLAC__BitReader *FLAC__bitreader_new(void)
  81610. {
  81611. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81612. return br;
  81613. }
  81614. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81615. {
  81616. FLAC__ASSERT(0 != br);
  81617. FLAC__bitreader_free(br);
  81618. free(br);
  81619. }
  81620. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81621. {
  81622. FLAC__ASSERT(0 != br);
  81623. br->words = br->bytes = 0;
  81624. br->consumed_words = br->consumed_bits = 0;
  81625. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81626. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81627. if(br->buffer == 0)
  81628. return false;
  81629. br->read_callback = rcb;
  81630. br->client_data = cd;
  81631. br->cpu_info = cpu;
  81632. return true;
  81633. }
  81634. void FLAC__bitreader_free(FLAC__BitReader *br)
  81635. {
  81636. FLAC__ASSERT(0 != br);
  81637. if(0 != br->buffer)
  81638. free(br->buffer);
  81639. br->buffer = 0;
  81640. br->capacity = 0;
  81641. br->words = br->bytes = 0;
  81642. br->consumed_words = br->consumed_bits = 0;
  81643. br->read_callback = 0;
  81644. br->client_data = 0;
  81645. }
  81646. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81647. {
  81648. br->words = br->bytes = 0;
  81649. br->consumed_words = br->consumed_bits = 0;
  81650. return true;
  81651. }
  81652. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81653. {
  81654. unsigned i, j;
  81655. if(br == 0) {
  81656. fprintf(out, "bitreader is NULL\n");
  81657. }
  81658. else {
  81659. 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);
  81660. for(i = 0; i < br->words; i++) {
  81661. fprintf(out, "%08X: ", i);
  81662. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81663. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81664. fprintf(out, ".");
  81665. else
  81666. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81667. fprintf(out, "\n");
  81668. }
  81669. if(br->bytes > 0) {
  81670. fprintf(out, "%08X: ", i);
  81671. for(j = 0; j < br->bytes*8; j++)
  81672. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81673. fprintf(out, ".");
  81674. else
  81675. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81676. fprintf(out, "\n");
  81677. }
  81678. }
  81679. }
  81680. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81681. {
  81682. FLAC__ASSERT(0 != br);
  81683. FLAC__ASSERT(0 != br->buffer);
  81684. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81685. br->read_crc16 = (unsigned)seed;
  81686. br->crc16_align = br->consumed_bits;
  81687. }
  81688. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81689. {
  81690. FLAC__ASSERT(0 != br);
  81691. FLAC__ASSERT(0 != br->buffer);
  81692. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81693. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81694. if(br->consumed_bits) {
  81695. const brword tail = br->buffer[br->consumed_words];
  81696. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81697. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81698. }
  81699. return br->read_crc16;
  81700. }
  81701. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81702. {
  81703. return ((br->consumed_bits & 7) == 0);
  81704. }
  81705. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81706. {
  81707. return 8 - (br->consumed_bits & 7);
  81708. }
  81709. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81710. {
  81711. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81712. }
  81713. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81714. {
  81715. FLAC__ASSERT(0 != br);
  81716. FLAC__ASSERT(0 != br->buffer);
  81717. FLAC__ASSERT(bits <= 32);
  81718. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81719. FLAC__ASSERT(br->consumed_words <= br->words);
  81720. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81721. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81722. *val = 0;
  81723. return true;
  81724. }
  81725. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81726. if(!bitreader_read_from_client_(br))
  81727. return false;
  81728. }
  81729. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81730. if(br->consumed_bits) {
  81731. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81732. const brword word = br->buffer[br->consumed_words];
  81733. if(bits < n) {
  81734. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81735. br->consumed_bits += bits;
  81736. return true;
  81737. }
  81738. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81739. bits -= n;
  81740. crc16_update_word_(br, word);
  81741. br->consumed_words++;
  81742. br->consumed_bits = 0;
  81743. 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 */
  81744. *val <<= bits;
  81745. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81746. br->consumed_bits = bits;
  81747. }
  81748. return true;
  81749. }
  81750. else {
  81751. const brword word = br->buffer[br->consumed_words];
  81752. if(bits < FLAC__BITS_PER_WORD) {
  81753. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81754. br->consumed_bits = bits;
  81755. return true;
  81756. }
  81757. *val = word;
  81758. crc16_update_word_(br, word);
  81759. br->consumed_words++;
  81760. return true;
  81761. }
  81762. }
  81763. else {
  81764. if(br->consumed_bits) {
  81765. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81766. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81767. br->consumed_bits += bits;
  81768. return true;
  81769. }
  81770. else {
  81771. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81772. br->consumed_bits += bits;
  81773. return true;
  81774. }
  81775. }
  81776. }
  81777. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81778. {
  81779. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81780. return false;
  81781. *val <<= (32-bits);
  81782. *val >>= (32-bits);
  81783. return true;
  81784. }
  81785. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81786. {
  81787. FLAC__uint32 hi, lo;
  81788. if(bits > 32) {
  81789. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81790. return false;
  81791. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81792. return false;
  81793. *val = hi;
  81794. *val <<= 32;
  81795. *val |= lo;
  81796. }
  81797. else {
  81798. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81799. return false;
  81800. *val = lo;
  81801. }
  81802. return true;
  81803. }
  81804. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81805. {
  81806. FLAC__uint32 x8, x32 = 0;
  81807. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81808. return false;
  81809. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81810. return false;
  81811. x32 |= (x8 << 8);
  81812. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81813. return false;
  81814. x32 |= (x8 << 16);
  81815. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81816. return false;
  81817. x32 |= (x8 << 24);
  81818. *val = x32;
  81819. return true;
  81820. }
  81821. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81822. {
  81823. FLAC__ASSERT(0 != br);
  81824. FLAC__ASSERT(0 != br->buffer);
  81825. if(bits > 0) {
  81826. const unsigned n = br->consumed_bits & 7;
  81827. unsigned m;
  81828. FLAC__uint32 x;
  81829. if(n != 0) {
  81830. m = min(8-n, bits);
  81831. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81832. return false;
  81833. bits -= m;
  81834. }
  81835. m = bits / 8;
  81836. if(m > 0) {
  81837. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81838. return false;
  81839. bits %= 8;
  81840. }
  81841. if(bits > 0) {
  81842. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81843. return false;
  81844. }
  81845. }
  81846. return true;
  81847. }
  81848. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81849. {
  81850. FLAC__uint32 x;
  81851. FLAC__ASSERT(0 != br);
  81852. FLAC__ASSERT(0 != br->buffer);
  81853. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81854. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81855. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81856. return false;
  81857. nvals--;
  81858. }
  81859. if(0 == nvals)
  81860. return true;
  81861. while(nvals >= FLAC__BYTES_PER_WORD) {
  81862. if(br->consumed_words < br->words) {
  81863. br->consumed_words++;
  81864. nvals -= FLAC__BYTES_PER_WORD;
  81865. }
  81866. else if(!bitreader_read_from_client_(br))
  81867. return false;
  81868. }
  81869. while(nvals) {
  81870. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81871. return false;
  81872. nvals--;
  81873. }
  81874. return true;
  81875. }
  81876. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81877. {
  81878. FLAC__uint32 x;
  81879. FLAC__ASSERT(0 != br);
  81880. FLAC__ASSERT(0 != br->buffer);
  81881. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81882. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81883. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81884. return false;
  81885. *val++ = (FLAC__byte)x;
  81886. nvals--;
  81887. }
  81888. if(0 == nvals)
  81889. return true;
  81890. while(nvals >= FLAC__BYTES_PER_WORD) {
  81891. if(br->consumed_words < br->words) {
  81892. const brword word = br->buffer[br->consumed_words++];
  81893. #if FLAC__BYTES_PER_WORD == 4
  81894. val[0] = (FLAC__byte)(word >> 24);
  81895. val[1] = (FLAC__byte)(word >> 16);
  81896. val[2] = (FLAC__byte)(word >> 8);
  81897. val[3] = (FLAC__byte)word;
  81898. #elif FLAC__BYTES_PER_WORD == 8
  81899. val[0] = (FLAC__byte)(word >> 56);
  81900. val[1] = (FLAC__byte)(word >> 48);
  81901. val[2] = (FLAC__byte)(word >> 40);
  81902. val[3] = (FLAC__byte)(word >> 32);
  81903. val[4] = (FLAC__byte)(word >> 24);
  81904. val[5] = (FLAC__byte)(word >> 16);
  81905. val[6] = (FLAC__byte)(word >> 8);
  81906. val[7] = (FLAC__byte)word;
  81907. #else
  81908. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81909. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81910. #endif
  81911. val += FLAC__BYTES_PER_WORD;
  81912. nvals -= FLAC__BYTES_PER_WORD;
  81913. }
  81914. else if(!bitreader_read_from_client_(br))
  81915. return false;
  81916. }
  81917. while(nvals) {
  81918. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81919. return false;
  81920. *val++ = (FLAC__byte)x;
  81921. nvals--;
  81922. }
  81923. return true;
  81924. }
  81925. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  81926. #if 0 /* slow but readable version */
  81927. {
  81928. unsigned bit;
  81929. FLAC__ASSERT(0 != br);
  81930. FLAC__ASSERT(0 != br->buffer);
  81931. *val = 0;
  81932. while(1) {
  81933. if(!FLAC__bitreader_read_bit(br, &bit))
  81934. return false;
  81935. if(bit)
  81936. break;
  81937. else
  81938. *val++;
  81939. }
  81940. return true;
  81941. }
  81942. #else
  81943. {
  81944. unsigned i;
  81945. FLAC__ASSERT(0 != br);
  81946. FLAC__ASSERT(0 != br->buffer);
  81947. *val = 0;
  81948. while(1) {
  81949. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81950. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  81951. if(b) {
  81952. i = COUNT_ZERO_MSBS(b);
  81953. *val += i;
  81954. i++;
  81955. br->consumed_bits += i;
  81956. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  81957. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81958. br->consumed_words++;
  81959. br->consumed_bits = 0;
  81960. }
  81961. return true;
  81962. }
  81963. else {
  81964. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  81965. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81966. br->consumed_words++;
  81967. br->consumed_bits = 0;
  81968. }
  81969. }
  81970. if(br->bytes) {
  81971. const unsigned end = br->bytes * 8;
  81972. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  81973. if(b) {
  81974. i = COUNT_ZERO_MSBS(b);
  81975. *val += i;
  81976. i++;
  81977. br->consumed_bits += i;
  81978. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81979. return true;
  81980. }
  81981. else {
  81982. *val += end - br->consumed_bits;
  81983. br->consumed_bits += end;
  81984. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81985. }
  81986. }
  81987. if(!bitreader_read_from_client_(br))
  81988. return false;
  81989. }
  81990. }
  81991. #endif
  81992. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  81993. {
  81994. FLAC__uint32 lsbs = 0, msbs = 0;
  81995. unsigned uval;
  81996. FLAC__ASSERT(0 != br);
  81997. FLAC__ASSERT(0 != br->buffer);
  81998. FLAC__ASSERT(parameter <= 31);
  81999. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82000. return false;
  82001. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82002. return false;
  82003. uval = (msbs << parameter) | lsbs;
  82004. if(uval & 1)
  82005. *val = -((int)(uval >> 1)) - 1;
  82006. else
  82007. *val = (int)(uval >> 1);
  82008. return true;
  82009. }
  82010. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82011. #ifdef _MSC_VER
  82012. {
  82013. unsigned i;
  82014. unsigned uval = 0;
  82015. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82016. register unsigned cwords;
  82017. register unsigned cbits;
  82018. FLAC__ASSERT(0 != br);
  82019. FLAC__ASSERT(0 != br->buffer);
  82020. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82021. FLAC__ASSERT(parameter < 32);
  82022. if(nvals == 0)
  82023. return true;
  82024. cbits = br->consumed_bits;
  82025. cwords = br->consumed_words;
  82026. while(1) {
  82027. while(1) {
  82028. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82029. brword b = br->buffer[cwords] << cbits;
  82030. if(b) {
  82031. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82032. __asm {
  82033. bsr eax, b
  82034. not eax
  82035. and eax, 31
  82036. mov i, eax
  82037. }
  82038. #else
  82039. i = COUNT_ZERO_MSBS(b);
  82040. #endif
  82041. uval += i;
  82042. bits = parameter;
  82043. i++;
  82044. cbits += i;
  82045. if(cbits == FLAC__BITS_PER_WORD) {
  82046. crc16_update_word_(br, br->buffer[cwords]);
  82047. cwords++;
  82048. cbits = 0;
  82049. }
  82050. goto break1;
  82051. }
  82052. else {
  82053. uval += FLAC__BITS_PER_WORD - cbits;
  82054. crc16_update_word_(br, br->buffer[cwords]);
  82055. cwords++;
  82056. cbits = 0;
  82057. }
  82058. }
  82059. if(br->bytes) {
  82060. const unsigned end = br->bytes * 8;
  82061. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82062. if(b) {
  82063. i = COUNT_ZERO_MSBS(b);
  82064. uval += i;
  82065. bits = parameter;
  82066. i++;
  82067. cbits += i;
  82068. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82069. goto break1;
  82070. }
  82071. else {
  82072. uval += end - cbits;
  82073. cbits += end;
  82074. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82075. }
  82076. }
  82077. br->consumed_bits = cbits;
  82078. br->consumed_words = cwords;
  82079. if(!bitreader_read_from_client_(br))
  82080. return false;
  82081. cwords = br->consumed_words;
  82082. }
  82083. break1:
  82084. FLAC__ASSERT(cwords <= br->words);
  82085. if(bits) {
  82086. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82087. br->consumed_bits = cbits;
  82088. br->consumed_words = cwords;
  82089. if(!bitreader_read_from_client_(br))
  82090. return false;
  82091. cwords = br->consumed_words;
  82092. }
  82093. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82094. if(cbits) {
  82095. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82096. const brword word = br->buffer[cwords];
  82097. if(bits < n) {
  82098. uval <<= bits;
  82099. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82100. cbits += bits;
  82101. goto break2;
  82102. }
  82103. uval <<= n;
  82104. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82105. bits -= n;
  82106. crc16_update_word_(br, word);
  82107. cwords++;
  82108. cbits = 0;
  82109. 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 */
  82110. uval <<= bits;
  82111. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82112. cbits = bits;
  82113. }
  82114. goto break2;
  82115. }
  82116. else {
  82117. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82118. uval <<= bits;
  82119. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82120. cbits = bits;
  82121. goto break2;
  82122. }
  82123. }
  82124. else {
  82125. uval <<= bits;
  82126. if(cbits) {
  82127. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82128. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82129. cbits += bits;
  82130. goto break2;
  82131. }
  82132. else {
  82133. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82134. cbits += bits;
  82135. goto break2;
  82136. }
  82137. }
  82138. }
  82139. break2:
  82140. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82141. --nvals;
  82142. if(nvals == 0) {
  82143. br->consumed_bits = cbits;
  82144. br->consumed_words = cwords;
  82145. return true;
  82146. }
  82147. uval = 0;
  82148. ++vals;
  82149. }
  82150. }
  82151. #else
  82152. {
  82153. unsigned i;
  82154. unsigned uval = 0;
  82155. register unsigned cwords;
  82156. register unsigned cbits;
  82157. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82158. FLAC__ASSERT(0 != br);
  82159. FLAC__ASSERT(0 != br->buffer);
  82160. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82161. FLAC__ASSERT(parameter < 32);
  82162. if(nvals == 0)
  82163. return true;
  82164. cbits = br->consumed_bits;
  82165. cwords = br->consumed_words;
  82166. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82167. while(1) {
  82168. while(1) {
  82169. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82170. brword b = br->buffer[cwords] << cbits;
  82171. if(b) {
  82172. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82173. asm volatile (
  82174. "bsrl %1, %0;"
  82175. "notl %0;"
  82176. "andl $31, %0;"
  82177. : "=r"(i)
  82178. : "r"(b)
  82179. );
  82180. #else
  82181. i = COUNT_ZERO_MSBS(b);
  82182. #endif
  82183. uval += i;
  82184. cbits += i;
  82185. cbits++; /* skip over stop bit */
  82186. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82187. crc16_update_word_(br, br->buffer[cwords]);
  82188. cwords++;
  82189. cbits = 0;
  82190. }
  82191. goto break1;
  82192. }
  82193. else {
  82194. uval += FLAC__BITS_PER_WORD - cbits;
  82195. crc16_update_word_(br, br->buffer[cwords]);
  82196. cwords++;
  82197. cbits = 0;
  82198. }
  82199. }
  82200. if(br->bytes) {
  82201. const unsigned end = br->bytes * 8;
  82202. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82203. if(b) {
  82204. i = COUNT_ZERO_MSBS(b);
  82205. uval += i;
  82206. cbits += i;
  82207. cbits++; /* skip over stop bit */
  82208. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82209. goto break1;
  82210. }
  82211. else {
  82212. uval += end - cbits;
  82213. cbits += end;
  82214. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82215. }
  82216. }
  82217. br->consumed_bits = cbits;
  82218. br->consumed_words = cwords;
  82219. if(!bitreader_read_from_client_(br))
  82220. return false;
  82221. cwords = br->consumed_words;
  82222. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82223. }
  82224. break1:
  82225. ucbits -= uval;
  82226. ucbits--; /* account for stop bit */
  82227. FLAC__ASSERT(cwords <= br->words);
  82228. if(parameter) {
  82229. while(ucbits < parameter) {
  82230. br->consumed_bits = cbits;
  82231. br->consumed_words = cwords;
  82232. if(!bitreader_read_from_client_(br))
  82233. return false;
  82234. cwords = br->consumed_words;
  82235. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82236. }
  82237. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82238. if(cbits) {
  82239. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82240. const brword word = br->buffer[cwords];
  82241. if(parameter < n) {
  82242. uval <<= parameter;
  82243. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82244. cbits += parameter;
  82245. }
  82246. else {
  82247. uval <<= n;
  82248. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82249. crc16_update_word_(br, word);
  82250. cwords++;
  82251. cbits = parameter - n;
  82252. 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 */
  82253. uval <<= cbits;
  82254. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82255. }
  82256. }
  82257. }
  82258. else {
  82259. cbits = parameter;
  82260. uval <<= parameter;
  82261. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82262. }
  82263. }
  82264. else {
  82265. uval <<= parameter;
  82266. if(cbits) {
  82267. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82268. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82269. cbits += parameter;
  82270. }
  82271. else {
  82272. cbits = parameter;
  82273. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82274. }
  82275. }
  82276. }
  82277. ucbits -= parameter;
  82278. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82279. --nvals;
  82280. if(nvals == 0) {
  82281. br->consumed_bits = cbits;
  82282. br->consumed_words = cwords;
  82283. return true;
  82284. }
  82285. uval = 0;
  82286. ++vals;
  82287. }
  82288. }
  82289. #endif
  82290. #if 0 /* UNUSED */
  82291. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82292. {
  82293. FLAC__uint32 lsbs = 0, msbs = 0;
  82294. unsigned bit, uval, k;
  82295. FLAC__ASSERT(0 != br);
  82296. FLAC__ASSERT(0 != br->buffer);
  82297. k = FLAC__bitmath_ilog2(parameter);
  82298. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82299. return false;
  82300. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82301. return false;
  82302. if(parameter == 1u<<k) {
  82303. uval = (msbs << k) | lsbs;
  82304. }
  82305. else {
  82306. unsigned d = (1 << (k+1)) - parameter;
  82307. if(lsbs >= d) {
  82308. if(!FLAC__bitreader_read_bit(br, &bit))
  82309. return false;
  82310. lsbs <<= 1;
  82311. lsbs |= bit;
  82312. lsbs -= d;
  82313. }
  82314. uval = msbs * parameter + lsbs;
  82315. }
  82316. if(uval & 1)
  82317. *val = -((int)(uval >> 1)) - 1;
  82318. else
  82319. *val = (int)(uval >> 1);
  82320. return true;
  82321. }
  82322. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82323. {
  82324. FLAC__uint32 lsbs, msbs = 0;
  82325. unsigned bit, k;
  82326. FLAC__ASSERT(0 != br);
  82327. FLAC__ASSERT(0 != br->buffer);
  82328. k = FLAC__bitmath_ilog2(parameter);
  82329. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82330. return false;
  82331. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82332. return false;
  82333. if(parameter == 1u<<k) {
  82334. *val = (msbs << k) | lsbs;
  82335. }
  82336. else {
  82337. unsigned d = (1 << (k+1)) - parameter;
  82338. if(lsbs >= d) {
  82339. if(!FLAC__bitreader_read_bit(br, &bit))
  82340. return false;
  82341. lsbs <<= 1;
  82342. lsbs |= bit;
  82343. lsbs -= d;
  82344. }
  82345. *val = msbs * parameter + lsbs;
  82346. }
  82347. return true;
  82348. }
  82349. #endif /* UNUSED */
  82350. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82351. {
  82352. FLAC__uint32 v = 0;
  82353. FLAC__uint32 x;
  82354. unsigned i;
  82355. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82356. return false;
  82357. if(raw)
  82358. raw[(*rawlen)++] = (FLAC__byte)x;
  82359. if(!(x & 0x80)) { /* 0xxxxxxx */
  82360. v = x;
  82361. i = 0;
  82362. }
  82363. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82364. v = x & 0x1F;
  82365. i = 1;
  82366. }
  82367. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82368. v = x & 0x0F;
  82369. i = 2;
  82370. }
  82371. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82372. v = x & 0x07;
  82373. i = 3;
  82374. }
  82375. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82376. v = x & 0x03;
  82377. i = 4;
  82378. }
  82379. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82380. v = x & 0x01;
  82381. i = 5;
  82382. }
  82383. else {
  82384. *val = 0xffffffff;
  82385. return true;
  82386. }
  82387. for( ; i; i--) {
  82388. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82389. return false;
  82390. if(raw)
  82391. raw[(*rawlen)++] = (FLAC__byte)x;
  82392. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82393. *val = 0xffffffff;
  82394. return true;
  82395. }
  82396. v <<= 6;
  82397. v |= (x & 0x3F);
  82398. }
  82399. *val = v;
  82400. return true;
  82401. }
  82402. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82403. {
  82404. FLAC__uint64 v = 0;
  82405. FLAC__uint32 x;
  82406. unsigned i;
  82407. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82408. return false;
  82409. if(raw)
  82410. raw[(*rawlen)++] = (FLAC__byte)x;
  82411. if(!(x & 0x80)) { /* 0xxxxxxx */
  82412. v = x;
  82413. i = 0;
  82414. }
  82415. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82416. v = x & 0x1F;
  82417. i = 1;
  82418. }
  82419. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82420. v = x & 0x0F;
  82421. i = 2;
  82422. }
  82423. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82424. v = x & 0x07;
  82425. i = 3;
  82426. }
  82427. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82428. v = x & 0x03;
  82429. i = 4;
  82430. }
  82431. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82432. v = x & 0x01;
  82433. i = 5;
  82434. }
  82435. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82436. v = 0;
  82437. i = 6;
  82438. }
  82439. else {
  82440. *val = FLAC__U64L(0xffffffffffffffff);
  82441. return true;
  82442. }
  82443. for( ; i; i--) {
  82444. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82445. return false;
  82446. if(raw)
  82447. raw[(*rawlen)++] = (FLAC__byte)x;
  82448. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82449. *val = FLAC__U64L(0xffffffffffffffff);
  82450. return true;
  82451. }
  82452. v <<= 6;
  82453. v |= (x & 0x3F);
  82454. }
  82455. *val = v;
  82456. return true;
  82457. }
  82458. #endif
  82459. /*** End of inlined file: bitreader.c ***/
  82460. /*** Start of inlined file: bitwriter.c ***/
  82461. /*** Start of inlined file: juce_FlacHeader.h ***/
  82462. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82463. // tasks..
  82464. #define VERSION "1.2.1"
  82465. #define FLAC__NO_DLL 1
  82466. #if JUCE_MSVC
  82467. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82468. #endif
  82469. #if JUCE_MAC
  82470. #define FLAC__SYS_DARWIN 1
  82471. #endif
  82472. /*** End of inlined file: juce_FlacHeader.h ***/
  82473. #if JUCE_USE_FLAC
  82474. #if HAVE_CONFIG_H
  82475. # include <config.h>
  82476. #endif
  82477. #include <stdlib.h> /* for malloc() */
  82478. #include <string.h> /* for memcpy(), memset() */
  82479. #ifdef _MSC_VER
  82480. #include <winsock.h> /* for ntohl() */
  82481. #elif defined FLAC__SYS_DARWIN
  82482. #include <machine/endian.h> /* for ntohl() */
  82483. #elif defined __MINGW32__
  82484. #include <winsock.h> /* for ntohl() */
  82485. #else
  82486. #include <netinet/in.h> /* for ntohl() */
  82487. #endif
  82488. #if 0 /* UNUSED */
  82489. #endif
  82490. /*** Start of inlined file: bitwriter.h ***/
  82491. #ifndef FLAC__PRIVATE__BITWRITER_H
  82492. #define FLAC__PRIVATE__BITWRITER_H
  82493. #include <stdio.h> /* for FILE */
  82494. struct FLAC__BitWriter;
  82495. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82496. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82497. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82498. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82499. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82500. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82501. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82502. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82503. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82504. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82505. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82506. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82507. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82508. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82509. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82510. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82511. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82512. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82513. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82514. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82515. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82516. #if 0 /* UNUSED */
  82517. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82518. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82519. #endif
  82520. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82521. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82522. #if 0 /* UNUSED */
  82523. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82524. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82525. #endif
  82526. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82527. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82528. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82529. #endif
  82530. /*** End of inlined file: bitwriter.h ***/
  82531. /*** Start of inlined file: alloc.h ***/
  82532. #ifndef FLAC__SHARE__ALLOC_H
  82533. #define FLAC__SHARE__ALLOC_H
  82534. #if HAVE_CONFIG_H
  82535. # include <config.h>
  82536. #endif
  82537. #include <limits.h> /* for SIZE_MAX */
  82538. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82539. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82540. #endif
  82541. #include <stdlib.h> /* for size_t, malloc(), etc */
  82542. #ifndef SIZE_MAX
  82543. # ifndef SIZE_T_MAX
  82544. # ifdef _MSC_VER
  82545. # define SIZE_T_MAX UINT_MAX
  82546. # else
  82547. # error
  82548. # endif
  82549. # endif
  82550. # define SIZE_MAX SIZE_T_MAX
  82551. #endif
  82552. #ifndef FLaC__INLINE
  82553. #define FLaC__INLINE
  82554. #endif
  82555. static FLaC__INLINE void *safe_malloc_(size_t size)
  82556. {
  82557. if(!size)
  82558. size++;
  82559. return malloc(size);
  82560. }
  82561. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82562. {
  82563. if(!nmemb || !size)
  82564. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82565. return calloc(nmemb, size);
  82566. }
  82567. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82568. {
  82569. size2 += size1;
  82570. if(size2 < size1)
  82571. return 0;
  82572. return safe_malloc_(size2);
  82573. }
  82574. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82575. {
  82576. size2 += size1;
  82577. if(size2 < size1)
  82578. return 0;
  82579. size3 += size2;
  82580. if(size3 < size2)
  82581. return 0;
  82582. return safe_malloc_(size3);
  82583. }
  82584. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82585. {
  82586. size2 += size1;
  82587. if(size2 < size1)
  82588. return 0;
  82589. size3 += size2;
  82590. if(size3 < size2)
  82591. return 0;
  82592. size4 += size3;
  82593. if(size4 < size3)
  82594. return 0;
  82595. return safe_malloc_(size4);
  82596. }
  82597. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82598. #if 0
  82599. needs support for cases where sizeof(size_t) != 4
  82600. {
  82601. if(sizeof(size_t) == 4) {
  82602. if ((double)size1 * (double)size2 < 4294967296.0)
  82603. return malloc(size1*size2);
  82604. }
  82605. return 0;
  82606. }
  82607. #else
  82608. {
  82609. if(!size1 || !size2)
  82610. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82611. if(size1 > SIZE_MAX / size2)
  82612. return 0;
  82613. return malloc(size1*size2);
  82614. }
  82615. #endif
  82616. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82617. {
  82618. if(!size1 || !size2 || !size3)
  82619. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82620. if(size1 > SIZE_MAX / size2)
  82621. return 0;
  82622. size1 *= size2;
  82623. if(size1 > SIZE_MAX / size3)
  82624. return 0;
  82625. return malloc(size1*size3);
  82626. }
  82627. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82628. {
  82629. if(!size1 || !size2)
  82630. return safe_malloc_(size3);
  82631. if(size1 > SIZE_MAX / size2)
  82632. return 0;
  82633. return safe_malloc_add_2op_(size1*size2, size3);
  82634. }
  82635. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82636. {
  82637. if(!size1 || (!size2 && !size3))
  82638. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82639. size2 += size3;
  82640. if(size2 < size3)
  82641. return 0;
  82642. return safe_malloc_mul_2op_(size1, size2);
  82643. }
  82644. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82645. {
  82646. size2 += size1;
  82647. if(size2 < size1)
  82648. return 0;
  82649. return realloc(ptr, size2);
  82650. }
  82651. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82652. {
  82653. size2 += size1;
  82654. if(size2 < size1)
  82655. return 0;
  82656. size3 += size2;
  82657. if(size3 < size2)
  82658. return 0;
  82659. return realloc(ptr, size3);
  82660. }
  82661. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82662. {
  82663. size2 += size1;
  82664. if(size2 < size1)
  82665. return 0;
  82666. size3 += size2;
  82667. if(size3 < size2)
  82668. return 0;
  82669. size4 += size3;
  82670. if(size4 < size3)
  82671. return 0;
  82672. return realloc(ptr, size4);
  82673. }
  82674. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82675. {
  82676. if(!size1 || !size2)
  82677. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82678. if(size1 > SIZE_MAX / size2)
  82679. return 0;
  82680. return realloc(ptr, size1*size2);
  82681. }
  82682. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82683. {
  82684. if(!size1 || (!size2 && !size3))
  82685. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82686. size2 += size3;
  82687. if(size2 < size3)
  82688. return 0;
  82689. return safe_realloc_mul_2op_(ptr, size1, size2);
  82690. }
  82691. #endif
  82692. /*** End of inlined file: alloc.h ***/
  82693. typedef FLAC__uint32 bwword;
  82694. #define FLAC__BYTES_PER_WORD 4
  82695. #define FLAC__BITS_PER_WORD 32
  82696. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82697. #if WORDS_BIGENDIAN
  82698. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82699. #else
  82700. #ifdef _MSC_VER
  82701. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82702. #else
  82703. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82704. #endif
  82705. #endif
  82706. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82707. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82708. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82709. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82710. #ifdef min
  82711. #undef min
  82712. #endif
  82713. #define min(x,y) ((x)<(y)?(x):(y))
  82714. #ifdef _MSC_VER
  82715. #define FLAC__U64L(x) x
  82716. #else
  82717. #define FLAC__U64L(x) x##LLU
  82718. #endif
  82719. #ifndef FLaC__INLINE
  82720. #define FLaC__INLINE
  82721. #endif
  82722. struct FLAC__BitWriter {
  82723. bwword *buffer;
  82724. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82725. unsigned capacity; /* capacity of buffer in words */
  82726. unsigned words; /* # of complete words in buffer */
  82727. unsigned bits; /* # of used bits in accum */
  82728. };
  82729. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82730. {
  82731. unsigned new_capacity;
  82732. bwword *new_buffer;
  82733. FLAC__ASSERT(0 != bw);
  82734. FLAC__ASSERT(0 != bw->buffer);
  82735. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82736. if(bw->capacity >= new_capacity)
  82737. return true;
  82738. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82739. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82740. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82741. FLAC__ASSERT(new_capacity > bw->capacity);
  82742. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82743. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82744. if(new_buffer == 0)
  82745. return false;
  82746. bw->buffer = new_buffer;
  82747. bw->capacity = new_capacity;
  82748. return true;
  82749. }
  82750. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82751. {
  82752. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82753. return bw;
  82754. }
  82755. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82756. {
  82757. FLAC__ASSERT(0 != bw);
  82758. FLAC__bitwriter_free(bw);
  82759. free(bw);
  82760. }
  82761. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82762. {
  82763. FLAC__ASSERT(0 != bw);
  82764. bw->words = bw->bits = 0;
  82765. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82766. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82767. if(bw->buffer == 0)
  82768. return false;
  82769. return true;
  82770. }
  82771. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82772. {
  82773. FLAC__ASSERT(0 != bw);
  82774. if(0 != bw->buffer)
  82775. free(bw->buffer);
  82776. bw->buffer = 0;
  82777. bw->capacity = 0;
  82778. bw->words = bw->bits = 0;
  82779. }
  82780. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82781. {
  82782. bw->words = bw->bits = 0;
  82783. }
  82784. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82785. {
  82786. unsigned i, j;
  82787. if(bw == 0) {
  82788. fprintf(out, "bitwriter is NULL\n");
  82789. }
  82790. else {
  82791. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82792. for(i = 0; i < bw->words; i++) {
  82793. fprintf(out, "%08X: ", i);
  82794. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82795. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82796. fprintf(out, "\n");
  82797. }
  82798. if(bw->bits > 0) {
  82799. fprintf(out, "%08X: ", i);
  82800. for(j = 0; j < bw->bits; j++)
  82801. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82802. fprintf(out, "\n");
  82803. }
  82804. }
  82805. }
  82806. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82807. {
  82808. const FLAC__byte *buffer;
  82809. size_t bytes;
  82810. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82811. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82812. return false;
  82813. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82814. FLAC__bitwriter_release_buffer(bw);
  82815. return true;
  82816. }
  82817. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82818. {
  82819. const FLAC__byte *buffer;
  82820. size_t bytes;
  82821. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82822. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82823. return false;
  82824. *crc = FLAC__crc8(buffer, bytes);
  82825. FLAC__bitwriter_release_buffer(bw);
  82826. return true;
  82827. }
  82828. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82829. {
  82830. return ((bw->bits & 7) == 0);
  82831. }
  82832. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82833. {
  82834. return FLAC__TOTAL_BITS(bw);
  82835. }
  82836. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82837. {
  82838. FLAC__ASSERT((bw->bits & 7) == 0);
  82839. if(bw->bits & 7)
  82840. return false;
  82841. if(bw->bits) {
  82842. FLAC__ASSERT(bw->words <= bw->capacity);
  82843. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82844. return false;
  82845. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82846. }
  82847. *buffer = (FLAC__byte*)bw->buffer;
  82848. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82849. return true;
  82850. }
  82851. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82852. {
  82853. (void)bw;
  82854. }
  82855. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82856. {
  82857. unsigned n;
  82858. FLAC__ASSERT(0 != bw);
  82859. FLAC__ASSERT(0 != bw->buffer);
  82860. if(bits == 0)
  82861. return true;
  82862. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82863. return false;
  82864. if(bw->bits) {
  82865. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82866. bw->accum <<= n;
  82867. bits -= n;
  82868. bw->bits += n;
  82869. if(bw->bits == FLAC__BITS_PER_WORD) {
  82870. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82871. bw->bits = 0;
  82872. }
  82873. else
  82874. return true;
  82875. }
  82876. while(bits >= FLAC__BITS_PER_WORD) {
  82877. bw->buffer[bw->words++] = 0;
  82878. bits -= FLAC__BITS_PER_WORD;
  82879. }
  82880. if(bits > 0) {
  82881. bw->accum = 0;
  82882. bw->bits = bits;
  82883. }
  82884. return true;
  82885. }
  82886. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82887. {
  82888. register unsigned left;
  82889. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82890. FLAC__ASSERT(0 != bw);
  82891. FLAC__ASSERT(0 != bw->buffer);
  82892. FLAC__ASSERT(bits <= 32);
  82893. if(bits == 0)
  82894. return true;
  82895. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82896. return false;
  82897. left = FLAC__BITS_PER_WORD - bw->bits;
  82898. if(bits < left) {
  82899. bw->accum <<= bits;
  82900. bw->accum |= val;
  82901. bw->bits += bits;
  82902. }
  82903. 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 */
  82904. bw->accum <<= left;
  82905. bw->accum |= val >> (bw->bits = bits - left);
  82906. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82907. bw->accum = val;
  82908. }
  82909. else {
  82910. bw->accum = val;
  82911. bw->bits = 0;
  82912. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82913. }
  82914. return true;
  82915. }
  82916. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  82917. {
  82918. if(bits < 32)
  82919. val &= (~(0xffffffff << bits));
  82920. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82921. }
  82922. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  82923. {
  82924. if(bits > 32) {
  82925. return
  82926. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  82927. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  82928. }
  82929. else
  82930. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82931. }
  82932. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  82933. {
  82934. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  82935. return false;
  82936. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  82937. return false;
  82938. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  82939. return false;
  82940. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  82941. return false;
  82942. return true;
  82943. }
  82944. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  82945. {
  82946. unsigned i;
  82947. for(i = 0; i < nvals; i++) {
  82948. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  82949. return false;
  82950. }
  82951. return true;
  82952. }
  82953. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  82954. {
  82955. if(val < 32)
  82956. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  82957. else
  82958. return
  82959. FLAC__bitwriter_write_zeroes(bw, val) &&
  82960. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  82961. }
  82962. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  82963. {
  82964. FLAC__uint32 uval;
  82965. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  82966. uval = (val<<1) ^ (val>>31);
  82967. return 1 + parameter + (uval >> parameter);
  82968. }
  82969. #if 0 /* UNUSED */
  82970. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  82971. {
  82972. unsigned bits, msbs, uval;
  82973. unsigned k;
  82974. FLAC__ASSERT(parameter > 0);
  82975. if(val < 0)
  82976. uval = (unsigned)(((-(++val)) << 1) + 1);
  82977. else
  82978. uval = (unsigned)(val << 1);
  82979. k = FLAC__bitmath_ilog2(parameter);
  82980. if(parameter == 1u<<k) {
  82981. FLAC__ASSERT(k <= 30);
  82982. msbs = uval >> k;
  82983. bits = 1 + k + msbs;
  82984. }
  82985. else {
  82986. unsigned q, r, d;
  82987. d = (1 << (k+1)) - parameter;
  82988. q = uval / parameter;
  82989. r = uval - (q * parameter);
  82990. bits = 1 + q + k;
  82991. if(r >= d)
  82992. bits++;
  82993. }
  82994. return bits;
  82995. }
  82996. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  82997. {
  82998. unsigned bits, msbs;
  82999. unsigned k;
  83000. FLAC__ASSERT(parameter > 0);
  83001. k = FLAC__bitmath_ilog2(parameter);
  83002. if(parameter == 1u<<k) {
  83003. FLAC__ASSERT(k <= 30);
  83004. msbs = uval >> k;
  83005. bits = 1 + k + msbs;
  83006. }
  83007. else {
  83008. unsigned q, r, d;
  83009. d = (1 << (k+1)) - parameter;
  83010. q = uval / parameter;
  83011. r = uval - (q * parameter);
  83012. bits = 1 + q + k;
  83013. if(r >= d)
  83014. bits++;
  83015. }
  83016. return bits;
  83017. }
  83018. #endif /* UNUSED */
  83019. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83020. {
  83021. unsigned total_bits, interesting_bits, msbs;
  83022. FLAC__uint32 uval, pattern;
  83023. FLAC__ASSERT(0 != bw);
  83024. FLAC__ASSERT(0 != bw->buffer);
  83025. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83026. uval = (val<<1) ^ (val>>31);
  83027. msbs = uval >> parameter;
  83028. interesting_bits = 1 + parameter;
  83029. total_bits = interesting_bits + msbs;
  83030. pattern = 1 << parameter; /* the unary end bit */
  83031. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83032. if(total_bits <= 32)
  83033. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83034. else
  83035. return
  83036. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83037. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83038. }
  83039. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83040. {
  83041. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83042. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83043. FLAC__uint32 uval;
  83044. unsigned left;
  83045. const unsigned lsbits = 1 + parameter;
  83046. unsigned msbits;
  83047. FLAC__ASSERT(0 != bw);
  83048. FLAC__ASSERT(0 != bw->buffer);
  83049. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83050. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83051. while(nvals) {
  83052. uval = (*vals<<1) ^ (*vals>>31);
  83053. msbits = uval >> parameter;
  83054. #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) */
  83055. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83056. bw->bits = bw->bits + msbits + lsbits;
  83057. uval |= mask1; /* set stop bit */
  83058. uval &= mask2; /* mask off unused top bits */
  83059. bw->accum <<= msbits;
  83060. bw->accum <<= lsbits;
  83061. bw->accum |= uval;
  83062. if(bw->bits == FLAC__BITS_PER_WORD) {
  83063. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83064. bw->bits = 0;
  83065. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83066. FLAC__ASSERT(bw->capacity == bw->words);
  83067. return false;
  83068. }
  83069. }
  83070. }
  83071. else {
  83072. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83073. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83074. bw->bits = bw->bits + msbits + lsbits;
  83075. uval |= mask1; /* set stop bit */
  83076. uval &= mask2; /* mask off unused top bits */
  83077. bw->accum <<= msbits + lsbits;
  83078. bw->accum |= uval;
  83079. }
  83080. else {
  83081. #endif
  83082. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83083. return false;
  83084. if(msbits) {
  83085. if(bw->bits) {
  83086. left = FLAC__BITS_PER_WORD - bw->bits;
  83087. if(msbits < left) {
  83088. bw->accum <<= msbits;
  83089. bw->bits += msbits;
  83090. goto break1;
  83091. }
  83092. else {
  83093. bw->accum <<= left;
  83094. msbits -= left;
  83095. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83096. bw->bits = 0;
  83097. }
  83098. }
  83099. while(msbits >= FLAC__BITS_PER_WORD) {
  83100. bw->buffer[bw->words++] = 0;
  83101. msbits -= FLAC__BITS_PER_WORD;
  83102. }
  83103. if(msbits > 0) {
  83104. bw->accum = 0;
  83105. bw->bits = msbits;
  83106. }
  83107. }
  83108. break1:
  83109. uval |= mask1; /* set stop bit */
  83110. uval &= mask2; /* mask off unused top bits */
  83111. left = FLAC__BITS_PER_WORD - bw->bits;
  83112. if(lsbits < left) {
  83113. bw->accum <<= lsbits;
  83114. bw->accum |= uval;
  83115. bw->bits += lsbits;
  83116. }
  83117. else {
  83118. FLAC__ASSERT(bw->bits);
  83119. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83120. bw->accum <<= left;
  83121. bw->accum |= uval >> (bw->bits = lsbits - left);
  83122. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83123. bw->accum = uval;
  83124. }
  83125. #if 1
  83126. }
  83127. #endif
  83128. vals++;
  83129. nvals--;
  83130. }
  83131. return true;
  83132. }
  83133. #if 0 /* UNUSED */
  83134. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83135. {
  83136. unsigned total_bits, msbs, uval;
  83137. unsigned k;
  83138. FLAC__ASSERT(0 != bw);
  83139. FLAC__ASSERT(0 != bw->buffer);
  83140. FLAC__ASSERT(parameter > 0);
  83141. if(val < 0)
  83142. uval = (unsigned)(((-(++val)) << 1) + 1);
  83143. else
  83144. uval = (unsigned)(val << 1);
  83145. k = FLAC__bitmath_ilog2(parameter);
  83146. if(parameter == 1u<<k) {
  83147. unsigned pattern;
  83148. FLAC__ASSERT(k <= 30);
  83149. msbs = uval >> k;
  83150. total_bits = 1 + k + msbs;
  83151. pattern = 1 << k; /* the unary end bit */
  83152. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83153. if(total_bits <= 32) {
  83154. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83155. return false;
  83156. }
  83157. else {
  83158. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83159. return false;
  83160. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83161. return false;
  83162. }
  83163. }
  83164. else {
  83165. unsigned q, r, d;
  83166. d = (1 << (k+1)) - parameter;
  83167. q = uval / parameter;
  83168. r = uval - (q * parameter);
  83169. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83170. return false;
  83171. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83172. return false;
  83173. if(r >= d) {
  83174. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83175. return false;
  83176. }
  83177. else {
  83178. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83179. return false;
  83180. }
  83181. }
  83182. return true;
  83183. }
  83184. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83185. {
  83186. unsigned total_bits, msbs;
  83187. unsigned k;
  83188. FLAC__ASSERT(0 != bw);
  83189. FLAC__ASSERT(0 != bw->buffer);
  83190. FLAC__ASSERT(parameter > 0);
  83191. k = FLAC__bitmath_ilog2(parameter);
  83192. if(parameter == 1u<<k) {
  83193. unsigned pattern;
  83194. FLAC__ASSERT(k <= 30);
  83195. msbs = uval >> k;
  83196. total_bits = 1 + k + msbs;
  83197. pattern = 1 << k; /* the unary end bit */
  83198. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83199. if(total_bits <= 32) {
  83200. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83201. return false;
  83202. }
  83203. else {
  83204. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83205. return false;
  83206. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83207. return false;
  83208. }
  83209. }
  83210. else {
  83211. unsigned q, r, d;
  83212. d = (1 << (k+1)) - parameter;
  83213. q = uval / parameter;
  83214. r = uval - (q * parameter);
  83215. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83216. return false;
  83217. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83218. return false;
  83219. if(r >= d) {
  83220. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83221. return false;
  83222. }
  83223. else {
  83224. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83225. return false;
  83226. }
  83227. }
  83228. return true;
  83229. }
  83230. #endif /* UNUSED */
  83231. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83232. {
  83233. FLAC__bool ok = 1;
  83234. FLAC__ASSERT(0 != bw);
  83235. FLAC__ASSERT(0 != bw->buffer);
  83236. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83237. if(val < 0x80) {
  83238. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83239. }
  83240. else if(val < 0x800) {
  83241. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83242. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83243. }
  83244. else if(val < 0x10000) {
  83245. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83246. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83247. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83248. }
  83249. else if(val < 0x200000) {
  83250. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83251. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83252. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83253. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83254. }
  83255. else if(val < 0x4000000) {
  83256. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83257. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83258. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83259. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83260. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83261. }
  83262. else {
  83263. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83264. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83265. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83266. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83267. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83268. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83269. }
  83270. return ok;
  83271. }
  83272. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83273. {
  83274. FLAC__bool ok = 1;
  83275. FLAC__ASSERT(0 != bw);
  83276. FLAC__ASSERT(0 != bw->buffer);
  83277. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83278. if(val < 0x80) {
  83279. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83280. }
  83281. else if(val < 0x800) {
  83282. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83283. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83284. }
  83285. else if(val < 0x10000) {
  83286. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83287. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83288. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83289. }
  83290. else if(val < 0x200000) {
  83291. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83292. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83293. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83294. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83295. }
  83296. else if(val < 0x4000000) {
  83297. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83298. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83299. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83300. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83301. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83302. }
  83303. else if(val < 0x80000000) {
  83304. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83305. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83306. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83307. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83308. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83309. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83310. }
  83311. else {
  83312. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83313. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83314. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83315. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83316. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83317. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83318. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83319. }
  83320. return ok;
  83321. }
  83322. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83323. {
  83324. if(bw->bits & 7u)
  83325. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83326. else
  83327. return true;
  83328. }
  83329. #endif
  83330. /*** End of inlined file: bitwriter.c ***/
  83331. /*** Start of inlined file: cpu.c ***/
  83332. /*** Start of inlined file: juce_FlacHeader.h ***/
  83333. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83334. // tasks..
  83335. #define VERSION "1.2.1"
  83336. #define FLAC__NO_DLL 1
  83337. #if JUCE_MSVC
  83338. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83339. #endif
  83340. #if JUCE_MAC
  83341. #define FLAC__SYS_DARWIN 1
  83342. #endif
  83343. /*** End of inlined file: juce_FlacHeader.h ***/
  83344. #if JUCE_USE_FLAC
  83345. #if HAVE_CONFIG_H
  83346. # include <config.h>
  83347. #endif
  83348. #include <stdlib.h>
  83349. #include <stdio.h>
  83350. #if defined FLAC__CPU_IA32
  83351. # include <signal.h>
  83352. #elif defined FLAC__CPU_PPC
  83353. # if !defined FLAC__NO_ASM
  83354. # if defined FLAC__SYS_DARWIN
  83355. # include <sys/sysctl.h>
  83356. # include <mach/mach.h>
  83357. # include <mach/mach_host.h>
  83358. # include <mach/host_info.h>
  83359. # include <mach/machine.h>
  83360. # ifndef CPU_SUBTYPE_POWERPC_970
  83361. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83362. # endif
  83363. # else /* FLAC__SYS_DARWIN */
  83364. # include <signal.h>
  83365. # include <setjmp.h>
  83366. static sigjmp_buf jmpbuf;
  83367. static volatile sig_atomic_t canjump = 0;
  83368. static void sigill_handler (int sig)
  83369. {
  83370. if (!canjump) {
  83371. signal (sig, SIG_DFL);
  83372. raise (sig);
  83373. }
  83374. canjump = 0;
  83375. siglongjmp (jmpbuf, 1);
  83376. }
  83377. # endif /* FLAC__SYS_DARWIN */
  83378. # endif /* FLAC__NO_ASM */
  83379. #endif /* FLAC__CPU_PPC */
  83380. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83381. #include <sys/param.h>
  83382. #include <sys/sysctl.h>
  83383. #include <machine/cpu.h>
  83384. #endif
  83385. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83386. #include <sys/types.h>
  83387. #include <sys/sysctl.h>
  83388. #endif
  83389. #if defined(__APPLE__)
  83390. #endif
  83391. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83392. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83393. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83394. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83395. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83396. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83397. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83398. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83399. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83400. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83401. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83402. # if defined(__linux__)
  83403. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83404. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83405. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83406. {
  83407. (void)signal;
  83408. sc.eip += 3 + 3 + 6;
  83409. }
  83410. # else
  83411. # include <sys/ucontext.h>
  83412. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83413. {
  83414. (void)signal, (void)si;
  83415. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83416. }
  83417. # endif
  83418. # elif defined(_MSC_VER)
  83419. # include <windows.h>
  83420. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83421. # ifdef USE_TRY_CATCH_FLAVOR
  83422. # else
  83423. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83424. {
  83425. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83426. ep->ContextRecord->Eip += 3 + 3 + 6;
  83427. return EXCEPTION_CONTINUE_EXECUTION;
  83428. }
  83429. return EXCEPTION_CONTINUE_SEARCH;
  83430. }
  83431. # endif
  83432. # endif
  83433. #endif
  83434. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83435. {
  83436. #ifdef FLAC__CPU_IA32
  83437. info->type = FLAC__CPUINFO_TYPE_IA32;
  83438. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83439. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83440. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83441. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83442. info->data.ia32.cmov = false;
  83443. info->data.ia32.mmx = false;
  83444. info->data.ia32.fxsr = false;
  83445. info->data.ia32.sse = false;
  83446. info->data.ia32.sse2 = false;
  83447. info->data.ia32.sse3 = false;
  83448. info->data.ia32.ssse3 = false;
  83449. info->data.ia32._3dnow = false;
  83450. info->data.ia32.ext3dnow = false;
  83451. info->data.ia32.extmmx = false;
  83452. if(info->data.ia32.cpuid) {
  83453. FLAC__uint32 flags_edx, flags_ecx;
  83454. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83455. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83456. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83457. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83458. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83459. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83460. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83461. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83462. #ifdef FLAC__USE_3DNOW
  83463. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83464. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83465. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83466. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83467. #else
  83468. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83469. #endif
  83470. #ifdef DEBUG
  83471. fprintf(stderr, "CPU info (IA-32):\n");
  83472. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83473. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83474. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83475. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83476. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83477. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83478. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83479. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83480. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83481. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83482. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83483. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83484. #endif
  83485. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83486. #if defined FLAC__NO_SSE_OS
  83487. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83488. #elif defined FLAC__SSE_OS
  83489. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83490. int sse = 0;
  83491. size_t len;
  83492. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83493. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83494. if(!sse)
  83495. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83496. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83497. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83498. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83499. size_t len = sizeof(val);
  83500. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83501. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83502. else { /* double-check SSE2 */
  83503. mib[1] = CPU_SSE2;
  83504. len = sizeof(val);
  83505. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83506. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83507. }
  83508. # else
  83509. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83510. # endif
  83511. #elif defined(__linux__)
  83512. int sse = 0;
  83513. struct sigaction sigill_save;
  83514. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83515. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83516. #else
  83517. struct sigaction sigill_sse;
  83518. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83519. __sigemptyset(&sigill_sse.sa_mask);
  83520. 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 */
  83521. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83522. #endif
  83523. {
  83524. asm volatile (
  83525. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83526. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83527. "incl %0\n\t" /* SIGILL handler will jump over this */
  83528. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83529. "nop\n\t"
  83530. "nop\n\t"
  83531. "nop\n\t"
  83532. "nop\n\t"
  83533. "nop\n\t"
  83534. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83535. "nop\n\t"
  83536. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83537. : "=r"(sse)
  83538. : "r"(sse)
  83539. );
  83540. sigaction(SIGILL, &sigill_save, NULL);
  83541. }
  83542. if(!sse)
  83543. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83544. #elif defined(_MSC_VER)
  83545. # ifdef USE_TRY_CATCH_FLAVOR
  83546. _try {
  83547. __asm {
  83548. # if _MSC_VER <= 1200
  83549. _emit 0x0F
  83550. _emit 0x57
  83551. _emit 0xC0
  83552. # else
  83553. xorps xmm0,xmm0
  83554. # endif
  83555. }
  83556. }
  83557. _except(EXCEPTION_EXECUTE_HANDLER) {
  83558. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83559. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83560. }
  83561. # else
  83562. int sse = 0;
  83563. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83564. __asm {
  83565. # if _MSC_VER <= 1200
  83566. _emit 0x0F
  83567. _emit 0x57
  83568. _emit 0xC0
  83569. # else
  83570. xorps xmm0,xmm0
  83571. # endif
  83572. inc sse
  83573. nop
  83574. nop
  83575. nop
  83576. nop
  83577. nop
  83578. nop
  83579. nop
  83580. nop
  83581. nop
  83582. }
  83583. SetUnhandledExceptionFilter(save);
  83584. if(!sse)
  83585. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83586. # endif
  83587. #else
  83588. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83589. #endif
  83590. #ifdef DEBUG
  83591. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83592. #endif
  83593. }
  83594. }
  83595. #else
  83596. info->use_asm = false;
  83597. #endif
  83598. #elif defined FLAC__CPU_PPC
  83599. info->type = FLAC__CPUINFO_TYPE_PPC;
  83600. # if !defined FLAC__NO_ASM
  83601. info->use_asm = true;
  83602. # ifdef FLAC__USE_ALTIVEC
  83603. # if defined FLAC__SYS_DARWIN
  83604. {
  83605. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83606. size_t len = sizeof(val);
  83607. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83608. }
  83609. {
  83610. host_basic_info_data_t hostInfo;
  83611. mach_msg_type_number_t infoCount;
  83612. infoCount = HOST_BASIC_INFO_COUNT;
  83613. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83614. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83615. }
  83616. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83617. {
  83618. info->data.ppc.altivec = 0;
  83619. info->data.ppc.ppc64 = 0;
  83620. signal (SIGILL, sigill_handler);
  83621. canjump = 0;
  83622. if (!sigsetjmp (jmpbuf, 1)) {
  83623. canjump = 1;
  83624. asm volatile (
  83625. "mtspr 256, %0\n\t"
  83626. "vand %%v0, %%v0, %%v0"
  83627. :
  83628. : "r" (-1)
  83629. );
  83630. info->data.ppc.altivec = 1;
  83631. }
  83632. canjump = 0;
  83633. if (!sigsetjmp (jmpbuf, 1)) {
  83634. int x = 0;
  83635. canjump = 1;
  83636. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83637. info->data.ppc.ppc64 = 1;
  83638. }
  83639. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83640. }
  83641. # endif
  83642. # else /* !FLAC__USE_ALTIVEC */
  83643. info->data.ppc.altivec = 0;
  83644. info->data.ppc.ppc64 = 0;
  83645. # endif
  83646. # else
  83647. info->use_asm = false;
  83648. # endif
  83649. #else
  83650. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83651. info->use_asm = false;
  83652. #endif
  83653. }
  83654. #endif
  83655. /*** End of inlined file: cpu.c ***/
  83656. /*** Start of inlined file: crc.c ***/
  83657. /*** Start of inlined file: juce_FlacHeader.h ***/
  83658. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83659. // tasks..
  83660. #define VERSION "1.2.1"
  83661. #define FLAC__NO_DLL 1
  83662. #if JUCE_MSVC
  83663. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83664. #endif
  83665. #if JUCE_MAC
  83666. #define FLAC__SYS_DARWIN 1
  83667. #endif
  83668. /*** End of inlined file: juce_FlacHeader.h ***/
  83669. #if JUCE_USE_FLAC
  83670. #if HAVE_CONFIG_H
  83671. # include <config.h>
  83672. #endif
  83673. FLAC__byte const FLAC__crc8_table[256] = {
  83674. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83675. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83676. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83677. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83678. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83679. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83680. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83681. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83682. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83683. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83684. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83685. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83686. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83687. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83688. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83689. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83690. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83691. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83692. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83693. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83694. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83695. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83696. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83697. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83698. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83699. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83700. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83701. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83702. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83703. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83704. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83705. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83706. };
  83707. unsigned FLAC__crc16_table[256] = {
  83708. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83709. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83710. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83711. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83712. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83713. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83714. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83715. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83716. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83717. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83718. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83719. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83720. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83721. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83722. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83723. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83724. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83725. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83726. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83727. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83728. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83729. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83730. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83731. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83732. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83733. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83734. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83735. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83736. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83737. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83738. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83739. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83740. };
  83741. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83742. {
  83743. *crc = FLAC__crc8_table[*crc ^ data];
  83744. }
  83745. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83746. {
  83747. while(len--)
  83748. *crc = FLAC__crc8_table[*crc ^ *data++];
  83749. }
  83750. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83751. {
  83752. FLAC__uint8 crc = 0;
  83753. while(len--)
  83754. crc = FLAC__crc8_table[crc ^ *data++];
  83755. return crc;
  83756. }
  83757. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83758. {
  83759. unsigned crc = 0;
  83760. while(len--)
  83761. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83762. return crc;
  83763. }
  83764. #endif
  83765. /*** End of inlined file: crc.c ***/
  83766. /*** Start of inlined file: fixed.c ***/
  83767. /*** Start of inlined file: juce_FlacHeader.h ***/
  83768. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83769. // tasks..
  83770. #define VERSION "1.2.1"
  83771. #define FLAC__NO_DLL 1
  83772. #if JUCE_MSVC
  83773. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83774. #endif
  83775. #if JUCE_MAC
  83776. #define FLAC__SYS_DARWIN 1
  83777. #endif
  83778. /*** End of inlined file: juce_FlacHeader.h ***/
  83779. #if JUCE_USE_FLAC
  83780. #if HAVE_CONFIG_H
  83781. # include <config.h>
  83782. #endif
  83783. #include <math.h>
  83784. #include <string.h>
  83785. /*** Start of inlined file: fixed.h ***/
  83786. #ifndef FLAC__PRIVATE__FIXED_H
  83787. #define FLAC__PRIVATE__FIXED_H
  83788. #ifdef HAVE_CONFIG_H
  83789. #include <config.h>
  83790. #endif
  83791. /*** Start of inlined file: float.h ***/
  83792. #ifndef FLAC__PRIVATE__FLOAT_H
  83793. #define FLAC__PRIVATE__FLOAT_H
  83794. #ifdef HAVE_CONFIG_H
  83795. #include <config.h>
  83796. #endif
  83797. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83798. typedef double FLAC__double;
  83799. typedef float FLAC__float;
  83800. typedef float FLAC__real;
  83801. #else
  83802. typedef FLAC__int32 FLAC__fixedpoint;
  83803. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83804. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83805. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83806. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83807. extern const FLAC__fixedpoint FLAC__FP_E;
  83808. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83809. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83810. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83811. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83812. #endif
  83813. #endif
  83814. /*** End of inlined file: float.h ***/
  83815. /*** Start of inlined file: format.h ***/
  83816. #ifndef FLAC__PRIVATE__FORMAT_H
  83817. #define FLAC__PRIVATE__FORMAT_H
  83818. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83819. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83820. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83821. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83822. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83823. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83824. #endif
  83825. /*** End of inlined file: format.h ***/
  83826. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83827. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83828. # ifndef FLAC__NO_ASM
  83829. # ifdef FLAC__CPU_IA32
  83830. # ifdef FLAC__HAS_NASM
  83831. 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]);
  83832. # endif
  83833. # endif
  83834. # endif
  83835. 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]);
  83836. #else
  83837. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83838. 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]);
  83839. #endif
  83840. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83841. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83842. #endif
  83843. /*** End of inlined file: fixed.h ***/
  83844. #ifndef M_LN2
  83845. #define M_LN2 0.69314718055994530942
  83846. #endif
  83847. #ifdef min
  83848. #undef min
  83849. #endif
  83850. #define min(x,y) ((x) < (y)? (x) : (y))
  83851. #ifdef local_abs
  83852. #undef local_abs
  83853. #endif
  83854. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83855. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83856. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83857. {
  83858. FLAC__uint32 rbps;
  83859. unsigned bits; /* the number of bits required to represent a number */
  83860. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83861. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83862. FLAC__ASSERT(err > 0);
  83863. FLAC__ASSERT(n > 0);
  83864. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83865. if(err <= n)
  83866. return 0;
  83867. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83868. err <<= fracbits;
  83869. err /= n;
  83870. FLAC__ASSERT(err > 0);
  83871. bits = FLAC__bitmath_ilog2(err)+1;
  83872. if(bits > 16) {
  83873. err >>= (bits-16);
  83874. fracbits -= (bits-16);
  83875. }
  83876. rbps = (FLAC__uint32)err;
  83877. rbps *= FLAC__FP_LN2;
  83878. fracbits += 16;
  83879. FLAC__ASSERT(fracbits >= 0);
  83880. {
  83881. const int f = fracbits & 3;
  83882. if(f) {
  83883. rbps >>= f;
  83884. fracbits -= f;
  83885. }
  83886. }
  83887. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83888. if(rbps == 0)
  83889. return 0;
  83890. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83891. FLAC__ASSERT(fracbits >= -3);
  83892. if(fracbits < 16)
  83893. return rbps << (16-fracbits);
  83894. else if(fracbits > 16)
  83895. return rbps >> (fracbits-16);
  83896. else
  83897. return rbps;
  83898. }
  83899. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83900. {
  83901. FLAC__uint32 rbps;
  83902. unsigned bits; /* the number of bits required to represent a number */
  83903. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83904. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83905. FLAC__ASSERT(err > 0);
  83906. FLAC__ASSERT(n > 0);
  83907. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83908. if(err <= n)
  83909. return 0;
  83910. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83911. err <<= fracbits;
  83912. err /= n;
  83913. FLAC__ASSERT(err > 0);
  83914. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83915. if(bits > 16) {
  83916. err >>= (bits-16);
  83917. fracbits -= (bits-16);
  83918. }
  83919. rbps = (FLAC__uint32)err;
  83920. rbps *= FLAC__FP_LN2;
  83921. fracbits += 16;
  83922. FLAC__ASSERT(fracbits >= 0);
  83923. {
  83924. const int f = fracbits & 3;
  83925. if(f) {
  83926. rbps >>= f;
  83927. fracbits -= f;
  83928. }
  83929. }
  83930. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83931. if(rbps == 0)
  83932. return 0;
  83933. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83934. FLAC__ASSERT(fracbits >= -3);
  83935. if(fracbits < 16)
  83936. return rbps << (16-fracbits);
  83937. else if(fracbits > 16)
  83938. return rbps >> (fracbits-16);
  83939. else
  83940. return rbps;
  83941. }
  83942. #endif
  83943. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83944. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83945. #else
  83946. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83947. #endif
  83948. {
  83949. FLAC__int32 last_error_0 = data[-1];
  83950. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83951. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83952. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83953. FLAC__int32 error, save;
  83954. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83955. unsigned i, order;
  83956. for(i = 0; i < data_len; i++) {
  83957. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83958. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83959. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83960. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83961. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83962. }
  83963. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83964. order = 0;
  83965. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83966. order = 1;
  83967. else if(total_error_2 < min(total_error_3, total_error_4))
  83968. order = 2;
  83969. else if(total_error_3 < total_error_4)
  83970. order = 3;
  83971. else
  83972. order = 4;
  83973. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83974. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83975. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83976. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83977. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83978. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83979. 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);
  83980. 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);
  83981. 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);
  83982. 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);
  83983. 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);
  83984. #else
  83985. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  83986. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  83987. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  83988. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  83989. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  83990. #endif
  83991. return order;
  83992. }
  83993. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83994. 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])
  83995. #else
  83996. 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])
  83997. #endif
  83998. {
  83999. FLAC__int32 last_error_0 = data[-1];
  84000. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84001. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84002. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84003. FLAC__int32 error, save;
  84004. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84005. unsigned i, order;
  84006. for(i = 0; i < data_len; i++) {
  84007. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84008. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84009. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84010. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84011. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84012. }
  84013. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84014. order = 0;
  84015. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84016. order = 1;
  84017. else if(total_error_2 < min(total_error_3, total_error_4))
  84018. order = 2;
  84019. else if(total_error_3 < total_error_4)
  84020. order = 3;
  84021. else
  84022. order = 4;
  84023. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84024. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84025. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84026. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84027. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84028. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84029. #if defined _MSC_VER || defined __MINGW32__
  84030. 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);
  84031. 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);
  84032. 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);
  84033. 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);
  84034. 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);
  84035. #else
  84036. 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);
  84037. 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);
  84038. 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);
  84039. 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);
  84040. 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);
  84041. #endif
  84042. #else
  84043. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84044. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84045. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84046. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84047. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84048. #endif
  84049. return order;
  84050. }
  84051. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84052. {
  84053. const int idata_len = (int)data_len;
  84054. int i;
  84055. switch(order) {
  84056. case 0:
  84057. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84058. memcpy(residual, data, sizeof(residual[0])*data_len);
  84059. break;
  84060. case 1:
  84061. for(i = 0; i < idata_len; i++)
  84062. residual[i] = data[i] - data[i-1];
  84063. break;
  84064. case 2:
  84065. for(i = 0; i < idata_len; i++)
  84066. #if 1 /* OPT: may be faster with some compilers on some systems */
  84067. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84068. #else
  84069. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84070. #endif
  84071. break;
  84072. case 3:
  84073. for(i = 0; i < idata_len; i++)
  84074. #if 1 /* OPT: may be faster with some compilers on some systems */
  84075. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84076. #else
  84077. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84078. #endif
  84079. break;
  84080. case 4:
  84081. for(i = 0; i < idata_len; i++)
  84082. #if 1 /* OPT: may be faster with some compilers on some systems */
  84083. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84084. #else
  84085. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84086. #endif
  84087. break;
  84088. default:
  84089. FLAC__ASSERT(0);
  84090. }
  84091. }
  84092. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84093. {
  84094. int i, idata_len = (int)data_len;
  84095. switch(order) {
  84096. case 0:
  84097. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84098. memcpy(data, residual, sizeof(residual[0])*data_len);
  84099. break;
  84100. case 1:
  84101. for(i = 0; i < idata_len; i++)
  84102. data[i] = residual[i] + data[i-1];
  84103. break;
  84104. case 2:
  84105. for(i = 0; i < idata_len; i++)
  84106. #if 1 /* OPT: may be faster with some compilers on some systems */
  84107. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84108. #else
  84109. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84110. #endif
  84111. break;
  84112. case 3:
  84113. for(i = 0; i < idata_len; i++)
  84114. #if 1 /* OPT: may be faster with some compilers on some systems */
  84115. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84116. #else
  84117. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84118. #endif
  84119. break;
  84120. case 4:
  84121. for(i = 0; i < idata_len; i++)
  84122. #if 1 /* OPT: may be faster with some compilers on some systems */
  84123. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84124. #else
  84125. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84126. #endif
  84127. break;
  84128. default:
  84129. FLAC__ASSERT(0);
  84130. }
  84131. }
  84132. #endif
  84133. /*** End of inlined file: fixed.c ***/
  84134. /*** Start of inlined file: float.c ***/
  84135. /*** Start of inlined file: juce_FlacHeader.h ***/
  84136. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84137. // tasks..
  84138. #define VERSION "1.2.1"
  84139. #define FLAC__NO_DLL 1
  84140. #if JUCE_MSVC
  84141. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84142. #endif
  84143. #if JUCE_MAC
  84144. #define FLAC__SYS_DARWIN 1
  84145. #endif
  84146. /*** End of inlined file: juce_FlacHeader.h ***/
  84147. #if JUCE_USE_FLAC
  84148. #if HAVE_CONFIG_H
  84149. # include <config.h>
  84150. #endif
  84151. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84152. #ifdef _MSC_VER
  84153. #define FLAC__U64L(x) x
  84154. #else
  84155. #define FLAC__U64L(x) x##LLU
  84156. #endif
  84157. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84158. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84159. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84160. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84161. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84162. #define LOG2_LOOKUP_PRECISION 16
  84163. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84164. {
  84165. 0x00000000,
  84166. 0x00000001,
  84167. 0x00000000,
  84168. 0x00000000,
  84169. 0x00000000,
  84170. 0x00000000,
  84171. 0x00000000,
  84172. 0x00000000,
  84173. 0x00000000,
  84174. 0x00000000,
  84175. 0x00000000,
  84176. 0x00000000,
  84177. 0x00000000,
  84178. 0x00000000,
  84179. 0x00000000,
  84180. 0x00000000
  84181. },
  84182. {
  84183. 0x00000000,
  84184. 0x00000010,
  84185. 0x00000007,
  84186. 0x00000003,
  84187. 0x00000001,
  84188. 0x00000001,
  84189. 0x00000000,
  84190. 0x00000000,
  84191. 0x00000000,
  84192. 0x00000000,
  84193. 0x00000000,
  84194. 0x00000000,
  84195. 0x00000000,
  84196. 0x00000000,
  84197. 0x00000000,
  84198. 0x00000000
  84199. },
  84200. {
  84201. 0x00000000,
  84202. 0x00000100,
  84203. 0x0000006a,
  84204. 0x00000031,
  84205. 0x00000018,
  84206. 0x0000000c,
  84207. 0x00000006,
  84208. 0x00000003,
  84209. 0x00000001,
  84210. 0x00000001,
  84211. 0x00000000,
  84212. 0x00000000,
  84213. 0x00000000,
  84214. 0x00000000,
  84215. 0x00000000,
  84216. 0x00000000
  84217. },
  84218. {
  84219. 0x00000000,
  84220. 0x00001000,
  84221. 0x000006a4,
  84222. 0x00000315,
  84223. 0x0000017d,
  84224. 0x000000bc,
  84225. 0x0000005d,
  84226. 0x0000002e,
  84227. 0x00000017,
  84228. 0x0000000c,
  84229. 0x00000006,
  84230. 0x00000003,
  84231. 0x00000001,
  84232. 0x00000001,
  84233. 0x00000000,
  84234. 0x00000000
  84235. },
  84236. {
  84237. 0x00000000,
  84238. 0x00010000,
  84239. 0x00006a40,
  84240. 0x00003151,
  84241. 0x000017d6,
  84242. 0x00000bba,
  84243. 0x000005d1,
  84244. 0x000002e6,
  84245. 0x00000172,
  84246. 0x000000b9,
  84247. 0x0000005c,
  84248. 0x0000002e,
  84249. 0x00000017,
  84250. 0x0000000c,
  84251. 0x00000006,
  84252. 0x00000003
  84253. },
  84254. {
  84255. 0x00000000,
  84256. 0x00100000,
  84257. 0x0006a3fe,
  84258. 0x00031513,
  84259. 0x00017d60,
  84260. 0x0000bb9d,
  84261. 0x00005d10,
  84262. 0x00002e59,
  84263. 0x00001721,
  84264. 0x00000b8e,
  84265. 0x000005c6,
  84266. 0x000002e3,
  84267. 0x00000171,
  84268. 0x000000b9,
  84269. 0x0000005c,
  84270. 0x0000002e
  84271. },
  84272. {
  84273. 0x00000000,
  84274. 0x01000000,
  84275. 0x006a3fe6,
  84276. 0x00315130,
  84277. 0x0017d605,
  84278. 0x000bb9ca,
  84279. 0x0005d0fc,
  84280. 0x0002e58f,
  84281. 0x0001720e,
  84282. 0x0000b8d8,
  84283. 0x00005c61,
  84284. 0x00002e2d,
  84285. 0x00001716,
  84286. 0x00000b8b,
  84287. 0x000005c5,
  84288. 0x000002e3
  84289. },
  84290. {
  84291. 0x00000000,
  84292. 0x10000000,
  84293. 0x06a3fe5c,
  84294. 0x03151301,
  84295. 0x017d6049,
  84296. 0x00bb9ca6,
  84297. 0x005d0fba,
  84298. 0x002e58f7,
  84299. 0x001720da,
  84300. 0x000b8d87,
  84301. 0x0005c60b,
  84302. 0x0002e2d7,
  84303. 0x00017160,
  84304. 0x0000b8ad,
  84305. 0x00005c56,
  84306. 0x00002e2b
  84307. }
  84308. };
  84309. #if 0
  84310. static const FLAC__uint64 log2_lookup_wide[] = {
  84311. {
  84312. 0x00000000,
  84313. FLAC__U64L(0x100000000),
  84314. FLAC__U64L(0x6a3fe5c6),
  84315. FLAC__U64L(0x31513015),
  84316. FLAC__U64L(0x17d60497),
  84317. FLAC__U64L(0x0bb9ca65),
  84318. FLAC__U64L(0x05d0fba2),
  84319. FLAC__U64L(0x02e58f74),
  84320. FLAC__U64L(0x01720d9c),
  84321. FLAC__U64L(0x00b8d875),
  84322. FLAC__U64L(0x005c60aa),
  84323. FLAC__U64L(0x002e2d72),
  84324. FLAC__U64L(0x00171600),
  84325. FLAC__U64L(0x000b8ad2),
  84326. FLAC__U64L(0x0005c55d),
  84327. FLAC__U64L(0x0002e2ac)
  84328. },
  84329. {
  84330. 0x00000000,
  84331. FLAC__U64L(0x1000000000000),
  84332. FLAC__U64L(0x6a3fe5c60429),
  84333. FLAC__U64L(0x315130157f7a),
  84334. FLAC__U64L(0x17d60496cfbb),
  84335. FLAC__U64L(0xbb9ca64ecac),
  84336. FLAC__U64L(0x5d0fba187cd),
  84337. FLAC__U64L(0x2e58f7441ee),
  84338. FLAC__U64L(0x1720d9c06a8),
  84339. FLAC__U64L(0xb8d8752173),
  84340. FLAC__U64L(0x5c60aa252e),
  84341. FLAC__U64L(0x2e2d71b0d8),
  84342. FLAC__U64L(0x1716001719),
  84343. FLAC__U64L(0xb8ad1de1b),
  84344. FLAC__U64L(0x5c55d640d),
  84345. FLAC__U64L(0x2e2abcf52)
  84346. }
  84347. };
  84348. #endif
  84349. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84350. {
  84351. const FLAC__uint32 ONE = (1u << fracbits);
  84352. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84353. FLAC__ASSERT(fracbits < 32);
  84354. FLAC__ASSERT((fracbits & 0x3) == 0);
  84355. if(x < ONE)
  84356. return 0;
  84357. if(precision > LOG2_LOOKUP_PRECISION)
  84358. precision = LOG2_LOOKUP_PRECISION;
  84359. {
  84360. FLAC__uint32 y = 0;
  84361. FLAC__uint32 z = x >> 1, k = 1;
  84362. while (x > ONE && k < precision) {
  84363. if (x - z >= ONE) {
  84364. x -= z;
  84365. z = x >> k;
  84366. y += table[k];
  84367. }
  84368. else {
  84369. z >>= 1;
  84370. k++;
  84371. }
  84372. }
  84373. return y;
  84374. }
  84375. }
  84376. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84377. #endif
  84378. /*** End of inlined file: float.c ***/
  84379. /*** Start of inlined file: format.c ***/
  84380. /*** Start of inlined file: juce_FlacHeader.h ***/
  84381. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84382. // tasks..
  84383. #define VERSION "1.2.1"
  84384. #define FLAC__NO_DLL 1
  84385. #if JUCE_MSVC
  84386. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84387. #endif
  84388. #if JUCE_MAC
  84389. #define FLAC__SYS_DARWIN 1
  84390. #endif
  84391. /*** End of inlined file: juce_FlacHeader.h ***/
  84392. #if JUCE_USE_FLAC
  84393. #if HAVE_CONFIG_H
  84394. # include <config.h>
  84395. #endif
  84396. #include <stdio.h>
  84397. #include <stdlib.h> /* for qsort() */
  84398. #include <string.h> /* for memset() */
  84399. #ifndef FLaC__INLINE
  84400. #define FLaC__INLINE
  84401. #endif
  84402. #ifdef min
  84403. #undef min
  84404. #endif
  84405. #define min(a,b) ((a)<(b)?(a):(b))
  84406. #ifdef _MSC_VER
  84407. #define FLAC__U64L(x) x
  84408. #else
  84409. #define FLAC__U64L(x) x##LLU
  84410. #endif
  84411. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84412. ;
  84413. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84414. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84415. #else
  84416. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84417. #endif
  84418. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84419. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84420. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84421. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84422. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84423. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84424. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84425. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84426. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84427. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84428. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84429. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84430. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84431. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84432. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84433. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84434. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84435. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84436. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84437. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84438. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84439. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84440. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84441. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84442. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84443. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84444. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84445. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84446. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84447. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84448. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84449. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84450. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84451. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84452. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84453. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84454. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84455. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84456. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84457. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84458. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84459. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84460. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84461. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84462. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84463. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84464. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84465. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84466. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84467. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84468. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84469. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84470. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84471. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84472. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84473. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84474. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84475. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84476. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84477. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84478. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84479. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84480. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84481. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84482. "PARTITIONED_RICE",
  84483. "PARTITIONED_RICE2"
  84484. };
  84485. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84486. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84487. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84488. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84489. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84490. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84491. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84492. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84493. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84494. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84495. "CONSTANT",
  84496. "VERBATIM",
  84497. "FIXED",
  84498. "LPC"
  84499. };
  84500. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84501. "INDEPENDENT",
  84502. "LEFT_SIDE",
  84503. "RIGHT_SIDE",
  84504. "MID_SIDE"
  84505. };
  84506. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84507. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84508. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84509. };
  84510. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84511. "STREAMINFO",
  84512. "PADDING",
  84513. "APPLICATION",
  84514. "SEEKTABLE",
  84515. "VORBIS_COMMENT",
  84516. "CUESHEET",
  84517. "PICTURE"
  84518. };
  84519. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84520. "Other",
  84521. "32x32 pixels 'file icon' (PNG only)",
  84522. "Other file icon",
  84523. "Cover (front)",
  84524. "Cover (back)",
  84525. "Leaflet page",
  84526. "Media (e.g. label side of CD)",
  84527. "Lead artist/lead performer/soloist",
  84528. "Artist/performer",
  84529. "Conductor",
  84530. "Band/Orchestra",
  84531. "Composer",
  84532. "Lyricist/text writer",
  84533. "Recording Location",
  84534. "During recording",
  84535. "During performance",
  84536. "Movie/video screen capture",
  84537. "A bright coloured fish",
  84538. "Illustration",
  84539. "Band/artist logotype",
  84540. "Publisher/Studio logotype"
  84541. };
  84542. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84543. {
  84544. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84545. return false;
  84546. }
  84547. else
  84548. return true;
  84549. }
  84550. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84551. {
  84552. if(
  84553. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84554. (
  84555. sample_rate >= (1u << 16) &&
  84556. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84557. )
  84558. ) {
  84559. return false;
  84560. }
  84561. else
  84562. return true;
  84563. }
  84564. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84565. {
  84566. unsigned i;
  84567. FLAC__uint64 prev_sample_number = 0;
  84568. FLAC__bool got_prev = false;
  84569. FLAC__ASSERT(0 != seek_table);
  84570. for(i = 0; i < seek_table->num_points; i++) {
  84571. if(got_prev) {
  84572. if(
  84573. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84574. seek_table->points[i].sample_number <= prev_sample_number
  84575. )
  84576. return false;
  84577. }
  84578. prev_sample_number = seek_table->points[i].sample_number;
  84579. got_prev = true;
  84580. }
  84581. return true;
  84582. }
  84583. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84584. {
  84585. if(l->sample_number == r->sample_number)
  84586. return 0;
  84587. else if(l->sample_number < r->sample_number)
  84588. return -1;
  84589. else
  84590. return 1;
  84591. }
  84592. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84593. {
  84594. unsigned i, j;
  84595. FLAC__bool first;
  84596. FLAC__ASSERT(0 != seek_table);
  84597. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84598. first = true;
  84599. for(i = j = 0; i < seek_table->num_points; i++) {
  84600. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84601. if(!first) {
  84602. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84603. continue;
  84604. }
  84605. }
  84606. first = false;
  84607. seek_table->points[j++] = seek_table->points[i];
  84608. }
  84609. for(i = j; i < seek_table->num_points; i++) {
  84610. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84611. seek_table->points[i].stream_offset = 0;
  84612. seek_table->points[i].frame_samples = 0;
  84613. }
  84614. return j;
  84615. }
  84616. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84617. {
  84618. FLAC__ASSERT(0 != utf8);
  84619. if ((utf8[0] & 0x80) == 0) {
  84620. return 1;
  84621. }
  84622. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84623. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84624. return 0;
  84625. return 2;
  84626. }
  84627. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84628. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84629. return 0;
  84630. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84631. return 0;
  84632. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84633. return 0;
  84634. return 3;
  84635. }
  84636. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84637. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84638. return 0;
  84639. return 4;
  84640. }
  84641. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84642. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84643. return 0;
  84644. return 5;
  84645. }
  84646. 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) {
  84647. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84648. return 0;
  84649. return 6;
  84650. }
  84651. else {
  84652. return 0;
  84653. }
  84654. }
  84655. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84656. {
  84657. char c;
  84658. for(c = *name; c; c = *(++name))
  84659. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84660. return false;
  84661. return true;
  84662. }
  84663. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84664. {
  84665. if(length == (unsigned)(-1)) {
  84666. while(*value) {
  84667. unsigned n = utf8len_(value);
  84668. if(n == 0)
  84669. return false;
  84670. value += n;
  84671. }
  84672. }
  84673. else {
  84674. const FLAC__byte *end = value + length;
  84675. while(value < end) {
  84676. unsigned n = utf8len_(value);
  84677. if(n == 0)
  84678. return false;
  84679. value += n;
  84680. }
  84681. if(value != end)
  84682. return false;
  84683. }
  84684. return true;
  84685. }
  84686. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84687. {
  84688. const FLAC__byte *s, *end;
  84689. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84690. if(*s < 0x20 || *s > 0x7D)
  84691. return false;
  84692. }
  84693. if(s == end)
  84694. return false;
  84695. s++; /* skip '=' */
  84696. while(s < end) {
  84697. unsigned n = utf8len_(s);
  84698. if(n == 0)
  84699. return false;
  84700. s += n;
  84701. }
  84702. if(s != end)
  84703. return false;
  84704. return true;
  84705. }
  84706. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84707. {
  84708. unsigned i, j;
  84709. if(check_cd_da_subset) {
  84710. if(cue_sheet->lead_in < 2 * 44100) {
  84711. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84712. return false;
  84713. }
  84714. if(cue_sheet->lead_in % 588 != 0) {
  84715. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84716. return false;
  84717. }
  84718. }
  84719. if(cue_sheet->num_tracks == 0) {
  84720. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84721. return false;
  84722. }
  84723. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84724. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84725. return false;
  84726. }
  84727. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84728. if(cue_sheet->tracks[i].number == 0) {
  84729. if(violation) *violation = "cue sheet may not have a track number 0";
  84730. return false;
  84731. }
  84732. if(check_cd_da_subset) {
  84733. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84734. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84735. return false;
  84736. }
  84737. }
  84738. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84739. if(violation) {
  84740. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84741. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84742. else
  84743. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84744. }
  84745. return false;
  84746. }
  84747. if(i < cue_sheet->num_tracks - 1) {
  84748. if(cue_sheet->tracks[i].num_indices == 0) {
  84749. if(violation) *violation = "cue sheet track must have at least one index point";
  84750. return false;
  84751. }
  84752. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84753. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84754. return false;
  84755. }
  84756. }
  84757. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84758. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84759. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84760. return false;
  84761. }
  84762. if(j > 0) {
  84763. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84764. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84765. return false;
  84766. }
  84767. }
  84768. }
  84769. }
  84770. return true;
  84771. }
  84772. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84773. {
  84774. char *p;
  84775. FLAC__byte *b;
  84776. for(p = picture->mime_type; *p; p++) {
  84777. if(*p < 0x20 || *p > 0x7e) {
  84778. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84779. return false;
  84780. }
  84781. }
  84782. for(b = picture->description; *b; ) {
  84783. unsigned n = utf8len_(b);
  84784. if(n == 0) {
  84785. if(violation) *violation = "description string must be valid UTF-8";
  84786. return false;
  84787. }
  84788. b += n;
  84789. }
  84790. return true;
  84791. }
  84792. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84793. {
  84794. return
  84795. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84796. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84797. blocksize,
  84798. predictor_order
  84799. );
  84800. }
  84801. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84802. {
  84803. unsigned max_rice_partition_order = 0;
  84804. while(!(blocksize & 1)) {
  84805. max_rice_partition_order++;
  84806. blocksize >>= 1;
  84807. }
  84808. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84809. }
  84810. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84811. {
  84812. unsigned max_rice_partition_order = limit;
  84813. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84814. max_rice_partition_order--;
  84815. FLAC__ASSERT(
  84816. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84817. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84818. );
  84819. return max_rice_partition_order;
  84820. }
  84821. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84822. {
  84823. FLAC__ASSERT(0 != object);
  84824. object->parameters = 0;
  84825. object->raw_bits = 0;
  84826. object->capacity_by_order = 0;
  84827. }
  84828. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84829. {
  84830. FLAC__ASSERT(0 != object);
  84831. if(0 != object->parameters)
  84832. free(object->parameters);
  84833. if(0 != object->raw_bits)
  84834. free(object->raw_bits);
  84835. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84836. }
  84837. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84838. {
  84839. FLAC__ASSERT(0 != object);
  84840. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84841. if(object->capacity_by_order < max_partition_order) {
  84842. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84843. return false;
  84844. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84845. return false;
  84846. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84847. object->capacity_by_order = max_partition_order;
  84848. }
  84849. return true;
  84850. }
  84851. #endif
  84852. /*** End of inlined file: format.c ***/
  84853. /*** Start of inlined file: lpc_flac.c ***/
  84854. /*** Start of inlined file: juce_FlacHeader.h ***/
  84855. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84856. // tasks..
  84857. #define VERSION "1.2.1"
  84858. #define FLAC__NO_DLL 1
  84859. #if JUCE_MSVC
  84860. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84861. #endif
  84862. #if JUCE_MAC
  84863. #define FLAC__SYS_DARWIN 1
  84864. #endif
  84865. /*** End of inlined file: juce_FlacHeader.h ***/
  84866. #if JUCE_USE_FLAC
  84867. #if HAVE_CONFIG_H
  84868. # include <config.h>
  84869. #endif
  84870. #include <math.h>
  84871. /*** Start of inlined file: lpc.h ***/
  84872. #ifndef FLAC__PRIVATE__LPC_H
  84873. #define FLAC__PRIVATE__LPC_H
  84874. #ifdef HAVE_CONFIG_H
  84875. #include <config.h>
  84876. #endif
  84877. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84878. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84879. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84880. #ifndef FLAC__NO_ASM
  84881. # ifdef FLAC__CPU_IA32
  84882. # ifdef FLAC__HAS_NASM
  84883. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84884. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84885. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84886. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84887. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84888. # endif
  84889. # endif
  84890. #endif
  84891. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84892. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84893. 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[]);
  84894. 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[]);
  84895. #ifndef FLAC__NO_ASM
  84896. # ifdef FLAC__CPU_IA32
  84897. # ifdef FLAC__HAS_NASM
  84898. 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[]);
  84899. 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[]);
  84900. # endif
  84901. # endif
  84902. #endif
  84903. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84904. 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[]);
  84905. 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[]);
  84906. #ifndef FLAC__NO_ASM
  84907. # ifdef FLAC__CPU_IA32
  84908. # ifdef FLAC__HAS_NASM
  84909. 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[]);
  84910. 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[]);
  84911. # endif /* FLAC__HAS_NASM */
  84912. # elif defined FLAC__CPU_PPC
  84913. 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[]);
  84914. 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[]);
  84915. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84916. #endif /* FLAC__NO_ASM */
  84917. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84918. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  84919. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  84920. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  84921. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84922. #endif
  84923. /*** End of inlined file: lpc.h ***/
  84924. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  84925. #include <stdio.h>
  84926. #endif
  84927. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84928. #ifndef M_LN2
  84929. #define M_LN2 0.69314718055994530942
  84930. #endif
  84931. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  84932. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  84933. {
  84934. unsigned i;
  84935. for(i = 0; i < data_len; i++)
  84936. out[i] = in[i] * window[i];
  84937. }
  84938. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  84939. {
  84940. #if 0
  84941. FLAC__real d;
  84942. unsigned i;
  84943. FLAC__ASSERT(lag > 0);
  84944. FLAC__ASSERT(lag <= data_len);
  84945. while(lag--) {
  84946. for(i = lag, d = 0.0; i < data_len; i++)
  84947. d += data[i] * data[i - lag];
  84948. autoc[lag] = d;
  84949. }
  84950. #endif
  84951. FLAC__real d;
  84952. unsigned sample, coeff;
  84953. const unsigned limit = data_len - lag;
  84954. FLAC__ASSERT(lag > 0);
  84955. FLAC__ASSERT(lag <= data_len);
  84956. for(coeff = 0; coeff < lag; coeff++)
  84957. autoc[coeff] = 0.0;
  84958. for(sample = 0; sample <= limit; sample++) {
  84959. d = data[sample];
  84960. for(coeff = 0; coeff < lag; coeff++)
  84961. autoc[coeff] += d * data[sample+coeff];
  84962. }
  84963. for(; sample < data_len; sample++) {
  84964. d = data[sample];
  84965. for(coeff = 0; coeff < data_len - sample; coeff++)
  84966. autoc[coeff] += d * data[sample+coeff];
  84967. }
  84968. }
  84969. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  84970. {
  84971. unsigned i, j;
  84972. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  84973. FLAC__ASSERT(0 != max_order);
  84974. FLAC__ASSERT(0 < *max_order);
  84975. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  84976. FLAC__ASSERT(autoc[0] != 0.0);
  84977. err = autoc[0];
  84978. for(i = 0; i < *max_order; i++) {
  84979. r = -autoc[i+1];
  84980. for(j = 0; j < i; j++)
  84981. r -= lpc[j] * autoc[i-j];
  84982. ref[i] = (r/=err);
  84983. lpc[i]=r;
  84984. for(j = 0; j < (i>>1); j++) {
  84985. FLAC__double tmp = lpc[j];
  84986. lpc[j] += r * lpc[i-1-j];
  84987. lpc[i-1-j] += r * tmp;
  84988. }
  84989. if(i & 1)
  84990. lpc[j] += lpc[j] * r;
  84991. err *= (1.0 - r * r);
  84992. for(j = 0; j <= i; j++)
  84993. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  84994. error[i] = err;
  84995. if(err == 0.0) {
  84996. *max_order = i+1;
  84997. return;
  84998. }
  84999. }
  85000. }
  85001. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85002. {
  85003. unsigned i;
  85004. FLAC__double cmax;
  85005. FLAC__int32 qmax, qmin;
  85006. FLAC__ASSERT(precision > 0);
  85007. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85008. precision--;
  85009. qmax = 1 << precision;
  85010. qmin = -qmax;
  85011. qmax--;
  85012. cmax = 0.0;
  85013. for(i = 0; i < order; i++) {
  85014. const FLAC__double d = fabs(lp_coeff[i]);
  85015. if(d > cmax)
  85016. cmax = d;
  85017. }
  85018. if(cmax <= 0.0) {
  85019. return 2;
  85020. }
  85021. else {
  85022. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85023. const int min_shiftlimit = -max_shiftlimit - 1;
  85024. int log2cmax;
  85025. (void)frexp(cmax, &log2cmax);
  85026. log2cmax--;
  85027. *shift = (int)precision - log2cmax - 1;
  85028. if(*shift > max_shiftlimit)
  85029. *shift = max_shiftlimit;
  85030. else if(*shift < min_shiftlimit)
  85031. return 1;
  85032. }
  85033. if(*shift >= 0) {
  85034. FLAC__double error = 0.0;
  85035. FLAC__int32 q;
  85036. for(i = 0; i < order; i++) {
  85037. error += lp_coeff[i] * (1 << *shift);
  85038. #if 1 /* unfortunately lround() is C99 */
  85039. if(error >= 0.0)
  85040. q = (FLAC__int32)(error + 0.5);
  85041. else
  85042. q = (FLAC__int32)(error - 0.5);
  85043. #else
  85044. q = lround(error);
  85045. #endif
  85046. #ifdef FLAC__OVERFLOW_DETECT
  85047. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85048. 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]);
  85049. else if(q < qmin)
  85050. 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]);
  85051. #endif
  85052. if(q > qmax)
  85053. q = qmax;
  85054. else if(q < qmin)
  85055. q = qmin;
  85056. error -= q;
  85057. qlp_coeff[i] = q;
  85058. }
  85059. }
  85060. else {
  85061. const int nshift = -(*shift);
  85062. FLAC__double error = 0.0;
  85063. FLAC__int32 q;
  85064. #ifdef DEBUG
  85065. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85066. #endif
  85067. for(i = 0; i < order; i++) {
  85068. error += lp_coeff[i] / (1 << nshift);
  85069. #if 1 /* unfortunately lround() is C99 */
  85070. if(error >= 0.0)
  85071. q = (FLAC__int32)(error + 0.5);
  85072. else
  85073. q = (FLAC__int32)(error - 0.5);
  85074. #else
  85075. q = lround(error);
  85076. #endif
  85077. #ifdef FLAC__OVERFLOW_DETECT
  85078. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85079. 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]);
  85080. else if(q < qmin)
  85081. 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]);
  85082. #endif
  85083. if(q > qmax)
  85084. q = qmax;
  85085. else if(q < qmin)
  85086. q = qmin;
  85087. error -= q;
  85088. qlp_coeff[i] = q;
  85089. }
  85090. *shift = 0;
  85091. }
  85092. return 0;
  85093. }
  85094. 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[])
  85095. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85096. {
  85097. FLAC__int64 sumo;
  85098. unsigned i, j;
  85099. FLAC__int32 sum;
  85100. const FLAC__int32 *history;
  85101. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85102. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85103. for(i=0;i<order;i++)
  85104. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85105. fprintf(stderr,"\n");
  85106. #endif
  85107. FLAC__ASSERT(order > 0);
  85108. for(i = 0; i < data_len; i++) {
  85109. sumo = 0;
  85110. sum = 0;
  85111. history = data;
  85112. for(j = 0; j < order; j++) {
  85113. sum += qlp_coeff[j] * (*(--history));
  85114. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85115. #if defined _MSC_VER
  85116. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85117. 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);
  85118. #else
  85119. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85120. 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);
  85121. #endif
  85122. }
  85123. *(residual++) = *(data++) - (sum >> lp_quantization);
  85124. }
  85125. }
  85126. #else /* fully unrolled version for normal use */
  85127. {
  85128. int i;
  85129. FLAC__int32 sum;
  85130. FLAC__ASSERT(order > 0);
  85131. FLAC__ASSERT(order <= 32);
  85132. if(order <= 12) {
  85133. if(order > 8) {
  85134. if(order > 10) {
  85135. if(order == 12) {
  85136. for(i = 0; i < (int)data_len; i++) {
  85137. sum = 0;
  85138. sum += qlp_coeff[11] * data[i-12];
  85139. sum += qlp_coeff[10] * data[i-11];
  85140. sum += qlp_coeff[9] * data[i-10];
  85141. sum += qlp_coeff[8] * data[i-9];
  85142. sum += qlp_coeff[7] * data[i-8];
  85143. sum += qlp_coeff[6] * data[i-7];
  85144. sum += qlp_coeff[5] * data[i-6];
  85145. sum += qlp_coeff[4] * data[i-5];
  85146. sum += qlp_coeff[3] * data[i-4];
  85147. sum += qlp_coeff[2] * data[i-3];
  85148. sum += qlp_coeff[1] * data[i-2];
  85149. sum += qlp_coeff[0] * data[i-1];
  85150. residual[i] = data[i] - (sum >> lp_quantization);
  85151. }
  85152. }
  85153. else { /* order == 11 */
  85154. for(i = 0; i < (int)data_len; i++) {
  85155. sum = 0;
  85156. sum += qlp_coeff[10] * data[i-11];
  85157. sum += qlp_coeff[9] * data[i-10];
  85158. sum += qlp_coeff[8] * data[i-9];
  85159. sum += qlp_coeff[7] * data[i-8];
  85160. sum += qlp_coeff[6] * data[i-7];
  85161. sum += qlp_coeff[5] * data[i-6];
  85162. sum += qlp_coeff[4] * data[i-5];
  85163. sum += qlp_coeff[3] * data[i-4];
  85164. sum += qlp_coeff[2] * data[i-3];
  85165. sum += qlp_coeff[1] * data[i-2];
  85166. sum += qlp_coeff[0] * data[i-1];
  85167. residual[i] = data[i] - (sum >> lp_quantization);
  85168. }
  85169. }
  85170. }
  85171. else {
  85172. if(order == 10) {
  85173. for(i = 0; i < (int)data_len; i++) {
  85174. sum = 0;
  85175. sum += qlp_coeff[9] * data[i-10];
  85176. sum += qlp_coeff[8] * data[i-9];
  85177. sum += qlp_coeff[7] * data[i-8];
  85178. sum += qlp_coeff[6] * data[i-7];
  85179. sum += qlp_coeff[5] * data[i-6];
  85180. sum += qlp_coeff[4] * data[i-5];
  85181. sum += qlp_coeff[3] * data[i-4];
  85182. sum += qlp_coeff[2] * data[i-3];
  85183. sum += qlp_coeff[1] * data[i-2];
  85184. sum += qlp_coeff[0] * data[i-1];
  85185. residual[i] = data[i] - (sum >> lp_quantization);
  85186. }
  85187. }
  85188. else { /* order == 9 */
  85189. for(i = 0; i < (int)data_len; i++) {
  85190. sum = 0;
  85191. sum += qlp_coeff[8] * data[i-9];
  85192. sum += qlp_coeff[7] * data[i-8];
  85193. sum += qlp_coeff[6] * data[i-7];
  85194. sum += qlp_coeff[5] * data[i-6];
  85195. sum += qlp_coeff[4] * data[i-5];
  85196. sum += qlp_coeff[3] * data[i-4];
  85197. sum += qlp_coeff[2] * data[i-3];
  85198. sum += qlp_coeff[1] * data[i-2];
  85199. sum += qlp_coeff[0] * data[i-1];
  85200. residual[i] = data[i] - (sum >> lp_quantization);
  85201. }
  85202. }
  85203. }
  85204. }
  85205. else if(order > 4) {
  85206. if(order > 6) {
  85207. if(order == 8) {
  85208. for(i = 0; i < (int)data_len; i++) {
  85209. sum = 0;
  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 == 7 */
  85222. for(i = 0; i < (int)data_len; i++) {
  85223. sum = 0;
  85224. sum += qlp_coeff[6] * data[i-7];
  85225. sum += qlp_coeff[5] * data[i-6];
  85226. sum += qlp_coeff[4] * data[i-5];
  85227. sum += qlp_coeff[3] * data[i-4];
  85228. sum += qlp_coeff[2] * data[i-3];
  85229. sum += qlp_coeff[1] * data[i-2];
  85230. sum += qlp_coeff[0] * data[i-1];
  85231. residual[i] = data[i] - (sum >> lp_quantization);
  85232. }
  85233. }
  85234. }
  85235. else {
  85236. if(order == 6) {
  85237. for(i = 0; i < (int)data_len; i++) {
  85238. sum = 0;
  85239. sum += qlp_coeff[5] * data[i-6];
  85240. sum += qlp_coeff[4] * data[i-5];
  85241. sum += qlp_coeff[3] * data[i-4];
  85242. sum += qlp_coeff[2] * data[i-3];
  85243. sum += qlp_coeff[1] * data[i-2];
  85244. sum += qlp_coeff[0] * data[i-1];
  85245. residual[i] = data[i] - (sum >> lp_quantization);
  85246. }
  85247. }
  85248. else { /* order == 5 */
  85249. for(i = 0; i < (int)data_len; i++) {
  85250. sum = 0;
  85251. sum += qlp_coeff[4] * data[i-5];
  85252. sum += qlp_coeff[3] * data[i-4];
  85253. sum += qlp_coeff[2] * data[i-3];
  85254. sum += qlp_coeff[1] * data[i-2];
  85255. sum += qlp_coeff[0] * data[i-1];
  85256. residual[i] = data[i] - (sum >> lp_quantization);
  85257. }
  85258. }
  85259. }
  85260. }
  85261. else {
  85262. if(order > 2) {
  85263. if(order == 4) {
  85264. for(i = 0; i < (int)data_len; i++) {
  85265. sum = 0;
  85266. sum += qlp_coeff[3] * data[i-4];
  85267. sum += qlp_coeff[2] * data[i-3];
  85268. sum += qlp_coeff[1] * data[i-2];
  85269. sum += qlp_coeff[0] * data[i-1];
  85270. residual[i] = data[i] - (sum >> lp_quantization);
  85271. }
  85272. }
  85273. else { /* order == 3 */
  85274. for(i = 0; i < (int)data_len; i++) {
  85275. sum = 0;
  85276. sum += qlp_coeff[2] * data[i-3];
  85277. sum += qlp_coeff[1] * data[i-2];
  85278. sum += qlp_coeff[0] * data[i-1];
  85279. residual[i] = data[i] - (sum >> lp_quantization);
  85280. }
  85281. }
  85282. }
  85283. else {
  85284. if(order == 2) {
  85285. for(i = 0; i < (int)data_len; i++) {
  85286. sum = 0;
  85287. sum += qlp_coeff[1] * data[i-2];
  85288. sum += qlp_coeff[0] * data[i-1];
  85289. residual[i] = data[i] - (sum >> lp_quantization);
  85290. }
  85291. }
  85292. else { /* order == 1 */
  85293. for(i = 0; i < (int)data_len; i++)
  85294. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85295. }
  85296. }
  85297. }
  85298. }
  85299. else { /* order > 12 */
  85300. for(i = 0; i < (int)data_len; i++) {
  85301. sum = 0;
  85302. switch(order) {
  85303. case 32: sum += qlp_coeff[31] * data[i-32];
  85304. case 31: sum += qlp_coeff[30] * data[i-31];
  85305. case 30: sum += qlp_coeff[29] * data[i-30];
  85306. case 29: sum += qlp_coeff[28] * data[i-29];
  85307. case 28: sum += qlp_coeff[27] * data[i-28];
  85308. case 27: sum += qlp_coeff[26] * data[i-27];
  85309. case 26: sum += qlp_coeff[25] * data[i-26];
  85310. case 25: sum += qlp_coeff[24] * data[i-25];
  85311. case 24: sum += qlp_coeff[23] * data[i-24];
  85312. case 23: sum += qlp_coeff[22] * data[i-23];
  85313. case 22: sum += qlp_coeff[21] * data[i-22];
  85314. case 21: sum += qlp_coeff[20] * data[i-21];
  85315. case 20: sum += qlp_coeff[19] * data[i-20];
  85316. case 19: sum += qlp_coeff[18] * data[i-19];
  85317. case 18: sum += qlp_coeff[17] * data[i-18];
  85318. case 17: sum += qlp_coeff[16] * data[i-17];
  85319. case 16: sum += qlp_coeff[15] * data[i-16];
  85320. case 15: sum += qlp_coeff[14] * data[i-15];
  85321. case 14: sum += qlp_coeff[13] * data[i-14];
  85322. case 13: sum += qlp_coeff[12] * data[i-13];
  85323. sum += qlp_coeff[11] * data[i-12];
  85324. sum += qlp_coeff[10] * data[i-11];
  85325. sum += qlp_coeff[ 9] * data[i-10];
  85326. sum += qlp_coeff[ 8] * data[i- 9];
  85327. sum += qlp_coeff[ 7] * data[i- 8];
  85328. sum += qlp_coeff[ 6] * data[i- 7];
  85329. sum += qlp_coeff[ 5] * data[i- 6];
  85330. sum += qlp_coeff[ 4] * data[i- 5];
  85331. sum += qlp_coeff[ 3] * data[i- 4];
  85332. sum += qlp_coeff[ 2] * data[i- 3];
  85333. sum += qlp_coeff[ 1] * data[i- 2];
  85334. sum += qlp_coeff[ 0] * data[i- 1];
  85335. }
  85336. residual[i] = data[i] - (sum >> lp_quantization);
  85337. }
  85338. }
  85339. }
  85340. #endif
  85341. 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[])
  85342. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85343. {
  85344. unsigned i, j;
  85345. FLAC__int64 sum;
  85346. const FLAC__int32 *history;
  85347. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85348. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85349. for(i=0;i<order;i++)
  85350. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85351. fprintf(stderr,"\n");
  85352. #endif
  85353. FLAC__ASSERT(order > 0);
  85354. for(i = 0; i < data_len; i++) {
  85355. sum = 0;
  85356. history = data;
  85357. for(j = 0; j < order; j++)
  85358. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85359. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85360. #if defined _MSC_VER
  85361. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85362. #else
  85363. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85364. #endif
  85365. break;
  85366. }
  85367. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85368. #if defined _MSC_VER
  85369. 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));
  85370. #else
  85371. 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)));
  85372. #endif
  85373. break;
  85374. }
  85375. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85376. }
  85377. }
  85378. #else /* fully unrolled version for normal use */
  85379. {
  85380. int i;
  85381. FLAC__int64 sum;
  85382. FLAC__ASSERT(order > 0);
  85383. FLAC__ASSERT(order <= 32);
  85384. if(order <= 12) {
  85385. if(order > 8) {
  85386. if(order > 10) {
  85387. if(order == 12) {
  85388. for(i = 0; i < (int)data_len; i++) {
  85389. sum = 0;
  85390. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85391. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85392. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85393. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85394. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85395. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85396. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85397. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85398. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85399. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85400. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85401. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85402. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85403. }
  85404. }
  85405. else { /* order == 11 */
  85406. for(i = 0; i < (int)data_len; i++) {
  85407. sum = 0;
  85408. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85409. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85410. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85411. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85412. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85413. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85414. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85415. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85416. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85417. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85418. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85419. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85420. }
  85421. }
  85422. }
  85423. else {
  85424. if(order == 10) {
  85425. for(i = 0; i < (int)data_len; i++) {
  85426. sum = 0;
  85427. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85428. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85429. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85430. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85431. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85432. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85433. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85434. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85435. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85436. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85437. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85438. }
  85439. }
  85440. else { /* order == 9 */
  85441. for(i = 0; i < (int)data_len; i++) {
  85442. sum = 0;
  85443. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85444. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85445. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85446. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85447. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85448. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85449. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85450. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85451. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85452. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85453. }
  85454. }
  85455. }
  85456. }
  85457. else if(order > 4) {
  85458. if(order > 6) {
  85459. if(order == 8) {
  85460. for(i = 0; i < (int)data_len; i++) {
  85461. sum = 0;
  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 == 7 */
  85474. for(i = 0; i < (int)data_len; i++) {
  85475. sum = 0;
  85476. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85477. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85478. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85479. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85480. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85481. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85482. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85483. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85484. }
  85485. }
  85486. }
  85487. else {
  85488. if(order == 6) {
  85489. for(i = 0; i < (int)data_len; i++) {
  85490. sum = 0;
  85491. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85492. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85493. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85494. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85495. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85496. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85497. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85498. }
  85499. }
  85500. else { /* order == 5 */
  85501. for(i = 0; i < (int)data_len; i++) {
  85502. sum = 0;
  85503. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85504. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85505. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85506. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85507. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85508. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85509. }
  85510. }
  85511. }
  85512. }
  85513. else {
  85514. if(order > 2) {
  85515. if(order == 4) {
  85516. for(i = 0; i < (int)data_len; i++) {
  85517. sum = 0;
  85518. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85519. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85520. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85521. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85522. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85523. }
  85524. }
  85525. else { /* order == 3 */
  85526. for(i = 0; i < (int)data_len; i++) {
  85527. sum = 0;
  85528. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85529. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85530. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85531. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85532. }
  85533. }
  85534. }
  85535. else {
  85536. if(order == 2) {
  85537. for(i = 0; i < (int)data_len; i++) {
  85538. sum = 0;
  85539. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85540. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85541. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85542. }
  85543. }
  85544. else { /* order == 1 */
  85545. for(i = 0; i < (int)data_len; i++)
  85546. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85547. }
  85548. }
  85549. }
  85550. }
  85551. else { /* order > 12 */
  85552. for(i = 0; i < (int)data_len; i++) {
  85553. sum = 0;
  85554. switch(order) {
  85555. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85556. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85557. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85558. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85559. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85560. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85561. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85562. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85563. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85564. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85565. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85566. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85567. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85568. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85569. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85570. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85571. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85572. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85573. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85574. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85575. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85576. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85577. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85578. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85579. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85580. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85581. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85582. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85583. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85584. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85585. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85586. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85587. }
  85588. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85589. }
  85590. }
  85591. }
  85592. #endif
  85593. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85594. 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[])
  85595. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85596. {
  85597. FLAC__int64 sumo;
  85598. unsigned i, j;
  85599. FLAC__int32 sum;
  85600. const FLAC__int32 *r = residual, *history;
  85601. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85602. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85603. for(i=0;i<order;i++)
  85604. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85605. fprintf(stderr,"\n");
  85606. #endif
  85607. FLAC__ASSERT(order > 0);
  85608. for(i = 0; i < data_len; i++) {
  85609. sumo = 0;
  85610. sum = 0;
  85611. history = data;
  85612. for(j = 0; j < order; j++) {
  85613. sum += qlp_coeff[j] * (*(--history));
  85614. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85615. #if defined _MSC_VER
  85616. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85617. 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);
  85618. #else
  85619. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85620. 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);
  85621. #endif
  85622. }
  85623. *(data++) = *(r++) + (sum >> lp_quantization);
  85624. }
  85625. }
  85626. #else /* fully unrolled version for normal use */
  85627. {
  85628. int i;
  85629. FLAC__int32 sum;
  85630. FLAC__ASSERT(order > 0);
  85631. FLAC__ASSERT(order <= 32);
  85632. if(order <= 12) {
  85633. if(order > 8) {
  85634. if(order > 10) {
  85635. if(order == 12) {
  85636. for(i = 0; i < (int)data_len; i++) {
  85637. sum = 0;
  85638. sum += qlp_coeff[11] * data[i-12];
  85639. sum += qlp_coeff[10] * data[i-11];
  85640. sum += qlp_coeff[9] * data[i-10];
  85641. sum += qlp_coeff[8] * data[i-9];
  85642. sum += qlp_coeff[7] * data[i-8];
  85643. sum += qlp_coeff[6] * data[i-7];
  85644. sum += qlp_coeff[5] * data[i-6];
  85645. sum += qlp_coeff[4] * data[i-5];
  85646. sum += qlp_coeff[3] * data[i-4];
  85647. sum += qlp_coeff[2] * data[i-3];
  85648. sum += qlp_coeff[1] * data[i-2];
  85649. sum += qlp_coeff[0] * data[i-1];
  85650. data[i] = residual[i] + (sum >> lp_quantization);
  85651. }
  85652. }
  85653. else { /* order == 11 */
  85654. for(i = 0; i < (int)data_len; i++) {
  85655. sum = 0;
  85656. sum += qlp_coeff[10] * data[i-11];
  85657. sum += qlp_coeff[9] * data[i-10];
  85658. sum += qlp_coeff[8] * data[i-9];
  85659. sum += qlp_coeff[7] * data[i-8];
  85660. sum += qlp_coeff[6] * data[i-7];
  85661. sum += qlp_coeff[5] * data[i-6];
  85662. sum += qlp_coeff[4] * data[i-5];
  85663. sum += qlp_coeff[3] * data[i-4];
  85664. sum += qlp_coeff[2] * data[i-3];
  85665. sum += qlp_coeff[1] * data[i-2];
  85666. sum += qlp_coeff[0] * data[i-1];
  85667. data[i] = residual[i] + (sum >> lp_quantization);
  85668. }
  85669. }
  85670. }
  85671. else {
  85672. if(order == 10) {
  85673. for(i = 0; i < (int)data_len; i++) {
  85674. sum = 0;
  85675. sum += qlp_coeff[9] * data[i-10];
  85676. sum += qlp_coeff[8] * data[i-9];
  85677. sum += qlp_coeff[7] * data[i-8];
  85678. sum += qlp_coeff[6] * data[i-7];
  85679. sum += qlp_coeff[5] * data[i-6];
  85680. sum += qlp_coeff[4] * data[i-5];
  85681. sum += qlp_coeff[3] * data[i-4];
  85682. sum += qlp_coeff[2] * data[i-3];
  85683. sum += qlp_coeff[1] * data[i-2];
  85684. sum += qlp_coeff[0] * data[i-1];
  85685. data[i] = residual[i] + (sum >> lp_quantization);
  85686. }
  85687. }
  85688. else { /* order == 9 */
  85689. for(i = 0; i < (int)data_len; i++) {
  85690. sum = 0;
  85691. sum += qlp_coeff[8] * data[i-9];
  85692. sum += qlp_coeff[7] * data[i-8];
  85693. sum += qlp_coeff[6] * data[i-7];
  85694. sum += qlp_coeff[5] * data[i-6];
  85695. sum += qlp_coeff[4] * data[i-5];
  85696. sum += qlp_coeff[3] * data[i-4];
  85697. sum += qlp_coeff[2] * data[i-3];
  85698. sum += qlp_coeff[1] * data[i-2];
  85699. sum += qlp_coeff[0] * data[i-1];
  85700. data[i] = residual[i] + (sum >> lp_quantization);
  85701. }
  85702. }
  85703. }
  85704. }
  85705. else if(order > 4) {
  85706. if(order > 6) {
  85707. if(order == 8) {
  85708. for(i = 0; i < (int)data_len; i++) {
  85709. sum = 0;
  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 == 7 */
  85722. for(i = 0; i < (int)data_len; i++) {
  85723. sum = 0;
  85724. sum += qlp_coeff[6] * data[i-7];
  85725. sum += qlp_coeff[5] * data[i-6];
  85726. sum += qlp_coeff[4] * data[i-5];
  85727. sum += qlp_coeff[3] * data[i-4];
  85728. sum += qlp_coeff[2] * data[i-3];
  85729. sum += qlp_coeff[1] * data[i-2];
  85730. sum += qlp_coeff[0] * data[i-1];
  85731. data[i] = residual[i] + (sum >> lp_quantization);
  85732. }
  85733. }
  85734. }
  85735. else {
  85736. if(order == 6) {
  85737. for(i = 0; i < (int)data_len; i++) {
  85738. sum = 0;
  85739. sum += qlp_coeff[5] * data[i-6];
  85740. sum += qlp_coeff[4] * data[i-5];
  85741. sum += qlp_coeff[3] * data[i-4];
  85742. sum += qlp_coeff[2] * data[i-3];
  85743. sum += qlp_coeff[1] * data[i-2];
  85744. sum += qlp_coeff[0] * data[i-1];
  85745. data[i] = residual[i] + (sum >> lp_quantization);
  85746. }
  85747. }
  85748. else { /* order == 5 */
  85749. for(i = 0; i < (int)data_len; i++) {
  85750. sum = 0;
  85751. sum += qlp_coeff[4] * data[i-5];
  85752. sum += qlp_coeff[3] * data[i-4];
  85753. sum += qlp_coeff[2] * data[i-3];
  85754. sum += qlp_coeff[1] * data[i-2];
  85755. sum += qlp_coeff[0] * data[i-1];
  85756. data[i] = residual[i] + (sum >> lp_quantization);
  85757. }
  85758. }
  85759. }
  85760. }
  85761. else {
  85762. if(order > 2) {
  85763. if(order == 4) {
  85764. for(i = 0; i < (int)data_len; i++) {
  85765. sum = 0;
  85766. sum += qlp_coeff[3] * data[i-4];
  85767. sum += qlp_coeff[2] * data[i-3];
  85768. sum += qlp_coeff[1] * data[i-2];
  85769. sum += qlp_coeff[0] * data[i-1];
  85770. data[i] = residual[i] + (sum >> lp_quantization);
  85771. }
  85772. }
  85773. else { /* order == 3 */
  85774. for(i = 0; i < (int)data_len; i++) {
  85775. sum = 0;
  85776. sum += qlp_coeff[2] * data[i-3];
  85777. sum += qlp_coeff[1] * data[i-2];
  85778. sum += qlp_coeff[0] * data[i-1];
  85779. data[i] = residual[i] + (sum >> lp_quantization);
  85780. }
  85781. }
  85782. }
  85783. else {
  85784. if(order == 2) {
  85785. for(i = 0; i < (int)data_len; i++) {
  85786. sum = 0;
  85787. sum += qlp_coeff[1] * data[i-2];
  85788. sum += qlp_coeff[0] * data[i-1];
  85789. data[i] = residual[i] + (sum >> lp_quantization);
  85790. }
  85791. }
  85792. else { /* order == 1 */
  85793. for(i = 0; i < (int)data_len; i++)
  85794. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85795. }
  85796. }
  85797. }
  85798. }
  85799. else { /* order > 12 */
  85800. for(i = 0; i < (int)data_len; i++) {
  85801. sum = 0;
  85802. switch(order) {
  85803. case 32: sum += qlp_coeff[31] * data[i-32];
  85804. case 31: sum += qlp_coeff[30] * data[i-31];
  85805. case 30: sum += qlp_coeff[29] * data[i-30];
  85806. case 29: sum += qlp_coeff[28] * data[i-29];
  85807. case 28: sum += qlp_coeff[27] * data[i-28];
  85808. case 27: sum += qlp_coeff[26] * data[i-27];
  85809. case 26: sum += qlp_coeff[25] * data[i-26];
  85810. case 25: sum += qlp_coeff[24] * data[i-25];
  85811. case 24: sum += qlp_coeff[23] * data[i-24];
  85812. case 23: sum += qlp_coeff[22] * data[i-23];
  85813. case 22: sum += qlp_coeff[21] * data[i-22];
  85814. case 21: sum += qlp_coeff[20] * data[i-21];
  85815. case 20: sum += qlp_coeff[19] * data[i-20];
  85816. case 19: sum += qlp_coeff[18] * data[i-19];
  85817. case 18: sum += qlp_coeff[17] * data[i-18];
  85818. case 17: sum += qlp_coeff[16] * data[i-17];
  85819. case 16: sum += qlp_coeff[15] * data[i-16];
  85820. case 15: sum += qlp_coeff[14] * data[i-15];
  85821. case 14: sum += qlp_coeff[13] * data[i-14];
  85822. case 13: sum += qlp_coeff[12] * data[i-13];
  85823. sum += qlp_coeff[11] * data[i-12];
  85824. sum += qlp_coeff[10] * data[i-11];
  85825. sum += qlp_coeff[ 9] * data[i-10];
  85826. sum += qlp_coeff[ 8] * data[i- 9];
  85827. sum += qlp_coeff[ 7] * data[i- 8];
  85828. sum += qlp_coeff[ 6] * data[i- 7];
  85829. sum += qlp_coeff[ 5] * data[i- 6];
  85830. sum += qlp_coeff[ 4] * data[i- 5];
  85831. sum += qlp_coeff[ 3] * data[i- 4];
  85832. sum += qlp_coeff[ 2] * data[i- 3];
  85833. sum += qlp_coeff[ 1] * data[i- 2];
  85834. sum += qlp_coeff[ 0] * data[i- 1];
  85835. }
  85836. data[i] = residual[i] + (sum >> lp_quantization);
  85837. }
  85838. }
  85839. }
  85840. #endif
  85841. 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[])
  85842. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85843. {
  85844. unsigned i, j;
  85845. FLAC__int64 sum;
  85846. const FLAC__int32 *r = residual, *history;
  85847. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85848. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85849. for(i=0;i<order;i++)
  85850. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85851. fprintf(stderr,"\n");
  85852. #endif
  85853. FLAC__ASSERT(order > 0);
  85854. for(i = 0; i < data_len; i++) {
  85855. sum = 0;
  85856. history = data;
  85857. for(j = 0; j < order; j++)
  85858. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85859. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85860. #ifdef _MSC_VER
  85861. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85862. #else
  85863. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85864. #endif
  85865. break;
  85866. }
  85867. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85868. #ifdef _MSC_VER
  85869. 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));
  85870. #else
  85871. 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)));
  85872. #endif
  85873. break;
  85874. }
  85875. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85876. }
  85877. }
  85878. #else /* fully unrolled version for normal use */
  85879. {
  85880. int i;
  85881. FLAC__int64 sum;
  85882. FLAC__ASSERT(order > 0);
  85883. FLAC__ASSERT(order <= 32);
  85884. if(order <= 12) {
  85885. if(order > 8) {
  85886. if(order > 10) {
  85887. if(order == 12) {
  85888. for(i = 0; i < (int)data_len; i++) {
  85889. sum = 0;
  85890. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85891. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85892. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85893. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85894. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85895. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85896. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85897. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85898. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85899. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85900. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85901. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85902. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85903. }
  85904. }
  85905. else { /* order == 11 */
  85906. for(i = 0; i < (int)data_len; i++) {
  85907. sum = 0;
  85908. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85909. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85910. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85911. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85912. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85913. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85914. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85915. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85916. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85917. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85918. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85919. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85920. }
  85921. }
  85922. }
  85923. else {
  85924. if(order == 10) {
  85925. for(i = 0; i < (int)data_len; i++) {
  85926. sum = 0;
  85927. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85928. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85929. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85930. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85931. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85932. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85933. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85934. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85935. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85936. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85937. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85938. }
  85939. }
  85940. else { /* order == 9 */
  85941. for(i = 0; i < (int)data_len; i++) {
  85942. sum = 0;
  85943. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85944. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85945. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85946. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85947. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85948. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85949. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85950. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85951. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85952. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85953. }
  85954. }
  85955. }
  85956. }
  85957. else if(order > 4) {
  85958. if(order > 6) {
  85959. if(order == 8) {
  85960. for(i = 0; i < (int)data_len; i++) {
  85961. sum = 0;
  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 == 7 */
  85974. for(i = 0; i < (int)data_len; i++) {
  85975. sum = 0;
  85976. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85977. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85978. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85979. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85980. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85981. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85982. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85983. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85984. }
  85985. }
  85986. }
  85987. else {
  85988. if(order == 6) {
  85989. for(i = 0; i < (int)data_len; i++) {
  85990. sum = 0;
  85991. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85992. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85993. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85994. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85995. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85996. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85997. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85998. }
  85999. }
  86000. else { /* order == 5 */
  86001. for(i = 0; i < (int)data_len; i++) {
  86002. sum = 0;
  86003. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86004. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86005. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86006. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86007. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86008. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86009. }
  86010. }
  86011. }
  86012. }
  86013. else {
  86014. if(order > 2) {
  86015. if(order == 4) {
  86016. for(i = 0; i < (int)data_len; i++) {
  86017. sum = 0;
  86018. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86019. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86020. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86021. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86022. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86023. }
  86024. }
  86025. else { /* order == 3 */
  86026. for(i = 0; i < (int)data_len; i++) {
  86027. sum = 0;
  86028. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86029. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86030. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86031. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86032. }
  86033. }
  86034. }
  86035. else {
  86036. if(order == 2) {
  86037. for(i = 0; i < (int)data_len; i++) {
  86038. sum = 0;
  86039. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86040. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86041. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86042. }
  86043. }
  86044. else { /* order == 1 */
  86045. for(i = 0; i < (int)data_len; i++)
  86046. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86047. }
  86048. }
  86049. }
  86050. }
  86051. else { /* order > 12 */
  86052. for(i = 0; i < (int)data_len; i++) {
  86053. sum = 0;
  86054. switch(order) {
  86055. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86056. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86057. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86058. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86059. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86060. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86061. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86062. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86063. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86064. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86065. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86066. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86067. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86068. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86069. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86070. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86071. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86072. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86073. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86074. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86075. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86076. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86077. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86078. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86079. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86080. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86081. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86082. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86083. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86084. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86085. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86086. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86087. }
  86088. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86089. }
  86090. }
  86091. }
  86092. #endif
  86093. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86094. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86095. {
  86096. FLAC__double error_scale;
  86097. FLAC__ASSERT(total_samples > 0);
  86098. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86099. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86100. }
  86101. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86102. {
  86103. if(lpc_error > 0.0) {
  86104. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86105. if(bps >= 0.0)
  86106. return bps;
  86107. else
  86108. return 0.0;
  86109. }
  86110. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86111. return 1e32;
  86112. }
  86113. else {
  86114. return 0.0;
  86115. }
  86116. }
  86117. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86118. {
  86119. 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 */
  86120. FLAC__double bits, best_bits, error_scale;
  86121. FLAC__ASSERT(max_order > 0);
  86122. FLAC__ASSERT(total_samples > 0);
  86123. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86124. best_index = 0;
  86125. best_bits = (unsigned)(-1);
  86126. for(index = 0, order = 1; index < max_order; index++, order++) {
  86127. 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);
  86128. if(bits < best_bits) {
  86129. best_index = index;
  86130. best_bits = bits;
  86131. }
  86132. }
  86133. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86134. }
  86135. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86136. #endif
  86137. /*** End of inlined file: lpc_flac.c ***/
  86138. /*** Start of inlined file: md5.c ***/
  86139. /*** Start of inlined file: juce_FlacHeader.h ***/
  86140. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86141. // tasks..
  86142. #define VERSION "1.2.1"
  86143. #define FLAC__NO_DLL 1
  86144. #if JUCE_MSVC
  86145. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86146. #endif
  86147. #if JUCE_MAC
  86148. #define FLAC__SYS_DARWIN 1
  86149. #endif
  86150. /*** End of inlined file: juce_FlacHeader.h ***/
  86151. #if JUCE_USE_FLAC
  86152. #if HAVE_CONFIG_H
  86153. # include <config.h>
  86154. #endif
  86155. #include <stdlib.h> /* for malloc() */
  86156. #include <string.h> /* for memcpy() */
  86157. /*** Start of inlined file: md5.h ***/
  86158. #ifndef FLAC__PRIVATE__MD5_H
  86159. #define FLAC__PRIVATE__MD5_H
  86160. typedef struct {
  86161. FLAC__uint32 in[16];
  86162. FLAC__uint32 buf[4];
  86163. FLAC__uint32 bytes[2];
  86164. FLAC__byte *internal_buf;
  86165. size_t capacity;
  86166. } FLAC__MD5Context;
  86167. void FLAC__MD5Init(FLAC__MD5Context *context);
  86168. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86169. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86170. #endif
  86171. /*** End of inlined file: md5.h ***/
  86172. #ifndef FLaC__INLINE
  86173. #define FLaC__INLINE
  86174. #endif
  86175. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86176. #define F2(x, y, z) F1(z, x, y)
  86177. #define F3(x, y, z) (x ^ y ^ z)
  86178. #define F4(x, y, z) (y ^ (x | ~z))
  86179. #define MD5STEP(f,w,x,y,z,in,s) \
  86180. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86181. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86182. {
  86183. register FLAC__uint32 a, b, c, d;
  86184. a = buf[0];
  86185. b = buf[1];
  86186. c = buf[2];
  86187. d = buf[3];
  86188. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86189. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86190. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86191. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86192. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86193. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86194. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86195. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86196. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86197. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86198. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86199. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86200. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86201. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86202. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86203. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86204. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86205. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86206. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86207. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86208. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86209. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86210. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86211. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86212. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86213. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86214. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86215. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86216. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86217. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86218. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86219. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86220. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86221. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86222. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86223. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86224. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86225. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86226. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86227. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86228. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86229. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86230. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86231. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86232. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86233. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86234. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86235. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86236. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86237. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86238. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86239. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86240. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86241. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86242. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86243. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86244. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86245. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86246. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86247. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86248. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86249. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86250. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86251. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86252. buf[0] += a;
  86253. buf[1] += b;
  86254. buf[2] += c;
  86255. buf[3] += d;
  86256. }
  86257. #if WORDS_BIGENDIAN
  86258. //@@@@@@ OPT: use bswap/intrinsics
  86259. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86260. {
  86261. register FLAC__uint32 x;
  86262. do {
  86263. x = *buf;
  86264. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86265. *buf++ = (x >> 16) | (x << 16);
  86266. } while (--words);
  86267. }
  86268. static void byteSwapX16(FLAC__uint32 *buf)
  86269. {
  86270. register FLAC__uint32 x;
  86271. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86272. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86273. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86274. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86275. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86276. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86277. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86278. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86279. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86280. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86281. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86282. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86283. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86284. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86285. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86286. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86287. }
  86288. #else
  86289. #define byteSwap(buf, words)
  86290. #define byteSwapX16(buf)
  86291. #endif
  86292. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86293. {
  86294. FLAC__uint32 t;
  86295. t = ctx->bytes[0];
  86296. if ((ctx->bytes[0] = t + len) < t)
  86297. ctx->bytes[1]++; /* Carry from low to high */
  86298. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86299. if (t > len) {
  86300. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86301. return;
  86302. }
  86303. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86304. byteSwapX16(ctx->in);
  86305. FLAC__MD5Transform(ctx->buf, ctx->in);
  86306. buf += t;
  86307. len -= t;
  86308. while (len >= 64) {
  86309. memcpy(ctx->in, buf, 64);
  86310. byteSwapX16(ctx->in);
  86311. FLAC__MD5Transform(ctx->buf, ctx->in);
  86312. buf += 64;
  86313. len -= 64;
  86314. }
  86315. memcpy(ctx->in, buf, len);
  86316. }
  86317. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86318. {
  86319. ctx->buf[0] = 0x67452301;
  86320. ctx->buf[1] = 0xefcdab89;
  86321. ctx->buf[2] = 0x98badcfe;
  86322. ctx->buf[3] = 0x10325476;
  86323. ctx->bytes[0] = 0;
  86324. ctx->bytes[1] = 0;
  86325. ctx->internal_buf = 0;
  86326. ctx->capacity = 0;
  86327. }
  86328. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86329. {
  86330. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86331. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86332. *p++ = 0x80;
  86333. count = 56 - 1 - count;
  86334. if (count < 0) { /* Padding forces an extra block */
  86335. memset(p, 0, count + 8);
  86336. byteSwapX16(ctx->in);
  86337. FLAC__MD5Transform(ctx->buf, ctx->in);
  86338. p = (FLAC__byte *)ctx->in;
  86339. count = 56;
  86340. }
  86341. memset(p, 0, count);
  86342. byteSwap(ctx->in, 14);
  86343. ctx->in[14] = ctx->bytes[0] << 3;
  86344. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86345. FLAC__MD5Transform(ctx->buf, ctx->in);
  86346. byteSwap(ctx->buf, 4);
  86347. memcpy(digest, ctx->buf, 16);
  86348. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86349. if(0 != ctx->internal_buf) {
  86350. free(ctx->internal_buf);
  86351. ctx->internal_buf = 0;
  86352. ctx->capacity = 0;
  86353. }
  86354. }
  86355. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86356. {
  86357. unsigned channel, sample;
  86358. register FLAC__int32 a_word;
  86359. register FLAC__byte *buf_ = buf;
  86360. #if WORDS_BIGENDIAN
  86361. #else
  86362. if(channels == 2 && bytes_per_sample == 2) {
  86363. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86364. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86365. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86366. *buf1_ = (FLAC__int16)signal[1][sample];
  86367. }
  86368. else if(channels == 1 && bytes_per_sample == 2) {
  86369. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86370. for(sample = 0; sample < samples; sample++)
  86371. *buf1_++ = (FLAC__int16)signal[0][sample];
  86372. }
  86373. else
  86374. #endif
  86375. if(bytes_per_sample == 2) {
  86376. if(channels == 2) {
  86377. for(sample = 0; sample < samples; sample++) {
  86378. a_word = signal[0][sample];
  86379. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86380. *buf_++ = (FLAC__byte)a_word;
  86381. a_word = signal[1][sample];
  86382. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86383. *buf_++ = (FLAC__byte)a_word;
  86384. }
  86385. }
  86386. else if(channels == 1) {
  86387. for(sample = 0; sample < samples; sample++) {
  86388. a_word = signal[0][sample];
  86389. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86390. *buf_++ = (FLAC__byte)a_word;
  86391. }
  86392. }
  86393. else {
  86394. for(sample = 0; sample < samples; sample++) {
  86395. for(channel = 0; channel < channels; channel++) {
  86396. a_word = signal[channel][sample];
  86397. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86398. *buf_++ = (FLAC__byte)a_word;
  86399. }
  86400. }
  86401. }
  86402. }
  86403. else if(bytes_per_sample == 3) {
  86404. if(channels == 2) {
  86405. for(sample = 0; sample < samples; sample++) {
  86406. a_word = signal[0][sample];
  86407. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86408. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86409. *buf_++ = (FLAC__byte)a_word;
  86410. a_word = signal[1][sample];
  86411. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86412. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86413. *buf_++ = (FLAC__byte)a_word;
  86414. }
  86415. }
  86416. else if(channels == 1) {
  86417. for(sample = 0; sample < samples; sample++) {
  86418. a_word = signal[0][sample];
  86419. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86420. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86421. *buf_++ = (FLAC__byte)a_word;
  86422. }
  86423. }
  86424. else {
  86425. for(sample = 0; sample < samples; sample++) {
  86426. for(channel = 0; channel < channels; channel++) {
  86427. a_word = signal[channel][sample];
  86428. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86429. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86430. *buf_++ = (FLAC__byte)a_word;
  86431. }
  86432. }
  86433. }
  86434. }
  86435. else if(bytes_per_sample == 1) {
  86436. if(channels == 2) {
  86437. for(sample = 0; sample < samples; sample++) {
  86438. a_word = signal[0][sample];
  86439. *buf_++ = (FLAC__byte)a_word;
  86440. a_word = signal[1][sample];
  86441. *buf_++ = (FLAC__byte)a_word;
  86442. }
  86443. }
  86444. else if(channels == 1) {
  86445. for(sample = 0; sample < samples; sample++) {
  86446. a_word = signal[0][sample];
  86447. *buf_++ = (FLAC__byte)a_word;
  86448. }
  86449. }
  86450. else {
  86451. for(sample = 0; sample < samples; sample++) {
  86452. for(channel = 0; channel < channels; channel++) {
  86453. a_word = signal[channel][sample];
  86454. *buf_++ = (FLAC__byte)a_word;
  86455. }
  86456. }
  86457. }
  86458. }
  86459. else { /* bytes_per_sample == 4, maybe optimize more later */
  86460. for(sample = 0; sample < samples; sample++) {
  86461. for(channel = 0; channel < channels; channel++) {
  86462. a_word = signal[channel][sample];
  86463. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86464. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86465. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86466. *buf_++ = (FLAC__byte)a_word;
  86467. }
  86468. }
  86469. }
  86470. }
  86471. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86472. {
  86473. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86474. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86475. return false;
  86476. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86477. return false;
  86478. if(ctx->capacity < bytes_needed) {
  86479. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86480. if(0 == tmp) {
  86481. free(ctx->internal_buf);
  86482. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86483. return false;
  86484. }
  86485. ctx->internal_buf = tmp;
  86486. ctx->capacity = bytes_needed;
  86487. }
  86488. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86489. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86490. return true;
  86491. }
  86492. #endif
  86493. /*** End of inlined file: md5.c ***/
  86494. /*** Start of inlined file: memory.c ***/
  86495. /*** Start of inlined file: juce_FlacHeader.h ***/
  86496. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86497. // tasks..
  86498. #define VERSION "1.2.1"
  86499. #define FLAC__NO_DLL 1
  86500. #if JUCE_MSVC
  86501. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86502. #endif
  86503. #if JUCE_MAC
  86504. #define FLAC__SYS_DARWIN 1
  86505. #endif
  86506. /*** End of inlined file: juce_FlacHeader.h ***/
  86507. #if JUCE_USE_FLAC
  86508. #if HAVE_CONFIG_H
  86509. # include <config.h>
  86510. #endif
  86511. /*** Start of inlined file: memory.h ***/
  86512. #ifndef FLAC__PRIVATE__MEMORY_H
  86513. #define FLAC__PRIVATE__MEMORY_H
  86514. #ifdef HAVE_CONFIG_H
  86515. #include <config.h>
  86516. #endif
  86517. #include <stdlib.h> /* for size_t */
  86518. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86519. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86520. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86521. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86522. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86523. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86524. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86525. #endif
  86526. #endif
  86527. /*** End of inlined file: memory.h ***/
  86528. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86529. {
  86530. void *x;
  86531. FLAC__ASSERT(0 != aligned_address);
  86532. #ifdef FLAC__ALIGN_MALLOC_DATA
  86533. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86534. #ifdef SIZEOF_VOIDP
  86535. #if SIZEOF_VOIDP == 4
  86536. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86537. #elif SIZEOF_VOIDP == 8
  86538. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86539. #else
  86540. # error Unsupported sizeof(void*)
  86541. #endif
  86542. #else
  86543. if(sizeof(void*) == sizeof(unsigned))
  86544. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86545. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86546. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86547. else
  86548. return 0;
  86549. #endif
  86550. #else
  86551. x = safe_malloc_(bytes);
  86552. *aligned_address = x;
  86553. #endif
  86554. return x;
  86555. }
  86556. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86557. {
  86558. FLAC__int32 *pu; /* unaligned pointer */
  86559. union { /* union needed to comply with C99 pointer aliasing rules */
  86560. FLAC__int32 *pa; /* aligned pointer */
  86561. void *pv; /* aligned pointer alias */
  86562. } u;
  86563. FLAC__ASSERT(elements > 0);
  86564. FLAC__ASSERT(0 != unaligned_pointer);
  86565. FLAC__ASSERT(0 != aligned_pointer);
  86566. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86567. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86568. if(0 == pu) {
  86569. return false;
  86570. }
  86571. else {
  86572. if(*unaligned_pointer != 0)
  86573. free(*unaligned_pointer);
  86574. *unaligned_pointer = pu;
  86575. *aligned_pointer = u.pa;
  86576. return true;
  86577. }
  86578. }
  86579. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86580. {
  86581. FLAC__uint32 *pu; /* unaligned pointer */
  86582. union { /* union needed to comply with C99 pointer aliasing rules */
  86583. FLAC__uint32 *pa; /* aligned pointer */
  86584. void *pv; /* aligned pointer alias */
  86585. } u;
  86586. FLAC__ASSERT(elements > 0);
  86587. FLAC__ASSERT(0 != unaligned_pointer);
  86588. FLAC__ASSERT(0 != aligned_pointer);
  86589. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86590. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86591. if(0 == pu) {
  86592. return false;
  86593. }
  86594. else {
  86595. if(*unaligned_pointer != 0)
  86596. free(*unaligned_pointer);
  86597. *unaligned_pointer = pu;
  86598. *aligned_pointer = u.pa;
  86599. return true;
  86600. }
  86601. }
  86602. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86603. {
  86604. FLAC__uint64 *pu; /* unaligned pointer */
  86605. union { /* union needed to comply with C99 pointer aliasing rules */
  86606. FLAC__uint64 *pa; /* aligned pointer */
  86607. void *pv; /* aligned pointer alias */
  86608. } u;
  86609. FLAC__ASSERT(elements > 0);
  86610. FLAC__ASSERT(0 != unaligned_pointer);
  86611. FLAC__ASSERT(0 != aligned_pointer);
  86612. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86613. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86614. if(0 == pu) {
  86615. return false;
  86616. }
  86617. else {
  86618. if(*unaligned_pointer != 0)
  86619. free(*unaligned_pointer);
  86620. *unaligned_pointer = pu;
  86621. *aligned_pointer = u.pa;
  86622. return true;
  86623. }
  86624. }
  86625. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86626. {
  86627. unsigned *pu; /* unaligned pointer */
  86628. union { /* union needed to comply with C99 pointer aliasing rules */
  86629. unsigned *pa; /* aligned pointer */
  86630. void *pv; /* aligned pointer alias */
  86631. } u;
  86632. FLAC__ASSERT(elements > 0);
  86633. FLAC__ASSERT(0 != unaligned_pointer);
  86634. FLAC__ASSERT(0 != aligned_pointer);
  86635. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86636. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86637. if(0 == pu) {
  86638. return false;
  86639. }
  86640. else {
  86641. if(*unaligned_pointer != 0)
  86642. free(*unaligned_pointer);
  86643. *unaligned_pointer = pu;
  86644. *aligned_pointer = u.pa;
  86645. return true;
  86646. }
  86647. }
  86648. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86649. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86650. {
  86651. FLAC__real *pu; /* unaligned pointer */
  86652. union { /* union needed to comply with C99 pointer aliasing rules */
  86653. FLAC__real *pa; /* aligned pointer */
  86654. void *pv; /* aligned pointer alias */
  86655. } u;
  86656. FLAC__ASSERT(elements > 0);
  86657. FLAC__ASSERT(0 != unaligned_pointer);
  86658. FLAC__ASSERT(0 != aligned_pointer);
  86659. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86660. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86661. if(0 == pu) {
  86662. return false;
  86663. }
  86664. else {
  86665. if(*unaligned_pointer != 0)
  86666. free(*unaligned_pointer);
  86667. *unaligned_pointer = pu;
  86668. *aligned_pointer = u.pa;
  86669. return true;
  86670. }
  86671. }
  86672. #endif
  86673. #endif
  86674. /*** End of inlined file: memory.c ***/
  86675. /*** Start of inlined file: stream_decoder.c ***/
  86676. /*** Start of inlined file: juce_FlacHeader.h ***/
  86677. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86678. // tasks..
  86679. #define VERSION "1.2.1"
  86680. #define FLAC__NO_DLL 1
  86681. #if JUCE_MSVC
  86682. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86683. #endif
  86684. #if JUCE_MAC
  86685. #define FLAC__SYS_DARWIN 1
  86686. #endif
  86687. /*** End of inlined file: juce_FlacHeader.h ***/
  86688. #if JUCE_USE_FLAC
  86689. #if HAVE_CONFIG_H
  86690. # include <config.h>
  86691. #endif
  86692. #if defined _MSC_VER || defined __MINGW32__
  86693. #include <io.h> /* for _setmode() */
  86694. #include <fcntl.h> /* for _O_BINARY */
  86695. #endif
  86696. #if defined __CYGWIN__ || defined __EMX__
  86697. #include <io.h> /* for setmode(), O_BINARY */
  86698. #include <fcntl.h> /* for _O_BINARY */
  86699. #endif
  86700. #include <stdio.h>
  86701. #include <stdlib.h> /* for malloc() */
  86702. #include <string.h> /* for memset/memcpy() */
  86703. #include <sys/stat.h> /* for stat() */
  86704. #include <sys/types.h> /* for off_t */
  86705. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86706. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86707. #define fseeko fseek
  86708. #define ftello ftell
  86709. #endif
  86710. #endif
  86711. /*** Start of inlined file: stream_decoder.h ***/
  86712. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86713. #define FLAC__PROTECTED__STREAM_DECODER_H
  86714. #if FLAC__HAS_OGG
  86715. #include "include/private/ogg_decoder_aspect.h"
  86716. #endif
  86717. typedef struct FLAC__StreamDecoderProtected {
  86718. FLAC__StreamDecoderState state;
  86719. unsigned channels;
  86720. FLAC__ChannelAssignment channel_assignment;
  86721. unsigned bits_per_sample;
  86722. unsigned sample_rate; /* in Hz */
  86723. unsigned blocksize; /* in samples (per channel) */
  86724. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86725. #if FLAC__HAS_OGG
  86726. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86727. #endif
  86728. } FLAC__StreamDecoderProtected;
  86729. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86730. #endif
  86731. /*** End of inlined file: stream_decoder.h ***/
  86732. #ifdef max
  86733. #undef max
  86734. #endif
  86735. #define max(a,b) ((a)>(b)?(a):(b))
  86736. #ifdef _MSC_VER
  86737. #define FLAC__U64L(x) x
  86738. #else
  86739. #define FLAC__U64L(x) x##LLU
  86740. #endif
  86741. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86742. #if FLAC__HAS_OGG
  86743. 1
  86744. #else
  86745. 0
  86746. #endif
  86747. ;
  86748. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86749. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86750. static FILE *get_binary_stdin_(void);
  86751. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86752. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86753. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86754. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86755. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86756. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86757. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86758. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86759. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86760. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86761. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86762. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86763. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86764. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86765. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86766. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86767. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86768. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86769. 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);
  86770. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86771. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86772. #if FLAC__HAS_OGG
  86773. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86774. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86775. #endif
  86776. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86777. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86778. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86779. #if FLAC__HAS_OGG
  86780. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86781. #endif
  86782. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86783. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86784. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86785. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86786. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86787. typedef struct FLAC__StreamDecoderPrivate {
  86788. #if FLAC__HAS_OGG
  86789. FLAC__bool is_ogg;
  86790. #endif
  86791. FLAC__StreamDecoderReadCallback read_callback;
  86792. FLAC__StreamDecoderSeekCallback seek_callback;
  86793. FLAC__StreamDecoderTellCallback tell_callback;
  86794. FLAC__StreamDecoderLengthCallback length_callback;
  86795. FLAC__StreamDecoderEofCallback eof_callback;
  86796. FLAC__StreamDecoderWriteCallback write_callback;
  86797. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86798. FLAC__StreamDecoderErrorCallback error_callback;
  86799. 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[]);
  86800. 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[]);
  86801. 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[]);
  86802. 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[]);
  86803. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86804. void *client_data;
  86805. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86806. FLAC__BitReader *input;
  86807. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86808. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86809. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86810. unsigned output_capacity, output_channels;
  86811. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86812. FLAC__uint64 samples_decoded;
  86813. FLAC__bool has_stream_info, has_seek_table;
  86814. FLAC__StreamMetadata stream_info;
  86815. FLAC__StreamMetadata seek_table;
  86816. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86817. FLAC__byte *metadata_filter_ids;
  86818. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86819. FLAC__Frame frame;
  86820. FLAC__bool cached; /* true if there is a byte in lookahead */
  86821. FLAC__CPUInfo cpuinfo;
  86822. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86823. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86824. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86825. 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 */
  86826. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86827. FLAC__bool is_seeking;
  86828. FLAC__MD5Context md5context;
  86829. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86830. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86831. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86832. FLAC__uint64 target_sample;
  86833. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86834. #if FLAC__HAS_OGG
  86835. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86836. #endif
  86837. } FLAC__StreamDecoderPrivate;
  86838. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86839. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86840. "FLAC__STREAM_DECODER_READ_METADATA",
  86841. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86842. "FLAC__STREAM_DECODER_READ_FRAME",
  86843. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86844. "FLAC__STREAM_DECODER_OGG_ERROR",
  86845. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86846. "FLAC__STREAM_DECODER_ABORTED",
  86847. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86848. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86849. };
  86850. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86851. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86852. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86853. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86854. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86855. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86856. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86857. };
  86858. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86859. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86860. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86861. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86862. };
  86863. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86864. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86865. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86866. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86867. };
  86868. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86869. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86870. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86871. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86872. };
  86873. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86874. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86875. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86876. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86877. };
  86878. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86879. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86880. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86881. };
  86882. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86883. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86884. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86885. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86886. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86887. };
  86888. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86889. {
  86890. FLAC__StreamDecoder *decoder;
  86891. unsigned i;
  86892. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86893. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86894. if(decoder == 0) {
  86895. return 0;
  86896. }
  86897. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86898. if(decoder->protected_ == 0) {
  86899. free(decoder);
  86900. return 0;
  86901. }
  86902. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86903. if(decoder->private_ == 0) {
  86904. free(decoder->protected_);
  86905. free(decoder);
  86906. return 0;
  86907. }
  86908. decoder->private_->input = FLAC__bitreader_new();
  86909. if(decoder->private_->input == 0) {
  86910. free(decoder->private_);
  86911. free(decoder->protected_);
  86912. free(decoder);
  86913. return 0;
  86914. }
  86915. decoder->private_->metadata_filter_ids_capacity = 16;
  86916. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  86917. FLAC__bitreader_delete(decoder->private_->input);
  86918. free(decoder->private_);
  86919. free(decoder->protected_);
  86920. free(decoder);
  86921. return 0;
  86922. }
  86923. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  86924. decoder->private_->output[i] = 0;
  86925. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  86926. }
  86927. decoder->private_->output_capacity = 0;
  86928. decoder->private_->output_channels = 0;
  86929. decoder->private_->has_seek_table = false;
  86930. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86931. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  86932. decoder->private_->file = 0;
  86933. set_defaults_dec(decoder);
  86934. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  86935. return decoder;
  86936. }
  86937. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  86938. {
  86939. unsigned i;
  86940. FLAC__ASSERT(0 != decoder);
  86941. FLAC__ASSERT(0 != decoder->protected_);
  86942. FLAC__ASSERT(0 != decoder->private_);
  86943. FLAC__ASSERT(0 != decoder->private_->input);
  86944. (void)FLAC__stream_decoder_finish(decoder);
  86945. if(0 != decoder->private_->metadata_filter_ids)
  86946. free(decoder->private_->metadata_filter_ids);
  86947. FLAC__bitreader_delete(decoder->private_->input);
  86948. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86949. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  86950. free(decoder->private_);
  86951. free(decoder->protected_);
  86952. free(decoder);
  86953. }
  86954. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  86955. FLAC__StreamDecoder *decoder,
  86956. FLAC__StreamDecoderReadCallback read_callback,
  86957. FLAC__StreamDecoderSeekCallback seek_callback,
  86958. FLAC__StreamDecoderTellCallback tell_callback,
  86959. FLAC__StreamDecoderLengthCallback length_callback,
  86960. FLAC__StreamDecoderEofCallback eof_callback,
  86961. FLAC__StreamDecoderWriteCallback write_callback,
  86962. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86963. FLAC__StreamDecoderErrorCallback error_callback,
  86964. void *client_data,
  86965. FLAC__bool is_ogg
  86966. )
  86967. {
  86968. FLAC__ASSERT(0 != decoder);
  86969. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  86970. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  86971. #if !FLAC__HAS_OGG
  86972. if(is_ogg)
  86973. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  86974. #endif
  86975. if(
  86976. 0 == read_callback ||
  86977. 0 == write_callback ||
  86978. 0 == error_callback ||
  86979. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  86980. )
  86981. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  86982. #if FLAC__HAS_OGG
  86983. decoder->private_->is_ogg = is_ogg;
  86984. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  86985. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  86986. #endif
  86987. FLAC__cpu_info(&decoder->private_->cpuinfo);
  86988. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  86989. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  86990. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  86991. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  86992. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  86993. #ifndef FLAC__NO_ASM
  86994. if(decoder->private_->cpuinfo.use_asm) {
  86995. #ifdef FLAC__CPU_IA32
  86996. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  86997. #ifdef FLAC__HAS_NASM
  86998. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  86999. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87000. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87001. #endif
  87002. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87003. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87004. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87005. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87006. }
  87007. else {
  87008. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87009. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87010. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87011. }
  87012. #endif
  87013. #elif defined FLAC__CPU_PPC
  87014. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87015. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87016. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87017. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87018. }
  87019. #endif
  87020. }
  87021. #endif
  87022. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87023. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87024. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87025. }
  87026. decoder->private_->read_callback = read_callback;
  87027. decoder->private_->seek_callback = seek_callback;
  87028. decoder->private_->tell_callback = tell_callback;
  87029. decoder->private_->length_callback = length_callback;
  87030. decoder->private_->eof_callback = eof_callback;
  87031. decoder->private_->write_callback = write_callback;
  87032. decoder->private_->metadata_callback = metadata_callback;
  87033. decoder->private_->error_callback = error_callback;
  87034. decoder->private_->client_data = client_data;
  87035. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87036. decoder->private_->samples_decoded = 0;
  87037. decoder->private_->has_stream_info = false;
  87038. decoder->private_->cached = false;
  87039. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87040. decoder->private_->is_seeking = false;
  87041. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87042. if(!FLAC__stream_decoder_reset(decoder)) {
  87043. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87044. }
  87045. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87046. }
  87047. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87048. FLAC__StreamDecoder *decoder,
  87049. FLAC__StreamDecoderReadCallback read_callback,
  87050. FLAC__StreamDecoderSeekCallback seek_callback,
  87051. FLAC__StreamDecoderTellCallback tell_callback,
  87052. FLAC__StreamDecoderLengthCallback length_callback,
  87053. FLAC__StreamDecoderEofCallback eof_callback,
  87054. FLAC__StreamDecoderWriteCallback write_callback,
  87055. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87056. FLAC__StreamDecoderErrorCallback error_callback,
  87057. void *client_data
  87058. )
  87059. {
  87060. return init_stream_internal_dec(
  87061. decoder,
  87062. read_callback,
  87063. seek_callback,
  87064. tell_callback,
  87065. length_callback,
  87066. eof_callback,
  87067. write_callback,
  87068. metadata_callback,
  87069. error_callback,
  87070. client_data,
  87071. false
  87072. );
  87073. }
  87074. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87075. FLAC__StreamDecoder *decoder,
  87076. FLAC__StreamDecoderReadCallback read_callback,
  87077. FLAC__StreamDecoderSeekCallback seek_callback,
  87078. FLAC__StreamDecoderTellCallback tell_callback,
  87079. FLAC__StreamDecoderLengthCallback length_callback,
  87080. FLAC__StreamDecoderEofCallback eof_callback,
  87081. FLAC__StreamDecoderWriteCallback write_callback,
  87082. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87083. FLAC__StreamDecoderErrorCallback error_callback,
  87084. void *client_data
  87085. )
  87086. {
  87087. return init_stream_internal_dec(
  87088. decoder,
  87089. read_callback,
  87090. seek_callback,
  87091. tell_callback,
  87092. length_callback,
  87093. eof_callback,
  87094. write_callback,
  87095. metadata_callback,
  87096. error_callback,
  87097. client_data,
  87098. true
  87099. );
  87100. }
  87101. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87102. FLAC__StreamDecoder *decoder,
  87103. FILE *file,
  87104. FLAC__StreamDecoderWriteCallback write_callback,
  87105. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87106. FLAC__StreamDecoderErrorCallback error_callback,
  87107. void *client_data,
  87108. FLAC__bool is_ogg
  87109. )
  87110. {
  87111. FLAC__ASSERT(0 != decoder);
  87112. FLAC__ASSERT(0 != file);
  87113. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87114. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87115. if(0 == write_callback || 0 == error_callback)
  87116. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87117. if(file == stdin)
  87118. file = get_binary_stdin_(); /* just to be safe */
  87119. decoder->private_->file = file;
  87120. return init_stream_internal_dec(
  87121. decoder,
  87122. file_read_callback_dec,
  87123. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87124. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87125. decoder->private_->file == stdin? 0: file_length_callback_,
  87126. file_eof_callback_,
  87127. write_callback,
  87128. metadata_callback,
  87129. error_callback,
  87130. client_data,
  87131. is_ogg
  87132. );
  87133. }
  87134. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87135. FLAC__StreamDecoder *decoder,
  87136. FILE *file,
  87137. FLAC__StreamDecoderWriteCallback write_callback,
  87138. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87139. FLAC__StreamDecoderErrorCallback error_callback,
  87140. void *client_data
  87141. )
  87142. {
  87143. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87144. }
  87145. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87146. FLAC__StreamDecoder *decoder,
  87147. FILE *file,
  87148. FLAC__StreamDecoderWriteCallback write_callback,
  87149. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87150. FLAC__StreamDecoderErrorCallback error_callback,
  87151. void *client_data
  87152. )
  87153. {
  87154. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87155. }
  87156. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87157. FLAC__StreamDecoder *decoder,
  87158. const char *filename,
  87159. FLAC__StreamDecoderWriteCallback write_callback,
  87160. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87161. FLAC__StreamDecoderErrorCallback error_callback,
  87162. void *client_data,
  87163. FLAC__bool is_ogg
  87164. )
  87165. {
  87166. FILE *file;
  87167. FLAC__ASSERT(0 != decoder);
  87168. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87169. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87170. if(0 == write_callback || 0 == error_callback)
  87171. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87172. file = filename? fopen(filename, "rb") : stdin;
  87173. if(0 == file)
  87174. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87175. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87176. }
  87177. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87178. FLAC__StreamDecoder *decoder,
  87179. const char *filename,
  87180. FLAC__StreamDecoderWriteCallback write_callback,
  87181. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87182. FLAC__StreamDecoderErrorCallback error_callback,
  87183. void *client_data
  87184. )
  87185. {
  87186. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87187. }
  87188. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87189. FLAC__StreamDecoder *decoder,
  87190. const char *filename,
  87191. FLAC__StreamDecoderWriteCallback write_callback,
  87192. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87193. FLAC__StreamDecoderErrorCallback error_callback,
  87194. void *client_data
  87195. )
  87196. {
  87197. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87198. }
  87199. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87200. {
  87201. FLAC__bool md5_failed = false;
  87202. unsigned i;
  87203. FLAC__ASSERT(0 != decoder);
  87204. FLAC__ASSERT(0 != decoder->private_);
  87205. FLAC__ASSERT(0 != decoder->protected_);
  87206. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87207. return true;
  87208. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87209. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87210. free(decoder->private_->seek_table.data.seek_table.points);
  87211. decoder->private_->seek_table.data.seek_table.points = 0;
  87212. decoder->private_->has_seek_table = false;
  87213. }
  87214. FLAC__bitreader_free(decoder->private_->input);
  87215. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87216. if(0 != decoder->private_->output[i]) {
  87217. free(decoder->private_->output[i]-4);
  87218. decoder->private_->output[i] = 0;
  87219. }
  87220. if(0 != decoder->private_->residual_unaligned[i]) {
  87221. free(decoder->private_->residual_unaligned[i]);
  87222. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87223. }
  87224. }
  87225. decoder->private_->output_capacity = 0;
  87226. decoder->private_->output_channels = 0;
  87227. #if FLAC__HAS_OGG
  87228. if(decoder->private_->is_ogg)
  87229. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87230. #endif
  87231. if(0 != decoder->private_->file) {
  87232. if(decoder->private_->file != stdin)
  87233. fclose(decoder->private_->file);
  87234. decoder->private_->file = 0;
  87235. }
  87236. if(decoder->private_->do_md5_checking) {
  87237. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87238. md5_failed = true;
  87239. }
  87240. decoder->private_->is_seeking = false;
  87241. set_defaults_dec(decoder);
  87242. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87243. return !md5_failed;
  87244. }
  87245. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87246. {
  87247. FLAC__ASSERT(0 != decoder);
  87248. FLAC__ASSERT(0 != decoder->private_);
  87249. FLAC__ASSERT(0 != decoder->protected_);
  87250. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87251. return false;
  87252. #if FLAC__HAS_OGG
  87253. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87254. return true;
  87255. #else
  87256. (void)value;
  87257. return false;
  87258. #endif
  87259. }
  87260. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87261. {
  87262. FLAC__ASSERT(0 != decoder);
  87263. FLAC__ASSERT(0 != decoder->protected_);
  87264. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87265. return false;
  87266. decoder->protected_->md5_checking = value;
  87267. return true;
  87268. }
  87269. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87270. {
  87271. FLAC__ASSERT(0 != decoder);
  87272. FLAC__ASSERT(0 != decoder->private_);
  87273. FLAC__ASSERT(0 != decoder->protected_);
  87274. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87275. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87276. return false;
  87277. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87278. return false;
  87279. decoder->private_->metadata_filter[type] = true;
  87280. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87281. decoder->private_->metadata_filter_ids_count = 0;
  87282. return true;
  87283. }
  87284. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87285. {
  87286. FLAC__ASSERT(0 != decoder);
  87287. FLAC__ASSERT(0 != decoder->private_);
  87288. FLAC__ASSERT(0 != decoder->protected_);
  87289. FLAC__ASSERT(0 != id);
  87290. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87291. return false;
  87292. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87293. return true;
  87294. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87295. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87296. 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))) {
  87297. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87298. return false;
  87299. }
  87300. decoder->private_->metadata_filter_ids_capacity *= 2;
  87301. }
  87302. 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));
  87303. decoder->private_->metadata_filter_ids_count++;
  87304. return true;
  87305. }
  87306. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87307. {
  87308. unsigned i;
  87309. FLAC__ASSERT(0 != decoder);
  87310. FLAC__ASSERT(0 != decoder->private_);
  87311. FLAC__ASSERT(0 != decoder->protected_);
  87312. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87313. return false;
  87314. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87315. decoder->private_->metadata_filter[i] = true;
  87316. decoder->private_->metadata_filter_ids_count = 0;
  87317. return true;
  87318. }
  87319. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87320. {
  87321. FLAC__ASSERT(0 != decoder);
  87322. FLAC__ASSERT(0 != decoder->private_);
  87323. FLAC__ASSERT(0 != decoder->protected_);
  87324. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87325. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87326. return false;
  87327. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87328. return false;
  87329. decoder->private_->metadata_filter[type] = false;
  87330. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87331. decoder->private_->metadata_filter_ids_count = 0;
  87332. return true;
  87333. }
  87334. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87335. {
  87336. FLAC__ASSERT(0 != decoder);
  87337. FLAC__ASSERT(0 != decoder->private_);
  87338. FLAC__ASSERT(0 != decoder->protected_);
  87339. FLAC__ASSERT(0 != id);
  87340. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87341. return false;
  87342. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87343. return true;
  87344. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87345. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87346. 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))) {
  87347. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87348. return false;
  87349. }
  87350. decoder->private_->metadata_filter_ids_capacity *= 2;
  87351. }
  87352. 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));
  87353. decoder->private_->metadata_filter_ids_count++;
  87354. return true;
  87355. }
  87356. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87357. {
  87358. FLAC__ASSERT(0 != decoder);
  87359. FLAC__ASSERT(0 != decoder->private_);
  87360. FLAC__ASSERT(0 != decoder->protected_);
  87361. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87362. return false;
  87363. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87364. decoder->private_->metadata_filter_ids_count = 0;
  87365. return true;
  87366. }
  87367. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87368. {
  87369. FLAC__ASSERT(0 != decoder);
  87370. FLAC__ASSERT(0 != decoder->protected_);
  87371. return decoder->protected_->state;
  87372. }
  87373. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87374. {
  87375. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87376. }
  87377. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87378. {
  87379. FLAC__ASSERT(0 != decoder);
  87380. FLAC__ASSERT(0 != decoder->protected_);
  87381. return decoder->protected_->md5_checking;
  87382. }
  87383. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87384. {
  87385. FLAC__ASSERT(0 != decoder);
  87386. FLAC__ASSERT(0 != decoder->protected_);
  87387. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87388. }
  87389. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87390. {
  87391. FLAC__ASSERT(0 != decoder);
  87392. FLAC__ASSERT(0 != decoder->protected_);
  87393. return decoder->protected_->channels;
  87394. }
  87395. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87396. {
  87397. FLAC__ASSERT(0 != decoder);
  87398. FLAC__ASSERT(0 != decoder->protected_);
  87399. return decoder->protected_->channel_assignment;
  87400. }
  87401. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87402. {
  87403. FLAC__ASSERT(0 != decoder);
  87404. FLAC__ASSERT(0 != decoder->protected_);
  87405. return decoder->protected_->bits_per_sample;
  87406. }
  87407. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87408. {
  87409. FLAC__ASSERT(0 != decoder);
  87410. FLAC__ASSERT(0 != decoder->protected_);
  87411. return decoder->protected_->sample_rate;
  87412. }
  87413. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87414. {
  87415. FLAC__ASSERT(0 != decoder);
  87416. FLAC__ASSERT(0 != decoder->protected_);
  87417. return decoder->protected_->blocksize;
  87418. }
  87419. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87420. {
  87421. FLAC__ASSERT(0 != decoder);
  87422. FLAC__ASSERT(0 != decoder->private_);
  87423. FLAC__ASSERT(0 != position);
  87424. #if FLAC__HAS_OGG
  87425. if(decoder->private_->is_ogg)
  87426. return false;
  87427. #endif
  87428. if(0 == decoder->private_->tell_callback)
  87429. return false;
  87430. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87431. return false;
  87432. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87433. return false;
  87434. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87435. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87436. return true;
  87437. }
  87438. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87439. {
  87440. FLAC__ASSERT(0 != decoder);
  87441. FLAC__ASSERT(0 != decoder->private_);
  87442. FLAC__ASSERT(0 != decoder->protected_);
  87443. decoder->private_->samples_decoded = 0;
  87444. decoder->private_->do_md5_checking = false;
  87445. #if FLAC__HAS_OGG
  87446. if(decoder->private_->is_ogg)
  87447. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87448. #endif
  87449. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87450. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87451. return false;
  87452. }
  87453. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87454. return true;
  87455. }
  87456. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87457. {
  87458. FLAC__ASSERT(0 != decoder);
  87459. FLAC__ASSERT(0 != decoder->private_);
  87460. FLAC__ASSERT(0 != decoder->protected_);
  87461. if(!FLAC__stream_decoder_flush(decoder)) {
  87462. return false;
  87463. }
  87464. #if FLAC__HAS_OGG
  87465. if(decoder->private_->is_ogg)
  87466. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87467. #endif
  87468. if(!decoder->private_->internal_reset_hack) {
  87469. if(decoder->private_->file == stdin)
  87470. return false; /* can't rewind stdin, reset fails */
  87471. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87472. return false; /* seekable and seek fails, reset fails */
  87473. }
  87474. else
  87475. decoder->private_->internal_reset_hack = false;
  87476. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87477. decoder->private_->has_stream_info = false;
  87478. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87479. free(decoder->private_->seek_table.data.seek_table.points);
  87480. decoder->private_->seek_table.data.seek_table.points = 0;
  87481. decoder->private_->has_seek_table = false;
  87482. }
  87483. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87484. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87485. FLAC__MD5Init(&decoder->private_->md5context);
  87486. decoder->private_->first_frame_offset = 0;
  87487. decoder->private_->unparseable_frame_count = 0;
  87488. return true;
  87489. }
  87490. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87491. {
  87492. FLAC__bool got_a_frame;
  87493. FLAC__ASSERT(0 != decoder);
  87494. FLAC__ASSERT(0 != decoder->protected_);
  87495. while(1) {
  87496. switch(decoder->protected_->state) {
  87497. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87498. if(!find_metadata_(decoder))
  87499. return false; /* above function sets the status for us */
  87500. break;
  87501. case FLAC__STREAM_DECODER_READ_METADATA:
  87502. if(!read_metadata_(decoder))
  87503. return false; /* above function sets the status for us */
  87504. else
  87505. return true;
  87506. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87507. if(!frame_sync_(decoder))
  87508. return true; /* above function sets the status for us */
  87509. break;
  87510. case FLAC__STREAM_DECODER_READ_FRAME:
  87511. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87512. return false; /* above function sets the status for us */
  87513. if(got_a_frame)
  87514. return true; /* above function sets the status for us */
  87515. break;
  87516. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87517. case FLAC__STREAM_DECODER_ABORTED:
  87518. return true;
  87519. default:
  87520. FLAC__ASSERT(0);
  87521. return false;
  87522. }
  87523. }
  87524. }
  87525. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87526. {
  87527. FLAC__ASSERT(0 != decoder);
  87528. FLAC__ASSERT(0 != decoder->protected_);
  87529. while(1) {
  87530. switch(decoder->protected_->state) {
  87531. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87532. if(!find_metadata_(decoder))
  87533. return false; /* above function sets the status for us */
  87534. break;
  87535. case FLAC__STREAM_DECODER_READ_METADATA:
  87536. if(!read_metadata_(decoder))
  87537. return false; /* above function sets the status for us */
  87538. break;
  87539. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87540. case FLAC__STREAM_DECODER_READ_FRAME:
  87541. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87542. case FLAC__STREAM_DECODER_ABORTED:
  87543. return true;
  87544. default:
  87545. FLAC__ASSERT(0);
  87546. return false;
  87547. }
  87548. }
  87549. }
  87550. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87551. {
  87552. FLAC__bool dummy;
  87553. FLAC__ASSERT(0 != decoder);
  87554. FLAC__ASSERT(0 != decoder->protected_);
  87555. while(1) {
  87556. switch(decoder->protected_->state) {
  87557. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87558. if(!find_metadata_(decoder))
  87559. return false; /* above function sets the status for us */
  87560. break;
  87561. case FLAC__STREAM_DECODER_READ_METADATA:
  87562. if(!read_metadata_(decoder))
  87563. return false; /* above function sets the status for us */
  87564. break;
  87565. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87566. if(!frame_sync_(decoder))
  87567. return true; /* above function sets the status for us */
  87568. break;
  87569. case FLAC__STREAM_DECODER_READ_FRAME:
  87570. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87571. return false; /* above function sets the status for us */
  87572. break;
  87573. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87574. case FLAC__STREAM_DECODER_ABORTED:
  87575. return true;
  87576. default:
  87577. FLAC__ASSERT(0);
  87578. return false;
  87579. }
  87580. }
  87581. }
  87582. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87583. {
  87584. FLAC__bool got_a_frame;
  87585. FLAC__ASSERT(0 != decoder);
  87586. FLAC__ASSERT(0 != decoder->protected_);
  87587. while(1) {
  87588. switch(decoder->protected_->state) {
  87589. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87590. case FLAC__STREAM_DECODER_READ_METADATA:
  87591. return false; /* above function sets the status for us */
  87592. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87593. if(!frame_sync_(decoder))
  87594. return true; /* above function sets the status for us */
  87595. break;
  87596. case FLAC__STREAM_DECODER_READ_FRAME:
  87597. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87598. return false; /* above function sets the status for us */
  87599. if(got_a_frame)
  87600. return true; /* above function sets the status for us */
  87601. break;
  87602. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87603. case FLAC__STREAM_DECODER_ABORTED:
  87604. return true;
  87605. default:
  87606. FLAC__ASSERT(0);
  87607. return false;
  87608. }
  87609. }
  87610. }
  87611. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87612. {
  87613. FLAC__uint64 length;
  87614. FLAC__ASSERT(0 != decoder);
  87615. if(
  87616. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87617. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87618. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87619. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87620. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87621. )
  87622. return false;
  87623. if(0 == decoder->private_->seek_callback)
  87624. return false;
  87625. FLAC__ASSERT(decoder->private_->seek_callback);
  87626. FLAC__ASSERT(decoder->private_->tell_callback);
  87627. FLAC__ASSERT(decoder->private_->length_callback);
  87628. FLAC__ASSERT(decoder->private_->eof_callback);
  87629. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87630. return false;
  87631. decoder->private_->is_seeking = true;
  87632. decoder->private_->do_md5_checking = false;
  87633. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87634. decoder->private_->is_seeking = false;
  87635. return false;
  87636. }
  87637. if(
  87638. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87639. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87640. ) {
  87641. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87642. decoder->private_->is_seeking = false;
  87643. return false;
  87644. }
  87645. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87646. decoder->private_->is_seeking = false;
  87647. return false;
  87648. }
  87649. }
  87650. {
  87651. const FLAC__bool ok =
  87652. #if FLAC__HAS_OGG
  87653. decoder->private_->is_ogg?
  87654. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87655. #endif
  87656. seek_to_absolute_sample_(decoder, length, sample)
  87657. ;
  87658. decoder->private_->is_seeking = false;
  87659. return ok;
  87660. }
  87661. }
  87662. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87663. {
  87664. FLAC__ASSERT(0 != decoder);
  87665. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87666. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87667. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87668. }
  87669. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87670. {
  87671. #if FLAC__HAS_OGG
  87672. decoder->private_->is_ogg = false;
  87673. #endif
  87674. decoder->private_->read_callback = 0;
  87675. decoder->private_->seek_callback = 0;
  87676. decoder->private_->tell_callback = 0;
  87677. decoder->private_->length_callback = 0;
  87678. decoder->private_->eof_callback = 0;
  87679. decoder->private_->write_callback = 0;
  87680. decoder->private_->metadata_callback = 0;
  87681. decoder->private_->error_callback = 0;
  87682. decoder->private_->client_data = 0;
  87683. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87684. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87685. decoder->private_->metadata_filter_ids_count = 0;
  87686. decoder->protected_->md5_checking = false;
  87687. #if FLAC__HAS_OGG
  87688. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87689. #endif
  87690. }
  87691. FILE *get_binary_stdin_(void)
  87692. {
  87693. #if defined _MSC_VER || defined __MINGW32__
  87694. _setmode(_fileno(stdin), _O_BINARY);
  87695. #elif defined __CYGWIN__
  87696. setmode(_fileno(stdin), _O_BINARY);
  87697. #elif defined __EMX__
  87698. setmode(fileno(stdin), O_BINARY);
  87699. #endif
  87700. return stdin;
  87701. }
  87702. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87703. {
  87704. unsigned i;
  87705. FLAC__int32 *tmp;
  87706. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87707. return true;
  87708. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87709. if(0 != decoder->private_->output[i]) {
  87710. free(decoder->private_->output[i]-4);
  87711. decoder->private_->output[i] = 0;
  87712. }
  87713. if(0 != decoder->private_->residual_unaligned[i]) {
  87714. free(decoder->private_->residual_unaligned[i]);
  87715. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87716. }
  87717. }
  87718. for(i = 0; i < channels; i++) {
  87719. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87720. if(tmp == 0) {
  87721. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87722. return false;
  87723. }
  87724. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87725. decoder->private_->output[i] = tmp + 4;
  87726. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87727. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87728. return false;
  87729. }
  87730. }
  87731. decoder->private_->output_capacity = size;
  87732. decoder->private_->output_channels = channels;
  87733. return true;
  87734. }
  87735. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87736. {
  87737. size_t i;
  87738. FLAC__ASSERT(0 != decoder);
  87739. FLAC__ASSERT(0 != decoder->private_);
  87740. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87741. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87742. return true;
  87743. return false;
  87744. }
  87745. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87746. {
  87747. FLAC__uint32 x;
  87748. unsigned i, id_;
  87749. FLAC__bool first = true;
  87750. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87751. for(i = id_ = 0; i < 4; ) {
  87752. if(decoder->private_->cached) {
  87753. x = (FLAC__uint32)decoder->private_->lookahead;
  87754. decoder->private_->cached = false;
  87755. }
  87756. else {
  87757. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87758. return false; /* read_callback_ sets the state for us */
  87759. }
  87760. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87761. first = true;
  87762. i++;
  87763. id_ = 0;
  87764. continue;
  87765. }
  87766. if(x == ID3V2_TAG_[id_]) {
  87767. id_++;
  87768. i = 0;
  87769. if(id_ == 3) {
  87770. if(!skip_id3v2_tag_(decoder))
  87771. return false; /* skip_id3v2_tag_ sets the state for us */
  87772. }
  87773. continue;
  87774. }
  87775. id_ = 0;
  87776. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87777. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87778. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87779. return false; /* read_callback_ sets the state for us */
  87780. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87781. decoder->private_->lookahead = (FLAC__byte)x;
  87782. decoder->private_->cached = true;
  87783. }
  87784. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87785. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87786. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87787. return true;
  87788. }
  87789. }
  87790. i = 0;
  87791. if(first) {
  87792. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87793. first = false;
  87794. }
  87795. }
  87796. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87797. return true;
  87798. }
  87799. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87800. {
  87801. FLAC__bool is_last;
  87802. FLAC__uint32 i, x, type, length;
  87803. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87804. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87805. return false; /* read_callback_ sets the state for us */
  87806. is_last = x? true : false;
  87807. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87808. return false; /* read_callback_ sets the state for us */
  87809. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87810. return false; /* read_callback_ sets the state for us */
  87811. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87812. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87813. return false;
  87814. decoder->private_->has_stream_info = true;
  87815. 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))
  87816. decoder->private_->do_md5_checking = false;
  87817. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87818. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87819. }
  87820. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87821. if(!read_metadata_seektable_(decoder, is_last, length))
  87822. return false;
  87823. decoder->private_->has_seek_table = true;
  87824. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87825. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87826. }
  87827. else {
  87828. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87829. unsigned real_length = length;
  87830. FLAC__StreamMetadata block;
  87831. block.is_last = is_last;
  87832. block.type = (FLAC__MetadataType)type;
  87833. block.length = length;
  87834. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87835. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87836. return false; /* read_callback_ sets the state for us */
  87837. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87838. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87839. return false;
  87840. }
  87841. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87842. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87843. skip_it = !skip_it;
  87844. }
  87845. if(skip_it) {
  87846. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87847. return false; /* read_callback_ sets the state for us */
  87848. }
  87849. else {
  87850. switch(type) {
  87851. case FLAC__METADATA_TYPE_PADDING:
  87852. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87853. return false; /* read_callback_ sets the state for us */
  87854. break;
  87855. case FLAC__METADATA_TYPE_APPLICATION:
  87856. if(real_length > 0) {
  87857. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87858. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87859. return false;
  87860. }
  87861. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87862. return false; /* read_callback_ sets the state for us */
  87863. }
  87864. else
  87865. block.data.application.data = 0;
  87866. break;
  87867. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87868. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87869. return false;
  87870. break;
  87871. case FLAC__METADATA_TYPE_CUESHEET:
  87872. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87873. return false;
  87874. break;
  87875. case FLAC__METADATA_TYPE_PICTURE:
  87876. if(!read_metadata_picture_(decoder, &block.data.picture))
  87877. return false;
  87878. break;
  87879. case FLAC__METADATA_TYPE_STREAMINFO:
  87880. case FLAC__METADATA_TYPE_SEEKTABLE:
  87881. FLAC__ASSERT(0);
  87882. break;
  87883. default:
  87884. if(real_length > 0) {
  87885. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87886. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87887. return false;
  87888. }
  87889. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87890. return false; /* read_callback_ sets the state for us */
  87891. }
  87892. else
  87893. block.data.unknown.data = 0;
  87894. break;
  87895. }
  87896. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87897. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87898. switch(type) {
  87899. case FLAC__METADATA_TYPE_PADDING:
  87900. break;
  87901. case FLAC__METADATA_TYPE_APPLICATION:
  87902. if(0 != block.data.application.data)
  87903. free(block.data.application.data);
  87904. break;
  87905. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87906. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87907. free(block.data.vorbis_comment.vendor_string.entry);
  87908. if(block.data.vorbis_comment.num_comments > 0)
  87909. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87910. if(0 != block.data.vorbis_comment.comments[i].entry)
  87911. free(block.data.vorbis_comment.comments[i].entry);
  87912. if(0 != block.data.vorbis_comment.comments)
  87913. free(block.data.vorbis_comment.comments);
  87914. break;
  87915. case FLAC__METADATA_TYPE_CUESHEET:
  87916. if(block.data.cue_sheet.num_tracks > 0)
  87917. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  87918. if(0 != block.data.cue_sheet.tracks[i].indices)
  87919. free(block.data.cue_sheet.tracks[i].indices);
  87920. if(0 != block.data.cue_sheet.tracks)
  87921. free(block.data.cue_sheet.tracks);
  87922. break;
  87923. case FLAC__METADATA_TYPE_PICTURE:
  87924. if(0 != block.data.picture.mime_type)
  87925. free(block.data.picture.mime_type);
  87926. if(0 != block.data.picture.description)
  87927. free(block.data.picture.description);
  87928. if(0 != block.data.picture.data)
  87929. free(block.data.picture.data);
  87930. break;
  87931. case FLAC__METADATA_TYPE_STREAMINFO:
  87932. case FLAC__METADATA_TYPE_SEEKTABLE:
  87933. FLAC__ASSERT(0);
  87934. default:
  87935. if(0 != block.data.unknown.data)
  87936. free(block.data.unknown.data);
  87937. break;
  87938. }
  87939. }
  87940. }
  87941. if(is_last) {
  87942. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  87943. decoder->private_->first_frame_offset = 0;
  87944. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87945. }
  87946. return true;
  87947. }
  87948. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87949. {
  87950. FLAC__uint32 x;
  87951. unsigned bits, used_bits = 0;
  87952. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87953. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  87954. decoder->private_->stream_info.is_last = is_last;
  87955. decoder->private_->stream_info.length = length;
  87956. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  87957. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  87958. return false; /* read_callback_ sets the state for us */
  87959. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  87960. used_bits += bits;
  87961. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  87962. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  87963. return false; /* read_callback_ sets the state for us */
  87964. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  87965. used_bits += bits;
  87966. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  87967. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  87968. return false; /* read_callback_ sets the state for us */
  87969. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  87970. used_bits += bits;
  87971. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  87972. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  87973. return false; /* read_callback_ sets the state for us */
  87974. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  87975. used_bits += bits;
  87976. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  87977. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  87978. return false; /* read_callback_ sets the state for us */
  87979. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  87980. used_bits += bits;
  87981. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  87982. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  87983. return false; /* read_callback_ sets the state for us */
  87984. decoder->private_->stream_info.data.stream_info.channels = x+1;
  87985. used_bits += bits;
  87986. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  87987. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  87988. return false; /* read_callback_ sets the state for us */
  87989. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  87990. used_bits += bits;
  87991. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  87992. 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))
  87993. return false; /* read_callback_ sets the state for us */
  87994. used_bits += bits;
  87995. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  87996. return false; /* read_callback_ sets the state for us */
  87997. used_bits += 16*8;
  87998. FLAC__ASSERT(used_bits % 8 == 0);
  87999. length -= (used_bits / 8);
  88000. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88001. return false; /* read_callback_ sets the state for us */
  88002. return true;
  88003. }
  88004. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88005. {
  88006. FLAC__uint32 i, x;
  88007. FLAC__uint64 xx;
  88008. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88009. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88010. decoder->private_->seek_table.is_last = is_last;
  88011. decoder->private_->seek_table.length = length;
  88012. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88013. 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)))) {
  88014. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88015. return false;
  88016. }
  88017. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88018. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88019. return false; /* read_callback_ sets the state for us */
  88020. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88021. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88022. return false; /* read_callback_ sets the state for us */
  88023. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88024. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88025. return false; /* read_callback_ sets the state for us */
  88026. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88027. }
  88028. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88029. if(length > 0) {
  88030. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88031. return false; /* read_callback_ sets the state for us */
  88032. }
  88033. return true;
  88034. }
  88035. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88036. {
  88037. FLAC__uint32 i;
  88038. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88039. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88040. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88041. return false; /* read_callback_ sets the state for us */
  88042. if(obj->vendor_string.length > 0) {
  88043. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88044. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88045. return false;
  88046. }
  88047. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88048. return false; /* read_callback_ sets the state for us */
  88049. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88050. }
  88051. else
  88052. obj->vendor_string.entry = 0;
  88053. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88054. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88055. return false; /* read_callback_ sets the state for us */
  88056. if(obj->num_comments > 0) {
  88057. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88058. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88059. return false;
  88060. }
  88061. for(i = 0; i < obj->num_comments; i++) {
  88062. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88063. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88064. return false; /* read_callback_ sets the state for us */
  88065. if(obj->comments[i].length > 0) {
  88066. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88067. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88068. return false;
  88069. }
  88070. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88071. return false; /* read_callback_ sets the state for us */
  88072. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88073. }
  88074. else
  88075. obj->comments[i].entry = 0;
  88076. }
  88077. }
  88078. else {
  88079. obj->comments = 0;
  88080. }
  88081. return true;
  88082. }
  88083. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88084. {
  88085. FLAC__uint32 i, j, x;
  88086. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88087. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88088. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88089. 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))
  88090. return false; /* read_callback_ sets the state for us */
  88091. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88092. return false; /* read_callback_ sets the state for us */
  88093. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88094. return false; /* read_callback_ sets the state for us */
  88095. obj->is_cd = x? true : false;
  88096. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88097. return false; /* read_callback_ sets the state for us */
  88098. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88099. return false; /* read_callback_ sets the state for us */
  88100. obj->num_tracks = x;
  88101. if(obj->num_tracks > 0) {
  88102. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88103. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88104. return false;
  88105. }
  88106. for(i = 0; i < obj->num_tracks; i++) {
  88107. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88108. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88109. return false; /* read_callback_ sets the state for us */
  88110. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88111. return false; /* read_callback_ sets the state for us */
  88112. track->number = (FLAC__byte)x;
  88113. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88114. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88115. return false; /* read_callback_ sets the state for us */
  88116. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88117. return false; /* read_callback_ sets the state for us */
  88118. track->type = x;
  88119. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88120. return false; /* read_callback_ sets the state for us */
  88121. track->pre_emphasis = x;
  88122. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88123. return false; /* read_callback_ sets the state for us */
  88124. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88125. return false; /* read_callback_ sets the state for us */
  88126. track->num_indices = (FLAC__byte)x;
  88127. if(track->num_indices > 0) {
  88128. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88129. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88130. return false;
  88131. }
  88132. for(j = 0; j < track->num_indices; j++) {
  88133. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88134. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88135. return false; /* read_callback_ sets the state for us */
  88136. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88137. return false; /* read_callback_ sets the state for us */
  88138. index->number = (FLAC__byte)x;
  88139. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88140. return false; /* read_callback_ sets the state for us */
  88141. }
  88142. }
  88143. }
  88144. }
  88145. return true;
  88146. }
  88147. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88148. {
  88149. FLAC__uint32 x;
  88150. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88151. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88152. return false; /* read_callback_ sets the state for us */
  88153. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88154. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88155. return false; /* read_callback_ sets the state for us */
  88156. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88157. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88158. return false;
  88159. }
  88160. if(x > 0) {
  88161. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88162. return false; /* read_callback_ sets the state for us */
  88163. }
  88164. obj->mime_type[x] = '\0';
  88165. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88166. return false; /* read_callback_ sets the state for us */
  88167. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88168. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88169. return false;
  88170. }
  88171. if(x > 0) {
  88172. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88173. return false; /* read_callback_ sets the state for us */
  88174. }
  88175. obj->description[x] = '\0';
  88176. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88177. return false; /* read_callback_ sets the state for us */
  88178. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88179. return false; /* read_callback_ sets the state for us */
  88180. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88181. return false; /* read_callback_ sets the state for us */
  88182. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88183. return false; /* read_callback_ sets the state for us */
  88184. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88185. return false; /* read_callback_ sets the state for us */
  88186. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88187. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88188. return false;
  88189. }
  88190. if(obj->data_length > 0) {
  88191. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88192. return false; /* read_callback_ sets the state for us */
  88193. }
  88194. return true;
  88195. }
  88196. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88197. {
  88198. FLAC__uint32 x;
  88199. unsigned i, skip;
  88200. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88201. return false; /* read_callback_ sets the state for us */
  88202. skip = 0;
  88203. for(i = 0; i < 4; i++) {
  88204. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88205. return false; /* read_callback_ sets the state for us */
  88206. skip <<= 7;
  88207. skip |= (x & 0x7f);
  88208. }
  88209. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88210. return false; /* read_callback_ sets the state for us */
  88211. return true;
  88212. }
  88213. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88214. {
  88215. FLAC__uint32 x;
  88216. FLAC__bool first = true;
  88217. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88218. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88219. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88220. return true;
  88221. }
  88222. }
  88223. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88224. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88225. return false; /* read_callback_ sets the state for us */
  88226. }
  88227. while(1) {
  88228. if(decoder->private_->cached) {
  88229. x = (FLAC__uint32)decoder->private_->lookahead;
  88230. decoder->private_->cached = false;
  88231. }
  88232. else {
  88233. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88234. return false; /* read_callback_ sets the state for us */
  88235. }
  88236. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88237. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88238. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88239. return false; /* read_callback_ sets the state for us */
  88240. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88241. decoder->private_->lookahead = (FLAC__byte)x;
  88242. decoder->private_->cached = true;
  88243. }
  88244. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88245. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88246. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88247. return true;
  88248. }
  88249. }
  88250. if(first) {
  88251. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88252. first = false;
  88253. }
  88254. }
  88255. return true;
  88256. }
  88257. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88258. {
  88259. unsigned channel;
  88260. unsigned i;
  88261. FLAC__int32 mid, side;
  88262. unsigned frame_crc; /* the one we calculate from the input stream */
  88263. FLAC__uint32 x;
  88264. *got_a_frame = false;
  88265. frame_crc = 0;
  88266. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88267. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88268. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88269. if(!read_frame_header_(decoder))
  88270. return false;
  88271. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88272. return true;
  88273. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88274. return false;
  88275. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88276. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88277. switch(decoder->private_->frame.header.channel_assignment) {
  88278. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88279. break;
  88280. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88281. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88282. if(channel == 1)
  88283. bps++;
  88284. break;
  88285. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88286. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88287. if(channel == 0)
  88288. bps++;
  88289. break;
  88290. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88291. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88292. if(channel == 1)
  88293. bps++;
  88294. break;
  88295. default:
  88296. FLAC__ASSERT(0);
  88297. }
  88298. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88299. return false;
  88300. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88301. return true;
  88302. }
  88303. if(!read_zero_padding_(decoder))
  88304. return false;
  88305. 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) */
  88306. return true;
  88307. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88308. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88309. return false; /* read_callback_ sets the state for us */
  88310. if(frame_crc == x) {
  88311. if(do_full_decode) {
  88312. switch(decoder->private_->frame.header.channel_assignment) {
  88313. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88314. break;
  88315. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88316. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88317. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88318. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88319. break;
  88320. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88321. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88322. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88323. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88324. break;
  88325. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88326. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88327. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88328. #if 1
  88329. mid = decoder->private_->output[0][i];
  88330. side = decoder->private_->output[1][i];
  88331. mid <<= 1;
  88332. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88333. decoder->private_->output[0][i] = (mid + side) >> 1;
  88334. decoder->private_->output[1][i] = (mid - side) >> 1;
  88335. #else
  88336. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88337. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88338. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88339. #endif
  88340. }
  88341. break;
  88342. default:
  88343. FLAC__ASSERT(0);
  88344. break;
  88345. }
  88346. }
  88347. }
  88348. else {
  88349. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88350. if(do_full_decode) {
  88351. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88352. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88353. }
  88354. }
  88355. }
  88356. *got_a_frame = true;
  88357. if(decoder->private_->next_fixed_block_size)
  88358. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88359. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88360. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88361. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88362. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88363. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88364. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88365. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88366. if(do_full_decode) {
  88367. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88368. return false;
  88369. }
  88370. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88371. return true;
  88372. }
  88373. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88374. {
  88375. FLAC__uint32 x;
  88376. FLAC__uint64 xx;
  88377. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88378. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88379. unsigned raw_header_len;
  88380. FLAC__bool is_unparseable = false;
  88381. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88382. raw_header[0] = decoder->private_->header_warmup[0];
  88383. raw_header[1] = decoder->private_->header_warmup[1];
  88384. raw_header_len = 2;
  88385. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88386. is_unparseable = true;
  88387. for(i = 0; i < 2; i++) {
  88388. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88389. return false; /* read_callback_ sets the state for us */
  88390. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88391. decoder->private_->lookahead = (FLAC__byte)x;
  88392. decoder->private_->cached = true;
  88393. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88394. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88395. return true;
  88396. }
  88397. raw_header[raw_header_len++] = (FLAC__byte)x;
  88398. }
  88399. switch(x = raw_header[2] >> 4) {
  88400. case 0:
  88401. is_unparseable = true;
  88402. break;
  88403. case 1:
  88404. decoder->private_->frame.header.blocksize = 192;
  88405. break;
  88406. case 2:
  88407. case 3:
  88408. case 4:
  88409. case 5:
  88410. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88411. break;
  88412. case 6:
  88413. case 7:
  88414. blocksize_hint = x;
  88415. break;
  88416. case 8:
  88417. case 9:
  88418. case 10:
  88419. case 11:
  88420. case 12:
  88421. case 13:
  88422. case 14:
  88423. case 15:
  88424. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88425. break;
  88426. default:
  88427. FLAC__ASSERT(0);
  88428. break;
  88429. }
  88430. switch(x = raw_header[2] & 0x0f) {
  88431. case 0:
  88432. if(decoder->private_->has_stream_info)
  88433. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88434. else
  88435. is_unparseable = true;
  88436. break;
  88437. case 1:
  88438. decoder->private_->frame.header.sample_rate = 88200;
  88439. break;
  88440. case 2:
  88441. decoder->private_->frame.header.sample_rate = 176400;
  88442. break;
  88443. case 3:
  88444. decoder->private_->frame.header.sample_rate = 192000;
  88445. break;
  88446. case 4:
  88447. decoder->private_->frame.header.sample_rate = 8000;
  88448. break;
  88449. case 5:
  88450. decoder->private_->frame.header.sample_rate = 16000;
  88451. break;
  88452. case 6:
  88453. decoder->private_->frame.header.sample_rate = 22050;
  88454. break;
  88455. case 7:
  88456. decoder->private_->frame.header.sample_rate = 24000;
  88457. break;
  88458. case 8:
  88459. decoder->private_->frame.header.sample_rate = 32000;
  88460. break;
  88461. case 9:
  88462. decoder->private_->frame.header.sample_rate = 44100;
  88463. break;
  88464. case 10:
  88465. decoder->private_->frame.header.sample_rate = 48000;
  88466. break;
  88467. case 11:
  88468. decoder->private_->frame.header.sample_rate = 96000;
  88469. break;
  88470. case 12:
  88471. case 13:
  88472. case 14:
  88473. sample_rate_hint = x;
  88474. break;
  88475. case 15:
  88476. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88477. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88478. return true;
  88479. default:
  88480. FLAC__ASSERT(0);
  88481. }
  88482. x = (unsigned)(raw_header[3] >> 4);
  88483. if(x & 8) {
  88484. decoder->private_->frame.header.channels = 2;
  88485. switch(x & 7) {
  88486. case 0:
  88487. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88488. break;
  88489. case 1:
  88490. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88491. break;
  88492. case 2:
  88493. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88494. break;
  88495. default:
  88496. is_unparseable = true;
  88497. break;
  88498. }
  88499. }
  88500. else {
  88501. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88502. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88503. }
  88504. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88505. case 0:
  88506. if(decoder->private_->has_stream_info)
  88507. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88508. else
  88509. is_unparseable = true;
  88510. break;
  88511. case 1:
  88512. decoder->private_->frame.header.bits_per_sample = 8;
  88513. break;
  88514. case 2:
  88515. decoder->private_->frame.header.bits_per_sample = 12;
  88516. break;
  88517. case 4:
  88518. decoder->private_->frame.header.bits_per_sample = 16;
  88519. break;
  88520. case 5:
  88521. decoder->private_->frame.header.bits_per_sample = 20;
  88522. break;
  88523. case 6:
  88524. decoder->private_->frame.header.bits_per_sample = 24;
  88525. break;
  88526. case 3:
  88527. case 7:
  88528. is_unparseable = true;
  88529. break;
  88530. default:
  88531. FLAC__ASSERT(0);
  88532. break;
  88533. }
  88534. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88535. is_unparseable = true;
  88536. if(
  88537. raw_header[1] & 0x01 ||
  88538. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88539. ) { /* variable blocksize */
  88540. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88541. return false; /* read_callback_ sets the state for us */
  88542. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88543. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88544. decoder->private_->cached = true;
  88545. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88546. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88547. return true;
  88548. }
  88549. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88550. decoder->private_->frame.header.number.sample_number = xx;
  88551. }
  88552. else { /* fixed blocksize */
  88553. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88554. return false; /* read_callback_ sets the state for us */
  88555. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88556. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88557. decoder->private_->cached = true;
  88558. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88559. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88560. return true;
  88561. }
  88562. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88563. decoder->private_->frame.header.number.frame_number = x;
  88564. }
  88565. if(blocksize_hint) {
  88566. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88567. return false; /* read_callback_ sets the state for us */
  88568. raw_header[raw_header_len++] = (FLAC__byte)x;
  88569. if(blocksize_hint == 7) {
  88570. FLAC__uint32 _x;
  88571. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88572. return false; /* read_callback_ sets the state for us */
  88573. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88574. x = (x << 8) | _x;
  88575. }
  88576. decoder->private_->frame.header.blocksize = x+1;
  88577. }
  88578. if(sample_rate_hint) {
  88579. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88580. return false; /* read_callback_ sets the state for us */
  88581. raw_header[raw_header_len++] = (FLAC__byte)x;
  88582. if(sample_rate_hint != 12) {
  88583. FLAC__uint32 _x;
  88584. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88585. return false; /* read_callback_ sets the state for us */
  88586. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88587. x = (x << 8) | _x;
  88588. }
  88589. if(sample_rate_hint == 12)
  88590. decoder->private_->frame.header.sample_rate = x*1000;
  88591. else if(sample_rate_hint == 13)
  88592. decoder->private_->frame.header.sample_rate = x;
  88593. else
  88594. decoder->private_->frame.header.sample_rate = x*10;
  88595. }
  88596. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88597. return false; /* read_callback_ sets the state for us */
  88598. crc8 = (FLAC__byte)x;
  88599. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88600. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88601. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88602. return true;
  88603. }
  88604. decoder->private_->next_fixed_block_size = 0;
  88605. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88606. x = decoder->private_->frame.header.number.frame_number;
  88607. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88608. if(decoder->private_->fixed_block_size)
  88609. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88610. else if(decoder->private_->has_stream_info) {
  88611. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88612. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88613. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88614. }
  88615. else
  88616. is_unparseable = true;
  88617. }
  88618. else if(x == 0) {
  88619. decoder->private_->frame.header.number.sample_number = 0;
  88620. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88621. }
  88622. else {
  88623. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88624. }
  88625. }
  88626. if(is_unparseable) {
  88627. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88628. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88629. return true;
  88630. }
  88631. return true;
  88632. }
  88633. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88634. {
  88635. FLAC__uint32 x;
  88636. FLAC__bool wasted_bits;
  88637. unsigned i;
  88638. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88639. return false; /* read_callback_ sets the state for us */
  88640. wasted_bits = (x & 1);
  88641. x &= 0xfe;
  88642. if(wasted_bits) {
  88643. unsigned u;
  88644. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88645. return false; /* read_callback_ sets the state for us */
  88646. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88647. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88648. }
  88649. else
  88650. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88651. if(x & 0x80) {
  88652. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88653. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88654. return true;
  88655. }
  88656. else if(x == 0) {
  88657. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88658. return false;
  88659. }
  88660. else if(x == 2) {
  88661. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88662. return false;
  88663. }
  88664. else if(x < 16) {
  88665. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88666. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88667. return true;
  88668. }
  88669. else if(x <= 24) {
  88670. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88671. return false;
  88672. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88673. return true;
  88674. }
  88675. else if(x < 64) {
  88676. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88677. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88678. return true;
  88679. }
  88680. else {
  88681. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88682. return false;
  88683. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88684. return true;
  88685. }
  88686. if(wasted_bits && do_full_decode) {
  88687. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88688. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88689. decoder->private_->output[channel][i] <<= x;
  88690. }
  88691. return true;
  88692. }
  88693. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88694. {
  88695. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88696. FLAC__int32 x;
  88697. unsigned i;
  88698. FLAC__int32 *output = decoder->private_->output[channel];
  88699. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88700. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88701. return false; /* read_callback_ sets the state for us */
  88702. subframe->value = x;
  88703. if(do_full_decode) {
  88704. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88705. output[i] = x;
  88706. }
  88707. return true;
  88708. }
  88709. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88710. {
  88711. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88712. FLAC__int32 i32;
  88713. FLAC__uint32 u32;
  88714. unsigned u;
  88715. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88716. subframe->residual = decoder->private_->residual[channel];
  88717. subframe->order = order;
  88718. for(u = 0; u < order; u++) {
  88719. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88720. return false; /* read_callback_ sets the state for us */
  88721. subframe->warmup[u] = i32;
  88722. }
  88723. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88724. return false; /* read_callback_ sets the state for us */
  88725. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88726. switch(subframe->entropy_coding_method.type) {
  88727. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88728. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88729. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88730. return false; /* read_callback_ sets the state for us */
  88731. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88732. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88733. break;
  88734. default:
  88735. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88736. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88737. return true;
  88738. }
  88739. switch(subframe->entropy_coding_method.type) {
  88740. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88741. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88742. 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))
  88743. return false;
  88744. break;
  88745. default:
  88746. FLAC__ASSERT(0);
  88747. }
  88748. if(do_full_decode) {
  88749. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88750. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88751. }
  88752. return true;
  88753. }
  88754. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88755. {
  88756. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88757. FLAC__int32 i32;
  88758. FLAC__uint32 u32;
  88759. unsigned u;
  88760. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88761. subframe->residual = decoder->private_->residual[channel];
  88762. subframe->order = order;
  88763. for(u = 0; u < order; u++) {
  88764. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88765. return false; /* read_callback_ sets the state for us */
  88766. subframe->warmup[u] = i32;
  88767. }
  88768. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88769. return false; /* read_callback_ sets the state for us */
  88770. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88771. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88772. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88773. return true;
  88774. }
  88775. subframe->qlp_coeff_precision = u32+1;
  88776. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88777. return false; /* read_callback_ sets the state for us */
  88778. subframe->quantization_level = i32;
  88779. for(u = 0; u < order; u++) {
  88780. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88781. return false; /* read_callback_ sets the state for us */
  88782. subframe->qlp_coeff[u] = i32;
  88783. }
  88784. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88785. return false; /* read_callback_ sets the state for us */
  88786. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88787. switch(subframe->entropy_coding_method.type) {
  88788. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88789. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88790. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88791. return false; /* read_callback_ sets the state for us */
  88792. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88793. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88794. break;
  88795. default:
  88796. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88797. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88798. return true;
  88799. }
  88800. switch(subframe->entropy_coding_method.type) {
  88801. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88802. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88803. 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))
  88804. return false;
  88805. break;
  88806. default:
  88807. FLAC__ASSERT(0);
  88808. }
  88809. if(do_full_decode) {
  88810. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88811. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88812. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88813. if(order <= 8)
  88814. 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);
  88815. else
  88816. 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);
  88817. }
  88818. else
  88819. 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);
  88820. else
  88821. 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);
  88822. }
  88823. return true;
  88824. }
  88825. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88826. {
  88827. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88828. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88829. unsigned i;
  88830. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88831. subframe->data = residual;
  88832. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88833. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88834. return false; /* read_callback_ sets the state for us */
  88835. residual[i] = x;
  88836. }
  88837. if(do_full_decode)
  88838. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88839. return true;
  88840. }
  88841. 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)
  88842. {
  88843. FLAC__uint32 rice_parameter;
  88844. int i;
  88845. unsigned partition, sample, u;
  88846. const unsigned partitions = 1u << partition_order;
  88847. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88848. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88849. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88850. if(partition_order == 0) {
  88851. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88852. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88853. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88854. return true;
  88855. }
  88856. }
  88857. else {
  88858. if(partition_samples < predictor_order) {
  88859. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88860. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88861. return true;
  88862. }
  88863. }
  88864. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88865. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88866. return false;
  88867. }
  88868. sample = 0;
  88869. for(partition = 0; partition < partitions; partition++) {
  88870. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88871. return false; /* read_callback_ sets the state for us */
  88872. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88873. if(rice_parameter < pesc) {
  88874. partitioned_rice_contents->raw_bits[partition] = 0;
  88875. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88876. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88877. return false; /* read_callback_ sets the state for us */
  88878. sample += u;
  88879. }
  88880. else {
  88881. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88882. return false; /* read_callback_ sets the state for us */
  88883. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88884. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88885. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88886. return false; /* read_callback_ sets the state for us */
  88887. residual[sample] = i;
  88888. }
  88889. }
  88890. }
  88891. return true;
  88892. }
  88893. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88894. {
  88895. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88896. FLAC__uint32 zero = 0;
  88897. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88898. return false; /* read_callback_ sets the state for us */
  88899. if(zero != 0) {
  88900. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88901. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88902. }
  88903. }
  88904. return true;
  88905. }
  88906. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88907. {
  88908. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88909. if(
  88910. #if FLAC__HAS_OGG
  88911. !decoder->private_->is_ogg &&
  88912. #endif
  88913. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88914. ) {
  88915. *bytes = 0;
  88916. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88917. return false;
  88918. }
  88919. else if(*bytes > 0) {
  88920. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  88921. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88922. return false;
  88923. }
  88924. else {
  88925. const FLAC__StreamDecoderReadStatus status =
  88926. #if FLAC__HAS_OGG
  88927. decoder->private_->is_ogg?
  88928. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  88929. #endif
  88930. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  88931. ;
  88932. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  88933. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88934. return false;
  88935. }
  88936. else if(*bytes == 0) {
  88937. if(
  88938. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  88939. (
  88940. #if FLAC__HAS_OGG
  88941. !decoder->private_->is_ogg &&
  88942. #endif
  88943. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88944. )
  88945. ) {
  88946. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88947. return false;
  88948. }
  88949. else
  88950. return true;
  88951. }
  88952. else
  88953. return true;
  88954. }
  88955. }
  88956. else {
  88957. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88958. return false;
  88959. }
  88960. }
  88961. #if FLAC__HAS_OGG
  88962. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  88963. {
  88964. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  88965. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  88966. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88967. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  88968. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88969. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  88970. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  88971. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  88972. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  88973. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  88974. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  88975. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  88976. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88977. default:
  88978. FLAC__ASSERT(0);
  88979. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88980. }
  88981. }
  88982. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  88983. {
  88984. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  88985. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  88986. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  88987. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  88988. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  88989. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  88990. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  88991. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88992. default:
  88993. FLAC__ASSERT(0);
  88994. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88995. }
  88996. }
  88997. #endif
  88998. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  88999. {
  89000. if(decoder->private_->is_seeking) {
  89001. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89002. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89003. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89004. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89005. #if FLAC__HAS_OGG
  89006. decoder->private_->got_a_frame = true;
  89007. #endif
  89008. decoder->private_->last_frame = *frame; /* save the frame */
  89009. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89010. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89011. decoder->private_->is_seeking = false;
  89012. if(delta > 0) {
  89013. unsigned channel;
  89014. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89015. for(channel = 0; channel < frame->header.channels; channel++)
  89016. newbuffer[channel] = buffer[channel] + delta;
  89017. decoder->private_->last_frame.header.blocksize -= delta;
  89018. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89019. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89020. }
  89021. else {
  89022. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89023. }
  89024. }
  89025. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89026. }
  89027. if(!decoder->private_->has_stream_info)
  89028. decoder->private_->do_md5_checking = false;
  89029. if(decoder->private_->do_md5_checking) {
  89030. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89031. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89032. }
  89033. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89034. }
  89035. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89036. {
  89037. if(!decoder->private_->is_seeking)
  89038. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89039. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89040. decoder->private_->unparseable_frame_count++;
  89041. }
  89042. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89043. {
  89044. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89045. FLAC__int64 pos = -1;
  89046. int i;
  89047. unsigned approx_bytes_per_frame;
  89048. FLAC__bool first_seek = true;
  89049. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89050. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89051. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89052. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89053. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89054. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89055. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89056. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89057. if(channels == 0)
  89058. channels = decoder->private_->stream_info.data.stream_info.channels;
  89059. if(bps == 0)
  89060. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89061. if(max_framesize > 0)
  89062. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89063. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89064. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89065. }
  89066. else
  89067. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89068. lower_bound = first_frame_offset;
  89069. lower_bound_sample = 0;
  89070. upper_bound = stream_length;
  89071. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89072. if(seek_table) {
  89073. FLAC__uint64 new_lower_bound = lower_bound;
  89074. FLAC__uint64 new_upper_bound = upper_bound;
  89075. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89076. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89077. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89078. if(
  89079. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89080. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89081. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89082. seek_table->points[i].sample_number <= target_sample
  89083. )
  89084. break;
  89085. }
  89086. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89087. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89088. new_lower_bound_sample = seek_table->points[i].sample_number;
  89089. }
  89090. for(i = 0; i < (int)seek_table->num_points; i++) {
  89091. if(
  89092. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89093. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89094. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89095. seek_table->points[i].sample_number > target_sample
  89096. )
  89097. break;
  89098. }
  89099. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89100. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89101. new_upper_bound_sample = seek_table->points[i].sample_number;
  89102. }
  89103. if(new_upper_bound >= new_lower_bound) {
  89104. lower_bound = new_lower_bound;
  89105. upper_bound = new_upper_bound;
  89106. lower_bound_sample = new_lower_bound_sample;
  89107. upper_bound_sample = new_upper_bound_sample;
  89108. }
  89109. }
  89110. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89111. if(upper_bound_sample == lower_bound_sample)
  89112. upper_bound_sample++;
  89113. decoder->private_->target_sample = target_sample;
  89114. while(1) {
  89115. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89116. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89117. return false;
  89118. }
  89119. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89120. #if defined _MSC_VER || defined __MINGW32__
  89121. 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;
  89122. #else
  89123. 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;
  89124. #endif
  89125. #else
  89126. if(upper_bound - lower_bound < 0xffffffff)
  89127. 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;
  89128. else /* @@@ WATCHOUT, ~2TB limit */
  89129. 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;
  89130. #endif
  89131. if(pos >= (FLAC__int64)upper_bound)
  89132. pos = (FLAC__int64)upper_bound - 1;
  89133. if(pos < (FLAC__int64)lower_bound)
  89134. pos = (FLAC__int64)lower_bound;
  89135. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89136. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89137. return false;
  89138. }
  89139. if(!FLAC__stream_decoder_flush(decoder)) {
  89140. return false;
  89141. }
  89142. decoder->private_->unparseable_frame_count = 0;
  89143. if(!FLAC__stream_decoder_process_single(decoder)) {
  89144. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89145. return false;
  89146. }
  89147. #if 0
  89148. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89149. break;
  89150. #endif
  89151. if(!decoder->private_->is_seeking)
  89152. break;
  89153. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89154. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89155. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89156. if (pos == (FLAC__int64)lower_bound) {
  89157. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89158. return false;
  89159. }
  89160. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89161. continue;
  89162. }
  89163. first_seek = false;
  89164. if (this_frame_sample < lower_bound_sample) {
  89165. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89166. return false;
  89167. }
  89168. if(target_sample < this_frame_sample) {
  89169. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89170. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89171. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89172. return false;
  89173. }
  89174. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89175. }
  89176. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89177. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89178. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89179. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89180. return false;
  89181. }
  89182. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89183. }
  89184. }
  89185. return true;
  89186. }
  89187. #if FLAC__HAS_OGG
  89188. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89189. {
  89190. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89191. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89192. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89193. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89194. FLAC__bool did_a_seek;
  89195. unsigned iteration = 0;
  89196. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89197. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89198. if(right_sample == 0) {
  89199. right_sample = (FLAC__uint64)(-1);
  89200. BINARY_SEARCH_AFTER_ITERATION = 0;
  89201. }
  89202. decoder->private_->target_sample = target_sample;
  89203. for( ; ; iteration++) {
  89204. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89205. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89206. pos = (right_pos + left_pos) / 2;
  89207. }
  89208. else {
  89209. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89210. #if defined _MSC_VER || defined __MINGW32__
  89211. 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));
  89212. #else
  89213. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89214. #endif
  89215. #else
  89216. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89217. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89218. else /* @@@ WATCHOUT, ~2TB limit */
  89219. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89220. #endif
  89221. }
  89222. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89223. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89224. return false;
  89225. }
  89226. if(!FLAC__stream_decoder_flush(decoder)) {
  89227. return false;
  89228. }
  89229. did_a_seek = true;
  89230. }
  89231. else
  89232. did_a_seek = false;
  89233. decoder->private_->got_a_frame = false;
  89234. if(!FLAC__stream_decoder_process_single(decoder)) {
  89235. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89236. return false;
  89237. }
  89238. if(!decoder->private_->got_a_frame) {
  89239. if(did_a_seek) {
  89240. right_pos = pos;
  89241. BINARY_SEARCH_AFTER_ITERATION = 0;
  89242. }
  89243. else {
  89244. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89245. return false;
  89246. }
  89247. }
  89248. else if(!decoder->private_->is_seeking) {
  89249. break;
  89250. }
  89251. else {
  89252. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89253. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89254. if (did_a_seek) {
  89255. if (this_frame_sample <= target_sample) {
  89256. FLAC__ASSERT(this_frame_sample != target_sample);
  89257. left_sample = this_frame_sample;
  89258. if (left_pos == pos) {
  89259. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89260. return false;
  89261. }
  89262. left_pos = pos;
  89263. }
  89264. else if(this_frame_sample > target_sample) {
  89265. right_sample = this_frame_sample;
  89266. if (right_pos == pos) {
  89267. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89268. return false;
  89269. }
  89270. right_pos = pos;
  89271. }
  89272. }
  89273. }
  89274. }
  89275. return true;
  89276. }
  89277. #endif
  89278. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89279. {
  89280. (void)client_data;
  89281. if(*bytes > 0) {
  89282. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89283. if(ferror(decoder->private_->file))
  89284. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89285. else if(*bytes == 0)
  89286. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89287. else
  89288. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89289. }
  89290. else
  89291. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89292. }
  89293. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89294. {
  89295. (void)client_data;
  89296. if(decoder->private_->file == stdin)
  89297. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89298. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89299. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89300. else
  89301. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89302. }
  89303. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89304. {
  89305. off_t pos;
  89306. (void)client_data;
  89307. if(decoder->private_->file == stdin)
  89308. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89309. else if((pos = ftello(decoder->private_->file)) < 0)
  89310. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89311. else {
  89312. *absolute_byte_offset = (FLAC__uint64)pos;
  89313. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89314. }
  89315. }
  89316. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89317. {
  89318. struct stat filestats;
  89319. (void)client_data;
  89320. if(decoder->private_->file == stdin)
  89321. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89322. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89323. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89324. else {
  89325. *stream_length = (FLAC__uint64)filestats.st_size;
  89326. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89327. }
  89328. }
  89329. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89330. {
  89331. (void)client_data;
  89332. return feof(decoder->private_->file)? true : false;
  89333. }
  89334. #endif
  89335. /*** End of inlined file: stream_decoder.c ***/
  89336. /*** Start of inlined file: stream_encoder.c ***/
  89337. /*** Start of inlined file: juce_FlacHeader.h ***/
  89338. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89339. // tasks..
  89340. #define VERSION "1.2.1"
  89341. #define FLAC__NO_DLL 1
  89342. #if JUCE_MSVC
  89343. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89344. #endif
  89345. #if JUCE_MAC
  89346. #define FLAC__SYS_DARWIN 1
  89347. #endif
  89348. /*** End of inlined file: juce_FlacHeader.h ***/
  89349. #if JUCE_USE_FLAC
  89350. #if HAVE_CONFIG_H
  89351. # include <config.h>
  89352. #endif
  89353. #if defined _MSC_VER || defined __MINGW32__
  89354. #include <io.h> /* for _setmode() */
  89355. #include <fcntl.h> /* for _O_BINARY */
  89356. #endif
  89357. #if defined __CYGWIN__ || defined __EMX__
  89358. #include <io.h> /* for setmode(), O_BINARY */
  89359. #include <fcntl.h> /* for _O_BINARY */
  89360. #endif
  89361. #include <limits.h>
  89362. #include <stdio.h>
  89363. #include <stdlib.h> /* for malloc() */
  89364. #include <string.h> /* for memcpy() */
  89365. #include <sys/types.h> /* for off_t */
  89366. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89367. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89368. #define fseeko fseek
  89369. #define ftello ftell
  89370. #endif
  89371. #endif
  89372. /*** Start of inlined file: stream_encoder.h ***/
  89373. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89374. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89375. #if FLAC__HAS_OGG
  89376. #include "private/ogg_encoder_aspect.h"
  89377. #endif
  89378. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89379. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89380. typedef enum {
  89381. FLAC__APODIZATION_BARTLETT,
  89382. FLAC__APODIZATION_BARTLETT_HANN,
  89383. FLAC__APODIZATION_BLACKMAN,
  89384. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89385. FLAC__APODIZATION_CONNES,
  89386. FLAC__APODIZATION_FLATTOP,
  89387. FLAC__APODIZATION_GAUSS,
  89388. FLAC__APODIZATION_HAMMING,
  89389. FLAC__APODIZATION_HANN,
  89390. FLAC__APODIZATION_KAISER_BESSEL,
  89391. FLAC__APODIZATION_NUTTALL,
  89392. FLAC__APODIZATION_RECTANGLE,
  89393. FLAC__APODIZATION_TRIANGLE,
  89394. FLAC__APODIZATION_TUKEY,
  89395. FLAC__APODIZATION_WELCH
  89396. } FLAC__ApodizationFunction;
  89397. typedef struct {
  89398. FLAC__ApodizationFunction type;
  89399. union {
  89400. struct {
  89401. FLAC__real stddev;
  89402. } gauss;
  89403. struct {
  89404. FLAC__real p;
  89405. } tukey;
  89406. } parameters;
  89407. } FLAC__ApodizationSpecification;
  89408. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89409. typedef struct FLAC__StreamEncoderProtected {
  89410. FLAC__StreamEncoderState state;
  89411. FLAC__bool verify;
  89412. FLAC__bool streamable_subset;
  89413. FLAC__bool do_md5;
  89414. FLAC__bool do_mid_side_stereo;
  89415. FLAC__bool loose_mid_side_stereo;
  89416. unsigned channels;
  89417. unsigned bits_per_sample;
  89418. unsigned sample_rate;
  89419. unsigned blocksize;
  89420. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89421. unsigned num_apodizations;
  89422. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89423. #endif
  89424. unsigned max_lpc_order;
  89425. unsigned qlp_coeff_precision;
  89426. FLAC__bool do_qlp_coeff_prec_search;
  89427. FLAC__bool do_exhaustive_model_search;
  89428. FLAC__bool do_escape_coding;
  89429. unsigned min_residual_partition_order;
  89430. unsigned max_residual_partition_order;
  89431. unsigned rice_parameter_search_dist;
  89432. FLAC__uint64 total_samples_estimate;
  89433. FLAC__StreamMetadata **metadata;
  89434. unsigned num_metadata_blocks;
  89435. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89436. #if FLAC__HAS_OGG
  89437. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89438. #endif
  89439. } FLAC__StreamEncoderProtected;
  89440. #endif
  89441. /*** End of inlined file: stream_encoder.h ***/
  89442. #if FLAC__HAS_OGG
  89443. #include "include/private/ogg_helper.h"
  89444. #include "include/private/ogg_mapping.h"
  89445. #endif
  89446. /*** Start of inlined file: stream_encoder_framing.h ***/
  89447. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89448. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89449. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89450. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89451. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89452. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89453. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89454. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89455. #endif
  89456. /*** End of inlined file: stream_encoder_framing.h ***/
  89457. /*** Start of inlined file: window.h ***/
  89458. #ifndef FLAC__PRIVATE__WINDOW_H
  89459. #define FLAC__PRIVATE__WINDOW_H
  89460. #ifdef HAVE_CONFIG_H
  89461. #include <config.h>
  89462. #endif
  89463. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89464. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89465. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89466. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89467. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89468. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89469. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89470. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89471. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89472. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89473. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89474. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89475. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89476. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89477. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89478. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89479. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89480. #endif
  89481. /*** End of inlined file: window.h ***/
  89482. #ifndef FLaC__INLINE
  89483. #define FLaC__INLINE
  89484. #endif
  89485. #ifdef min
  89486. #undef min
  89487. #endif
  89488. #define min(x,y) ((x)<(y)?(x):(y))
  89489. #ifdef max
  89490. #undef max
  89491. #endif
  89492. #define max(x,y) ((x)>(y)?(x):(y))
  89493. #undef EXACT_RICE_BITS_CALCULATION
  89494. #undef ENABLE_RICE_PARAMETER_SEARCH
  89495. typedef struct {
  89496. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89497. unsigned size; /* of each data[] in samples */
  89498. unsigned tail;
  89499. } verify_input_fifo;
  89500. typedef struct {
  89501. const FLAC__byte *data;
  89502. unsigned capacity;
  89503. unsigned bytes;
  89504. } verify_output;
  89505. typedef enum {
  89506. ENCODER_IN_MAGIC = 0,
  89507. ENCODER_IN_METADATA = 1,
  89508. ENCODER_IN_AUDIO = 2
  89509. } EncoderStateHint;
  89510. static struct CompressionLevels {
  89511. FLAC__bool do_mid_side_stereo;
  89512. FLAC__bool loose_mid_side_stereo;
  89513. unsigned max_lpc_order;
  89514. unsigned qlp_coeff_precision;
  89515. FLAC__bool do_qlp_coeff_prec_search;
  89516. FLAC__bool do_escape_coding;
  89517. FLAC__bool do_exhaustive_model_search;
  89518. unsigned min_residual_partition_order;
  89519. unsigned max_residual_partition_order;
  89520. unsigned rice_parameter_search_dist;
  89521. } compression_levels_[] = {
  89522. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89523. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89524. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89525. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89526. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89527. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89528. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89529. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89530. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89531. };
  89532. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89533. static void free_(FLAC__StreamEncoder *encoder);
  89534. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89535. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89536. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89537. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89538. #if FLAC__HAS_OGG
  89539. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89540. #endif
  89541. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89542. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89543. static FLAC__bool process_subframe_(
  89544. FLAC__StreamEncoder *encoder,
  89545. unsigned min_partition_order,
  89546. unsigned max_partition_order,
  89547. const FLAC__FrameHeader *frame_header,
  89548. unsigned subframe_bps,
  89549. const FLAC__int32 integer_signal[],
  89550. FLAC__Subframe *subframe[2],
  89551. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89552. FLAC__int32 *residual[2],
  89553. unsigned *best_subframe,
  89554. unsigned *best_bits
  89555. );
  89556. static FLAC__bool add_subframe_(
  89557. FLAC__StreamEncoder *encoder,
  89558. unsigned blocksize,
  89559. unsigned subframe_bps,
  89560. const FLAC__Subframe *subframe,
  89561. FLAC__BitWriter *frame
  89562. );
  89563. static unsigned evaluate_constant_subframe_(
  89564. FLAC__StreamEncoder *encoder,
  89565. const FLAC__int32 signal,
  89566. unsigned blocksize,
  89567. unsigned subframe_bps,
  89568. FLAC__Subframe *subframe
  89569. );
  89570. static unsigned evaluate_fixed_subframe_(
  89571. FLAC__StreamEncoder *encoder,
  89572. const FLAC__int32 signal[],
  89573. FLAC__int32 residual[],
  89574. FLAC__uint64 abs_residual_partition_sums[],
  89575. unsigned raw_bits_per_partition[],
  89576. unsigned blocksize,
  89577. unsigned subframe_bps,
  89578. unsigned order,
  89579. unsigned rice_parameter,
  89580. unsigned rice_parameter_limit,
  89581. unsigned min_partition_order,
  89582. unsigned max_partition_order,
  89583. FLAC__bool do_escape_coding,
  89584. unsigned rice_parameter_search_dist,
  89585. FLAC__Subframe *subframe,
  89586. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89587. );
  89588. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89589. static unsigned evaluate_lpc_subframe_(
  89590. FLAC__StreamEncoder *encoder,
  89591. const FLAC__int32 signal[],
  89592. FLAC__int32 residual[],
  89593. FLAC__uint64 abs_residual_partition_sums[],
  89594. unsigned raw_bits_per_partition[],
  89595. const FLAC__real lp_coeff[],
  89596. unsigned blocksize,
  89597. unsigned subframe_bps,
  89598. unsigned order,
  89599. unsigned qlp_coeff_precision,
  89600. unsigned rice_parameter,
  89601. unsigned rice_parameter_limit,
  89602. unsigned min_partition_order,
  89603. unsigned max_partition_order,
  89604. FLAC__bool do_escape_coding,
  89605. unsigned rice_parameter_search_dist,
  89606. FLAC__Subframe *subframe,
  89607. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89608. );
  89609. #endif
  89610. static unsigned evaluate_verbatim_subframe_(
  89611. FLAC__StreamEncoder *encoder,
  89612. const FLAC__int32 signal[],
  89613. unsigned blocksize,
  89614. unsigned subframe_bps,
  89615. FLAC__Subframe *subframe
  89616. );
  89617. static unsigned find_best_partition_order_(
  89618. struct FLAC__StreamEncoderPrivate *private_,
  89619. const FLAC__int32 residual[],
  89620. FLAC__uint64 abs_residual_partition_sums[],
  89621. unsigned raw_bits_per_partition[],
  89622. unsigned residual_samples,
  89623. unsigned predictor_order,
  89624. unsigned rice_parameter,
  89625. unsigned rice_parameter_limit,
  89626. unsigned min_partition_order,
  89627. unsigned max_partition_order,
  89628. unsigned bps,
  89629. FLAC__bool do_escape_coding,
  89630. unsigned rice_parameter_search_dist,
  89631. FLAC__EntropyCodingMethod *best_ecm
  89632. );
  89633. static void precompute_partition_info_sums_(
  89634. const FLAC__int32 residual[],
  89635. FLAC__uint64 abs_residual_partition_sums[],
  89636. unsigned residual_samples,
  89637. unsigned predictor_order,
  89638. unsigned min_partition_order,
  89639. unsigned max_partition_order,
  89640. unsigned bps
  89641. );
  89642. static void precompute_partition_info_escapes_(
  89643. const FLAC__int32 residual[],
  89644. unsigned raw_bits_per_partition[],
  89645. unsigned residual_samples,
  89646. unsigned predictor_order,
  89647. unsigned min_partition_order,
  89648. unsigned max_partition_order
  89649. );
  89650. static FLAC__bool set_partitioned_rice_(
  89651. #ifdef EXACT_RICE_BITS_CALCULATION
  89652. const FLAC__int32 residual[],
  89653. #endif
  89654. const FLAC__uint64 abs_residual_partition_sums[],
  89655. const unsigned raw_bits_per_partition[],
  89656. const unsigned residual_samples,
  89657. const unsigned predictor_order,
  89658. const unsigned suggested_rice_parameter,
  89659. const unsigned rice_parameter_limit,
  89660. const unsigned rice_parameter_search_dist,
  89661. const unsigned partition_order,
  89662. const FLAC__bool search_for_escapes,
  89663. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89664. unsigned *bits
  89665. );
  89666. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89667. static void append_to_verify_fifo_(
  89668. verify_input_fifo *fifo,
  89669. const FLAC__int32 * const input[],
  89670. unsigned input_offset,
  89671. unsigned channels,
  89672. unsigned wide_samples
  89673. );
  89674. static void append_to_verify_fifo_interleaved_(
  89675. verify_input_fifo *fifo,
  89676. const FLAC__int32 input[],
  89677. unsigned input_offset,
  89678. unsigned channels,
  89679. unsigned wide_samples
  89680. );
  89681. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89682. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89683. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89684. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89685. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89686. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89687. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89688. 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);
  89689. static FILE *get_binary_stdout_(void);
  89690. typedef struct FLAC__StreamEncoderPrivate {
  89691. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89692. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89693. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89694. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89695. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89696. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89697. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89698. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89699. #endif
  89700. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89701. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89702. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89703. FLAC__int32 *residual_workspace_mid_side[2][2];
  89704. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89705. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89706. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89707. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89708. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89709. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89710. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89711. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89712. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89713. unsigned best_subframe_mid_side[2];
  89714. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89715. unsigned best_subframe_bits_mid_side[2];
  89716. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89717. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89718. FLAC__BitWriter *frame; /* the current frame being worked on */
  89719. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89720. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89721. FLAC__ChannelAssignment last_channel_assignment;
  89722. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89723. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89724. unsigned current_sample_number;
  89725. unsigned current_frame_number;
  89726. FLAC__MD5Context md5context;
  89727. FLAC__CPUInfo cpuinfo;
  89728. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89729. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89730. #else
  89731. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89732. #endif
  89733. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89734. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89735. 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[]);
  89736. 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[]);
  89737. 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[]);
  89738. #endif
  89739. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89740. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89741. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89742. FLAC__bool disable_constant_subframes;
  89743. FLAC__bool disable_fixed_subframes;
  89744. FLAC__bool disable_verbatim_subframes;
  89745. #if FLAC__HAS_OGG
  89746. FLAC__bool is_ogg;
  89747. #endif
  89748. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89749. FLAC__StreamEncoderSeekCallback seek_callback;
  89750. FLAC__StreamEncoderTellCallback tell_callback;
  89751. FLAC__StreamEncoderWriteCallback write_callback;
  89752. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89753. FLAC__StreamEncoderProgressCallback progress_callback;
  89754. void *client_data;
  89755. unsigned first_seekpoint_to_check;
  89756. FILE *file; /* only used when encoding to a file */
  89757. FLAC__uint64 bytes_written;
  89758. FLAC__uint64 samples_written;
  89759. unsigned frames_written;
  89760. unsigned total_frames_estimate;
  89761. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89762. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89763. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89764. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89765. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89766. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89767. FLAC__real *windowed_signal_unaligned;
  89768. #endif
  89769. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89770. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89771. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89772. unsigned *raw_bits_per_partition_unaligned;
  89773. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89774. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89775. #endif
  89776. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89777. struct {
  89778. FLAC__StreamDecoder *decoder;
  89779. EncoderStateHint state_hint;
  89780. FLAC__bool needs_magic_hack;
  89781. verify_input_fifo input_fifo;
  89782. verify_output output;
  89783. struct {
  89784. FLAC__uint64 absolute_sample;
  89785. unsigned frame_number;
  89786. unsigned channel;
  89787. unsigned sample;
  89788. FLAC__int32 expected;
  89789. FLAC__int32 got;
  89790. } error_stats;
  89791. } verify;
  89792. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89793. } FLAC__StreamEncoderPrivate;
  89794. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89795. "FLAC__STREAM_ENCODER_OK",
  89796. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89797. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89798. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89799. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89800. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89801. "FLAC__STREAM_ENCODER_IO_ERROR",
  89802. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89803. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89804. };
  89805. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89806. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89807. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89808. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89809. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89810. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89811. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89812. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89813. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89814. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89815. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89816. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89817. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89818. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89819. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89820. };
  89821. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89822. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89823. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89824. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89825. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89826. };
  89827. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89828. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89829. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89830. };
  89831. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89832. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89833. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89834. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89835. };
  89836. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89837. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89838. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89839. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89840. };
  89841. static const unsigned OVERREAD_ = 1;
  89842. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89843. {
  89844. FLAC__StreamEncoder *encoder;
  89845. unsigned i;
  89846. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89847. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89848. if(encoder == 0) {
  89849. return 0;
  89850. }
  89851. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89852. if(encoder->protected_ == 0) {
  89853. free(encoder);
  89854. return 0;
  89855. }
  89856. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89857. if(encoder->private_ == 0) {
  89858. free(encoder->protected_);
  89859. free(encoder);
  89860. return 0;
  89861. }
  89862. encoder->private_->frame = FLAC__bitwriter_new();
  89863. if(encoder->private_->frame == 0) {
  89864. free(encoder->private_);
  89865. free(encoder->protected_);
  89866. free(encoder);
  89867. return 0;
  89868. }
  89869. encoder->private_->file = 0;
  89870. set_defaults_enc(encoder);
  89871. encoder->private_->is_being_deleted = false;
  89872. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89873. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89874. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89875. }
  89876. for(i = 0; i < 2; i++) {
  89877. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89878. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89879. }
  89880. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89881. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89882. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89883. }
  89884. for(i = 0; i < 2; i++) {
  89885. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89886. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89887. }
  89888. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89889. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89890. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89891. }
  89892. for(i = 0; i < 2; i++) {
  89893. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89894. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89895. }
  89896. for(i = 0; i < 2; i++)
  89897. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89898. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89899. return encoder;
  89900. }
  89901. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89902. {
  89903. unsigned i;
  89904. FLAC__ASSERT(0 != encoder);
  89905. FLAC__ASSERT(0 != encoder->protected_);
  89906. FLAC__ASSERT(0 != encoder->private_);
  89907. FLAC__ASSERT(0 != encoder->private_->frame);
  89908. encoder->private_->is_being_deleted = true;
  89909. (void)FLAC__stream_encoder_finish(encoder);
  89910. if(0 != encoder->private_->verify.decoder)
  89911. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89912. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89913. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89914. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89915. }
  89916. for(i = 0; i < 2; i++) {
  89917. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89918. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89919. }
  89920. for(i = 0; i < 2; i++)
  89921. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  89922. FLAC__bitwriter_delete(encoder->private_->frame);
  89923. free(encoder->private_);
  89924. free(encoder->protected_);
  89925. free(encoder);
  89926. }
  89927. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  89928. FLAC__StreamEncoder *encoder,
  89929. FLAC__StreamEncoderReadCallback read_callback,
  89930. FLAC__StreamEncoderWriteCallback write_callback,
  89931. FLAC__StreamEncoderSeekCallback seek_callback,
  89932. FLAC__StreamEncoderTellCallback tell_callback,
  89933. FLAC__StreamEncoderMetadataCallback metadata_callback,
  89934. void *client_data,
  89935. FLAC__bool is_ogg
  89936. )
  89937. {
  89938. unsigned i;
  89939. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  89940. FLAC__ASSERT(0 != encoder);
  89941. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  89942. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  89943. #if !FLAC__HAS_OGG
  89944. if(is_ogg)
  89945. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  89946. #endif
  89947. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  89948. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  89949. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  89950. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  89951. if(encoder->protected_->channels != 2) {
  89952. encoder->protected_->do_mid_side_stereo = false;
  89953. encoder->protected_->loose_mid_side_stereo = false;
  89954. }
  89955. else if(!encoder->protected_->do_mid_side_stereo)
  89956. encoder->protected_->loose_mid_side_stereo = false;
  89957. if(encoder->protected_->bits_per_sample >= 32)
  89958. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  89959. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  89960. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  89961. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  89962. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  89963. if(encoder->protected_->blocksize == 0) {
  89964. if(encoder->protected_->max_lpc_order == 0)
  89965. encoder->protected_->blocksize = 1152;
  89966. else
  89967. encoder->protected_->blocksize = 4096;
  89968. }
  89969. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  89970. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  89971. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  89972. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  89973. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  89974. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  89975. if(encoder->protected_->qlp_coeff_precision == 0) {
  89976. if(encoder->protected_->bits_per_sample < 16) {
  89977. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  89978. }
  89979. else if(encoder->protected_->bits_per_sample == 16) {
  89980. if(encoder->protected_->blocksize <= 192)
  89981. encoder->protected_->qlp_coeff_precision = 7;
  89982. else if(encoder->protected_->blocksize <= 384)
  89983. encoder->protected_->qlp_coeff_precision = 8;
  89984. else if(encoder->protected_->blocksize <= 576)
  89985. encoder->protected_->qlp_coeff_precision = 9;
  89986. else if(encoder->protected_->blocksize <= 1152)
  89987. encoder->protected_->qlp_coeff_precision = 10;
  89988. else if(encoder->protected_->blocksize <= 2304)
  89989. encoder->protected_->qlp_coeff_precision = 11;
  89990. else if(encoder->protected_->blocksize <= 4608)
  89991. encoder->protected_->qlp_coeff_precision = 12;
  89992. else
  89993. encoder->protected_->qlp_coeff_precision = 13;
  89994. }
  89995. else {
  89996. if(encoder->protected_->blocksize <= 384)
  89997. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  89998. else if(encoder->protected_->blocksize <= 1152)
  89999. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90000. else
  90001. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90002. }
  90003. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90004. }
  90005. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90006. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90007. if(encoder->protected_->streamable_subset) {
  90008. if(
  90009. encoder->protected_->blocksize != 192 &&
  90010. encoder->protected_->blocksize != 576 &&
  90011. encoder->protected_->blocksize != 1152 &&
  90012. encoder->protected_->blocksize != 2304 &&
  90013. encoder->protected_->blocksize != 4608 &&
  90014. encoder->protected_->blocksize != 256 &&
  90015. encoder->protected_->blocksize != 512 &&
  90016. encoder->protected_->blocksize != 1024 &&
  90017. encoder->protected_->blocksize != 2048 &&
  90018. encoder->protected_->blocksize != 4096 &&
  90019. encoder->protected_->blocksize != 8192 &&
  90020. encoder->protected_->blocksize != 16384
  90021. )
  90022. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90023. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90024. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90025. if(
  90026. encoder->protected_->bits_per_sample != 8 &&
  90027. encoder->protected_->bits_per_sample != 12 &&
  90028. encoder->protected_->bits_per_sample != 16 &&
  90029. encoder->protected_->bits_per_sample != 20 &&
  90030. encoder->protected_->bits_per_sample != 24
  90031. )
  90032. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90033. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90034. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90035. if(
  90036. encoder->protected_->sample_rate <= 48000 &&
  90037. (
  90038. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90039. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90040. )
  90041. ) {
  90042. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90043. }
  90044. }
  90045. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90046. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90047. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90048. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90049. #if FLAC__HAS_OGG
  90050. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90051. unsigned i;
  90052. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90053. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90054. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90055. for( ; i > 0; i--)
  90056. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90057. encoder->protected_->metadata[0] = vc;
  90058. break;
  90059. }
  90060. }
  90061. }
  90062. #endif
  90063. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90064. unsigned i;
  90065. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90066. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90067. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90068. break; /* take only the first one */
  90069. }
  90070. }
  90071. }
  90072. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90073. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90074. metadata_has_seektable = false;
  90075. metadata_has_vorbis_comment = false;
  90076. metadata_picture_has_type1 = false;
  90077. metadata_picture_has_type2 = false;
  90078. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90079. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90080. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90081. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90082. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90083. if(metadata_has_seektable) /* only one is allowed */
  90084. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90085. metadata_has_seektable = true;
  90086. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90087. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90088. }
  90089. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90090. if(metadata_has_vorbis_comment) /* only one is allowed */
  90091. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90092. metadata_has_vorbis_comment = true;
  90093. }
  90094. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90095. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90096. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90097. }
  90098. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90099. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90100. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90101. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90102. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90103. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90104. metadata_picture_has_type1 = true;
  90105. if(
  90106. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90107. (
  90108. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90109. m->data.picture.width != 32 ||
  90110. m->data.picture.height != 32
  90111. )
  90112. )
  90113. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90114. }
  90115. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90116. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90117. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90118. metadata_picture_has_type2 = true;
  90119. }
  90120. }
  90121. }
  90122. encoder->private_->input_capacity = 0;
  90123. for(i = 0; i < encoder->protected_->channels; i++) {
  90124. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90125. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90126. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90127. #endif
  90128. }
  90129. for(i = 0; i < 2; i++) {
  90130. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90131. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90132. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90133. #endif
  90134. }
  90135. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90136. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90137. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90138. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90139. #endif
  90140. for(i = 0; i < encoder->protected_->channels; i++) {
  90141. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90142. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90143. encoder->private_->best_subframe[i] = 0;
  90144. }
  90145. for(i = 0; i < 2; i++) {
  90146. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90147. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90148. encoder->private_->best_subframe_mid_side[i] = 0;
  90149. }
  90150. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90151. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90152. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90153. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90154. #else
  90155. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90156. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90157. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90158. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90159. 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);
  90160. #endif
  90161. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90162. encoder->private_->loose_mid_side_stereo_frames = 1;
  90163. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90164. encoder->private_->current_sample_number = 0;
  90165. encoder->private_->current_frame_number = 0;
  90166. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90167. 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? */
  90168. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90169. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90170. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90171. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90172. #endif
  90173. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90174. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90175. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90176. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90177. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90178. #endif
  90179. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90180. # ifndef FLAC__NO_ASM
  90181. if(encoder->private_->cpuinfo.use_asm) {
  90182. # ifdef FLAC__CPU_IA32
  90183. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90184. # ifdef FLAC__HAS_NASM
  90185. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90186. if(encoder->protected_->max_lpc_order < 4)
  90187. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90188. else if(encoder->protected_->max_lpc_order < 8)
  90189. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90190. else if(encoder->protected_->max_lpc_order < 12)
  90191. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90192. else
  90193. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90194. }
  90195. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90196. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90197. else
  90198. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90199. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90200. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90201. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90202. }
  90203. else {
  90204. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90205. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90206. }
  90207. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90208. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90209. # endif /* FLAC__HAS_NASM */
  90210. # endif /* FLAC__CPU_IA32 */
  90211. }
  90212. # endif /* !FLAC__NO_ASM */
  90213. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90214. if(encoder->private_->use_wide_by_block) {
  90215. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90216. }
  90217. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90218. #if FLAC__HAS_OGG
  90219. encoder->private_->is_ogg = is_ogg;
  90220. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90221. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90222. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90223. }
  90224. #endif
  90225. encoder->private_->read_callback = read_callback;
  90226. encoder->private_->write_callback = write_callback;
  90227. encoder->private_->seek_callback = seek_callback;
  90228. encoder->private_->tell_callback = tell_callback;
  90229. encoder->private_->metadata_callback = metadata_callback;
  90230. encoder->private_->client_data = client_data;
  90231. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90232. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90233. }
  90234. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90235. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90236. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90237. }
  90238. if(encoder->protected_->verify) {
  90239. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90240. for(i = 0; i < encoder->protected_->channels; i++) {
  90241. 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))) {
  90242. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90243. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90244. }
  90245. }
  90246. encoder->private_->verify.input_fifo.tail = 0;
  90247. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90248. if(0 == encoder->private_->verify.decoder) {
  90249. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90250. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90251. }
  90252. 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) {
  90253. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90254. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90255. }
  90256. }
  90257. encoder->private_->verify.error_stats.absolute_sample = 0;
  90258. encoder->private_->verify.error_stats.frame_number = 0;
  90259. encoder->private_->verify.error_stats.channel = 0;
  90260. encoder->private_->verify.error_stats.sample = 0;
  90261. encoder->private_->verify.error_stats.expected = 0;
  90262. encoder->private_->verify.error_stats.got = 0;
  90263. encoder->private_->first_seekpoint_to_check = 0;
  90264. encoder->private_->samples_written = 0;
  90265. encoder->protected_->streaminfo_offset = 0;
  90266. encoder->protected_->seektable_offset = 0;
  90267. encoder->protected_->audio_offset = 0;
  90268. if(encoder->protected_->verify)
  90269. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90270. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90271. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90272. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90273. }
  90274. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90275. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90276. }
  90277. if(encoder->protected_->verify)
  90278. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90279. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90280. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90281. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90282. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90283. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90284. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90285. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90286. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90287. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90288. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90289. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90290. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90291. if(encoder->protected_->do_md5)
  90292. FLAC__MD5Init(&encoder->private_->md5context);
  90293. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90294. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90295. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90296. }
  90297. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90298. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90299. }
  90300. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90301. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90302. if(!metadata_has_vorbis_comment) {
  90303. FLAC__StreamMetadata vorbis_comment;
  90304. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90305. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90306. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90307. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90308. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90309. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90310. vorbis_comment.data.vorbis_comment.comments = 0;
  90311. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90312. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90313. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90314. }
  90315. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90316. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90317. }
  90318. }
  90319. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90320. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90321. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90322. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90323. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90324. }
  90325. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90326. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90327. }
  90328. }
  90329. 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 */
  90330. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90331. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90332. }
  90333. if(encoder->protected_->verify)
  90334. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90335. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90336. }
  90337. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90338. FLAC__StreamEncoder *encoder,
  90339. FLAC__StreamEncoderWriteCallback write_callback,
  90340. FLAC__StreamEncoderSeekCallback seek_callback,
  90341. FLAC__StreamEncoderTellCallback tell_callback,
  90342. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90343. void *client_data
  90344. )
  90345. {
  90346. return init_stream_internal_enc(
  90347. encoder,
  90348. 0,
  90349. write_callback,
  90350. seek_callback,
  90351. tell_callback,
  90352. metadata_callback,
  90353. client_data,
  90354. false
  90355. );
  90356. }
  90357. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90358. FLAC__StreamEncoder *encoder,
  90359. FLAC__StreamEncoderReadCallback read_callback,
  90360. FLAC__StreamEncoderWriteCallback write_callback,
  90361. FLAC__StreamEncoderSeekCallback seek_callback,
  90362. FLAC__StreamEncoderTellCallback tell_callback,
  90363. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90364. void *client_data
  90365. )
  90366. {
  90367. return init_stream_internal_enc(
  90368. encoder,
  90369. read_callback,
  90370. write_callback,
  90371. seek_callback,
  90372. tell_callback,
  90373. metadata_callback,
  90374. client_data,
  90375. true
  90376. );
  90377. }
  90378. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90379. FLAC__StreamEncoder *encoder,
  90380. FILE *file,
  90381. FLAC__StreamEncoderProgressCallback progress_callback,
  90382. void *client_data,
  90383. FLAC__bool is_ogg
  90384. )
  90385. {
  90386. FLAC__StreamEncoderInitStatus init_status;
  90387. FLAC__ASSERT(0 != encoder);
  90388. FLAC__ASSERT(0 != file);
  90389. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90390. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90391. if(file == 0) {
  90392. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90393. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90394. }
  90395. if(file == stdout)
  90396. file = get_binary_stdout_(); /* just to be safe */
  90397. encoder->private_->file = file;
  90398. encoder->private_->progress_callback = progress_callback;
  90399. encoder->private_->bytes_written = 0;
  90400. encoder->private_->samples_written = 0;
  90401. encoder->private_->frames_written = 0;
  90402. init_status = init_stream_internal_enc(
  90403. encoder,
  90404. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90405. file_write_callback_,
  90406. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90407. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90408. 0,
  90409. client_data,
  90410. is_ogg
  90411. );
  90412. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90413. return init_status;
  90414. }
  90415. {
  90416. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90417. FLAC__ASSERT(blocksize != 0);
  90418. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90419. }
  90420. return init_status;
  90421. }
  90422. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90423. FLAC__StreamEncoder *encoder,
  90424. FILE *file,
  90425. FLAC__StreamEncoderProgressCallback progress_callback,
  90426. void *client_data
  90427. )
  90428. {
  90429. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90430. }
  90431. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90432. FLAC__StreamEncoder *encoder,
  90433. FILE *file,
  90434. FLAC__StreamEncoderProgressCallback progress_callback,
  90435. void *client_data
  90436. )
  90437. {
  90438. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90439. }
  90440. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90441. FLAC__StreamEncoder *encoder,
  90442. const char *filename,
  90443. FLAC__StreamEncoderProgressCallback progress_callback,
  90444. void *client_data,
  90445. FLAC__bool is_ogg
  90446. )
  90447. {
  90448. FILE *file;
  90449. FLAC__ASSERT(0 != encoder);
  90450. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90451. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90452. file = filename? fopen(filename, "w+b") : stdout;
  90453. if(file == 0) {
  90454. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90455. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90456. }
  90457. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90458. }
  90459. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90460. FLAC__StreamEncoder *encoder,
  90461. const char *filename,
  90462. FLAC__StreamEncoderProgressCallback progress_callback,
  90463. void *client_data
  90464. )
  90465. {
  90466. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90467. }
  90468. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90469. FLAC__StreamEncoder *encoder,
  90470. const char *filename,
  90471. FLAC__StreamEncoderProgressCallback progress_callback,
  90472. void *client_data
  90473. )
  90474. {
  90475. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90476. }
  90477. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90478. {
  90479. FLAC__bool error = false;
  90480. FLAC__ASSERT(0 != encoder);
  90481. FLAC__ASSERT(0 != encoder->private_);
  90482. FLAC__ASSERT(0 != encoder->protected_);
  90483. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90484. return true;
  90485. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90486. if(encoder->private_->current_sample_number != 0) {
  90487. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90488. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90489. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90490. error = true;
  90491. }
  90492. }
  90493. if(encoder->protected_->do_md5)
  90494. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90495. if(!encoder->private_->is_being_deleted) {
  90496. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90497. if(encoder->private_->seek_callback) {
  90498. #if FLAC__HAS_OGG
  90499. if(encoder->private_->is_ogg)
  90500. update_ogg_metadata_(encoder);
  90501. else
  90502. #endif
  90503. update_metadata_(encoder);
  90504. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90505. error = true;
  90506. }
  90507. if(encoder->private_->metadata_callback)
  90508. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90509. }
  90510. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90511. if(!error)
  90512. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90513. error = true;
  90514. }
  90515. }
  90516. if(0 != encoder->private_->file) {
  90517. if(encoder->private_->file != stdout)
  90518. fclose(encoder->private_->file);
  90519. encoder->private_->file = 0;
  90520. }
  90521. #if FLAC__HAS_OGG
  90522. if(encoder->private_->is_ogg)
  90523. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90524. #endif
  90525. free_(encoder);
  90526. set_defaults_enc(encoder);
  90527. if(!error)
  90528. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90529. return !error;
  90530. }
  90531. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90532. {
  90533. FLAC__ASSERT(0 != encoder);
  90534. FLAC__ASSERT(0 != encoder->private_);
  90535. FLAC__ASSERT(0 != encoder->protected_);
  90536. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90537. return false;
  90538. #if FLAC__HAS_OGG
  90539. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90540. return true;
  90541. #else
  90542. (void)value;
  90543. return false;
  90544. #endif
  90545. }
  90546. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90547. {
  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 false;
  90553. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90554. encoder->protected_->verify = value;
  90555. #endif
  90556. return true;
  90557. }
  90558. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90559. {
  90560. FLAC__ASSERT(0 != encoder);
  90561. FLAC__ASSERT(0 != encoder->private_);
  90562. FLAC__ASSERT(0 != encoder->protected_);
  90563. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90564. return false;
  90565. encoder->protected_->streamable_subset = value;
  90566. return true;
  90567. }
  90568. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90569. {
  90570. FLAC__ASSERT(0 != encoder);
  90571. FLAC__ASSERT(0 != encoder->private_);
  90572. FLAC__ASSERT(0 != encoder->protected_);
  90573. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90574. return false;
  90575. encoder->protected_->do_md5 = value;
  90576. return true;
  90577. }
  90578. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90579. {
  90580. FLAC__ASSERT(0 != encoder);
  90581. FLAC__ASSERT(0 != encoder->private_);
  90582. FLAC__ASSERT(0 != encoder->protected_);
  90583. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90584. return false;
  90585. encoder->protected_->channels = value;
  90586. return true;
  90587. }
  90588. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90589. {
  90590. FLAC__ASSERT(0 != encoder);
  90591. FLAC__ASSERT(0 != encoder->private_);
  90592. FLAC__ASSERT(0 != encoder->protected_);
  90593. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90594. return false;
  90595. encoder->protected_->bits_per_sample = value;
  90596. return true;
  90597. }
  90598. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90599. {
  90600. FLAC__ASSERT(0 != encoder);
  90601. FLAC__ASSERT(0 != encoder->private_);
  90602. FLAC__ASSERT(0 != encoder->protected_);
  90603. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90604. return false;
  90605. encoder->protected_->sample_rate = value;
  90606. return true;
  90607. }
  90608. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90609. {
  90610. FLAC__bool ok = true;
  90611. FLAC__ASSERT(0 != encoder);
  90612. FLAC__ASSERT(0 != encoder->private_);
  90613. FLAC__ASSERT(0 != encoder->protected_);
  90614. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90615. return false;
  90616. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90617. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90618. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90619. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90620. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90621. #if 0
  90622. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90623. #else
  90624. encoder->protected_->num_apodizations = 1;
  90625. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90626. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90627. #endif
  90628. #endif
  90629. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90630. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90631. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90632. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90633. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90634. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90635. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90636. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90637. return ok;
  90638. }
  90639. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90640. {
  90641. FLAC__ASSERT(0 != encoder);
  90642. FLAC__ASSERT(0 != encoder->private_);
  90643. FLAC__ASSERT(0 != encoder->protected_);
  90644. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90645. return false;
  90646. encoder->protected_->blocksize = value;
  90647. return true;
  90648. }
  90649. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90650. {
  90651. FLAC__ASSERT(0 != encoder);
  90652. FLAC__ASSERT(0 != encoder->private_);
  90653. FLAC__ASSERT(0 != encoder->protected_);
  90654. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90655. return false;
  90656. encoder->protected_->do_mid_side_stereo = value;
  90657. return true;
  90658. }
  90659. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90660. {
  90661. FLAC__ASSERT(0 != encoder);
  90662. FLAC__ASSERT(0 != encoder->private_);
  90663. FLAC__ASSERT(0 != encoder->protected_);
  90664. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90665. return false;
  90666. encoder->protected_->loose_mid_side_stereo = value;
  90667. return true;
  90668. }
  90669. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90670. {
  90671. FLAC__ASSERT(0 != encoder);
  90672. FLAC__ASSERT(0 != encoder->private_);
  90673. FLAC__ASSERT(0 != encoder->protected_);
  90674. FLAC__ASSERT(0 != specification);
  90675. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90676. return false;
  90677. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90678. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90679. #else
  90680. encoder->protected_->num_apodizations = 0;
  90681. while(1) {
  90682. const char *s = strchr(specification, ';');
  90683. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90684. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90685. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90686. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90687. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90688. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90689. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90690. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90691. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90692. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90693. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90694. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90695. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90696. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90697. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90698. if (stddev > 0.0 && stddev <= 0.5) {
  90699. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90700. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90701. }
  90702. }
  90703. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90704. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90705. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90706. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90707. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90708. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90709. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90710. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90711. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90712. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90713. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90714. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90715. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90716. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90717. if (p >= 0.0 && p <= 1.0) {
  90718. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90719. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90720. }
  90721. }
  90722. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90723. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90724. if (encoder->protected_->num_apodizations == 32)
  90725. break;
  90726. if (s)
  90727. specification = s+1;
  90728. else
  90729. break;
  90730. }
  90731. if(encoder->protected_->num_apodizations == 0) {
  90732. encoder->protected_->num_apodizations = 1;
  90733. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90734. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90735. }
  90736. #endif
  90737. return true;
  90738. }
  90739. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90740. {
  90741. FLAC__ASSERT(0 != encoder);
  90742. FLAC__ASSERT(0 != encoder->private_);
  90743. FLAC__ASSERT(0 != encoder->protected_);
  90744. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90745. return false;
  90746. encoder->protected_->max_lpc_order = value;
  90747. return true;
  90748. }
  90749. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90750. {
  90751. FLAC__ASSERT(0 != encoder);
  90752. FLAC__ASSERT(0 != encoder->private_);
  90753. FLAC__ASSERT(0 != encoder->protected_);
  90754. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90755. return false;
  90756. encoder->protected_->qlp_coeff_precision = value;
  90757. return true;
  90758. }
  90759. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90760. {
  90761. FLAC__ASSERT(0 != encoder);
  90762. FLAC__ASSERT(0 != encoder->private_);
  90763. FLAC__ASSERT(0 != encoder->protected_);
  90764. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90765. return false;
  90766. encoder->protected_->do_qlp_coeff_prec_search = value;
  90767. return true;
  90768. }
  90769. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90770. {
  90771. FLAC__ASSERT(0 != encoder);
  90772. FLAC__ASSERT(0 != encoder->private_);
  90773. FLAC__ASSERT(0 != encoder->protected_);
  90774. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90775. return false;
  90776. #if 0
  90777. encoder->protected_->do_escape_coding = value;
  90778. #else
  90779. (void)value;
  90780. #endif
  90781. return true;
  90782. }
  90783. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90784. {
  90785. FLAC__ASSERT(0 != encoder);
  90786. FLAC__ASSERT(0 != encoder->private_);
  90787. FLAC__ASSERT(0 != encoder->protected_);
  90788. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90789. return false;
  90790. encoder->protected_->do_exhaustive_model_search = value;
  90791. return true;
  90792. }
  90793. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90794. {
  90795. FLAC__ASSERT(0 != encoder);
  90796. FLAC__ASSERT(0 != encoder->private_);
  90797. FLAC__ASSERT(0 != encoder->protected_);
  90798. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90799. return false;
  90800. encoder->protected_->min_residual_partition_order = value;
  90801. return true;
  90802. }
  90803. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90804. {
  90805. FLAC__ASSERT(0 != encoder);
  90806. FLAC__ASSERT(0 != encoder->private_);
  90807. FLAC__ASSERT(0 != encoder->protected_);
  90808. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90809. return false;
  90810. encoder->protected_->max_residual_partition_order = value;
  90811. return true;
  90812. }
  90813. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90814. {
  90815. FLAC__ASSERT(0 != encoder);
  90816. FLAC__ASSERT(0 != encoder->private_);
  90817. FLAC__ASSERT(0 != encoder->protected_);
  90818. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90819. return false;
  90820. #if 0
  90821. encoder->protected_->rice_parameter_search_dist = value;
  90822. #else
  90823. (void)value;
  90824. #endif
  90825. return true;
  90826. }
  90827. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 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_->total_samples_estimate = value;
  90835. return true;
  90836. }
  90837. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  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 == metadata)
  90845. num_blocks = 0;
  90846. if(0 == num_blocks)
  90847. metadata = 0;
  90848. if(encoder->protected_->metadata) {
  90849. free(encoder->protected_->metadata);
  90850. encoder->protected_->metadata = 0;
  90851. encoder->protected_->num_metadata_blocks = 0;
  90852. }
  90853. if(num_blocks) {
  90854. FLAC__StreamMetadata **m;
  90855. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90856. return false;
  90857. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90858. encoder->protected_->metadata = m;
  90859. encoder->protected_->num_metadata_blocks = num_blocks;
  90860. }
  90861. #if FLAC__HAS_OGG
  90862. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90863. return false;
  90864. #endif
  90865. return true;
  90866. }
  90867. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90868. {
  90869. FLAC__ASSERT(0 != encoder);
  90870. FLAC__ASSERT(0 != encoder->private_);
  90871. FLAC__ASSERT(0 != encoder->protected_);
  90872. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90873. return false;
  90874. encoder->private_->disable_constant_subframes = value;
  90875. return true;
  90876. }
  90877. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90878. {
  90879. FLAC__ASSERT(0 != encoder);
  90880. FLAC__ASSERT(0 != encoder->private_);
  90881. FLAC__ASSERT(0 != encoder->protected_);
  90882. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90883. return false;
  90884. encoder->private_->disable_fixed_subframes = value;
  90885. return true;
  90886. }
  90887. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90888. {
  90889. FLAC__ASSERT(0 != encoder);
  90890. FLAC__ASSERT(0 != encoder->private_);
  90891. FLAC__ASSERT(0 != encoder->protected_);
  90892. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90893. return false;
  90894. encoder->private_->disable_verbatim_subframes = value;
  90895. return true;
  90896. }
  90897. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90898. {
  90899. FLAC__ASSERT(0 != encoder);
  90900. FLAC__ASSERT(0 != encoder->private_);
  90901. FLAC__ASSERT(0 != encoder->protected_);
  90902. return encoder->protected_->state;
  90903. }
  90904. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90905. {
  90906. FLAC__ASSERT(0 != encoder);
  90907. FLAC__ASSERT(0 != encoder->private_);
  90908. FLAC__ASSERT(0 != encoder->protected_);
  90909. if(encoder->protected_->verify)
  90910. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90911. else
  90912. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90913. }
  90914. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90915. {
  90916. FLAC__ASSERT(0 != encoder);
  90917. FLAC__ASSERT(0 != encoder->private_);
  90918. FLAC__ASSERT(0 != encoder->protected_);
  90919. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  90920. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  90921. else
  90922. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  90923. }
  90924. 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)
  90925. {
  90926. FLAC__ASSERT(0 != encoder);
  90927. FLAC__ASSERT(0 != encoder->private_);
  90928. FLAC__ASSERT(0 != encoder->protected_);
  90929. if(0 != absolute_sample)
  90930. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  90931. if(0 != frame_number)
  90932. *frame_number = encoder->private_->verify.error_stats.frame_number;
  90933. if(0 != channel)
  90934. *channel = encoder->private_->verify.error_stats.channel;
  90935. if(0 != sample)
  90936. *sample = encoder->private_->verify.error_stats.sample;
  90937. if(0 != expected)
  90938. *expected = encoder->private_->verify.error_stats.expected;
  90939. if(0 != got)
  90940. *got = encoder->private_->verify.error_stats.got;
  90941. }
  90942. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  90943. {
  90944. FLAC__ASSERT(0 != encoder);
  90945. FLAC__ASSERT(0 != encoder->private_);
  90946. FLAC__ASSERT(0 != encoder->protected_);
  90947. return encoder->protected_->verify;
  90948. }
  90949. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  90950. {
  90951. FLAC__ASSERT(0 != encoder);
  90952. FLAC__ASSERT(0 != encoder->private_);
  90953. FLAC__ASSERT(0 != encoder->protected_);
  90954. return encoder->protected_->streamable_subset;
  90955. }
  90956. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  90957. {
  90958. FLAC__ASSERT(0 != encoder);
  90959. FLAC__ASSERT(0 != encoder->private_);
  90960. FLAC__ASSERT(0 != encoder->protected_);
  90961. return encoder->protected_->do_md5;
  90962. }
  90963. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  90964. {
  90965. FLAC__ASSERT(0 != encoder);
  90966. FLAC__ASSERT(0 != encoder->private_);
  90967. FLAC__ASSERT(0 != encoder->protected_);
  90968. return encoder->protected_->channels;
  90969. }
  90970. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  90971. {
  90972. FLAC__ASSERT(0 != encoder);
  90973. FLAC__ASSERT(0 != encoder->private_);
  90974. FLAC__ASSERT(0 != encoder->protected_);
  90975. return encoder->protected_->bits_per_sample;
  90976. }
  90977. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  90978. {
  90979. FLAC__ASSERT(0 != encoder);
  90980. FLAC__ASSERT(0 != encoder->private_);
  90981. FLAC__ASSERT(0 != encoder->protected_);
  90982. return encoder->protected_->sample_rate;
  90983. }
  90984. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  90985. {
  90986. FLAC__ASSERT(0 != encoder);
  90987. FLAC__ASSERT(0 != encoder->private_);
  90988. FLAC__ASSERT(0 != encoder->protected_);
  90989. return encoder->protected_->blocksize;
  90990. }
  90991. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90992. {
  90993. FLAC__ASSERT(0 != encoder);
  90994. FLAC__ASSERT(0 != encoder->private_);
  90995. FLAC__ASSERT(0 != encoder->protected_);
  90996. return encoder->protected_->do_mid_side_stereo;
  90997. }
  90998. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90999. {
  91000. FLAC__ASSERT(0 != encoder);
  91001. FLAC__ASSERT(0 != encoder->private_);
  91002. FLAC__ASSERT(0 != encoder->protected_);
  91003. return encoder->protected_->loose_mid_side_stereo;
  91004. }
  91005. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91006. {
  91007. FLAC__ASSERT(0 != encoder);
  91008. FLAC__ASSERT(0 != encoder->private_);
  91009. FLAC__ASSERT(0 != encoder->protected_);
  91010. return encoder->protected_->max_lpc_order;
  91011. }
  91012. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91013. {
  91014. FLAC__ASSERT(0 != encoder);
  91015. FLAC__ASSERT(0 != encoder->private_);
  91016. FLAC__ASSERT(0 != encoder->protected_);
  91017. return encoder->protected_->qlp_coeff_precision;
  91018. }
  91019. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91020. {
  91021. FLAC__ASSERT(0 != encoder);
  91022. FLAC__ASSERT(0 != encoder->private_);
  91023. FLAC__ASSERT(0 != encoder->protected_);
  91024. return encoder->protected_->do_qlp_coeff_prec_search;
  91025. }
  91026. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91027. {
  91028. FLAC__ASSERT(0 != encoder);
  91029. FLAC__ASSERT(0 != encoder->private_);
  91030. FLAC__ASSERT(0 != encoder->protected_);
  91031. return encoder->protected_->do_escape_coding;
  91032. }
  91033. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91034. {
  91035. FLAC__ASSERT(0 != encoder);
  91036. FLAC__ASSERT(0 != encoder->private_);
  91037. FLAC__ASSERT(0 != encoder->protected_);
  91038. return encoder->protected_->do_exhaustive_model_search;
  91039. }
  91040. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91041. {
  91042. FLAC__ASSERT(0 != encoder);
  91043. FLAC__ASSERT(0 != encoder->private_);
  91044. FLAC__ASSERT(0 != encoder->protected_);
  91045. return encoder->protected_->min_residual_partition_order;
  91046. }
  91047. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91048. {
  91049. FLAC__ASSERT(0 != encoder);
  91050. FLAC__ASSERT(0 != encoder->private_);
  91051. FLAC__ASSERT(0 != encoder->protected_);
  91052. return encoder->protected_->max_residual_partition_order;
  91053. }
  91054. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91055. {
  91056. FLAC__ASSERT(0 != encoder);
  91057. FLAC__ASSERT(0 != encoder->private_);
  91058. FLAC__ASSERT(0 != encoder->protected_);
  91059. return encoder->protected_->rice_parameter_search_dist;
  91060. }
  91061. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91062. {
  91063. FLAC__ASSERT(0 != encoder);
  91064. FLAC__ASSERT(0 != encoder->private_);
  91065. FLAC__ASSERT(0 != encoder->protected_);
  91066. return encoder->protected_->total_samples_estimate;
  91067. }
  91068. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91069. {
  91070. unsigned i, j = 0, channel;
  91071. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91072. FLAC__ASSERT(0 != encoder);
  91073. FLAC__ASSERT(0 != encoder->private_);
  91074. FLAC__ASSERT(0 != encoder->protected_);
  91075. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91076. do {
  91077. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91078. if(encoder->protected_->verify)
  91079. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91080. for(channel = 0; channel < channels; channel++)
  91081. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91082. if(encoder->protected_->do_mid_side_stereo) {
  91083. FLAC__ASSERT(channels == 2);
  91084. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91085. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91086. 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' ! */
  91087. }
  91088. }
  91089. else
  91090. j += n;
  91091. encoder->private_->current_sample_number += n;
  91092. if(encoder->private_->current_sample_number > blocksize) {
  91093. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91094. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91095. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91096. return false;
  91097. for(channel = 0; channel < channels; channel++)
  91098. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91099. if(encoder->protected_->do_mid_side_stereo) {
  91100. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91101. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91102. }
  91103. encoder->private_->current_sample_number = 1;
  91104. }
  91105. } while(j < samples);
  91106. return true;
  91107. }
  91108. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91109. {
  91110. unsigned i, j, k, channel;
  91111. FLAC__int32 x, mid, side;
  91112. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91113. FLAC__ASSERT(0 != encoder);
  91114. FLAC__ASSERT(0 != encoder->private_);
  91115. FLAC__ASSERT(0 != encoder->protected_);
  91116. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91117. j = k = 0;
  91118. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91119. do {
  91120. if(encoder->protected_->verify)
  91121. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91122. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91123. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91124. x = buffer[k++];
  91125. encoder->private_->integer_signal[1][i] = x;
  91126. mid += x;
  91127. side -= x;
  91128. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91129. encoder->private_->integer_signal_mid_side[1][i] = side;
  91130. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91131. }
  91132. encoder->private_->current_sample_number = i;
  91133. if(i > blocksize) {
  91134. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91135. return false;
  91136. /* move unprocessed overread samples to beginnings of arrays */
  91137. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91138. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91139. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91140. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91141. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91142. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91143. encoder->private_->current_sample_number = 1;
  91144. }
  91145. } while(j < samples);
  91146. }
  91147. else {
  91148. do {
  91149. if(encoder->protected_->verify)
  91150. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91151. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91152. for(channel = 0; channel < channels; channel++)
  91153. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91154. }
  91155. encoder->private_->current_sample_number = i;
  91156. if(i > blocksize) {
  91157. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91158. return false;
  91159. /* move unprocessed overread samples to beginnings of arrays */
  91160. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91161. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91162. for(channel = 0; channel < channels; channel++)
  91163. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91164. encoder->private_->current_sample_number = 1;
  91165. }
  91166. } while(j < samples);
  91167. }
  91168. return true;
  91169. }
  91170. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91171. {
  91172. FLAC__ASSERT(0 != encoder);
  91173. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91174. encoder->protected_->verify = true;
  91175. #else
  91176. encoder->protected_->verify = false;
  91177. #endif
  91178. encoder->protected_->streamable_subset = true;
  91179. encoder->protected_->do_md5 = true;
  91180. encoder->protected_->do_mid_side_stereo = false;
  91181. encoder->protected_->loose_mid_side_stereo = false;
  91182. encoder->protected_->channels = 2;
  91183. encoder->protected_->bits_per_sample = 16;
  91184. encoder->protected_->sample_rate = 44100;
  91185. encoder->protected_->blocksize = 0;
  91186. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91187. encoder->protected_->num_apodizations = 1;
  91188. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91189. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91190. #endif
  91191. encoder->protected_->max_lpc_order = 0;
  91192. encoder->protected_->qlp_coeff_precision = 0;
  91193. encoder->protected_->do_qlp_coeff_prec_search = false;
  91194. encoder->protected_->do_exhaustive_model_search = false;
  91195. encoder->protected_->do_escape_coding = false;
  91196. encoder->protected_->min_residual_partition_order = 0;
  91197. encoder->protected_->max_residual_partition_order = 0;
  91198. encoder->protected_->rice_parameter_search_dist = 0;
  91199. encoder->protected_->total_samples_estimate = 0;
  91200. encoder->protected_->metadata = 0;
  91201. encoder->protected_->num_metadata_blocks = 0;
  91202. encoder->private_->seek_table = 0;
  91203. encoder->private_->disable_constant_subframes = false;
  91204. encoder->private_->disable_fixed_subframes = false;
  91205. encoder->private_->disable_verbatim_subframes = false;
  91206. #if FLAC__HAS_OGG
  91207. encoder->private_->is_ogg = false;
  91208. #endif
  91209. encoder->private_->read_callback = 0;
  91210. encoder->private_->write_callback = 0;
  91211. encoder->private_->seek_callback = 0;
  91212. encoder->private_->tell_callback = 0;
  91213. encoder->private_->metadata_callback = 0;
  91214. encoder->private_->progress_callback = 0;
  91215. encoder->private_->client_data = 0;
  91216. #if FLAC__HAS_OGG
  91217. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91218. #endif
  91219. }
  91220. void free_(FLAC__StreamEncoder *encoder)
  91221. {
  91222. unsigned i, channel;
  91223. FLAC__ASSERT(0 != encoder);
  91224. if(encoder->protected_->metadata) {
  91225. free(encoder->protected_->metadata);
  91226. encoder->protected_->metadata = 0;
  91227. encoder->protected_->num_metadata_blocks = 0;
  91228. }
  91229. for(i = 0; i < encoder->protected_->channels; i++) {
  91230. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91231. free(encoder->private_->integer_signal_unaligned[i]);
  91232. encoder->private_->integer_signal_unaligned[i] = 0;
  91233. }
  91234. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91235. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91236. free(encoder->private_->real_signal_unaligned[i]);
  91237. encoder->private_->real_signal_unaligned[i] = 0;
  91238. }
  91239. #endif
  91240. }
  91241. for(i = 0; i < 2; i++) {
  91242. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91243. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91244. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91245. }
  91246. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91247. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91248. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91249. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91250. }
  91251. #endif
  91252. }
  91253. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91254. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91255. if(0 != encoder->private_->window_unaligned[i]) {
  91256. free(encoder->private_->window_unaligned[i]);
  91257. encoder->private_->window_unaligned[i] = 0;
  91258. }
  91259. }
  91260. if(0 != encoder->private_->windowed_signal_unaligned) {
  91261. free(encoder->private_->windowed_signal_unaligned);
  91262. encoder->private_->windowed_signal_unaligned = 0;
  91263. }
  91264. #endif
  91265. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91266. for(i = 0; i < 2; i++) {
  91267. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91268. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91269. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91270. }
  91271. }
  91272. }
  91273. for(channel = 0; channel < 2; channel++) {
  91274. for(i = 0; i < 2; i++) {
  91275. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91276. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91277. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91278. }
  91279. }
  91280. }
  91281. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91282. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91283. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91284. }
  91285. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91286. free(encoder->private_->raw_bits_per_partition_unaligned);
  91287. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91288. }
  91289. if(encoder->protected_->verify) {
  91290. for(i = 0; i < encoder->protected_->channels; i++) {
  91291. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91292. free(encoder->private_->verify.input_fifo.data[i]);
  91293. encoder->private_->verify.input_fifo.data[i] = 0;
  91294. }
  91295. }
  91296. }
  91297. FLAC__bitwriter_free(encoder->private_->frame);
  91298. }
  91299. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91300. {
  91301. FLAC__bool ok;
  91302. unsigned i, channel;
  91303. FLAC__ASSERT(new_blocksize > 0);
  91304. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91305. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91306. if(new_blocksize <= encoder->private_->input_capacity)
  91307. return true;
  91308. ok = true;
  91309. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91310. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91311. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91312. encoder->private_->integer_signal[i] += 4;
  91313. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91314. #if 0 /* @@@ currently unused */
  91315. if(encoder->protected_->max_lpc_order > 0)
  91316. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91317. #endif
  91318. #endif
  91319. }
  91320. for(i = 0; ok && i < 2; i++) {
  91321. 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]);
  91322. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91323. encoder->private_->integer_signal_mid_side[i] += 4;
  91324. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91325. #if 0 /* @@@ currently unused */
  91326. if(encoder->protected_->max_lpc_order > 0)
  91327. 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]);
  91328. #endif
  91329. #endif
  91330. }
  91331. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91332. if(ok && encoder->protected_->max_lpc_order > 0) {
  91333. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91334. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91335. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91336. }
  91337. #endif
  91338. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91339. for(i = 0; ok && i < 2; i++) {
  91340. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91341. }
  91342. }
  91343. for(channel = 0; ok && channel < 2; channel++) {
  91344. for(i = 0; ok && i < 2; i++) {
  91345. 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]);
  91346. }
  91347. }
  91348. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91349. if(encoder->protected_->do_escape_coding)
  91350. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91351. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91352. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91353. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91354. switch(encoder->protected_->apodizations[i].type) {
  91355. case FLAC__APODIZATION_BARTLETT:
  91356. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91357. break;
  91358. case FLAC__APODIZATION_BARTLETT_HANN:
  91359. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91360. break;
  91361. case FLAC__APODIZATION_BLACKMAN:
  91362. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91363. break;
  91364. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91365. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91366. break;
  91367. case FLAC__APODIZATION_CONNES:
  91368. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91369. break;
  91370. case FLAC__APODIZATION_FLATTOP:
  91371. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91372. break;
  91373. case FLAC__APODIZATION_GAUSS:
  91374. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91375. break;
  91376. case FLAC__APODIZATION_HAMMING:
  91377. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91378. break;
  91379. case FLAC__APODIZATION_HANN:
  91380. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91381. break;
  91382. case FLAC__APODIZATION_KAISER_BESSEL:
  91383. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91384. break;
  91385. case FLAC__APODIZATION_NUTTALL:
  91386. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91387. break;
  91388. case FLAC__APODIZATION_RECTANGLE:
  91389. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91390. break;
  91391. case FLAC__APODIZATION_TRIANGLE:
  91392. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91393. break;
  91394. case FLAC__APODIZATION_TUKEY:
  91395. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91396. break;
  91397. case FLAC__APODIZATION_WELCH:
  91398. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91399. break;
  91400. default:
  91401. FLAC__ASSERT(0);
  91402. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91403. break;
  91404. }
  91405. }
  91406. }
  91407. #endif
  91408. if(ok)
  91409. encoder->private_->input_capacity = new_blocksize;
  91410. else
  91411. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91412. return ok;
  91413. }
  91414. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91415. {
  91416. const FLAC__byte *buffer;
  91417. size_t bytes;
  91418. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91419. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91420. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91421. return false;
  91422. }
  91423. if(encoder->protected_->verify) {
  91424. encoder->private_->verify.output.data = buffer;
  91425. encoder->private_->verify.output.bytes = bytes;
  91426. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91427. encoder->private_->verify.needs_magic_hack = true;
  91428. }
  91429. else {
  91430. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91431. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91432. FLAC__bitwriter_clear(encoder->private_->frame);
  91433. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91434. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91435. return false;
  91436. }
  91437. }
  91438. }
  91439. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91440. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91441. FLAC__bitwriter_clear(encoder->private_->frame);
  91442. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91443. return false;
  91444. }
  91445. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91446. FLAC__bitwriter_clear(encoder->private_->frame);
  91447. if(samples > 0) {
  91448. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91449. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91450. }
  91451. return true;
  91452. }
  91453. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91454. {
  91455. FLAC__StreamEncoderWriteStatus status;
  91456. FLAC__uint64 output_position = 0;
  91457. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91458. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91459. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91460. }
  91461. if(samples == 0) {
  91462. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91463. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91464. encoder->protected_->streaminfo_offset = output_position;
  91465. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91466. encoder->protected_->seektable_offset = output_position;
  91467. }
  91468. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91469. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91470. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91471. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91472. FLAC__uint64 test_sample;
  91473. unsigned i;
  91474. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91475. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91476. if(test_sample > frame_last_sample) {
  91477. break;
  91478. }
  91479. else if(test_sample >= frame_first_sample) {
  91480. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91481. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91482. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91483. encoder->private_->first_seekpoint_to_check++;
  91484. }
  91485. else {
  91486. encoder->private_->first_seekpoint_to_check++;
  91487. }
  91488. }
  91489. }
  91490. #if FLAC__HAS_OGG
  91491. if(encoder->private_->is_ogg) {
  91492. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91493. &encoder->protected_->ogg_encoder_aspect,
  91494. buffer,
  91495. bytes,
  91496. samples,
  91497. encoder->private_->current_frame_number,
  91498. is_last_block,
  91499. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91500. encoder,
  91501. encoder->private_->client_data
  91502. );
  91503. }
  91504. else
  91505. #endif
  91506. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91507. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91508. encoder->private_->bytes_written += bytes;
  91509. encoder->private_->samples_written += samples;
  91510. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91511. }
  91512. else
  91513. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91514. return status;
  91515. }
  91516. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91517. {
  91518. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91519. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91520. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91521. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91522. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91523. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91524. FLAC__StreamEncoderSeekStatus seek_status;
  91525. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91526. {
  91527. const unsigned md5_offset =
  91528. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91529. (
  91530. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91531. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91532. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91533. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91534. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91535. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91536. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91537. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91538. ) / 8;
  91539. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91540. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91541. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91542. return;
  91543. }
  91544. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91545. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91546. return;
  91547. }
  91548. }
  91549. {
  91550. const unsigned total_samples_byte_offset =
  91551. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91552. (
  91553. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91554. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91555. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91556. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91557. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91558. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91559. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91560. - 4
  91561. ) / 8;
  91562. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91563. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91564. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91565. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91566. b[4] = (FLAC__byte)(samples & 0xFF);
  91567. 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) {
  91568. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91569. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91570. return;
  91571. }
  91572. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91573. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91574. return;
  91575. }
  91576. }
  91577. {
  91578. const unsigned min_framesize_offset =
  91579. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91580. (
  91581. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91582. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91583. ) / 8;
  91584. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91585. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91586. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91587. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91588. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91589. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91590. 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) {
  91591. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91592. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91593. return;
  91594. }
  91595. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91596. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91597. return;
  91598. }
  91599. }
  91600. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91601. unsigned i;
  91602. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91603. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91604. 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) {
  91605. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91606. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91607. return;
  91608. }
  91609. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91610. FLAC__uint64 xx;
  91611. unsigned x;
  91612. xx = encoder->private_->seek_table->points[i].sample_number;
  91613. b[7] = (FLAC__byte)xx; xx >>= 8;
  91614. b[6] = (FLAC__byte)xx; xx >>= 8;
  91615. b[5] = (FLAC__byte)xx; xx >>= 8;
  91616. b[4] = (FLAC__byte)xx; xx >>= 8;
  91617. b[3] = (FLAC__byte)xx; xx >>= 8;
  91618. b[2] = (FLAC__byte)xx; xx >>= 8;
  91619. b[1] = (FLAC__byte)xx; xx >>= 8;
  91620. b[0] = (FLAC__byte)xx; xx >>= 8;
  91621. xx = encoder->private_->seek_table->points[i].stream_offset;
  91622. b[15] = (FLAC__byte)xx; xx >>= 8;
  91623. b[14] = (FLAC__byte)xx; xx >>= 8;
  91624. b[13] = (FLAC__byte)xx; xx >>= 8;
  91625. b[12] = (FLAC__byte)xx; xx >>= 8;
  91626. b[11] = (FLAC__byte)xx; xx >>= 8;
  91627. b[10] = (FLAC__byte)xx; xx >>= 8;
  91628. b[9] = (FLAC__byte)xx; xx >>= 8;
  91629. b[8] = (FLAC__byte)xx; xx >>= 8;
  91630. x = encoder->private_->seek_table->points[i].frame_samples;
  91631. b[17] = (FLAC__byte)x; x >>= 8;
  91632. b[16] = (FLAC__byte)x; x >>= 8;
  91633. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91634. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91635. return;
  91636. }
  91637. }
  91638. }
  91639. }
  91640. #if FLAC__HAS_OGG
  91641. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91642. {
  91643. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91644. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91645. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91646. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91647. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91648. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91649. FLAC__STREAM_SYNC_LENGTH
  91650. ;
  91651. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91652. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91653. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91654. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91655. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91656. ogg_page page;
  91657. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91658. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91659. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91660. return;
  91661. simple_ogg_page__init(&page);
  91662. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91663. simple_ogg_page__clear(&page);
  91664. return; /* state already set */
  91665. }
  91666. {
  91667. const unsigned md5_offset =
  91668. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91669. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91670. (
  91671. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91672. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91673. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91674. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91675. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91676. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91677. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91678. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91679. ) / 8;
  91680. if(md5_offset + 16 > (unsigned)page.body_len) {
  91681. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91682. simple_ogg_page__clear(&page);
  91683. return;
  91684. }
  91685. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91686. }
  91687. {
  91688. const unsigned total_samples_byte_offset =
  91689. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91690. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91691. (
  91692. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91693. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91694. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91695. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91696. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91697. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91698. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91699. - 4
  91700. ) / 8;
  91701. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91702. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91703. simple_ogg_page__clear(&page);
  91704. return;
  91705. }
  91706. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91707. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91708. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91709. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91710. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91711. b[4] = (FLAC__byte)(samples & 0xFF);
  91712. memcpy(page.body + total_samples_byte_offset, b, 5);
  91713. }
  91714. {
  91715. const unsigned min_framesize_offset =
  91716. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91717. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91718. (
  91719. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91720. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91721. ) / 8;
  91722. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91723. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91724. simple_ogg_page__clear(&page);
  91725. return;
  91726. }
  91727. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91728. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91729. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91730. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91731. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91732. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91733. memcpy(page.body + min_framesize_offset, b, 6);
  91734. }
  91735. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91736. simple_ogg_page__clear(&page);
  91737. return; /* state already set */
  91738. }
  91739. simple_ogg_page__clear(&page);
  91740. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91741. unsigned i;
  91742. FLAC__byte *p;
  91743. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91744. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91745. simple_ogg_page__init(&page);
  91746. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91747. simple_ogg_page__clear(&page);
  91748. return; /* state already set */
  91749. }
  91750. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91751. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91752. simple_ogg_page__clear(&page);
  91753. return;
  91754. }
  91755. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91756. FLAC__uint64 xx;
  91757. unsigned x;
  91758. xx = encoder->private_->seek_table->points[i].sample_number;
  91759. b[7] = (FLAC__byte)xx; xx >>= 8;
  91760. b[6] = (FLAC__byte)xx; xx >>= 8;
  91761. b[5] = (FLAC__byte)xx; xx >>= 8;
  91762. b[4] = (FLAC__byte)xx; xx >>= 8;
  91763. b[3] = (FLAC__byte)xx; xx >>= 8;
  91764. b[2] = (FLAC__byte)xx; xx >>= 8;
  91765. b[1] = (FLAC__byte)xx; xx >>= 8;
  91766. b[0] = (FLAC__byte)xx; xx >>= 8;
  91767. xx = encoder->private_->seek_table->points[i].stream_offset;
  91768. b[15] = (FLAC__byte)xx; xx >>= 8;
  91769. b[14] = (FLAC__byte)xx; xx >>= 8;
  91770. b[13] = (FLAC__byte)xx; xx >>= 8;
  91771. b[12] = (FLAC__byte)xx; xx >>= 8;
  91772. b[11] = (FLAC__byte)xx; xx >>= 8;
  91773. b[10] = (FLAC__byte)xx; xx >>= 8;
  91774. b[9] = (FLAC__byte)xx; xx >>= 8;
  91775. b[8] = (FLAC__byte)xx; xx >>= 8;
  91776. x = encoder->private_->seek_table->points[i].frame_samples;
  91777. b[17] = (FLAC__byte)x; x >>= 8;
  91778. b[16] = (FLAC__byte)x; x >>= 8;
  91779. memcpy(p, b, 18);
  91780. }
  91781. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91782. simple_ogg_page__clear(&page);
  91783. return; /* state already set */
  91784. }
  91785. simple_ogg_page__clear(&page);
  91786. }
  91787. }
  91788. #endif
  91789. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91790. {
  91791. FLAC__uint16 crc;
  91792. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91793. 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)) {
  91794. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91795. return false;
  91796. }
  91797. if(!process_subframes_(encoder, is_fractional_block)) {
  91798. return false;
  91799. }
  91800. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91801. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91802. return false;
  91803. }
  91804. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91805. if(
  91806. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91807. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91808. ) {
  91809. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91810. return false;
  91811. }
  91812. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91813. return false;
  91814. }
  91815. encoder->private_->current_sample_number = 0;
  91816. encoder->private_->current_frame_number++;
  91817. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91818. return true;
  91819. }
  91820. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91821. {
  91822. FLAC__FrameHeader frame_header;
  91823. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91824. FLAC__bool do_independent, do_mid_side;
  91825. if(is_fractional_block) {
  91826. max_partition_order = 0;
  91827. }
  91828. else {
  91829. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91830. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91831. }
  91832. min_partition_order = min(min_partition_order, max_partition_order);
  91833. frame_header.blocksize = encoder->protected_->blocksize;
  91834. frame_header.sample_rate = encoder->protected_->sample_rate;
  91835. frame_header.channels = encoder->protected_->channels;
  91836. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91837. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91838. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91839. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91840. if(encoder->protected_->do_mid_side_stereo) {
  91841. if(encoder->protected_->loose_mid_side_stereo) {
  91842. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91843. do_independent = true;
  91844. do_mid_side = true;
  91845. }
  91846. else {
  91847. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91848. do_mid_side = !do_independent;
  91849. }
  91850. }
  91851. else {
  91852. do_independent = true;
  91853. do_mid_side = true;
  91854. }
  91855. }
  91856. else {
  91857. do_independent = true;
  91858. do_mid_side = false;
  91859. }
  91860. FLAC__ASSERT(do_independent || do_mid_side);
  91861. if(do_independent) {
  91862. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91863. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91864. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91865. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91866. }
  91867. }
  91868. if(do_mid_side) {
  91869. FLAC__ASSERT(encoder->protected_->channels == 2);
  91870. for(channel = 0; channel < 2; channel++) {
  91871. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91872. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91873. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91874. }
  91875. }
  91876. if(do_independent) {
  91877. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91878. if(!
  91879. process_subframe_(
  91880. encoder,
  91881. min_partition_order,
  91882. max_partition_order,
  91883. &frame_header,
  91884. encoder->private_->subframe_bps[channel],
  91885. encoder->private_->integer_signal[channel],
  91886. encoder->private_->subframe_workspace_ptr[channel],
  91887. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91888. encoder->private_->residual_workspace[channel],
  91889. encoder->private_->best_subframe+channel,
  91890. encoder->private_->best_subframe_bits+channel
  91891. )
  91892. )
  91893. return false;
  91894. }
  91895. }
  91896. if(do_mid_side) {
  91897. FLAC__ASSERT(encoder->protected_->channels == 2);
  91898. for(channel = 0; channel < 2; channel++) {
  91899. if(!
  91900. process_subframe_(
  91901. encoder,
  91902. min_partition_order,
  91903. max_partition_order,
  91904. &frame_header,
  91905. encoder->private_->subframe_bps_mid_side[channel],
  91906. encoder->private_->integer_signal_mid_side[channel],
  91907. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91908. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91909. encoder->private_->residual_workspace_mid_side[channel],
  91910. encoder->private_->best_subframe_mid_side+channel,
  91911. encoder->private_->best_subframe_bits_mid_side+channel
  91912. )
  91913. )
  91914. return false;
  91915. }
  91916. }
  91917. if(do_mid_side) {
  91918. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  91919. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  91920. FLAC__ChannelAssignment channel_assignment;
  91921. FLAC__ASSERT(encoder->protected_->channels == 2);
  91922. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  91923. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  91924. }
  91925. else {
  91926. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  91927. unsigned min_bits;
  91928. int ca;
  91929. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  91930. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  91931. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  91932. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  91933. FLAC__ASSERT(do_independent && do_mid_side);
  91934. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  91935. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  91936. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  91937. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  91938. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  91939. min_bits = bits[channel_assignment];
  91940. for(ca = 1; ca <= 3; ca++) {
  91941. if(bits[ca] < min_bits) {
  91942. min_bits = bits[ca];
  91943. channel_assignment = (FLAC__ChannelAssignment)ca;
  91944. }
  91945. }
  91946. }
  91947. frame_header.channel_assignment = channel_assignment;
  91948. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91949. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91950. return false;
  91951. }
  91952. switch(channel_assignment) {
  91953. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91954. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91955. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91956. break;
  91957. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91958. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91959. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91960. break;
  91961. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91962. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91963. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91964. break;
  91965. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91966. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  91967. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91968. break;
  91969. default:
  91970. FLAC__ASSERT(0);
  91971. }
  91972. switch(channel_assignment) {
  91973. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91974. left_bps = encoder->private_->subframe_bps [0];
  91975. right_bps = encoder->private_->subframe_bps [1];
  91976. break;
  91977. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91978. left_bps = encoder->private_->subframe_bps [0];
  91979. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91980. break;
  91981. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91982. left_bps = encoder->private_->subframe_bps_mid_side[1];
  91983. right_bps = encoder->private_->subframe_bps [1];
  91984. break;
  91985. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91986. left_bps = encoder->private_->subframe_bps_mid_side[0];
  91987. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91988. break;
  91989. default:
  91990. FLAC__ASSERT(0);
  91991. }
  91992. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  91993. return false;
  91994. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  91995. return false;
  91996. }
  91997. else {
  91998. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91999. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92000. return false;
  92001. }
  92002. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92003. 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)) {
  92004. return false;
  92005. }
  92006. }
  92007. }
  92008. if(encoder->protected_->loose_mid_side_stereo) {
  92009. encoder->private_->loose_mid_side_stereo_frame_count++;
  92010. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92011. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92012. }
  92013. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92014. return true;
  92015. }
  92016. FLAC__bool process_subframe_(
  92017. FLAC__StreamEncoder *encoder,
  92018. unsigned min_partition_order,
  92019. unsigned max_partition_order,
  92020. const FLAC__FrameHeader *frame_header,
  92021. unsigned subframe_bps,
  92022. const FLAC__int32 integer_signal[],
  92023. FLAC__Subframe *subframe[2],
  92024. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92025. FLAC__int32 *residual[2],
  92026. unsigned *best_subframe,
  92027. unsigned *best_bits
  92028. )
  92029. {
  92030. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92031. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92032. #else
  92033. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92034. #endif
  92035. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92036. FLAC__double lpc_residual_bits_per_sample;
  92037. 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 */
  92038. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92039. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92040. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92041. #endif
  92042. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92043. unsigned rice_parameter;
  92044. unsigned _candidate_bits, _best_bits;
  92045. unsigned _best_subframe;
  92046. 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;
  92047. FLAC__ASSERT(frame_header->blocksize > 0);
  92048. _best_subframe = 0;
  92049. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92050. _best_bits = UINT_MAX;
  92051. else
  92052. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92053. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92054. unsigned signal_is_constant = false;
  92055. 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);
  92056. if(
  92057. !encoder->private_->disable_constant_subframes &&
  92058. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92059. fixed_residual_bits_per_sample[1] == 0.0
  92060. #else
  92061. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92062. #endif
  92063. ) {
  92064. unsigned i;
  92065. signal_is_constant = true;
  92066. for(i = 1; i < frame_header->blocksize; i++) {
  92067. if(integer_signal[0] != integer_signal[i]) {
  92068. signal_is_constant = false;
  92069. break;
  92070. }
  92071. }
  92072. }
  92073. if(signal_is_constant) {
  92074. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92075. if(_candidate_bits < _best_bits) {
  92076. _best_subframe = !_best_subframe;
  92077. _best_bits = _candidate_bits;
  92078. }
  92079. }
  92080. else {
  92081. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92082. if(encoder->protected_->do_exhaustive_model_search) {
  92083. min_fixed_order = 0;
  92084. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92085. }
  92086. else {
  92087. min_fixed_order = max_fixed_order = guess_fixed_order;
  92088. }
  92089. if(max_fixed_order >= frame_header->blocksize)
  92090. max_fixed_order = frame_header->blocksize - 1;
  92091. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92092. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92093. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92094. continue; /* don't even try */
  92095. 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 */
  92096. #else
  92097. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92098. continue; /* don't even try */
  92099. 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 */
  92100. #endif
  92101. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92102. if(rice_parameter >= rice_parameter_limit) {
  92103. #ifdef DEBUG_VERBOSE
  92104. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92105. #endif
  92106. rice_parameter = rice_parameter_limit - 1;
  92107. }
  92108. _candidate_bits =
  92109. evaluate_fixed_subframe_(
  92110. encoder,
  92111. integer_signal,
  92112. residual[!_best_subframe],
  92113. encoder->private_->abs_residual_partition_sums,
  92114. encoder->private_->raw_bits_per_partition,
  92115. frame_header->blocksize,
  92116. subframe_bps,
  92117. fixed_order,
  92118. rice_parameter,
  92119. rice_parameter_limit,
  92120. min_partition_order,
  92121. max_partition_order,
  92122. encoder->protected_->do_escape_coding,
  92123. encoder->protected_->rice_parameter_search_dist,
  92124. subframe[!_best_subframe],
  92125. partitioned_rice_contents[!_best_subframe]
  92126. );
  92127. if(_candidate_bits < _best_bits) {
  92128. _best_subframe = !_best_subframe;
  92129. _best_bits = _candidate_bits;
  92130. }
  92131. }
  92132. }
  92133. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92134. if(encoder->protected_->max_lpc_order > 0) {
  92135. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92136. max_lpc_order = frame_header->blocksize-1;
  92137. else
  92138. max_lpc_order = encoder->protected_->max_lpc_order;
  92139. if(max_lpc_order > 0) {
  92140. unsigned a;
  92141. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92142. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92143. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92144. if(autoc[0] != 0.0) {
  92145. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92146. if(encoder->protected_->do_exhaustive_model_search) {
  92147. min_lpc_order = 1;
  92148. }
  92149. else {
  92150. const unsigned guess_lpc_order =
  92151. FLAC__lpc_compute_best_order(
  92152. lpc_error,
  92153. max_lpc_order,
  92154. frame_header->blocksize,
  92155. subframe_bps + (
  92156. encoder->protected_->do_qlp_coeff_prec_search?
  92157. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92158. encoder->protected_->qlp_coeff_precision
  92159. )
  92160. );
  92161. min_lpc_order = max_lpc_order = guess_lpc_order;
  92162. }
  92163. if(max_lpc_order >= frame_header->blocksize)
  92164. max_lpc_order = frame_header->blocksize - 1;
  92165. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92166. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92167. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92168. continue; /* don't even try */
  92169. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92170. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92171. if(rice_parameter >= rice_parameter_limit) {
  92172. #ifdef DEBUG_VERBOSE
  92173. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92174. #endif
  92175. rice_parameter = rice_parameter_limit - 1;
  92176. }
  92177. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92178. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92179. if(subframe_bps <= 17) {
  92180. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92181. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92182. }
  92183. else
  92184. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92185. }
  92186. else {
  92187. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92188. }
  92189. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92190. _candidate_bits =
  92191. evaluate_lpc_subframe_(
  92192. encoder,
  92193. integer_signal,
  92194. residual[!_best_subframe],
  92195. encoder->private_->abs_residual_partition_sums,
  92196. encoder->private_->raw_bits_per_partition,
  92197. encoder->private_->lp_coeff[lpc_order-1],
  92198. frame_header->blocksize,
  92199. subframe_bps,
  92200. lpc_order,
  92201. qlp_coeff_precision,
  92202. rice_parameter,
  92203. rice_parameter_limit,
  92204. min_partition_order,
  92205. max_partition_order,
  92206. encoder->protected_->do_escape_coding,
  92207. encoder->protected_->rice_parameter_search_dist,
  92208. subframe[!_best_subframe],
  92209. partitioned_rice_contents[!_best_subframe]
  92210. );
  92211. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92212. if(_candidate_bits < _best_bits) {
  92213. _best_subframe = !_best_subframe;
  92214. _best_bits = _candidate_bits;
  92215. }
  92216. }
  92217. }
  92218. }
  92219. }
  92220. }
  92221. }
  92222. }
  92223. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92224. }
  92225. }
  92226. if(_best_bits == UINT_MAX) {
  92227. FLAC__ASSERT(_best_subframe == 0);
  92228. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92229. }
  92230. *best_subframe = _best_subframe;
  92231. *best_bits = _best_bits;
  92232. return true;
  92233. }
  92234. FLAC__bool add_subframe_(
  92235. FLAC__StreamEncoder *encoder,
  92236. unsigned blocksize,
  92237. unsigned subframe_bps,
  92238. const FLAC__Subframe *subframe,
  92239. FLAC__BitWriter *frame
  92240. )
  92241. {
  92242. switch(subframe->type) {
  92243. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92244. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92245. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92246. return false;
  92247. }
  92248. break;
  92249. case FLAC__SUBFRAME_TYPE_FIXED:
  92250. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92251. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92252. return false;
  92253. }
  92254. break;
  92255. case FLAC__SUBFRAME_TYPE_LPC:
  92256. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92257. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92258. return false;
  92259. }
  92260. break;
  92261. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92262. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92263. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92264. return false;
  92265. }
  92266. break;
  92267. default:
  92268. FLAC__ASSERT(0);
  92269. }
  92270. return true;
  92271. }
  92272. #define SPOTCHECK_ESTIMATE 0
  92273. #if SPOTCHECK_ESTIMATE
  92274. static void spotcheck_subframe_estimate_(
  92275. FLAC__StreamEncoder *encoder,
  92276. unsigned blocksize,
  92277. unsigned subframe_bps,
  92278. const FLAC__Subframe *subframe,
  92279. unsigned estimate
  92280. )
  92281. {
  92282. FLAC__bool ret;
  92283. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92284. if(frame == 0) {
  92285. fprintf(stderr, "EST: can't allocate frame\n");
  92286. return;
  92287. }
  92288. if(!FLAC__bitwriter_init(frame)) {
  92289. fprintf(stderr, "EST: can't init frame\n");
  92290. return;
  92291. }
  92292. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92293. FLAC__ASSERT(ret);
  92294. {
  92295. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92296. if(estimate != actual)
  92297. 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);
  92298. }
  92299. FLAC__bitwriter_delete(frame);
  92300. }
  92301. #endif
  92302. unsigned evaluate_constant_subframe_(
  92303. FLAC__StreamEncoder *encoder,
  92304. const FLAC__int32 signal,
  92305. unsigned blocksize,
  92306. unsigned subframe_bps,
  92307. FLAC__Subframe *subframe
  92308. )
  92309. {
  92310. unsigned estimate;
  92311. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92312. subframe->data.constant.value = signal;
  92313. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92314. #if SPOTCHECK_ESTIMATE
  92315. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92316. #else
  92317. (void)encoder, (void)blocksize;
  92318. #endif
  92319. return estimate;
  92320. }
  92321. unsigned evaluate_fixed_subframe_(
  92322. FLAC__StreamEncoder *encoder,
  92323. const FLAC__int32 signal[],
  92324. FLAC__int32 residual[],
  92325. FLAC__uint64 abs_residual_partition_sums[],
  92326. unsigned raw_bits_per_partition[],
  92327. unsigned blocksize,
  92328. unsigned subframe_bps,
  92329. unsigned order,
  92330. unsigned rice_parameter,
  92331. unsigned rice_parameter_limit,
  92332. unsigned min_partition_order,
  92333. unsigned max_partition_order,
  92334. FLAC__bool do_escape_coding,
  92335. unsigned rice_parameter_search_dist,
  92336. FLAC__Subframe *subframe,
  92337. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92338. )
  92339. {
  92340. unsigned i, residual_bits, estimate;
  92341. const unsigned residual_samples = blocksize - order;
  92342. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92343. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92344. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92345. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92346. subframe->data.fixed.residual = residual;
  92347. residual_bits =
  92348. find_best_partition_order_(
  92349. encoder->private_,
  92350. residual,
  92351. abs_residual_partition_sums,
  92352. raw_bits_per_partition,
  92353. residual_samples,
  92354. order,
  92355. rice_parameter,
  92356. rice_parameter_limit,
  92357. min_partition_order,
  92358. max_partition_order,
  92359. subframe_bps,
  92360. do_escape_coding,
  92361. rice_parameter_search_dist,
  92362. &subframe->data.fixed.entropy_coding_method
  92363. );
  92364. subframe->data.fixed.order = order;
  92365. for(i = 0; i < order; i++)
  92366. subframe->data.fixed.warmup[i] = signal[i];
  92367. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92368. #if SPOTCHECK_ESTIMATE
  92369. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92370. #endif
  92371. return estimate;
  92372. }
  92373. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92374. unsigned evaluate_lpc_subframe_(
  92375. FLAC__StreamEncoder *encoder,
  92376. const FLAC__int32 signal[],
  92377. FLAC__int32 residual[],
  92378. FLAC__uint64 abs_residual_partition_sums[],
  92379. unsigned raw_bits_per_partition[],
  92380. const FLAC__real lp_coeff[],
  92381. unsigned blocksize,
  92382. unsigned subframe_bps,
  92383. unsigned order,
  92384. unsigned qlp_coeff_precision,
  92385. unsigned rice_parameter,
  92386. unsigned rice_parameter_limit,
  92387. unsigned min_partition_order,
  92388. unsigned max_partition_order,
  92389. FLAC__bool do_escape_coding,
  92390. unsigned rice_parameter_search_dist,
  92391. FLAC__Subframe *subframe,
  92392. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92393. )
  92394. {
  92395. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92396. unsigned i, residual_bits, estimate;
  92397. int quantization, ret;
  92398. const unsigned residual_samples = blocksize - order;
  92399. if(subframe_bps <= 16) {
  92400. FLAC__ASSERT(order > 0);
  92401. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92402. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92403. }
  92404. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92405. if(ret != 0)
  92406. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92407. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92408. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92409. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92410. else
  92411. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92412. else
  92413. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92414. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92415. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92416. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92417. subframe->data.lpc.residual = residual;
  92418. residual_bits =
  92419. find_best_partition_order_(
  92420. encoder->private_,
  92421. residual,
  92422. abs_residual_partition_sums,
  92423. raw_bits_per_partition,
  92424. residual_samples,
  92425. order,
  92426. rice_parameter,
  92427. rice_parameter_limit,
  92428. min_partition_order,
  92429. max_partition_order,
  92430. subframe_bps,
  92431. do_escape_coding,
  92432. rice_parameter_search_dist,
  92433. &subframe->data.lpc.entropy_coding_method
  92434. );
  92435. subframe->data.lpc.order = order;
  92436. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92437. subframe->data.lpc.quantization_level = quantization;
  92438. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92439. for(i = 0; i < order; i++)
  92440. subframe->data.lpc.warmup[i] = signal[i];
  92441. 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;
  92442. #if SPOTCHECK_ESTIMATE
  92443. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92444. #endif
  92445. return estimate;
  92446. }
  92447. #endif
  92448. unsigned evaluate_verbatim_subframe_(
  92449. FLAC__StreamEncoder *encoder,
  92450. const FLAC__int32 signal[],
  92451. unsigned blocksize,
  92452. unsigned subframe_bps,
  92453. FLAC__Subframe *subframe
  92454. )
  92455. {
  92456. unsigned estimate;
  92457. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92458. subframe->data.verbatim.data = signal;
  92459. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92460. #if SPOTCHECK_ESTIMATE
  92461. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92462. #else
  92463. (void)encoder;
  92464. #endif
  92465. return estimate;
  92466. }
  92467. unsigned find_best_partition_order_(
  92468. FLAC__StreamEncoderPrivate *private_,
  92469. const FLAC__int32 residual[],
  92470. FLAC__uint64 abs_residual_partition_sums[],
  92471. unsigned raw_bits_per_partition[],
  92472. unsigned residual_samples,
  92473. unsigned predictor_order,
  92474. unsigned rice_parameter,
  92475. unsigned rice_parameter_limit,
  92476. unsigned min_partition_order,
  92477. unsigned max_partition_order,
  92478. unsigned bps,
  92479. FLAC__bool do_escape_coding,
  92480. unsigned rice_parameter_search_dist,
  92481. FLAC__EntropyCodingMethod *best_ecm
  92482. )
  92483. {
  92484. unsigned residual_bits, best_residual_bits = 0;
  92485. unsigned best_parameters_index = 0;
  92486. unsigned best_partition_order = 0;
  92487. const unsigned blocksize = residual_samples + predictor_order;
  92488. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92489. min_partition_order = min(min_partition_order, max_partition_order);
  92490. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92491. if(do_escape_coding)
  92492. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92493. {
  92494. int partition_order;
  92495. unsigned sum;
  92496. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92497. if(!
  92498. set_partitioned_rice_(
  92499. #ifdef EXACT_RICE_BITS_CALCULATION
  92500. residual,
  92501. #endif
  92502. abs_residual_partition_sums+sum,
  92503. raw_bits_per_partition+sum,
  92504. residual_samples,
  92505. predictor_order,
  92506. rice_parameter,
  92507. rice_parameter_limit,
  92508. rice_parameter_search_dist,
  92509. (unsigned)partition_order,
  92510. do_escape_coding,
  92511. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92512. &residual_bits
  92513. )
  92514. )
  92515. {
  92516. FLAC__ASSERT(best_residual_bits != 0);
  92517. break;
  92518. }
  92519. sum += 1u << partition_order;
  92520. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92521. best_residual_bits = residual_bits;
  92522. best_parameters_index = !best_parameters_index;
  92523. best_partition_order = partition_order;
  92524. }
  92525. }
  92526. }
  92527. best_ecm->data.partitioned_rice.order = best_partition_order;
  92528. {
  92529. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92530. unsigned partition;
  92531. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92532. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92533. if(do_escape_coding)
  92534. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92535. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92536. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92537. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92538. break;
  92539. }
  92540. }
  92541. }
  92542. return best_residual_bits;
  92543. }
  92544. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92545. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92546. const FLAC__int32 residual[],
  92547. FLAC__uint64 abs_residual_partition_sums[],
  92548. unsigned blocksize,
  92549. unsigned predictor_order,
  92550. unsigned min_partition_order,
  92551. unsigned max_partition_order
  92552. );
  92553. #endif
  92554. void precompute_partition_info_sums_(
  92555. const FLAC__int32 residual[],
  92556. FLAC__uint64 abs_residual_partition_sums[],
  92557. unsigned residual_samples,
  92558. unsigned predictor_order,
  92559. unsigned min_partition_order,
  92560. unsigned max_partition_order,
  92561. unsigned bps
  92562. )
  92563. {
  92564. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92565. unsigned partitions = 1u << max_partition_order;
  92566. FLAC__ASSERT(default_partition_samples > predictor_order);
  92567. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92568. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92569. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92570. return;
  92571. }
  92572. #endif
  92573. {
  92574. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92575. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92576. FLAC__uint32 abs_residual_partition_sum;
  92577. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92578. end += default_partition_samples;
  92579. abs_residual_partition_sum = 0;
  92580. for( ; residual_sample < end; residual_sample++)
  92581. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92582. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92583. }
  92584. }
  92585. else { /* have to pessimistically use 64 bits for accumulator */
  92586. FLAC__uint64 abs_residual_partition_sum;
  92587. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92588. end += default_partition_samples;
  92589. abs_residual_partition_sum = 0;
  92590. for( ; residual_sample < end; residual_sample++)
  92591. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92592. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92593. }
  92594. }
  92595. }
  92596. {
  92597. unsigned from_partition = 0, to_partition = partitions;
  92598. int partition_order;
  92599. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92600. unsigned i;
  92601. partitions >>= 1;
  92602. for(i = 0; i < partitions; i++) {
  92603. abs_residual_partition_sums[to_partition++] =
  92604. abs_residual_partition_sums[from_partition ] +
  92605. abs_residual_partition_sums[from_partition+1];
  92606. from_partition += 2;
  92607. }
  92608. }
  92609. }
  92610. }
  92611. void precompute_partition_info_escapes_(
  92612. const FLAC__int32 residual[],
  92613. unsigned raw_bits_per_partition[],
  92614. unsigned residual_samples,
  92615. unsigned predictor_order,
  92616. unsigned min_partition_order,
  92617. unsigned max_partition_order
  92618. )
  92619. {
  92620. int partition_order;
  92621. unsigned from_partition, to_partition = 0;
  92622. const unsigned blocksize = residual_samples + predictor_order;
  92623. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92624. FLAC__int32 r;
  92625. FLAC__uint32 rmax;
  92626. unsigned partition, partition_sample, partition_samples, residual_sample;
  92627. const unsigned partitions = 1u << partition_order;
  92628. const unsigned default_partition_samples = blocksize >> partition_order;
  92629. FLAC__ASSERT(default_partition_samples > predictor_order);
  92630. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92631. partition_samples = default_partition_samples;
  92632. if(partition == 0)
  92633. partition_samples -= predictor_order;
  92634. rmax = 0;
  92635. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92636. r = residual[residual_sample++];
  92637. if(r < 0)
  92638. rmax |= ~r;
  92639. else
  92640. rmax |= r;
  92641. }
  92642. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92643. }
  92644. to_partition = partitions;
  92645. break; /*@@@ yuck, should remove the 'for' loop instead */
  92646. }
  92647. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92648. unsigned m;
  92649. unsigned i;
  92650. const unsigned partitions = 1u << partition_order;
  92651. for(i = 0; i < partitions; i++) {
  92652. m = raw_bits_per_partition[from_partition];
  92653. from_partition++;
  92654. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92655. from_partition++;
  92656. to_partition++;
  92657. }
  92658. }
  92659. }
  92660. #ifdef EXACT_RICE_BITS_CALCULATION
  92661. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92662. const unsigned rice_parameter,
  92663. const unsigned partition_samples,
  92664. const FLAC__int32 *residual
  92665. )
  92666. {
  92667. unsigned i, partition_bits =
  92668. 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 */
  92669. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92670. ;
  92671. for(i = 0; i < partition_samples; i++)
  92672. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92673. return partition_bits;
  92674. }
  92675. #else
  92676. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92677. const unsigned rice_parameter,
  92678. const unsigned partition_samples,
  92679. const FLAC__uint64 abs_residual_partition_sum
  92680. )
  92681. {
  92682. return
  92683. 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 */
  92684. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92685. (
  92686. rice_parameter?
  92687. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92688. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92689. )
  92690. - (partition_samples >> 1)
  92691. ;
  92692. }
  92693. #endif
  92694. FLAC__bool set_partitioned_rice_(
  92695. #ifdef EXACT_RICE_BITS_CALCULATION
  92696. const FLAC__int32 residual[],
  92697. #endif
  92698. const FLAC__uint64 abs_residual_partition_sums[],
  92699. const unsigned raw_bits_per_partition[],
  92700. const unsigned residual_samples,
  92701. const unsigned predictor_order,
  92702. const unsigned suggested_rice_parameter,
  92703. const unsigned rice_parameter_limit,
  92704. const unsigned rice_parameter_search_dist,
  92705. const unsigned partition_order,
  92706. const FLAC__bool search_for_escapes,
  92707. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92708. unsigned *bits
  92709. )
  92710. {
  92711. unsigned rice_parameter, partition_bits;
  92712. unsigned best_partition_bits, best_rice_parameter = 0;
  92713. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92714. unsigned *parameters, *raw_bits;
  92715. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92716. unsigned min_rice_parameter, max_rice_parameter;
  92717. #else
  92718. (void)rice_parameter_search_dist;
  92719. #endif
  92720. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92721. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92722. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92723. parameters = partitioned_rice_contents->parameters;
  92724. raw_bits = partitioned_rice_contents->raw_bits;
  92725. if(partition_order == 0) {
  92726. best_partition_bits = (unsigned)(-1);
  92727. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92728. if(rice_parameter_search_dist) {
  92729. if(suggested_rice_parameter < rice_parameter_search_dist)
  92730. min_rice_parameter = 0;
  92731. else
  92732. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92733. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92734. if(max_rice_parameter >= rice_parameter_limit) {
  92735. #ifdef DEBUG_VERBOSE
  92736. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92737. #endif
  92738. max_rice_parameter = rice_parameter_limit - 1;
  92739. }
  92740. }
  92741. else
  92742. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92743. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92744. #else
  92745. rice_parameter = suggested_rice_parameter;
  92746. #endif
  92747. #ifdef EXACT_RICE_BITS_CALCULATION
  92748. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92749. #else
  92750. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92751. #endif
  92752. if(partition_bits < best_partition_bits) {
  92753. best_rice_parameter = rice_parameter;
  92754. best_partition_bits = partition_bits;
  92755. }
  92756. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92757. }
  92758. #endif
  92759. if(search_for_escapes) {
  92760. 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;
  92761. if(partition_bits <= best_partition_bits) {
  92762. raw_bits[0] = raw_bits_per_partition[0];
  92763. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92764. best_partition_bits = partition_bits;
  92765. }
  92766. else
  92767. raw_bits[0] = 0;
  92768. }
  92769. parameters[0] = best_rice_parameter;
  92770. bits_ += best_partition_bits;
  92771. }
  92772. else {
  92773. unsigned partition, residual_sample;
  92774. unsigned partition_samples;
  92775. FLAC__uint64 mean, k;
  92776. const unsigned partitions = 1u << partition_order;
  92777. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92778. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92779. if(partition == 0) {
  92780. if(partition_samples <= predictor_order)
  92781. return false;
  92782. else
  92783. partition_samples -= predictor_order;
  92784. }
  92785. mean = abs_residual_partition_sums[partition];
  92786. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92787. ;
  92788. if(rice_parameter >= rice_parameter_limit) {
  92789. #ifdef DEBUG_VERBOSE
  92790. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92791. #endif
  92792. rice_parameter = rice_parameter_limit - 1;
  92793. }
  92794. best_partition_bits = (unsigned)(-1);
  92795. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92796. if(rice_parameter_search_dist) {
  92797. if(rice_parameter < rice_parameter_search_dist)
  92798. min_rice_parameter = 0;
  92799. else
  92800. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92801. max_rice_parameter = 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) @7\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 = rice_parameter;
  92811. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92812. #endif
  92813. #ifdef EXACT_RICE_BITS_CALCULATION
  92814. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92815. #else
  92816. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92817. #endif
  92818. if(partition_bits < best_partition_bits) {
  92819. best_rice_parameter = rice_parameter;
  92820. best_partition_bits = partition_bits;
  92821. }
  92822. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92823. }
  92824. #endif
  92825. if(search_for_escapes) {
  92826. 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;
  92827. if(partition_bits <= best_partition_bits) {
  92828. raw_bits[partition] = raw_bits_per_partition[partition];
  92829. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92830. best_partition_bits = partition_bits;
  92831. }
  92832. else
  92833. raw_bits[partition] = 0;
  92834. }
  92835. parameters[partition] = best_rice_parameter;
  92836. bits_ += best_partition_bits;
  92837. residual_sample += partition_samples;
  92838. }
  92839. }
  92840. *bits = bits_;
  92841. return true;
  92842. }
  92843. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92844. {
  92845. unsigned i, shift;
  92846. FLAC__int32 x = 0;
  92847. for(i = 0; i < samples && !(x&1); i++)
  92848. x |= signal[i];
  92849. if(x == 0) {
  92850. shift = 0;
  92851. }
  92852. else {
  92853. for(shift = 0; !(x&1); shift++)
  92854. x >>= 1;
  92855. }
  92856. if(shift > 0) {
  92857. for(i = 0; i < samples; i++)
  92858. signal[i] >>= shift;
  92859. }
  92860. return shift;
  92861. }
  92862. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92863. {
  92864. unsigned channel;
  92865. for(channel = 0; channel < channels; channel++)
  92866. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92867. fifo->tail += wide_samples;
  92868. FLAC__ASSERT(fifo->tail <= fifo->size);
  92869. }
  92870. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92871. {
  92872. unsigned channel;
  92873. unsigned sample, wide_sample;
  92874. unsigned tail = fifo->tail;
  92875. sample = input_offset * channels;
  92876. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92877. for(channel = 0; channel < channels; channel++)
  92878. fifo->data[channel][tail] = input[sample++];
  92879. tail++;
  92880. }
  92881. fifo->tail = tail;
  92882. FLAC__ASSERT(fifo->tail <= fifo->size);
  92883. }
  92884. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92885. {
  92886. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92887. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92888. (void)decoder;
  92889. if(encoder->private_->verify.needs_magic_hack) {
  92890. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92891. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92892. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92893. encoder->private_->verify.needs_magic_hack = false;
  92894. }
  92895. else {
  92896. if(encoded_bytes == 0) {
  92897. FLAC__ASSERT(0);
  92898. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92899. }
  92900. else if(encoded_bytes < *bytes)
  92901. *bytes = encoded_bytes;
  92902. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92903. encoder->private_->verify.output.data += *bytes;
  92904. encoder->private_->verify.output.bytes -= *bytes;
  92905. }
  92906. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92907. }
  92908. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92909. {
  92910. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92911. unsigned channel;
  92912. const unsigned channels = frame->header.channels;
  92913. const unsigned blocksize = frame->header.blocksize;
  92914. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92915. (void)decoder;
  92916. for(channel = 0; channel < channels; channel++) {
  92917. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  92918. unsigned i, sample = 0;
  92919. FLAC__int32 expect = 0, got = 0;
  92920. for(i = 0; i < blocksize; i++) {
  92921. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  92922. sample = i;
  92923. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  92924. got = (FLAC__int32)buffer[channel][i];
  92925. break;
  92926. }
  92927. }
  92928. FLAC__ASSERT(i < blocksize);
  92929. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  92930. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  92931. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  92932. encoder->private_->verify.error_stats.channel = channel;
  92933. encoder->private_->verify.error_stats.sample = sample;
  92934. encoder->private_->verify.error_stats.expected = expect;
  92935. encoder->private_->verify.error_stats.got = got;
  92936. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  92937. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  92938. }
  92939. }
  92940. encoder->private_->verify.input_fifo.tail -= blocksize;
  92941. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  92942. for(channel = 0; channel < channels; channel++)
  92943. 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]));
  92944. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  92945. }
  92946. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  92947. {
  92948. (void)decoder, (void)metadata, (void)client_data;
  92949. }
  92950. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  92951. {
  92952. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92953. (void)decoder, (void)status;
  92954. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92955. }
  92956. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92957. {
  92958. (void)client_data;
  92959. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  92960. if (*bytes == 0) {
  92961. if (feof(encoder->private_->file))
  92962. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  92963. else if (ferror(encoder->private_->file))
  92964. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  92965. }
  92966. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  92967. }
  92968. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  92969. {
  92970. (void)client_data;
  92971. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  92972. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  92973. else
  92974. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  92975. }
  92976. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  92977. {
  92978. off_t offset;
  92979. (void)client_data;
  92980. offset = ftello(encoder->private_->file);
  92981. if(offset < 0) {
  92982. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  92983. }
  92984. else {
  92985. *absolute_byte_offset = (FLAC__uint64)offset;
  92986. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  92987. }
  92988. }
  92989. #ifdef FLAC__VALGRIND_TESTING
  92990. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  92991. {
  92992. size_t ret = fwrite(ptr, size, nmemb, stream);
  92993. if(!ferror(stream))
  92994. fflush(stream);
  92995. return ret;
  92996. }
  92997. #else
  92998. #define local__fwrite fwrite
  92999. #endif
  93000. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93001. {
  93002. (void)client_data, (void)current_frame;
  93003. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93004. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93005. #if FLAC__HAS_OGG
  93006. encoder->private_->is_ogg? true :
  93007. #endif
  93008. samples > 0
  93009. );
  93010. if(call_it) {
  93011. 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);
  93012. }
  93013. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93014. }
  93015. else
  93016. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93017. }
  93018. FILE *get_binary_stdout_(void)
  93019. {
  93020. #if defined _MSC_VER || defined __MINGW32__
  93021. _setmode(_fileno(stdout), _O_BINARY);
  93022. #elif defined __CYGWIN__
  93023. setmode(_fileno(stdout), _O_BINARY);
  93024. #elif defined __EMX__
  93025. setmode(fileno(stdout), O_BINARY);
  93026. #endif
  93027. return stdout;
  93028. }
  93029. #endif
  93030. /*** End of inlined file: stream_encoder.c ***/
  93031. /*** Start of inlined file: stream_encoder_framing.c ***/
  93032. /*** Start of inlined file: juce_FlacHeader.h ***/
  93033. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93034. // tasks..
  93035. #define VERSION "1.2.1"
  93036. #define FLAC__NO_DLL 1
  93037. #if JUCE_MSVC
  93038. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93039. #endif
  93040. #if JUCE_MAC
  93041. #define FLAC__SYS_DARWIN 1
  93042. #endif
  93043. /*** End of inlined file: juce_FlacHeader.h ***/
  93044. #if JUCE_USE_FLAC
  93045. #if HAVE_CONFIG_H
  93046. # include <config.h>
  93047. #endif
  93048. #include <stdio.h>
  93049. #include <string.h> /* for strlen() */
  93050. #ifdef max
  93051. #undef max
  93052. #endif
  93053. #define max(x,y) ((x)>(y)?(x):(y))
  93054. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93055. 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);
  93056. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93057. {
  93058. unsigned i, j;
  93059. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93060. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93061. return false;
  93062. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93063. return false;
  93064. i = metadata->length;
  93065. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93066. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93067. i -= metadata->data.vorbis_comment.vendor_string.length;
  93068. i += vendor_string_length;
  93069. }
  93070. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93071. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93072. return false;
  93073. switch(metadata->type) {
  93074. case FLAC__METADATA_TYPE_STREAMINFO:
  93075. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93076. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93077. return false;
  93078. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93079. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93080. return false;
  93081. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93082. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93083. return false;
  93084. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93085. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93086. return false;
  93087. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93088. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93089. return false;
  93090. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93091. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93092. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93093. return false;
  93094. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93095. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93096. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93097. return false;
  93098. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93099. return false;
  93100. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93101. return false;
  93102. break;
  93103. case FLAC__METADATA_TYPE_PADDING:
  93104. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93105. return false;
  93106. break;
  93107. case FLAC__METADATA_TYPE_APPLICATION:
  93108. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93109. return false;
  93110. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93111. return false;
  93112. break;
  93113. case FLAC__METADATA_TYPE_SEEKTABLE:
  93114. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93115. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93116. return false;
  93117. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93118. return false;
  93119. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93120. return false;
  93121. }
  93122. break;
  93123. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93124. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93125. return false;
  93126. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93127. return false;
  93128. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93129. return false;
  93130. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93131. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93132. return false;
  93133. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93134. return false;
  93135. }
  93136. break;
  93137. case FLAC__METADATA_TYPE_CUESHEET:
  93138. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93139. 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))
  93140. return false;
  93141. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93142. return false;
  93143. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93144. return false;
  93145. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93146. return false;
  93147. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93148. return false;
  93149. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93150. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93151. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93152. return false;
  93153. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93154. return false;
  93155. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93156. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93157. return false;
  93158. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93159. return false;
  93160. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93161. return false;
  93162. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93163. return false;
  93164. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93165. return false;
  93166. for(j = 0; j < track->num_indices; j++) {
  93167. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93168. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93169. return false;
  93170. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93171. return false;
  93172. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93173. return false;
  93174. }
  93175. }
  93176. break;
  93177. case FLAC__METADATA_TYPE_PICTURE:
  93178. {
  93179. size_t len;
  93180. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93181. return false;
  93182. len = strlen(metadata->data.picture.mime_type);
  93183. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93184. return false;
  93185. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93186. return false;
  93187. len = strlen((const char *)metadata->data.picture.description);
  93188. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93189. return false;
  93190. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93191. return false;
  93192. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93193. return false;
  93194. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93195. return false;
  93196. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93197. return false;
  93198. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93199. return false;
  93200. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93201. return false;
  93202. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93203. return false;
  93204. }
  93205. break;
  93206. default:
  93207. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93208. return false;
  93209. break;
  93210. }
  93211. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93212. return true;
  93213. }
  93214. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93215. {
  93216. unsigned u, blocksize_hint, sample_rate_hint;
  93217. FLAC__byte crc;
  93218. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93219. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93220. return false;
  93221. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93222. return false;
  93223. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93224. return false;
  93225. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93226. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93227. blocksize_hint = 0;
  93228. switch(header->blocksize) {
  93229. case 192: u = 1; break;
  93230. case 576: u = 2; break;
  93231. case 1152: u = 3; break;
  93232. case 2304: u = 4; break;
  93233. case 4608: u = 5; break;
  93234. case 256: u = 8; break;
  93235. case 512: u = 9; break;
  93236. case 1024: u = 10; break;
  93237. case 2048: u = 11; break;
  93238. case 4096: u = 12; break;
  93239. case 8192: u = 13; break;
  93240. case 16384: u = 14; break;
  93241. case 32768: u = 15; break;
  93242. default:
  93243. if(header->blocksize <= 0x100)
  93244. blocksize_hint = u = 6;
  93245. else
  93246. blocksize_hint = u = 7;
  93247. break;
  93248. }
  93249. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93250. return false;
  93251. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93252. sample_rate_hint = 0;
  93253. switch(header->sample_rate) {
  93254. case 88200: u = 1; break;
  93255. case 176400: u = 2; break;
  93256. case 192000: u = 3; break;
  93257. case 8000: u = 4; break;
  93258. case 16000: u = 5; break;
  93259. case 22050: u = 6; break;
  93260. case 24000: u = 7; break;
  93261. case 32000: u = 8; break;
  93262. case 44100: u = 9; break;
  93263. case 48000: u = 10; break;
  93264. case 96000: u = 11; break;
  93265. default:
  93266. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93267. sample_rate_hint = u = 12;
  93268. else if(header->sample_rate % 10 == 0)
  93269. sample_rate_hint = u = 14;
  93270. else if(header->sample_rate <= 0xffff)
  93271. sample_rate_hint = u = 13;
  93272. else
  93273. u = 0;
  93274. break;
  93275. }
  93276. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93277. return false;
  93278. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93279. switch(header->channel_assignment) {
  93280. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93281. u = header->channels - 1;
  93282. break;
  93283. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93284. FLAC__ASSERT(header->channels == 2);
  93285. u = 8;
  93286. break;
  93287. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93288. FLAC__ASSERT(header->channels == 2);
  93289. u = 9;
  93290. break;
  93291. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93292. FLAC__ASSERT(header->channels == 2);
  93293. u = 10;
  93294. break;
  93295. default:
  93296. FLAC__ASSERT(0);
  93297. }
  93298. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93299. return false;
  93300. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93301. switch(header->bits_per_sample) {
  93302. case 8 : u = 1; break;
  93303. case 12: u = 2; break;
  93304. case 16: u = 4; break;
  93305. case 20: u = 5; break;
  93306. case 24: u = 6; break;
  93307. default: u = 0; break;
  93308. }
  93309. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93310. return false;
  93311. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93312. return false;
  93313. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93314. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93315. return false;
  93316. }
  93317. else {
  93318. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93319. return false;
  93320. }
  93321. if(blocksize_hint)
  93322. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93323. return false;
  93324. switch(sample_rate_hint) {
  93325. case 12:
  93326. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93327. return false;
  93328. break;
  93329. case 13:
  93330. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93331. return false;
  93332. break;
  93333. case 14:
  93334. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93335. return false;
  93336. break;
  93337. }
  93338. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93339. return false;
  93340. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93341. return false;
  93342. return true;
  93343. }
  93344. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93345. {
  93346. FLAC__bool ok;
  93347. ok =
  93348. 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) &&
  93349. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93350. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93351. ;
  93352. return ok;
  93353. }
  93354. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93355. {
  93356. unsigned i;
  93357. 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))
  93358. return false;
  93359. if(wasted_bits)
  93360. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93361. return false;
  93362. for(i = 0; i < subframe->order; i++)
  93363. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93364. return false;
  93365. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93366. return false;
  93367. switch(subframe->entropy_coding_method.type) {
  93368. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93369. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93370. if(!add_residual_partitioned_rice_(
  93371. bw,
  93372. subframe->residual,
  93373. residual_samples,
  93374. subframe->order,
  93375. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93376. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93377. subframe->entropy_coding_method.data.partitioned_rice.order,
  93378. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93379. ))
  93380. return false;
  93381. break;
  93382. default:
  93383. FLAC__ASSERT(0);
  93384. }
  93385. return true;
  93386. }
  93387. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93388. {
  93389. unsigned i;
  93390. 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))
  93391. return false;
  93392. if(wasted_bits)
  93393. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93394. return false;
  93395. for(i = 0; i < subframe->order; i++)
  93396. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93397. return false;
  93398. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93399. return false;
  93400. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93401. return false;
  93402. for(i = 0; i < subframe->order; i++)
  93403. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93404. return false;
  93405. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93406. return false;
  93407. switch(subframe->entropy_coding_method.type) {
  93408. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93409. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93410. if(!add_residual_partitioned_rice_(
  93411. bw,
  93412. subframe->residual,
  93413. residual_samples,
  93414. subframe->order,
  93415. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93416. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93417. subframe->entropy_coding_method.data.partitioned_rice.order,
  93418. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93419. ))
  93420. return false;
  93421. break;
  93422. default:
  93423. FLAC__ASSERT(0);
  93424. }
  93425. return true;
  93426. }
  93427. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93428. {
  93429. unsigned i;
  93430. const FLAC__int32 *signal = subframe->data;
  93431. 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))
  93432. return false;
  93433. if(wasted_bits)
  93434. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93435. return false;
  93436. for(i = 0; i < samples; i++)
  93437. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93438. return false;
  93439. return true;
  93440. }
  93441. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93442. {
  93443. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93444. return false;
  93445. switch(method->type) {
  93446. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93447. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93448. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93449. return false;
  93450. break;
  93451. default:
  93452. FLAC__ASSERT(0);
  93453. }
  93454. return true;
  93455. }
  93456. 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)
  93457. {
  93458. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93459. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93460. if(partition_order == 0) {
  93461. unsigned i;
  93462. if(raw_bits[0] == 0) {
  93463. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93464. return false;
  93465. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93466. return false;
  93467. }
  93468. else {
  93469. FLAC__ASSERT(rice_parameters[0] == 0);
  93470. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93471. return false;
  93472. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93473. return false;
  93474. for(i = 0; i < residual_samples; i++) {
  93475. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93476. return false;
  93477. }
  93478. }
  93479. return true;
  93480. }
  93481. else {
  93482. unsigned i, j, k = 0, k_last = 0;
  93483. unsigned partition_samples;
  93484. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93485. for(i = 0; i < (1u<<partition_order); i++) {
  93486. partition_samples = default_partition_samples;
  93487. if(i == 0)
  93488. partition_samples -= predictor_order;
  93489. k += partition_samples;
  93490. if(raw_bits[i] == 0) {
  93491. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93492. return false;
  93493. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93494. return false;
  93495. }
  93496. else {
  93497. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93498. return false;
  93499. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93500. return false;
  93501. for(j = k_last; j < k; j++) {
  93502. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93503. return false;
  93504. }
  93505. }
  93506. k_last = k;
  93507. }
  93508. return true;
  93509. }
  93510. }
  93511. #endif
  93512. /*** End of inlined file: stream_encoder_framing.c ***/
  93513. /*** Start of inlined file: window_flac.c ***/
  93514. /*** Start of inlined file: juce_FlacHeader.h ***/
  93515. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93516. // tasks..
  93517. #define VERSION "1.2.1"
  93518. #define FLAC__NO_DLL 1
  93519. #if JUCE_MSVC
  93520. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93521. #endif
  93522. #if JUCE_MAC
  93523. #define FLAC__SYS_DARWIN 1
  93524. #endif
  93525. /*** End of inlined file: juce_FlacHeader.h ***/
  93526. #if JUCE_USE_FLAC
  93527. #if HAVE_CONFIG_H
  93528. # include <config.h>
  93529. #endif
  93530. #include <math.h>
  93531. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93532. #ifndef M_PI
  93533. #define M_PI 3.14159265358979323846
  93534. #endif
  93535. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93536. {
  93537. const FLAC__int32 N = L - 1;
  93538. FLAC__int32 n;
  93539. if (L & 1) {
  93540. for (n = 0; n <= N/2; n++)
  93541. window[n] = 2.0f * n / (float)N;
  93542. for (; n <= N; n++)
  93543. window[n] = 2.0f - 2.0f * n / (float)N;
  93544. }
  93545. else {
  93546. for (n = 0; n <= L/2-1; n++)
  93547. window[n] = 2.0f * n / (float)N;
  93548. for (; n <= N; n++)
  93549. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93550. }
  93551. }
  93552. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93553. {
  93554. const FLAC__int32 N = L - 1;
  93555. FLAC__int32 n;
  93556. for (n = 0; n < L; n++)
  93557. 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)));
  93558. }
  93559. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93560. {
  93561. const FLAC__int32 N = L - 1;
  93562. FLAC__int32 n;
  93563. for (n = 0; n < L; n++)
  93564. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93565. }
  93566. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93567. {
  93568. const FLAC__int32 N = L - 1;
  93569. FLAC__int32 n;
  93570. for (n = 0; n <= N; n++)
  93571. 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));
  93572. }
  93573. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93574. {
  93575. const FLAC__int32 N = L - 1;
  93576. const double N2 = (double)N / 2.;
  93577. FLAC__int32 n;
  93578. for (n = 0; n <= N; n++) {
  93579. double k = ((double)n - N2) / N2;
  93580. k = 1.0f - k * k;
  93581. window[n] = (FLAC__real)(k * k);
  93582. }
  93583. }
  93584. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93585. {
  93586. const FLAC__int32 N = L - 1;
  93587. FLAC__int32 n;
  93588. for (n = 0; n < L; n++)
  93589. 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));
  93590. }
  93591. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93592. {
  93593. const FLAC__int32 N = L - 1;
  93594. const double N2 = (double)N / 2.;
  93595. FLAC__int32 n;
  93596. for (n = 0; n <= N; n++) {
  93597. const double k = ((double)n - N2) / (stddev * N2);
  93598. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93599. }
  93600. }
  93601. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93602. {
  93603. const FLAC__int32 N = L - 1;
  93604. FLAC__int32 n;
  93605. for (n = 0; n < L; n++)
  93606. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93607. }
  93608. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93609. {
  93610. const FLAC__int32 N = L - 1;
  93611. FLAC__int32 n;
  93612. for (n = 0; n < L; n++)
  93613. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93614. }
  93615. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93616. {
  93617. const FLAC__int32 N = L - 1;
  93618. FLAC__int32 n;
  93619. for (n = 0; n < L; n++)
  93620. 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));
  93621. }
  93622. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93623. {
  93624. const FLAC__int32 N = L - 1;
  93625. FLAC__int32 n;
  93626. for (n = 0; n < L; n++)
  93627. 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));
  93628. }
  93629. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93630. {
  93631. FLAC__int32 n;
  93632. for (n = 0; n < L; n++)
  93633. window[n] = 1.0f;
  93634. }
  93635. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93636. {
  93637. FLAC__int32 n;
  93638. if (L & 1) {
  93639. for (n = 1; n <= L+1/2; n++)
  93640. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93641. for (; n <= L; n++)
  93642. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93643. }
  93644. else {
  93645. for (n = 1; n <= L/2; n++)
  93646. window[n-1] = 2.0f * n / (float)L;
  93647. for (; n <= L; n++)
  93648. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93649. }
  93650. }
  93651. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93652. {
  93653. if (p <= 0.0)
  93654. FLAC__window_rectangle(window, L);
  93655. else if (p >= 1.0)
  93656. FLAC__window_hann(window, L);
  93657. else {
  93658. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93659. FLAC__int32 n;
  93660. FLAC__window_rectangle(window, L);
  93661. if (Np > 0) {
  93662. for (n = 0; n <= Np; n++) {
  93663. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93664. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93665. }
  93666. }
  93667. }
  93668. }
  93669. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93670. {
  93671. const FLAC__int32 N = L - 1;
  93672. const double N2 = (double)N / 2.;
  93673. FLAC__int32 n;
  93674. for (n = 0; n <= N; n++) {
  93675. const double k = ((double)n - N2) / N2;
  93676. window[n] = (FLAC__real)(1.0f - k * k);
  93677. }
  93678. }
  93679. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93680. #endif
  93681. /*** End of inlined file: window_flac.c ***/
  93682. #else
  93683. #include <FLAC/all.h>
  93684. #endif
  93685. }
  93686. #undef max
  93687. #undef min
  93688. #ifdef _MSC_VER
  93689. #pragma warning (pop)
  93690. #endif
  93691. BEGIN_JUCE_NAMESPACE
  93692. static const char* const flacFormatName = "FLAC file";
  93693. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93694. class FlacReader : public AudioFormatReader
  93695. {
  93696. public:
  93697. FlacReader (InputStream* const in)
  93698. : AudioFormatReader (in, TRANS (flacFormatName)),
  93699. reservoir (2, 0),
  93700. reservoirStart (0),
  93701. samplesInReservoir (0),
  93702. scanningForLength (false)
  93703. {
  93704. using namespace FlacNamespace;
  93705. lengthInSamples = 0;
  93706. decoder = FLAC__stream_decoder_new();
  93707. ok = FLAC__stream_decoder_init_stream (decoder,
  93708. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93709. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93710. this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93711. if (ok)
  93712. {
  93713. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93714. if (lengthInSamples == 0 && sampleRate > 0)
  93715. {
  93716. // the length hasn't been stored in the metadata, so we'll need to
  93717. // work it out the length the hard way, by scanning the whole file..
  93718. scanningForLength = true;
  93719. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93720. scanningForLength = false;
  93721. const int64 tempLength = lengthInSamples;
  93722. FLAC__stream_decoder_reset (decoder);
  93723. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93724. lengthInSamples = tempLength;
  93725. }
  93726. }
  93727. }
  93728. ~FlacReader()
  93729. {
  93730. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93731. }
  93732. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93733. {
  93734. sampleRate = info.sample_rate;
  93735. bitsPerSample = info.bits_per_sample;
  93736. lengthInSamples = (unsigned int) info.total_samples;
  93737. numChannels = info.channels;
  93738. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93739. }
  93740. // returns the number of samples read
  93741. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93742. int64 startSampleInFile, int numSamples)
  93743. {
  93744. using namespace FlacNamespace;
  93745. if (! ok)
  93746. return false;
  93747. while (numSamples > 0)
  93748. {
  93749. if (startSampleInFile >= reservoirStart
  93750. && startSampleInFile < reservoirStart + samplesInReservoir)
  93751. {
  93752. const int num = (int) jmin ((int64) numSamples,
  93753. reservoirStart + samplesInReservoir - startSampleInFile);
  93754. jassert (num > 0);
  93755. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93756. if (destSamples[i] != 0)
  93757. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93758. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93759. sizeof (int) * num);
  93760. startOffsetInDestBuffer += num;
  93761. startSampleInFile += num;
  93762. numSamples -= num;
  93763. }
  93764. else
  93765. {
  93766. if (startSampleInFile >= (int) lengthInSamples)
  93767. {
  93768. samplesInReservoir = 0;
  93769. }
  93770. else if (startSampleInFile < reservoirStart
  93771. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93772. {
  93773. // had some problems with flac crashing if the read pos is aligned more
  93774. // accurately than this. Probably fixed in newer versions of the library, though.
  93775. reservoirStart = (int) (startSampleInFile & ~511);
  93776. samplesInReservoir = 0;
  93777. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93778. }
  93779. else
  93780. {
  93781. reservoirStart += samplesInReservoir;
  93782. samplesInReservoir = 0;
  93783. FLAC__stream_decoder_process_single (decoder);
  93784. }
  93785. if (samplesInReservoir == 0)
  93786. break;
  93787. }
  93788. }
  93789. if (numSamples > 0)
  93790. {
  93791. for (int i = numDestChannels; --i >= 0;)
  93792. if (destSamples[i] != 0)
  93793. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93794. sizeof (int) * numSamples);
  93795. }
  93796. return true;
  93797. }
  93798. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93799. {
  93800. if (scanningForLength)
  93801. {
  93802. lengthInSamples += numSamples;
  93803. }
  93804. else
  93805. {
  93806. if (numSamples > reservoir.getNumSamples())
  93807. reservoir.setSize (numChannels, numSamples, false, false, true);
  93808. const int bitsToShift = 32 - bitsPerSample;
  93809. for (int i = 0; i < (int) numChannels; ++i)
  93810. {
  93811. const FlacNamespace::FLAC__int32* src = buffer[i];
  93812. int n = i;
  93813. while (src == 0 && n > 0)
  93814. src = buffer [--n];
  93815. if (src != 0)
  93816. {
  93817. int* dest = (int*) reservoir.getSampleData(i);
  93818. for (int j = 0; j < numSamples; ++j)
  93819. dest[j] = src[j] << bitsToShift;
  93820. }
  93821. }
  93822. samplesInReservoir = numSamples;
  93823. }
  93824. }
  93825. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93826. {
  93827. using namespace FlacNamespace;
  93828. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93829. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93830. }
  93831. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93832. {
  93833. using namespace FlacNamespace;
  93834. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93835. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93836. }
  93837. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93838. {
  93839. using namespace FlacNamespace;
  93840. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93841. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93842. }
  93843. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93844. {
  93845. using namespace FlacNamespace;
  93846. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93847. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93848. }
  93849. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93850. {
  93851. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93852. }
  93853. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93854. const FlacNamespace::FLAC__Frame* frame,
  93855. const FlacNamespace::FLAC__int32* const buffer[],
  93856. void* client_data)
  93857. {
  93858. using namespace FlacNamespace;
  93859. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93860. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93861. }
  93862. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93863. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93864. void* client_data)
  93865. {
  93866. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93867. }
  93868. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93869. {
  93870. }
  93871. juce_UseDebuggingNewOperator
  93872. private:
  93873. FlacNamespace::FLAC__StreamDecoder* decoder;
  93874. AudioSampleBuffer reservoir;
  93875. int reservoirStart, samplesInReservoir;
  93876. bool ok, scanningForLength;
  93877. FlacReader (const FlacReader&);
  93878. FlacReader& operator= (const FlacReader&);
  93879. };
  93880. class FlacWriter : public AudioFormatWriter
  93881. {
  93882. public:
  93883. FlacWriter (OutputStream* const out,
  93884. const double sampleRate_,
  93885. const int numChannels_,
  93886. const int bitsPerSample_)
  93887. : AudioFormatWriter (out, TRANS (flacFormatName),
  93888. sampleRate_,
  93889. numChannels_,
  93890. bitsPerSample_)
  93891. {
  93892. using namespace FlacNamespace;
  93893. encoder = FLAC__stream_encoder_new();
  93894. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93895. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93896. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93897. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93898. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93899. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93900. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93901. ok = FLAC__stream_encoder_init_stream (encoder,
  93902. encodeWriteCallback, encodeSeekCallback,
  93903. encodeTellCallback, encodeMetadataCallback,
  93904. this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93905. }
  93906. ~FlacWriter()
  93907. {
  93908. if (ok)
  93909. {
  93910. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93911. output->flush();
  93912. }
  93913. else
  93914. {
  93915. output = 0; // to stop the base class deleting this, as it needs to be returned
  93916. // to the caller of createWriter()
  93917. }
  93918. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  93919. }
  93920. bool write (const int** samplesToWrite, int numSamples)
  93921. {
  93922. using namespace FlacNamespace;
  93923. if (! ok)
  93924. return false;
  93925. int* buf[3];
  93926. const int bitsToShift = 32 - bitsPerSample;
  93927. if (bitsToShift > 0)
  93928. {
  93929. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  93930. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  93931. buf[0] = (int*) temp.getData();
  93932. buf[1] = buf[0] + numSamples;
  93933. buf[2] = 0;
  93934. for (int i = numChannelsToWrite; --i >= 0;)
  93935. {
  93936. if (samplesToWrite[i] != 0)
  93937. {
  93938. for (int j = 0; j < numSamples; ++j)
  93939. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  93940. }
  93941. }
  93942. samplesToWrite = (const int**) buf;
  93943. }
  93944. return FLAC__stream_encoder_process (encoder,
  93945. (const FLAC__int32**) samplesToWrite,
  93946. numSamples) != 0;
  93947. }
  93948. bool writeData (const void* const data, const int size) const
  93949. {
  93950. return output->write (data, size);
  93951. }
  93952. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  93953. {
  93954. using namespace FlacNamespace;
  93955. b += bytes;
  93956. for (int i = 0; i < bytes; ++i)
  93957. {
  93958. *(--b) = (FLAC__byte) (val & 0xff);
  93959. val >>= 8;
  93960. }
  93961. }
  93962. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  93963. {
  93964. using namespace FlacNamespace;
  93965. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  93966. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  93967. const unsigned int channelsMinus1 = info.channels - 1;
  93968. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  93969. packUint32 (info.min_blocksize, buffer, 2);
  93970. packUint32 (info.max_blocksize, buffer + 2, 2);
  93971. packUint32 (info.min_framesize, buffer + 4, 3);
  93972. packUint32 (info.max_framesize, buffer + 7, 3);
  93973. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  93974. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  93975. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  93976. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  93977. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  93978. memcpy (buffer + 18, info.md5sum, 16);
  93979. const bool seekOk = output->setPosition (4);
  93980. (void) seekOk;
  93981. // if this fails, you've given it an output stream that can't seek! It needs
  93982. // to be able to seek back to write the header
  93983. jassert (seekOk);
  93984. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93985. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93986. }
  93987. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  93988. const FlacNamespace::FLAC__byte buffer[],
  93989. size_t bytes,
  93990. unsigned int /*samples*/,
  93991. unsigned int /*current_frame*/,
  93992. void* client_data)
  93993. {
  93994. using namespace FlacNamespace;
  93995. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  93996. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  93997. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93998. }
  93999. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94000. {
  94001. using namespace FlacNamespace;
  94002. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94003. }
  94004. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94005. {
  94006. using namespace FlacNamespace;
  94007. if (client_data == 0)
  94008. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94009. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  94010. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94011. }
  94012. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  94013. {
  94014. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  94015. }
  94016. juce_UseDebuggingNewOperator
  94017. bool ok;
  94018. private:
  94019. FlacNamespace::FLAC__StreamEncoder* encoder;
  94020. MemoryBlock temp;
  94021. FlacWriter (const FlacWriter&);
  94022. FlacWriter& operator= (const FlacWriter&);
  94023. };
  94024. FlacAudioFormat::FlacAudioFormat()
  94025. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94026. {
  94027. }
  94028. FlacAudioFormat::~FlacAudioFormat()
  94029. {
  94030. }
  94031. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94032. {
  94033. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94034. return Array <int> (rates);
  94035. }
  94036. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94037. {
  94038. const int depths[] = { 16, 24, 0 };
  94039. return Array <int> (depths);
  94040. }
  94041. bool FlacAudioFormat::canDoStereo()
  94042. {
  94043. return true;
  94044. }
  94045. bool FlacAudioFormat::canDoMono()
  94046. {
  94047. return true;
  94048. }
  94049. bool FlacAudioFormat::isCompressed()
  94050. {
  94051. return true;
  94052. }
  94053. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94054. const bool deleteStreamIfOpeningFails)
  94055. {
  94056. ScopedPointer<FlacReader> r (new FlacReader (in));
  94057. if (r->sampleRate != 0)
  94058. return r.release();
  94059. if (! deleteStreamIfOpeningFails)
  94060. r->input = 0;
  94061. return 0;
  94062. }
  94063. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94064. double sampleRate,
  94065. unsigned int numberOfChannels,
  94066. int bitsPerSample,
  94067. const StringPairArray& /*metadataValues*/,
  94068. int /*qualityOptionIndex*/)
  94069. {
  94070. if (getPossibleBitDepths().contains (bitsPerSample))
  94071. {
  94072. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94073. if (w->ok)
  94074. return w.release();
  94075. }
  94076. return 0;
  94077. }
  94078. END_JUCE_NAMESPACE
  94079. #endif
  94080. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94081. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94082. #if JUCE_USE_OGGVORBIS
  94083. #if JUCE_MAC
  94084. #define __MACOSX__ 1
  94085. #endif
  94086. namespace OggVorbisNamespace
  94087. {
  94088. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94089. /*** Start of inlined file: vorbisenc.h ***/
  94090. #ifndef _OV_ENC_H_
  94091. #define _OV_ENC_H_
  94092. #ifdef __cplusplus
  94093. extern "C"
  94094. {
  94095. #endif /* __cplusplus */
  94096. /*** Start of inlined file: codec.h ***/
  94097. #ifndef _vorbis_codec_h_
  94098. #define _vorbis_codec_h_
  94099. #ifdef __cplusplus
  94100. extern "C"
  94101. {
  94102. #endif /* __cplusplus */
  94103. /*** Start of inlined file: ogg.h ***/
  94104. #ifndef _OGG_H
  94105. #define _OGG_H
  94106. #ifdef __cplusplus
  94107. extern "C" {
  94108. #endif
  94109. /*** Start of inlined file: os_types.h ***/
  94110. #ifndef _OS_TYPES_H
  94111. #define _OS_TYPES_H
  94112. #define _ogg_malloc malloc
  94113. #define _ogg_calloc calloc
  94114. #define _ogg_realloc realloc
  94115. #define _ogg_free free
  94116. #if defined(_WIN32)
  94117. # if defined(__CYGWIN__)
  94118. # include <_G_config.h>
  94119. typedef _G_int64_t ogg_int64_t;
  94120. typedef _G_int32_t ogg_int32_t;
  94121. typedef _G_uint32_t ogg_uint32_t;
  94122. typedef _G_int16_t ogg_int16_t;
  94123. typedef _G_uint16_t ogg_uint16_t;
  94124. # elif defined(__MINGW32__)
  94125. typedef short ogg_int16_t;
  94126. typedef unsigned short ogg_uint16_t;
  94127. typedef int ogg_int32_t;
  94128. typedef unsigned int ogg_uint32_t;
  94129. typedef long long ogg_int64_t;
  94130. typedef unsigned long long ogg_uint64_t;
  94131. # elif defined(__MWERKS__)
  94132. typedef long long ogg_int64_t;
  94133. typedef int ogg_int32_t;
  94134. typedef unsigned int ogg_uint32_t;
  94135. typedef short ogg_int16_t;
  94136. typedef unsigned short ogg_uint16_t;
  94137. # else
  94138. typedef __int64 ogg_int64_t;
  94139. typedef __int32 ogg_int32_t;
  94140. typedef unsigned __int32 ogg_uint32_t;
  94141. typedef __int16 ogg_int16_t;
  94142. typedef unsigned __int16 ogg_uint16_t;
  94143. # endif
  94144. #elif defined(__MACOS__)
  94145. # include <sys/types.h>
  94146. typedef SInt16 ogg_int16_t;
  94147. typedef UInt16 ogg_uint16_t;
  94148. typedef SInt32 ogg_int32_t;
  94149. typedef UInt32 ogg_uint32_t;
  94150. typedef SInt64 ogg_int64_t;
  94151. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94152. # include <sys/types.h>
  94153. typedef int16_t ogg_int16_t;
  94154. typedef u_int16_t ogg_uint16_t;
  94155. typedef int32_t ogg_int32_t;
  94156. typedef u_int32_t ogg_uint32_t;
  94157. typedef int64_t ogg_int64_t;
  94158. #elif defined(__BEOS__)
  94159. # include <inttypes.h>
  94160. typedef int16_t ogg_int16_t;
  94161. typedef u_int16_t ogg_uint16_t;
  94162. typedef int32_t ogg_int32_t;
  94163. typedef u_int32_t ogg_uint32_t;
  94164. typedef int64_t ogg_int64_t;
  94165. #elif defined (__EMX__)
  94166. typedef short ogg_int16_t;
  94167. typedef unsigned short ogg_uint16_t;
  94168. typedef int ogg_int32_t;
  94169. typedef unsigned int ogg_uint32_t;
  94170. typedef long long ogg_int64_t;
  94171. #elif defined (DJGPP)
  94172. typedef short ogg_int16_t;
  94173. typedef int ogg_int32_t;
  94174. typedef unsigned int ogg_uint32_t;
  94175. typedef long long ogg_int64_t;
  94176. #elif defined(R5900)
  94177. typedef long ogg_int64_t;
  94178. typedef int ogg_int32_t;
  94179. typedef unsigned ogg_uint32_t;
  94180. typedef short ogg_int16_t;
  94181. #elif defined(__SYMBIAN32__)
  94182. typedef signed short ogg_int16_t;
  94183. typedef unsigned short ogg_uint16_t;
  94184. typedef signed int ogg_int32_t;
  94185. typedef unsigned int ogg_uint32_t;
  94186. typedef long long int ogg_int64_t;
  94187. #else
  94188. # include <sys/types.h>
  94189. /*** Start of inlined file: config_types.h ***/
  94190. #ifndef __CONFIG_TYPES_H__
  94191. #define __CONFIG_TYPES_H__
  94192. typedef int16_t ogg_int16_t;
  94193. typedef unsigned short ogg_uint16_t;
  94194. typedef int32_t ogg_int32_t;
  94195. typedef unsigned int ogg_uint32_t;
  94196. typedef int64_t ogg_int64_t;
  94197. #endif
  94198. /*** End of inlined file: config_types.h ***/
  94199. #endif
  94200. #endif /* _OS_TYPES_H */
  94201. /*** End of inlined file: os_types.h ***/
  94202. typedef struct {
  94203. long endbyte;
  94204. int endbit;
  94205. unsigned char *buffer;
  94206. unsigned char *ptr;
  94207. long storage;
  94208. } oggpack_buffer;
  94209. typedef struct {
  94210. unsigned char *header;
  94211. long header_len;
  94212. unsigned char *body;
  94213. long body_len;
  94214. } ogg_page;
  94215. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94216. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94217. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94218. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94219. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94220. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94221. }
  94222. typedef struct {
  94223. unsigned char *body_data; /* bytes from packet bodies */
  94224. long body_storage; /* storage elements allocated */
  94225. long body_fill; /* elements stored; fill mark */
  94226. long body_returned; /* elements of fill returned */
  94227. int *lacing_vals; /* The values that will go to the segment table */
  94228. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94229. this way, but it is simple coupled to the
  94230. lacing fifo */
  94231. long lacing_storage;
  94232. long lacing_fill;
  94233. long lacing_packet;
  94234. long lacing_returned;
  94235. unsigned char header[282]; /* working space for header encode */
  94236. int header_fill;
  94237. int e_o_s; /* set when we have buffered the last packet in the
  94238. logical bitstream */
  94239. int b_o_s; /* set after we've written the initial page
  94240. of a logical bitstream */
  94241. long serialno;
  94242. long pageno;
  94243. ogg_int64_t packetno; /* sequence number for decode; the framing
  94244. knows where there's a hole in the data,
  94245. but we need coupling so that the codec
  94246. (which is in a seperate abstraction
  94247. layer) also knows about the gap */
  94248. ogg_int64_t granulepos;
  94249. } ogg_stream_state;
  94250. typedef struct {
  94251. unsigned char *packet;
  94252. long bytes;
  94253. long b_o_s;
  94254. long e_o_s;
  94255. ogg_int64_t granulepos;
  94256. ogg_int64_t packetno; /* sequence number for decode; the framing
  94257. knows where there's a hole in the data,
  94258. but we need coupling so that the codec
  94259. (which is in a seperate abstraction
  94260. layer) also knows about the gap */
  94261. } ogg_packet;
  94262. typedef struct {
  94263. unsigned char *data;
  94264. int storage;
  94265. int fill;
  94266. int returned;
  94267. int unsynced;
  94268. int headerbytes;
  94269. int bodybytes;
  94270. } ogg_sync_state;
  94271. extern void oggpack_writeinit(oggpack_buffer *b);
  94272. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94273. extern void oggpack_writealign(oggpack_buffer *b);
  94274. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94275. extern void oggpack_reset(oggpack_buffer *b);
  94276. extern void oggpack_writeclear(oggpack_buffer *b);
  94277. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94278. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94279. extern long oggpack_look(oggpack_buffer *b,int bits);
  94280. extern long oggpack_look1(oggpack_buffer *b);
  94281. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94282. extern void oggpack_adv1(oggpack_buffer *b);
  94283. extern long oggpack_read(oggpack_buffer *b,int bits);
  94284. extern long oggpack_read1(oggpack_buffer *b);
  94285. extern long oggpack_bytes(oggpack_buffer *b);
  94286. extern long oggpack_bits(oggpack_buffer *b);
  94287. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94288. extern void oggpackB_writeinit(oggpack_buffer *b);
  94289. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94290. extern void oggpackB_writealign(oggpack_buffer *b);
  94291. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94292. extern void oggpackB_reset(oggpack_buffer *b);
  94293. extern void oggpackB_writeclear(oggpack_buffer *b);
  94294. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94295. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94296. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94297. extern long oggpackB_look1(oggpack_buffer *b);
  94298. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94299. extern void oggpackB_adv1(oggpack_buffer *b);
  94300. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94301. extern long oggpackB_read1(oggpack_buffer *b);
  94302. extern long oggpackB_bytes(oggpack_buffer *b);
  94303. extern long oggpackB_bits(oggpack_buffer *b);
  94304. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94305. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94306. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94307. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94308. extern int ogg_sync_init(ogg_sync_state *oy);
  94309. extern int ogg_sync_clear(ogg_sync_state *oy);
  94310. extern int ogg_sync_reset(ogg_sync_state *oy);
  94311. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94312. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94313. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94314. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94315. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94316. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94317. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94318. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94319. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94320. extern int ogg_stream_clear(ogg_stream_state *os);
  94321. extern int ogg_stream_reset(ogg_stream_state *os);
  94322. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94323. extern int ogg_stream_destroy(ogg_stream_state *os);
  94324. extern int ogg_stream_eos(ogg_stream_state *os);
  94325. extern void ogg_page_checksum_set(ogg_page *og);
  94326. extern int ogg_page_version(ogg_page *og);
  94327. extern int ogg_page_continued(ogg_page *og);
  94328. extern int ogg_page_bos(ogg_page *og);
  94329. extern int ogg_page_eos(ogg_page *og);
  94330. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94331. extern int ogg_page_serialno(ogg_page *og);
  94332. extern long ogg_page_pageno(ogg_page *og);
  94333. extern int ogg_page_packets(ogg_page *og);
  94334. extern void ogg_packet_clear(ogg_packet *op);
  94335. #ifdef __cplusplus
  94336. }
  94337. #endif
  94338. #endif /* _OGG_H */
  94339. /*** End of inlined file: ogg.h ***/
  94340. typedef struct vorbis_info{
  94341. int version;
  94342. int channels;
  94343. long rate;
  94344. long bitrate_upper;
  94345. long bitrate_nominal;
  94346. long bitrate_lower;
  94347. long bitrate_window;
  94348. void *codec_setup;
  94349. } vorbis_info;
  94350. typedef struct vorbis_dsp_state{
  94351. int analysisp;
  94352. vorbis_info *vi;
  94353. float **pcm;
  94354. float **pcmret;
  94355. int pcm_storage;
  94356. int pcm_current;
  94357. int pcm_returned;
  94358. int preextrapolate;
  94359. int eofflag;
  94360. long lW;
  94361. long W;
  94362. long nW;
  94363. long centerW;
  94364. ogg_int64_t granulepos;
  94365. ogg_int64_t sequence;
  94366. ogg_int64_t glue_bits;
  94367. ogg_int64_t time_bits;
  94368. ogg_int64_t floor_bits;
  94369. ogg_int64_t res_bits;
  94370. void *backend_state;
  94371. } vorbis_dsp_state;
  94372. typedef struct vorbis_block{
  94373. float **pcm; /* this is a pointer into local storage */
  94374. oggpack_buffer opb;
  94375. long lW;
  94376. long W;
  94377. long nW;
  94378. int pcmend;
  94379. int mode;
  94380. int eofflag;
  94381. ogg_int64_t granulepos;
  94382. ogg_int64_t sequence;
  94383. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94384. void *localstore;
  94385. long localtop;
  94386. long localalloc;
  94387. long totaluse;
  94388. struct alloc_chain *reap;
  94389. long glue_bits;
  94390. long time_bits;
  94391. long floor_bits;
  94392. long res_bits;
  94393. void *internal;
  94394. } vorbis_block;
  94395. struct alloc_chain{
  94396. void *ptr;
  94397. struct alloc_chain *next;
  94398. };
  94399. typedef struct vorbis_comment{
  94400. char **user_comments;
  94401. int *comment_lengths;
  94402. int comments;
  94403. char *vendor;
  94404. } vorbis_comment;
  94405. extern void vorbis_info_init(vorbis_info *vi);
  94406. extern void vorbis_info_clear(vorbis_info *vi);
  94407. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94408. extern void vorbis_comment_init(vorbis_comment *vc);
  94409. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94410. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94411. const char *tag, char *contents);
  94412. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94413. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94414. extern void vorbis_comment_clear(vorbis_comment *vc);
  94415. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94416. extern int vorbis_block_clear(vorbis_block *vb);
  94417. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94418. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94419. ogg_int64_t granulepos);
  94420. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94421. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94422. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94423. vorbis_comment *vc,
  94424. ogg_packet *op,
  94425. ogg_packet *op_comm,
  94426. ogg_packet *op_code);
  94427. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94428. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94429. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94430. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94431. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94432. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94433. ogg_packet *op);
  94434. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94435. ogg_packet *op);
  94436. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94437. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94438. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94439. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94440. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94441. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94442. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94443. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94444. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94445. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94446. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94447. #define OV_FALSE -1
  94448. #define OV_EOF -2
  94449. #define OV_HOLE -3
  94450. #define OV_EREAD -128
  94451. #define OV_EFAULT -129
  94452. #define OV_EIMPL -130
  94453. #define OV_EINVAL -131
  94454. #define OV_ENOTVORBIS -132
  94455. #define OV_EBADHEADER -133
  94456. #define OV_EVERSION -134
  94457. #define OV_ENOTAUDIO -135
  94458. #define OV_EBADPACKET -136
  94459. #define OV_EBADLINK -137
  94460. #define OV_ENOSEEK -138
  94461. #ifdef __cplusplus
  94462. }
  94463. #endif /* __cplusplus */
  94464. #endif
  94465. /*** End of inlined file: codec.h ***/
  94466. extern int vorbis_encode_init(vorbis_info *vi,
  94467. long channels,
  94468. long rate,
  94469. long max_bitrate,
  94470. long nominal_bitrate,
  94471. long min_bitrate);
  94472. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94473. long channels,
  94474. long rate,
  94475. long max_bitrate,
  94476. long nominal_bitrate,
  94477. long min_bitrate);
  94478. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94479. long channels,
  94480. long rate,
  94481. float quality /* quality level from 0. (lo) to 1. (hi) */
  94482. );
  94483. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94484. long channels,
  94485. long rate,
  94486. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94487. );
  94488. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94489. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94490. #define OV_ECTL_RATEMANAGE_GET 0x10
  94491. #define OV_ECTL_RATEMANAGE_SET 0x11
  94492. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94493. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94494. struct ovectl_ratemanage_arg {
  94495. int management_active;
  94496. long bitrate_hard_min;
  94497. long bitrate_hard_max;
  94498. double bitrate_hard_window;
  94499. long bitrate_av_lo;
  94500. long bitrate_av_hi;
  94501. double bitrate_av_window;
  94502. double bitrate_av_window_center;
  94503. };
  94504. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94505. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94506. struct ovectl_ratemanage2_arg {
  94507. int management_active;
  94508. long bitrate_limit_min_kbps;
  94509. long bitrate_limit_max_kbps;
  94510. long bitrate_limit_reservoir_bits;
  94511. double bitrate_limit_reservoir_bias;
  94512. long bitrate_average_kbps;
  94513. double bitrate_average_damping;
  94514. };
  94515. #define OV_ECTL_LOWPASS_GET 0x20
  94516. #define OV_ECTL_LOWPASS_SET 0x21
  94517. #define OV_ECTL_IBLOCK_GET 0x30
  94518. #define OV_ECTL_IBLOCK_SET 0x31
  94519. #ifdef __cplusplus
  94520. }
  94521. #endif /* __cplusplus */
  94522. #endif
  94523. /*** End of inlined file: vorbisenc.h ***/
  94524. /*** Start of inlined file: vorbisfile.h ***/
  94525. #ifndef _OV_FILE_H_
  94526. #define _OV_FILE_H_
  94527. #ifdef __cplusplus
  94528. extern "C"
  94529. {
  94530. #endif /* __cplusplus */
  94531. #include <stdio.h>
  94532. typedef struct {
  94533. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94534. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94535. int (*close_func) (void *datasource);
  94536. long (*tell_func) (void *datasource);
  94537. } ov_callbacks;
  94538. #define NOTOPEN 0
  94539. #define PARTOPEN 1
  94540. #define OPENED 2
  94541. #define STREAMSET 3
  94542. #define INITSET 4
  94543. typedef struct OggVorbis_File {
  94544. void *datasource; /* Pointer to a FILE *, etc. */
  94545. int seekable;
  94546. ogg_int64_t offset;
  94547. ogg_int64_t end;
  94548. ogg_sync_state oy;
  94549. int links;
  94550. ogg_int64_t *offsets;
  94551. ogg_int64_t *dataoffsets;
  94552. long *serialnos;
  94553. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94554. compatability; x2 size, stores both
  94555. beginning and end values */
  94556. vorbis_info *vi;
  94557. vorbis_comment *vc;
  94558. ogg_int64_t pcm_offset;
  94559. int ready_state;
  94560. long current_serialno;
  94561. int current_link;
  94562. double bittrack;
  94563. double samptrack;
  94564. ogg_stream_state os; /* take physical pages, weld into a logical
  94565. stream of packets */
  94566. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94567. vorbis_block vb; /* local working space for packet->PCM decode */
  94568. ov_callbacks callbacks;
  94569. } OggVorbis_File;
  94570. extern int ov_clear(OggVorbis_File *vf);
  94571. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94572. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94573. char *initial, long ibytes, ov_callbacks callbacks);
  94574. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94575. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94576. char *initial, long ibytes, ov_callbacks callbacks);
  94577. extern int ov_test_open(OggVorbis_File *vf);
  94578. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94579. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94580. extern long ov_streams(OggVorbis_File *vf);
  94581. extern long ov_seekable(OggVorbis_File *vf);
  94582. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94583. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94584. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94585. extern double ov_time_total(OggVorbis_File *vf,int i);
  94586. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94587. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94588. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94589. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94590. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94591. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94592. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94593. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94594. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94595. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94596. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94597. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94598. extern double ov_time_tell(OggVorbis_File *vf);
  94599. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94600. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94601. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94602. int *bitstream);
  94603. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94604. int bigendianp,int word,int sgned,int *bitstream);
  94605. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94606. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94607. extern int ov_halfrate_p(OggVorbis_File *vf);
  94608. #ifdef __cplusplus
  94609. }
  94610. #endif /* __cplusplus */
  94611. #endif
  94612. /*** End of inlined file: vorbisfile.h ***/
  94613. /*** Start of inlined file: bitwise.c ***/
  94614. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94615. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94616. // tasks..
  94617. #if JUCE_MSVC
  94618. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94619. #endif
  94620. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94621. #if JUCE_USE_OGGVORBIS
  94622. #include <string.h>
  94623. #include <stdlib.h>
  94624. #define BUFFER_INCREMENT 256
  94625. static const unsigned long mask[]=
  94626. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94627. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94628. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94629. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94630. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94631. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94632. 0x3fffffff,0x7fffffff,0xffffffff };
  94633. static const unsigned int mask8B[]=
  94634. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94635. void oggpack_writeinit(oggpack_buffer *b){
  94636. memset(b,0,sizeof(*b));
  94637. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94638. b->buffer[0]='\0';
  94639. b->storage=BUFFER_INCREMENT;
  94640. }
  94641. void oggpackB_writeinit(oggpack_buffer *b){
  94642. oggpack_writeinit(b);
  94643. }
  94644. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94645. long bytes=bits>>3;
  94646. bits-=bytes*8;
  94647. b->ptr=b->buffer+bytes;
  94648. b->endbit=bits;
  94649. b->endbyte=bytes;
  94650. *b->ptr&=mask[bits];
  94651. }
  94652. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94653. long bytes=bits>>3;
  94654. bits-=bytes*8;
  94655. b->ptr=b->buffer+bytes;
  94656. b->endbit=bits;
  94657. b->endbyte=bytes;
  94658. *b->ptr&=mask8B[bits];
  94659. }
  94660. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94661. if(b->endbyte+4>=b->storage){
  94662. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94663. b->storage+=BUFFER_INCREMENT;
  94664. b->ptr=b->buffer+b->endbyte;
  94665. }
  94666. value&=mask[bits];
  94667. bits+=b->endbit;
  94668. b->ptr[0]|=value<<b->endbit;
  94669. if(bits>=8){
  94670. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94671. if(bits>=16){
  94672. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94673. if(bits>=24){
  94674. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94675. if(bits>=32){
  94676. if(b->endbit)
  94677. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94678. else
  94679. b->ptr[4]=0;
  94680. }
  94681. }
  94682. }
  94683. }
  94684. b->endbyte+=bits/8;
  94685. b->ptr+=bits/8;
  94686. b->endbit=bits&7;
  94687. }
  94688. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94689. if(b->endbyte+4>=b->storage){
  94690. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94691. b->storage+=BUFFER_INCREMENT;
  94692. b->ptr=b->buffer+b->endbyte;
  94693. }
  94694. value=(value&mask[bits])<<(32-bits);
  94695. bits+=b->endbit;
  94696. b->ptr[0]|=value>>(24+b->endbit);
  94697. if(bits>=8){
  94698. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94699. if(bits>=16){
  94700. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94701. if(bits>=24){
  94702. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94703. if(bits>=32){
  94704. if(b->endbit)
  94705. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94706. else
  94707. b->ptr[4]=0;
  94708. }
  94709. }
  94710. }
  94711. }
  94712. b->endbyte+=bits/8;
  94713. b->ptr+=bits/8;
  94714. b->endbit=bits&7;
  94715. }
  94716. void oggpack_writealign(oggpack_buffer *b){
  94717. int bits=8-b->endbit;
  94718. if(bits<8)
  94719. oggpack_write(b,0,bits);
  94720. }
  94721. void oggpackB_writealign(oggpack_buffer *b){
  94722. int bits=8-b->endbit;
  94723. if(bits<8)
  94724. oggpackB_write(b,0,bits);
  94725. }
  94726. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94727. void *source,
  94728. long bits,
  94729. void (*w)(oggpack_buffer *,
  94730. unsigned long,
  94731. int),
  94732. int msb){
  94733. unsigned char *ptr=(unsigned char *)source;
  94734. long bytes=bits/8;
  94735. bits-=bytes*8;
  94736. if(b->endbit){
  94737. int i;
  94738. for(i=0;i<bytes;i++)
  94739. w(b,(unsigned long)(ptr[i]),8);
  94740. }else{
  94741. if(b->endbyte+bytes+1>=b->storage){
  94742. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94743. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94744. b->ptr=b->buffer+b->endbyte;
  94745. }
  94746. memmove(b->ptr,source,bytes);
  94747. b->ptr+=bytes;
  94748. b->endbyte+=bytes;
  94749. *b->ptr=0;
  94750. }
  94751. if(bits){
  94752. if(msb)
  94753. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94754. else
  94755. w(b,(unsigned long)(ptr[bytes]),bits);
  94756. }
  94757. }
  94758. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94759. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94760. }
  94761. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94762. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94763. }
  94764. void oggpack_reset(oggpack_buffer *b){
  94765. b->ptr=b->buffer;
  94766. b->buffer[0]=0;
  94767. b->endbit=b->endbyte=0;
  94768. }
  94769. void oggpackB_reset(oggpack_buffer *b){
  94770. oggpack_reset(b);
  94771. }
  94772. void oggpack_writeclear(oggpack_buffer *b){
  94773. _ogg_free(b->buffer);
  94774. memset(b,0,sizeof(*b));
  94775. }
  94776. void oggpackB_writeclear(oggpack_buffer *b){
  94777. oggpack_writeclear(b);
  94778. }
  94779. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94780. memset(b,0,sizeof(*b));
  94781. b->buffer=b->ptr=buf;
  94782. b->storage=bytes;
  94783. }
  94784. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94785. oggpack_readinit(b,buf,bytes);
  94786. }
  94787. long oggpack_look(oggpack_buffer *b,int bits){
  94788. unsigned long ret;
  94789. unsigned long m=mask[bits];
  94790. bits+=b->endbit;
  94791. if(b->endbyte+4>=b->storage){
  94792. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94793. }
  94794. ret=b->ptr[0]>>b->endbit;
  94795. if(bits>8){
  94796. ret|=b->ptr[1]<<(8-b->endbit);
  94797. if(bits>16){
  94798. ret|=b->ptr[2]<<(16-b->endbit);
  94799. if(bits>24){
  94800. ret|=b->ptr[3]<<(24-b->endbit);
  94801. if(bits>32 && b->endbit)
  94802. ret|=b->ptr[4]<<(32-b->endbit);
  94803. }
  94804. }
  94805. }
  94806. return(m&ret);
  94807. }
  94808. long oggpackB_look(oggpack_buffer *b,int bits){
  94809. unsigned long ret;
  94810. int m=32-bits;
  94811. bits+=b->endbit;
  94812. if(b->endbyte+4>=b->storage){
  94813. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94814. }
  94815. ret=b->ptr[0]<<(24+b->endbit);
  94816. if(bits>8){
  94817. ret|=b->ptr[1]<<(16+b->endbit);
  94818. if(bits>16){
  94819. ret|=b->ptr[2]<<(8+b->endbit);
  94820. if(bits>24){
  94821. ret|=b->ptr[3]<<(b->endbit);
  94822. if(bits>32 && b->endbit)
  94823. ret|=b->ptr[4]>>(8-b->endbit);
  94824. }
  94825. }
  94826. }
  94827. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94828. }
  94829. long oggpack_look1(oggpack_buffer *b){
  94830. if(b->endbyte>=b->storage)return(-1);
  94831. return((b->ptr[0]>>b->endbit)&1);
  94832. }
  94833. long oggpackB_look1(oggpack_buffer *b){
  94834. if(b->endbyte>=b->storage)return(-1);
  94835. return((b->ptr[0]>>(7-b->endbit))&1);
  94836. }
  94837. void oggpack_adv(oggpack_buffer *b,int bits){
  94838. bits+=b->endbit;
  94839. b->ptr+=bits/8;
  94840. b->endbyte+=bits/8;
  94841. b->endbit=bits&7;
  94842. }
  94843. void oggpackB_adv(oggpack_buffer *b,int bits){
  94844. oggpack_adv(b,bits);
  94845. }
  94846. void oggpack_adv1(oggpack_buffer *b){
  94847. if(++(b->endbit)>7){
  94848. b->endbit=0;
  94849. b->ptr++;
  94850. b->endbyte++;
  94851. }
  94852. }
  94853. void oggpackB_adv1(oggpack_buffer *b){
  94854. oggpack_adv1(b);
  94855. }
  94856. long oggpack_read(oggpack_buffer *b,int bits){
  94857. long ret;
  94858. unsigned long m=mask[bits];
  94859. bits+=b->endbit;
  94860. if(b->endbyte+4>=b->storage){
  94861. ret=-1L;
  94862. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94863. }
  94864. ret=b->ptr[0]>>b->endbit;
  94865. if(bits>8){
  94866. ret|=b->ptr[1]<<(8-b->endbit);
  94867. if(bits>16){
  94868. ret|=b->ptr[2]<<(16-b->endbit);
  94869. if(bits>24){
  94870. ret|=b->ptr[3]<<(24-b->endbit);
  94871. if(bits>32 && b->endbit){
  94872. ret|=b->ptr[4]<<(32-b->endbit);
  94873. }
  94874. }
  94875. }
  94876. }
  94877. ret&=m;
  94878. overflow:
  94879. b->ptr+=bits/8;
  94880. b->endbyte+=bits/8;
  94881. b->endbit=bits&7;
  94882. return(ret);
  94883. }
  94884. long oggpackB_read(oggpack_buffer *b,int bits){
  94885. long ret;
  94886. long m=32-bits;
  94887. bits+=b->endbit;
  94888. if(b->endbyte+4>=b->storage){
  94889. ret=-1L;
  94890. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94891. }
  94892. ret=b->ptr[0]<<(24+b->endbit);
  94893. if(bits>8){
  94894. ret|=b->ptr[1]<<(16+b->endbit);
  94895. if(bits>16){
  94896. ret|=b->ptr[2]<<(8+b->endbit);
  94897. if(bits>24){
  94898. ret|=b->ptr[3]<<(b->endbit);
  94899. if(bits>32 && b->endbit)
  94900. ret|=b->ptr[4]>>(8-b->endbit);
  94901. }
  94902. }
  94903. }
  94904. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94905. overflow:
  94906. b->ptr+=bits/8;
  94907. b->endbyte+=bits/8;
  94908. b->endbit=bits&7;
  94909. return(ret);
  94910. }
  94911. long oggpack_read1(oggpack_buffer *b){
  94912. long ret;
  94913. if(b->endbyte>=b->storage){
  94914. ret=-1L;
  94915. goto overflow;
  94916. }
  94917. ret=(b->ptr[0]>>b->endbit)&1;
  94918. overflow:
  94919. b->endbit++;
  94920. if(b->endbit>7){
  94921. b->endbit=0;
  94922. b->ptr++;
  94923. b->endbyte++;
  94924. }
  94925. return(ret);
  94926. }
  94927. long oggpackB_read1(oggpack_buffer *b){
  94928. long ret;
  94929. if(b->endbyte>=b->storage){
  94930. ret=-1L;
  94931. goto overflow;
  94932. }
  94933. ret=(b->ptr[0]>>(7-b->endbit))&1;
  94934. overflow:
  94935. b->endbit++;
  94936. if(b->endbit>7){
  94937. b->endbit=0;
  94938. b->ptr++;
  94939. b->endbyte++;
  94940. }
  94941. return(ret);
  94942. }
  94943. long oggpack_bytes(oggpack_buffer *b){
  94944. return(b->endbyte+(b->endbit+7)/8);
  94945. }
  94946. long oggpack_bits(oggpack_buffer *b){
  94947. return(b->endbyte*8+b->endbit);
  94948. }
  94949. long oggpackB_bytes(oggpack_buffer *b){
  94950. return oggpack_bytes(b);
  94951. }
  94952. long oggpackB_bits(oggpack_buffer *b){
  94953. return oggpack_bits(b);
  94954. }
  94955. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  94956. return(b->buffer);
  94957. }
  94958. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  94959. return oggpack_get_buffer(b);
  94960. }
  94961. #ifdef _V_SELFTEST
  94962. #include <stdio.h>
  94963. static int ilog(unsigned int v){
  94964. int ret=0;
  94965. while(v){
  94966. ret++;
  94967. v>>=1;
  94968. }
  94969. return(ret);
  94970. }
  94971. oggpack_buffer o;
  94972. oggpack_buffer r;
  94973. void report(char *in){
  94974. fprintf(stderr,"%s",in);
  94975. exit(1);
  94976. }
  94977. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94978. long bytes,i;
  94979. unsigned char *buffer;
  94980. oggpack_reset(&o);
  94981. for(i=0;i<vals;i++)
  94982. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  94983. buffer=oggpack_get_buffer(&o);
  94984. bytes=oggpack_bytes(&o);
  94985. if(bytes!=compsize)report("wrong number of bytes!\n");
  94986. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94987. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94988. report("wrote incorrect value!\n");
  94989. }
  94990. oggpack_readinit(&r,buffer,bytes);
  94991. for(i=0;i<vals;i++){
  94992. int tbit=bits?bits:ilog(b[i]);
  94993. if(oggpack_look(&r,tbit)==-1)
  94994. report("out of data!\n");
  94995. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  94996. report("looked at incorrect value!\n");
  94997. if(tbit==1)
  94998. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  94999. report("looked at single bit incorrect value!\n");
  95000. if(tbit==1){
  95001. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95002. report("read incorrect single bit value!\n");
  95003. }else{
  95004. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95005. report("read incorrect value!\n");
  95006. }
  95007. }
  95008. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95009. }
  95010. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95011. long bytes,i;
  95012. unsigned char *buffer;
  95013. oggpackB_reset(&o);
  95014. for(i=0;i<vals;i++)
  95015. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95016. buffer=oggpackB_get_buffer(&o);
  95017. bytes=oggpackB_bytes(&o);
  95018. if(bytes!=compsize)report("wrong number of bytes!\n");
  95019. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95020. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95021. report("wrote incorrect value!\n");
  95022. }
  95023. oggpackB_readinit(&r,buffer,bytes);
  95024. for(i=0;i<vals;i++){
  95025. int tbit=bits?bits:ilog(b[i]);
  95026. if(oggpackB_look(&r,tbit)==-1)
  95027. report("out of data!\n");
  95028. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95029. report("looked at incorrect value!\n");
  95030. if(tbit==1)
  95031. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95032. report("looked at single bit incorrect value!\n");
  95033. if(tbit==1){
  95034. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95035. report("read incorrect single bit value!\n");
  95036. }else{
  95037. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95038. report("read incorrect value!\n");
  95039. }
  95040. }
  95041. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95042. }
  95043. int main(void){
  95044. unsigned char *buffer;
  95045. long bytes,i;
  95046. static unsigned long testbuffer1[]=
  95047. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95048. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95049. int test1size=43;
  95050. static unsigned long testbuffer2[]=
  95051. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95052. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95053. 85525151,0,12321,1,349528352};
  95054. int test2size=21;
  95055. static unsigned long testbuffer3[]=
  95056. {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,
  95057. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95058. int test3size=56;
  95059. static unsigned long large[]=
  95060. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95061. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95062. 85525151,0,12321,1,2146528352};
  95063. int onesize=33;
  95064. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95065. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95066. 223,4};
  95067. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95068. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95069. 245,251,128};
  95070. int twosize=6;
  95071. static int two[6]={61,255,255,251,231,29};
  95072. static int twoB[6]={247,63,255,253,249,120};
  95073. int threesize=54;
  95074. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95075. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95076. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95077. 100,52,4,14,18,86,77,1};
  95078. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95079. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95080. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95081. 200,20,254,4,58,106,176,144,0};
  95082. int foursize=38;
  95083. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95084. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95085. 28,2,133,0,1};
  95086. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95087. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95088. 129,10,4,32};
  95089. int fivesize=45;
  95090. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95091. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95092. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95093. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95094. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95095. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95096. int sixsize=7;
  95097. static int six[7]={17,177,170,242,169,19,148};
  95098. static int sixB[7]={136,141,85,79,149,200,41};
  95099. oggpack_writeinit(&o);
  95100. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95101. cliptest(testbuffer1,test1size,0,one,onesize);
  95102. fprintf(stderr,"ok.");
  95103. fprintf(stderr,"\nNull bit call (LSb): ");
  95104. cliptest(testbuffer3,test3size,0,two,twosize);
  95105. fprintf(stderr,"ok.");
  95106. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95107. cliptest(testbuffer2,test2size,0,three,threesize);
  95108. fprintf(stderr,"ok.");
  95109. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95110. oggpack_reset(&o);
  95111. for(i=0;i<test2size;i++)
  95112. oggpack_write(&o,large[i],32);
  95113. buffer=oggpack_get_buffer(&o);
  95114. bytes=oggpack_bytes(&o);
  95115. oggpack_readinit(&r,buffer,bytes);
  95116. for(i=0;i<test2size;i++){
  95117. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95118. if(oggpack_look(&r,32)!=large[i]){
  95119. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95120. oggpack_look(&r,32),large[i]);
  95121. report("read incorrect value!\n");
  95122. }
  95123. oggpack_adv(&r,32);
  95124. }
  95125. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95126. fprintf(stderr,"ok.");
  95127. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95128. cliptest(testbuffer1,test1size,7,four,foursize);
  95129. fprintf(stderr,"ok.");
  95130. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95131. cliptest(testbuffer2,test2size,17,five,fivesize);
  95132. fprintf(stderr,"ok.");
  95133. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95134. cliptest(testbuffer3,test3size,1,six,sixsize);
  95135. fprintf(stderr,"ok.");
  95136. fprintf(stderr,"\nTesting read past end (LSb): ");
  95137. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95138. for(i=0;i<64;i++){
  95139. if(oggpack_read(&r,1)!=0){
  95140. fprintf(stderr,"failed; got -1 prematurely.\n");
  95141. exit(1);
  95142. }
  95143. }
  95144. if(oggpack_look(&r,1)!=-1 ||
  95145. oggpack_read(&r,1)!=-1){
  95146. fprintf(stderr,"failed; read past end without -1.\n");
  95147. exit(1);
  95148. }
  95149. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95150. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95151. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95152. exit(1);
  95153. }
  95154. if(oggpack_look(&r,18)!=0 ||
  95155. oggpack_look(&r,18)!=0){
  95156. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95157. exit(1);
  95158. }
  95159. if(oggpack_look(&r,19)!=-1 ||
  95160. oggpack_look(&r,19)!=-1){
  95161. fprintf(stderr,"failed; read past end without -1.\n");
  95162. exit(1);
  95163. }
  95164. if(oggpack_look(&r,32)!=-1 ||
  95165. oggpack_look(&r,32)!=-1){
  95166. fprintf(stderr,"failed; read past end without -1.\n");
  95167. exit(1);
  95168. }
  95169. oggpack_writeclear(&o);
  95170. fprintf(stderr,"ok.\n");
  95171. oggpackB_writeinit(&o);
  95172. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95173. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95174. fprintf(stderr,"ok.");
  95175. fprintf(stderr,"\nNull bit call (MSb): ");
  95176. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95177. fprintf(stderr,"ok.");
  95178. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95179. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95180. fprintf(stderr,"ok.");
  95181. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95182. oggpackB_reset(&o);
  95183. for(i=0;i<test2size;i++)
  95184. oggpackB_write(&o,large[i],32);
  95185. buffer=oggpackB_get_buffer(&o);
  95186. bytes=oggpackB_bytes(&o);
  95187. oggpackB_readinit(&r,buffer,bytes);
  95188. for(i=0;i<test2size;i++){
  95189. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95190. if(oggpackB_look(&r,32)!=large[i]){
  95191. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95192. oggpackB_look(&r,32),large[i]);
  95193. report("read incorrect value!\n");
  95194. }
  95195. oggpackB_adv(&r,32);
  95196. }
  95197. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95198. fprintf(stderr,"ok.");
  95199. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95200. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95201. fprintf(stderr,"ok.");
  95202. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95203. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95204. fprintf(stderr,"ok.");
  95205. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95206. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95207. fprintf(stderr,"ok.");
  95208. fprintf(stderr,"\nTesting read past end (MSb): ");
  95209. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95210. for(i=0;i<64;i++){
  95211. if(oggpackB_read(&r,1)!=0){
  95212. fprintf(stderr,"failed; got -1 prematurely.\n");
  95213. exit(1);
  95214. }
  95215. }
  95216. if(oggpackB_look(&r,1)!=-1 ||
  95217. oggpackB_read(&r,1)!=-1){
  95218. fprintf(stderr,"failed; read past end without -1.\n");
  95219. exit(1);
  95220. }
  95221. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95222. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95223. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95224. exit(1);
  95225. }
  95226. if(oggpackB_look(&r,18)!=0 ||
  95227. oggpackB_look(&r,18)!=0){
  95228. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95229. exit(1);
  95230. }
  95231. if(oggpackB_look(&r,19)!=-1 ||
  95232. oggpackB_look(&r,19)!=-1){
  95233. fprintf(stderr,"failed; read past end without -1.\n");
  95234. exit(1);
  95235. }
  95236. if(oggpackB_look(&r,32)!=-1 ||
  95237. oggpackB_look(&r,32)!=-1){
  95238. fprintf(stderr,"failed; read past end without -1.\n");
  95239. exit(1);
  95240. }
  95241. oggpackB_writeclear(&o);
  95242. fprintf(stderr,"ok.\n\n");
  95243. return(0);
  95244. }
  95245. #endif /* _V_SELFTEST */
  95246. #undef BUFFER_INCREMENT
  95247. #endif
  95248. /*** End of inlined file: bitwise.c ***/
  95249. /*** Start of inlined file: framing.c ***/
  95250. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95251. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95252. // tasks..
  95253. #if JUCE_MSVC
  95254. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95255. #endif
  95256. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95257. #if JUCE_USE_OGGVORBIS
  95258. #include <stdlib.h>
  95259. #include <string.h>
  95260. int ogg_page_version(ogg_page *og){
  95261. return((int)(og->header[4]));
  95262. }
  95263. int ogg_page_continued(ogg_page *og){
  95264. return((int)(og->header[5]&0x01));
  95265. }
  95266. int ogg_page_bos(ogg_page *og){
  95267. return((int)(og->header[5]&0x02));
  95268. }
  95269. int ogg_page_eos(ogg_page *og){
  95270. return((int)(og->header[5]&0x04));
  95271. }
  95272. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95273. unsigned char *page=og->header;
  95274. ogg_int64_t granulepos=page[13]&(0xff);
  95275. granulepos= (granulepos<<8)|(page[12]&0xff);
  95276. granulepos= (granulepos<<8)|(page[11]&0xff);
  95277. granulepos= (granulepos<<8)|(page[10]&0xff);
  95278. granulepos= (granulepos<<8)|(page[9]&0xff);
  95279. granulepos= (granulepos<<8)|(page[8]&0xff);
  95280. granulepos= (granulepos<<8)|(page[7]&0xff);
  95281. granulepos= (granulepos<<8)|(page[6]&0xff);
  95282. return(granulepos);
  95283. }
  95284. int ogg_page_serialno(ogg_page *og){
  95285. return(og->header[14] |
  95286. (og->header[15]<<8) |
  95287. (og->header[16]<<16) |
  95288. (og->header[17]<<24));
  95289. }
  95290. long ogg_page_pageno(ogg_page *og){
  95291. return(og->header[18] |
  95292. (og->header[19]<<8) |
  95293. (og->header[20]<<16) |
  95294. (og->header[21]<<24));
  95295. }
  95296. int ogg_page_packets(ogg_page *og){
  95297. int i,n=og->header[26],count=0;
  95298. for(i=0;i<n;i++)
  95299. if(og->header[27+i]<255)count++;
  95300. return(count);
  95301. }
  95302. #if 0
  95303. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95304. int i;
  95305. unsigned long r;
  95306. r = index << 24;
  95307. for (i=0; i<8; i++)
  95308. if (r & 0x80000000UL)
  95309. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95310. polynomial, although we use an
  95311. unreflected alg and an init/final
  95312. of 0, not 0xffffffff */
  95313. else
  95314. r<<=1;
  95315. return (r & 0xffffffffUL);
  95316. }
  95317. #endif
  95318. static const ogg_uint32_t crc_lookup[256]={
  95319. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95320. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95321. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95322. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95323. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95324. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95325. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95326. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95327. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95328. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95329. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95330. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95331. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95332. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95333. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95334. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95335. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95336. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95337. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95338. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95339. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95340. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95341. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95342. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95343. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95344. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95345. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95346. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95347. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95348. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95349. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95350. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95351. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95352. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95353. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95354. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95355. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95356. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95357. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95358. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95359. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95360. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95361. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95362. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95363. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95364. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95365. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95366. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95367. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95368. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95369. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95370. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95371. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95372. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95373. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95374. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95375. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95376. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95377. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95378. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95379. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95380. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95381. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95382. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95383. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95384. if(os){
  95385. memset(os,0,sizeof(*os));
  95386. os->body_storage=16*1024;
  95387. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95388. os->lacing_storage=1024;
  95389. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95390. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95391. os->serialno=serialno;
  95392. return(0);
  95393. }
  95394. return(-1);
  95395. }
  95396. int ogg_stream_clear(ogg_stream_state *os){
  95397. if(os){
  95398. if(os->body_data)_ogg_free(os->body_data);
  95399. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95400. if(os->granule_vals)_ogg_free(os->granule_vals);
  95401. memset(os,0,sizeof(*os));
  95402. }
  95403. return(0);
  95404. }
  95405. int ogg_stream_destroy(ogg_stream_state *os){
  95406. if(os){
  95407. ogg_stream_clear(os);
  95408. _ogg_free(os);
  95409. }
  95410. return(0);
  95411. }
  95412. static void _os_body_expand(ogg_stream_state *os,int needed){
  95413. if(os->body_storage<=os->body_fill+needed){
  95414. os->body_storage+=(needed+1024);
  95415. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95416. }
  95417. }
  95418. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95419. if(os->lacing_storage<=os->lacing_fill+needed){
  95420. os->lacing_storage+=(needed+32);
  95421. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95422. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95423. }
  95424. }
  95425. void ogg_page_checksum_set(ogg_page *og){
  95426. if(og){
  95427. ogg_uint32_t crc_reg=0;
  95428. int i;
  95429. og->header[22]=0;
  95430. og->header[23]=0;
  95431. og->header[24]=0;
  95432. og->header[25]=0;
  95433. for(i=0;i<og->header_len;i++)
  95434. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95435. for(i=0;i<og->body_len;i++)
  95436. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95437. og->header[22]=(unsigned char)(crc_reg&0xff);
  95438. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95439. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95440. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95441. }
  95442. }
  95443. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95444. int lacing_vals=op->bytes/255+1,i;
  95445. if(os->body_returned){
  95446. os->body_fill-=os->body_returned;
  95447. if(os->body_fill)
  95448. memmove(os->body_data,os->body_data+os->body_returned,
  95449. os->body_fill);
  95450. os->body_returned=0;
  95451. }
  95452. _os_body_expand(os,op->bytes);
  95453. _os_lacing_expand(os,lacing_vals);
  95454. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95455. os->body_fill+=op->bytes;
  95456. for(i=0;i<lacing_vals-1;i++){
  95457. os->lacing_vals[os->lacing_fill+i]=255;
  95458. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95459. }
  95460. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95461. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95462. os->lacing_vals[os->lacing_fill]|= 0x100;
  95463. os->lacing_fill+=lacing_vals;
  95464. os->packetno++;
  95465. if(op->e_o_s)os->e_o_s=1;
  95466. return(0);
  95467. }
  95468. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95469. int i;
  95470. int vals=0;
  95471. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95472. int bytes=0;
  95473. long acc=0;
  95474. ogg_int64_t granule_pos=-1;
  95475. if(maxvals==0)return(0);
  95476. if(os->b_o_s==0){ /* 'initial header page' case */
  95477. granule_pos=0;
  95478. for(vals=0;vals<maxvals;vals++){
  95479. if((os->lacing_vals[vals]&0x0ff)<255){
  95480. vals++;
  95481. break;
  95482. }
  95483. }
  95484. }else{
  95485. for(vals=0;vals<maxvals;vals++){
  95486. if(acc>4096)break;
  95487. acc+=os->lacing_vals[vals]&0x0ff;
  95488. if((os->lacing_vals[vals]&0xff)<255)
  95489. granule_pos=os->granule_vals[vals];
  95490. }
  95491. }
  95492. memcpy(os->header,"OggS",4);
  95493. os->header[4]=0x00;
  95494. os->header[5]=0x00;
  95495. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95496. if(os->b_o_s==0)os->header[5]|=0x02;
  95497. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95498. os->b_o_s=1;
  95499. for(i=6;i<14;i++){
  95500. os->header[i]=(unsigned char)(granule_pos&0xff);
  95501. granule_pos>>=8;
  95502. }
  95503. {
  95504. long serialno=os->serialno;
  95505. for(i=14;i<18;i++){
  95506. os->header[i]=(unsigned char)(serialno&0xff);
  95507. serialno>>=8;
  95508. }
  95509. }
  95510. if(os->pageno==-1)os->pageno=0; /* because someone called
  95511. stream_reset; this would be a
  95512. strange thing to do in an
  95513. encode stream, but it has
  95514. plausible uses */
  95515. {
  95516. long pageno=os->pageno++;
  95517. for(i=18;i<22;i++){
  95518. os->header[i]=(unsigned char)(pageno&0xff);
  95519. pageno>>=8;
  95520. }
  95521. }
  95522. os->header[22]=0;
  95523. os->header[23]=0;
  95524. os->header[24]=0;
  95525. os->header[25]=0;
  95526. os->header[26]=(unsigned char)(vals&0xff);
  95527. for(i=0;i<vals;i++)
  95528. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95529. og->header=os->header;
  95530. og->header_len=os->header_fill=vals+27;
  95531. og->body=os->body_data+os->body_returned;
  95532. og->body_len=bytes;
  95533. os->lacing_fill-=vals;
  95534. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95535. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95536. os->body_returned+=bytes;
  95537. ogg_page_checksum_set(og);
  95538. return(1);
  95539. }
  95540. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95541. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95542. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95543. os->lacing_fill>=255 || /* 'segment table full' case */
  95544. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95545. return(ogg_stream_flush(os,og));
  95546. }
  95547. return(0);
  95548. }
  95549. int ogg_stream_eos(ogg_stream_state *os){
  95550. return os->e_o_s;
  95551. }
  95552. int ogg_sync_init(ogg_sync_state *oy){
  95553. if(oy){
  95554. memset(oy,0,sizeof(*oy));
  95555. }
  95556. return(0);
  95557. }
  95558. int ogg_sync_clear(ogg_sync_state *oy){
  95559. if(oy){
  95560. if(oy->data)_ogg_free(oy->data);
  95561. ogg_sync_init(oy);
  95562. }
  95563. return(0);
  95564. }
  95565. int ogg_sync_destroy(ogg_sync_state *oy){
  95566. if(oy){
  95567. ogg_sync_clear(oy);
  95568. _ogg_free(oy);
  95569. }
  95570. return(0);
  95571. }
  95572. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95573. if(oy->returned){
  95574. oy->fill-=oy->returned;
  95575. if(oy->fill>0)
  95576. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95577. oy->returned=0;
  95578. }
  95579. if(size>oy->storage-oy->fill){
  95580. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95581. if(oy->data)
  95582. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95583. else
  95584. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95585. oy->storage=newsize;
  95586. }
  95587. return((char *)oy->data+oy->fill);
  95588. }
  95589. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95590. if(oy->fill+bytes>oy->storage)return(-1);
  95591. oy->fill+=bytes;
  95592. return(0);
  95593. }
  95594. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95595. unsigned char *page=oy->data+oy->returned;
  95596. unsigned char *next;
  95597. long bytes=oy->fill-oy->returned;
  95598. if(oy->headerbytes==0){
  95599. int headerbytes,i;
  95600. if(bytes<27)return(0); /* not enough for a header */
  95601. if(memcmp(page,"OggS",4))goto sync_fail;
  95602. headerbytes=page[26]+27;
  95603. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95604. for(i=0;i<page[26];i++)
  95605. oy->bodybytes+=page[27+i];
  95606. oy->headerbytes=headerbytes;
  95607. }
  95608. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95609. {
  95610. char chksum[4];
  95611. ogg_page log;
  95612. memcpy(chksum,page+22,4);
  95613. memset(page+22,0,4);
  95614. log.header=page;
  95615. log.header_len=oy->headerbytes;
  95616. log.body=page+oy->headerbytes;
  95617. log.body_len=oy->bodybytes;
  95618. ogg_page_checksum_set(&log);
  95619. if(memcmp(chksum,page+22,4)){
  95620. memcpy(page+22,chksum,4);
  95621. goto sync_fail;
  95622. }
  95623. }
  95624. {
  95625. unsigned char *page=oy->data+oy->returned;
  95626. long bytes;
  95627. if(og){
  95628. og->header=page;
  95629. og->header_len=oy->headerbytes;
  95630. og->body=page+oy->headerbytes;
  95631. og->body_len=oy->bodybytes;
  95632. }
  95633. oy->unsynced=0;
  95634. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95635. oy->headerbytes=0;
  95636. oy->bodybytes=0;
  95637. return(bytes);
  95638. }
  95639. sync_fail:
  95640. oy->headerbytes=0;
  95641. oy->bodybytes=0;
  95642. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95643. if(!next)
  95644. next=oy->data+oy->fill;
  95645. oy->returned=next-oy->data;
  95646. return(-(next-page));
  95647. }
  95648. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95649. for(;;){
  95650. long ret=ogg_sync_pageseek(oy,og);
  95651. if(ret>0){
  95652. return(1);
  95653. }
  95654. if(ret==0){
  95655. return(0);
  95656. }
  95657. if(!oy->unsynced){
  95658. oy->unsynced=1;
  95659. return(-1);
  95660. }
  95661. }
  95662. }
  95663. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95664. unsigned char *header=og->header;
  95665. unsigned char *body=og->body;
  95666. long bodysize=og->body_len;
  95667. int segptr=0;
  95668. int version=ogg_page_version(og);
  95669. int continued=ogg_page_continued(og);
  95670. int bos=ogg_page_bos(og);
  95671. int eos=ogg_page_eos(og);
  95672. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95673. int serialno=ogg_page_serialno(og);
  95674. long pageno=ogg_page_pageno(og);
  95675. int segments=header[26];
  95676. {
  95677. long lr=os->lacing_returned;
  95678. long br=os->body_returned;
  95679. if(br){
  95680. os->body_fill-=br;
  95681. if(os->body_fill)
  95682. memmove(os->body_data,os->body_data+br,os->body_fill);
  95683. os->body_returned=0;
  95684. }
  95685. if(lr){
  95686. if(os->lacing_fill-lr){
  95687. memmove(os->lacing_vals,os->lacing_vals+lr,
  95688. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95689. memmove(os->granule_vals,os->granule_vals+lr,
  95690. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95691. }
  95692. os->lacing_fill-=lr;
  95693. os->lacing_packet-=lr;
  95694. os->lacing_returned=0;
  95695. }
  95696. }
  95697. if(serialno!=os->serialno)return(-1);
  95698. if(version>0)return(-1);
  95699. _os_lacing_expand(os,segments+1);
  95700. if(pageno!=os->pageno){
  95701. int i;
  95702. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95703. os->body_fill-=os->lacing_vals[i]&0xff;
  95704. os->lacing_fill=os->lacing_packet;
  95705. if(os->pageno!=-1){
  95706. os->lacing_vals[os->lacing_fill++]=0x400;
  95707. os->lacing_packet++;
  95708. }
  95709. }
  95710. if(continued){
  95711. if(os->lacing_fill<1 ||
  95712. os->lacing_vals[os->lacing_fill-1]==0x400){
  95713. bos=0;
  95714. for(;segptr<segments;segptr++){
  95715. int val=header[27+segptr];
  95716. body+=val;
  95717. bodysize-=val;
  95718. if(val<255){
  95719. segptr++;
  95720. break;
  95721. }
  95722. }
  95723. }
  95724. }
  95725. if(bodysize){
  95726. _os_body_expand(os,bodysize);
  95727. memcpy(os->body_data+os->body_fill,body,bodysize);
  95728. os->body_fill+=bodysize;
  95729. }
  95730. {
  95731. int saved=-1;
  95732. while(segptr<segments){
  95733. int val=header[27+segptr];
  95734. os->lacing_vals[os->lacing_fill]=val;
  95735. os->granule_vals[os->lacing_fill]=-1;
  95736. if(bos){
  95737. os->lacing_vals[os->lacing_fill]|=0x100;
  95738. bos=0;
  95739. }
  95740. if(val<255)saved=os->lacing_fill;
  95741. os->lacing_fill++;
  95742. segptr++;
  95743. if(val<255)os->lacing_packet=os->lacing_fill;
  95744. }
  95745. if(saved!=-1){
  95746. os->granule_vals[saved]=granulepos;
  95747. }
  95748. }
  95749. if(eos){
  95750. os->e_o_s=1;
  95751. if(os->lacing_fill>0)
  95752. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95753. }
  95754. os->pageno=pageno+1;
  95755. return(0);
  95756. }
  95757. int ogg_sync_reset(ogg_sync_state *oy){
  95758. oy->fill=0;
  95759. oy->returned=0;
  95760. oy->unsynced=0;
  95761. oy->headerbytes=0;
  95762. oy->bodybytes=0;
  95763. return(0);
  95764. }
  95765. int ogg_stream_reset(ogg_stream_state *os){
  95766. os->body_fill=0;
  95767. os->body_returned=0;
  95768. os->lacing_fill=0;
  95769. os->lacing_packet=0;
  95770. os->lacing_returned=0;
  95771. os->header_fill=0;
  95772. os->e_o_s=0;
  95773. os->b_o_s=0;
  95774. os->pageno=-1;
  95775. os->packetno=0;
  95776. os->granulepos=0;
  95777. return(0);
  95778. }
  95779. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95780. ogg_stream_reset(os);
  95781. os->serialno=serialno;
  95782. return(0);
  95783. }
  95784. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95785. int ptr=os->lacing_returned;
  95786. if(os->lacing_packet<=ptr)return(0);
  95787. if(os->lacing_vals[ptr]&0x400){
  95788. os->lacing_returned++;
  95789. os->packetno++;
  95790. return(-1);
  95791. }
  95792. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95793. to ask if there's a whole packet
  95794. waiting */
  95795. {
  95796. int size=os->lacing_vals[ptr]&0xff;
  95797. int bytes=size;
  95798. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95799. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95800. while(size==255){
  95801. int val=os->lacing_vals[++ptr];
  95802. size=val&0xff;
  95803. if(val&0x200)eos=0x200;
  95804. bytes+=size;
  95805. }
  95806. if(op){
  95807. op->e_o_s=eos;
  95808. op->b_o_s=bos;
  95809. op->packet=os->body_data+os->body_returned;
  95810. op->packetno=os->packetno;
  95811. op->granulepos=os->granule_vals[ptr];
  95812. op->bytes=bytes;
  95813. }
  95814. if(adv){
  95815. os->body_returned+=bytes;
  95816. os->lacing_returned=ptr+1;
  95817. os->packetno++;
  95818. }
  95819. }
  95820. return(1);
  95821. }
  95822. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95823. return _packetout(os,op,1);
  95824. }
  95825. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95826. return _packetout(os,op,0);
  95827. }
  95828. void ogg_packet_clear(ogg_packet *op) {
  95829. _ogg_free(op->packet);
  95830. memset(op, 0, sizeof(*op));
  95831. }
  95832. #ifdef _V_SELFTEST
  95833. #include <stdio.h>
  95834. ogg_stream_state os_en, os_de;
  95835. ogg_sync_state oy;
  95836. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95837. long j;
  95838. static int sequence=0;
  95839. static int lastno=0;
  95840. if(op->bytes!=len){
  95841. fprintf(stderr,"incorrect packet length!\n");
  95842. exit(1);
  95843. }
  95844. if(op->granulepos!=pos){
  95845. fprintf(stderr,"incorrect packet position!\n");
  95846. exit(1);
  95847. }
  95848. if(no==0){
  95849. sequence=0;
  95850. }else{
  95851. sequence++;
  95852. if(no>lastno+1)
  95853. sequence++;
  95854. }
  95855. lastno=no;
  95856. if(op->packetno!=sequence){
  95857. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95858. (long)(op->packetno),sequence);
  95859. exit(1);
  95860. }
  95861. for(j=0;j<op->bytes;j++)
  95862. if(op->packet[j]!=((j+no)&0xff)){
  95863. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95864. j,op->packet[j],(j+no)&0xff);
  95865. exit(1);
  95866. }
  95867. }
  95868. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95869. long j;
  95870. for(j=0;j<og->body_len;j++)
  95871. if(og->body[j]!=data[j]){
  95872. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95873. j,data[j],og->body[j]);
  95874. exit(1);
  95875. }
  95876. for(j=0;j<og->header_len;j++){
  95877. if(og->header[j]!=header[j]){
  95878. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95879. for(j=0;j<header[26]+27;j++)
  95880. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95881. fprintf(stderr,"\n");
  95882. exit(1);
  95883. }
  95884. }
  95885. if(og->header_len!=header[26]+27){
  95886. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95887. og->header_len,header[26]+27);
  95888. exit(1);
  95889. }
  95890. }
  95891. void print_header(ogg_page *og){
  95892. int j;
  95893. fprintf(stderr,"\nHEADER:\n");
  95894. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95895. og->header[0],og->header[1],og->header[2],og->header[3],
  95896. (int)og->header[4],(int)og->header[5]);
  95897. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95898. (og->header[9]<<24)|(og->header[8]<<16)|
  95899. (og->header[7]<<8)|og->header[6],
  95900. (og->header[17]<<24)|(og->header[16]<<16)|
  95901. (og->header[15]<<8)|og->header[14],
  95902. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95903. (og->header[19]<<8)|og->header[18]);
  95904. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95905. (int)og->header[22],(int)og->header[23],
  95906. (int)og->header[24],(int)og->header[25],
  95907. (int)og->header[26]);
  95908. for(j=27;j<og->header_len;j++)
  95909. fprintf(stderr,"%d ",(int)og->header[j]);
  95910. fprintf(stderr,")\n\n");
  95911. }
  95912. void copy_page(ogg_page *og){
  95913. unsigned char *temp=_ogg_malloc(og->header_len);
  95914. memcpy(temp,og->header,og->header_len);
  95915. og->header=temp;
  95916. temp=_ogg_malloc(og->body_len);
  95917. memcpy(temp,og->body,og->body_len);
  95918. og->body=temp;
  95919. }
  95920. void free_page(ogg_page *og){
  95921. _ogg_free (og->header);
  95922. _ogg_free (og->body);
  95923. }
  95924. void error(void){
  95925. fprintf(stderr,"error!\n");
  95926. exit(1);
  95927. }
  95928. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  95929. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95930. 0x01,0x02,0x03,0x04,0,0,0,0,
  95931. 0x15,0xed,0xec,0x91,
  95932. 1,
  95933. 17};
  95934. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95935. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95936. 0x01,0x02,0x03,0x04,0,0,0,0,
  95937. 0x59,0x10,0x6c,0x2c,
  95938. 1,
  95939. 17};
  95940. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95941. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  95942. 0x01,0x02,0x03,0x04,1,0,0,0,
  95943. 0x89,0x33,0x85,0xce,
  95944. 13,
  95945. 254,255,0,255,1,255,245,255,255,0,
  95946. 255,255,90};
  95947. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95948. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95949. 0x01,0x02,0x03,0x04,0,0,0,0,
  95950. 0xff,0x7b,0x23,0x17,
  95951. 1,
  95952. 0};
  95953. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95954. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  95955. 0x01,0x02,0x03,0x04,1,0,0,0,
  95956. 0x5c,0x3f,0x66,0xcb,
  95957. 17,
  95958. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  95959. 255,255,90,0};
  95960. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95961. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95962. 0x01,0x02,0x03,0x04,0,0,0,0,
  95963. 0x01,0x27,0x31,0xaa,
  95964. 18,
  95965. 255,255,255,255,255,255,255,255,
  95966. 255,255,255,255,255,255,255,255,255,10};
  95967. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95968. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  95969. 0x01,0x02,0x03,0x04,1,0,0,0,
  95970. 0x7f,0x4e,0x8a,0xd2,
  95971. 4,
  95972. 255,4,255,0};
  95973. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95974. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95975. 0x01,0x02,0x03,0x04,0,0,0,0,
  95976. 0xff,0x7b,0x23,0x17,
  95977. 1,
  95978. 0};
  95979. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95980. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95981. 0x01,0x02,0x03,0x04,1,0,0,0,
  95982. 0x54,0x05,0x51,0xc8,
  95983. 17,
  95984. 255,255,255,255,255,255,255,255,
  95985. 255,255,255,255,255,255,255,255,255};
  95986. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95987. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  95988. 0x01,0x02,0x03,0x04,2,0,0,0,
  95989. 0xc8,0xc3,0xcb,0xed,
  95990. 5,
  95991. 10,255,4,255,0};
  95992. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95993. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95994. 0x01,0x02,0x03,0x04,0,0,0,0,
  95995. 0xff,0x7b,0x23,0x17,
  95996. 1,
  95997. 0};
  95998. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95999. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96000. 0x01,0x02,0x03,0x04,1,0,0,0,
  96001. 0xed,0x2a,0x2e,0xa7,
  96002. 255,
  96003. 10,10,10,10,10,10,10,10,
  96004. 10,10,10,10,10,10,10,10,
  96005. 10,10,10,10,10,10,10,10,
  96006. 10,10,10,10,10,10,10,10,
  96007. 10,10,10,10,10,10,10,10,
  96008. 10,10,10,10,10,10,10,10,
  96009. 10,10,10,10,10,10,10,10,
  96010. 10,10,10,10,10,10,10,10,
  96011. 10,10,10,10,10,10,10,10,
  96012. 10,10,10,10,10,10,10,10,
  96013. 10,10,10,10,10,10,10,10,
  96014. 10,10,10,10,10,10,10,10,
  96015. 10,10,10,10,10,10,10,10,
  96016. 10,10,10,10,10,10,10,10,
  96017. 10,10,10,10,10,10,10,10,
  96018. 10,10,10,10,10,10,10,10,
  96019. 10,10,10,10,10,10,10,10,
  96020. 10,10,10,10,10,10,10,10,
  96021. 10,10,10,10,10,10,10,10,
  96022. 10,10,10,10,10,10,10,10,
  96023. 10,10,10,10,10,10,10,10,
  96024. 10,10,10,10,10,10,10,10,
  96025. 10,10,10,10,10,10,10,10,
  96026. 10,10,10,10,10,10,10,10,
  96027. 10,10,10,10,10,10,10,10,
  96028. 10,10,10,10,10,10,10,10,
  96029. 10,10,10,10,10,10,10,10,
  96030. 10,10,10,10,10,10,10,10,
  96031. 10,10,10,10,10,10,10,10,
  96032. 10,10,10,10,10,10,10,10,
  96033. 10,10,10,10,10,10,10,10,
  96034. 10,10,10,10,10,10,10};
  96035. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96036. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96037. 0x01,0x02,0x03,0x04,2,0,0,0,
  96038. 0x6c,0x3b,0x82,0x3d,
  96039. 1,
  96040. 50};
  96041. const int head1_6[] = {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_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96048. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96049. 0x01,0x02,0x03,0x04,1,0,0,0,
  96050. 0x3c,0xd9,0x4d,0x3f,
  96051. 17,
  96052. 100,255,255,255,255,255,255,255,255,
  96053. 255,255,255,255,255,255,255,255};
  96054. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96055. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96056. 0x01,0x02,0x03,0x04,2,0,0,0,
  96057. 0x01,0xd2,0xe5,0xe5,
  96058. 17,
  96059. 255,255,255,255,255,255,255,255,
  96060. 255,255,255,255,255,255,255,255,255};
  96061. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96062. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96063. 0x01,0x02,0x03,0x04,3,0,0,0,
  96064. 0xef,0xdd,0x88,0xde,
  96065. 7,
  96066. 255,255,75,255,4,255,0};
  96067. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96068. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96069. 0x01,0x02,0x03,0x04,0,0,0,0,
  96070. 0xff,0x7b,0x23,0x17,
  96071. 1,
  96072. 0};
  96073. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96074. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96075. 0x01,0x02,0x03,0x04,1,0,0,0,
  96076. 0x3c,0xd9,0x4d,0x3f,
  96077. 17,
  96078. 100,255,255,255,255,255,255,255,255,
  96079. 255,255,255,255,255,255,255,255};
  96080. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96081. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96082. 0x01,0x02,0x03,0x04,2,0,0,0,
  96083. 0xd4,0xe0,0x60,0xe5,
  96084. 1,0};
  96085. void test_pack(const int *pl, const int **headers, int byteskip,
  96086. int pageskip, int packetskip){
  96087. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96088. long inptr=0;
  96089. long outptr=0;
  96090. long deptr=0;
  96091. long depacket=0;
  96092. long granule_pos=7,pageno=0;
  96093. int i,j,packets,pageout=pageskip;
  96094. int eosflag=0;
  96095. int bosflag=0;
  96096. int byteskipcount=0;
  96097. ogg_stream_reset(&os_en);
  96098. ogg_stream_reset(&os_de);
  96099. ogg_sync_reset(&oy);
  96100. for(packets=0;packets<packetskip;packets++)
  96101. depacket+=pl[packets];
  96102. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96103. for(i=0;i<packets;i++){
  96104. ogg_packet op;
  96105. int len=pl[i];
  96106. op.packet=data+inptr;
  96107. op.bytes=len;
  96108. op.e_o_s=(pl[i+1]<0?1:0);
  96109. op.granulepos=granule_pos;
  96110. granule_pos+=1024;
  96111. for(j=0;j<len;j++)data[inptr++]=i+j;
  96112. ogg_stream_packetin(&os_en,&op);
  96113. {
  96114. ogg_page og;
  96115. while(ogg_stream_pageout(&os_en,&og)){
  96116. fprintf(stderr,"%ld, ",pageno);
  96117. if(headers[pageno]==NULL){
  96118. fprintf(stderr,"coded too many pages!\n");
  96119. exit(1);
  96120. }
  96121. check_page(data+outptr,headers[pageno],&og);
  96122. outptr+=og.body_len;
  96123. pageno++;
  96124. if(pageskip){
  96125. bosflag=1;
  96126. pageskip--;
  96127. deptr+=og.body_len;
  96128. }
  96129. {
  96130. ogg_page og_de;
  96131. ogg_packet op_de,op_de2;
  96132. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96133. char *next=buf;
  96134. byteskipcount+=og.header_len;
  96135. if(byteskipcount>byteskip){
  96136. memcpy(next,og.header,byteskipcount-byteskip);
  96137. next+=byteskipcount-byteskip;
  96138. byteskipcount=byteskip;
  96139. }
  96140. byteskipcount+=og.body_len;
  96141. if(byteskipcount>byteskip){
  96142. memcpy(next,og.body,byteskipcount-byteskip);
  96143. next+=byteskipcount-byteskip;
  96144. byteskipcount=byteskip;
  96145. }
  96146. ogg_sync_wrote(&oy,next-buf);
  96147. while(1){
  96148. int ret=ogg_sync_pageout(&oy,&og_de);
  96149. if(ret==0)break;
  96150. if(ret<0)continue;
  96151. fprintf(stderr,"(%ld), ",pageout);
  96152. check_page(data+deptr,headers[pageout],&og_de);
  96153. deptr+=og_de.body_len;
  96154. pageout++;
  96155. ogg_stream_pagein(&os_de,&og_de);
  96156. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96157. ogg_stream_packetpeek(&os_de,NULL);
  96158. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96159. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96160. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96161. depacket);
  96162. exit(1);
  96163. }
  96164. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96165. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96166. depacket);
  96167. exit(1);
  96168. }
  96169. if(bosflag==0 && op_de.b_o_s==0){
  96170. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96171. exit(1);
  96172. }
  96173. if(bosflag && op_de.b_o_s){
  96174. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96175. exit(1);
  96176. }
  96177. bosflag=1;
  96178. depacket+=op_de.bytes;
  96179. if(eosflag){
  96180. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96181. exit(1);
  96182. }
  96183. if(op_de.e_o_s)eosflag=1;
  96184. if(op_de.granulepos!=-1){
  96185. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96186. }
  96187. }
  96188. }
  96189. }
  96190. }
  96191. }
  96192. }
  96193. _ogg_free(data);
  96194. if(headers[pageno]!=NULL){
  96195. fprintf(stderr,"did not write last page!\n");
  96196. exit(1);
  96197. }
  96198. if(headers[pageout]!=NULL){
  96199. fprintf(stderr,"did not decode last page!\n");
  96200. exit(1);
  96201. }
  96202. if(inptr!=outptr){
  96203. fprintf(stderr,"encoded page data incomplete!\n");
  96204. exit(1);
  96205. }
  96206. if(inptr!=deptr){
  96207. fprintf(stderr,"decoded page data incomplete!\n");
  96208. exit(1);
  96209. }
  96210. if(inptr!=depacket){
  96211. fprintf(stderr,"decoded packet data incomplete!\n");
  96212. exit(1);
  96213. }
  96214. if(!eosflag){
  96215. fprintf(stderr,"Never got a packet with EOS set!\n");
  96216. exit(1);
  96217. }
  96218. fprintf(stderr,"ok.\n");
  96219. }
  96220. int main(void){
  96221. ogg_stream_init(&os_en,0x04030201);
  96222. ogg_stream_init(&os_de,0x04030201);
  96223. ogg_sync_init(&oy);
  96224. {
  96225. const int packets[]={17, -1};
  96226. const int *headret[]={head1_0,NULL};
  96227. fprintf(stderr,"testing single page encoding... ");
  96228. test_pack(packets,headret,0,0,0);
  96229. }
  96230. {
  96231. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96232. const int *headret[]={head1_1,head2_1,NULL};
  96233. fprintf(stderr,"testing basic page encoding... ");
  96234. test_pack(packets,headret,0,0,0);
  96235. }
  96236. {
  96237. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96238. const int *headret[]={head1_2,head2_2,NULL};
  96239. fprintf(stderr,"testing basic nil packets... ");
  96240. test_pack(packets,headret,0,0,0);
  96241. }
  96242. {
  96243. const int packets[]={4345,259,255,-1};
  96244. const int *headret[]={head1_3,head2_3,NULL};
  96245. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96246. test_pack(packets,headret,0,0,0);
  96247. }
  96248. {
  96249. const int packets[]={0,4345,259,255,-1};
  96250. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96251. fprintf(stderr,"testing single packet page span... ");
  96252. test_pack(packets,headret,0,0,0);
  96253. }
  96254. {
  96255. const int packets[]={0,10,10,10,10,10,10,10,10,
  96256. 10,10,10,10,10,10,10,10,
  96257. 10,10,10,10,10,10,10,10,
  96258. 10,10,10,10,10,10,10,10,
  96259. 10,10,10,10,10,10,10,10,
  96260. 10,10,10,10,10,10,10,10,
  96261. 10,10,10,10,10,10,10,10,
  96262. 10,10,10,10,10,10,10,10,
  96263. 10,10,10,10,10,10,10,10,
  96264. 10,10,10,10,10,10,10,10,
  96265. 10,10,10,10,10,10,10,10,
  96266. 10,10,10,10,10,10,10,10,
  96267. 10,10,10,10,10,10,10,10,
  96268. 10,10,10,10,10,10,10,10,
  96269. 10,10,10,10,10,10,10,10,
  96270. 10,10,10,10,10,10,10,10,
  96271. 10,10,10,10,10,10,10,10,
  96272. 10,10,10,10,10,10,10,10,
  96273. 10,10,10,10,10,10,10,10,
  96274. 10,10,10,10,10,10,10,10,
  96275. 10,10,10,10,10,10,10,10,
  96276. 10,10,10,10,10,10,10,10,
  96277. 10,10,10,10,10,10,10,10,
  96278. 10,10,10,10,10,10,10,10,
  96279. 10,10,10,10,10,10,10,10,
  96280. 10,10,10,10,10,10,10,10,
  96281. 10,10,10,10,10,10,10,10,
  96282. 10,10,10,10,10,10,10,10,
  96283. 10,10,10,10,10,10,10,10,
  96284. 10,10,10,10,10,10,10,10,
  96285. 10,10,10,10,10,10,10,10,
  96286. 10,10,10,10,10,10,10,50,-1};
  96287. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96288. fprintf(stderr,"testing max packet segments... ");
  96289. test_pack(packets,headret,0,0,0);
  96290. }
  96291. {
  96292. const int packets[]={0,100,9000,259,255,-1};
  96293. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96294. fprintf(stderr,"testing very large packets... ");
  96295. test_pack(packets,headret,0,0,0);
  96296. }
  96297. {
  96298. const int packets[]={0,100,9000,259,255,-1};
  96299. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96300. fprintf(stderr,"testing continuation resync in very large packets... ");
  96301. test_pack(packets,headret,100,2,3);
  96302. }
  96303. {
  96304. const int packets[]={0,100,4080,-1};
  96305. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96306. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96307. test_pack(packets,headret,0,0,0);
  96308. }
  96309. {
  96310. unsigned char *data=_ogg_malloc(1024*1024);
  96311. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96312. int inptr=0,i,j;
  96313. ogg_page og[5];
  96314. ogg_stream_reset(&os_en);
  96315. for(i=0;pl[i]!=-1;i++){
  96316. ogg_packet op;
  96317. int len=pl[i];
  96318. op.packet=data+inptr;
  96319. op.bytes=len;
  96320. op.e_o_s=(pl[i+1]<0?1:0);
  96321. op.granulepos=(i+1)*1000;
  96322. for(j=0;j<len;j++)data[inptr++]=i+j;
  96323. ogg_stream_packetin(&os_en,&op);
  96324. }
  96325. _ogg_free(data);
  96326. for(i=0;i<5;i++){
  96327. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96328. fprintf(stderr,"Too few pages output building sync tests!\n");
  96329. exit(1);
  96330. }
  96331. copy_page(&og[i]);
  96332. }
  96333. {
  96334. ogg_page temp;
  96335. ogg_packet test;
  96336. fprintf(stderr,"Testing loss of pages... ");
  96337. ogg_sync_reset(&oy);
  96338. ogg_stream_reset(&os_de);
  96339. for(i=0;i<5;i++){
  96340. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96341. og[i].header_len);
  96342. ogg_sync_wrote(&oy,og[i].header_len);
  96343. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96344. ogg_sync_wrote(&oy,og[i].body_len);
  96345. }
  96346. ogg_sync_pageout(&oy,&temp);
  96347. ogg_stream_pagein(&os_de,&temp);
  96348. ogg_sync_pageout(&oy,&temp);
  96349. ogg_stream_pagein(&os_de,&temp);
  96350. ogg_sync_pageout(&oy,&temp);
  96351. ogg_sync_pageout(&oy,&temp);
  96352. ogg_stream_pagein(&os_de,&temp);
  96353. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96354. checkpacket(&test,0,0,0);
  96355. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96356. checkpacket(&test,100,1,-1);
  96357. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96358. checkpacket(&test,4079,2,3000);
  96359. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96360. fprintf(stderr,"Error: loss of page did not return error\n");
  96361. exit(1);
  96362. }
  96363. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96364. checkpacket(&test,76,5,-1);
  96365. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96366. checkpacket(&test,34,6,-1);
  96367. fprintf(stderr,"ok.\n");
  96368. }
  96369. {
  96370. ogg_page temp;
  96371. ogg_packet test;
  96372. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96373. ogg_sync_reset(&oy);
  96374. ogg_stream_reset(&os_de);
  96375. for(i=0;i<5;i++){
  96376. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96377. og[i].header_len);
  96378. ogg_sync_wrote(&oy,og[i].header_len);
  96379. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96380. ogg_sync_wrote(&oy,og[i].body_len);
  96381. }
  96382. ogg_sync_pageout(&oy,&temp);
  96383. ogg_stream_pagein(&os_de,&temp);
  96384. ogg_sync_pageout(&oy,&temp);
  96385. ogg_stream_pagein(&os_de,&temp);
  96386. ogg_sync_pageout(&oy,&temp);
  96387. ogg_stream_pagein(&os_de,&temp);
  96388. ogg_sync_pageout(&oy,&temp);
  96389. ogg_sync_pageout(&oy,&temp);
  96390. ogg_stream_pagein(&os_de,&temp);
  96391. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96392. checkpacket(&test,0,0,0);
  96393. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96394. checkpacket(&test,100,1,-1);
  96395. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96396. checkpacket(&test,4079,2,3000);
  96397. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96398. checkpacket(&test,2956,3,4000);
  96399. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96400. fprintf(stderr,"Error: loss of page did not return error\n");
  96401. exit(1);
  96402. }
  96403. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96404. checkpacket(&test,300,13,14000);
  96405. fprintf(stderr,"ok.\n");
  96406. }
  96407. {
  96408. ogg_page og_de;
  96409. fprintf(stderr,"Testing sync on partial inputs... ");
  96410. ogg_sync_reset(&oy);
  96411. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96412. 3);
  96413. ogg_sync_wrote(&oy,3);
  96414. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96415. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96416. 20);
  96417. ogg_sync_wrote(&oy,20);
  96418. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96419. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96420. 5);
  96421. ogg_sync_wrote(&oy,5);
  96422. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96423. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96424. og[1].header_len-28);
  96425. ogg_sync_wrote(&oy,og[1].header_len-28);
  96426. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96427. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96428. ogg_sync_wrote(&oy,1000);
  96429. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96430. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96431. og[1].body_len-1000);
  96432. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96433. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96434. fprintf(stderr,"ok.\n");
  96435. }
  96436. {
  96437. ogg_page og_de;
  96438. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96439. ogg_sync_reset(&oy);
  96440. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96441. og[1].header_len);
  96442. ogg_sync_wrote(&oy,og[1].header_len);
  96443. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96444. og[1].body_len);
  96445. ogg_sync_wrote(&oy,og[1].body_len);
  96446. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96447. 20);
  96448. ogg_sync_wrote(&oy,20);
  96449. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96450. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96451. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96452. og[1].header_len-20);
  96453. ogg_sync_wrote(&oy,og[1].header_len-20);
  96454. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96455. og[1].body_len);
  96456. ogg_sync_wrote(&oy,og[1].body_len);
  96457. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96458. fprintf(stderr,"ok.\n");
  96459. }
  96460. {
  96461. ogg_page og_de;
  96462. fprintf(stderr,"Testing search for capture... ");
  96463. ogg_sync_reset(&oy);
  96464. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96465. og[1].body_len);
  96466. ogg_sync_wrote(&oy,og[1].body_len);
  96467. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96468. og[1].header_len);
  96469. ogg_sync_wrote(&oy,og[1].header_len);
  96470. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96471. og[1].body_len);
  96472. ogg_sync_wrote(&oy,og[1].body_len);
  96473. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96474. 20);
  96475. ogg_sync_wrote(&oy,20);
  96476. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96477. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96478. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96479. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96480. og[2].header_len-20);
  96481. ogg_sync_wrote(&oy,og[2].header_len-20);
  96482. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96483. og[2].body_len);
  96484. ogg_sync_wrote(&oy,og[2].body_len);
  96485. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96486. fprintf(stderr,"ok.\n");
  96487. }
  96488. {
  96489. ogg_page og_de;
  96490. fprintf(stderr,"Testing recapture... ");
  96491. ogg_sync_reset(&oy);
  96492. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96493. og[1].header_len);
  96494. ogg_sync_wrote(&oy,og[1].header_len);
  96495. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96496. og[1].body_len);
  96497. ogg_sync_wrote(&oy,og[1].body_len);
  96498. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96499. og[2].header_len);
  96500. ogg_sync_wrote(&oy,og[2].header_len);
  96501. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96502. og[2].header_len);
  96503. ogg_sync_wrote(&oy,og[2].header_len);
  96504. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96505. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96506. og[2].body_len-5);
  96507. ogg_sync_wrote(&oy,og[2].body_len-5);
  96508. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96509. og[3].header_len);
  96510. ogg_sync_wrote(&oy,og[3].header_len);
  96511. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96512. og[3].body_len);
  96513. ogg_sync_wrote(&oy,og[3].body_len);
  96514. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96515. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96516. fprintf(stderr,"ok.\n");
  96517. }
  96518. {
  96519. for(i=0;i<5;i++){
  96520. free_page(&og[i]);
  96521. }
  96522. }
  96523. }
  96524. return(0);
  96525. }
  96526. #endif
  96527. #endif
  96528. /*** End of inlined file: framing.c ***/
  96529. /*** Start of inlined file: analysis.c ***/
  96530. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96531. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96532. // tasks..
  96533. #if JUCE_MSVC
  96534. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96535. #endif
  96536. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96537. #if JUCE_USE_OGGVORBIS
  96538. #include <stdio.h>
  96539. #include <string.h>
  96540. #include <math.h>
  96541. /*** Start of inlined file: codec_internal.h ***/
  96542. #ifndef _V_CODECI_H_
  96543. #define _V_CODECI_H_
  96544. /*** Start of inlined file: envelope.h ***/
  96545. #ifndef _V_ENVELOPE_
  96546. #define _V_ENVELOPE_
  96547. /*** Start of inlined file: mdct.h ***/
  96548. #ifndef _OGG_mdct_H_
  96549. #define _OGG_mdct_H_
  96550. #ifdef MDCT_INTEGERIZED
  96551. #define DATA_TYPE int
  96552. #define REG_TYPE register int
  96553. #define TRIGBITS 14
  96554. #define cPI3_8 6270
  96555. #define cPI2_8 11585
  96556. #define cPI1_8 15137
  96557. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96558. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96559. #define HALVE(x) ((x)>>1)
  96560. #else
  96561. #define DATA_TYPE float
  96562. #define REG_TYPE float
  96563. #define cPI3_8 .38268343236508977175F
  96564. #define cPI2_8 .70710678118654752441F
  96565. #define cPI1_8 .92387953251128675613F
  96566. #define FLOAT_CONV(x) (x)
  96567. #define MULT_NORM(x) (x)
  96568. #define HALVE(x) ((x)*.5f)
  96569. #endif
  96570. typedef struct {
  96571. int n;
  96572. int log2n;
  96573. DATA_TYPE *trig;
  96574. int *bitrev;
  96575. DATA_TYPE scale;
  96576. } mdct_lookup;
  96577. extern void mdct_init(mdct_lookup *lookup,int n);
  96578. extern void mdct_clear(mdct_lookup *l);
  96579. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96580. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96581. #endif
  96582. /*** End of inlined file: mdct.h ***/
  96583. #define VE_PRE 16
  96584. #define VE_WIN 4
  96585. #define VE_POST 2
  96586. #define VE_AMP (VE_PRE+VE_POST-1)
  96587. #define VE_BANDS 7
  96588. #define VE_NEARDC 15
  96589. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96590. #define VE_MAXSTRETCH 12 /* one-third full block */
  96591. typedef struct {
  96592. float ampbuf[VE_AMP];
  96593. int ampptr;
  96594. float nearDC[VE_NEARDC];
  96595. float nearDC_acc;
  96596. float nearDC_partialacc;
  96597. int nearptr;
  96598. } envelope_filter_state;
  96599. typedef struct {
  96600. int begin;
  96601. int end;
  96602. float *window;
  96603. float total;
  96604. } envelope_band;
  96605. typedef struct {
  96606. int ch;
  96607. int winlength;
  96608. int searchstep;
  96609. float minenergy;
  96610. mdct_lookup mdct;
  96611. float *mdct_win;
  96612. envelope_band band[VE_BANDS];
  96613. envelope_filter_state *filter;
  96614. int stretch;
  96615. int *mark;
  96616. long storage;
  96617. long current;
  96618. long curmark;
  96619. long cursor;
  96620. } envelope_lookup;
  96621. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96622. extern void _ve_envelope_clear(envelope_lookup *e);
  96623. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96624. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96625. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96626. #endif
  96627. /*** End of inlined file: envelope.h ***/
  96628. /*** Start of inlined file: codebook.h ***/
  96629. #ifndef _V_CODEBOOK_H_
  96630. #define _V_CODEBOOK_H_
  96631. typedef struct static_codebook{
  96632. long dim; /* codebook dimensions (elements per vector) */
  96633. long entries; /* codebook entries */
  96634. long *lengthlist; /* codeword lengths in bits */
  96635. int maptype; /* 0=none
  96636. 1=implicitly populated values from map column
  96637. 2=listed arbitrary values */
  96638. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96639. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96640. int q_quant; /* bits: 0 < quant <= 16 */
  96641. int q_sequencep; /* bitflag */
  96642. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96643. map == 2: list of dim*entries quantized entry vals
  96644. */
  96645. struct encode_aux_nearestmatch *nearest_tree;
  96646. struct encode_aux_threshmatch *thresh_tree;
  96647. struct encode_aux_pigeonhole *pigeon_tree;
  96648. int allocedp;
  96649. } static_codebook;
  96650. typedef struct encode_aux_nearestmatch{
  96651. long *ptr0;
  96652. long *ptr1;
  96653. long *p; /* decision points (each is an entry) */
  96654. long *q; /* decision points (each is an entry) */
  96655. long aux; /* number of tree entries */
  96656. long alloc;
  96657. } encode_aux_nearestmatch;
  96658. typedef struct encode_aux_threshmatch{
  96659. float *quantthresh;
  96660. long *quantmap;
  96661. int quantvals;
  96662. int threshvals;
  96663. } encode_aux_threshmatch;
  96664. typedef struct encode_aux_pigeonhole{
  96665. float min;
  96666. float del;
  96667. int mapentries;
  96668. int quantvals;
  96669. long *pigeonmap;
  96670. long fittotal;
  96671. long *fitlist;
  96672. long *fitmap;
  96673. long *fitlength;
  96674. } encode_aux_pigeonhole;
  96675. typedef struct codebook{
  96676. long dim; /* codebook dimensions (elements per vector) */
  96677. long entries; /* codebook entries */
  96678. long used_entries; /* populated codebook entries */
  96679. const static_codebook *c;
  96680. float *valuelist; /* list of dim*entries actual entry values */
  96681. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96682. int *dec_index; /* only used if sparseness collapsed */
  96683. char *dec_codelengths;
  96684. ogg_uint32_t *dec_firsttable;
  96685. int dec_firsttablen;
  96686. int dec_maxlength;
  96687. } codebook;
  96688. extern void vorbis_staticbook_clear(static_codebook *b);
  96689. extern void vorbis_staticbook_destroy(static_codebook *b);
  96690. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96691. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96692. extern void vorbis_book_clear(codebook *b);
  96693. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96694. extern float *_book_logdist(const static_codebook *b,float *vals);
  96695. extern float _float32_unpack(long val);
  96696. extern long _float32_pack(float val);
  96697. extern int _best(codebook *book, float *a, int step);
  96698. extern int _ilog(unsigned int v);
  96699. extern long _book_maptype1_quantvals(const static_codebook *b);
  96700. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96701. extern long vorbis_book_codeword(codebook *book,int entry);
  96702. extern long vorbis_book_codelen(codebook *book,int entry);
  96703. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96704. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96705. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96706. extern int vorbis_book_errorv(codebook *book, float *a);
  96707. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96708. oggpack_buffer *b);
  96709. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96710. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96711. oggpack_buffer *b,int n);
  96712. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96713. oggpack_buffer *b,int n);
  96714. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96715. oggpack_buffer *b,int n);
  96716. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96717. long off,int ch,
  96718. oggpack_buffer *b,int n);
  96719. #endif
  96720. /*** End of inlined file: codebook.h ***/
  96721. #define BLOCKTYPE_IMPULSE 0
  96722. #define BLOCKTYPE_PADDING 1
  96723. #define BLOCKTYPE_TRANSITION 0
  96724. #define BLOCKTYPE_LONG 1
  96725. #define PACKETBLOBS 15
  96726. typedef struct vorbis_block_internal{
  96727. float **pcmdelay; /* this is a pointer into local storage */
  96728. float ampmax;
  96729. int blocktype;
  96730. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96731. blob [PACKETBLOBS/2] points to
  96732. the oggpack_buffer in the
  96733. main vorbis_block */
  96734. } vorbis_block_internal;
  96735. typedef void vorbis_look_floor;
  96736. typedef void vorbis_look_residue;
  96737. typedef void vorbis_look_transform;
  96738. typedef struct {
  96739. int blockflag;
  96740. int windowtype;
  96741. int transformtype;
  96742. int mapping;
  96743. } vorbis_info_mode;
  96744. typedef void vorbis_info_floor;
  96745. typedef void vorbis_info_residue;
  96746. typedef void vorbis_info_mapping;
  96747. /*** Start of inlined file: psy.h ***/
  96748. #ifndef _V_PSY_H_
  96749. #define _V_PSY_H_
  96750. /*** Start of inlined file: smallft.h ***/
  96751. #ifndef _V_SMFT_H_
  96752. #define _V_SMFT_H_
  96753. typedef struct {
  96754. int n;
  96755. float *trigcache;
  96756. int *splitcache;
  96757. } drft_lookup;
  96758. extern void drft_forward(drft_lookup *l,float *data);
  96759. extern void drft_backward(drft_lookup *l,float *data);
  96760. extern void drft_init(drft_lookup *l,int n);
  96761. extern void drft_clear(drft_lookup *l);
  96762. #endif
  96763. /*** End of inlined file: smallft.h ***/
  96764. /*** Start of inlined file: backends.h ***/
  96765. #ifndef _vorbis_backend_h_
  96766. #define _vorbis_backend_h_
  96767. typedef struct{
  96768. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96769. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96770. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96771. void (*free_info) (vorbis_info_floor *);
  96772. void (*free_look) (vorbis_look_floor *);
  96773. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96774. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96775. void *buffer,float *);
  96776. } vorbis_func_floor;
  96777. typedef struct{
  96778. int order;
  96779. long rate;
  96780. long barkmap;
  96781. int ampbits;
  96782. int ampdB;
  96783. int numbooks; /* <= 16 */
  96784. int books[16];
  96785. float lessthan; /* encode-only config setting hacks for libvorbis */
  96786. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96787. } vorbis_info_floor0;
  96788. #define VIF_POSIT 63
  96789. #define VIF_CLASS 16
  96790. #define VIF_PARTS 31
  96791. typedef struct{
  96792. int partitions; /* 0 to 31 */
  96793. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96794. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96795. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96796. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96797. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96798. int mult; /* 1 2 3 or 4 */
  96799. int postlist[VIF_POSIT+2]; /* first two implicit */
  96800. float maxover;
  96801. float maxunder;
  96802. float maxerr;
  96803. float twofitweight;
  96804. float twofitatten;
  96805. int n;
  96806. } vorbis_info_floor1;
  96807. typedef struct{
  96808. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96809. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96810. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96811. vorbis_info_residue *);
  96812. void (*free_info) (vorbis_info_residue *);
  96813. void (*free_look) (vorbis_look_residue *);
  96814. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96815. float **,int *,int);
  96816. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96817. vorbis_look_residue *,
  96818. float **,float **,int *,int,long **);
  96819. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96820. float **,int *,int);
  96821. } vorbis_func_residue;
  96822. typedef struct vorbis_info_residue0{
  96823. long begin;
  96824. long end;
  96825. int grouping; /* group n vectors per partition */
  96826. int partitions; /* possible codebooks for a partition */
  96827. int groupbook; /* huffbook for partitioning */
  96828. int secondstages[64]; /* expanded out to pointers in lookup */
  96829. int booklist[256]; /* list of second stage books */
  96830. float classmetric1[64];
  96831. float classmetric2[64];
  96832. } vorbis_info_residue0;
  96833. typedef struct{
  96834. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96835. oggpack_buffer *);
  96836. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96837. void (*free_info) (vorbis_info_mapping *);
  96838. int (*forward) (struct vorbis_block *vb);
  96839. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96840. } vorbis_func_mapping;
  96841. typedef struct vorbis_info_mapping0{
  96842. int submaps; /* <= 16 */
  96843. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96844. int floorsubmap[16]; /* [mux] submap to floors */
  96845. int residuesubmap[16]; /* [mux] submap to residue */
  96846. int coupling_steps;
  96847. int coupling_mag[256];
  96848. int coupling_ang[256];
  96849. } vorbis_info_mapping0;
  96850. #endif
  96851. /*** End of inlined file: backends.h ***/
  96852. #ifndef EHMER_MAX
  96853. #define EHMER_MAX 56
  96854. #endif
  96855. #define P_BANDS 17 /* 62Hz to 16kHz */
  96856. #define P_LEVELS 8 /* 30dB to 100dB */
  96857. #define P_LEVEL_0 30. /* 30 dB */
  96858. #define P_NOISECURVES 3
  96859. #define NOISE_COMPAND_LEVELS 40
  96860. typedef struct vorbis_info_psy{
  96861. int blockflag;
  96862. float ath_adjatt;
  96863. float ath_maxatt;
  96864. float tone_masteratt[P_NOISECURVES];
  96865. float tone_centerboost;
  96866. float tone_decay;
  96867. float tone_abs_limit;
  96868. float toneatt[P_BANDS];
  96869. int noisemaskp;
  96870. float noisemaxsupp;
  96871. float noisewindowlo;
  96872. float noisewindowhi;
  96873. int noisewindowlomin;
  96874. int noisewindowhimin;
  96875. int noisewindowfixed;
  96876. float noiseoff[P_NOISECURVES][P_BANDS];
  96877. float noisecompand[NOISE_COMPAND_LEVELS];
  96878. float max_curve_dB;
  96879. int normal_channel_p;
  96880. int normal_point_p;
  96881. int normal_start;
  96882. int normal_partition;
  96883. double normal_thresh;
  96884. } vorbis_info_psy;
  96885. typedef struct{
  96886. int eighth_octave_lines;
  96887. float preecho_thresh[VE_BANDS];
  96888. float postecho_thresh[VE_BANDS];
  96889. float stretch_penalty;
  96890. float preecho_minenergy;
  96891. float ampmax_att_per_sec;
  96892. int coupling_pkHz[PACKETBLOBS];
  96893. int coupling_pointlimit[2][PACKETBLOBS];
  96894. int coupling_prepointamp[PACKETBLOBS];
  96895. int coupling_postpointamp[PACKETBLOBS];
  96896. int sliding_lowpass[2][PACKETBLOBS];
  96897. } vorbis_info_psy_global;
  96898. typedef struct {
  96899. float ampmax;
  96900. int channels;
  96901. vorbis_info_psy_global *gi;
  96902. int coupling_pointlimit[2][P_NOISECURVES];
  96903. } vorbis_look_psy_global;
  96904. typedef struct {
  96905. int n;
  96906. struct vorbis_info_psy *vi;
  96907. float ***tonecurves;
  96908. float **noiseoffset;
  96909. float *ath;
  96910. long *octave; /* in n.ocshift format */
  96911. long *bark;
  96912. long firstoc;
  96913. long shiftoc;
  96914. int eighth_octave_lines; /* power of two, please */
  96915. int total_octave_lines;
  96916. long rate; /* cache it */
  96917. float m_val; /* Masking compensation value */
  96918. } vorbis_look_psy;
  96919. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  96920. vorbis_info_psy_global *gi,int n,long rate);
  96921. extern void _vp_psy_clear(vorbis_look_psy *p);
  96922. extern void *_vi_psy_dup(void *source);
  96923. extern void _vi_psy_free(vorbis_info_psy *i);
  96924. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  96925. extern void _vp_remove_floor(vorbis_look_psy *p,
  96926. float *mdct,
  96927. int *icodedflr,
  96928. float *residue,
  96929. int sliding_lowpass);
  96930. extern void _vp_noisemask(vorbis_look_psy *p,
  96931. float *logmdct,
  96932. float *logmask);
  96933. extern void _vp_tonemask(vorbis_look_psy *p,
  96934. float *logfft,
  96935. float *logmask,
  96936. float global_specmax,
  96937. float local_specmax);
  96938. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  96939. float *noise,
  96940. float *tone,
  96941. int offset_select,
  96942. float *logmask,
  96943. float *mdct,
  96944. float *logmdct);
  96945. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  96946. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  96947. vorbis_info_psy_global *g,
  96948. vorbis_look_psy *p,
  96949. vorbis_info_mapping0 *vi,
  96950. float **mdct);
  96951. extern void _vp_couple(int blobno,
  96952. vorbis_info_psy_global *g,
  96953. vorbis_look_psy *p,
  96954. vorbis_info_mapping0 *vi,
  96955. float **res,
  96956. float **mag_memo,
  96957. int **mag_sort,
  96958. int **ifloor,
  96959. int *nonzero,
  96960. int sliding_lowpass);
  96961. extern void _vp_noise_normalize(vorbis_look_psy *p,
  96962. float *in,float *out,int *sortedindex);
  96963. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  96964. float *magnitudes,int *sortedindex);
  96965. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  96966. vorbis_look_psy *p,
  96967. vorbis_info_mapping0 *vi,
  96968. float **mags);
  96969. extern void hf_reduction(vorbis_info_psy_global *g,
  96970. vorbis_look_psy *p,
  96971. vorbis_info_mapping0 *vi,
  96972. float **mdct);
  96973. #endif
  96974. /*** End of inlined file: psy.h ***/
  96975. /*** Start of inlined file: bitrate.h ***/
  96976. #ifndef _V_BITRATE_H_
  96977. #define _V_BITRATE_H_
  96978. /*** Start of inlined file: os.h ***/
  96979. #ifndef _OS_H
  96980. #define _OS_H
  96981. #ifdef HAVE_CONFIG_H
  96982. #include "config.h"
  96983. #endif
  96984. #include <math.h>
  96985. /*** Start of inlined file: misc.h ***/
  96986. #ifndef _V_RANDOM_H_
  96987. #define _V_RANDOM_H_
  96988. extern int analysis_noisy;
  96989. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  96990. extern void _vorbis_block_ripcord(vorbis_block *vb);
  96991. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  96992. ogg_int64_t off);
  96993. #ifdef DEBUG_MALLOC
  96994. #define _VDBG_GRAPHFILE "malloc.m"
  96995. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  96996. extern void _VDBG_free(void *ptr,char *file,long line);
  96997. #ifndef MISC_C
  96998. #undef _ogg_malloc
  96999. #undef _ogg_calloc
  97000. #undef _ogg_realloc
  97001. #undef _ogg_free
  97002. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97003. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97004. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97005. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97006. #endif
  97007. #endif
  97008. #endif
  97009. /*** End of inlined file: misc.h ***/
  97010. #ifndef _V_IFDEFJAIL_H_
  97011. # define _V_IFDEFJAIL_H_
  97012. # ifdef __GNUC__
  97013. # define STIN static __inline__
  97014. # elif _WIN32
  97015. # define STIN static __inline
  97016. # else
  97017. # define STIN static
  97018. # endif
  97019. #ifdef DJGPP
  97020. # define rint(x) (floor((x)+0.5f))
  97021. #endif
  97022. #ifndef M_PI
  97023. # define M_PI (3.1415926536f)
  97024. #endif
  97025. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97026. # include <malloc.h>
  97027. # define rint(x) (floor((x)+0.5f))
  97028. # define NO_FLOAT_MATH_LIB
  97029. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97030. #endif
  97031. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97032. void *_alloca(size_t size);
  97033. # define alloca _alloca
  97034. #endif
  97035. #ifndef FAST_HYPOT
  97036. # define FAST_HYPOT hypot
  97037. #endif
  97038. #endif
  97039. #ifdef HAVE_ALLOCA_H
  97040. # include <alloca.h>
  97041. #endif
  97042. #ifdef USE_MEMORY_H
  97043. # include <memory.h>
  97044. #endif
  97045. #ifndef min
  97046. # define min(x,y) ((x)>(y)?(y):(x))
  97047. #endif
  97048. #ifndef max
  97049. # define max(x,y) ((x)<(y)?(y):(x))
  97050. #endif
  97051. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97052. # define VORBIS_FPU_CONTROL
  97053. typedef ogg_int16_t vorbis_fpu_control;
  97054. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97055. ogg_int16_t ret;
  97056. ogg_int16_t temp;
  97057. __asm__ __volatile__("fnstcw %0\n\t"
  97058. "movw %0,%%dx\n\t"
  97059. "orw $62463,%%dx\n\t"
  97060. "movw %%dx,%1\n\t"
  97061. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97062. *fpu=ret;
  97063. }
  97064. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97065. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97066. }
  97067. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97068. we get extra fst/fld to
  97069. truncate precision */
  97070. int i;
  97071. __asm__("fistl %0": "=m"(i) : "t"(f));
  97072. return(i);
  97073. }
  97074. #endif
  97075. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97076. # define VORBIS_FPU_CONTROL
  97077. typedef ogg_int16_t vorbis_fpu_control;
  97078. static __inline int vorbis_ftoi(double f){
  97079. int i;
  97080. __asm{
  97081. fld f
  97082. fistp i
  97083. }
  97084. return i;
  97085. }
  97086. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97087. }
  97088. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97089. }
  97090. #endif
  97091. #ifndef VORBIS_FPU_CONTROL
  97092. typedef int vorbis_fpu_control;
  97093. static int vorbis_ftoi(double f){
  97094. return (int)(f+.5);
  97095. }
  97096. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97097. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97098. #endif
  97099. #endif /* _OS_H */
  97100. /*** End of inlined file: os.h ***/
  97101. typedef struct bitrate_manager_state {
  97102. int managed;
  97103. long avg_reservoir;
  97104. long minmax_reservoir;
  97105. long avg_bitsper;
  97106. long min_bitsper;
  97107. long max_bitsper;
  97108. long short_per_long;
  97109. double avgfloat;
  97110. vorbis_block *vb;
  97111. int choice;
  97112. } bitrate_manager_state;
  97113. typedef struct bitrate_manager_info{
  97114. long avg_rate;
  97115. long min_rate;
  97116. long max_rate;
  97117. long reservoir_bits;
  97118. double reservoir_bias;
  97119. double slew_damp;
  97120. } bitrate_manager_info;
  97121. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97122. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97123. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97124. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97125. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97126. #endif
  97127. /*** End of inlined file: bitrate.h ***/
  97128. static int ilog(unsigned int v){
  97129. int ret=0;
  97130. while(v){
  97131. ret++;
  97132. v>>=1;
  97133. }
  97134. return(ret);
  97135. }
  97136. static int ilog2(unsigned int v){
  97137. int ret=0;
  97138. if(v)--v;
  97139. while(v){
  97140. ret++;
  97141. v>>=1;
  97142. }
  97143. return(ret);
  97144. }
  97145. typedef struct private_state {
  97146. envelope_lookup *ve; /* envelope lookup */
  97147. int window[2];
  97148. vorbis_look_transform **transform[2]; /* block, type */
  97149. drft_lookup fft_look[2];
  97150. int modebits;
  97151. vorbis_look_floor **flr;
  97152. vorbis_look_residue **residue;
  97153. vorbis_look_psy *psy;
  97154. vorbis_look_psy_global *psy_g_look;
  97155. unsigned char *header;
  97156. unsigned char *header1;
  97157. unsigned char *header2;
  97158. bitrate_manager_state bms;
  97159. ogg_int64_t sample_count;
  97160. } private_state;
  97161. /*** Start of inlined file: highlevel.h ***/
  97162. typedef struct highlevel_byblocktype {
  97163. double tone_mask_setting;
  97164. double tone_peaklimit_setting;
  97165. double noise_bias_setting;
  97166. double noise_compand_setting;
  97167. } highlevel_byblocktype;
  97168. typedef struct highlevel_encode_setup {
  97169. void *setup;
  97170. int set_in_stone;
  97171. double base_setting;
  97172. double long_setting;
  97173. double short_setting;
  97174. double impulse_noisetune;
  97175. int managed;
  97176. long bitrate_min;
  97177. long bitrate_av;
  97178. double bitrate_av_damp;
  97179. long bitrate_max;
  97180. long bitrate_reservoir;
  97181. double bitrate_reservoir_bias;
  97182. int impulse_block_p;
  97183. int noise_normalize_p;
  97184. double stereo_point_setting;
  97185. double lowpass_kHz;
  97186. double ath_floating_dB;
  97187. double ath_absolute_dB;
  97188. double amplitude_track_dBpersec;
  97189. double trigger_setting;
  97190. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97191. } highlevel_encode_setup;
  97192. /*** End of inlined file: highlevel.h ***/
  97193. typedef struct codec_setup_info {
  97194. long blocksizes[2];
  97195. int modes;
  97196. int maps;
  97197. int floors;
  97198. int residues;
  97199. int books;
  97200. int psys; /* encode only */
  97201. vorbis_info_mode *mode_param[64];
  97202. int map_type[64];
  97203. vorbis_info_mapping *map_param[64];
  97204. int floor_type[64];
  97205. vorbis_info_floor *floor_param[64];
  97206. int residue_type[64];
  97207. vorbis_info_residue *residue_param[64];
  97208. static_codebook *book_param[256];
  97209. codebook *fullbooks;
  97210. vorbis_info_psy *psy_param[4]; /* encode only */
  97211. vorbis_info_psy_global psy_g_param;
  97212. bitrate_manager_info bi;
  97213. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97214. highly redundant structure, but
  97215. improves clarity of program flow. */
  97216. int halfrate_flag; /* painless downsample for decode */
  97217. } codec_setup_info;
  97218. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97219. extern void _vp_global_free(vorbis_look_psy_global *look);
  97220. #endif
  97221. /*** End of inlined file: codec_internal.h ***/
  97222. /*** Start of inlined file: registry.h ***/
  97223. #ifndef _V_REG_H_
  97224. #define _V_REG_H_
  97225. #define VI_TRANSFORMB 1
  97226. #define VI_WINDOWB 1
  97227. #define VI_TIMEB 1
  97228. #define VI_FLOORB 2
  97229. #define VI_RESB 3
  97230. #define VI_MAPB 1
  97231. extern vorbis_func_floor *_floor_P[];
  97232. extern vorbis_func_residue *_residue_P[];
  97233. extern vorbis_func_mapping *_mapping_P[];
  97234. #endif
  97235. /*** End of inlined file: registry.h ***/
  97236. /*** Start of inlined file: scales.h ***/
  97237. #ifndef _V_SCALES_H_
  97238. #define _V_SCALES_H_
  97239. #include <math.h>
  97240. #define VORBIS_IEEE_FLOAT32 1
  97241. #ifdef VORBIS_IEEE_FLOAT32
  97242. static float unitnorm(float x){
  97243. union {
  97244. ogg_uint32_t i;
  97245. float f;
  97246. } ix;
  97247. ix.f = x;
  97248. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97249. return ix.f;
  97250. }
  97251. static float todB(const float *x){
  97252. union {
  97253. ogg_uint32_t i;
  97254. float f;
  97255. } ix;
  97256. ix.f = *x;
  97257. ix.i = ix.i&0x7fffffff;
  97258. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97259. }
  97260. #define todB_nn(x) todB(x)
  97261. #else
  97262. static float unitnorm(float x){
  97263. if(x<0)return(-1.f);
  97264. return(1.f);
  97265. }
  97266. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97267. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97268. #endif
  97269. #define fromdB(x) (exp((x)*.11512925f))
  97270. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97271. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97272. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97273. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97274. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97275. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97276. #endif
  97277. /*** End of inlined file: scales.h ***/
  97278. int analysis_noisy=1;
  97279. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97280. int ret,i;
  97281. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97282. vb->glue_bits=0;
  97283. vb->time_bits=0;
  97284. vb->floor_bits=0;
  97285. vb->res_bits=0;
  97286. for(i=0;i<PACKETBLOBS;i++)
  97287. oggpack_reset(vbi->packetblob[i]);
  97288. if((ret=_mapping_P[0]->forward(vb)))
  97289. return(ret);
  97290. if(op){
  97291. if(vorbis_bitrate_managed(vb))
  97292. return(OV_EINVAL);
  97293. op->packet=oggpack_get_buffer(&vb->opb);
  97294. op->bytes=oggpack_bytes(&vb->opb);
  97295. op->b_o_s=0;
  97296. op->e_o_s=vb->eofflag;
  97297. op->granulepos=vb->granulepos;
  97298. op->packetno=vb->sequence; /* for sake of completeness */
  97299. }
  97300. return(0);
  97301. }
  97302. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97303. int j;
  97304. FILE *of;
  97305. char buffer[80];
  97306. sprintf(buffer,"%s_%d.m",base,i);
  97307. of=fopen(buffer,"w");
  97308. if(!of)perror("failed to open data dump file");
  97309. for(j=0;j<n;j++){
  97310. if(bark){
  97311. float b=toBARK((4000.f*j/n)+.25);
  97312. fprintf(of,"%f ",b);
  97313. }else
  97314. if(off!=0)
  97315. fprintf(of,"%f ",(double)(j+off)/8000.);
  97316. else
  97317. fprintf(of,"%f ",(double)j);
  97318. if(dB){
  97319. float val;
  97320. if(v[j]==0.)
  97321. val=-140.;
  97322. else
  97323. val=todB(v+j);
  97324. fprintf(of,"%f\n",val);
  97325. }else{
  97326. fprintf(of,"%f\n",v[j]);
  97327. }
  97328. }
  97329. fclose(of);
  97330. }
  97331. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97332. ogg_int64_t off){
  97333. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97334. }
  97335. #endif
  97336. /*** End of inlined file: analysis.c ***/
  97337. /*** Start of inlined file: bitrate.c ***/
  97338. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97339. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97340. // tasks..
  97341. #if JUCE_MSVC
  97342. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97343. #endif
  97344. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97345. #if JUCE_USE_OGGVORBIS
  97346. #include <stdlib.h>
  97347. #include <string.h>
  97348. #include <math.h>
  97349. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97350. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97351. bitrate_manager_info *bi=&ci->bi;
  97352. memset(bm,0,sizeof(*bm));
  97353. if(bi && (bi->reservoir_bits>0)){
  97354. long ratesamples=vi->rate;
  97355. int halfsamples=ci->blocksizes[0]>>1;
  97356. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97357. bm->managed=1;
  97358. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97359. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97360. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97361. bm->avgfloat=PACKETBLOBS/2;
  97362. {
  97363. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97364. bm->minmax_reservoir=desired_fill;
  97365. bm->avg_reservoir=desired_fill;
  97366. }
  97367. }
  97368. }
  97369. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97370. memset(bm,0,sizeof(*bm));
  97371. return;
  97372. }
  97373. int vorbis_bitrate_managed(vorbis_block *vb){
  97374. vorbis_dsp_state *vd=vb->vd;
  97375. private_state *b=(private_state*)vd->backend_state;
  97376. bitrate_manager_state *bm=&b->bms;
  97377. if(bm && bm->managed)return(1);
  97378. return(0);
  97379. }
  97380. int vorbis_bitrate_addblock(vorbis_block *vb){
  97381. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97382. vorbis_dsp_state *vd=vb->vd;
  97383. private_state *b=(private_state*)vd->backend_state;
  97384. bitrate_manager_state *bm=&b->bms;
  97385. vorbis_info *vi=vd->vi;
  97386. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97387. bitrate_manager_info *bi=&ci->bi;
  97388. int choice=rint(bm->avgfloat);
  97389. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97390. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97391. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97392. int samples=ci->blocksizes[vb->W]>>1;
  97393. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97394. if(!bm->managed){
  97395. if(bm->vb)return(-1); /* one has been submitted without
  97396. being claimed */
  97397. bm->vb=vb;
  97398. return(0);
  97399. }
  97400. bm->vb=vb;
  97401. if(bm->avg_bitsper>0){
  97402. double slew=0.;
  97403. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97404. double slewlimit= 15./bi->slew_damp;
  97405. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97406. while(choice>0 && this_bits>avg_target_bits &&
  97407. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97408. choice--;
  97409. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97410. }
  97411. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97412. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97413. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97414. choice++;
  97415. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97416. }
  97417. }
  97418. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97419. if(slew<-slewlimit)slew=-slewlimit;
  97420. if(slew>slewlimit)slew=slewlimit;
  97421. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97422. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97423. }
  97424. if(bm->min_bitsper>0){
  97425. if(this_bits<min_target_bits){
  97426. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97427. choice++;
  97428. if(choice>=PACKETBLOBS)break;
  97429. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97430. }
  97431. }
  97432. }
  97433. if(bm->max_bitsper>0){
  97434. if(this_bits>max_target_bits){
  97435. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97436. choice--;
  97437. if(choice<0)break;
  97438. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97439. }
  97440. }
  97441. }
  97442. if(choice<0){
  97443. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97444. bm->choice=choice=0;
  97445. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97446. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97447. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97448. }
  97449. }else{
  97450. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97451. if(choice>=PACKETBLOBS)
  97452. choice=PACKETBLOBS-1;
  97453. bm->choice=choice;
  97454. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97455. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97456. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97457. }
  97458. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97459. if(max_target_bits>0 && this_bits>max_target_bits){
  97460. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97461. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97462. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97463. }else{
  97464. if(bm->minmax_reservoir>desired_fill){
  97465. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97466. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97467. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97468. }else{
  97469. bm->minmax_reservoir=desired_fill;
  97470. }
  97471. }else{
  97472. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97473. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97474. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97475. }else{
  97476. bm->minmax_reservoir=desired_fill;
  97477. }
  97478. }
  97479. }
  97480. }
  97481. if(bm->avg_bitsper>0){
  97482. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97483. bm->avg_reservoir+=this_bits-avg_target_bits;
  97484. }
  97485. return(0);
  97486. }
  97487. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97488. private_state *b=(private_state*)vd->backend_state;
  97489. bitrate_manager_state *bm=&b->bms;
  97490. vorbis_block *vb=bm->vb;
  97491. int choice=PACKETBLOBS/2;
  97492. if(!vb)return 0;
  97493. if(op){
  97494. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97495. if(vorbis_bitrate_managed(vb))
  97496. choice=bm->choice;
  97497. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97498. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97499. op->b_o_s=0;
  97500. op->e_o_s=vb->eofflag;
  97501. op->granulepos=vb->granulepos;
  97502. op->packetno=vb->sequence; /* for sake of completeness */
  97503. }
  97504. bm->vb=0;
  97505. return(1);
  97506. }
  97507. #endif
  97508. /*** End of inlined file: bitrate.c ***/
  97509. /*** Start of inlined file: block.c ***/
  97510. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97511. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97512. // tasks..
  97513. #if JUCE_MSVC
  97514. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97515. #endif
  97516. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97517. #if JUCE_USE_OGGVORBIS
  97518. #include <stdio.h>
  97519. #include <stdlib.h>
  97520. #include <string.h>
  97521. /*** Start of inlined file: window.h ***/
  97522. #ifndef _V_WINDOW_
  97523. #define _V_WINDOW_
  97524. extern float *_vorbis_window_get(int n);
  97525. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97526. int lW,int W,int nW);
  97527. #endif
  97528. /*** End of inlined file: window.h ***/
  97529. /*** Start of inlined file: lpc.h ***/
  97530. #ifndef _V_LPC_H_
  97531. #define _V_LPC_H_
  97532. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97533. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97534. float *data,long n);
  97535. #endif
  97536. /*** End of inlined file: lpc.h ***/
  97537. #ifndef WORD_ALIGN
  97538. #define WORD_ALIGN 8
  97539. #endif
  97540. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97541. int i;
  97542. memset(vb,0,sizeof(*vb));
  97543. vb->vd=v;
  97544. vb->localalloc=0;
  97545. vb->localstore=NULL;
  97546. if(v->analysisp){
  97547. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97548. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97549. vbi->ampmax=-9999;
  97550. for(i=0;i<PACKETBLOBS;i++){
  97551. if(i==PACKETBLOBS/2){
  97552. vbi->packetblob[i]=&vb->opb;
  97553. }else{
  97554. vbi->packetblob[i]=
  97555. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97556. }
  97557. oggpack_writeinit(vbi->packetblob[i]);
  97558. }
  97559. }
  97560. return(0);
  97561. }
  97562. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97563. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97564. if(bytes+vb->localtop>vb->localalloc){
  97565. if(vb->localstore){
  97566. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97567. vb->totaluse+=vb->localtop;
  97568. link->next=vb->reap;
  97569. link->ptr=vb->localstore;
  97570. vb->reap=link;
  97571. }
  97572. vb->localalloc=bytes;
  97573. vb->localstore=_ogg_malloc(vb->localalloc);
  97574. vb->localtop=0;
  97575. }
  97576. {
  97577. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97578. vb->localtop+=bytes;
  97579. return ret;
  97580. }
  97581. }
  97582. void _vorbis_block_ripcord(vorbis_block *vb){
  97583. struct alloc_chain *reap=vb->reap;
  97584. while(reap){
  97585. struct alloc_chain *next=reap->next;
  97586. _ogg_free(reap->ptr);
  97587. memset(reap,0,sizeof(*reap));
  97588. _ogg_free(reap);
  97589. reap=next;
  97590. }
  97591. if(vb->totaluse){
  97592. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97593. vb->localalloc+=vb->totaluse;
  97594. vb->totaluse=0;
  97595. }
  97596. vb->localtop=0;
  97597. vb->reap=NULL;
  97598. }
  97599. int vorbis_block_clear(vorbis_block *vb){
  97600. int i;
  97601. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97602. _vorbis_block_ripcord(vb);
  97603. if(vb->localstore)_ogg_free(vb->localstore);
  97604. if(vbi){
  97605. for(i=0;i<PACKETBLOBS;i++){
  97606. oggpack_writeclear(vbi->packetblob[i]);
  97607. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97608. }
  97609. _ogg_free(vbi);
  97610. }
  97611. memset(vb,0,sizeof(*vb));
  97612. return(0);
  97613. }
  97614. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97615. int i;
  97616. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97617. private_state *b=NULL;
  97618. int hs;
  97619. if(ci==NULL) return 1;
  97620. hs=ci->halfrate_flag;
  97621. memset(v,0,sizeof(*v));
  97622. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97623. v->vi=vi;
  97624. b->modebits=ilog2(ci->modes);
  97625. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97626. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97627. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97628. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97629. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97630. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97631. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97632. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97633. if(encp){ /* encode/decode differ here */
  97634. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97635. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97636. if(!ci->fullbooks){
  97637. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97638. for(i=0;i<ci->books;i++)
  97639. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97640. }
  97641. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97642. for(i=0;i<ci->psys;i++){
  97643. _vp_psy_init(b->psy+i,
  97644. ci->psy_param[i],
  97645. &ci->psy_g_param,
  97646. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97647. vi->rate);
  97648. }
  97649. v->analysisp=1;
  97650. }else{
  97651. if(!ci->fullbooks){
  97652. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97653. for(i=0;i<ci->books;i++){
  97654. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97655. vorbis_staticbook_destroy(ci->book_param[i]);
  97656. ci->book_param[i]=NULL;
  97657. }
  97658. }
  97659. }
  97660. v->pcm_storage=ci->blocksizes[1];
  97661. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97662. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97663. {
  97664. int i;
  97665. for(i=0;i<vi->channels;i++)
  97666. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97667. }
  97668. v->lW=0; /* previous window size */
  97669. v->W=0; /* current window size */
  97670. v->centerW=ci->blocksizes[1]/2;
  97671. v->pcm_current=v->centerW;
  97672. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97673. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97674. for(i=0;i<ci->floors;i++)
  97675. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97676. look(v,ci->floor_param[i]);
  97677. for(i=0;i<ci->residues;i++)
  97678. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97679. look(v,ci->residue_param[i]);
  97680. return 0;
  97681. }
  97682. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97683. private_state *b=NULL;
  97684. if(_vds_shared_init(v,vi,1))return 1;
  97685. b=(private_state*)v->backend_state;
  97686. b->psy_g_look=_vp_global_look(vi);
  97687. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97688. _ve_envelope_init(b->ve,vi);
  97689. vorbis_bitrate_init(vi,&b->bms);
  97690. v->sequence=3;
  97691. return(0);
  97692. }
  97693. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97694. int i;
  97695. if(v){
  97696. vorbis_info *vi=v->vi;
  97697. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97698. private_state *b=(private_state*)v->backend_state;
  97699. if(b){
  97700. if(b->ve){
  97701. _ve_envelope_clear(b->ve);
  97702. _ogg_free(b->ve);
  97703. }
  97704. if(b->transform[0]){
  97705. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97706. _ogg_free(b->transform[0][0]);
  97707. _ogg_free(b->transform[0]);
  97708. }
  97709. if(b->transform[1]){
  97710. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97711. _ogg_free(b->transform[1][0]);
  97712. _ogg_free(b->transform[1]);
  97713. }
  97714. if(b->flr){
  97715. for(i=0;i<ci->floors;i++)
  97716. _floor_P[ci->floor_type[i]]->
  97717. free_look(b->flr[i]);
  97718. _ogg_free(b->flr);
  97719. }
  97720. if(b->residue){
  97721. for(i=0;i<ci->residues;i++)
  97722. _residue_P[ci->residue_type[i]]->
  97723. free_look(b->residue[i]);
  97724. _ogg_free(b->residue);
  97725. }
  97726. if(b->psy){
  97727. for(i=0;i<ci->psys;i++)
  97728. _vp_psy_clear(b->psy+i);
  97729. _ogg_free(b->psy);
  97730. }
  97731. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97732. vorbis_bitrate_clear(&b->bms);
  97733. drft_clear(&b->fft_look[0]);
  97734. drft_clear(&b->fft_look[1]);
  97735. }
  97736. if(v->pcm){
  97737. for(i=0;i<vi->channels;i++)
  97738. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97739. _ogg_free(v->pcm);
  97740. if(v->pcmret)_ogg_free(v->pcmret);
  97741. }
  97742. if(b){
  97743. if(b->header)_ogg_free(b->header);
  97744. if(b->header1)_ogg_free(b->header1);
  97745. if(b->header2)_ogg_free(b->header2);
  97746. _ogg_free(b);
  97747. }
  97748. memset(v,0,sizeof(*v));
  97749. }
  97750. }
  97751. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97752. int i;
  97753. vorbis_info *vi=v->vi;
  97754. private_state *b=(private_state*)v->backend_state;
  97755. if(b->header)_ogg_free(b->header);b->header=NULL;
  97756. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97757. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97758. if(v->pcm_current+vals>=v->pcm_storage){
  97759. v->pcm_storage=v->pcm_current+vals*2;
  97760. for(i=0;i<vi->channels;i++){
  97761. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97762. }
  97763. }
  97764. for(i=0;i<vi->channels;i++)
  97765. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97766. return(v->pcmret);
  97767. }
  97768. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97769. int i;
  97770. int order=32;
  97771. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97772. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97773. long j;
  97774. v->preextrapolate=1;
  97775. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97776. for(i=0;i<v->vi->channels;i++){
  97777. for(j=0;j<v->pcm_current;j++)
  97778. work[j]=v->pcm[i][v->pcm_current-j-1];
  97779. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97780. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97781. order,
  97782. work+v->pcm_current-v->centerW,
  97783. v->centerW);
  97784. for(j=0;j<v->pcm_current;j++)
  97785. v->pcm[i][v->pcm_current-j-1]=work[j];
  97786. }
  97787. }
  97788. }
  97789. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97790. vorbis_info *vi=v->vi;
  97791. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97792. if(vals<=0){
  97793. int order=32;
  97794. int i;
  97795. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97796. if(!v->preextrapolate)
  97797. _preextrapolate_helper(v);
  97798. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97799. v->eofflag=v->pcm_current;
  97800. v->pcm_current+=ci->blocksizes[1]*3;
  97801. for(i=0;i<vi->channels;i++){
  97802. if(v->eofflag>order*2){
  97803. long n;
  97804. n=v->eofflag;
  97805. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97806. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97807. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97808. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97809. }else{
  97810. memset(v->pcm[i]+v->eofflag,0,
  97811. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97812. }
  97813. }
  97814. }else{
  97815. if(v->pcm_current+vals>v->pcm_storage)
  97816. return(OV_EINVAL);
  97817. v->pcm_current+=vals;
  97818. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97819. _preextrapolate_helper(v);
  97820. }
  97821. return(0);
  97822. }
  97823. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97824. int i;
  97825. vorbis_info *vi=v->vi;
  97826. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97827. private_state *b=(private_state*)v->backend_state;
  97828. vorbis_look_psy_global *g=b->psy_g_look;
  97829. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97830. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97831. if(!v->preextrapolate)return(0);
  97832. if(v->eofflag==-1)return(0);
  97833. {
  97834. long bp=_ve_envelope_search(v);
  97835. if(bp==-1){
  97836. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97837. full long block */
  97838. v->nW=0;
  97839. }else{
  97840. if(ci->blocksizes[0]==ci->blocksizes[1])
  97841. v->nW=0;
  97842. else
  97843. v->nW=bp;
  97844. }
  97845. }
  97846. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97847. {
  97848. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97849. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97850. although this check is
  97851. less strict that the
  97852. _ve_envelope_search,
  97853. the search is not run
  97854. if we only use one
  97855. block size */
  97856. }
  97857. _vorbis_block_ripcord(vb);
  97858. vb->lW=v->lW;
  97859. vb->W=v->W;
  97860. vb->nW=v->nW;
  97861. if(v->W){
  97862. if(!v->lW || !v->nW){
  97863. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97864. }else{
  97865. vbi->blocktype=BLOCKTYPE_LONG;
  97866. }
  97867. }else{
  97868. if(_ve_envelope_mark(v)){
  97869. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97870. }else{
  97871. vbi->blocktype=BLOCKTYPE_PADDING;
  97872. }
  97873. }
  97874. vb->vd=v;
  97875. vb->sequence=v->sequence++;
  97876. vb->granulepos=v->granulepos;
  97877. vb->pcmend=ci->blocksizes[v->W];
  97878. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97879. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97880. vbi->ampmax=g->ampmax;
  97881. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97882. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97883. for(i=0;i<vi->channels;i++){
  97884. vbi->pcmdelay[i]=
  97885. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97886. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97887. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97888. }
  97889. if(v->eofflag){
  97890. if(v->centerW>=v->eofflag){
  97891. v->eofflag=-1;
  97892. vb->eofflag=1;
  97893. return(1);
  97894. }
  97895. }
  97896. {
  97897. int new_centerNext=ci->blocksizes[1]/2;
  97898. int movementW=centerNext-new_centerNext;
  97899. if(movementW>0){
  97900. _ve_envelope_shift(b->ve,movementW);
  97901. v->pcm_current-=movementW;
  97902. for(i=0;i<vi->channels;i++)
  97903. memmove(v->pcm[i],v->pcm[i]+movementW,
  97904. v->pcm_current*sizeof(*v->pcm[i]));
  97905. v->lW=v->W;
  97906. v->W=v->nW;
  97907. v->centerW=new_centerNext;
  97908. if(v->eofflag){
  97909. v->eofflag-=movementW;
  97910. if(v->eofflag<=0)v->eofflag=-1;
  97911. if(v->centerW>=v->eofflag){
  97912. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97913. }else{
  97914. v->granulepos+=movementW;
  97915. }
  97916. }else{
  97917. v->granulepos+=movementW;
  97918. }
  97919. }
  97920. }
  97921. return(1);
  97922. }
  97923. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  97924. vorbis_info *vi=v->vi;
  97925. codec_setup_info *ci;
  97926. int hs;
  97927. if(!v->backend_state)return -1;
  97928. if(!vi)return -1;
  97929. ci=(codec_setup_info*) vi->codec_setup;
  97930. if(!ci)return -1;
  97931. hs=ci->halfrate_flag;
  97932. v->centerW=ci->blocksizes[1]>>(hs+1);
  97933. v->pcm_current=v->centerW>>hs;
  97934. v->pcm_returned=-1;
  97935. v->granulepos=-1;
  97936. v->sequence=-1;
  97937. v->eofflag=0;
  97938. ((private_state *)(v->backend_state))->sample_count=-1;
  97939. return(0);
  97940. }
  97941. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97942. if(_vds_shared_init(v,vi,0)) return 1;
  97943. vorbis_synthesis_restart(v);
  97944. return 0;
  97945. }
  97946. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  97947. vorbis_info *vi=v->vi;
  97948. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97949. private_state *b=(private_state*)v->backend_state;
  97950. int hs=ci->halfrate_flag;
  97951. int i,j;
  97952. if(!vb)return(OV_EINVAL);
  97953. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  97954. v->lW=v->W;
  97955. v->W=vb->W;
  97956. v->nW=-1;
  97957. if((v->sequence==-1)||
  97958. (v->sequence+1 != vb->sequence)){
  97959. v->granulepos=-1; /* out of sequence; lose count */
  97960. b->sample_count=-1;
  97961. }
  97962. v->sequence=vb->sequence;
  97963. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  97964. was called on block */
  97965. int n=ci->blocksizes[v->W]>>(hs+1);
  97966. int n0=ci->blocksizes[0]>>(hs+1);
  97967. int n1=ci->blocksizes[1]>>(hs+1);
  97968. int thisCenter;
  97969. int prevCenter;
  97970. v->glue_bits+=vb->glue_bits;
  97971. v->time_bits+=vb->time_bits;
  97972. v->floor_bits+=vb->floor_bits;
  97973. v->res_bits+=vb->res_bits;
  97974. if(v->centerW){
  97975. thisCenter=n1;
  97976. prevCenter=0;
  97977. }else{
  97978. thisCenter=0;
  97979. prevCenter=n1;
  97980. }
  97981. for(j=0;j<vi->channels;j++){
  97982. if(v->lW){
  97983. if(v->W){
  97984. float *w=_vorbis_window_get(b->window[1]-hs);
  97985. float *pcm=v->pcm[j]+prevCenter;
  97986. float *p=vb->pcm[j];
  97987. for(i=0;i<n1;i++)
  97988. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  97989. }else{
  97990. float *w=_vorbis_window_get(b->window[0]-hs);
  97991. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  97992. float *p=vb->pcm[j];
  97993. for(i=0;i<n0;i++)
  97994. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97995. }
  97996. }else{
  97997. if(v->W){
  97998. float *w=_vorbis_window_get(b->window[0]-hs);
  97999. float *pcm=v->pcm[j]+prevCenter;
  98000. float *p=vb->pcm[j]+n1/2-n0/2;
  98001. for(i=0;i<n0;i++)
  98002. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98003. for(;i<n1/2+n0/2;i++)
  98004. pcm[i]=p[i];
  98005. }else{
  98006. float *w=_vorbis_window_get(b->window[0]-hs);
  98007. float *pcm=v->pcm[j]+prevCenter;
  98008. float *p=vb->pcm[j];
  98009. for(i=0;i<n0;i++)
  98010. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98011. }
  98012. }
  98013. {
  98014. float *pcm=v->pcm[j]+thisCenter;
  98015. float *p=vb->pcm[j]+n;
  98016. for(i=0;i<n;i++)
  98017. pcm[i]=p[i];
  98018. }
  98019. }
  98020. if(v->centerW)
  98021. v->centerW=0;
  98022. else
  98023. v->centerW=n1;
  98024. if(v->pcm_returned==-1){
  98025. v->pcm_returned=thisCenter;
  98026. v->pcm_current=thisCenter;
  98027. }else{
  98028. v->pcm_returned=prevCenter;
  98029. v->pcm_current=prevCenter+
  98030. ((ci->blocksizes[v->lW]/4+
  98031. ci->blocksizes[v->W]/4)>>hs);
  98032. }
  98033. }
  98034. if(b->sample_count==-1){
  98035. b->sample_count=0;
  98036. }else{
  98037. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98038. }
  98039. if(v->granulepos==-1){
  98040. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98041. v->granulepos=vb->granulepos;
  98042. if(b->sample_count>v->granulepos){
  98043. if(vb->eofflag){
  98044. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98045. }else{
  98046. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98047. if(v->pcm_returned>v->pcm_current)
  98048. v->pcm_returned=v->pcm_current;
  98049. }
  98050. }
  98051. }
  98052. }else{
  98053. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98054. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98055. if(v->granulepos>vb->granulepos){
  98056. long extra=v->granulepos-vb->granulepos;
  98057. if(extra)
  98058. if(vb->eofflag){
  98059. v->pcm_current-=extra>>hs;
  98060. } /* else {Shouldn't happen *unless* the bitstream is out of
  98061. spec. Either way, believe the bitstream } */
  98062. } /* else {Shouldn't happen *unless* the bitstream is out of
  98063. spec. Either way, believe the bitstream } */
  98064. v->granulepos=vb->granulepos;
  98065. }
  98066. }
  98067. if(vb->eofflag)v->eofflag=1;
  98068. return(0);
  98069. }
  98070. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98071. vorbis_info *vi=v->vi;
  98072. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98073. if(pcm){
  98074. int i;
  98075. for(i=0;i<vi->channels;i++)
  98076. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98077. *pcm=v->pcmret;
  98078. }
  98079. return(v->pcm_current-v->pcm_returned);
  98080. }
  98081. return(0);
  98082. }
  98083. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98084. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98085. v->pcm_returned+=n;
  98086. return(0);
  98087. }
  98088. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98089. vorbis_info *vi=v->vi;
  98090. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98091. int hs=ci->halfrate_flag;
  98092. int n=ci->blocksizes[v->W]>>(hs+1);
  98093. int n0=ci->blocksizes[0]>>(hs+1);
  98094. int n1=ci->blocksizes[1]>>(hs+1);
  98095. int i,j;
  98096. if(v->pcm_returned<0)return 0;
  98097. if(v->centerW==n1){
  98098. for(j=0;j<vi->channels;j++){
  98099. float *p=v->pcm[j];
  98100. for(i=0;i<n1;i++){
  98101. float temp=p[i];
  98102. p[i]=p[i+n1];
  98103. p[i+n1]=temp;
  98104. }
  98105. }
  98106. v->pcm_current-=n1;
  98107. v->pcm_returned-=n1;
  98108. v->centerW=0;
  98109. }
  98110. if((v->lW^v->W)==1){
  98111. for(j=0;j<vi->channels;j++){
  98112. float *s=v->pcm[j];
  98113. float *d=v->pcm[j]+(n1-n0)/2;
  98114. for(i=(n1+n0)/2-1;i>=0;--i)
  98115. d[i]=s[i];
  98116. }
  98117. v->pcm_returned+=(n1-n0)/2;
  98118. v->pcm_current+=(n1-n0)/2;
  98119. }else{
  98120. if(v->lW==0){
  98121. for(j=0;j<vi->channels;j++){
  98122. float *s=v->pcm[j];
  98123. float *d=v->pcm[j]+n1-n0;
  98124. for(i=n0-1;i>=0;--i)
  98125. d[i]=s[i];
  98126. }
  98127. v->pcm_returned+=n1-n0;
  98128. v->pcm_current+=n1-n0;
  98129. }
  98130. }
  98131. if(pcm){
  98132. int i;
  98133. for(i=0;i<vi->channels;i++)
  98134. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98135. *pcm=v->pcmret;
  98136. }
  98137. return(n1+n-v->pcm_returned);
  98138. }
  98139. float *vorbis_window(vorbis_dsp_state *v,int W){
  98140. vorbis_info *vi=v->vi;
  98141. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98142. int hs=ci->halfrate_flag;
  98143. private_state *b=(private_state*)v->backend_state;
  98144. if(b->window[W]-1<0)return NULL;
  98145. return _vorbis_window_get(b->window[W]-hs);
  98146. }
  98147. #endif
  98148. /*** End of inlined file: block.c ***/
  98149. /*** Start of inlined file: codebook.c ***/
  98150. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98151. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98152. // tasks..
  98153. #if JUCE_MSVC
  98154. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98155. #endif
  98156. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98157. #if JUCE_USE_OGGVORBIS
  98158. #include <stdlib.h>
  98159. #include <string.h>
  98160. #include <math.h>
  98161. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98162. long i,j;
  98163. int ordered=0;
  98164. oggpack_write(opb,0x564342,24);
  98165. oggpack_write(opb,c->dim,16);
  98166. oggpack_write(opb,c->entries,24);
  98167. for(i=1;i<c->entries;i++)
  98168. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98169. if(i==c->entries)ordered=1;
  98170. if(ordered){
  98171. long count=0;
  98172. oggpack_write(opb,1,1); /* ordered */
  98173. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98174. for(i=1;i<c->entries;i++){
  98175. long thisx=c->lengthlist[i];
  98176. long last=c->lengthlist[i-1];
  98177. if(thisx>last){
  98178. for(j=last;j<thisx;j++){
  98179. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98180. count=i;
  98181. }
  98182. }
  98183. }
  98184. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98185. }else{
  98186. oggpack_write(opb,0,1); /* unordered */
  98187. for(i=0;i<c->entries;i++)
  98188. if(c->lengthlist[i]==0)break;
  98189. if(i==c->entries){
  98190. oggpack_write(opb,0,1); /* no unused entries */
  98191. for(i=0;i<c->entries;i++)
  98192. oggpack_write(opb,c->lengthlist[i]-1,5);
  98193. }else{
  98194. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98195. for(i=0;i<c->entries;i++){
  98196. if(c->lengthlist[i]==0){
  98197. oggpack_write(opb,0,1);
  98198. }else{
  98199. oggpack_write(opb,1,1);
  98200. oggpack_write(opb,c->lengthlist[i]-1,5);
  98201. }
  98202. }
  98203. }
  98204. }
  98205. oggpack_write(opb,c->maptype,4);
  98206. switch(c->maptype){
  98207. case 0:
  98208. break;
  98209. case 1:case 2:
  98210. if(!c->quantlist){
  98211. return(-1);
  98212. }
  98213. oggpack_write(opb,c->q_min,32);
  98214. oggpack_write(opb,c->q_delta,32);
  98215. oggpack_write(opb,c->q_quant-1,4);
  98216. oggpack_write(opb,c->q_sequencep,1);
  98217. {
  98218. int quantvals;
  98219. switch(c->maptype){
  98220. case 1:
  98221. quantvals=_book_maptype1_quantvals(c);
  98222. break;
  98223. case 2:
  98224. quantvals=c->entries*c->dim;
  98225. break;
  98226. default: /* NOT_REACHABLE */
  98227. quantvals=-1;
  98228. }
  98229. for(i=0;i<quantvals;i++)
  98230. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98231. }
  98232. break;
  98233. default:
  98234. return(-1);
  98235. }
  98236. return(0);
  98237. }
  98238. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98239. long i,j;
  98240. memset(s,0,sizeof(*s));
  98241. s->allocedp=1;
  98242. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98243. s->dim=oggpack_read(opb,16);
  98244. s->entries=oggpack_read(opb,24);
  98245. if(s->entries==-1)goto _eofout;
  98246. switch((int)oggpack_read(opb,1)){
  98247. case 0:
  98248. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98249. if(oggpack_read(opb,1)){
  98250. for(i=0;i<s->entries;i++){
  98251. if(oggpack_read(opb,1)){
  98252. long num=oggpack_read(opb,5);
  98253. if(num==-1)goto _eofout;
  98254. s->lengthlist[i]=num+1;
  98255. }else
  98256. s->lengthlist[i]=0;
  98257. }
  98258. }else{
  98259. for(i=0;i<s->entries;i++){
  98260. long num=oggpack_read(opb,5);
  98261. if(num==-1)goto _eofout;
  98262. s->lengthlist[i]=num+1;
  98263. }
  98264. }
  98265. break;
  98266. case 1:
  98267. {
  98268. long length=oggpack_read(opb,5)+1;
  98269. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98270. for(i=0;i<s->entries;){
  98271. long num=oggpack_read(opb,_ilog(s->entries-i));
  98272. if(num==-1)goto _eofout;
  98273. for(j=0;j<num && i<s->entries;j++,i++)
  98274. s->lengthlist[i]=length;
  98275. length++;
  98276. }
  98277. }
  98278. break;
  98279. default:
  98280. return(-1);
  98281. }
  98282. switch((s->maptype=oggpack_read(opb,4))){
  98283. case 0:
  98284. break;
  98285. case 1: case 2:
  98286. s->q_min=oggpack_read(opb,32);
  98287. s->q_delta=oggpack_read(opb,32);
  98288. s->q_quant=oggpack_read(opb,4)+1;
  98289. s->q_sequencep=oggpack_read(opb,1);
  98290. {
  98291. int quantvals=0;
  98292. switch(s->maptype){
  98293. case 1:
  98294. quantvals=_book_maptype1_quantvals(s);
  98295. break;
  98296. case 2:
  98297. quantvals=s->entries*s->dim;
  98298. break;
  98299. }
  98300. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98301. for(i=0;i<quantvals;i++)
  98302. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98303. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98304. }
  98305. break;
  98306. default:
  98307. goto _errout;
  98308. }
  98309. return(0);
  98310. _errout:
  98311. _eofout:
  98312. vorbis_staticbook_clear(s);
  98313. return(-1);
  98314. }
  98315. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98316. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98317. return(book->c->lengthlist[a]);
  98318. }
  98319. int vorbis_book_errorv(codebook *book,float *a){
  98320. int dim=book->dim,k;
  98321. int best=_best(book,a,1);
  98322. for(k=0;k<dim;k++)
  98323. a[k]=(book->valuelist+best*dim)[k];
  98324. return(best);
  98325. }
  98326. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98327. int k,dim=book->dim;
  98328. for(k=0;k<dim;k++)
  98329. a[k]=(book->valuelist+best*dim)[k];
  98330. return(vorbis_book_encode(book,best,b));
  98331. }
  98332. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98333. int read=book->dec_maxlength;
  98334. long lo,hi;
  98335. long lok = oggpack_look(b,book->dec_firsttablen);
  98336. if (lok >= 0) {
  98337. long entry = book->dec_firsttable[lok];
  98338. if(entry&0x80000000UL){
  98339. lo=(entry>>15)&0x7fff;
  98340. hi=book->used_entries-(entry&0x7fff);
  98341. }else{
  98342. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98343. return(entry-1);
  98344. }
  98345. }else{
  98346. lo=0;
  98347. hi=book->used_entries;
  98348. }
  98349. lok = oggpack_look(b, read);
  98350. while(lok<0 && read>1)
  98351. lok = oggpack_look(b, --read);
  98352. if(lok<0)return -1;
  98353. {
  98354. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98355. while(hi-lo>1){
  98356. long p=(hi-lo)>>1;
  98357. long test=book->codelist[lo+p]>testword;
  98358. lo+=p&(test-1);
  98359. hi-=p&(-test);
  98360. }
  98361. if(book->dec_codelengths[lo]<=read){
  98362. oggpack_adv(b, book->dec_codelengths[lo]);
  98363. return(lo);
  98364. }
  98365. }
  98366. oggpack_adv(b, read);
  98367. return(-1);
  98368. }
  98369. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98370. long packed_entry=decode_packed_entry_number(book,b);
  98371. if(packed_entry>=0)
  98372. return(book->dec_index[packed_entry]);
  98373. return(packed_entry);
  98374. }
  98375. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98376. int step=n/book->dim;
  98377. long *entry = (long*)alloca(sizeof(*entry)*step);
  98378. float **t = (float**)alloca(sizeof(*t)*step);
  98379. int i,j,o;
  98380. for (i = 0; i < step; i++) {
  98381. entry[i]=decode_packed_entry_number(book,b);
  98382. if(entry[i]==-1)return(-1);
  98383. t[i] = book->valuelist+entry[i]*book->dim;
  98384. }
  98385. for(i=0,o=0;i<book->dim;i++,o+=step)
  98386. for (j=0;j<step;j++)
  98387. a[o+j]+=t[j][i];
  98388. return(0);
  98389. }
  98390. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98391. int i,j,entry;
  98392. float *t;
  98393. if(book->dim>8){
  98394. for(i=0;i<n;){
  98395. entry = decode_packed_entry_number(book,b);
  98396. if(entry==-1)return(-1);
  98397. t = book->valuelist+entry*book->dim;
  98398. for (j=0;j<book->dim;)
  98399. a[i++]+=t[j++];
  98400. }
  98401. }else{
  98402. for(i=0;i<n;){
  98403. entry = decode_packed_entry_number(book,b);
  98404. if(entry==-1)return(-1);
  98405. t = book->valuelist+entry*book->dim;
  98406. j=0;
  98407. switch((int)book->dim){
  98408. case 8:
  98409. a[i++]+=t[j++];
  98410. case 7:
  98411. a[i++]+=t[j++];
  98412. case 6:
  98413. a[i++]+=t[j++];
  98414. case 5:
  98415. a[i++]+=t[j++];
  98416. case 4:
  98417. a[i++]+=t[j++];
  98418. case 3:
  98419. a[i++]+=t[j++];
  98420. case 2:
  98421. a[i++]+=t[j++];
  98422. case 1:
  98423. a[i++]+=t[j++];
  98424. case 0:
  98425. break;
  98426. }
  98427. }
  98428. }
  98429. return(0);
  98430. }
  98431. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98432. int i,j,entry;
  98433. float *t;
  98434. for(i=0;i<n;){
  98435. entry = decode_packed_entry_number(book,b);
  98436. if(entry==-1)return(-1);
  98437. t = book->valuelist+entry*book->dim;
  98438. for (j=0;j<book->dim;)
  98439. a[i++]=t[j++];
  98440. }
  98441. return(0);
  98442. }
  98443. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98444. oggpack_buffer *b,int n){
  98445. long i,j,entry;
  98446. int chptr=0;
  98447. for(i=offset/ch;i<(offset+n)/ch;){
  98448. entry = decode_packed_entry_number(book,b);
  98449. if(entry==-1)return(-1);
  98450. {
  98451. const float *t = book->valuelist+entry*book->dim;
  98452. for (j=0;j<book->dim;j++){
  98453. a[chptr++][i]+=t[j];
  98454. if(chptr==ch){
  98455. chptr=0;
  98456. i++;
  98457. }
  98458. }
  98459. }
  98460. }
  98461. return(0);
  98462. }
  98463. #ifdef _V_SELFTEST
  98464. #include <stdio.h>
  98465. #include "vorbis/book/lsp20_0.vqh"
  98466. #include "vorbis/book/res0a_13.vqh"
  98467. #define TESTSIZE 40
  98468. float test1[TESTSIZE]={
  98469. 0.105939f,
  98470. 0.215373f,
  98471. 0.429117f,
  98472. 0.587974f,
  98473. 0.181173f,
  98474. 0.296583f,
  98475. 0.515707f,
  98476. 0.715261f,
  98477. 0.162327f,
  98478. 0.263834f,
  98479. 0.342876f,
  98480. 0.406025f,
  98481. 0.103571f,
  98482. 0.223561f,
  98483. 0.368513f,
  98484. 0.540313f,
  98485. 0.136672f,
  98486. 0.395882f,
  98487. 0.587183f,
  98488. 0.652476f,
  98489. 0.114338f,
  98490. 0.417300f,
  98491. 0.525486f,
  98492. 0.698679f,
  98493. 0.147492f,
  98494. 0.324481f,
  98495. 0.643089f,
  98496. 0.757582f,
  98497. 0.139556f,
  98498. 0.215795f,
  98499. 0.324559f,
  98500. 0.399387f,
  98501. 0.120236f,
  98502. 0.267420f,
  98503. 0.446940f,
  98504. 0.608760f,
  98505. 0.115587f,
  98506. 0.287234f,
  98507. 0.571081f,
  98508. 0.708603f,
  98509. };
  98510. float test3[TESTSIZE]={
  98511. 0,1,-2,3,4,-5,6,7,8,9,
  98512. 8,-2,7,-1,4,6,8,3,1,-9,
  98513. 10,11,12,13,14,15,26,17,18,19,
  98514. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98515. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98516. &_vq_book_res0a_13,NULL};
  98517. float *testvec[]={test1,test3};
  98518. int main(){
  98519. oggpack_buffer write;
  98520. oggpack_buffer read;
  98521. long ptr=0,i;
  98522. oggpack_writeinit(&write);
  98523. fprintf(stderr,"Testing codebook abstraction...:\n");
  98524. while(testlist[ptr]){
  98525. codebook c;
  98526. static_codebook s;
  98527. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98528. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98529. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98530. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98531. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98532. oggpack_reset(&write);
  98533. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98534. we can write */
  98535. vorbis_staticbook_pack(testlist[ptr],&write);
  98536. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98537. for(i=0;i<TESTSIZE;i+=c.dim){
  98538. int best=_best(&c,qv+i,1);
  98539. vorbis_book_encodev(&c,best,qv+i,&write);
  98540. }
  98541. vorbis_book_clear(&c);
  98542. fprintf(stderr,"OK.\n");
  98543. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98544. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98545. if(vorbis_staticbook_unpack(&read,&s)){
  98546. fprintf(stderr,"Error unpacking codebook.\n");
  98547. exit(1);
  98548. }
  98549. if(vorbis_book_init_decode(&c,&s)){
  98550. fprintf(stderr,"Error initializing codebook.\n");
  98551. exit(1);
  98552. }
  98553. for(i=0;i<TESTSIZE;i+=c.dim)
  98554. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98555. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98556. exit(1);
  98557. }
  98558. for(i=0;i<TESTSIZE;i++)
  98559. if(fabs(qv[i]-iv[i])>.000001){
  98560. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98561. iv[i],qv[i],i);
  98562. exit(1);
  98563. }
  98564. fprintf(stderr,"OK\n");
  98565. ptr++;
  98566. }
  98567. exit(0);
  98568. }
  98569. #endif
  98570. #endif
  98571. /*** End of inlined file: codebook.c ***/
  98572. /*** Start of inlined file: envelope.c ***/
  98573. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98574. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98575. // tasks..
  98576. #if JUCE_MSVC
  98577. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98578. #endif
  98579. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98580. #if JUCE_USE_OGGVORBIS
  98581. #include <stdlib.h>
  98582. #include <string.h>
  98583. #include <stdio.h>
  98584. #include <math.h>
  98585. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98586. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98587. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98588. int ch=vi->channels;
  98589. int i,j;
  98590. int n=e->winlength=128;
  98591. e->searchstep=64; /* not random */
  98592. e->minenergy=gi->preecho_minenergy;
  98593. e->ch=ch;
  98594. e->storage=128;
  98595. e->cursor=ci->blocksizes[1]/2;
  98596. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98597. mdct_init(&e->mdct,n);
  98598. for(i=0;i<n;i++){
  98599. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98600. e->mdct_win[i]*=e->mdct_win[i];
  98601. }
  98602. e->band[0].begin=2; e->band[0].end=4;
  98603. e->band[1].begin=4; e->band[1].end=5;
  98604. e->band[2].begin=6; e->band[2].end=6;
  98605. e->band[3].begin=9; e->band[3].end=8;
  98606. e->band[4].begin=13; e->band[4].end=8;
  98607. e->band[5].begin=17; e->band[5].end=8;
  98608. e->band[6].begin=22; e->band[6].end=8;
  98609. for(j=0;j<VE_BANDS;j++){
  98610. n=e->band[j].end;
  98611. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98612. for(i=0;i<n;i++){
  98613. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98614. e->band[j].total+=e->band[j].window[i];
  98615. }
  98616. e->band[j].total=1./e->band[j].total;
  98617. }
  98618. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98619. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98620. }
  98621. void _ve_envelope_clear(envelope_lookup *e){
  98622. int i;
  98623. mdct_clear(&e->mdct);
  98624. for(i=0;i<VE_BANDS;i++)
  98625. _ogg_free(e->band[i].window);
  98626. _ogg_free(e->mdct_win);
  98627. _ogg_free(e->filter);
  98628. _ogg_free(e->mark);
  98629. memset(e,0,sizeof(*e));
  98630. }
  98631. static int _ve_amp(envelope_lookup *ve,
  98632. vorbis_info_psy_global *gi,
  98633. float *data,
  98634. envelope_band *bands,
  98635. envelope_filter_state *filters,
  98636. long pos){
  98637. long n=ve->winlength;
  98638. int ret=0;
  98639. long i,j;
  98640. float decay;
  98641. float minV=ve->minenergy;
  98642. float *vec=(float*) alloca(n*sizeof(*vec));
  98643. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98644. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98645. if(penalty<0.f)penalty=0.f;
  98646. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98647. for(i=0;i<n;i++)
  98648. vec[i]=data[i]*ve->mdct_win[i];
  98649. mdct_forward(&ve->mdct,vec,vec);
  98650. {
  98651. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98652. int ptr=filters->nearptr;
  98653. if(ptr==0){
  98654. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98655. filters->nearDC_partialacc=temp;
  98656. }else{
  98657. decay=filters->nearDC_acc+=temp;
  98658. filters->nearDC_partialacc+=temp;
  98659. }
  98660. filters->nearDC_acc-=filters->nearDC[ptr];
  98661. filters->nearDC[ptr]=temp;
  98662. decay*=(1./(VE_NEARDC+1));
  98663. filters->nearptr++;
  98664. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98665. decay=todB(&decay)*.5-15.f;
  98666. }
  98667. for(i=0;i<n/2;i+=2){
  98668. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98669. val=todB(&val)*.5f;
  98670. if(val<decay)val=decay;
  98671. if(val<minV)val=minV;
  98672. vec[i>>1]=val;
  98673. decay-=8.;
  98674. }
  98675. for(j=0;j<VE_BANDS;j++){
  98676. float acc=0.;
  98677. float valmax,valmin;
  98678. for(i=0;i<bands[j].end;i++)
  98679. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98680. acc*=bands[j].total;
  98681. {
  98682. int p,thisx=filters[j].ampptr;
  98683. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98684. p=thisx;
  98685. p--;
  98686. if(p<0)p+=VE_AMP;
  98687. postmax=max(acc,filters[j].ampbuf[p]);
  98688. postmin=min(acc,filters[j].ampbuf[p]);
  98689. for(i=0;i<stretch;i++){
  98690. p--;
  98691. if(p<0)p+=VE_AMP;
  98692. premax=max(premax,filters[j].ampbuf[p]);
  98693. premin=min(premin,filters[j].ampbuf[p]);
  98694. }
  98695. valmin=postmin-premin;
  98696. valmax=postmax-premax;
  98697. filters[j].ampbuf[thisx]=acc;
  98698. filters[j].ampptr++;
  98699. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98700. }
  98701. if(valmax>gi->preecho_thresh[j]+penalty){
  98702. ret|=1;
  98703. ret|=4;
  98704. }
  98705. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98706. }
  98707. return(ret);
  98708. }
  98709. #if 0
  98710. static int seq=0;
  98711. static ogg_int64_t totalshift=-1024;
  98712. #endif
  98713. long _ve_envelope_search(vorbis_dsp_state *v){
  98714. vorbis_info *vi=v->vi;
  98715. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98716. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98717. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98718. long i,j;
  98719. int first=ve->current/ve->searchstep;
  98720. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98721. if(first<0)first=0;
  98722. if(last+VE_WIN+VE_POST>ve->storage){
  98723. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98724. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98725. }
  98726. for(j=first;j<last;j++){
  98727. int ret=0;
  98728. ve->stretch++;
  98729. if(ve->stretch>VE_MAXSTRETCH*2)
  98730. ve->stretch=VE_MAXSTRETCH*2;
  98731. for(i=0;i<ve->ch;i++){
  98732. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98733. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98734. }
  98735. ve->mark[j+VE_POST]=0;
  98736. if(ret&1){
  98737. ve->mark[j]=1;
  98738. ve->mark[j+1]=1;
  98739. }
  98740. if(ret&2){
  98741. ve->mark[j]=1;
  98742. if(j>0)ve->mark[j-1]=1;
  98743. }
  98744. if(ret&4)ve->stretch=-1;
  98745. }
  98746. ve->current=last*ve->searchstep;
  98747. {
  98748. long centerW=v->centerW;
  98749. long testW=
  98750. centerW+
  98751. ci->blocksizes[v->W]/4+
  98752. ci->blocksizes[1]/2+
  98753. ci->blocksizes[0]/4;
  98754. j=ve->cursor;
  98755. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98756. working back one window */
  98757. if(j>=testW)return(1);
  98758. ve->cursor=j;
  98759. if(ve->mark[j/ve->searchstep]){
  98760. if(j>centerW){
  98761. #if 0
  98762. if(j>ve->curmark){
  98763. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98764. int l,m;
  98765. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98766. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98767. seq,
  98768. (totalshift+ve->cursor)/44100.,
  98769. (totalshift+j)/44100.);
  98770. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98771. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98772. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98773. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98774. for(m=0;m<VE_BANDS;m++){
  98775. char buf[80];
  98776. sprintf(buf,"delL%d",m);
  98777. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98778. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98779. }
  98780. for(m=0;m<VE_BANDS;m++){
  98781. char buf[80];
  98782. sprintf(buf,"delR%d",m);
  98783. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98784. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98785. }
  98786. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98787. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98788. seq++;
  98789. }
  98790. #endif
  98791. ve->curmark=j;
  98792. if(j>=testW)return(1);
  98793. return(0);
  98794. }
  98795. }
  98796. j+=ve->searchstep;
  98797. }
  98798. }
  98799. return(-1);
  98800. }
  98801. int _ve_envelope_mark(vorbis_dsp_state *v){
  98802. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98803. vorbis_info *vi=v->vi;
  98804. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98805. long centerW=v->centerW;
  98806. long beginW=centerW-ci->blocksizes[v->W]/4;
  98807. long endW=centerW+ci->blocksizes[v->W]/4;
  98808. if(v->W){
  98809. beginW-=ci->blocksizes[v->lW]/4;
  98810. endW+=ci->blocksizes[v->nW]/4;
  98811. }else{
  98812. beginW-=ci->blocksizes[0]/4;
  98813. endW+=ci->blocksizes[0]/4;
  98814. }
  98815. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98816. {
  98817. long first=beginW/ve->searchstep;
  98818. long last=endW/ve->searchstep;
  98819. long i;
  98820. for(i=first;i<last;i++)
  98821. if(ve->mark[i])return(1);
  98822. }
  98823. return(0);
  98824. }
  98825. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98826. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98827. ahead of ve->current */
  98828. int smallshift=shift/e->searchstep;
  98829. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98830. #if 0
  98831. for(i=0;i<VE_BANDS*e->ch;i++)
  98832. memmove(e->filter[i].markers,
  98833. e->filter[i].markers+smallshift,
  98834. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98835. totalshift+=shift;
  98836. #endif
  98837. e->current-=shift;
  98838. if(e->curmark>=0)
  98839. e->curmark-=shift;
  98840. e->cursor-=shift;
  98841. }
  98842. #endif
  98843. /*** End of inlined file: envelope.c ***/
  98844. /*** Start of inlined file: floor0.c ***/
  98845. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98846. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98847. // tasks..
  98848. #if JUCE_MSVC
  98849. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98850. #endif
  98851. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98852. #if JUCE_USE_OGGVORBIS
  98853. #include <stdlib.h>
  98854. #include <string.h>
  98855. #include <math.h>
  98856. /*** Start of inlined file: lsp.h ***/
  98857. #ifndef _V_LSP_H_
  98858. #define _V_LSP_H_
  98859. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98860. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98861. float *lsp,int m,
  98862. float amp,float ampoffset);
  98863. #endif
  98864. /*** End of inlined file: lsp.h ***/
  98865. #include <stdio.h>
  98866. typedef struct {
  98867. int ln;
  98868. int m;
  98869. int **linearmap;
  98870. int n[2];
  98871. vorbis_info_floor0 *vi;
  98872. long bits;
  98873. long frames;
  98874. } vorbis_look_floor0;
  98875. static void floor0_free_info(vorbis_info_floor *i){
  98876. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98877. if(info){
  98878. memset(info,0,sizeof(*info));
  98879. _ogg_free(info);
  98880. }
  98881. }
  98882. static void floor0_free_look(vorbis_look_floor *i){
  98883. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98884. if(look){
  98885. if(look->linearmap){
  98886. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98887. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98888. _ogg_free(look->linearmap);
  98889. }
  98890. memset(look,0,sizeof(*look));
  98891. _ogg_free(look);
  98892. }
  98893. }
  98894. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98895. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98896. int j;
  98897. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98898. info->order=oggpack_read(opb,8);
  98899. info->rate=oggpack_read(opb,16);
  98900. info->barkmap=oggpack_read(opb,16);
  98901. info->ampbits=oggpack_read(opb,6);
  98902. info->ampdB=oggpack_read(opb,8);
  98903. info->numbooks=oggpack_read(opb,4)+1;
  98904. if(info->order<1)goto err_out;
  98905. if(info->rate<1)goto err_out;
  98906. if(info->barkmap<1)goto err_out;
  98907. if(info->numbooks<1)goto err_out;
  98908. for(j=0;j<info->numbooks;j++){
  98909. info->books[j]=oggpack_read(opb,8);
  98910. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98911. }
  98912. return(info);
  98913. err_out:
  98914. floor0_free_info(info);
  98915. return(NULL);
  98916. }
  98917. static void floor0_map_lazy_init(vorbis_block *vb,
  98918. vorbis_info_floor *infoX,
  98919. vorbis_look_floor0 *look){
  98920. if(!look->linearmap[vb->W]){
  98921. vorbis_dsp_state *vd=vb->vd;
  98922. vorbis_info *vi=vd->vi;
  98923. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98924. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  98925. int W=vb->W;
  98926. int n=ci->blocksizes[W]/2,j;
  98927. float scale=look->ln/toBARK(info->rate/2.f);
  98928. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  98929. for(j=0;j<n;j++){
  98930. int val=floor( toBARK((info->rate/2.f)/n*j)
  98931. *scale); /* bark numbers represent band edges */
  98932. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  98933. look->linearmap[W][j]=val;
  98934. }
  98935. look->linearmap[W][j]=-1;
  98936. look->n[W]=n;
  98937. }
  98938. }
  98939. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  98940. vorbis_info_floor *i){
  98941. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  98942. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  98943. look->m=info->order;
  98944. look->ln=info->barkmap;
  98945. look->vi=info;
  98946. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  98947. return look;
  98948. }
  98949. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  98950. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98951. vorbis_info_floor0 *info=look->vi;
  98952. int j,k;
  98953. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  98954. if(ampraw>0){ /* also handles the -1 out of data case */
  98955. long maxval=(1<<info->ampbits)-1;
  98956. float amp=(float)ampraw/maxval*info->ampdB;
  98957. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  98958. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  98959. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  98960. codebook *b=ci->fullbooks+info->books[booknum];
  98961. float last=0.f;
  98962. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  98963. for(j=0;j<look->m;j+=b->dim)
  98964. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  98965. for(j=0;j<look->m;){
  98966. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  98967. last=lsp[j-1];
  98968. }
  98969. lsp[look->m]=amp;
  98970. return(lsp);
  98971. }
  98972. }
  98973. eop:
  98974. return(NULL);
  98975. }
  98976. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  98977. void *memo,float *out){
  98978. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98979. vorbis_info_floor0 *info=look->vi;
  98980. floor0_map_lazy_init(vb,info,look);
  98981. if(memo){
  98982. float *lsp=(float *)memo;
  98983. float amp=lsp[look->m];
  98984. vorbis_lsp_to_curve(out,
  98985. look->linearmap[vb->W],
  98986. look->n[vb->W],
  98987. look->ln,
  98988. lsp,look->m,amp,(float)info->ampdB);
  98989. return(1);
  98990. }
  98991. memset(out,0,sizeof(*out)*look->n[vb->W]);
  98992. return(0);
  98993. }
  98994. vorbis_func_floor floor0_exportbundle={
  98995. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  98996. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  98997. };
  98998. #endif
  98999. /*** End of inlined file: floor0.c ***/
  99000. /*** Start of inlined file: floor1.c ***/
  99001. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99002. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99003. // tasks..
  99004. #if JUCE_MSVC
  99005. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99006. #endif
  99007. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99008. #if JUCE_USE_OGGVORBIS
  99009. #include <stdlib.h>
  99010. #include <string.h>
  99011. #include <math.h>
  99012. #include <stdio.h>
  99013. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99014. typedef struct {
  99015. int sorted_index[VIF_POSIT+2];
  99016. int forward_index[VIF_POSIT+2];
  99017. int reverse_index[VIF_POSIT+2];
  99018. int hineighbor[VIF_POSIT];
  99019. int loneighbor[VIF_POSIT];
  99020. int posts;
  99021. int n;
  99022. int quant_q;
  99023. vorbis_info_floor1 *vi;
  99024. long phrasebits;
  99025. long postbits;
  99026. long frames;
  99027. } vorbis_look_floor1;
  99028. typedef struct lsfit_acc{
  99029. long x0;
  99030. long x1;
  99031. long xa;
  99032. long ya;
  99033. long x2a;
  99034. long y2a;
  99035. long xya;
  99036. long an;
  99037. } lsfit_acc;
  99038. static void floor1_free_info(vorbis_info_floor *i){
  99039. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99040. if(info){
  99041. memset(info,0,sizeof(*info));
  99042. _ogg_free(info);
  99043. }
  99044. }
  99045. static void floor1_free_look(vorbis_look_floor *i){
  99046. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99047. if(look){
  99048. memset(look,0,sizeof(*look));
  99049. _ogg_free(look);
  99050. }
  99051. }
  99052. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99053. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99054. int j,k;
  99055. int count=0;
  99056. int rangebits;
  99057. int maxposit=info->postlist[1];
  99058. int maxclass=-1;
  99059. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99060. for(j=0;j<info->partitions;j++){
  99061. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99062. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99063. }
  99064. for(j=0;j<maxclass+1;j++){
  99065. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99066. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99067. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99068. for(k=0;k<(1<<info->class_subs[j]);k++)
  99069. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99070. }
  99071. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99072. oggpack_write(opb,ilog2(maxposit),4);
  99073. rangebits=ilog2(maxposit);
  99074. for(j=0,k=0;j<info->partitions;j++){
  99075. count+=info->class_dim[info->partitionclass[j]];
  99076. for(;k<count;k++)
  99077. oggpack_write(opb,info->postlist[k+2],rangebits);
  99078. }
  99079. }
  99080. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99081. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99082. int j,k,count=0,maxclass=-1,rangebits;
  99083. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99084. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99085. for(j=0;j<info->partitions;j++){
  99086. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99087. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99088. }
  99089. for(j=0;j<maxclass+1;j++){
  99090. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99091. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99092. if(info->class_subs[j]<0)
  99093. goto err_out;
  99094. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99095. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99096. goto err_out;
  99097. for(k=0;k<(1<<info->class_subs[j]);k++){
  99098. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99099. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99100. goto err_out;
  99101. }
  99102. }
  99103. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99104. rangebits=oggpack_read(opb,4);
  99105. for(j=0,k=0;j<info->partitions;j++){
  99106. count+=info->class_dim[info->partitionclass[j]];
  99107. for(;k<count;k++){
  99108. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99109. if(t<0 || t>=(1<<rangebits))
  99110. goto err_out;
  99111. }
  99112. }
  99113. info->postlist[0]=0;
  99114. info->postlist[1]=1<<rangebits;
  99115. return(info);
  99116. err_out:
  99117. floor1_free_info(info);
  99118. return(NULL);
  99119. }
  99120. static int icomp(const void *a,const void *b){
  99121. return(**(int **)a-**(int **)b);
  99122. }
  99123. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99124. vorbis_info_floor *in){
  99125. int *sortpointer[VIF_POSIT+2];
  99126. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99127. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99128. int i,j,n=0;
  99129. look->vi=info;
  99130. look->n=info->postlist[1];
  99131. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99132. n+=2;
  99133. look->posts=n;
  99134. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99135. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99136. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99137. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99138. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99139. switch(info->mult){
  99140. case 1: /* 1024 -> 256 */
  99141. look->quant_q=256;
  99142. break;
  99143. case 2: /* 1024 -> 128 */
  99144. look->quant_q=128;
  99145. break;
  99146. case 3: /* 1024 -> 86 */
  99147. look->quant_q=86;
  99148. break;
  99149. case 4: /* 1024 -> 64 */
  99150. look->quant_q=64;
  99151. break;
  99152. }
  99153. for(i=0;i<n-2;i++){
  99154. int lo=0;
  99155. int hi=1;
  99156. int lx=0;
  99157. int hx=look->n;
  99158. int currentx=info->postlist[i+2];
  99159. for(j=0;j<i+2;j++){
  99160. int x=info->postlist[j];
  99161. if(x>lx && x<currentx){
  99162. lo=j;
  99163. lx=x;
  99164. }
  99165. if(x<hx && x>currentx){
  99166. hi=j;
  99167. hx=x;
  99168. }
  99169. }
  99170. look->loneighbor[i]=lo;
  99171. look->hineighbor[i]=hi;
  99172. }
  99173. return(look);
  99174. }
  99175. static int render_point(int x0,int x1,int y0,int y1,int x){
  99176. y0&=0x7fff; /* mask off flag */
  99177. y1&=0x7fff;
  99178. {
  99179. int dy=y1-y0;
  99180. int adx=x1-x0;
  99181. int ady=abs(dy);
  99182. int err=ady*(x-x0);
  99183. int off=err/adx;
  99184. if(dy<0)return(y0-off);
  99185. return(y0+off);
  99186. }
  99187. }
  99188. static int vorbis_dBquant(const float *x){
  99189. int i= *x*7.3142857f+1023.5f;
  99190. if(i>1023)return(1023);
  99191. if(i<0)return(0);
  99192. return i;
  99193. }
  99194. static float FLOOR1_fromdB_LOOKUP[256]={
  99195. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99196. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99197. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99198. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99199. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99200. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99201. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99202. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99203. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99204. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99205. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99206. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99207. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99208. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99209. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99210. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99211. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99212. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99213. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99214. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99215. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99216. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99217. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99218. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99219. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99220. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99221. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99222. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99223. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99224. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99225. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99226. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99227. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99228. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99229. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99230. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99231. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99232. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99233. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99234. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99235. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99236. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99237. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99238. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99239. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99240. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99241. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99242. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99243. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99244. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99245. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99246. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99247. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99248. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99249. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99250. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99251. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99252. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99253. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99254. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99255. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99256. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99257. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99258. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99259. };
  99260. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99261. int dy=y1-y0;
  99262. int adx=x1-x0;
  99263. int ady=abs(dy);
  99264. int base=dy/adx;
  99265. int sy=(dy<0?base-1:base+1);
  99266. int x=x0;
  99267. int y=y0;
  99268. int err=0;
  99269. ady-=abs(base*adx);
  99270. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99271. while(++x<x1){
  99272. err=err+ady;
  99273. if(err>=adx){
  99274. err-=adx;
  99275. y+=sy;
  99276. }else{
  99277. y+=base;
  99278. }
  99279. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99280. }
  99281. }
  99282. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99283. int dy=y1-y0;
  99284. int adx=x1-x0;
  99285. int ady=abs(dy);
  99286. int base=dy/adx;
  99287. int sy=(dy<0?base-1:base+1);
  99288. int x=x0;
  99289. int y=y0;
  99290. int err=0;
  99291. ady-=abs(base*adx);
  99292. d[x]=y;
  99293. while(++x<x1){
  99294. err=err+ady;
  99295. if(err>=adx){
  99296. err-=adx;
  99297. y+=sy;
  99298. }else{
  99299. y+=base;
  99300. }
  99301. d[x]=y;
  99302. }
  99303. }
  99304. static int accumulate_fit(const float *flr,const float *mdct,
  99305. int x0, int x1,lsfit_acc *a,
  99306. int n,vorbis_info_floor1 *info){
  99307. long i;
  99308. 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;
  99309. memset(a,0,sizeof(*a));
  99310. a->x0=x0;
  99311. a->x1=x1;
  99312. if(x1>=n)x1=n-1;
  99313. for(i=x0;i<=x1;i++){
  99314. int quantized=vorbis_dBquant(flr+i);
  99315. if(quantized){
  99316. if(mdct[i]+info->twofitatten>=flr[i]){
  99317. xa += i;
  99318. ya += quantized;
  99319. x2a += i*i;
  99320. y2a += quantized*quantized;
  99321. xya += i*quantized;
  99322. na++;
  99323. }else{
  99324. xb += i;
  99325. yb += quantized;
  99326. x2b += i*i;
  99327. y2b += quantized*quantized;
  99328. xyb += i*quantized;
  99329. nb++;
  99330. }
  99331. }
  99332. }
  99333. xb+=xa;
  99334. yb+=ya;
  99335. x2b+=x2a;
  99336. y2b+=y2a;
  99337. xyb+=xya;
  99338. nb+=na;
  99339. {
  99340. int weight=nb*info->twofitweight/(na+1);
  99341. a->xa=xa*weight+xb;
  99342. a->ya=ya*weight+yb;
  99343. a->x2a=x2a*weight+x2b;
  99344. a->y2a=y2a*weight+y2b;
  99345. a->xya=xya*weight+xyb;
  99346. a->an=na*weight+nb;
  99347. }
  99348. return(na);
  99349. }
  99350. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99351. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99352. long x0=a[0].x0;
  99353. long x1=a[fits-1].x1;
  99354. for(i=0;i<fits;i++){
  99355. x+=a[i].xa;
  99356. y+=a[i].ya;
  99357. x2+=a[i].x2a;
  99358. y2+=a[i].y2a;
  99359. xy+=a[i].xya;
  99360. an+=a[i].an;
  99361. }
  99362. if(*y0>=0){
  99363. x+= x0;
  99364. y+= *y0;
  99365. x2+= x0 * x0;
  99366. y2+= *y0 * *y0;
  99367. xy+= *y0 * x0;
  99368. an++;
  99369. }
  99370. if(*y1>=0){
  99371. x+= x1;
  99372. y+= *y1;
  99373. x2+= x1 * x1;
  99374. y2+= *y1 * *y1;
  99375. xy+= *y1 * x1;
  99376. an++;
  99377. }
  99378. if(an){
  99379. double fx=x;
  99380. double fy=y;
  99381. double fx2=x2;
  99382. double fxy=xy;
  99383. double denom=1./(an*fx2-fx*fx);
  99384. double a=(fy*fx2-fxy*fx)*denom;
  99385. double b=(an*fxy-fx*fy)*denom;
  99386. *y0=rint(a+b*x0);
  99387. *y1=rint(a+b*x1);
  99388. if(*y0>1023)*y0=1023;
  99389. if(*y1>1023)*y1=1023;
  99390. if(*y0<0)*y0=0;
  99391. if(*y1<0)*y1=0;
  99392. }else{
  99393. *y0=0;
  99394. *y1=0;
  99395. }
  99396. }
  99397. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99398. const float *mdct,
  99399. vorbis_info_floor1 *info){
  99400. int dy=y1-y0;
  99401. int adx=x1-x0;
  99402. int ady=abs(dy);
  99403. int base=dy/adx;
  99404. int sy=(dy<0?base-1:base+1);
  99405. int x=x0;
  99406. int y=y0;
  99407. int err=0;
  99408. int val=vorbis_dBquant(mask+x);
  99409. int mse=0;
  99410. int n=0;
  99411. ady-=abs(base*adx);
  99412. mse=(y-val);
  99413. mse*=mse;
  99414. n++;
  99415. if(mdct[x]+info->twofitatten>=mask[x]){
  99416. if(y+info->maxover<val)return(1);
  99417. if(y-info->maxunder>val)return(1);
  99418. }
  99419. while(++x<x1){
  99420. err=err+ady;
  99421. if(err>=adx){
  99422. err-=adx;
  99423. y+=sy;
  99424. }else{
  99425. y+=base;
  99426. }
  99427. val=vorbis_dBquant(mask+x);
  99428. mse+=((y-val)*(y-val));
  99429. n++;
  99430. if(mdct[x]+info->twofitatten>=mask[x]){
  99431. if(val){
  99432. if(y+info->maxover<val)return(1);
  99433. if(y-info->maxunder>val)return(1);
  99434. }
  99435. }
  99436. }
  99437. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99438. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99439. if(mse/n>info->maxerr)return(1);
  99440. return(0);
  99441. }
  99442. static int post_Y(int *A,int *B,int pos){
  99443. if(A[pos]<0)
  99444. return B[pos];
  99445. if(B[pos]<0)
  99446. return A[pos];
  99447. return (A[pos]+B[pos])>>1;
  99448. }
  99449. int *floor1_fit(vorbis_block *vb,void *look_,
  99450. const float *logmdct, /* in */
  99451. const float *logmask){
  99452. long i,j;
  99453. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99454. vorbis_info_floor1 *info=look->vi;
  99455. long n=look->n;
  99456. long posts=look->posts;
  99457. long nonzero=0;
  99458. lsfit_acc fits[VIF_POSIT+1];
  99459. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99460. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99461. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99462. int hineighbor[VIF_POSIT+2];
  99463. int *output=NULL;
  99464. int memo[VIF_POSIT+2];
  99465. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99466. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99467. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99468. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99469. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99470. if(posts==0){
  99471. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99472. }else{
  99473. for(i=0;i<posts-1;i++)
  99474. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99475. look->sorted_index[i+1],fits+i,
  99476. n,info);
  99477. }
  99478. if(nonzero){
  99479. int y0=-200;
  99480. int y1=-200;
  99481. fit_line(fits,posts-1,&y0,&y1);
  99482. fit_valueA[0]=y0;
  99483. fit_valueB[0]=y0;
  99484. fit_valueB[1]=y1;
  99485. fit_valueA[1]=y1;
  99486. for(i=2;i<posts;i++){
  99487. int sortpos=look->reverse_index[i];
  99488. int ln=loneighbor[sortpos];
  99489. int hn=hineighbor[sortpos];
  99490. if(memo[ln]!=hn){
  99491. int lsortpos=look->reverse_index[ln];
  99492. int hsortpos=look->reverse_index[hn];
  99493. memo[ln]=hn;
  99494. {
  99495. int lx=info->postlist[ln];
  99496. int hx=info->postlist[hn];
  99497. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99498. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99499. if(ly==-1 || hy==-1){
  99500. exit(1);
  99501. }
  99502. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99503. int ly0=-200;
  99504. int ly1=-200;
  99505. int hy0=-200;
  99506. int hy1=-200;
  99507. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99508. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99509. fit_valueB[ln]=ly0;
  99510. if(ln==0)fit_valueA[ln]=ly0;
  99511. fit_valueA[i]=ly1;
  99512. fit_valueB[i]=hy0;
  99513. fit_valueA[hn]=hy1;
  99514. if(hn==1)fit_valueB[hn]=hy1;
  99515. if(ly1>=0 || hy0>=0){
  99516. for(j=sortpos-1;j>=0;j--)
  99517. if(hineighbor[j]==hn)
  99518. hineighbor[j]=i;
  99519. else
  99520. break;
  99521. for(j=sortpos+1;j<posts;j++)
  99522. if(loneighbor[j]==ln)
  99523. loneighbor[j]=i;
  99524. else
  99525. break;
  99526. }
  99527. }else{
  99528. fit_valueA[i]=-200;
  99529. fit_valueB[i]=-200;
  99530. }
  99531. }
  99532. }
  99533. }
  99534. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99535. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99536. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99537. for(i=2;i<posts;i++){
  99538. int ln=look->loneighbor[i-2];
  99539. int hn=look->hineighbor[i-2];
  99540. int x0=info->postlist[ln];
  99541. int x1=info->postlist[hn];
  99542. int y0=output[ln];
  99543. int y1=output[hn];
  99544. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99545. int vx=post_Y(fit_valueA,fit_valueB,i);
  99546. if(vx>=0 && predicted!=vx){
  99547. output[i]=vx;
  99548. }else{
  99549. output[i]= predicted|0x8000;
  99550. }
  99551. }
  99552. }
  99553. return(output);
  99554. }
  99555. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99556. int *A,int *B,
  99557. int del){
  99558. long i;
  99559. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99560. long posts=look->posts;
  99561. int *output=NULL;
  99562. if(A && B){
  99563. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99564. for(i=0;i<posts;i++){
  99565. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99566. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99567. }
  99568. }
  99569. return(output);
  99570. }
  99571. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99572. void*look_,
  99573. int *post,int *ilogmask){
  99574. long i,j;
  99575. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99576. vorbis_info_floor1 *info=look->vi;
  99577. long posts=look->posts;
  99578. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99579. int out[VIF_POSIT+2];
  99580. static_codebook **sbooks=ci->book_param;
  99581. codebook *books=ci->fullbooks;
  99582. static long seq=0;
  99583. if(post){
  99584. for(i=0;i<posts;i++){
  99585. int val=post[i]&0x7fff;
  99586. switch(info->mult){
  99587. case 1: /* 1024 -> 256 */
  99588. val>>=2;
  99589. break;
  99590. case 2: /* 1024 -> 128 */
  99591. val>>=3;
  99592. break;
  99593. case 3: /* 1024 -> 86 */
  99594. val/=12;
  99595. break;
  99596. case 4: /* 1024 -> 64 */
  99597. val>>=4;
  99598. break;
  99599. }
  99600. post[i]=val | (post[i]&0x8000);
  99601. }
  99602. out[0]=post[0];
  99603. out[1]=post[1];
  99604. for(i=2;i<posts;i++){
  99605. int ln=look->loneighbor[i-2];
  99606. int hn=look->hineighbor[i-2];
  99607. int x0=info->postlist[ln];
  99608. int x1=info->postlist[hn];
  99609. int y0=post[ln];
  99610. int y1=post[hn];
  99611. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99612. if((post[i]&0x8000) || (predicted==post[i])){
  99613. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99614. in interpolation */
  99615. out[i]=0;
  99616. }else{
  99617. int headroom=(look->quant_q-predicted<predicted?
  99618. look->quant_q-predicted:predicted);
  99619. int val=post[i]-predicted;
  99620. if(val<0)
  99621. if(val<-headroom)
  99622. val=headroom-val-1;
  99623. else
  99624. val=-1-(val<<1);
  99625. else
  99626. if(val>=headroom)
  99627. val= val+headroom;
  99628. else
  99629. val<<=1;
  99630. out[i]=val;
  99631. post[ln]&=0x7fff;
  99632. post[hn]&=0x7fff;
  99633. }
  99634. }
  99635. oggpack_write(opb,1,1);
  99636. look->frames++;
  99637. look->postbits+=ilog(look->quant_q-1)*2;
  99638. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99639. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99640. for(i=0,j=2;i<info->partitions;i++){
  99641. int classx=info->partitionclass[i];
  99642. int cdim=info->class_dim[classx];
  99643. int csubbits=info->class_subs[classx];
  99644. int csub=1<<csubbits;
  99645. int bookas[8]={0,0,0,0,0,0,0,0};
  99646. int cval=0;
  99647. int cshift=0;
  99648. int k,l;
  99649. if(csubbits){
  99650. int maxval[8];
  99651. for(k=0;k<csub;k++){
  99652. int booknum=info->class_subbook[classx][k];
  99653. if(booknum<0){
  99654. maxval[k]=1;
  99655. }else{
  99656. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99657. }
  99658. }
  99659. for(k=0;k<cdim;k++){
  99660. for(l=0;l<csub;l++){
  99661. int val=out[j+k];
  99662. if(val<maxval[l]){
  99663. bookas[k]=l;
  99664. break;
  99665. }
  99666. }
  99667. cval|= bookas[k]<<cshift;
  99668. cshift+=csubbits;
  99669. }
  99670. look->phrasebits+=
  99671. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99672. #ifdef TRAIN_FLOOR1
  99673. {
  99674. FILE *of;
  99675. char buffer[80];
  99676. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99677. vb->pcmend/2,posts-2,class);
  99678. of=fopen(buffer,"a");
  99679. fprintf(of,"%d\n",cval);
  99680. fclose(of);
  99681. }
  99682. #endif
  99683. }
  99684. for(k=0;k<cdim;k++){
  99685. int book=info->class_subbook[classx][bookas[k]];
  99686. if(book>=0){
  99687. if(out[j+k]<(books+book)->entries)
  99688. look->postbits+=vorbis_book_encode(books+book,
  99689. out[j+k],opb);
  99690. #ifdef TRAIN_FLOOR1
  99691. {
  99692. FILE *of;
  99693. char buffer[80];
  99694. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99695. vb->pcmend/2,posts-2,class,bookas[k]);
  99696. of=fopen(buffer,"a");
  99697. fprintf(of,"%d\n",out[j+k]);
  99698. fclose(of);
  99699. }
  99700. #endif
  99701. }
  99702. }
  99703. j+=cdim;
  99704. }
  99705. {
  99706. int hx=0;
  99707. int lx=0;
  99708. int ly=post[0]*info->mult;
  99709. for(j=1;j<look->posts;j++){
  99710. int current=look->forward_index[j];
  99711. int hy=post[current]&0x7fff;
  99712. if(hy==post[current]){
  99713. hy*=info->mult;
  99714. hx=info->postlist[current];
  99715. render_line0(lx,hx,ly,hy,ilogmask);
  99716. lx=hx;
  99717. ly=hy;
  99718. }
  99719. }
  99720. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99721. seq++;
  99722. return(1);
  99723. }
  99724. }else{
  99725. oggpack_write(opb,0,1);
  99726. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99727. seq++;
  99728. return(0);
  99729. }
  99730. }
  99731. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99732. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99733. vorbis_info_floor1 *info=look->vi;
  99734. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99735. int i,j,k;
  99736. codebook *books=ci->fullbooks;
  99737. if(oggpack_read(&vb->opb,1)==1){
  99738. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99739. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99740. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99741. for(i=0,j=2;i<info->partitions;i++){
  99742. int classx=info->partitionclass[i];
  99743. int cdim=info->class_dim[classx];
  99744. int csubbits=info->class_subs[classx];
  99745. int csub=1<<csubbits;
  99746. int cval=0;
  99747. if(csubbits){
  99748. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99749. if(cval==-1)goto eop;
  99750. }
  99751. for(k=0;k<cdim;k++){
  99752. int book=info->class_subbook[classx][cval&(csub-1)];
  99753. cval>>=csubbits;
  99754. if(book>=0){
  99755. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99756. goto eop;
  99757. }else{
  99758. fit_value[j+k]=0;
  99759. }
  99760. }
  99761. j+=cdim;
  99762. }
  99763. for(i=2;i<look->posts;i++){
  99764. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99765. info->postlist[look->hineighbor[i-2]],
  99766. fit_value[look->loneighbor[i-2]],
  99767. fit_value[look->hineighbor[i-2]],
  99768. info->postlist[i]);
  99769. int hiroom=look->quant_q-predicted;
  99770. int loroom=predicted;
  99771. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99772. int val=fit_value[i];
  99773. if(val){
  99774. if(val>=room){
  99775. if(hiroom>loroom){
  99776. val = val-loroom;
  99777. }else{
  99778. val = -1-(val-hiroom);
  99779. }
  99780. }else{
  99781. if(val&1){
  99782. val= -((val+1)>>1);
  99783. }else{
  99784. val>>=1;
  99785. }
  99786. }
  99787. fit_value[i]=val+predicted;
  99788. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99789. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99790. }else{
  99791. fit_value[i]=predicted|0x8000;
  99792. }
  99793. }
  99794. return(fit_value);
  99795. }
  99796. eop:
  99797. return(NULL);
  99798. }
  99799. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99800. float *out){
  99801. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99802. vorbis_info_floor1 *info=look->vi;
  99803. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99804. int n=ci->blocksizes[vb->W]/2;
  99805. int j;
  99806. if(memo){
  99807. int *fit_value=(int *)memo;
  99808. int hx=0;
  99809. int lx=0;
  99810. int ly=fit_value[0]*info->mult;
  99811. for(j=1;j<look->posts;j++){
  99812. int current=look->forward_index[j];
  99813. int hy=fit_value[current]&0x7fff;
  99814. if(hy==fit_value[current]){
  99815. hy*=info->mult;
  99816. hx=info->postlist[current];
  99817. render_line(lx,hx,ly,hy,out);
  99818. lx=hx;
  99819. ly=hy;
  99820. }
  99821. }
  99822. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99823. return(1);
  99824. }
  99825. memset(out,0,sizeof(*out)*n);
  99826. return(0);
  99827. }
  99828. vorbis_func_floor floor1_exportbundle={
  99829. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99830. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99831. };
  99832. #endif
  99833. /*** End of inlined file: floor1.c ***/
  99834. /*** Start of inlined file: info.c ***/
  99835. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99836. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99837. // tasks..
  99838. #if JUCE_MSVC
  99839. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99840. #endif
  99841. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99842. #if JUCE_USE_OGGVORBIS
  99843. #include <stdlib.h>
  99844. #include <string.h>
  99845. #include <ctype.h>
  99846. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99847. while(bytes--){
  99848. oggpack_write(o,*s++,8);
  99849. }
  99850. }
  99851. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99852. while(bytes--){
  99853. *buf++=oggpack_read(o,8);
  99854. }
  99855. }
  99856. void vorbis_comment_init(vorbis_comment *vc){
  99857. memset(vc,0,sizeof(*vc));
  99858. }
  99859. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99860. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99861. (vc->comments+2)*sizeof(*vc->user_comments));
  99862. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99863. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99864. vc->comment_lengths[vc->comments]=strlen(comment);
  99865. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99866. strcpy(vc->user_comments[vc->comments], comment);
  99867. vc->comments++;
  99868. vc->user_comments[vc->comments]=NULL;
  99869. }
  99870. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99871. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99872. strcpy(comment, tag);
  99873. strcat(comment, "=");
  99874. strcat(comment, contents);
  99875. vorbis_comment_add(vc, comment);
  99876. }
  99877. static int tagcompare(const char *s1, const char *s2, int n){
  99878. int c=0;
  99879. while(c < n){
  99880. if(toupper(s1[c]) != toupper(s2[c]))
  99881. return !0;
  99882. c++;
  99883. }
  99884. return 0;
  99885. }
  99886. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99887. long i;
  99888. int found = 0;
  99889. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99890. char *fulltag = (char*)alloca(taglen+ 1);
  99891. strcpy(fulltag, tag);
  99892. strcat(fulltag, "=");
  99893. for(i=0;i<vc->comments;i++){
  99894. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99895. if(count == found)
  99896. return vc->user_comments[i] + taglen;
  99897. else
  99898. found++;
  99899. }
  99900. }
  99901. return NULL; /* didn't find anything */
  99902. }
  99903. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99904. int i,count=0;
  99905. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99906. char *fulltag = (char*)alloca(taglen+1);
  99907. strcpy(fulltag,tag);
  99908. strcat(fulltag, "=");
  99909. for(i=0;i<vc->comments;i++){
  99910. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99911. count++;
  99912. }
  99913. return count;
  99914. }
  99915. void vorbis_comment_clear(vorbis_comment *vc){
  99916. if(vc){
  99917. long i;
  99918. for(i=0;i<vc->comments;i++)
  99919. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  99920. if(vc->user_comments)_ogg_free(vc->user_comments);
  99921. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  99922. if(vc->vendor)_ogg_free(vc->vendor);
  99923. }
  99924. memset(vc,0,sizeof(*vc));
  99925. }
  99926. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  99927. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  99928. return ci ? ci->blocksizes[zo] : -1;
  99929. }
  99930. void vorbis_info_init(vorbis_info *vi){
  99931. memset(vi,0,sizeof(*vi));
  99932. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  99933. }
  99934. void vorbis_info_clear(vorbis_info *vi){
  99935. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99936. int i;
  99937. if(ci){
  99938. for(i=0;i<ci->modes;i++)
  99939. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  99940. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  99941. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  99942. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  99943. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  99944. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  99945. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  99946. for(i=0;i<ci->books;i++){
  99947. if(ci->book_param[i]){
  99948. vorbis_staticbook_destroy(ci->book_param[i]);
  99949. }
  99950. if(ci->fullbooks)
  99951. vorbis_book_clear(ci->fullbooks+i);
  99952. }
  99953. if(ci->fullbooks)
  99954. _ogg_free(ci->fullbooks);
  99955. for(i=0;i<ci->psys;i++)
  99956. _vi_psy_free(ci->psy_param[i]);
  99957. _ogg_free(ci);
  99958. }
  99959. memset(vi,0,sizeof(*vi));
  99960. }
  99961. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  99962. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99963. if(!ci)return(OV_EFAULT);
  99964. vi->version=oggpack_read(opb,32);
  99965. if(vi->version!=0)return(OV_EVERSION);
  99966. vi->channels=oggpack_read(opb,8);
  99967. vi->rate=oggpack_read(opb,32);
  99968. vi->bitrate_upper=oggpack_read(opb,32);
  99969. vi->bitrate_nominal=oggpack_read(opb,32);
  99970. vi->bitrate_lower=oggpack_read(opb,32);
  99971. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  99972. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  99973. if(vi->rate<1)goto err_out;
  99974. if(vi->channels<1)goto err_out;
  99975. if(ci->blocksizes[0]<8)goto err_out;
  99976. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  99977. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99978. return(0);
  99979. err_out:
  99980. vorbis_info_clear(vi);
  99981. return(OV_EBADHEADER);
  99982. }
  99983. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  99984. int i;
  99985. int vendorlen=oggpack_read(opb,32);
  99986. if(vendorlen<0)goto err_out;
  99987. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  99988. _v_readstring(opb,vc->vendor,vendorlen);
  99989. vc->comments=oggpack_read(opb,32);
  99990. if(vc->comments<0)goto err_out;
  99991. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  99992. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  99993. for(i=0;i<vc->comments;i++){
  99994. int len=oggpack_read(opb,32);
  99995. if(len<0)goto err_out;
  99996. vc->comment_lengths[i]=len;
  99997. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  99998. _v_readstring(opb,vc->user_comments[i],len);
  99999. }
  100000. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100001. return(0);
  100002. err_out:
  100003. vorbis_comment_clear(vc);
  100004. return(OV_EBADHEADER);
  100005. }
  100006. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100007. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100008. int i;
  100009. if(!ci)return(OV_EFAULT);
  100010. ci->books=oggpack_read(opb,8)+1;
  100011. for(i=0;i<ci->books;i++){
  100012. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100013. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100014. }
  100015. {
  100016. int times=oggpack_read(opb,6)+1;
  100017. for(i=0;i<times;i++){
  100018. int test=oggpack_read(opb,16);
  100019. if(test<0 || test>=VI_TIMEB)goto err_out;
  100020. }
  100021. }
  100022. ci->floors=oggpack_read(opb,6)+1;
  100023. for(i=0;i<ci->floors;i++){
  100024. ci->floor_type[i]=oggpack_read(opb,16);
  100025. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100026. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100027. if(!ci->floor_param[i])goto err_out;
  100028. }
  100029. ci->residues=oggpack_read(opb,6)+1;
  100030. for(i=0;i<ci->residues;i++){
  100031. ci->residue_type[i]=oggpack_read(opb,16);
  100032. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100033. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100034. if(!ci->residue_param[i])goto err_out;
  100035. }
  100036. ci->maps=oggpack_read(opb,6)+1;
  100037. for(i=0;i<ci->maps;i++){
  100038. ci->map_type[i]=oggpack_read(opb,16);
  100039. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100040. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100041. if(!ci->map_param[i])goto err_out;
  100042. }
  100043. ci->modes=oggpack_read(opb,6)+1;
  100044. for(i=0;i<ci->modes;i++){
  100045. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100046. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100047. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100048. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100049. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100050. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100051. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100052. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100053. }
  100054. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100055. return(0);
  100056. err_out:
  100057. vorbis_info_clear(vi);
  100058. return(OV_EBADHEADER);
  100059. }
  100060. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100061. oggpack_buffer opb;
  100062. if(op){
  100063. oggpack_readinit(&opb,op->packet,op->bytes);
  100064. {
  100065. char buffer[6];
  100066. int packtype=oggpack_read(&opb,8);
  100067. memset(buffer,0,6);
  100068. _v_readstring(&opb,buffer,6);
  100069. if(memcmp(buffer,"vorbis",6)){
  100070. return(OV_ENOTVORBIS);
  100071. }
  100072. switch(packtype){
  100073. case 0x01: /* least significant *bit* is read first */
  100074. if(!op->b_o_s){
  100075. return(OV_EBADHEADER);
  100076. }
  100077. if(vi->rate!=0){
  100078. return(OV_EBADHEADER);
  100079. }
  100080. return(_vorbis_unpack_info(vi,&opb));
  100081. case 0x03: /* least significant *bit* is read first */
  100082. if(vi->rate==0){
  100083. return(OV_EBADHEADER);
  100084. }
  100085. return(_vorbis_unpack_comment(vc,&opb));
  100086. case 0x05: /* least significant *bit* is read first */
  100087. if(vi->rate==0 || vc->vendor==NULL){
  100088. return(OV_EBADHEADER);
  100089. }
  100090. return(_vorbis_unpack_books(vi,&opb));
  100091. default:
  100092. return(OV_EBADHEADER);
  100093. break;
  100094. }
  100095. }
  100096. }
  100097. return(OV_EBADHEADER);
  100098. }
  100099. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100100. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100101. if(!ci)return(OV_EFAULT);
  100102. oggpack_write(opb,0x01,8);
  100103. _v_writestring(opb,"vorbis", 6);
  100104. oggpack_write(opb,0x00,32);
  100105. oggpack_write(opb,vi->channels,8);
  100106. oggpack_write(opb,vi->rate,32);
  100107. oggpack_write(opb,vi->bitrate_upper,32);
  100108. oggpack_write(opb,vi->bitrate_nominal,32);
  100109. oggpack_write(opb,vi->bitrate_lower,32);
  100110. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100111. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100112. oggpack_write(opb,1,1);
  100113. return(0);
  100114. }
  100115. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100116. char temp[]="Xiph.Org libVorbis I 20050304";
  100117. int bytes = strlen(temp);
  100118. oggpack_write(opb,0x03,8);
  100119. _v_writestring(opb,"vorbis", 6);
  100120. oggpack_write(opb,bytes,32);
  100121. _v_writestring(opb,temp, bytes);
  100122. oggpack_write(opb,vc->comments,32);
  100123. if(vc->comments){
  100124. int i;
  100125. for(i=0;i<vc->comments;i++){
  100126. if(vc->user_comments[i]){
  100127. oggpack_write(opb,vc->comment_lengths[i],32);
  100128. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100129. }else{
  100130. oggpack_write(opb,0,32);
  100131. }
  100132. }
  100133. }
  100134. oggpack_write(opb,1,1);
  100135. return(0);
  100136. }
  100137. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100138. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100139. int i;
  100140. if(!ci)return(OV_EFAULT);
  100141. oggpack_write(opb,0x05,8);
  100142. _v_writestring(opb,"vorbis", 6);
  100143. oggpack_write(opb,ci->books-1,8);
  100144. for(i=0;i<ci->books;i++)
  100145. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100146. oggpack_write(opb,0,6);
  100147. oggpack_write(opb,0,16);
  100148. oggpack_write(opb,ci->floors-1,6);
  100149. for(i=0;i<ci->floors;i++){
  100150. oggpack_write(opb,ci->floor_type[i],16);
  100151. if(_floor_P[ci->floor_type[i]]->pack)
  100152. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100153. else
  100154. goto err_out;
  100155. }
  100156. oggpack_write(opb,ci->residues-1,6);
  100157. for(i=0;i<ci->residues;i++){
  100158. oggpack_write(opb,ci->residue_type[i],16);
  100159. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100160. }
  100161. oggpack_write(opb,ci->maps-1,6);
  100162. for(i=0;i<ci->maps;i++){
  100163. oggpack_write(opb,ci->map_type[i],16);
  100164. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100165. }
  100166. oggpack_write(opb,ci->modes-1,6);
  100167. for(i=0;i<ci->modes;i++){
  100168. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100169. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100170. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100171. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100172. }
  100173. oggpack_write(opb,1,1);
  100174. return(0);
  100175. err_out:
  100176. return(-1);
  100177. }
  100178. int vorbis_commentheader_out(vorbis_comment *vc,
  100179. ogg_packet *op){
  100180. oggpack_buffer opb;
  100181. oggpack_writeinit(&opb);
  100182. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100183. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100184. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100185. op->bytes=oggpack_bytes(&opb);
  100186. op->b_o_s=0;
  100187. op->e_o_s=0;
  100188. op->granulepos=0;
  100189. op->packetno=1;
  100190. return 0;
  100191. }
  100192. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100193. vorbis_comment *vc,
  100194. ogg_packet *op,
  100195. ogg_packet *op_comm,
  100196. ogg_packet *op_code){
  100197. int ret=OV_EIMPL;
  100198. vorbis_info *vi=v->vi;
  100199. oggpack_buffer opb;
  100200. private_state *b=(private_state*)v->backend_state;
  100201. if(!b){
  100202. ret=OV_EFAULT;
  100203. goto err_out;
  100204. }
  100205. oggpack_writeinit(&opb);
  100206. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100207. if(b->header)_ogg_free(b->header);
  100208. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100209. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100210. op->packet=b->header;
  100211. op->bytes=oggpack_bytes(&opb);
  100212. op->b_o_s=1;
  100213. op->e_o_s=0;
  100214. op->granulepos=0;
  100215. op->packetno=0;
  100216. oggpack_reset(&opb);
  100217. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100218. if(b->header1)_ogg_free(b->header1);
  100219. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100220. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100221. op_comm->packet=b->header1;
  100222. op_comm->bytes=oggpack_bytes(&opb);
  100223. op_comm->b_o_s=0;
  100224. op_comm->e_o_s=0;
  100225. op_comm->granulepos=0;
  100226. op_comm->packetno=1;
  100227. oggpack_reset(&opb);
  100228. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100229. if(b->header2)_ogg_free(b->header2);
  100230. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100231. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100232. op_code->packet=b->header2;
  100233. op_code->bytes=oggpack_bytes(&opb);
  100234. op_code->b_o_s=0;
  100235. op_code->e_o_s=0;
  100236. op_code->granulepos=0;
  100237. op_code->packetno=2;
  100238. oggpack_writeclear(&opb);
  100239. return(0);
  100240. err_out:
  100241. oggpack_writeclear(&opb);
  100242. memset(op,0,sizeof(*op));
  100243. memset(op_comm,0,sizeof(*op_comm));
  100244. memset(op_code,0,sizeof(*op_code));
  100245. if(b->header)_ogg_free(b->header);
  100246. if(b->header1)_ogg_free(b->header1);
  100247. if(b->header2)_ogg_free(b->header2);
  100248. b->header=NULL;
  100249. b->header1=NULL;
  100250. b->header2=NULL;
  100251. return(ret);
  100252. }
  100253. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100254. if(granulepos>=0)
  100255. return((double)granulepos/v->vi->rate);
  100256. return(-1);
  100257. }
  100258. #endif
  100259. /*** End of inlined file: info.c ***/
  100260. /*** Start of inlined file: lpc.c ***/
  100261. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100262. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100263. // tasks..
  100264. #if JUCE_MSVC
  100265. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100266. #endif
  100267. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100268. #if JUCE_USE_OGGVORBIS
  100269. #include <stdlib.h>
  100270. #include <string.h>
  100271. #include <math.h>
  100272. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100273. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100274. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100275. double error;
  100276. int i,j;
  100277. j=m+1;
  100278. while(j--){
  100279. double d=0; /* double needed for accumulator depth */
  100280. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100281. aut[j]=d;
  100282. }
  100283. error=aut[0];
  100284. for(i=0;i<m;i++){
  100285. double r= -aut[i+1];
  100286. if(error==0){
  100287. memset(lpci,0,m*sizeof(*lpci));
  100288. return 0;
  100289. }
  100290. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100291. r/=error;
  100292. lpc[i]=r;
  100293. for(j=0;j<i/2;j++){
  100294. double tmp=lpc[j];
  100295. lpc[j]+=r*lpc[i-1-j];
  100296. lpc[i-1-j]+=r*tmp;
  100297. }
  100298. if(i%2)lpc[j]+=lpc[j]*r;
  100299. error*=1.f-r*r;
  100300. }
  100301. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100302. return error;
  100303. }
  100304. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100305. float *data,long n){
  100306. long i,j,o,p;
  100307. float y;
  100308. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100309. if(!prime)
  100310. for(i=0;i<m;i++)
  100311. work[i]=0.f;
  100312. else
  100313. for(i=0;i<m;i++)
  100314. work[i]=prime[i];
  100315. for(i=0;i<n;i++){
  100316. y=0;
  100317. o=i;
  100318. p=m;
  100319. for(j=0;j<m;j++)
  100320. y-=work[o++]*coeff[--p];
  100321. data[i]=work[o]=y;
  100322. }
  100323. }
  100324. #endif
  100325. /*** End of inlined file: lpc.c ***/
  100326. /*** Start of inlined file: lsp.c ***/
  100327. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100328. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100329. // tasks..
  100330. #if JUCE_MSVC
  100331. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100332. #endif
  100333. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100334. #if JUCE_USE_OGGVORBIS
  100335. #include <math.h>
  100336. #include <string.h>
  100337. #include <stdlib.h>
  100338. /*** Start of inlined file: lookup.h ***/
  100339. #ifndef _V_LOOKUP_H_
  100340. #ifdef FLOAT_LOOKUP
  100341. extern float vorbis_coslook(float a);
  100342. extern float vorbis_invsqlook(float a);
  100343. extern float vorbis_invsq2explook(int a);
  100344. extern float vorbis_fromdBlook(float a);
  100345. #endif
  100346. #ifdef INT_LOOKUP
  100347. extern long vorbis_invsqlook_i(long a,long e);
  100348. extern long vorbis_coslook_i(long a);
  100349. extern float vorbis_fromdBlook_i(long a);
  100350. #endif
  100351. #endif
  100352. /*** End of inlined file: lookup.h ***/
  100353. #define FLOAT_LOOKUP
  100354. #undef INT_LOOKUP
  100355. #ifdef FLOAT_LOOKUP
  100356. /*** Start of inlined file: lookup.c ***/
  100357. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100358. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100359. // tasks..
  100360. #if JUCE_MSVC
  100361. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100362. #endif
  100363. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100364. #if JUCE_USE_OGGVORBIS
  100365. #include <math.h>
  100366. /*** Start of inlined file: lookup.h ***/
  100367. #ifndef _V_LOOKUP_H_
  100368. #ifdef FLOAT_LOOKUP
  100369. extern float vorbis_coslook(float a);
  100370. extern float vorbis_invsqlook(float a);
  100371. extern float vorbis_invsq2explook(int a);
  100372. extern float vorbis_fromdBlook(float a);
  100373. #endif
  100374. #ifdef INT_LOOKUP
  100375. extern long vorbis_invsqlook_i(long a,long e);
  100376. extern long vorbis_coslook_i(long a);
  100377. extern float vorbis_fromdBlook_i(long a);
  100378. #endif
  100379. #endif
  100380. /*** End of inlined file: lookup.h ***/
  100381. /*** Start of inlined file: lookup_data.h ***/
  100382. #ifndef _V_LOOKUP_DATA_H_
  100383. #ifdef FLOAT_LOOKUP
  100384. #define COS_LOOKUP_SZ 128
  100385. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100386. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100387. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100388. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100389. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100390. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100391. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100392. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100393. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100394. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100395. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100396. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100397. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100398. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100399. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100400. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100401. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100402. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100403. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100404. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100405. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100406. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100407. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100408. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100409. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100410. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100411. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100412. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100413. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100414. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100415. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100416. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100417. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100418. -1.0000000000000f,
  100419. };
  100420. #define INVSQ_LOOKUP_SZ 32
  100421. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100422. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100423. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100424. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100425. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100426. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100427. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100428. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100429. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100430. 1.000000000000f,
  100431. };
  100432. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100433. #define INVSQ2EXP_LOOKUP_MAX 32
  100434. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100435. INVSQ2EXP_LOOKUP_MIN+1]={
  100436. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100437. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100438. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100439. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100440. 256.f, 181.019336f, 128.f, 90.50966799f,
  100441. 64.f, 45.254834f, 32.f, 22.627417f,
  100442. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100443. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100444. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100445. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100446. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100447. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100448. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100449. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100450. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100451. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100452. 1.525878906e-05f,
  100453. };
  100454. #endif
  100455. #define FROMdB_LOOKUP_SZ 35
  100456. #define FROMdB2_LOOKUP_SZ 32
  100457. #define FROMdB_SHIFT 5
  100458. #define FROMdB2_SHIFT 3
  100459. #define FROMdB2_MASK 31
  100460. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100461. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100462. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100463. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100464. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100465. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100466. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100467. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100468. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100469. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100470. };
  100471. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100472. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100473. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100474. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100475. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100476. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100477. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100478. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100479. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100480. };
  100481. #ifdef INT_LOOKUP
  100482. #define INVSQ_LOOKUP_I_SHIFT 10
  100483. #define INVSQ_LOOKUP_I_MASK 1023
  100484. static long INVSQ_LOOKUP_I[64+1]={
  100485. 92682l, 91966l, 91267l, 90583l,
  100486. 89915l, 89261l, 88621l, 87995l,
  100487. 87381l, 86781l, 86192l, 85616l,
  100488. 85051l, 84497l, 83953l, 83420l,
  100489. 82897l, 82384l, 81880l, 81385l,
  100490. 80899l, 80422l, 79953l, 79492l,
  100491. 79039l, 78594l, 78156l, 77726l,
  100492. 77302l, 76885l, 76475l, 76072l,
  100493. 75674l, 75283l, 74898l, 74519l,
  100494. 74146l, 73778l, 73415l, 73058l,
  100495. 72706l, 72359l, 72016l, 71679l,
  100496. 71347l, 71019l, 70695l, 70376l,
  100497. 70061l, 69750l, 69444l, 69141l,
  100498. 68842l, 68548l, 68256l, 67969l,
  100499. 67685l, 67405l, 67128l, 66855l,
  100500. 66585l, 66318l, 66054l, 65794l,
  100501. 65536l,
  100502. };
  100503. #define COS_LOOKUP_I_SHIFT 9
  100504. #define COS_LOOKUP_I_MASK 511
  100505. #define COS_LOOKUP_I_SZ 128
  100506. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100507. 16384l, 16379l, 16364l, 16340l,
  100508. 16305l, 16261l, 16207l, 16143l,
  100509. 16069l, 15986l, 15893l, 15791l,
  100510. 15679l, 15557l, 15426l, 15286l,
  100511. 15137l, 14978l, 14811l, 14635l,
  100512. 14449l, 14256l, 14053l, 13842l,
  100513. 13623l, 13395l, 13160l, 12916l,
  100514. 12665l, 12406l, 12140l, 11866l,
  100515. 11585l, 11297l, 11003l, 10702l,
  100516. 10394l, 10080l, 9760l, 9434l,
  100517. 9102l, 8765l, 8423l, 8076l,
  100518. 7723l, 7366l, 7005l, 6639l,
  100519. 6270l, 5897l, 5520l, 5139l,
  100520. 4756l, 4370l, 3981l, 3590l,
  100521. 3196l, 2801l, 2404l, 2006l,
  100522. 1606l, 1205l, 804l, 402l,
  100523. 0l, -401l, -803l, -1204l,
  100524. -1605l, -2005l, -2403l, -2800l,
  100525. -3195l, -3589l, -3980l, -4369l,
  100526. -4755l, -5138l, -5519l, -5896l,
  100527. -6269l, -6638l, -7004l, -7365l,
  100528. -7722l, -8075l, -8422l, -8764l,
  100529. -9101l, -9433l, -9759l, -10079l,
  100530. -10393l, -10701l, -11002l, -11296l,
  100531. -11584l, -11865l, -12139l, -12405l,
  100532. -12664l, -12915l, -13159l, -13394l,
  100533. -13622l, -13841l, -14052l, -14255l,
  100534. -14448l, -14634l, -14810l, -14977l,
  100535. -15136l, -15285l, -15425l, -15556l,
  100536. -15678l, -15790l, -15892l, -15985l,
  100537. -16068l, -16142l, -16206l, -16260l,
  100538. -16304l, -16339l, -16363l, -16378l,
  100539. -16383l,
  100540. };
  100541. #endif
  100542. #endif
  100543. /*** End of inlined file: lookup_data.h ***/
  100544. #ifdef FLOAT_LOOKUP
  100545. float vorbis_coslook(float a){
  100546. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100547. int i=vorbis_ftoi(d-.5);
  100548. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100549. }
  100550. float vorbis_invsqlook(float a){
  100551. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100552. int i=vorbis_ftoi(d-.5f);
  100553. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100554. }
  100555. float vorbis_invsq2explook(int a){
  100556. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100557. }
  100558. #include <stdio.h>
  100559. float vorbis_fromdBlook(float a){
  100560. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100561. return (i<0)?1.f:
  100562. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100563. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100564. }
  100565. #endif
  100566. #ifdef INT_LOOKUP
  100567. long vorbis_invsqlook_i(long a,long e){
  100568. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100569. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100570. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100571. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100572. d)>>16); /* result 1.16 */
  100573. e+=32;
  100574. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100575. e=(e>>1)-8;
  100576. return(val>>e);
  100577. }
  100578. float vorbis_fromdBlook_i(long a){
  100579. int i=(-a)>>(12-FROMdB2_SHIFT);
  100580. return (i<0)?1.f:
  100581. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100582. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100583. }
  100584. long vorbis_coslook_i(long a){
  100585. int i=a>>COS_LOOKUP_I_SHIFT;
  100586. int d=a&COS_LOOKUP_I_MASK;
  100587. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100588. COS_LOOKUP_I_SHIFT);
  100589. }
  100590. #endif
  100591. #endif
  100592. /*** End of inlined file: lookup.c ***/
  100593. /* catch this in the build system; we #include for
  100594. compilers (like gcc) that can't inline across
  100595. modules */
  100596. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100597. float amp,float ampoffset){
  100598. int i;
  100599. float wdel=M_PI/ln;
  100600. vorbis_fpu_control fpu;
  100601. (void) fpu; // to avoid an unused variable warning
  100602. vorbis_fpu_setround(&fpu);
  100603. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100604. i=0;
  100605. while(i<n){
  100606. int k=map[i];
  100607. int qexp;
  100608. float p=.7071067812f;
  100609. float q=.7071067812f;
  100610. float w=vorbis_coslook(wdel*k);
  100611. float *ftmp=lsp;
  100612. int c=m>>1;
  100613. do{
  100614. q*=ftmp[0]-w;
  100615. p*=ftmp[1]-w;
  100616. ftmp+=2;
  100617. }while(--c);
  100618. if(m&1){
  100619. q*=ftmp[0]-w;
  100620. q*=q;
  100621. p*=p*(1.f-w*w);
  100622. }else{
  100623. q*=q*(1.f+w);
  100624. p*=p*(1.f-w);
  100625. }
  100626. q=frexp(p+q,&qexp);
  100627. q=vorbis_fromdBlook(amp*
  100628. vorbis_invsqlook(q)*
  100629. vorbis_invsq2explook(qexp+m)-
  100630. ampoffset);
  100631. do{
  100632. curve[i++]*=q;
  100633. }while(map[i]==k);
  100634. }
  100635. vorbis_fpu_restore(fpu);
  100636. }
  100637. #else
  100638. #ifdef INT_LOOKUP
  100639. /*** Start of inlined file: lookup.c ***/
  100640. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100641. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100642. // tasks..
  100643. #if JUCE_MSVC
  100644. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100645. #endif
  100646. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100647. #if JUCE_USE_OGGVORBIS
  100648. #include <math.h>
  100649. /*** Start of inlined file: lookup.h ***/
  100650. #ifndef _V_LOOKUP_H_
  100651. #ifdef FLOAT_LOOKUP
  100652. extern float vorbis_coslook(float a);
  100653. extern float vorbis_invsqlook(float a);
  100654. extern float vorbis_invsq2explook(int a);
  100655. extern float vorbis_fromdBlook(float a);
  100656. #endif
  100657. #ifdef INT_LOOKUP
  100658. extern long vorbis_invsqlook_i(long a,long e);
  100659. extern long vorbis_coslook_i(long a);
  100660. extern float vorbis_fromdBlook_i(long a);
  100661. #endif
  100662. #endif
  100663. /*** End of inlined file: lookup.h ***/
  100664. /*** Start of inlined file: lookup_data.h ***/
  100665. #ifndef _V_LOOKUP_DATA_H_
  100666. #ifdef FLOAT_LOOKUP
  100667. #define COS_LOOKUP_SZ 128
  100668. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100669. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100670. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100671. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100672. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100673. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100674. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100675. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100676. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100677. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100678. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100679. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100680. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100681. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100682. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100683. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100684. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100685. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100686. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100687. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100688. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100689. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100690. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100691. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100692. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100693. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100694. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100695. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100696. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100697. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100698. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100699. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100700. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100701. -1.0000000000000f,
  100702. };
  100703. #define INVSQ_LOOKUP_SZ 32
  100704. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100705. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100706. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100707. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100708. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100709. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100710. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100711. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100712. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100713. 1.000000000000f,
  100714. };
  100715. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100716. #define INVSQ2EXP_LOOKUP_MAX 32
  100717. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100718. INVSQ2EXP_LOOKUP_MIN+1]={
  100719. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100720. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100721. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100722. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100723. 256.f, 181.019336f, 128.f, 90.50966799f,
  100724. 64.f, 45.254834f, 32.f, 22.627417f,
  100725. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100726. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100727. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100728. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100729. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100730. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100731. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100732. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100733. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100734. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100735. 1.525878906e-05f,
  100736. };
  100737. #endif
  100738. #define FROMdB_LOOKUP_SZ 35
  100739. #define FROMdB2_LOOKUP_SZ 32
  100740. #define FROMdB_SHIFT 5
  100741. #define FROMdB2_SHIFT 3
  100742. #define FROMdB2_MASK 31
  100743. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100744. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100745. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100746. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100747. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100748. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100749. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100750. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100751. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100752. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100753. };
  100754. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100755. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100756. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100757. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100758. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100759. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100760. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100761. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100762. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100763. };
  100764. #ifdef INT_LOOKUP
  100765. #define INVSQ_LOOKUP_I_SHIFT 10
  100766. #define INVSQ_LOOKUP_I_MASK 1023
  100767. static long INVSQ_LOOKUP_I[64+1]={
  100768. 92682l, 91966l, 91267l, 90583l,
  100769. 89915l, 89261l, 88621l, 87995l,
  100770. 87381l, 86781l, 86192l, 85616l,
  100771. 85051l, 84497l, 83953l, 83420l,
  100772. 82897l, 82384l, 81880l, 81385l,
  100773. 80899l, 80422l, 79953l, 79492l,
  100774. 79039l, 78594l, 78156l, 77726l,
  100775. 77302l, 76885l, 76475l, 76072l,
  100776. 75674l, 75283l, 74898l, 74519l,
  100777. 74146l, 73778l, 73415l, 73058l,
  100778. 72706l, 72359l, 72016l, 71679l,
  100779. 71347l, 71019l, 70695l, 70376l,
  100780. 70061l, 69750l, 69444l, 69141l,
  100781. 68842l, 68548l, 68256l, 67969l,
  100782. 67685l, 67405l, 67128l, 66855l,
  100783. 66585l, 66318l, 66054l, 65794l,
  100784. 65536l,
  100785. };
  100786. #define COS_LOOKUP_I_SHIFT 9
  100787. #define COS_LOOKUP_I_MASK 511
  100788. #define COS_LOOKUP_I_SZ 128
  100789. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100790. 16384l, 16379l, 16364l, 16340l,
  100791. 16305l, 16261l, 16207l, 16143l,
  100792. 16069l, 15986l, 15893l, 15791l,
  100793. 15679l, 15557l, 15426l, 15286l,
  100794. 15137l, 14978l, 14811l, 14635l,
  100795. 14449l, 14256l, 14053l, 13842l,
  100796. 13623l, 13395l, 13160l, 12916l,
  100797. 12665l, 12406l, 12140l, 11866l,
  100798. 11585l, 11297l, 11003l, 10702l,
  100799. 10394l, 10080l, 9760l, 9434l,
  100800. 9102l, 8765l, 8423l, 8076l,
  100801. 7723l, 7366l, 7005l, 6639l,
  100802. 6270l, 5897l, 5520l, 5139l,
  100803. 4756l, 4370l, 3981l, 3590l,
  100804. 3196l, 2801l, 2404l, 2006l,
  100805. 1606l, 1205l, 804l, 402l,
  100806. 0l, -401l, -803l, -1204l,
  100807. -1605l, -2005l, -2403l, -2800l,
  100808. -3195l, -3589l, -3980l, -4369l,
  100809. -4755l, -5138l, -5519l, -5896l,
  100810. -6269l, -6638l, -7004l, -7365l,
  100811. -7722l, -8075l, -8422l, -8764l,
  100812. -9101l, -9433l, -9759l, -10079l,
  100813. -10393l, -10701l, -11002l, -11296l,
  100814. -11584l, -11865l, -12139l, -12405l,
  100815. -12664l, -12915l, -13159l, -13394l,
  100816. -13622l, -13841l, -14052l, -14255l,
  100817. -14448l, -14634l, -14810l, -14977l,
  100818. -15136l, -15285l, -15425l, -15556l,
  100819. -15678l, -15790l, -15892l, -15985l,
  100820. -16068l, -16142l, -16206l, -16260l,
  100821. -16304l, -16339l, -16363l, -16378l,
  100822. -16383l,
  100823. };
  100824. #endif
  100825. #endif
  100826. /*** End of inlined file: lookup_data.h ***/
  100827. #ifdef FLOAT_LOOKUP
  100828. float vorbis_coslook(float a){
  100829. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100830. int i=vorbis_ftoi(d-.5);
  100831. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100832. }
  100833. float vorbis_invsqlook(float a){
  100834. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100835. int i=vorbis_ftoi(d-.5f);
  100836. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100837. }
  100838. float vorbis_invsq2explook(int a){
  100839. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100840. }
  100841. #include <stdio.h>
  100842. float vorbis_fromdBlook(float a){
  100843. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100844. return (i<0)?1.f:
  100845. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100846. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100847. }
  100848. #endif
  100849. #ifdef INT_LOOKUP
  100850. long vorbis_invsqlook_i(long a,long e){
  100851. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100852. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100853. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100854. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100855. d)>>16); /* result 1.16 */
  100856. e+=32;
  100857. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100858. e=(e>>1)-8;
  100859. return(val>>e);
  100860. }
  100861. float vorbis_fromdBlook_i(long a){
  100862. int i=(-a)>>(12-FROMdB2_SHIFT);
  100863. return (i<0)?1.f:
  100864. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100865. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100866. }
  100867. long vorbis_coslook_i(long a){
  100868. int i=a>>COS_LOOKUP_I_SHIFT;
  100869. int d=a&COS_LOOKUP_I_MASK;
  100870. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100871. COS_LOOKUP_I_SHIFT);
  100872. }
  100873. #endif
  100874. #endif
  100875. /*** End of inlined file: lookup.c ***/
  100876. /* catch this in the build system; we #include for
  100877. compilers (like gcc) that can't inline across
  100878. modules */
  100879. static int MLOOP_1[64]={
  100880. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100881. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100882. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100883. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100884. };
  100885. static int MLOOP_2[64]={
  100886. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100887. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100888. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100889. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100890. };
  100891. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100892. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100893. float amp,float ampoffset){
  100894. int i;
  100895. int ampoffseti=rint(ampoffset*4096.f);
  100896. int ampi=rint(amp*16.f);
  100897. long *ilsp=alloca(m*sizeof(*ilsp));
  100898. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100899. i=0;
  100900. while(i<n){
  100901. int j,k=map[i];
  100902. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100903. unsigned long qi=46341;
  100904. int qexp=0,shift;
  100905. long wi=vorbis_coslook_i(k*65536/ln);
  100906. qi*=labs(ilsp[0]-wi);
  100907. pi*=labs(ilsp[1]-wi);
  100908. for(j=3;j<m;j+=2){
  100909. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100910. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100911. shift=MLOOP_3[(pi|qi)>>16];
  100912. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100913. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100914. qexp+=shift;
  100915. }
  100916. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100917. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100918. shift=MLOOP_3[(pi|qi)>>16];
  100919. if(m&1){
  100920. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100921. pi=(pi>>shift)<<14;
  100922. qexp+=shift;
  100923. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100924. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100925. shift=MLOOP_3[(pi|qi)>>16];
  100926. pi>>=shift;
  100927. qi>>=shift;
  100928. qexp+=shift-14*((m+1)>>1);
  100929. pi=((pi*pi)>>16);
  100930. qi=((qi*qi)>>16);
  100931. qexp=qexp*2+m;
  100932. pi*=(1<<14)-((wi*wi)>>14);
  100933. qi+=pi>>14;
  100934. }else{
  100935. pi>>=shift;
  100936. qi>>=shift;
  100937. qexp+=shift-7*m;
  100938. pi=((pi*pi)>>16);
  100939. qi=((qi*qi)>>16);
  100940. qexp=qexp*2+m;
  100941. pi*=(1<<14)-wi;
  100942. qi*=(1<<14)+wi;
  100943. qi=(qi+pi)>>14;
  100944. }
  100945. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  100946. qi>>=1; qexp++;
  100947. }else
  100948. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  100949. qi<<=1; qexp--;
  100950. }
  100951. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  100952. vorbis_invsqlook_i(qi,qexp)-
  100953. ampoffseti); /* 8.12[0] */
  100954. curve[i]*=amp;
  100955. while(map[++i]==k)curve[i]*=amp;
  100956. }
  100957. }
  100958. #else
  100959. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100960. float amp,float ampoffset){
  100961. int i;
  100962. float wdel=M_PI/ln;
  100963. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  100964. i=0;
  100965. while(i<n){
  100966. int j,k=map[i];
  100967. float p=.5f;
  100968. float q=.5f;
  100969. float w=2.f*cos(wdel*k);
  100970. for(j=1;j<m;j+=2){
  100971. q *= w-lsp[j-1];
  100972. p *= w-lsp[j];
  100973. }
  100974. if(j==m){
  100975. q*=w-lsp[j-1];
  100976. p*=p*(4.f-w*w);
  100977. q*=q;
  100978. }else{
  100979. p*=p*(2.f-w);
  100980. q*=q*(2.f+w);
  100981. }
  100982. q=fromdB(amp/sqrt(p+q)-ampoffset);
  100983. curve[i]*=q;
  100984. while(map[++i]==k)curve[i]*=q;
  100985. }
  100986. }
  100987. #endif
  100988. #endif
  100989. static void cheby(float *g, int ord) {
  100990. int i, j;
  100991. g[0] *= .5f;
  100992. for(i=2; i<= ord; i++) {
  100993. for(j=ord; j >= i; j--) {
  100994. g[j-2] -= g[j];
  100995. g[j] += g[j];
  100996. }
  100997. }
  100998. }
  100999. static int comp(const void *a,const void *b){
  101000. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101001. }
  101002. #define EPSILON 10e-7
  101003. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101004. int i,m;
  101005. double lastdelta=0.f;
  101006. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101007. for(i=0;i<=ord;i++)defl[i]=a[i];
  101008. for(m=ord;m>0;m--){
  101009. double newx=0.f,delta;
  101010. while(1){
  101011. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101012. for(i=m;i>0;i--){
  101013. ppp = newx*ppp + pp;
  101014. pp = newx*pp + p;
  101015. p = newx*p + defl[i-1];
  101016. }
  101017. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101018. if(denom<0)
  101019. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101020. if(pp>0){
  101021. denom = pp + sqrt(denom);
  101022. if(denom<EPSILON)denom=EPSILON;
  101023. }else{
  101024. denom = pp - sqrt(denom);
  101025. if(denom>-(EPSILON))denom=-(EPSILON);
  101026. }
  101027. delta = m*p/denom;
  101028. newx -= delta;
  101029. if(delta<0.f)delta*=-1;
  101030. if(fabs(delta/newx)<10e-12)break;
  101031. lastdelta=delta;
  101032. }
  101033. r[m-1]=newx;
  101034. for(i=m;i>0;i--)
  101035. defl[i-1]+=newx*defl[i];
  101036. defl++;
  101037. }
  101038. return(0);
  101039. }
  101040. static int Newton_Raphson(float *a,int ord,float *r){
  101041. int i, k, count=0;
  101042. double error=1.f;
  101043. double *root=(double*)alloca(ord*sizeof(*root));
  101044. for(i=0; i<ord;i++) root[i] = r[i];
  101045. while(error>1e-20){
  101046. error=0;
  101047. for(i=0; i<ord; i++) { /* Update each point. */
  101048. double pp=0.,delta;
  101049. double rooti=root[i];
  101050. double p=a[ord];
  101051. for(k=ord-1; k>= 0; k--) {
  101052. pp= pp* rooti + p;
  101053. p = p * rooti + a[k];
  101054. }
  101055. delta = p/pp;
  101056. root[i] -= delta;
  101057. error+= delta*delta;
  101058. }
  101059. if(count>40)return(-1);
  101060. count++;
  101061. }
  101062. for(i=0; i<ord;i++) r[i] = root[i];
  101063. return(0);
  101064. }
  101065. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101066. int order2=(m+1)>>1;
  101067. int g1_order,g2_order;
  101068. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101069. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101070. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101071. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101072. int i;
  101073. g1_order=(m+1)>>1;
  101074. g2_order=(m) >>1;
  101075. g1[g1_order] = 1.f;
  101076. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101077. g2[g2_order] = 1.f;
  101078. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101079. if(g1_order>g2_order){
  101080. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101081. }else{
  101082. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101083. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101084. }
  101085. cheby(g1,g1_order);
  101086. cheby(g2,g2_order);
  101087. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101088. Laguerre_With_Deflation(g2,g2_order,g2r))
  101089. return(-1);
  101090. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101091. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101092. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101093. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101094. for(i=0;i<g1_order;i++)
  101095. lsp[i*2] = acos(g1r[i]);
  101096. for(i=0;i<g2_order;i++)
  101097. lsp[i*2+1] = acos(g2r[i]);
  101098. return(0);
  101099. }
  101100. #endif
  101101. /*** End of inlined file: lsp.c ***/
  101102. /*** Start of inlined file: mapping0.c ***/
  101103. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101104. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101105. // tasks..
  101106. #if JUCE_MSVC
  101107. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101108. #endif
  101109. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101110. #if JUCE_USE_OGGVORBIS
  101111. #include <stdlib.h>
  101112. #include <stdio.h>
  101113. #include <string.h>
  101114. #include <math.h>
  101115. static void mapping0_free_info(vorbis_info_mapping *i){
  101116. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101117. if(info){
  101118. memset(info,0,sizeof(*info));
  101119. _ogg_free(info);
  101120. }
  101121. }
  101122. static int ilog3(unsigned int v){
  101123. int ret=0;
  101124. if(v)--v;
  101125. while(v){
  101126. ret++;
  101127. v>>=1;
  101128. }
  101129. return(ret);
  101130. }
  101131. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101132. oggpack_buffer *opb){
  101133. int i;
  101134. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101135. if(info->submaps>1){
  101136. oggpack_write(opb,1,1);
  101137. oggpack_write(opb,info->submaps-1,4);
  101138. }else
  101139. oggpack_write(opb,0,1);
  101140. if(info->coupling_steps>0){
  101141. oggpack_write(opb,1,1);
  101142. oggpack_write(opb,info->coupling_steps-1,8);
  101143. for(i=0;i<info->coupling_steps;i++){
  101144. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101145. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101146. }
  101147. }else
  101148. oggpack_write(opb,0,1);
  101149. oggpack_write(opb,0,2); /* 2,3:reserved */
  101150. if(info->submaps>1){
  101151. for(i=0;i<vi->channels;i++)
  101152. oggpack_write(opb,info->chmuxlist[i],4);
  101153. }
  101154. for(i=0;i<info->submaps;i++){
  101155. oggpack_write(opb,0,8); /* time submap unused */
  101156. oggpack_write(opb,info->floorsubmap[i],8);
  101157. oggpack_write(opb,info->residuesubmap[i],8);
  101158. }
  101159. }
  101160. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101161. int i;
  101162. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101163. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101164. memset(info,0,sizeof(*info));
  101165. if(oggpack_read(opb,1))
  101166. info->submaps=oggpack_read(opb,4)+1;
  101167. else
  101168. info->submaps=1;
  101169. if(oggpack_read(opb,1)){
  101170. info->coupling_steps=oggpack_read(opb,8)+1;
  101171. for(i=0;i<info->coupling_steps;i++){
  101172. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101173. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101174. if(testM<0 ||
  101175. testA<0 ||
  101176. testM==testA ||
  101177. testM>=vi->channels ||
  101178. testA>=vi->channels) goto err_out;
  101179. }
  101180. }
  101181. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101182. if(info->submaps>1){
  101183. for(i=0;i<vi->channels;i++){
  101184. info->chmuxlist[i]=oggpack_read(opb,4);
  101185. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101186. }
  101187. }
  101188. for(i=0;i<info->submaps;i++){
  101189. oggpack_read(opb,8); /* time submap unused */
  101190. info->floorsubmap[i]=oggpack_read(opb,8);
  101191. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101192. info->residuesubmap[i]=oggpack_read(opb,8);
  101193. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101194. }
  101195. return info;
  101196. err_out:
  101197. mapping0_free_info(info);
  101198. return(NULL);
  101199. }
  101200. #if 0
  101201. static long seq=0;
  101202. static ogg_int64_t total=0;
  101203. static float FLOOR1_fromdB_LOOKUP[256]={
  101204. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101205. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101206. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101207. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101208. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101209. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101210. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101211. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101212. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101213. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101214. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101215. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101216. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101217. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101218. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101219. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101220. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101221. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101222. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101223. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101224. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101225. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101226. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101227. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101228. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101229. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101230. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101231. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101232. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101233. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101234. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101235. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101236. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101237. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101238. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101239. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101240. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101241. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101242. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101243. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101244. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101245. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101246. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101247. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101248. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101249. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101250. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101251. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101252. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101253. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101254. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101255. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101256. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101257. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101258. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101259. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101260. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101261. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101262. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101263. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101264. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101265. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101266. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101267. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101268. };
  101269. #endif
  101270. extern int *floor1_fit(vorbis_block *vb,void *look,
  101271. const float *logmdct, /* in */
  101272. const float *logmask);
  101273. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101274. int *A,int *B,
  101275. int del);
  101276. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101277. void*look,
  101278. int *post,int *ilogmask);
  101279. static int mapping0_forward(vorbis_block *vb){
  101280. vorbis_dsp_state *vd=vb->vd;
  101281. vorbis_info *vi=vd->vi;
  101282. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101283. private_state *b=(private_state*)vb->vd->backend_state;
  101284. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101285. int n=vb->pcmend;
  101286. int i,j,k;
  101287. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101288. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101289. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101290. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101291. float global_ampmax=vbi->ampmax;
  101292. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101293. int blocktype=vbi->blocktype;
  101294. int modenumber=vb->W;
  101295. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101296. vorbis_look_psy *psy_look=
  101297. b->psy+blocktype+(vb->W?2:0);
  101298. vb->mode=modenumber;
  101299. for(i=0;i<vi->channels;i++){
  101300. float scale=4.f/n;
  101301. float scale_dB;
  101302. float *pcm =vb->pcm[i];
  101303. float *logfft =pcm;
  101304. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101305. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101306. todB estimation used on IEEE 754
  101307. compliant machines had a bug that
  101308. returned dB values about a third
  101309. of a decibel too high. The bug
  101310. was harmless because tunings
  101311. implicitly took that into
  101312. account. However, fixing the bug
  101313. in the estimator requires
  101314. changing all the tunings as well.
  101315. For now, it's easier to sync
  101316. things back up here, and
  101317. recalibrate the tunings in the
  101318. next major model upgrade. */
  101319. #if 0
  101320. if(vi->channels==2)
  101321. if(i==0)
  101322. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101323. else
  101324. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101325. #endif
  101326. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101327. #if 0
  101328. if(vi->channels==2)
  101329. if(i==0)
  101330. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101331. else
  101332. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101333. #endif
  101334. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101335. drft_forward(&b->fft_look[vb->W],pcm);
  101336. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101337. original todB estimation used on
  101338. IEEE 754 compliant machines had a
  101339. bug that returned dB values about
  101340. a third of a decibel too high.
  101341. The bug was harmless because
  101342. tunings implicitly took that into
  101343. account. However, fixing the bug
  101344. in the estimator requires
  101345. changing all the tunings as well.
  101346. For now, it's easier to sync
  101347. things back up here, and
  101348. recalibrate the tunings in the
  101349. next major model upgrade. */
  101350. local_ampmax[i]=logfft[0];
  101351. for(j=1;j<n-1;j+=2){
  101352. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101353. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101354. .345 is a hack; the original todB
  101355. estimation used on IEEE 754
  101356. compliant machines had a bug that
  101357. returned dB values about a third
  101358. of a decibel too high. The bug
  101359. was harmless because tunings
  101360. implicitly took that into
  101361. account. However, fixing the bug
  101362. in the estimator requires
  101363. changing all the tunings as well.
  101364. For now, it's easier to sync
  101365. things back up here, and
  101366. recalibrate the tunings in the
  101367. next major model upgrade. */
  101368. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101369. }
  101370. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101371. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101372. #if 0
  101373. if(vi->channels==2){
  101374. if(i==0){
  101375. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101376. }else{
  101377. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101378. }
  101379. }
  101380. #endif
  101381. }
  101382. {
  101383. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101384. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101385. for(i=0;i<vi->channels;i++){
  101386. int submap=info->chmuxlist[i];
  101387. float *mdct =gmdct[i];
  101388. float *logfft =vb->pcm[i];
  101389. float *logmdct =logfft+n/2;
  101390. float *logmask =logfft;
  101391. vb->mode=modenumber;
  101392. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101393. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101394. for(j=0;j<n/2;j++)
  101395. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101396. todB estimation used on IEEE 754
  101397. compliant machines had a bug that
  101398. returned dB values about a third
  101399. of a decibel too high. The bug
  101400. was harmless because tunings
  101401. implicitly took that into
  101402. account. However, fixing the bug
  101403. in the estimator requires
  101404. changing all the tunings as well.
  101405. For now, it's easier to sync
  101406. things back up here, and
  101407. recalibrate the tunings in the
  101408. next major model upgrade. */
  101409. #if 0
  101410. if(vi->channels==2){
  101411. if(i==0)
  101412. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101413. else
  101414. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101415. }else{
  101416. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101417. }
  101418. #endif
  101419. _vp_noisemask(psy_look,
  101420. logmdct,
  101421. noise); /* noise does not have by-frequency offset
  101422. bias applied yet */
  101423. #if 0
  101424. if(vi->channels==2){
  101425. if(i==0)
  101426. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101427. else
  101428. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101429. }
  101430. #endif
  101431. _vp_tonemask(psy_look,
  101432. logfft,
  101433. tone,
  101434. global_ampmax,
  101435. local_ampmax[i]);
  101436. #if 0
  101437. if(vi->channels==2){
  101438. if(i==0)
  101439. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101440. else
  101441. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101442. }
  101443. #endif
  101444. #if 0
  101445. {
  101446. float aotuv[psy_look->n];
  101447. #endif
  101448. _vp_offset_and_mix(psy_look,
  101449. noise,
  101450. tone,
  101451. 1,
  101452. logmask,
  101453. mdct,
  101454. logmdct);
  101455. #if 0
  101456. if(vi->channels==2){
  101457. if(i==0)
  101458. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101459. else
  101460. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101461. }
  101462. }
  101463. #endif
  101464. #if 0
  101465. if(vi->channels==2){
  101466. if(i==0)
  101467. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101468. else
  101469. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101470. }
  101471. #endif
  101472. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101473. floor_posts[i][PACKETBLOBS/2]=
  101474. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101475. logmdct,
  101476. logmask);
  101477. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101478. _vp_offset_and_mix(psy_look,
  101479. noise,
  101480. tone,
  101481. 2,
  101482. logmask,
  101483. mdct,
  101484. logmdct);
  101485. #if 0
  101486. if(vi->channels==2){
  101487. if(i==0)
  101488. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101489. else
  101490. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101491. }
  101492. #endif
  101493. floor_posts[i][PACKETBLOBS-1]=
  101494. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101495. logmdct,
  101496. logmask);
  101497. _vp_offset_and_mix(psy_look,
  101498. noise,
  101499. tone,
  101500. 0,
  101501. logmask,
  101502. mdct,
  101503. logmdct);
  101504. #if 0
  101505. if(vi->channels==2)
  101506. if(i==0)
  101507. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101508. else
  101509. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101510. #endif
  101511. floor_posts[i][0]=
  101512. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101513. logmdct,
  101514. logmask);
  101515. for(k=1;k<PACKETBLOBS/2;k++)
  101516. floor_posts[i][k]=
  101517. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101518. floor_posts[i][0],
  101519. floor_posts[i][PACKETBLOBS/2],
  101520. k*65536/(PACKETBLOBS/2));
  101521. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101522. floor_posts[i][k]=
  101523. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101524. floor_posts[i][PACKETBLOBS/2],
  101525. floor_posts[i][PACKETBLOBS-1],
  101526. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101527. }
  101528. }
  101529. }
  101530. vbi->ampmax=global_ampmax;
  101531. {
  101532. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101533. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101534. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101535. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101536. float **mag_memo;
  101537. int **mag_sort;
  101538. if(info->coupling_steps){
  101539. mag_memo=_vp_quantize_couple_memo(vb,
  101540. &ci->psy_g_param,
  101541. psy_look,
  101542. info,
  101543. gmdct);
  101544. mag_sort=_vp_quantize_couple_sort(vb,
  101545. psy_look,
  101546. info,
  101547. mag_memo);
  101548. hf_reduction(&ci->psy_g_param,
  101549. psy_look,
  101550. info,
  101551. mag_memo);
  101552. }
  101553. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101554. if(psy_look->vi->normal_channel_p){
  101555. for(i=0;i<vi->channels;i++){
  101556. float *mdct =gmdct[i];
  101557. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101558. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101559. }
  101560. }
  101561. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101562. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101563. k++){
  101564. oggpack_buffer *opb=vbi->packetblob[k];
  101565. oggpack_write(opb,0,1);
  101566. oggpack_write(opb,modenumber,b->modebits);
  101567. if(vb->W){
  101568. oggpack_write(opb,vb->lW,1);
  101569. oggpack_write(opb,vb->nW,1);
  101570. }
  101571. for(i=0;i<vi->channels;i++){
  101572. int submap=info->chmuxlist[i];
  101573. float *mdct =gmdct[i];
  101574. float *res =vb->pcm[i];
  101575. int *ilogmask=ilogmaskch[i]=
  101576. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101577. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101578. floor_posts[i][k],
  101579. ilogmask);
  101580. #if 0
  101581. {
  101582. char buf[80];
  101583. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101584. float work[n/2];
  101585. for(j=0;j<n/2;j++)
  101586. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101587. _analysis_output(buf,seq,work,n/2,1,1,0);
  101588. }
  101589. #endif
  101590. _vp_remove_floor(psy_look,
  101591. mdct,
  101592. ilogmask,
  101593. res,
  101594. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101595. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101596. #if 0
  101597. {
  101598. char buf[80];
  101599. float work[n/2];
  101600. for(j=0;j<n/2;j++)
  101601. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101602. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101603. _analysis_output(buf,seq,work,n/2,1,1,0);
  101604. }
  101605. #endif
  101606. }
  101607. if(info->coupling_steps){
  101608. _vp_couple(k,
  101609. &ci->psy_g_param,
  101610. psy_look,
  101611. info,
  101612. vb->pcm,
  101613. mag_memo,
  101614. mag_sort,
  101615. ilogmaskch,
  101616. nonzero,
  101617. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101618. }
  101619. for(i=0;i<info->submaps;i++){
  101620. int ch_in_bundle=0;
  101621. long **classifications;
  101622. int resnum=info->residuesubmap[i];
  101623. for(j=0;j<vi->channels;j++){
  101624. if(info->chmuxlist[j]==i){
  101625. zerobundle[ch_in_bundle]=0;
  101626. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101627. res_bundle[ch_in_bundle]=vb->pcm[j];
  101628. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101629. }
  101630. }
  101631. classifications=_residue_P[ci->residue_type[resnum]]->
  101632. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101633. _residue_P[ci->residue_type[resnum]]->
  101634. forward(opb,vb,b->residue[resnum],
  101635. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101636. }
  101637. }
  101638. }
  101639. #if 0
  101640. seq++;
  101641. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101642. #endif
  101643. return(0);
  101644. }
  101645. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101646. vorbis_dsp_state *vd=vb->vd;
  101647. vorbis_info *vi=vd->vi;
  101648. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101649. private_state *b=(private_state*)vd->backend_state;
  101650. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101651. int i,j;
  101652. long n=vb->pcmend=ci->blocksizes[vb->W];
  101653. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101654. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101655. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101656. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101657. for(i=0;i<vi->channels;i++){
  101658. int submap=info->chmuxlist[i];
  101659. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101660. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101661. if(floormemo[i])
  101662. nonzero[i]=1;
  101663. else
  101664. nonzero[i]=0;
  101665. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101666. }
  101667. for(i=0;i<info->coupling_steps;i++){
  101668. if(nonzero[info->coupling_mag[i]] ||
  101669. nonzero[info->coupling_ang[i]]){
  101670. nonzero[info->coupling_mag[i]]=1;
  101671. nonzero[info->coupling_ang[i]]=1;
  101672. }
  101673. }
  101674. for(i=0;i<info->submaps;i++){
  101675. int ch_in_bundle=0;
  101676. for(j=0;j<vi->channels;j++){
  101677. if(info->chmuxlist[j]==i){
  101678. if(nonzero[j])
  101679. zerobundle[ch_in_bundle]=1;
  101680. else
  101681. zerobundle[ch_in_bundle]=0;
  101682. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101683. }
  101684. }
  101685. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101686. inverse(vb,b->residue[info->residuesubmap[i]],
  101687. pcmbundle,zerobundle,ch_in_bundle);
  101688. }
  101689. for(i=info->coupling_steps-1;i>=0;i--){
  101690. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101691. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101692. for(j=0;j<n/2;j++){
  101693. float mag=pcmM[j];
  101694. float ang=pcmA[j];
  101695. if(mag>0)
  101696. if(ang>0){
  101697. pcmM[j]=mag;
  101698. pcmA[j]=mag-ang;
  101699. }else{
  101700. pcmA[j]=mag;
  101701. pcmM[j]=mag+ang;
  101702. }
  101703. else
  101704. if(ang>0){
  101705. pcmM[j]=mag;
  101706. pcmA[j]=mag+ang;
  101707. }else{
  101708. pcmA[j]=mag;
  101709. pcmM[j]=mag-ang;
  101710. }
  101711. }
  101712. }
  101713. for(i=0;i<vi->channels;i++){
  101714. float *pcm=vb->pcm[i];
  101715. int submap=info->chmuxlist[i];
  101716. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101717. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101718. floormemo[i],pcm);
  101719. }
  101720. for(i=0;i<vi->channels;i++){
  101721. float *pcm=vb->pcm[i];
  101722. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101723. }
  101724. return(0);
  101725. }
  101726. vorbis_func_mapping mapping0_exportbundle={
  101727. &mapping0_pack,
  101728. &mapping0_unpack,
  101729. &mapping0_free_info,
  101730. &mapping0_forward,
  101731. &mapping0_inverse
  101732. };
  101733. #endif
  101734. /*** End of inlined file: mapping0.c ***/
  101735. /*** Start of inlined file: mdct.c ***/
  101736. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101737. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101738. // tasks..
  101739. #if JUCE_MSVC
  101740. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101741. #endif
  101742. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101743. #if JUCE_USE_OGGVORBIS
  101744. #include <stdio.h>
  101745. #include <stdlib.h>
  101746. #include <string.h>
  101747. #include <math.h>
  101748. void mdct_init(mdct_lookup *lookup,int n){
  101749. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101750. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101751. int i;
  101752. int n2=n>>1;
  101753. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101754. lookup->n=n;
  101755. lookup->trig=T;
  101756. lookup->bitrev=bitrev;
  101757. for(i=0;i<n/4;i++){
  101758. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101759. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101760. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101761. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101762. }
  101763. for(i=0;i<n/8;i++){
  101764. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101765. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101766. }
  101767. {
  101768. int mask=(1<<(log2n-1))-1,i,j;
  101769. int msb=1<<(log2n-2);
  101770. for(i=0;i<n/8;i++){
  101771. int acc=0;
  101772. for(j=0;msb>>j;j++)
  101773. if((msb>>j)&i)acc|=1<<j;
  101774. bitrev[i*2]=((~acc)&mask)-1;
  101775. bitrev[i*2+1]=acc;
  101776. }
  101777. }
  101778. lookup->scale=FLOAT_CONV(4.f/n);
  101779. }
  101780. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101781. REG_TYPE r0 = x[6] + x[2];
  101782. REG_TYPE r1 = x[6] - x[2];
  101783. REG_TYPE r2 = x[4] + x[0];
  101784. REG_TYPE r3 = x[4] - x[0];
  101785. x[6] = r0 + r2;
  101786. x[4] = r0 - r2;
  101787. r0 = x[5] - x[1];
  101788. r2 = x[7] - x[3];
  101789. x[0] = r1 + r0;
  101790. x[2] = r1 - r0;
  101791. r0 = x[5] + x[1];
  101792. r1 = x[7] + x[3];
  101793. x[3] = r2 + r3;
  101794. x[1] = r2 - r3;
  101795. x[7] = r1 + r0;
  101796. x[5] = r1 - r0;
  101797. }
  101798. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101799. REG_TYPE r0 = x[1] - x[9];
  101800. REG_TYPE r1 = x[0] - x[8];
  101801. x[8] += x[0];
  101802. x[9] += x[1];
  101803. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101804. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101805. r0 = x[3] - x[11];
  101806. r1 = x[10] - x[2];
  101807. x[10] += x[2];
  101808. x[11] += x[3];
  101809. x[2] = r0;
  101810. x[3] = r1;
  101811. r0 = x[12] - x[4];
  101812. r1 = x[13] - x[5];
  101813. x[12] += x[4];
  101814. x[13] += x[5];
  101815. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101816. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101817. r0 = x[14] - x[6];
  101818. r1 = x[15] - x[7];
  101819. x[14] += x[6];
  101820. x[15] += x[7];
  101821. x[6] = r0;
  101822. x[7] = r1;
  101823. mdct_butterfly_8(x);
  101824. mdct_butterfly_8(x+8);
  101825. }
  101826. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101827. REG_TYPE r0 = x[30] - x[14];
  101828. REG_TYPE r1 = x[31] - x[15];
  101829. x[30] += x[14];
  101830. x[31] += x[15];
  101831. x[14] = r0;
  101832. x[15] = r1;
  101833. r0 = x[28] - x[12];
  101834. r1 = x[29] - x[13];
  101835. x[28] += x[12];
  101836. x[29] += x[13];
  101837. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101838. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101839. r0 = x[26] - x[10];
  101840. r1 = x[27] - x[11];
  101841. x[26] += x[10];
  101842. x[27] += x[11];
  101843. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101844. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101845. r0 = x[24] - x[8];
  101846. r1 = x[25] - x[9];
  101847. x[24] += x[8];
  101848. x[25] += x[9];
  101849. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101850. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101851. r0 = x[22] - x[6];
  101852. r1 = x[7] - x[23];
  101853. x[22] += x[6];
  101854. x[23] += x[7];
  101855. x[6] = r1;
  101856. x[7] = r0;
  101857. r0 = x[4] - x[20];
  101858. r1 = x[5] - x[21];
  101859. x[20] += x[4];
  101860. x[21] += x[5];
  101861. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101862. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101863. r0 = x[2] - x[18];
  101864. r1 = x[3] - x[19];
  101865. x[18] += x[2];
  101866. x[19] += x[3];
  101867. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101868. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101869. r0 = x[0] - x[16];
  101870. r1 = x[1] - x[17];
  101871. x[16] += x[0];
  101872. x[17] += x[1];
  101873. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101874. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101875. mdct_butterfly_16(x);
  101876. mdct_butterfly_16(x+16);
  101877. }
  101878. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101879. DATA_TYPE *x,
  101880. int points){
  101881. DATA_TYPE *x1 = x + points - 8;
  101882. DATA_TYPE *x2 = x + (points>>1) - 8;
  101883. REG_TYPE r0;
  101884. REG_TYPE r1;
  101885. do{
  101886. r0 = x1[6] - x2[6];
  101887. r1 = x1[7] - x2[7];
  101888. x1[6] += x2[6];
  101889. x1[7] += x2[7];
  101890. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101891. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101892. r0 = x1[4] - x2[4];
  101893. r1 = x1[5] - x2[5];
  101894. x1[4] += x2[4];
  101895. x1[5] += x2[5];
  101896. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101897. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101898. r0 = x1[2] - x2[2];
  101899. r1 = x1[3] - x2[3];
  101900. x1[2] += x2[2];
  101901. x1[3] += x2[3];
  101902. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101903. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101904. r0 = x1[0] - x2[0];
  101905. r1 = x1[1] - x2[1];
  101906. x1[0] += x2[0];
  101907. x1[1] += x2[1];
  101908. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101909. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101910. x1-=8;
  101911. x2-=8;
  101912. T+=16;
  101913. }while(x2>=x);
  101914. }
  101915. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101916. DATA_TYPE *x,
  101917. int points,
  101918. int trigint){
  101919. DATA_TYPE *x1 = x + points - 8;
  101920. DATA_TYPE *x2 = x + (points>>1) - 8;
  101921. REG_TYPE r0;
  101922. REG_TYPE r1;
  101923. do{
  101924. r0 = x1[6] - x2[6];
  101925. r1 = x1[7] - x2[7];
  101926. x1[6] += x2[6];
  101927. x1[7] += x2[7];
  101928. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101929. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101930. T+=trigint;
  101931. r0 = x1[4] - x2[4];
  101932. r1 = x1[5] - x2[5];
  101933. x1[4] += x2[4];
  101934. x1[5] += x2[5];
  101935. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101936. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101937. T+=trigint;
  101938. r0 = x1[2] - x2[2];
  101939. r1 = x1[3] - x2[3];
  101940. x1[2] += x2[2];
  101941. x1[3] += x2[3];
  101942. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101943. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101944. T+=trigint;
  101945. r0 = x1[0] - x2[0];
  101946. r1 = x1[1] - x2[1];
  101947. x1[0] += x2[0];
  101948. x1[1] += x2[1];
  101949. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101950. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101951. T+=trigint;
  101952. x1-=8;
  101953. x2-=8;
  101954. }while(x2>=x);
  101955. }
  101956. STIN void mdct_butterflies(mdct_lookup *init,
  101957. DATA_TYPE *x,
  101958. int points){
  101959. DATA_TYPE *T=init->trig;
  101960. int stages=init->log2n-5;
  101961. int i,j;
  101962. if(--stages>0){
  101963. mdct_butterfly_first(T,x,points);
  101964. }
  101965. for(i=1;--stages>0;i++){
  101966. for(j=0;j<(1<<i);j++)
  101967. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  101968. }
  101969. for(j=0;j<points;j+=32)
  101970. mdct_butterfly_32(x+j);
  101971. }
  101972. void mdct_clear(mdct_lookup *l){
  101973. if(l){
  101974. if(l->trig)_ogg_free(l->trig);
  101975. if(l->bitrev)_ogg_free(l->bitrev);
  101976. memset(l,0,sizeof(*l));
  101977. }
  101978. }
  101979. STIN void mdct_bitreverse(mdct_lookup *init,
  101980. DATA_TYPE *x){
  101981. int n = init->n;
  101982. int *bit = init->bitrev;
  101983. DATA_TYPE *w0 = x;
  101984. DATA_TYPE *w1 = x = w0+(n>>1);
  101985. DATA_TYPE *T = init->trig+n;
  101986. do{
  101987. DATA_TYPE *x0 = x+bit[0];
  101988. DATA_TYPE *x1 = x+bit[1];
  101989. REG_TYPE r0 = x0[1] - x1[1];
  101990. REG_TYPE r1 = x0[0] + x1[0];
  101991. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  101992. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  101993. w1 -= 4;
  101994. r0 = HALVE(x0[1] + x1[1]);
  101995. r1 = HALVE(x0[0] - x1[0]);
  101996. w0[0] = r0 + r2;
  101997. w1[2] = r0 - r2;
  101998. w0[1] = r1 + r3;
  101999. w1[3] = r3 - r1;
  102000. x0 = x+bit[2];
  102001. x1 = x+bit[3];
  102002. r0 = x0[1] - x1[1];
  102003. r1 = x0[0] + x1[0];
  102004. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102005. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102006. r0 = HALVE(x0[1] + x1[1]);
  102007. r1 = HALVE(x0[0] - x1[0]);
  102008. w0[2] = r0 + r2;
  102009. w1[0] = r0 - r2;
  102010. w0[3] = r1 + r3;
  102011. w1[1] = r3 - r1;
  102012. T += 4;
  102013. bit += 4;
  102014. w0 += 4;
  102015. }while(w0<w1);
  102016. }
  102017. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102018. int n=init->n;
  102019. int n2=n>>1;
  102020. int n4=n>>2;
  102021. DATA_TYPE *iX = in+n2-7;
  102022. DATA_TYPE *oX = out+n2+n4;
  102023. DATA_TYPE *T = init->trig+n4;
  102024. do{
  102025. oX -= 4;
  102026. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102027. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102028. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102029. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102030. iX -= 8;
  102031. T += 4;
  102032. }while(iX>=in);
  102033. iX = in+n2-8;
  102034. oX = out+n2+n4;
  102035. T = init->trig+n4;
  102036. do{
  102037. T -= 4;
  102038. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102039. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102040. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102041. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102042. iX -= 8;
  102043. oX += 4;
  102044. }while(iX>=in);
  102045. mdct_butterflies(init,out+n2,n2);
  102046. mdct_bitreverse(init,out);
  102047. {
  102048. DATA_TYPE *oX1=out+n2+n4;
  102049. DATA_TYPE *oX2=out+n2+n4;
  102050. DATA_TYPE *iX =out;
  102051. T =init->trig+n2;
  102052. do{
  102053. oX1-=4;
  102054. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102055. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102056. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102057. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102058. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102059. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102060. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102061. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102062. oX2+=4;
  102063. iX += 8;
  102064. T += 8;
  102065. }while(iX<oX1);
  102066. iX=out+n2+n4;
  102067. oX1=out+n4;
  102068. oX2=oX1;
  102069. do{
  102070. oX1-=4;
  102071. iX-=4;
  102072. oX2[0] = -(oX1[3] = iX[3]);
  102073. oX2[1] = -(oX1[2] = iX[2]);
  102074. oX2[2] = -(oX1[1] = iX[1]);
  102075. oX2[3] = -(oX1[0] = iX[0]);
  102076. oX2+=4;
  102077. }while(oX2<iX);
  102078. iX=out+n2+n4;
  102079. oX1=out+n2+n4;
  102080. oX2=out+n2;
  102081. do{
  102082. oX1-=4;
  102083. oX1[0]= iX[3];
  102084. oX1[1]= iX[2];
  102085. oX1[2]= iX[1];
  102086. oX1[3]= iX[0];
  102087. iX+=4;
  102088. }while(oX1>oX2);
  102089. }
  102090. }
  102091. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102092. int n=init->n;
  102093. int n2=n>>1;
  102094. int n4=n>>2;
  102095. int n8=n>>3;
  102096. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102097. DATA_TYPE *w2=w+n2;
  102098. REG_TYPE r0;
  102099. REG_TYPE r1;
  102100. DATA_TYPE *x0=in+n2+n4;
  102101. DATA_TYPE *x1=x0+1;
  102102. DATA_TYPE *T=init->trig+n2;
  102103. int i=0;
  102104. for(i=0;i<n8;i+=2){
  102105. x0 -=4;
  102106. T-=2;
  102107. r0= x0[2] + x1[0];
  102108. r1= x0[0] + x1[2];
  102109. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102110. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102111. x1 +=4;
  102112. }
  102113. x1=in+1;
  102114. for(;i<n2-n8;i+=2){
  102115. T-=2;
  102116. x0 -=4;
  102117. r0= x0[2] - x1[0];
  102118. r1= x0[0] - x1[2];
  102119. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102120. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102121. x1 +=4;
  102122. }
  102123. x0=in+n;
  102124. for(;i<n2;i+=2){
  102125. T-=2;
  102126. x0 -=4;
  102127. r0= -x0[2] - x1[0];
  102128. r1= -x0[0] - x1[2];
  102129. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102130. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102131. x1 +=4;
  102132. }
  102133. mdct_butterflies(init,w+n2,n2);
  102134. mdct_bitreverse(init,w);
  102135. T=init->trig+n2;
  102136. x0=out+n2;
  102137. for(i=0;i<n4;i++){
  102138. x0--;
  102139. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102140. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102141. w+=2;
  102142. T+=2;
  102143. }
  102144. }
  102145. #endif
  102146. /*** End of inlined file: mdct.c ***/
  102147. /*** Start of inlined file: psy.c ***/
  102148. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102149. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102150. // tasks..
  102151. #if JUCE_MSVC
  102152. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102153. #endif
  102154. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102155. #if JUCE_USE_OGGVORBIS
  102156. #include <stdlib.h>
  102157. #include <math.h>
  102158. #include <string.h>
  102159. /*** Start of inlined file: masking.h ***/
  102160. #ifndef _V_MASKING_H_
  102161. #define _V_MASKING_H_
  102162. #define MAX_ATH 88
  102163. static float ATH[]={
  102164. -51, -52, -53, -54, -55, -56, -57, -58,
  102165. -59, -60, -61, -62, -63, -64, -65, -66,
  102166. -67, -68, -69, -70, -71, -72, -73, -74,
  102167. -75, -76, -77, -78, -80, -81, -82, -83,
  102168. -84, -85, -86, -87, -88, -88, -89, -89,
  102169. -90, -91, -91, -92, -93, -94, -95, -96,
  102170. -96, -97, -98, -98, -99, -99,-100,-100,
  102171. -101,-102,-103,-104,-106,-107,-107,-107,
  102172. -107,-105,-103,-102,-101, -99, -98, -96,
  102173. -95, -95, -96, -97, -96, -95, -93, -90,
  102174. -80, -70, -50, -40, -30, -30, -30, -30
  102175. };
  102176. #define EHMER_OFFSET 16
  102177. #define EHMER_MAX 56
  102178. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102179. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102180. -60, -60, -60, -60, -62, -62, -65, -73,
  102181. -69, -68, -68, -67, -70, -70, -72, -74,
  102182. -75, -79, -79, -80, -83, -88, -93, -100,
  102183. -110, -999, -999, -999, -999, -999, -999, -999,
  102184. -999, -999, -999, -999, -999, -999, -999, -999,
  102185. -999, -999, -999, -999, -999, -999, -999, -999},
  102186. { -48, -48, -48, -48, -48, -48, -48, -48,
  102187. -48, -48, -48, -48, -48, -53, -61, -66,
  102188. -66, -68, -67, -70, -76, -76, -72, -73,
  102189. -75, -76, -78, -79, -83, -88, -93, -100,
  102190. -110, -999, -999, -999, -999, -999, -999, -999,
  102191. -999, -999, -999, -999, -999, -999, -999, -999,
  102192. -999, -999, -999, -999, -999, -999, -999, -999},
  102193. { -37, -37, -37, -37, -37, -37, -37, -37,
  102194. -38, -40, -42, -46, -48, -53, -55, -62,
  102195. -65, -58, -56, -56, -61, -60, -65, -67,
  102196. -69, -71, -77, -77, -78, -80, -82, -84,
  102197. -88, -93, -98, -106, -112, -999, -999, -999,
  102198. -999, -999, -999, -999, -999, -999, -999, -999,
  102199. -999, -999, -999, -999, -999, -999, -999, -999},
  102200. { -25, -25, -25, -25, -25, -25, -25, -25,
  102201. -25, -26, -27, -29, -32, -38, -48, -52,
  102202. -52, -50, -48, -48, -51, -52, -54, -60,
  102203. -67, -67, -66, -68, -69, -73, -73, -76,
  102204. -80, -81, -81, -85, -85, -86, -88, -93,
  102205. -100, -110, -999, -999, -999, -999, -999, -999,
  102206. -999, -999, -999, -999, -999, -999, -999, -999},
  102207. { -16, -16, -16, -16, -16, -16, -16, -16,
  102208. -17, -19, -20, -22, -26, -28, -31, -40,
  102209. -47, -39, -39, -40, -42, -43, -47, -51,
  102210. -57, -52, -55, -55, -60, -58, -62, -63,
  102211. -70, -67, -69, -72, -73, -77, -80, -82,
  102212. -83, -87, -90, -94, -98, -104, -115, -999,
  102213. -999, -999, -999, -999, -999, -999, -999, -999},
  102214. { -8, -8, -8, -8, -8, -8, -8, -8,
  102215. -8, -8, -10, -11, -15, -19, -25, -30,
  102216. -34, -31, -30, -31, -29, -32, -35, -42,
  102217. -48, -42, -44, -46, -50, -50, -51, -52,
  102218. -59, -54, -55, -55, -58, -62, -63, -66,
  102219. -72, -73, -76, -75, -78, -80, -80, -81,
  102220. -84, -88, -90, -94, -98, -101, -106, -110}},
  102221. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102222. -66, -66, -66, -66, -66, -67, -67, -67,
  102223. -76, -72, -71, -74, -76, -76, -75, -78,
  102224. -79, -79, -81, -83, -86, -89, -93, -97,
  102225. -100, -105, -110, -999, -999, -999, -999, -999,
  102226. -999, -999, -999, -999, -999, -999, -999, -999,
  102227. -999, -999, -999, -999, -999, -999, -999, -999},
  102228. { -47, -47, -47, -47, -47, -47, -47, -47,
  102229. -47, -47, -47, -48, -51, -55, -59, -66,
  102230. -66, -66, -67, -66, -68, -69, -70, -74,
  102231. -79, -77, -77, -78, -80, -81, -82, -84,
  102232. -86, -88, -91, -95, -100, -108, -116, -999,
  102233. -999, -999, -999, -999, -999, -999, -999, -999,
  102234. -999, -999, -999, -999, -999, -999, -999, -999},
  102235. { -36, -36, -36, -36, -36, -36, -36, -36,
  102236. -36, -37, -37, -41, -44, -48, -51, -58,
  102237. -62, -60, -57, -59, -59, -60, -63, -65,
  102238. -72, -71, -70, -72, -74, -77, -76, -78,
  102239. -81, -81, -80, -83, -86, -91, -96, -100,
  102240. -105, -110, -999, -999, -999, -999, -999, -999,
  102241. -999, -999, -999, -999, -999, -999, -999, -999},
  102242. { -28, -28, -28, -28, -28, -28, -28, -28,
  102243. -28, -30, -32, -32, -33, -35, -41, -49,
  102244. -50, -49, -47, -48, -48, -52, -51, -57,
  102245. -65, -61, -59, -61, -64, -69, -70, -74,
  102246. -77, -77, -78, -81, -84, -85, -87, -90,
  102247. -92, -96, -100, -107, -112, -999, -999, -999,
  102248. -999, -999, -999, -999, -999, -999, -999, -999},
  102249. { -19, -19, -19, -19, -19, -19, -19, -19,
  102250. -20, -21, -23, -27, -30, -35, -36, -41,
  102251. -46, -44, -42, -40, -41, -41, -43, -48,
  102252. -55, -53, -52, -53, -56, -59, -58, -60,
  102253. -67, -66, -69, -71, -72, -75, -79, -81,
  102254. -84, -87, -90, -93, -97, -101, -107, -114,
  102255. -999, -999, -999, -999, -999, -999, -999, -999},
  102256. { -9, -9, -9, -9, -9, -9, -9, -9,
  102257. -11, -12, -12, -15, -16, -20, -23, -30,
  102258. -37, -34, -33, -34, -31, -32, -32, -38,
  102259. -47, -44, -41, -40, -47, -49, -46, -46,
  102260. -58, -50, -50, -54, -58, -62, -64, -67,
  102261. -67, -70, -72, -76, -79, -83, -87, -91,
  102262. -96, -100, -104, -110, -999, -999, -999, -999}},
  102263. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102264. -62, -62, -63, -64, -66, -67, -66, -68,
  102265. -75, -72, -76, -75, -76, -78, -79, -82,
  102266. -84, -85, -90, -94, -101, -110, -999, -999,
  102267. -999, -999, -999, -999, -999, -999, -999, -999,
  102268. -999, -999, -999, -999, -999, -999, -999, -999,
  102269. -999, -999, -999, -999, -999, -999, -999, -999},
  102270. { -59, -59, -59, -59, -59, -59, -59, -59,
  102271. -59, -59, -59, -60, -60, -61, -63, -66,
  102272. -71, -68, -70, -70, -71, -72, -72, -75,
  102273. -81, -78, -79, -82, -83, -86, -90, -97,
  102274. -103, -113, -999, -999, -999, -999, -999, -999,
  102275. -999, -999, -999, -999, -999, -999, -999, -999,
  102276. -999, -999, -999, -999, -999, -999, -999, -999},
  102277. { -53, -53, -53, -53, -53, -53, -53, -53,
  102278. -53, -54, -55, -57, -56, -57, -55, -61,
  102279. -65, -60, -60, -62, -63, -63, -66, -68,
  102280. -74, -73, -75, -75, -78, -80, -80, -82,
  102281. -85, -90, -96, -101, -108, -999, -999, -999,
  102282. -999, -999, -999, -999, -999, -999, -999, -999,
  102283. -999, -999, -999, -999, -999, -999, -999, -999},
  102284. { -46, -46, -46, -46, -46, -46, -46, -46,
  102285. -46, -46, -47, -47, -47, -47, -48, -51,
  102286. -57, -51, -49, -50, -51, -53, -54, -59,
  102287. -66, -60, -62, -67, -67, -70, -72, -75,
  102288. -76, -78, -81, -85, -88, -94, -97, -104,
  102289. -112, -999, -999, -999, -999, -999, -999, -999,
  102290. -999, -999, -999, -999, -999, -999, -999, -999},
  102291. { -36, -36, -36, -36, -36, -36, -36, -36,
  102292. -39, -41, -42, -42, -39, -38, -41, -43,
  102293. -52, -44, -40, -39, -37, -37, -40, -47,
  102294. -54, -50, -48, -50, -55, -61, -59, -62,
  102295. -66, -66, -66, -69, -69, -73, -74, -74,
  102296. -75, -77, -79, -82, -87, -91, -95, -100,
  102297. -108, -115, -999, -999, -999, -999, -999, -999},
  102298. { -28, -26, -24, -22, -20, -20, -23, -29,
  102299. -30, -31, -28, -27, -28, -28, -28, -35,
  102300. -40, -33, -32, -29, -30, -30, -30, -37,
  102301. -45, -41, -37, -38, -45, -47, -47, -48,
  102302. -53, -49, -48, -50, -49, -49, -51, -52,
  102303. -58, -56, -57, -56, -60, -61, -62, -70,
  102304. -72, -74, -78, -83, -88, -93, -100, -106}},
  102305. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102306. -999, -110, -105, -100, -95, -91, -87, -83,
  102307. -80, -78, -76, -78, -78, -81, -83, -85,
  102308. -86, -85, -86, -87, -90, -97, -107, -999,
  102309. -999, -999, -999, -999, -999, -999, -999, -999,
  102310. -999, -999, -999, -999, -999, -999, -999, -999,
  102311. -999, -999, -999, -999, -999, -999, -999, -999},
  102312. {-999, -999, -999, -110, -105, -100, -95, -90,
  102313. -85, -81, -77, -73, -70, -67, -67, -68,
  102314. -75, -73, -70, -69, -70, -72, -75, -79,
  102315. -84, -83, -84, -86, -88, -89, -89, -93,
  102316. -98, -105, -112, -999, -999, -999, -999, -999,
  102317. -999, -999, -999, -999, -999, -999, -999, -999,
  102318. -999, -999, -999, -999, -999, -999, -999, -999},
  102319. {-105, -100, -95, -90, -85, -80, -76, -71,
  102320. -68, -68, -65, -63, -63, -62, -62, -64,
  102321. -65, -64, -61, -62, -63, -64, -66, -68,
  102322. -73, -73, -74, -75, -76, -81, -83, -85,
  102323. -88, -89, -92, -95, -100, -108, -999, -999,
  102324. -999, -999, -999, -999, -999, -999, -999, -999,
  102325. -999, -999, -999, -999, -999, -999, -999, -999},
  102326. { -80, -75, -71, -68, -65, -63, -62, -61,
  102327. -61, -61, -61, -59, -56, -57, -53, -50,
  102328. -58, -52, -50, -50, -52, -53, -54, -58,
  102329. -67, -63, -67, -68, -72, -75, -78, -80,
  102330. -81, -81, -82, -85, -89, -90, -93, -97,
  102331. -101, -107, -114, -999, -999, -999, -999, -999,
  102332. -999, -999, -999, -999, -999, -999, -999, -999},
  102333. { -65, -61, -59, -57, -56, -55, -55, -56,
  102334. -56, -57, -55, -53, -52, -47, -44, -44,
  102335. -50, -44, -41, -39, -39, -42, -40, -46,
  102336. -51, -49, -50, -53, -54, -63, -60, -61,
  102337. -62, -66, -66, -66, -70, -73, -74, -75,
  102338. -76, -75, -79, -85, -89, -91, -96, -102,
  102339. -110, -999, -999, -999, -999, -999, -999, -999},
  102340. { -52, -50, -49, -49, -48, -48, -48, -49,
  102341. -50, -50, -49, -46, -43, -39, -35, -33,
  102342. -38, -36, -32, -29, -32, -32, -32, -35,
  102343. -44, -39, -38, -38, -46, -50, -45, -46,
  102344. -53, -50, -50, -50, -54, -54, -53, -53,
  102345. -56, -57, -59, -66, -70, -72, -74, -79,
  102346. -83, -85, -90, -97, -114, -999, -999, -999}},
  102347. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102348. -100, -95, -90, -86, -80, -75, -75, -79,
  102349. -80, -79, -80, -81, -82, -88, -95, -103,
  102350. -110, -999, -999, -999, -999, -999, -999, -999,
  102351. -999, -999, -999, -999, -999, -999, -999, -999,
  102352. -999, -999, -999, -999, -999, -999, -999, -999,
  102353. -999, -999, -999, -999, -999, -999, -999, -999},
  102354. {-999, -999, -999, -999, -108, -103, -98, -93,
  102355. -88, -83, -79, -78, -75, -71, -67, -68,
  102356. -73, -73, -72, -73, -75, -77, -80, -82,
  102357. -88, -93, -100, -107, -114, -999, -999, -999,
  102358. -999, -999, -999, -999, -999, -999, -999, -999,
  102359. -999, -999, -999, -999, -999, -999, -999, -999,
  102360. -999, -999, -999, -999, -999, -999, -999, -999},
  102361. {-999, -999, -999, -110, -105, -101, -96, -90,
  102362. -86, -81, -77, -73, -69, -66, -61, -62,
  102363. -66, -64, -62, -65, -66, -70, -72, -76,
  102364. -81, -80, -84, -90, -95, -102, -110, -999,
  102365. -999, -999, -999, -999, -999, -999, -999, -999,
  102366. -999, -999, -999, -999, -999, -999, -999, -999,
  102367. -999, -999, -999, -999, -999, -999, -999, -999},
  102368. {-999, -999, -999, -107, -103, -97, -92, -88,
  102369. -83, -79, -74, -70, -66, -59, -53, -58,
  102370. -62, -55, -54, -54, -54, -58, -61, -62,
  102371. -72, -70, -72, -75, -78, -80, -81, -80,
  102372. -83, -83, -88, -93, -100, -107, -115, -999,
  102373. -999, -999, -999, -999, -999, -999, -999, -999,
  102374. -999, -999, -999, -999, -999, -999, -999, -999},
  102375. {-999, -999, -999, -105, -100, -95, -90, -85,
  102376. -80, -75, -70, -66, -62, -56, -48, -44,
  102377. -48, -46, -46, -43, -46, -48, -48, -51,
  102378. -58, -58, -59, -60, -62, -62, -61, -61,
  102379. -65, -64, -65, -68, -70, -74, -75, -78,
  102380. -81, -86, -95, -110, -999, -999, -999, -999,
  102381. -999, -999, -999, -999, -999, -999, -999, -999},
  102382. {-999, -999, -105, -100, -95, -90, -85, -80,
  102383. -75, -70, -65, -61, -55, -49, -39, -33,
  102384. -40, -35, -32, -38, -40, -33, -35, -37,
  102385. -46, -41, -45, -44, -46, -42, -45, -46,
  102386. -52, -50, -50, -50, -54, -54, -55, -57,
  102387. -62, -64, -66, -68, -70, -76, -81, -90,
  102388. -100, -110, -999, -999, -999, -999, -999, -999}},
  102389. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102390. -105, -98, -90, -85, -82, -83, -80, -78,
  102391. -84, -79, -80, -83, -87, -89, -91, -93,
  102392. -99, -106, -117, -999, -999, -999, -999, -999,
  102393. -999, -999, -999, -999, -999, -999, -999, -999,
  102394. -999, -999, -999, -999, -999, -999, -999, -999,
  102395. -999, -999, -999, -999, -999, -999, -999, -999},
  102396. {-999, -999, -999, -999, -999, -999, -999, -999,
  102397. -105, -98, -90, -85, -80, -75, -70, -68,
  102398. -74, -72, -74, -77, -80, -82, -85, -87,
  102399. -92, -89, -91, -95, -100, -106, -112, -999,
  102400. -999, -999, -999, -999, -999, -999, -999, -999,
  102401. -999, -999, -999, -999, -999, -999, -999, -999,
  102402. -999, -999, -999, -999, -999, -999, -999, -999},
  102403. {-999, -999, -999, -999, -999, -999, -999, -999,
  102404. -105, -98, -90, -83, -75, -71, -63, -64,
  102405. -67, -62, -64, -67, -70, -73, -77, -81,
  102406. -84, -83, -85, -89, -90, -93, -98, -104,
  102407. -109, -114, -999, -999, -999, -999, -999, -999,
  102408. -999, -999, -999, -999, -999, -999, -999, -999,
  102409. -999, -999, -999, -999, -999, -999, -999, -999},
  102410. {-999, -999, -999, -999, -999, -999, -999, -999,
  102411. -103, -96, -88, -81, -75, -68, -58, -54,
  102412. -56, -54, -56, -56, -58, -60, -63, -66,
  102413. -74, -69, -72, -72, -75, -74, -77, -81,
  102414. -81, -82, -84, -87, -93, -96, -99, -104,
  102415. -110, -999, -999, -999, -999, -999, -999, -999,
  102416. -999, -999, -999, -999, -999, -999, -999, -999},
  102417. {-999, -999, -999, -999, -999, -108, -102, -96,
  102418. -91, -85, -80, -74, -68, -60, -51, -46,
  102419. -48, -46, -43, -45, -47, -47, -49, -48,
  102420. -56, -53, -55, -58, -57, -63, -58, -60,
  102421. -66, -64, -67, -70, -70, -74, -77, -84,
  102422. -86, -89, -91, -93, -94, -101, -109, -118,
  102423. -999, -999, -999, -999, -999, -999, -999, -999},
  102424. {-999, -999, -999, -108, -103, -98, -93, -88,
  102425. -83, -78, -73, -68, -60, -53, -44, -35,
  102426. -38, -38, -34, -34, -36, -40, -41, -44,
  102427. -51, -45, -46, -47, -46, -54, -50, -49,
  102428. -50, -50, -50, -51, -54, -57, -58, -60,
  102429. -66, -66, -66, -64, -65, -68, -77, -82,
  102430. -87, -95, -110, -999, -999, -999, -999, -999}},
  102431. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102432. -107, -102, -97, -92, -87, -83, -78, -75,
  102433. -82, -79, -83, -85, -89, -92, -95, -98,
  102434. -101, -105, -109, -113, -999, -999, -999, -999,
  102435. -999, -999, -999, -999, -999, -999, -999, -999,
  102436. -999, -999, -999, -999, -999, -999, -999, -999,
  102437. -999, -999, -999, -999, -999, -999, -999, -999},
  102438. {-999, -999, -999, -999, -999, -999, -999, -106,
  102439. -100, -95, -90, -86, -81, -78, -74, -69,
  102440. -74, -74, -76, -79, -83, -84, -86, -89,
  102441. -92, -97, -93, -100, -103, -107, -110, -999,
  102442. -999, -999, -999, -999, -999, -999, -999, -999,
  102443. -999, -999, -999, -999, -999, -999, -999, -999,
  102444. -999, -999, -999, -999, -999, -999, -999, -999},
  102445. {-999, -999, -999, -999, -999, -999, -106, -100,
  102446. -95, -90, -87, -83, -80, -75, -69, -60,
  102447. -66, -66, -68, -70, -74, -78, -79, -81,
  102448. -81, -83, -84, -87, -93, -96, -99, -103,
  102449. -107, -110, -999, -999, -999, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999,
  102451. -999, -999, -999, -999, -999, -999, -999, -999},
  102452. {-999, -999, -999, -999, -999, -108, -103, -98,
  102453. -93, -89, -85, -82, -78, -71, -62, -55,
  102454. -58, -58, -54, -54, -55, -59, -61, -62,
  102455. -70, -66, -66, -67, -70, -72, -75, -78,
  102456. -84, -84, -84, -88, -91, -90, -95, -98,
  102457. -102, -103, -106, -110, -999, -999, -999, -999,
  102458. -999, -999, -999, -999, -999, -999, -999, -999},
  102459. {-999, -999, -999, -999, -108, -103, -98, -94,
  102460. -90, -87, -82, -79, -73, -67, -58, -47,
  102461. -50, -45, -41, -45, -48, -44, -44, -49,
  102462. -54, -51, -48, -47, -49, -50, -51, -57,
  102463. -58, -60, -63, -69, -70, -69, -71, -74,
  102464. -78, -82, -90, -95, -101, -105, -110, -999,
  102465. -999, -999, -999, -999, -999, -999, -999, -999},
  102466. {-999, -999, -999, -105, -101, -97, -93, -90,
  102467. -85, -80, -77, -72, -65, -56, -48, -37,
  102468. -40, -36, -34, -40, -50, -47, -38, -41,
  102469. -47, -38, -35, -39, -38, -43, -40, -45,
  102470. -50, -45, -44, -47, -50, -55, -48, -48,
  102471. -52, -66, -70, -76, -82, -90, -97, -105,
  102472. -110, -999, -999, -999, -999, -999, -999, -999}},
  102473. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102474. -999, -108, -103, -98, -93, -86, -79, -76,
  102475. -83, -81, -85, -87, -89, -93, -98, -102,
  102476. -107, -112, -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. -999, -999, -999, -999, -999, -999, -999, -999},
  102480. {-999, -999, -999, -999, -999, -999, -999, -999,
  102481. -999, -108, -103, -98, -93, -86, -79, -71,
  102482. -77, -74, -77, -79, -81, -84, -85, -90,
  102483. -92, -93, -92, -98, -101, -108, -112, -999,
  102484. -999, -999, -999, -999, -999, -999, -999, -999,
  102485. -999, -999, -999, -999, -999, -999, -999, -999,
  102486. -999, -999, -999, -999, -999, -999, -999, -999},
  102487. {-999, -999, -999, -999, -999, -999, -999, -999,
  102488. -108, -103, -98, -93, -87, -78, -68, -65,
  102489. -66, -62, -65, -67, -70, -73, -75, -78,
  102490. -82, -82, -83, -84, -91, -93, -98, -102,
  102491. -106, -110, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999,
  102493. -999, -999, -999, -999, -999, -999, -999, -999},
  102494. {-999, -999, -999, -999, -999, -999, -999, -999,
  102495. -105, -100, -95, -90, -82, -74, -62, -57,
  102496. -58, -56, -51, -52, -52, -54, -54, -58,
  102497. -66, -59, -60, -63, -66, -69, -73, -79,
  102498. -83, -84, -80, -81, -81, -82, -88, -92,
  102499. -98, -105, -113, -999, -999, -999, -999, -999,
  102500. -999, -999, -999, -999, -999, -999, -999, -999},
  102501. {-999, -999, -999, -999, -999, -999, -999, -107,
  102502. -102, -97, -92, -84, -79, -69, -57, -47,
  102503. -52, -47, -44, -45, -50, -52, -42, -42,
  102504. -53, -43, -43, -48, -51, -56, -55, -52,
  102505. -57, -59, -61, -62, -67, -71, -78, -83,
  102506. -86, -94, -98, -103, -110, -999, -999, -999,
  102507. -999, -999, -999, -999, -999, -999, -999, -999},
  102508. {-999, -999, -999, -999, -999, -999, -105, -100,
  102509. -95, -90, -84, -78, -70, -61, -51, -41,
  102510. -40, -38, -40, -46, -52, -51, -41, -40,
  102511. -46, -40, -38, -38, -41, -46, -41, -46,
  102512. -47, -43, -43, -45, -41, -45, -56, -67,
  102513. -68, -83, -87, -90, -95, -102, -107, -113,
  102514. -999, -999, -999, -999, -999, -999, -999, -999}},
  102515. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102516. -999, -109, -105, -101, -96, -91, -84, -77,
  102517. -82, -82, -85, -89, -94, -100, -106, -110,
  102518. -999, -999, -999, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -999, -999, -999, -999,
  102520. -999, -999, -999, -999, -999, -999, -999, -999,
  102521. -999, -999, -999, -999, -999, -999, -999, -999},
  102522. {-999, -999, -999, -999, -999, -999, -999, -999,
  102523. -999, -106, -103, -98, -92, -85, -80, -71,
  102524. -75, -72, -76, -80, -84, -86, -89, -93,
  102525. -100, -107, -113, -999, -999, -999, -999, -999,
  102526. -999, -999, -999, -999, -999, -999, -999, -999,
  102527. -999, -999, -999, -999, -999, -999, -999, -999,
  102528. -999, -999, -999, -999, -999, -999, -999, -999},
  102529. {-999, -999, -999, -999, -999, -999, -999, -107,
  102530. -104, -101, -97, -92, -88, -84, -80, -64,
  102531. -66, -63, -64, -66, -69, -73, -77, -83,
  102532. -83, -86, -91, -98, -104, -111, -999, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999,
  102535. -999, -999, -999, -999, -999, -999, -999, -999},
  102536. {-999, -999, -999, -999, -999, -999, -999, -107,
  102537. -104, -101, -97, -92, -90, -84, -74, -57,
  102538. -58, -52, -55, -54, -50, -52, -50, -52,
  102539. -63, -62, -69, -76, -77, -78, -78, -79,
  102540. -82, -88, -94, -100, -106, -111, -999, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999,
  102542. -999, -999, -999, -999, -999, -999, -999, -999},
  102543. {-999, -999, -999, -999, -999, -999, -106, -102,
  102544. -98, -95, -90, -85, -83, -78, -70, -50,
  102545. -50, -41, -44, -49, -47, -50, -50, -44,
  102546. -55, -46, -47, -48, -48, -54, -49, -49,
  102547. -58, -62, -71, -81, -87, -92, -97, -102,
  102548. -108, -114, -999, -999, -999, -999, -999, -999,
  102549. -999, -999, -999, -999, -999, -999, -999, -999},
  102550. {-999, -999, -999, -999, -999, -999, -106, -102,
  102551. -98, -95, -90, -85, -83, -78, -70, -45,
  102552. -43, -41, -47, -50, -51, -50, -49, -45,
  102553. -47, -41, -44, -41, -39, -43, -38, -37,
  102554. -40, -41, -44, -50, -58, -65, -73, -79,
  102555. -85, -92, -97, -101, -105, -109, -113, -999,
  102556. -999, -999, -999, -999, -999, -999, -999, -999}},
  102557. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102558. -999, -999, -999, -107, -100, -95, -87, -81,
  102559. -85, -83, -88, -93, -100, -107, -114, -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. -999, -999, -999, -999, -999, -999, -999, -999},
  102564. {-999, -999, -999, -999, -999, -999, -999, -999,
  102565. -999, -999, -107, -101, -95, -88, -83, -76,
  102566. -73, -72, -79, -84, -90, -95, -100, -105,
  102567. -110, -115, -999, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -999, -999, -999, -999,
  102569. -999, -999, -999, -999, -999, -999, -999, -999,
  102570. -999, -999, -999, -999, -999, -999, -999, -999},
  102571. {-999, -999, -999, -999, -999, -999, -999, -999,
  102572. -999, -999, -104, -98, -92, -87, -81, -70,
  102573. -65, -62, -67, -71, -74, -80, -85, -91,
  102574. -95, -99, -103, -108, -111, -114, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999,
  102577. -999, -999, -999, -999, -999, -999, -999, -999},
  102578. {-999, -999, -999, -999, -999, -999, -999, -999,
  102579. -999, -999, -103, -97, -90, -85, -76, -60,
  102580. -56, -54, -60, -62, -61, -56, -63, -65,
  102581. -73, -74, -77, -75, -78, -81, -86, -87,
  102582. -88, -91, -94, -98, -103, -110, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999,
  102584. -999, -999, -999, -999, -999, -999, -999, -999},
  102585. {-999, -999, -999, -999, -999, -999, -999, -105,
  102586. -100, -97, -92, -86, -81, -79, -70, -57,
  102587. -51, -47, -51, -58, -60, -56, -53, -50,
  102588. -58, -52, -50, -50, -53, -55, -64, -69,
  102589. -71, -85, -82, -78, -81, -85, -95, -102,
  102590. -112, -999, -999, -999, -999, -999, -999, -999,
  102591. -999, -999, -999, -999, -999, -999, -999, -999},
  102592. {-999, -999, -999, -999, -999, -999, -999, -105,
  102593. -100, -97, -92, -85, -83, -79, -72, -49,
  102594. -40, -43, -43, -54, -56, -51, -50, -40,
  102595. -43, -38, -36, -35, -37, -38, -37, -44,
  102596. -54, -60, -57, -60, -70, -75, -84, -92,
  102597. -103, -112, -999, -999, -999, -999, -999, -999,
  102598. -999, -999, -999, -999, -999, -999, -999, -999}},
  102599. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102600. -999, -999, -999, -110, -102, -95, -89, -82,
  102601. -83, -84, -90, -92, -99, -107, -113, -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, -999,
  102605. -999, -999, -999, -999, -999, -999, -999, -999},
  102606. {-999, -999, -999, -999, -999, -999, -999, -999,
  102607. -999, -999, -107, -101, -95, -89, -83, -72,
  102608. -74, -78, -85, -88, -88, -90, -92, -98,
  102609. -105, -111, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -999, -999, -999, -999, -999, -999,
  102611. -999, -999, -999, -999, -999, -999, -999, -999,
  102612. -999, -999, -999, -999, -999, -999, -999, -999},
  102613. {-999, -999, -999, -999, -999, -999, -999, -999,
  102614. -999, -109, -103, -97, -93, -87, -81, -70,
  102615. -70, -67, -75, -73, -76, -79, -81, -83,
  102616. -88, -89, -97, -103, -110, -999, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999,
  102619. -999, -999, -999, -999, -999, -999, -999, -999},
  102620. {-999, -999, -999, -999, -999, -999, -999, -999,
  102621. -999, -107, -100, -94, -88, -83, -75, -63,
  102622. -59, -59, -63, -66, -60, -62, -67, -67,
  102623. -77, -76, -81, -88, -86, -92, -96, -102,
  102624. -109, -116, -999, -999, -999, -999, -999, -999,
  102625. -999, -999, -999, -999, -999, -999, -999, -999,
  102626. -999, -999, -999, -999, -999, -999, -999, -999},
  102627. {-999, -999, -999, -999, -999, -999, -999, -999,
  102628. -999, -105, -98, -92, -86, -81, -73, -56,
  102629. -52, -47, -55, -60, -58, -52, -51, -45,
  102630. -49, -50, -53, -54, -61, -71, -70, -69,
  102631. -78, -79, -87, -90, -96, -104, -112, -999,
  102632. -999, -999, -999, -999, -999, -999, -999, -999,
  102633. -999, -999, -999, -999, -999, -999, -999, -999},
  102634. {-999, -999, -999, -999, -999, -999, -999, -999,
  102635. -999, -103, -96, -90, -86, -78, -70, -51,
  102636. -42, -47, -48, -55, -54, -54, -53, -42,
  102637. -35, -28, -33, -38, -37, -44, -47, -49,
  102638. -54, -63, -68, -78, -82, -89, -94, -99,
  102639. -104, -109, -114, -999, -999, -999, -999, -999,
  102640. -999, -999, -999, -999, -999, -999, -999, -999}},
  102641. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102642. -999, -999, -999, -999, -110, -100, -90, -79,
  102643. -85, -81, -82, -82, -89, -94, -99, -103,
  102644. -109, -115, -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, -999, -999, -999, -999, -999, -999},
  102648. {-999, -999, -999, -999, -999, -999, -999, -999,
  102649. -999, -999, -999, -999, -105, -97, -85, -72,
  102650. -74, -70, -70, -70, -76, -85, -91, -93,
  102651. -97, -103, -109, -115, -999, -999, -999, -999,
  102652. -999, -999, -999, -999, -999, -999, -999, -999,
  102653. -999, -999, -999, -999, -999, -999, -999, -999,
  102654. -999, -999, -999, -999, -999, -999, -999, -999},
  102655. {-999, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -999, -999, -999, -112, -93, -81, -68,
  102657. -62, -60, -60, -57, -63, -70, -77, -82,
  102658. -90, -93, -98, -104, -109, -113, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999,
  102661. -999, -999, -999, -999, -999, -999, -999, -999},
  102662. {-999, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -999, -999, -113, -100, -93, -84, -63,
  102664. -58, -48, -53, -54, -52, -52, -57, -64,
  102665. -66, -76, -83, -81, -85, -85, -90, -95,
  102666. -98, -101, -103, -106, -108, -111, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999,
  102668. -999, -999, -999, -999, -999, -999, -999, -999},
  102669. {-999, -999, -999, -999, -999, -999, -999, -999,
  102670. -999, -999, -999, -105, -95, -86, -74, -53,
  102671. -50, -38, -43, -49, -43, -42, -39, -39,
  102672. -46, -52, -57, -56, -72, -69, -74, -81,
  102673. -87, -92, -94, -97, -99, -102, -105, -108,
  102674. -999, -999, -999, -999, -999, -999, -999, -999,
  102675. -999, -999, -999, -999, -999, -999, -999, -999},
  102676. {-999, -999, -999, -999, -999, -999, -999, -999,
  102677. -999, -999, -108, -99, -90, -76, -66, -45,
  102678. -43, -41, -44, -47, -43, -47, -40, -30,
  102679. -31, -31, -39, -33, -40, -41, -43, -53,
  102680. -59, -70, -73, -77, -79, -82, -84, -87,
  102681. -999, -999, -999, -999, -999, -999, -999, -999,
  102682. -999, -999, -999, -999, -999, -999, -999, -999}},
  102683. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102684. -999, -999, -999, -999, -999, -110, -91, -76,
  102685. -75, -85, -93, -98, -104, -110, -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, -999, -999, -999, -999, -999, -999, -999},
  102690. {-999, -999, -999, -999, -999, -999, -999, -999,
  102691. -999, -999, -999, -999, -999, -110, -91, -70,
  102692. -70, -75, -86, -89, -94, -98, -101, -106,
  102693. -110, -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, -999, -999, -999, -999, -999, -999, -999},
  102697. {-999, -999, -999, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -999, -110, -95, -80, -60,
  102699. -65, -64, -74, -83, -88, -91, -95, -99,
  102700. -103, -107, -110, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999,
  102703. -999, -999, -999, -999, -999, -999, -999, -999},
  102704. {-999, -999, -999, -999, -999, -999, -999, -999,
  102705. -999, -999, -999, -999, -110, -95, -80, -58,
  102706. -55, -49, -66, -68, -71, -78, -78, -80,
  102707. -88, -85, -89, -97, -100, -105, -110, -999,
  102708. -999, -999, -999, -999, -999, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999,
  102710. -999, -999, -999, -999, -999, -999, -999, -999},
  102711. {-999, -999, -999, -999, -999, -999, -999, -999,
  102712. -999, -999, -999, -999, -110, -95, -80, -53,
  102713. -52, -41, -59, -59, -49, -58, -56, -63,
  102714. -86, -79, -90, -93, -98, -103, -107, -112,
  102715. -999, -999, -999, -999, -999, -999, -999, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999,
  102717. -999, -999, -999, -999, -999, -999, -999, -999},
  102718. {-999, -999, -999, -999, -999, -999, -999, -999,
  102719. -999, -999, -999, -110, -97, -91, -73, -45,
  102720. -40, -33, -53, -61, -49, -54, -50, -50,
  102721. -60, -52, -67, -74, -81, -92, -96, -100,
  102722. -105, -110, -999, -999, -999, -999, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999,
  102724. -999, -999, -999, -999, -999, -999, -999, -999}},
  102725. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102726. -999, -999, -999, -113, -106, -99, -92, -77,
  102727. -80, -88, -97, -106, -115, -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, -999, -999, -999, -999, -999},
  102732. {-999, -999, -999, -999, -999, -999, -999, -999,
  102733. -999, -999, -116, -109, -102, -95, -89, -74,
  102734. -72, -88, -87, -95, -102, -109, -116, -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, -999, -999, -999, -999, -999},
  102739. {-999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -116, -109, -102, -95, -89, -75,
  102741. -66, -74, -77, -78, -86, -87, -90, -96,
  102742. -105, -115, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999,
  102745. -999, -999, -999, -999, -999, -999, -999, -999},
  102746. {-999, -999, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -115, -108, -101, -94, -88, -66,
  102748. -56, -61, -70, -65, -78, -72, -83, -84,
  102749. -93, -98, -105, -110, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999,
  102752. -999, -999, -999, -999, -999, -999, -999, -999},
  102753. {-999, -999, -999, -999, -999, -999, -999, -999,
  102754. -999, -999, -110, -105, -95, -89, -82, -57,
  102755. -52, -52, -59, -56, -59, -58, -69, -67,
  102756. -88, -82, -82, -89, -94, -100, -108, -999,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999,
  102759. -999, -999, -999, -999, -999, -999, -999, -999},
  102760. {-999, -999, -999, -999, -999, -999, -999, -999,
  102761. -999, -110, -101, -96, -90, -83, -77, -54,
  102762. -43, -38, -50, -48, -52, -48, -42, -42,
  102763. -51, -52, -53, -59, -65, -71, -78, -85,
  102764. -95, -999, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999,
  102766. -999, -999, -999, -999, -999, -999, -999, -999}},
  102767. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102768. -999, -999, -999, -999, -120, -105, -86, -68,
  102769. -78, -79, -90, -100, -110, -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, -999, -999, -999, -999},
  102774. {-999, -999, -999, -999, -999, -999, -999, -999,
  102775. -999, -999, -999, -999, -120, -105, -86, -66,
  102776. -73, -77, -88, -96, -105, -115, -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, -999, -999, -999, -999},
  102781. {-999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -120, -105, -92, -80, -61,
  102783. -64, -68, -80, -87, -92, -100, -110, -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, -999, -999, -999, -999, -999},
  102788. {-999, -999, -999, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -120, -104, -91, -79, -52,
  102790. -60, -54, -64, -69, -77, -80, -82, -84,
  102791. -85, -87, -88, -90, -999, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999},
  102795. {-999, -999, -999, -999, -999, -999, -999, -999,
  102796. -999, -999, -999, -118, -100, -87, -77, -49,
  102797. -50, -44, -58, -61, -61, -67, -65, -62,
  102798. -62, -62, -65, -68, -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, -999, -999, -999, -999, -999, -999},
  102802. {-999, -999, -999, -999, -999, -999, -999, -999,
  102803. -999, -999, -999, -115, -98, -84, -62, -49,
  102804. -44, -38, -46, -49, -49, -46, -39, -37,
  102805. -39, -40, -42, -43, -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, -999, -999, -999, -999, -999, -999}},
  102809. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102810. -999, -999, -999, -999, -999, -110, -88, -74,
  102811. -77, -82, -82, -85, -90, -94, -99, -104,
  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, -999, -999, -999, -999, -999, -999},
  102816. {-999, -999, -999, -999, -999, -999, -999, -999,
  102817. -999, -999, -999, -999, -999, -110, -88, -66,
  102818. -70, -81, -80, -81, -84, -88, -91, -93,
  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, -999, -999, -999, -999, -999, -999},
  102823. {-999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -110, -88, -61,
  102825. -63, -70, -71, -74, -77, -80, -83, -85,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999},
  102830. {-999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -110, -86, -62,
  102832. -63, -62, -62, -58, -52, -50, -50, -52,
  102833. -54, -999, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999},
  102837. {-999, -999, -999, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -118, -108, -84, -53,
  102839. -50, -50, -50, -55, -47, -45, -40, -40,
  102840. -40, -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, -999, -999, -999, -999},
  102844. {-999, -999, -999, -999, -999, -999, -999, -999,
  102845. -999, -999, -999, -999, -118, -100, -73, -43,
  102846. -37, -42, -43, -53, -38, -37, -35, -35,
  102847. -38, -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, -999, -999, -999, -999, -999}},
  102851. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102852. -999, -999, -999, -110, -100, -91, -84, -74,
  102853. -80, -80, -80, -80, -80, -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, -999, -999, -999, -999, -999},
  102858. {-999, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -110, -100, -91, -84, -74,
  102860. -68, -68, -68, -68, -68, -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, -999, -999, -999, -999, -999},
  102865. {-999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -110, -100, -86, -78, -70,
  102867. -60, -45, -30, -21, -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, -999, -999, -999, -999, -999},
  102872. {-999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -999, -110, -100, -87, -78, -67,
  102874. -48, -38, -29, -21, -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, -999, -999, -999},
  102879. {-999, -999, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -999, -110, -100, -86, -69, -56,
  102881. -45, -35, -33, -29, -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, -999, -999, -999},
  102886. {-999, -999, -999, -999, -999, -999, -999, -999,
  102887. -999, -999, -999, -110, -100, -83, -71, -48,
  102888. -27, -38, -37, -34, -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, -999, -999, -999}}
  102893. };
  102894. #endif
  102895. /*** End of inlined file: masking.h ***/
  102896. #define NEGINF -9999.f
  102897. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102898. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102899. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102900. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102901. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102902. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102903. look->channels=vi->channels;
  102904. look->ampmax=-9999.;
  102905. look->gi=gi;
  102906. return(look);
  102907. }
  102908. void _vp_global_free(vorbis_look_psy_global *look){
  102909. if(look){
  102910. memset(look,0,sizeof(*look));
  102911. _ogg_free(look);
  102912. }
  102913. }
  102914. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102915. if(i){
  102916. memset(i,0,sizeof(*i));
  102917. _ogg_free(i);
  102918. }
  102919. }
  102920. void _vi_psy_free(vorbis_info_psy *i){
  102921. if(i){
  102922. memset(i,0,sizeof(*i));
  102923. _ogg_free(i);
  102924. }
  102925. }
  102926. static void min_curve(float *c,
  102927. float *c2){
  102928. int i;
  102929. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  102930. }
  102931. static void max_curve(float *c,
  102932. float *c2){
  102933. int i;
  102934. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  102935. }
  102936. static void attenuate_curve(float *c,float att){
  102937. int i;
  102938. for(i=0;i<EHMER_MAX;i++)
  102939. c[i]+=att;
  102940. }
  102941. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  102942. float center_boost, float center_decay_rate){
  102943. int i,j,k,m;
  102944. float ath[EHMER_MAX];
  102945. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  102946. float athc[P_LEVELS][EHMER_MAX];
  102947. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  102948. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  102949. memset(workc,0,sizeof(workc));
  102950. for(i=0;i<P_BANDS;i++){
  102951. int ath_offset=i*4;
  102952. for(j=0;j<EHMER_MAX;j++){
  102953. float min=999.;
  102954. for(k=0;k<4;k++)
  102955. if(j+k+ath_offset<MAX_ATH){
  102956. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  102957. }else{
  102958. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  102959. }
  102960. ath[j]=min;
  102961. }
  102962. for(j=0;j<6;j++)
  102963. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  102964. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102965. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102966. for(j=0;j<P_LEVELS;j++){
  102967. for(k=0;k<EHMER_MAX;k++){
  102968. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  102969. if(adj<0. && center_boost>0)adj=0.;
  102970. if(adj>0. && center_boost<0)adj=0.;
  102971. workc[i][j][k]+=adj;
  102972. }
  102973. }
  102974. for(j=0;j<P_LEVELS;j++){
  102975. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  102976. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  102977. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  102978. max_curve(athc[j],workc[i][j]);
  102979. }
  102980. for(j=1;j<P_LEVELS;j++){
  102981. min_curve(athc[j],athc[j-1]);
  102982. min_curve(workc[i][j],athc[j]);
  102983. }
  102984. }
  102985. for(i=0;i<P_BANDS;i++){
  102986. int hi_curve,lo_curve,bin;
  102987. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  102988. bin=floor(fromOC(i*.5)/binHz);
  102989. lo_curve= ceil(toOC(bin*binHz+1)*2);
  102990. hi_curve= floor(toOC((bin+1)*binHz)*2);
  102991. if(lo_curve>i)lo_curve=i;
  102992. if(lo_curve<0)lo_curve=0;
  102993. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  102994. for(m=0;m<P_LEVELS;m++){
  102995. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  102996. for(j=0;j<n;j++)brute_buffer[j]=999.;
  102997. for(k=lo_curve;k<=hi_curve;k++){
  102998. int l=0;
  102999. for(j=0;j<EHMER_MAX;j++){
  103000. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103001. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103002. if(lo_bin<0)lo_bin=0;
  103003. if(lo_bin>n)lo_bin=n;
  103004. if(lo_bin<l)l=lo_bin;
  103005. if(hi_bin<0)hi_bin=0;
  103006. if(hi_bin>n)hi_bin=n;
  103007. for(;l<hi_bin && l<n;l++)
  103008. if(brute_buffer[l]>workc[k][m][j])
  103009. brute_buffer[l]=workc[k][m][j];
  103010. }
  103011. for(;l<n;l++)
  103012. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103013. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103014. }
  103015. if(i+1<P_BANDS){
  103016. int l=0;
  103017. k=i+1;
  103018. for(j=0;j<EHMER_MAX;j++){
  103019. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103020. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103021. if(lo_bin<0)lo_bin=0;
  103022. if(lo_bin>n)lo_bin=n;
  103023. if(lo_bin<l)l=lo_bin;
  103024. if(hi_bin<0)hi_bin=0;
  103025. if(hi_bin>n)hi_bin=n;
  103026. for(;l<hi_bin && l<n;l++)
  103027. if(brute_buffer[l]>workc[k][m][j])
  103028. brute_buffer[l]=workc[k][m][j];
  103029. }
  103030. for(;l<n;l++)
  103031. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103032. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103033. }
  103034. for(j=0;j<EHMER_MAX;j++){
  103035. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103036. if(bin<0){
  103037. ret[i][m][j+2]=-999.;
  103038. }else{
  103039. if(bin>=n){
  103040. ret[i][m][j+2]=-999.;
  103041. }else{
  103042. ret[i][m][j+2]=brute_buffer[bin];
  103043. }
  103044. }
  103045. }
  103046. for(j=0;j<EHMER_OFFSET;j++)
  103047. if(ret[i][m][j+2]>-200.f)break;
  103048. ret[i][m][0]=j;
  103049. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103050. if(ret[i][m][j+2]>-200.f)
  103051. break;
  103052. ret[i][m][1]=j;
  103053. }
  103054. }
  103055. return(ret);
  103056. }
  103057. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103058. vorbis_info_psy_global *gi,int n,long rate){
  103059. long i,j,lo=-99,hi=1;
  103060. long maxoc;
  103061. memset(p,0,sizeof(*p));
  103062. p->eighth_octave_lines=gi->eighth_octave_lines;
  103063. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103064. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103065. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103066. p->total_octave_lines=maxoc-p->firstoc+1;
  103067. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103068. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103069. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103070. p->vi=vi;
  103071. p->n=n;
  103072. p->rate=rate;
  103073. p->m_val = 1.;
  103074. if(rate < 26000) p->m_val = 0;
  103075. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103076. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103077. for(i=0,j=0;i<MAX_ATH-1;i++){
  103078. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103079. float base=ATH[i];
  103080. if(j<endpos){
  103081. float delta=(ATH[i+1]-base)/(endpos-j);
  103082. for(;j<endpos && j<n;j++){
  103083. p->ath[j]=base+100.;
  103084. base+=delta;
  103085. }
  103086. }
  103087. }
  103088. for(i=0;i<n;i++){
  103089. float bark=toBARK(rate/(2*n)*i);
  103090. for(;lo+vi->noisewindowlomin<i &&
  103091. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103092. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103093. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103094. p->bark[i]=((lo-1)<<16)+(hi-1);
  103095. }
  103096. for(i=0;i<n;i++)
  103097. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103098. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103099. vi->tone_centerboost,vi->tone_decay);
  103100. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103101. for(i=0;i<P_NOISECURVES;i++)
  103102. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103103. for(i=0;i<n;i++){
  103104. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103105. int inthalfoc;
  103106. float del;
  103107. if(halfoc<0)halfoc=0;
  103108. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103109. inthalfoc=(int)halfoc;
  103110. del=halfoc-inthalfoc;
  103111. for(j=0;j<P_NOISECURVES;j++)
  103112. p->noiseoffset[j][i]=
  103113. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103114. p->vi->noiseoff[j][inthalfoc+1]*del;
  103115. }
  103116. #if 0
  103117. {
  103118. static int ls=0;
  103119. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103120. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103121. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103122. }
  103123. #endif
  103124. }
  103125. void _vp_psy_clear(vorbis_look_psy *p){
  103126. int i,j;
  103127. if(p){
  103128. if(p->ath)_ogg_free(p->ath);
  103129. if(p->octave)_ogg_free(p->octave);
  103130. if(p->bark)_ogg_free(p->bark);
  103131. if(p->tonecurves){
  103132. for(i=0;i<P_BANDS;i++){
  103133. for(j=0;j<P_LEVELS;j++){
  103134. _ogg_free(p->tonecurves[i][j]);
  103135. }
  103136. _ogg_free(p->tonecurves[i]);
  103137. }
  103138. _ogg_free(p->tonecurves);
  103139. }
  103140. if(p->noiseoffset){
  103141. for(i=0;i<P_NOISECURVES;i++){
  103142. _ogg_free(p->noiseoffset[i]);
  103143. }
  103144. _ogg_free(p->noiseoffset);
  103145. }
  103146. memset(p,0,sizeof(*p));
  103147. }
  103148. }
  103149. static void seed_curve(float *seed,
  103150. const float **curves,
  103151. float amp,
  103152. int oc, int n,
  103153. int linesper,float dBoffset){
  103154. int i,post1;
  103155. int seedptr;
  103156. const float *posts,*curve;
  103157. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103158. choice=max(choice,0);
  103159. choice=min(choice,P_LEVELS-1);
  103160. posts=curves[choice];
  103161. curve=posts+2;
  103162. post1=(int)posts[1];
  103163. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103164. for(i=posts[0];i<post1;i++){
  103165. if(seedptr>0){
  103166. float lin=amp+curve[i];
  103167. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103168. }
  103169. seedptr+=linesper;
  103170. if(seedptr>=n)break;
  103171. }
  103172. }
  103173. static void seed_loop(vorbis_look_psy *p,
  103174. const float ***curves,
  103175. const float *f,
  103176. const float *flr,
  103177. float *seed,
  103178. float specmax){
  103179. vorbis_info_psy *vi=p->vi;
  103180. long n=p->n,i;
  103181. float dBoffset=vi->max_curve_dB-specmax;
  103182. for(i=0;i<n;i++){
  103183. float max=f[i];
  103184. long oc=p->octave[i];
  103185. while(i+1<n && p->octave[i+1]==oc){
  103186. i++;
  103187. if(f[i]>max)max=f[i];
  103188. }
  103189. if(max+6.f>flr[i]){
  103190. oc=oc>>p->shiftoc;
  103191. if(oc>=P_BANDS)oc=P_BANDS-1;
  103192. if(oc<0)oc=0;
  103193. seed_curve(seed,
  103194. curves[oc],
  103195. max,
  103196. p->octave[i]-p->firstoc,
  103197. p->total_octave_lines,
  103198. p->eighth_octave_lines,
  103199. dBoffset);
  103200. }
  103201. }
  103202. }
  103203. static void seed_chase(float *seeds, int linesper, long n){
  103204. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103205. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103206. long stack=0;
  103207. long pos=0;
  103208. long i;
  103209. for(i=0;i<n;i++){
  103210. if(stack<2){
  103211. posstack[stack]=i;
  103212. ampstack[stack++]=seeds[i];
  103213. }else{
  103214. while(1){
  103215. if(seeds[i]<ampstack[stack-1]){
  103216. posstack[stack]=i;
  103217. ampstack[stack++]=seeds[i];
  103218. break;
  103219. }else{
  103220. if(i<posstack[stack-1]+linesper){
  103221. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103222. i<posstack[stack-2]+linesper){
  103223. stack--;
  103224. continue;
  103225. }
  103226. }
  103227. posstack[stack]=i;
  103228. ampstack[stack++]=seeds[i];
  103229. break;
  103230. }
  103231. }
  103232. }
  103233. }
  103234. for(i=0;i<stack;i++){
  103235. long endpos;
  103236. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103237. endpos=posstack[i+1];
  103238. }else{
  103239. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103240. discarded in short frames */
  103241. }
  103242. if(endpos>n)endpos=n;
  103243. for(;pos<endpos;pos++)
  103244. seeds[pos]=ampstack[i];
  103245. }
  103246. }
  103247. #include<stdio.h>
  103248. static void max_seeds(vorbis_look_psy *p,
  103249. float *seed,
  103250. float *flr){
  103251. long n=p->total_octave_lines;
  103252. int linesper=p->eighth_octave_lines;
  103253. long linpos=0;
  103254. long pos;
  103255. seed_chase(seed,linesper,n); /* for masking */
  103256. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103257. while(linpos+1<p->n){
  103258. float minV=seed[pos];
  103259. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103260. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103261. while(pos+1<=end){
  103262. pos++;
  103263. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103264. minV=seed[pos];
  103265. }
  103266. end=pos+p->firstoc;
  103267. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103268. if(flr[linpos]<minV)flr[linpos]=minV;
  103269. }
  103270. {
  103271. float minV=seed[p->total_octave_lines-1];
  103272. for(;linpos<p->n;linpos++)
  103273. if(flr[linpos]<minV)flr[linpos]=minV;
  103274. }
  103275. }
  103276. static void bark_noise_hybridmp(int n,const long *b,
  103277. const float *f,
  103278. float *noise,
  103279. const float offset,
  103280. const int fixed){
  103281. float *N=(float*) alloca(n*sizeof(*N));
  103282. float *X=(float*) alloca(n*sizeof(*N));
  103283. float *XX=(float*) alloca(n*sizeof(*N));
  103284. float *Y=(float*) alloca(n*sizeof(*N));
  103285. float *XY=(float*) alloca(n*sizeof(*N));
  103286. float tN, tX, tXX, tY, tXY;
  103287. int i;
  103288. int lo, hi;
  103289. float R, A, B, D;
  103290. float w, x, y;
  103291. tN = tX = tXX = tY = tXY = 0.f;
  103292. y = f[0] + offset;
  103293. if (y < 1.f) y = 1.f;
  103294. w = y * y * .5;
  103295. tN += w;
  103296. tX += w;
  103297. tY += w * y;
  103298. N[0] = tN;
  103299. X[0] = tX;
  103300. XX[0] = tXX;
  103301. Y[0] = tY;
  103302. XY[0] = tXY;
  103303. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103304. y = f[i] + offset;
  103305. if (y < 1.f) y = 1.f;
  103306. w = y * y;
  103307. tN += w;
  103308. tX += w * x;
  103309. tXX += w * x * x;
  103310. tY += w * y;
  103311. tXY += w * x * y;
  103312. N[i] = tN;
  103313. X[i] = tX;
  103314. XX[i] = tXX;
  103315. Y[i] = tY;
  103316. XY[i] = tXY;
  103317. }
  103318. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103319. lo = b[i] >> 16;
  103320. if( lo>=0 ) break;
  103321. hi = b[i] & 0xffff;
  103322. tN = N[hi] + N[-lo];
  103323. tX = X[hi] - X[-lo];
  103324. tXX = XX[hi] + XX[-lo];
  103325. tY = Y[hi] + Y[-lo];
  103326. tXY = XY[hi] - XY[-lo];
  103327. A = tY * tXX - tX * tXY;
  103328. B = tN * tXY - tX * tY;
  103329. D = tN * tXX - tX * tX;
  103330. R = (A + x * B) / D;
  103331. if (R < 0.f)
  103332. R = 0.f;
  103333. noise[i] = R - offset;
  103334. }
  103335. for ( ;; i++, x += 1.f) {
  103336. lo = b[i] >> 16;
  103337. hi = b[i] & 0xffff;
  103338. if(hi>=n)break;
  103339. tN = N[hi] - N[lo];
  103340. tX = X[hi] - X[lo];
  103341. tXX = XX[hi] - XX[lo];
  103342. tY = Y[hi] - Y[lo];
  103343. tXY = XY[hi] - XY[lo];
  103344. A = tY * tXX - tX * tXY;
  103345. B = tN * tXY - tX * tY;
  103346. D = tN * tXX - tX * tX;
  103347. R = (A + x * B) / D;
  103348. if (R < 0.f) R = 0.f;
  103349. noise[i] = R - offset;
  103350. }
  103351. for ( ; i < n; i++, x += 1.f) {
  103352. R = (A + x * B) / D;
  103353. if (R < 0.f) R = 0.f;
  103354. noise[i] = R - offset;
  103355. }
  103356. if (fixed <= 0) return;
  103357. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103358. hi = i + fixed / 2;
  103359. lo = hi - fixed;
  103360. if(lo>=0)break;
  103361. tN = N[hi] + N[-lo];
  103362. tX = X[hi] - X[-lo];
  103363. tXX = XX[hi] + XX[-lo];
  103364. tY = Y[hi] + Y[-lo];
  103365. tXY = XY[hi] - XY[-lo];
  103366. A = tY * tXX - tX * tXY;
  103367. B = tN * tXY - tX * tY;
  103368. D = tN * tXX - tX * tX;
  103369. R = (A + x * B) / D;
  103370. if (R - offset < noise[i]) noise[i] = R - offset;
  103371. }
  103372. for ( ;; i++, x += 1.f) {
  103373. hi = i + fixed / 2;
  103374. lo = hi - fixed;
  103375. if(hi>=n)break;
  103376. tN = N[hi] - N[lo];
  103377. tX = X[hi] - X[lo];
  103378. tXX = XX[hi] - XX[lo];
  103379. tY = Y[hi] - Y[lo];
  103380. tXY = XY[hi] - XY[lo];
  103381. A = tY * tXX - tX * tXY;
  103382. B = tN * tXY - tX * tY;
  103383. D = tN * tXX - tX * tX;
  103384. R = (A + x * B) / D;
  103385. if (R - offset < noise[i]) noise[i] = R - offset;
  103386. }
  103387. for ( ; i < n; i++, x += 1.f) {
  103388. R = (A + x * B) / D;
  103389. if (R - offset < noise[i]) noise[i] = R - offset;
  103390. }
  103391. }
  103392. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103393. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103394. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103395. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103396. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103397. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103398. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103399. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103400. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103401. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103402. 973377.F, 913981.F, 858210.F, 805842.F,
  103403. 756669.F, 710497.F, 667142.F, 626433.F,
  103404. 588208.F, 552316.F, 518613.F, 486967.F,
  103405. 457252.F, 429351.F, 403152.F, 378551.F,
  103406. 355452.F, 333762.F, 313396.F, 294273.F,
  103407. 276316.F, 259455.F, 243623.F, 228757.F,
  103408. 214798.F, 201691.F, 189384.F, 177828.F,
  103409. 166977.F, 156788.F, 147221.F, 138237.F,
  103410. 129802.F, 121881.F, 114444.F, 107461.F,
  103411. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103412. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103413. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103414. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103415. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103416. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103417. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103418. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103419. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103420. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103421. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103422. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103423. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103424. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103425. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103426. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103427. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103428. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103429. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103430. 842.910F, 791.475F, 743.179F, 697.830F,
  103431. 655.249F, 615.265F, 577.722F, 542.469F,
  103432. 509.367F, 478.286F, 449.101F, 421.696F,
  103433. 395.964F, 371.803F, 349.115F, 327.812F,
  103434. 307.809F, 289.026F, 271.390F, 254.830F,
  103435. 239.280F, 224.679F, 210.969F, 198.096F,
  103436. 186.008F, 174.658F, 164.000F, 153.993F,
  103437. 144.596F, 135.773F, 127.488F, 119.708F,
  103438. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103439. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103440. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103441. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103442. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103443. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103444. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103445. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103446. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103447. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103448. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103449. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103450. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103451. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103452. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103453. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103454. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103455. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103456. 1.20790F, 1.13419F, 1.06499F, 1.F
  103457. };
  103458. void _vp_remove_floor(vorbis_look_psy *p,
  103459. float *mdct,
  103460. int *codedflr,
  103461. float *residue,
  103462. int sliding_lowpass){
  103463. int i,n=p->n;
  103464. if(sliding_lowpass>n)sliding_lowpass=n;
  103465. for(i=0;i<sliding_lowpass;i++){
  103466. residue[i]=
  103467. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103468. }
  103469. for(;i<n;i++)
  103470. residue[i]=0.;
  103471. }
  103472. void _vp_noisemask(vorbis_look_psy *p,
  103473. float *logmdct,
  103474. float *logmask){
  103475. int i,n=p->n;
  103476. float *work=(float*) alloca(n*sizeof(*work));
  103477. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103478. 140.,-1);
  103479. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103480. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103481. p->vi->noisewindowfixed);
  103482. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103483. #if 0
  103484. {
  103485. static int seq=0;
  103486. float work2[n];
  103487. for(i=0;i<n;i++){
  103488. work2[i]=logmask[i]+work[i];
  103489. }
  103490. if(seq&1)
  103491. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103492. else
  103493. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103494. if(seq&1)
  103495. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103496. else
  103497. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103498. seq++;
  103499. }
  103500. #endif
  103501. for(i=0;i<n;i++){
  103502. int dB=logmask[i]+.5;
  103503. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103504. if(dB<0)dB=0;
  103505. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103506. }
  103507. }
  103508. void _vp_tonemask(vorbis_look_psy *p,
  103509. float *logfft,
  103510. float *logmask,
  103511. float global_specmax,
  103512. float local_specmax){
  103513. int i,n=p->n;
  103514. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103515. float att=local_specmax+p->vi->ath_adjatt;
  103516. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103517. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103518. for(i=0;i<n;i++)
  103519. logmask[i]=p->ath[i]+att;
  103520. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103521. max_seeds(p,seed,logmask);
  103522. }
  103523. void _vp_offset_and_mix(vorbis_look_psy *p,
  103524. float *noise,
  103525. float *tone,
  103526. int offset_select,
  103527. float *logmask,
  103528. float *mdct,
  103529. float *logmdct){
  103530. int i,n=p->n;
  103531. float de, coeffi, cx;/* AoTuV */
  103532. float toneatt=p->vi->tone_masteratt[offset_select];
  103533. cx = p->m_val;
  103534. for(i=0;i<n;i++){
  103535. float val= noise[i]+p->noiseoffset[offset_select][i];
  103536. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103537. logmask[i]=max(val,tone[i]+toneatt);
  103538. if(offset_select == 1) {
  103539. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103540. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103541. if(val > coeffi){
  103542. de = 1.0-((val-coeffi)*0.005*cx);
  103543. if(de < 0) de = 0.0001;
  103544. }else
  103545. de = 1.0-((val-coeffi)*0.0003*cx);
  103546. mdct[i] *= de;
  103547. }
  103548. }
  103549. }
  103550. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103551. vorbis_info *vi=vd->vi;
  103552. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103553. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103554. int n=ci->blocksizes[vd->W]/2;
  103555. float secs=(float)n/vi->rate;
  103556. amp+=secs*gi->ampmax_att_per_sec;
  103557. if(amp<-9999)amp=-9999;
  103558. return(amp);
  103559. }
  103560. static void couple_lossless(float A, float B,
  103561. float *qA, float *qB){
  103562. int test1=fabs(*qA)>fabs(*qB);
  103563. test1-= fabs(*qA)<fabs(*qB);
  103564. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103565. if(test1==1){
  103566. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103567. }else{
  103568. float temp=*qB;
  103569. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103570. *qA=temp;
  103571. }
  103572. if(*qB>fabs(*qA)*1.9999f){
  103573. *qB= -fabs(*qA)*2.f;
  103574. *qA= -*qA;
  103575. }
  103576. }
  103577. static float hypot_lookup[32]={
  103578. -0.009935, -0.011245, -0.012726, -0.014397,
  103579. -0.016282, -0.018407, -0.020800, -0.023494,
  103580. -0.026522, -0.029923, -0.033737, -0.038010,
  103581. -0.042787, -0.048121, -0.054064, -0.060671,
  103582. -0.068000, -0.076109, -0.085054, -0.094892,
  103583. -0.105675, -0.117451, -0.130260, -0.144134,
  103584. -0.159093, -0.175146, -0.192286, -0.210490,
  103585. -0.229718, -0.249913, -0.271001, -0.292893};
  103586. static void precomputed_couple_point(float premag,
  103587. int floorA,int floorB,
  103588. float *mag, float *ang){
  103589. int test=(floorA>floorB)-1;
  103590. int offset=31-abs(floorA-floorB);
  103591. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103592. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103593. *mag=premag*floormag;
  103594. *ang=0.f;
  103595. }
  103596. static float dipole_hypot(float a, float b){
  103597. if(a>0.){
  103598. if(b>0.)return sqrt(a*a+b*b);
  103599. if(a>-b)return sqrt(a*a-b*b);
  103600. return -sqrt(b*b-a*a);
  103601. }
  103602. if(b<0.)return -sqrt(a*a+b*b);
  103603. if(-a>b)return -sqrt(a*a-b*b);
  103604. return sqrt(b*b-a*a);
  103605. }
  103606. static float round_hypot(float a, float b){
  103607. if(a>0.){
  103608. if(b>0.)return sqrt(a*a+b*b);
  103609. if(a>-b)return sqrt(a*a+b*b);
  103610. return -sqrt(b*b+a*a);
  103611. }
  103612. if(b<0.)return -sqrt(a*a+b*b);
  103613. if(-a>b)return -sqrt(a*a+b*b);
  103614. return sqrt(b*b+a*a);
  103615. }
  103616. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103617. vorbis_info_psy_global *g,
  103618. vorbis_look_psy *p,
  103619. vorbis_info_mapping0 *vi,
  103620. float **mdct){
  103621. int i,j,n=p->n;
  103622. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103623. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103624. for(i=0;i<vi->coupling_steps;i++){
  103625. float *mdctM=mdct[vi->coupling_mag[i]];
  103626. float *mdctA=mdct[vi->coupling_ang[i]];
  103627. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103628. for(j=0;j<limit;j++)
  103629. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103630. for(;j<n;j++)
  103631. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103632. }
  103633. return(ret);
  103634. }
  103635. static int apsort(const void *a, const void *b){
  103636. float f1=fabs(**(float**)a);
  103637. float f2=fabs(**(float**)b);
  103638. return (f1<f2)-(f1>f2);
  103639. }
  103640. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103641. vorbis_look_psy *p,
  103642. vorbis_info_mapping0 *vi,
  103643. float **mags){
  103644. if(p->vi->normal_point_p){
  103645. int i,j,k,n=p->n;
  103646. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103647. int partition=p->vi->normal_partition;
  103648. float **work=(float**) alloca(sizeof(*work)*partition);
  103649. for(i=0;i<vi->coupling_steps;i++){
  103650. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103651. for(j=0;j<n;j+=partition){
  103652. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103653. qsort(work,partition,sizeof(*work),apsort);
  103654. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103655. }
  103656. }
  103657. return(ret);
  103658. }
  103659. return(NULL);
  103660. }
  103661. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103662. float *magnitudes,int *sortedindex){
  103663. int i,j,n=p->n;
  103664. vorbis_info_psy *vi=p->vi;
  103665. int partition=vi->normal_partition;
  103666. float **work=(float**) alloca(sizeof(*work)*partition);
  103667. int start=vi->normal_start;
  103668. for(j=start;j<n;j+=partition){
  103669. if(j+partition>n)partition=n-j;
  103670. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103671. qsort(work,partition,sizeof(*work),apsort);
  103672. for(i=0;i<partition;i++){
  103673. sortedindex[i+j-start]=work[i]-magnitudes;
  103674. }
  103675. }
  103676. }
  103677. void _vp_noise_normalize(vorbis_look_psy *p,
  103678. float *in,float *out,int *sortedindex){
  103679. int flag=0,i,j=0,n=p->n;
  103680. vorbis_info_psy *vi=p->vi;
  103681. int partition=vi->normal_partition;
  103682. int start=vi->normal_start;
  103683. if(start>n)start=n;
  103684. if(vi->normal_channel_p){
  103685. for(;j<start;j++)
  103686. out[j]=rint(in[j]);
  103687. for(;j+partition<=n;j+=partition){
  103688. float acc=0.;
  103689. int k;
  103690. for(i=j;i<j+partition;i++)
  103691. acc+=in[i]*in[i];
  103692. for(i=0;i<partition;i++){
  103693. k=sortedindex[i+j-start];
  103694. if(in[k]*in[k]>=.25f){
  103695. out[k]=rint(in[k]);
  103696. acc-=in[k]*in[k];
  103697. flag=1;
  103698. }else{
  103699. if(acc<vi->normal_thresh)break;
  103700. out[k]=unitnorm(in[k]);
  103701. acc-=1.;
  103702. }
  103703. }
  103704. for(;i<partition;i++){
  103705. k=sortedindex[i+j-start];
  103706. out[k]=0.;
  103707. }
  103708. }
  103709. }
  103710. for(;j<n;j++)
  103711. out[j]=rint(in[j]);
  103712. }
  103713. void _vp_couple(int blobno,
  103714. vorbis_info_psy_global *g,
  103715. vorbis_look_psy *p,
  103716. vorbis_info_mapping0 *vi,
  103717. float **res,
  103718. float **mag_memo,
  103719. int **mag_sort,
  103720. int **ifloor,
  103721. int *nonzero,
  103722. int sliding_lowpass){
  103723. int i,j,k,n=p->n;
  103724. for(i=0;i<vi->coupling_steps;i++){
  103725. if(nonzero[vi->coupling_mag[i]] ||
  103726. nonzero[vi->coupling_ang[i]]){
  103727. float *rM=res[vi->coupling_mag[i]];
  103728. float *rA=res[vi->coupling_ang[i]];
  103729. float *qM=rM+n;
  103730. float *qA=rA+n;
  103731. int *floorM=ifloor[vi->coupling_mag[i]];
  103732. int *floorA=ifloor[vi->coupling_ang[i]];
  103733. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103734. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103735. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103736. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103737. int pointlimit=limit;
  103738. nonzero[vi->coupling_mag[i]]=1;
  103739. nonzero[vi->coupling_ang[i]]=1;
  103740. if(n > 1000)
  103741. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103742. for(j=0;j<p->n;j+=partition){
  103743. float acc=0.f;
  103744. for(k=0;k<partition;k++){
  103745. int l=k+j;
  103746. if(l<sliding_lowpass){
  103747. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103748. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103749. precomputed_couple_point(mag_memo[i][l],
  103750. floorM[l],floorA[l],
  103751. qM+l,qA+l);
  103752. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103753. }else{
  103754. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103755. }
  103756. }else{
  103757. qM[l]=0.;
  103758. qA[l]=0.;
  103759. }
  103760. }
  103761. if(p->vi->normal_point_p){
  103762. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103763. int l=mag_sort[i][j+k];
  103764. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103765. qM[l]=unitnorm(qM[l]);
  103766. acc-=1.f;
  103767. }
  103768. }
  103769. }
  103770. }
  103771. }
  103772. }
  103773. }
  103774. void hf_reduction(vorbis_info_psy_global *g,
  103775. vorbis_look_psy *p,
  103776. vorbis_info_mapping0 *vi,
  103777. float **mdct){
  103778. int i,j,n=p->n, de=0.3*p->m_val;
  103779. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103780. for(i=0; i<vi->coupling_steps; i++){
  103781. for(j=limit; j<n; j++)
  103782. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103783. }
  103784. }
  103785. #endif
  103786. /*** End of inlined file: psy.c ***/
  103787. /*** Start of inlined file: registry.c ***/
  103788. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103789. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103790. // tasks..
  103791. #if JUCE_MSVC
  103792. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103793. #endif
  103794. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103795. #if JUCE_USE_OGGVORBIS
  103796. extern vorbis_func_floor floor0_exportbundle;
  103797. extern vorbis_func_floor floor1_exportbundle;
  103798. extern vorbis_func_residue residue0_exportbundle;
  103799. extern vorbis_func_residue residue1_exportbundle;
  103800. extern vorbis_func_residue residue2_exportbundle;
  103801. extern vorbis_func_mapping mapping0_exportbundle;
  103802. vorbis_func_floor *_floor_P[]={
  103803. &floor0_exportbundle,
  103804. &floor1_exportbundle,
  103805. };
  103806. vorbis_func_residue *_residue_P[]={
  103807. &residue0_exportbundle,
  103808. &residue1_exportbundle,
  103809. &residue2_exportbundle,
  103810. };
  103811. vorbis_func_mapping *_mapping_P[]={
  103812. &mapping0_exportbundle,
  103813. };
  103814. #endif
  103815. /*** End of inlined file: registry.c ***/
  103816. /*** Start of inlined file: res0.c ***/
  103817. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103818. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103819. // tasks..
  103820. #if JUCE_MSVC
  103821. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103822. #endif
  103823. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103824. #if JUCE_USE_OGGVORBIS
  103825. #include <stdlib.h>
  103826. #include <string.h>
  103827. #include <math.h>
  103828. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103829. #include <stdio.h>
  103830. #endif
  103831. typedef struct {
  103832. vorbis_info_residue0 *info;
  103833. int parts;
  103834. int stages;
  103835. codebook *fullbooks;
  103836. codebook *phrasebook;
  103837. codebook ***partbooks;
  103838. int partvals;
  103839. int **decodemap;
  103840. long postbits;
  103841. long phrasebits;
  103842. long frames;
  103843. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103844. int train_seq;
  103845. long *training_data[8][64];
  103846. float training_max[8][64];
  103847. float training_min[8][64];
  103848. float tmin;
  103849. float tmax;
  103850. #endif
  103851. } vorbis_look_residue0;
  103852. void res0_free_info(vorbis_info_residue *i){
  103853. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103854. if(info){
  103855. memset(info,0,sizeof(*info));
  103856. _ogg_free(info);
  103857. }
  103858. }
  103859. void res0_free_look(vorbis_look_residue *i){
  103860. int j;
  103861. if(i){
  103862. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103863. #ifdef TRAIN_RES
  103864. {
  103865. int j,k,l;
  103866. for(j=0;j<look->parts;j++){
  103867. for(k=0;k<8;k++)
  103868. if(look->training_data[k][j]){
  103869. char buffer[80];
  103870. FILE *of;
  103871. codebook *statebook=look->partbooks[j][k];
  103872. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103873. of=fopen(buffer,"a");
  103874. for(l=0;l<statebook->entries;l++)
  103875. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103876. fclose(of);
  103877. _ogg_free(look->training_data[k][j]);
  103878. look->training_data[k][j]=NULL;
  103879. }
  103880. }
  103881. }
  103882. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103883. #endif
  103884. for(j=0;j<look->parts;j++)
  103885. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103886. _ogg_free(look->partbooks);
  103887. for(j=0;j<look->partvals;j++)
  103888. _ogg_free(look->decodemap[j]);
  103889. _ogg_free(look->decodemap);
  103890. memset(look,0,sizeof(*look));
  103891. _ogg_free(look);
  103892. }
  103893. }
  103894. static int icount(unsigned int v){
  103895. int ret=0;
  103896. while(v){
  103897. ret+=v&1;
  103898. v>>=1;
  103899. }
  103900. return(ret);
  103901. }
  103902. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103903. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103904. int j,acc=0;
  103905. oggpack_write(opb,info->begin,24);
  103906. oggpack_write(opb,info->end,24);
  103907. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103908. code with a partitioned book */
  103909. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103910. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103911. for(j=0;j<info->partitions;j++){
  103912. if(ilog(info->secondstages[j])>3){
  103913. oggpack_write(opb,info->secondstages[j],3);
  103914. oggpack_write(opb,1,1);
  103915. oggpack_write(opb,info->secondstages[j]>>3,5);
  103916. }else
  103917. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  103918. acc+=icount(info->secondstages[j]);
  103919. }
  103920. for(j=0;j<acc;j++)
  103921. oggpack_write(opb,info->booklist[j],8);
  103922. }
  103923. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  103924. int j,acc=0;
  103925. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  103926. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  103927. info->begin=oggpack_read(opb,24);
  103928. info->end=oggpack_read(opb,24);
  103929. info->grouping=oggpack_read(opb,24)+1;
  103930. info->partitions=oggpack_read(opb,6)+1;
  103931. info->groupbook=oggpack_read(opb,8);
  103932. for(j=0;j<info->partitions;j++){
  103933. int cascade=oggpack_read(opb,3);
  103934. if(oggpack_read(opb,1))
  103935. cascade|=(oggpack_read(opb,5)<<3);
  103936. info->secondstages[j]=cascade;
  103937. acc+=icount(cascade);
  103938. }
  103939. for(j=0;j<acc;j++)
  103940. info->booklist[j]=oggpack_read(opb,8);
  103941. if(info->groupbook>=ci->books)goto errout;
  103942. for(j=0;j<acc;j++)
  103943. if(info->booklist[j]>=ci->books)goto errout;
  103944. return(info);
  103945. errout:
  103946. res0_free_info(info);
  103947. return(NULL);
  103948. }
  103949. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  103950. vorbis_info_residue *vr){
  103951. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103952. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  103953. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  103954. int j,k,acc=0;
  103955. int dim;
  103956. int maxstage=0;
  103957. look->info=info;
  103958. look->parts=info->partitions;
  103959. look->fullbooks=ci->fullbooks;
  103960. look->phrasebook=ci->fullbooks+info->groupbook;
  103961. dim=look->phrasebook->dim;
  103962. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  103963. for(j=0;j<look->parts;j++){
  103964. int stages=ilog(info->secondstages[j]);
  103965. if(stages){
  103966. if(stages>maxstage)maxstage=stages;
  103967. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  103968. for(k=0;k<stages;k++)
  103969. if(info->secondstages[j]&(1<<k)){
  103970. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  103971. #ifdef TRAIN_RES
  103972. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  103973. sizeof(***look->training_data));
  103974. #endif
  103975. }
  103976. }
  103977. }
  103978. look->partvals=rint(pow((float)look->parts,(float)dim));
  103979. look->stages=maxstage;
  103980. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  103981. for(j=0;j<look->partvals;j++){
  103982. long val=j;
  103983. long mult=look->partvals/look->parts;
  103984. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  103985. for(k=0;k<dim;k++){
  103986. long deco=val/mult;
  103987. val-=deco*mult;
  103988. mult/=look->parts;
  103989. look->decodemap[j][k]=deco;
  103990. }
  103991. }
  103992. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103993. {
  103994. static int train_seq=0;
  103995. look->train_seq=train_seq++;
  103996. }
  103997. #endif
  103998. return(look);
  103999. }
  104000. static int local_book_besterror(codebook *book,float *a){
  104001. int dim=book->dim,i,k,o;
  104002. int best=0;
  104003. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104004. for(k=0,o=dim;k<dim;++k){
  104005. float val=a[--o];
  104006. i=tt->threshvals>>1;
  104007. if(val<tt->quantthresh[i]){
  104008. if(val<tt->quantthresh[i-1]){
  104009. for(--i;i>0;--i)
  104010. if(val>=tt->quantthresh[i-1])
  104011. break;
  104012. }
  104013. }else{
  104014. for(++i;i<tt->threshvals-1;++i)
  104015. if(val<tt->quantthresh[i])break;
  104016. }
  104017. best=(best*tt->quantvals)+tt->quantmap[i];
  104018. }
  104019. if(book->c->lengthlist[best]<=0){
  104020. const static_codebook *c=book->c;
  104021. int i,j;
  104022. float bestf=0.f;
  104023. float *e=book->valuelist;
  104024. best=-1;
  104025. for(i=0;i<book->entries;i++){
  104026. if(c->lengthlist[i]>0){
  104027. float thisx=0.f;
  104028. for(j=0;j<dim;j++){
  104029. float val=(e[j]-a[j]);
  104030. thisx+=val*val;
  104031. }
  104032. if(best==-1 || thisx<bestf){
  104033. bestf=thisx;
  104034. best=i;
  104035. }
  104036. }
  104037. e+=dim;
  104038. }
  104039. }
  104040. {
  104041. float *ptr=book->valuelist+best*dim;
  104042. for(i=0;i<dim;i++)
  104043. *a++ -= *ptr++;
  104044. }
  104045. return(best);
  104046. }
  104047. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104048. codebook *book,long *acc){
  104049. int i,bits=0;
  104050. int dim=book->dim;
  104051. int step=n/dim;
  104052. for(i=0;i<step;i++){
  104053. int entry=local_book_besterror(book,vec+i*dim);
  104054. #ifdef TRAIN_RES
  104055. acc[entry]++;
  104056. #endif
  104057. bits+=vorbis_book_encode(book,entry,opb);
  104058. }
  104059. return(bits);
  104060. }
  104061. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104062. float **in,int ch){
  104063. long i,j,k;
  104064. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104065. vorbis_info_residue0 *info=look->info;
  104066. int samples_per_partition=info->grouping;
  104067. int possible_partitions=info->partitions;
  104068. int n=info->end-info->begin;
  104069. int partvals=n/samples_per_partition;
  104070. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104071. float scale=100./samples_per_partition;
  104072. for(i=0;i<ch;i++){
  104073. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104074. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104075. }
  104076. for(i=0;i<partvals;i++){
  104077. int offset=i*samples_per_partition+info->begin;
  104078. for(j=0;j<ch;j++){
  104079. float max=0.;
  104080. float ent=0.;
  104081. for(k=0;k<samples_per_partition;k++){
  104082. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104083. ent+=fabs(rint(in[j][offset+k]));
  104084. }
  104085. ent*=scale;
  104086. for(k=0;k<possible_partitions-1;k++)
  104087. if(max<=info->classmetric1[k] &&
  104088. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104089. break;
  104090. partword[j][i]=k;
  104091. }
  104092. }
  104093. #ifdef TRAIN_RESAUX
  104094. {
  104095. FILE *of;
  104096. char buffer[80];
  104097. for(i=0;i<ch;i++){
  104098. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104099. of=fopen(buffer,"a");
  104100. for(j=0;j<partvals;j++)
  104101. fprintf(of,"%ld, ",partword[i][j]);
  104102. fprintf(of,"\n");
  104103. fclose(of);
  104104. }
  104105. }
  104106. #endif
  104107. look->frames++;
  104108. return(partword);
  104109. }
  104110. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104111. int ch){
  104112. long i,j,k,l;
  104113. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104114. vorbis_info_residue0 *info=look->info;
  104115. int samples_per_partition=info->grouping;
  104116. int possible_partitions=info->partitions;
  104117. int n=info->end-info->begin;
  104118. int partvals=n/samples_per_partition;
  104119. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104120. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104121. FILE *of;
  104122. char buffer[80];
  104123. #endif
  104124. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104125. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104126. for(i=0,l=info->begin/ch;i<partvals;i++){
  104127. float magmax=0.f;
  104128. float angmax=0.f;
  104129. for(j=0;j<samples_per_partition;j+=ch){
  104130. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104131. for(k=1;k<ch;k++)
  104132. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104133. l++;
  104134. }
  104135. for(j=0;j<possible_partitions-1;j++)
  104136. if(magmax<=info->classmetric1[j] &&
  104137. angmax<=info->classmetric2[j])
  104138. break;
  104139. partword[0][i]=j;
  104140. }
  104141. #ifdef TRAIN_RESAUX
  104142. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104143. of=fopen(buffer,"a");
  104144. for(i=0;i<partvals;i++)
  104145. fprintf(of,"%ld, ",partword[0][i]);
  104146. fprintf(of,"\n");
  104147. fclose(of);
  104148. #endif
  104149. look->frames++;
  104150. return(partword);
  104151. }
  104152. static int _01forward(oggpack_buffer *opb,
  104153. vorbis_block *vb,vorbis_look_residue *vl,
  104154. float **in,int ch,
  104155. long **partword,
  104156. int (*encode)(oggpack_buffer *,float *,int,
  104157. codebook *,long *)){
  104158. long i,j,k,s;
  104159. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104160. vorbis_info_residue0 *info=look->info;
  104161. int samples_per_partition=info->grouping;
  104162. int possible_partitions=info->partitions;
  104163. int partitions_per_word=look->phrasebook->dim;
  104164. int n=info->end-info->begin;
  104165. int partvals=n/samples_per_partition;
  104166. long resbits[128];
  104167. long resvals[128];
  104168. #ifdef TRAIN_RES
  104169. for(i=0;i<ch;i++)
  104170. for(j=info->begin;j<info->end;j++){
  104171. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104172. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104173. }
  104174. #endif
  104175. memset(resbits,0,sizeof(resbits));
  104176. memset(resvals,0,sizeof(resvals));
  104177. for(s=0;s<look->stages;s++){
  104178. for(i=0;i<partvals;){
  104179. if(s==0){
  104180. for(j=0;j<ch;j++){
  104181. long val=partword[j][i];
  104182. for(k=1;k<partitions_per_word;k++){
  104183. val*=possible_partitions;
  104184. if(i+k<partvals)
  104185. val+=partword[j][i+k];
  104186. }
  104187. if(val<look->phrasebook->entries)
  104188. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104189. #if 0 /*def TRAIN_RES*/
  104190. else
  104191. fprintf(stderr,"!");
  104192. #endif
  104193. }
  104194. }
  104195. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104196. long offset=i*samples_per_partition+info->begin;
  104197. for(j=0;j<ch;j++){
  104198. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104199. if(info->secondstages[partword[j][i]]&(1<<s)){
  104200. codebook *statebook=look->partbooks[partword[j][i]][s];
  104201. if(statebook){
  104202. int ret;
  104203. long *accumulator=NULL;
  104204. #ifdef TRAIN_RES
  104205. accumulator=look->training_data[s][partword[j][i]];
  104206. {
  104207. int l;
  104208. float *samples=in[j]+offset;
  104209. for(l=0;l<samples_per_partition;l++){
  104210. if(samples[l]<look->training_min[s][partword[j][i]])
  104211. look->training_min[s][partword[j][i]]=samples[l];
  104212. if(samples[l]>look->training_max[s][partword[j][i]])
  104213. look->training_max[s][partword[j][i]]=samples[l];
  104214. }
  104215. }
  104216. #endif
  104217. ret=encode(opb,in[j]+offset,samples_per_partition,
  104218. statebook,accumulator);
  104219. look->postbits+=ret;
  104220. resbits[partword[j][i]]+=ret;
  104221. }
  104222. }
  104223. }
  104224. }
  104225. }
  104226. }
  104227. return(0);
  104228. }
  104229. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104230. float **in,int ch,
  104231. long (*decodepart)(codebook *, float *,
  104232. oggpack_buffer *,int)){
  104233. long i,j,k,l,s;
  104234. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104235. vorbis_info_residue0 *info=look->info;
  104236. int samples_per_partition=info->grouping;
  104237. int partitions_per_word=look->phrasebook->dim;
  104238. int n=info->end-info->begin;
  104239. int partvals=n/samples_per_partition;
  104240. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104241. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104242. for(j=0;j<ch;j++)
  104243. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104244. for(s=0;s<look->stages;s++){
  104245. for(i=0,l=0;i<partvals;l++){
  104246. if(s==0){
  104247. for(j=0;j<ch;j++){
  104248. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104249. if(temp==-1)goto eopbreak;
  104250. partword[j][l]=look->decodemap[temp];
  104251. if(partword[j][l]==NULL)goto errout;
  104252. }
  104253. }
  104254. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104255. for(j=0;j<ch;j++){
  104256. long offset=info->begin+i*samples_per_partition;
  104257. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104258. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104259. if(stagebook){
  104260. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104261. samples_per_partition)==-1)goto eopbreak;
  104262. }
  104263. }
  104264. }
  104265. }
  104266. }
  104267. errout:
  104268. eopbreak:
  104269. return(0);
  104270. }
  104271. #if 0
  104272. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104273. float **in,int *nonzero,int ch){
  104274. int i,used=0;
  104275. for(i=0;i<ch;i++)
  104276. if(nonzero[i])
  104277. in[used++]=in[i];
  104278. if(used)
  104279. return(_01class(vb,vl,in,used));
  104280. else
  104281. return(0);
  104282. }
  104283. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104284. float **in,float **out,int *nonzero,int ch,
  104285. long **partword){
  104286. int i,j,used=0,n=vb->pcmend/2;
  104287. for(i=0;i<ch;i++)
  104288. if(nonzero[i]){
  104289. if(out)
  104290. for(j=0;j<n;j++)
  104291. out[i][j]+=in[i][j];
  104292. in[used++]=in[i];
  104293. }
  104294. if(used){
  104295. int ret=_01forward(vb,vl,in,used,partword,
  104296. _interleaved_encodepart);
  104297. if(out){
  104298. used=0;
  104299. for(i=0;i<ch;i++)
  104300. if(nonzero[i]){
  104301. for(j=0;j<n;j++)
  104302. out[i][j]-=in[used][j];
  104303. used++;
  104304. }
  104305. }
  104306. return(ret);
  104307. }else{
  104308. return(0);
  104309. }
  104310. }
  104311. #endif
  104312. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104313. float **in,int *nonzero,int ch){
  104314. int i,used=0;
  104315. for(i=0;i<ch;i++)
  104316. if(nonzero[i])
  104317. in[used++]=in[i];
  104318. if(used)
  104319. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104320. else
  104321. return(0);
  104322. }
  104323. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104324. float **in,float **out,int *nonzero,int ch,
  104325. long **partword){
  104326. int i,j,used=0,n=vb->pcmend/2;
  104327. for(i=0;i<ch;i++)
  104328. if(nonzero[i]){
  104329. if(out)
  104330. for(j=0;j<n;j++)
  104331. out[i][j]+=in[i][j];
  104332. in[used++]=in[i];
  104333. }
  104334. if(used){
  104335. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104336. if(out){
  104337. used=0;
  104338. for(i=0;i<ch;i++)
  104339. if(nonzero[i]){
  104340. for(j=0;j<n;j++)
  104341. out[i][j]-=in[used][j];
  104342. used++;
  104343. }
  104344. }
  104345. return(ret);
  104346. }else{
  104347. return(0);
  104348. }
  104349. }
  104350. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104351. float **in,int *nonzero,int ch){
  104352. int i,used=0;
  104353. for(i=0;i<ch;i++)
  104354. if(nonzero[i])
  104355. in[used++]=in[i];
  104356. if(used)
  104357. return(_01class(vb,vl,in,used));
  104358. else
  104359. return(0);
  104360. }
  104361. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104362. float **in,int *nonzero,int ch){
  104363. int i,used=0;
  104364. for(i=0;i<ch;i++)
  104365. if(nonzero[i])
  104366. in[used++]=in[i];
  104367. if(used)
  104368. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104369. else
  104370. return(0);
  104371. }
  104372. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104373. float **in,int *nonzero,int ch){
  104374. int i,used=0;
  104375. for(i=0;i<ch;i++)
  104376. if(nonzero[i])used++;
  104377. if(used)
  104378. return(_2class(vb,vl,in,ch));
  104379. else
  104380. return(0);
  104381. }
  104382. int res2_forward(oggpack_buffer *opb,
  104383. vorbis_block *vb,vorbis_look_residue *vl,
  104384. float **in,float **out,int *nonzero,int ch,
  104385. long **partword){
  104386. long i,j,k,n=vb->pcmend/2,used=0;
  104387. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104388. for(i=0;i<ch;i++){
  104389. float *pcm=in[i];
  104390. if(nonzero[i])used++;
  104391. for(j=0,k=i;j<n;j++,k+=ch)
  104392. work[k]=pcm[j];
  104393. }
  104394. if(used){
  104395. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104396. if(out){
  104397. for(i=0;i<ch;i++){
  104398. float *pcm=in[i];
  104399. float *sofar=out[i];
  104400. for(j=0,k=i;j<n;j++,k+=ch)
  104401. sofar[j]+=pcm[j]-work[k];
  104402. }
  104403. }
  104404. return(ret);
  104405. }else{
  104406. return(0);
  104407. }
  104408. }
  104409. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104410. float **in,int *nonzero,int ch){
  104411. long i,k,l,s;
  104412. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104413. vorbis_info_residue0 *info=look->info;
  104414. int samples_per_partition=info->grouping;
  104415. int partitions_per_word=look->phrasebook->dim;
  104416. int n=info->end-info->begin;
  104417. int partvals=n/samples_per_partition;
  104418. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104419. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104420. for(i=0;i<ch;i++)if(nonzero[i])break;
  104421. if(i==ch)return(0); /* no nonzero vectors */
  104422. for(s=0;s<look->stages;s++){
  104423. for(i=0,l=0;i<partvals;l++){
  104424. if(s==0){
  104425. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104426. if(temp==-1)goto eopbreak;
  104427. partword[l]=look->decodemap[temp];
  104428. if(partword[l]==NULL)goto errout;
  104429. }
  104430. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104431. if(info->secondstages[partword[l][k]]&(1<<s)){
  104432. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104433. if(stagebook){
  104434. if(vorbis_book_decodevv_add(stagebook,in,
  104435. i*samples_per_partition+info->begin,ch,
  104436. &vb->opb,samples_per_partition)==-1)
  104437. goto eopbreak;
  104438. }
  104439. }
  104440. }
  104441. }
  104442. errout:
  104443. eopbreak:
  104444. return(0);
  104445. }
  104446. vorbis_func_residue residue0_exportbundle={
  104447. NULL,
  104448. &res0_unpack,
  104449. &res0_look,
  104450. &res0_free_info,
  104451. &res0_free_look,
  104452. NULL,
  104453. NULL,
  104454. &res0_inverse
  104455. };
  104456. vorbis_func_residue residue1_exportbundle={
  104457. &res0_pack,
  104458. &res0_unpack,
  104459. &res0_look,
  104460. &res0_free_info,
  104461. &res0_free_look,
  104462. &res1_class,
  104463. &res1_forward,
  104464. &res1_inverse
  104465. };
  104466. vorbis_func_residue residue2_exportbundle={
  104467. &res0_pack,
  104468. &res0_unpack,
  104469. &res0_look,
  104470. &res0_free_info,
  104471. &res0_free_look,
  104472. &res2_class,
  104473. &res2_forward,
  104474. &res2_inverse
  104475. };
  104476. #endif
  104477. /*** End of inlined file: res0.c ***/
  104478. /*** Start of inlined file: sharedbook.c ***/
  104479. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104480. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104481. // tasks..
  104482. #if JUCE_MSVC
  104483. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104484. #endif
  104485. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104486. #if JUCE_USE_OGGVORBIS
  104487. #include <stdlib.h>
  104488. #include <math.h>
  104489. #include <string.h>
  104490. int _ilog(unsigned int v){
  104491. int ret=0;
  104492. while(v){
  104493. ret++;
  104494. v>>=1;
  104495. }
  104496. return(ret);
  104497. }
  104498. #define VQ_FEXP 10
  104499. #define VQ_FMAN 21
  104500. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104501. long _float32_pack(float val){
  104502. int sign=0;
  104503. long exp;
  104504. long mant;
  104505. if(val<0){
  104506. sign=0x80000000;
  104507. val= -val;
  104508. }
  104509. exp= floor(log(val)/log(2.f));
  104510. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104511. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104512. return(sign|exp|mant);
  104513. }
  104514. float _float32_unpack(long val){
  104515. double mant=val&0x1fffff;
  104516. int sign=val&0x80000000;
  104517. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104518. if(sign)mant= -mant;
  104519. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104520. }
  104521. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104522. long i,j,count=0;
  104523. ogg_uint32_t marker[33];
  104524. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104525. memset(marker,0,sizeof(marker));
  104526. for(i=0;i<n;i++){
  104527. long length=l[i];
  104528. if(length>0){
  104529. ogg_uint32_t entry=marker[length];
  104530. if(length<32 && (entry>>length)){
  104531. _ogg_free(r);
  104532. return(NULL);
  104533. }
  104534. r[count++]=entry;
  104535. {
  104536. for(j=length;j>0;j--){
  104537. if(marker[j]&1){
  104538. if(j==1)
  104539. marker[1]++;
  104540. else
  104541. marker[j]=marker[j-1]<<1;
  104542. break; /* invariant says next upper marker would already
  104543. have been moved if it was on the same path */
  104544. }
  104545. marker[j]++;
  104546. }
  104547. }
  104548. for(j=length+1;j<33;j++)
  104549. if((marker[j]>>1) == entry){
  104550. entry=marker[j];
  104551. marker[j]=marker[j-1]<<1;
  104552. }else
  104553. break;
  104554. }else
  104555. if(sparsecount==0)count++;
  104556. }
  104557. for(i=0,count=0;i<n;i++){
  104558. ogg_uint32_t temp=0;
  104559. for(j=0;j<l[i];j++){
  104560. temp<<=1;
  104561. temp|=(r[count]>>j)&1;
  104562. }
  104563. if(sparsecount){
  104564. if(l[i])
  104565. r[count++]=temp;
  104566. }else
  104567. r[count++]=temp;
  104568. }
  104569. return(r);
  104570. }
  104571. long _book_maptype1_quantvals(const static_codebook *b){
  104572. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104573. while(1){
  104574. long acc=1;
  104575. long acc1=1;
  104576. int i;
  104577. for(i=0;i<b->dim;i++){
  104578. acc*=vals;
  104579. acc1*=vals+1;
  104580. }
  104581. if(acc<=b->entries && acc1>b->entries){
  104582. return(vals);
  104583. }else{
  104584. if(acc>b->entries){
  104585. vals--;
  104586. }else{
  104587. vals++;
  104588. }
  104589. }
  104590. }
  104591. }
  104592. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104593. long j,k,count=0;
  104594. if(b->maptype==1 || b->maptype==2){
  104595. int quantvals;
  104596. float mindel=_float32_unpack(b->q_min);
  104597. float delta=_float32_unpack(b->q_delta);
  104598. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104599. switch(b->maptype){
  104600. case 1:
  104601. quantvals=_book_maptype1_quantvals(b);
  104602. for(j=0;j<b->entries;j++){
  104603. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104604. float last=0.f;
  104605. int indexdiv=1;
  104606. for(k=0;k<b->dim;k++){
  104607. int index= (j/indexdiv)%quantvals;
  104608. float val=b->quantlist[index];
  104609. val=fabs(val)*delta+mindel+last;
  104610. if(b->q_sequencep)last=val;
  104611. if(sparsemap)
  104612. r[sparsemap[count]*b->dim+k]=val;
  104613. else
  104614. r[count*b->dim+k]=val;
  104615. indexdiv*=quantvals;
  104616. }
  104617. count++;
  104618. }
  104619. }
  104620. break;
  104621. case 2:
  104622. for(j=0;j<b->entries;j++){
  104623. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104624. float last=0.f;
  104625. for(k=0;k<b->dim;k++){
  104626. float val=b->quantlist[j*b->dim+k];
  104627. val=fabs(val)*delta+mindel+last;
  104628. if(b->q_sequencep)last=val;
  104629. if(sparsemap)
  104630. r[sparsemap[count]*b->dim+k]=val;
  104631. else
  104632. r[count*b->dim+k]=val;
  104633. }
  104634. count++;
  104635. }
  104636. }
  104637. break;
  104638. }
  104639. return(r);
  104640. }
  104641. return(NULL);
  104642. }
  104643. void vorbis_staticbook_clear(static_codebook *b){
  104644. if(b->allocedp){
  104645. if(b->quantlist)_ogg_free(b->quantlist);
  104646. if(b->lengthlist)_ogg_free(b->lengthlist);
  104647. if(b->nearest_tree){
  104648. _ogg_free(b->nearest_tree->ptr0);
  104649. _ogg_free(b->nearest_tree->ptr1);
  104650. _ogg_free(b->nearest_tree->p);
  104651. _ogg_free(b->nearest_tree->q);
  104652. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104653. _ogg_free(b->nearest_tree);
  104654. }
  104655. if(b->thresh_tree){
  104656. _ogg_free(b->thresh_tree->quantthresh);
  104657. _ogg_free(b->thresh_tree->quantmap);
  104658. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104659. _ogg_free(b->thresh_tree);
  104660. }
  104661. memset(b,0,sizeof(*b));
  104662. }
  104663. }
  104664. void vorbis_staticbook_destroy(static_codebook *b){
  104665. if(b->allocedp){
  104666. vorbis_staticbook_clear(b);
  104667. _ogg_free(b);
  104668. }
  104669. }
  104670. void vorbis_book_clear(codebook *b){
  104671. if(b->valuelist)_ogg_free(b->valuelist);
  104672. if(b->codelist)_ogg_free(b->codelist);
  104673. if(b->dec_index)_ogg_free(b->dec_index);
  104674. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104675. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104676. memset(b,0,sizeof(*b));
  104677. }
  104678. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104679. memset(c,0,sizeof(*c));
  104680. c->c=s;
  104681. c->entries=s->entries;
  104682. c->used_entries=s->entries;
  104683. c->dim=s->dim;
  104684. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104685. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104686. return(0);
  104687. }
  104688. static int sort32a(const void *a,const void *b){
  104689. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104690. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104691. }
  104692. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104693. int i,j,n=0,tabn;
  104694. int *sortindex;
  104695. memset(c,0,sizeof(*c));
  104696. for(i=0;i<s->entries;i++)
  104697. if(s->lengthlist[i]>0)
  104698. n++;
  104699. c->entries=s->entries;
  104700. c->used_entries=n;
  104701. c->dim=s->dim;
  104702. {
  104703. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104704. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104705. if(codes==NULL)goto err_out;
  104706. for(i=0;i<n;i++){
  104707. codes[i]=ogg_bitreverse(codes[i]);
  104708. codep[i]=codes+i;
  104709. }
  104710. qsort(codep,n,sizeof(*codep),sort32a);
  104711. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104712. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104713. for(i=0;i<n;i++){
  104714. int position=codep[i]-codes;
  104715. sortindex[position]=i;
  104716. }
  104717. for(i=0;i<n;i++)
  104718. c->codelist[sortindex[i]]=codes[i];
  104719. _ogg_free(codes);
  104720. }
  104721. c->valuelist=_book_unquantize(s,n,sortindex);
  104722. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104723. for(n=0,i=0;i<s->entries;i++)
  104724. if(s->lengthlist[i]>0)
  104725. c->dec_index[sortindex[n++]]=i;
  104726. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104727. for(n=0,i=0;i<s->entries;i++)
  104728. if(s->lengthlist[i]>0)
  104729. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104730. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104731. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104732. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104733. tabn=1<<c->dec_firsttablen;
  104734. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104735. c->dec_maxlength=0;
  104736. for(i=0;i<n;i++){
  104737. if(c->dec_maxlength<c->dec_codelengths[i])
  104738. c->dec_maxlength=c->dec_codelengths[i];
  104739. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104740. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104741. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104742. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104743. }
  104744. }
  104745. {
  104746. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104747. long lo=0,hi=0;
  104748. for(i=0;i<tabn;i++){
  104749. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104750. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104751. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104752. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104753. {
  104754. unsigned long loval=lo;
  104755. unsigned long hival=n-hi;
  104756. if(loval>0x7fff)loval=0x7fff;
  104757. if(hival>0x7fff)hival=0x7fff;
  104758. c->dec_firsttable[ogg_bitreverse(word)]=
  104759. 0x80000000UL | (loval<<15) | hival;
  104760. }
  104761. }
  104762. }
  104763. }
  104764. return(0);
  104765. err_out:
  104766. vorbis_book_clear(c);
  104767. return(-1);
  104768. }
  104769. static float _dist(int el,float *ref, float *b,int step){
  104770. int i;
  104771. float acc=0.f;
  104772. for(i=0;i<el;i++){
  104773. float val=(ref[i]-b[i*step]);
  104774. acc+=val*val;
  104775. }
  104776. return(acc);
  104777. }
  104778. int _best(codebook *book, float *a, int step){
  104779. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104780. #if 0
  104781. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104782. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104783. #endif
  104784. int dim=book->dim;
  104785. int k,o;
  104786. if(tt){
  104787. int index=0,i;
  104788. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104789. i=tt->threshvals>>1;
  104790. if(a[o]<tt->quantthresh[i]){
  104791. for(;i>0;i--)
  104792. if(a[o]>=tt->quantthresh[i-1])
  104793. break;
  104794. }else{
  104795. for(i++;i<tt->threshvals-1;i++)
  104796. if(a[o]<tt->quantthresh[i])break;
  104797. }
  104798. index=(index*tt->quantvals)+tt->quantmap[i];
  104799. }
  104800. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104801. use a decision tree after all
  104802. and fall through*/
  104803. return(index);
  104804. }
  104805. #if 0
  104806. if(pt){
  104807. const static_codebook *c=book->c;
  104808. int i,besti=-1;
  104809. float best=0.f;
  104810. int entry=0;
  104811. if(c->q_sequencep){
  104812. int pv;
  104813. long mul=1;
  104814. float qlast=0;
  104815. for(k=0,o=0;k<dim;k++,o+=step){
  104816. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104817. if(pv<0 || pv>=pt->mapentries)break;
  104818. entry+=pt->pigeonmap[pv]*mul;
  104819. mul*=pt->quantvals;
  104820. qlast+=pv*pt->del+pt->min;
  104821. }
  104822. }else{
  104823. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104824. int pv=(int)((a[o]-pt->min)/pt->del);
  104825. if(pv<0 || pv>=pt->mapentries)break;
  104826. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104827. }
  104828. }
  104829. if(k==dim && pt->fitlength[entry]){
  104830. long *list=pt->fitlist+pt->fitmap[entry];
  104831. for(i=0;i<pt->fitlength[entry];i++){
  104832. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104833. if(besti==-1 || this<best){
  104834. best=this;
  104835. besti=list[i];
  104836. }
  104837. }
  104838. return(besti);
  104839. }
  104840. }
  104841. if(nt){
  104842. while(1){
  104843. float c=0.f;
  104844. float *p=book->valuelist+nt->p[ptr];
  104845. float *q=book->valuelist+nt->q[ptr];
  104846. for(k=0,o=0;k<dim;k++,o+=step)
  104847. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104848. if(c>0.f) /* in A */
  104849. ptr= -nt->ptr0[ptr];
  104850. else /* in B */
  104851. ptr= -nt->ptr1[ptr];
  104852. if(ptr<=0)break;
  104853. }
  104854. return(-ptr);
  104855. }
  104856. #endif
  104857. {
  104858. const static_codebook *c=book->c;
  104859. int i,besti=-1;
  104860. float best=0.f;
  104861. float *e=book->valuelist;
  104862. for(i=0;i<book->entries;i++){
  104863. if(c->lengthlist[i]>0){
  104864. float thisx=_dist(dim,e,a,step);
  104865. if(besti==-1 || thisx<best){
  104866. best=thisx;
  104867. besti=i;
  104868. }
  104869. }
  104870. e+=dim;
  104871. }
  104872. return(besti);
  104873. }
  104874. }
  104875. long vorbis_book_codeword(codebook *book,int entry){
  104876. if(book->c) /* only use with encode; decode optimizations are
  104877. allowed to break this */
  104878. return book->codelist[entry];
  104879. return -1;
  104880. }
  104881. long vorbis_book_codelen(codebook *book,int entry){
  104882. if(book->c) /* only use with encode; decode optimizations are
  104883. allowed to break this */
  104884. return book->c->lengthlist[entry];
  104885. return -1;
  104886. }
  104887. #ifdef _V_SELFTEST
  104888. #include <stdio.h>
  104889. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104890. static long partial_quantlist1[]={0,7,2};
  104891. static_codebook test1={
  104892. 4,16,
  104893. NULL,
  104894. 0,
  104895. 0,0,0,0,
  104896. NULL,
  104897. NULL,NULL
  104898. };
  104899. static float *test1_result=NULL;
  104900. static_codebook test2={
  104901. 4,3,
  104902. NULL,
  104903. 2,
  104904. -533200896,1611661312,4,0,
  104905. full_quantlist1,
  104906. NULL,NULL
  104907. };
  104908. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104909. static_codebook test3={
  104910. 4,3,
  104911. NULL,
  104912. 2,
  104913. -533200896,1611661312,4,1,
  104914. full_quantlist1,
  104915. NULL,NULL
  104916. };
  104917. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  104918. static_codebook test4={
  104919. 3,27,
  104920. NULL,
  104921. 1,
  104922. -533200896,1611661312,4,0,
  104923. partial_quantlist1,
  104924. NULL,NULL
  104925. };
  104926. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  104927. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  104928. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  104929. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  104930. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  104931. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  104932. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  104933. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  104934. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  104935. static_codebook test5={
  104936. 3,27,
  104937. NULL,
  104938. 1,
  104939. -533200896,1611661312,4,1,
  104940. partial_quantlist1,
  104941. NULL,NULL
  104942. };
  104943. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  104944. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  104945. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  104946. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  104947. -3, 1, 5, 4, 8,12, -1, 3, 7,
  104948. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  104949. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  104950. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  104951. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  104952. void run_test(static_codebook *b,float *comp){
  104953. float *out=_book_unquantize(b,b->entries,NULL);
  104954. int i;
  104955. if(comp){
  104956. if(!out){
  104957. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  104958. exit(1);
  104959. }
  104960. for(i=0;i<b->entries*b->dim;i++)
  104961. if(fabs(out[i]-comp[i])>.0001){
  104962. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  104963. "position %d, %g != %g\n",i,out[i],comp[i]);
  104964. exit(1);
  104965. }
  104966. }else{
  104967. if(out){
  104968. fprintf(stderr,"_book_unquantize returned a value array: \n"
  104969. " correct result should have been NULL\n");
  104970. exit(1);
  104971. }
  104972. }
  104973. }
  104974. int main(){
  104975. fprintf(stderr,"Dequant test 1... ");
  104976. run_test(&test1,test1_result);
  104977. fprintf(stderr,"OK\nDequant test 2... ");
  104978. run_test(&test2,test2_result);
  104979. fprintf(stderr,"OK\nDequant test 3... ");
  104980. run_test(&test3,test3_result);
  104981. fprintf(stderr,"OK\nDequant test 4... ");
  104982. run_test(&test4,test4_result);
  104983. fprintf(stderr,"OK\nDequant test 5... ");
  104984. run_test(&test5,test5_result);
  104985. fprintf(stderr,"OK\n\n");
  104986. return(0);
  104987. }
  104988. #endif
  104989. #endif
  104990. /*** End of inlined file: sharedbook.c ***/
  104991. /*** Start of inlined file: smallft.c ***/
  104992. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104993. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104994. // tasks..
  104995. #if JUCE_MSVC
  104996. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104997. #endif
  104998. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104999. #if JUCE_USE_OGGVORBIS
  105000. #include <stdlib.h>
  105001. #include <string.h>
  105002. #include <math.h>
  105003. static void drfti1(int n, float *wa, int *ifac){
  105004. static int ntryh[4] = { 4,2,3,5 };
  105005. static float tpi = 6.28318530717958648f;
  105006. float arg,argh,argld,fi;
  105007. int ntry=0,i,j=-1;
  105008. int k1, l1, l2, ib;
  105009. int ld, ii, ip, is, nq, nr;
  105010. int ido, ipm, nfm1;
  105011. int nl=n;
  105012. int nf=0;
  105013. L101:
  105014. j++;
  105015. if (j < 4)
  105016. ntry=ntryh[j];
  105017. else
  105018. ntry+=2;
  105019. L104:
  105020. nq=nl/ntry;
  105021. nr=nl-ntry*nq;
  105022. if (nr!=0) goto L101;
  105023. nf++;
  105024. ifac[nf+1]=ntry;
  105025. nl=nq;
  105026. if(ntry!=2)goto L107;
  105027. if(nf==1)goto L107;
  105028. for (i=1;i<nf;i++){
  105029. ib=nf-i+1;
  105030. ifac[ib+1]=ifac[ib];
  105031. }
  105032. ifac[2] = 2;
  105033. L107:
  105034. if(nl!=1)goto L104;
  105035. ifac[0]=n;
  105036. ifac[1]=nf;
  105037. argh=tpi/n;
  105038. is=0;
  105039. nfm1=nf-1;
  105040. l1=1;
  105041. if(nfm1==0)return;
  105042. for (k1=0;k1<nfm1;k1++){
  105043. ip=ifac[k1+2];
  105044. ld=0;
  105045. l2=l1*ip;
  105046. ido=n/l2;
  105047. ipm=ip-1;
  105048. for (j=0;j<ipm;j++){
  105049. ld+=l1;
  105050. i=is;
  105051. argld=(float)ld*argh;
  105052. fi=0.f;
  105053. for (ii=2;ii<ido;ii+=2){
  105054. fi+=1.f;
  105055. arg=fi*argld;
  105056. wa[i++]=cos(arg);
  105057. wa[i++]=sin(arg);
  105058. }
  105059. is+=ido;
  105060. }
  105061. l1=l2;
  105062. }
  105063. }
  105064. static void fdrffti(int n, float *wsave, int *ifac){
  105065. if (n == 1) return;
  105066. drfti1(n, wsave+n, ifac);
  105067. }
  105068. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105069. int i,k;
  105070. float ti2,tr2;
  105071. int t0,t1,t2,t3,t4,t5,t6;
  105072. t1=0;
  105073. t0=(t2=l1*ido);
  105074. t3=ido<<1;
  105075. for(k=0;k<l1;k++){
  105076. ch[t1<<1]=cc[t1]+cc[t2];
  105077. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105078. t1+=ido;
  105079. t2+=ido;
  105080. }
  105081. if(ido<2)return;
  105082. if(ido==2)goto L105;
  105083. t1=0;
  105084. t2=t0;
  105085. for(k=0;k<l1;k++){
  105086. t3=t2;
  105087. t4=(t1<<1)+(ido<<1);
  105088. t5=t1;
  105089. t6=t1+t1;
  105090. for(i=2;i<ido;i+=2){
  105091. t3+=2;
  105092. t4-=2;
  105093. t5+=2;
  105094. t6+=2;
  105095. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105096. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105097. ch[t6]=cc[t5]+ti2;
  105098. ch[t4]=ti2-cc[t5];
  105099. ch[t6-1]=cc[t5-1]+tr2;
  105100. ch[t4-1]=cc[t5-1]-tr2;
  105101. }
  105102. t1+=ido;
  105103. t2+=ido;
  105104. }
  105105. if(ido%2==1)return;
  105106. L105:
  105107. t3=(t2=(t1=ido)-1);
  105108. t2+=t0;
  105109. for(k=0;k<l1;k++){
  105110. ch[t1]=-cc[t2];
  105111. ch[t1-1]=cc[t3];
  105112. t1+=ido<<1;
  105113. t2+=ido;
  105114. t3+=ido;
  105115. }
  105116. }
  105117. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105118. float *wa2,float *wa3){
  105119. static float hsqt2 = .70710678118654752f;
  105120. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105121. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105122. t0=l1*ido;
  105123. t1=t0;
  105124. t4=t1<<1;
  105125. t2=t1+(t1<<1);
  105126. t3=0;
  105127. for(k=0;k<l1;k++){
  105128. tr1=cc[t1]+cc[t2];
  105129. tr2=cc[t3]+cc[t4];
  105130. ch[t5=t3<<2]=tr1+tr2;
  105131. ch[(ido<<2)+t5-1]=tr2-tr1;
  105132. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105133. ch[t5]=cc[t2]-cc[t1];
  105134. t1+=ido;
  105135. t2+=ido;
  105136. t3+=ido;
  105137. t4+=ido;
  105138. }
  105139. if(ido<2)return;
  105140. if(ido==2)goto L105;
  105141. t1=0;
  105142. for(k=0;k<l1;k++){
  105143. t2=t1;
  105144. t4=t1<<2;
  105145. t5=(t6=ido<<1)+t4;
  105146. for(i=2;i<ido;i+=2){
  105147. t3=(t2+=2);
  105148. t4+=2;
  105149. t5-=2;
  105150. t3+=t0;
  105151. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105152. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105153. t3+=t0;
  105154. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105155. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105156. t3+=t0;
  105157. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105158. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105159. tr1=cr2+cr4;
  105160. tr4=cr4-cr2;
  105161. ti1=ci2+ci4;
  105162. ti4=ci2-ci4;
  105163. ti2=cc[t2]+ci3;
  105164. ti3=cc[t2]-ci3;
  105165. tr2=cc[t2-1]+cr3;
  105166. tr3=cc[t2-1]-cr3;
  105167. ch[t4-1]=tr1+tr2;
  105168. ch[t4]=ti1+ti2;
  105169. ch[t5-1]=tr3-ti4;
  105170. ch[t5]=tr4-ti3;
  105171. ch[t4+t6-1]=ti4+tr3;
  105172. ch[t4+t6]=tr4+ti3;
  105173. ch[t5+t6-1]=tr2-tr1;
  105174. ch[t5+t6]=ti1-ti2;
  105175. }
  105176. t1+=ido;
  105177. }
  105178. if(ido&1)return;
  105179. L105:
  105180. t2=(t1=t0+ido-1)+(t0<<1);
  105181. t3=ido<<2;
  105182. t4=ido;
  105183. t5=ido<<1;
  105184. t6=ido;
  105185. for(k=0;k<l1;k++){
  105186. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105187. tr1=hsqt2*(cc[t1]-cc[t2]);
  105188. ch[t4-1]=tr1+cc[t6-1];
  105189. ch[t4+t5-1]=cc[t6-1]-tr1;
  105190. ch[t4]=ti1-cc[t1+t0];
  105191. ch[t4+t5]=ti1+cc[t1+t0];
  105192. t1+=ido;
  105193. t2+=ido;
  105194. t4+=t3;
  105195. t6+=ido;
  105196. }
  105197. }
  105198. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105199. float *c2,float *ch,float *ch2,float *wa){
  105200. static float tpi=6.283185307179586f;
  105201. int idij,ipph,i,j,k,l,ic,ik,is;
  105202. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105203. float dc2,ai1,ai2,ar1,ar2,ds2;
  105204. int nbd;
  105205. float dcp,arg,dsp,ar1h,ar2h;
  105206. int idp2,ipp2;
  105207. arg=tpi/(float)ip;
  105208. dcp=cos(arg);
  105209. dsp=sin(arg);
  105210. ipph=(ip+1)>>1;
  105211. ipp2=ip;
  105212. idp2=ido;
  105213. nbd=(ido-1)>>1;
  105214. t0=l1*ido;
  105215. t10=ip*ido;
  105216. if(ido==1)goto L119;
  105217. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105218. t1=0;
  105219. for(j=1;j<ip;j++){
  105220. t1+=t0;
  105221. t2=t1;
  105222. for(k=0;k<l1;k++){
  105223. ch[t2]=c1[t2];
  105224. t2+=ido;
  105225. }
  105226. }
  105227. is=-ido;
  105228. t1=0;
  105229. if(nbd>l1){
  105230. for(j=1;j<ip;j++){
  105231. t1+=t0;
  105232. is+=ido;
  105233. t2= -ido+t1;
  105234. for(k=0;k<l1;k++){
  105235. idij=is-1;
  105236. t2+=ido;
  105237. t3=t2;
  105238. for(i=2;i<ido;i+=2){
  105239. idij+=2;
  105240. t3+=2;
  105241. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105242. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105243. }
  105244. }
  105245. }
  105246. }else{
  105247. for(j=1;j<ip;j++){
  105248. is+=ido;
  105249. idij=is-1;
  105250. t1+=t0;
  105251. t2=t1;
  105252. for(i=2;i<ido;i+=2){
  105253. idij+=2;
  105254. t2+=2;
  105255. t3=t2;
  105256. for(k=0;k<l1;k++){
  105257. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105258. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105259. t3+=ido;
  105260. }
  105261. }
  105262. }
  105263. }
  105264. t1=0;
  105265. t2=ipp2*t0;
  105266. if(nbd<l1){
  105267. for(j=1;j<ipph;j++){
  105268. t1+=t0;
  105269. t2-=t0;
  105270. t3=t1;
  105271. t4=t2;
  105272. for(i=2;i<ido;i+=2){
  105273. t3+=2;
  105274. t4+=2;
  105275. t5=t3-ido;
  105276. t6=t4-ido;
  105277. for(k=0;k<l1;k++){
  105278. t5+=ido;
  105279. t6+=ido;
  105280. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105281. c1[t6-1]=ch[t5]-ch[t6];
  105282. c1[t5]=ch[t5]+ch[t6];
  105283. c1[t6]=ch[t6-1]-ch[t5-1];
  105284. }
  105285. }
  105286. }
  105287. }else{
  105288. for(j=1;j<ipph;j++){
  105289. t1+=t0;
  105290. t2-=t0;
  105291. t3=t1;
  105292. t4=t2;
  105293. for(k=0;k<l1;k++){
  105294. t5=t3;
  105295. t6=t4;
  105296. for(i=2;i<ido;i+=2){
  105297. t5+=2;
  105298. t6+=2;
  105299. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105300. c1[t6-1]=ch[t5]-ch[t6];
  105301. c1[t5]=ch[t5]+ch[t6];
  105302. c1[t6]=ch[t6-1]-ch[t5-1];
  105303. }
  105304. t3+=ido;
  105305. t4+=ido;
  105306. }
  105307. }
  105308. }
  105309. L119:
  105310. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105311. t1=0;
  105312. t2=ipp2*idl1;
  105313. for(j=1;j<ipph;j++){
  105314. t1+=t0;
  105315. t2-=t0;
  105316. t3=t1-ido;
  105317. t4=t2-ido;
  105318. for(k=0;k<l1;k++){
  105319. t3+=ido;
  105320. t4+=ido;
  105321. c1[t3]=ch[t3]+ch[t4];
  105322. c1[t4]=ch[t4]-ch[t3];
  105323. }
  105324. }
  105325. ar1=1.f;
  105326. ai1=0.f;
  105327. t1=0;
  105328. t2=ipp2*idl1;
  105329. t3=(ip-1)*idl1;
  105330. for(l=1;l<ipph;l++){
  105331. t1+=idl1;
  105332. t2-=idl1;
  105333. ar1h=dcp*ar1-dsp*ai1;
  105334. ai1=dcp*ai1+dsp*ar1;
  105335. ar1=ar1h;
  105336. t4=t1;
  105337. t5=t2;
  105338. t6=t3;
  105339. t7=idl1;
  105340. for(ik=0;ik<idl1;ik++){
  105341. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105342. ch2[t5++]=ai1*c2[t6++];
  105343. }
  105344. dc2=ar1;
  105345. ds2=ai1;
  105346. ar2=ar1;
  105347. ai2=ai1;
  105348. t4=idl1;
  105349. t5=(ipp2-1)*idl1;
  105350. for(j=2;j<ipph;j++){
  105351. t4+=idl1;
  105352. t5-=idl1;
  105353. ar2h=dc2*ar2-ds2*ai2;
  105354. ai2=dc2*ai2+ds2*ar2;
  105355. ar2=ar2h;
  105356. t6=t1;
  105357. t7=t2;
  105358. t8=t4;
  105359. t9=t5;
  105360. for(ik=0;ik<idl1;ik++){
  105361. ch2[t6++]+=ar2*c2[t8++];
  105362. ch2[t7++]+=ai2*c2[t9++];
  105363. }
  105364. }
  105365. }
  105366. t1=0;
  105367. for(j=1;j<ipph;j++){
  105368. t1+=idl1;
  105369. t2=t1;
  105370. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105371. }
  105372. if(ido<l1)goto L132;
  105373. t1=0;
  105374. t2=0;
  105375. for(k=0;k<l1;k++){
  105376. t3=t1;
  105377. t4=t2;
  105378. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105379. t1+=ido;
  105380. t2+=t10;
  105381. }
  105382. goto L135;
  105383. L132:
  105384. for(i=0;i<ido;i++){
  105385. t1=i;
  105386. t2=i;
  105387. for(k=0;k<l1;k++){
  105388. cc[t2]=ch[t1];
  105389. t1+=ido;
  105390. t2+=t10;
  105391. }
  105392. }
  105393. L135:
  105394. t1=0;
  105395. t2=ido<<1;
  105396. t3=0;
  105397. t4=ipp2*t0;
  105398. for(j=1;j<ipph;j++){
  105399. t1+=t2;
  105400. t3+=t0;
  105401. t4-=t0;
  105402. t5=t1;
  105403. t6=t3;
  105404. t7=t4;
  105405. for(k=0;k<l1;k++){
  105406. cc[t5-1]=ch[t6];
  105407. cc[t5]=ch[t7];
  105408. t5+=t10;
  105409. t6+=ido;
  105410. t7+=ido;
  105411. }
  105412. }
  105413. if(ido==1)return;
  105414. if(nbd<l1)goto L141;
  105415. t1=-ido;
  105416. t3=0;
  105417. t4=0;
  105418. t5=ipp2*t0;
  105419. for(j=1;j<ipph;j++){
  105420. t1+=t2;
  105421. t3+=t2;
  105422. t4+=t0;
  105423. t5-=t0;
  105424. t6=t1;
  105425. t7=t3;
  105426. t8=t4;
  105427. t9=t5;
  105428. for(k=0;k<l1;k++){
  105429. for(i=2;i<ido;i+=2){
  105430. ic=idp2-i;
  105431. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105432. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105433. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105434. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105435. }
  105436. t6+=t10;
  105437. t7+=t10;
  105438. t8+=ido;
  105439. t9+=ido;
  105440. }
  105441. }
  105442. return;
  105443. L141:
  105444. t1=-ido;
  105445. t3=0;
  105446. t4=0;
  105447. t5=ipp2*t0;
  105448. for(j=1;j<ipph;j++){
  105449. t1+=t2;
  105450. t3+=t2;
  105451. t4+=t0;
  105452. t5-=t0;
  105453. for(i=2;i<ido;i+=2){
  105454. t6=idp2+t1-i;
  105455. t7=i+t3;
  105456. t8=i+t4;
  105457. t9=i+t5;
  105458. for(k=0;k<l1;k++){
  105459. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105460. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105461. cc[t7]=ch[t8]+ch[t9];
  105462. cc[t6]=ch[t9]-ch[t8];
  105463. t6+=t10;
  105464. t7+=t10;
  105465. t8+=ido;
  105466. t9+=ido;
  105467. }
  105468. }
  105469. }
  105470. }
  105471. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105472. int i,k1,l1,l2;
  105473. int na,kh,nf;
  105474. int ip,iw,ido,idl1,ix2,ix3;
  105475. nf=ifac[1];
  105476. na=1;
  105477. l2=n;
  105478. iw=n;
  105479. for(k1=0;k1<nf;k1++){
  105480. kh=nf-k1;
  105481. ip=ifac[kh+1];
  105482. l1=l2/ip;
  105483. ido=n/l2;
  105484. idl1=ido*l1;
  105485. iw-=(ip-1)*ido;
  105486. na=1-na;
  105487. if(ip!=4)goto L102;
  105488. ix2=iw+ido;
  105489. ix3=ix2+ido;
  105490. if(na!=0)
  105491. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105492. else
  105493. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105494. goto L110;
  105495. L102:
  105496. if(ip!=2)goto L104;
  105497. if(na!=0)goto L103;
  105498. dradf2(ido,l1,c,ch,wa+iw-1);
  105499. goto L110;
  105500. L103:
  105501. dradf2(ido,l1,ch,c,wa+iw-1);
  105502. goto L110;
  105503. L104:
  105504. if(ido==1)na=1-na;
  105505. if(na!=0)goto L109;
  105506. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105507. na=1;
  105508. goto L110;
  105509. L109:
  105510. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105511. na=0;
  105512. L110:
  105513. l2=l1;
  105514. }
  105515. if(na==1)return;
  105516. for(i=0;i<n;i++)c[i]=ch[i];
  105517. }
  105518. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105519. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105520. float ti2,tr2;
  105521. t0=l1*ido;
  105522. t1=0;
  105523. t2=0;
  105524. t3=(ido<<1)-1;
  105525. for(k=0;k<l1;k++){
  105526. ch[t1]=cc[t2]+cc[t3+t2];
  105527. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105528. t2=(t1+=ido)<<1;
  105529. }
  105530. if(ido<2)return;
  105531. if(ido==2)goto L105;
  105532. t1=0;
  105533. t2=0;
  105534. for(k=0;k<l1;k++){
  105535. t3=t1;
  105536. t5=(t4=t2)+(ido<<1);
  105537. t6=t0+t1;
  105538. for(i=2;i<ido;i+=2){
  105539. t3+=2;
  105540. t4+=2;
  105541. t5-=2;
  105542. t6+=2;
  105543. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105544. tr2=cc[t4-1]-cc[t5-1];
  105545. ch[t3]=cc[t4]-cc[t5];
  105546. ti2=cc[t4]+cc[t5];
  105547. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105548. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105549. }
  105550. t2=(t1+=ido)<<1;
  105551. }
  105552. if(ido%2==1)return;
  105553. L105:
  105554. t1=ido-1;
  105555. t2=ido-1;
  105556. for(k=0;k<l1;k++){
  105557. ch[t1]=cc[t2]+cc[t2];
  105558. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105559. t1+=ido;
  105560. t2+=ido<<1;
  105561. }
  105562. }
  105563. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105564. float *wa2){
  105565. static float taur = -.5f;
  105566. static float taui = .8660254037844386f;
  105567. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105568. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105569. t0=l1*ido;
  105570. t1=0;
  105571. t2=t0<<1;
  105572. t3=ido<<1;
  105573. t4=ido+(ido<<1);
  105574. t5=0;
  105575. for(k=0;k<l1;k++){
  105576. tr2=cc[t3-1]+cc[t3-1];
  105577. cr2=cc[t5]+(taur*tr2);
  105578. ch[t1]=cc[t5]+tr2;
  105579. ci3=taui*(cc[t3]+cc[t3]);
  105580. ch[t1+t0]=cr2-ci3;
  105581. ch[t1+t2]=cr2+ci3;
  105582. t1+=ido;
  105583. t3+=t4;
  105584. t5+=t4;
  105585. }
  105586. if(ido==1)return;
  105587. t1=0;
  105588. t3=ido<<1;
  105589. for(k=0;k<l1;k++){
  105590. t7=t1+(t1<<1);
  105591. t6=(t5=t7+t3);
  105592. t8=t1;
  105593. t10=(t9=t1+t0)+t0;
  105594. for(i=2;i<ido;i+=2){
  105595. t5+=2;
  105596. t6-=2;
  105597. t7+=2;
  105598. t8+=2;
  105599. t9+=2;
  105600. t10+=2;
  105601. tr2=cc[t5-1]+cc[t6-1];
  105602. cr2=cc[t7-1]+(taur*tr2);
  105603. ch[t8-1]=cc[t7-1]+tr2;
  105604. ti2=cc[t5]-cc[t6];
  105605. ci2=cc[t7]+(taur*ti2);
  105606. ch[t8]=cc[t7]+ti2;
  105607. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105608. ci3=taui*(cc[t5]+cc[t6]);
  105609. dr2=cr2-ci3;
  105610. dr3=cr2+ci3;
  105611. di2=ci2+cr3;
  105612. di3=ci2-cr3;
  105613. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105614. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105615. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105616. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105617. }
  105618. t1+=ido;
  105619. }
  105620. }
  105621. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105622. float *wa2,float *wa3){
  105623. static float sqrt2=1.414213562373095f;
  105624. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105625. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105626. t0=l1*ido;
  105627. t1=0;
  105628. t2=ido<<2;
  105629. t3=0;
  105630. t6=ido<<1;
  105631. for(k=0;k<l1;k++){
  105632. t4=t3+t6;
  105633. t5=t1;
  105634. tr3=cc[t4-1]+cc[t4-1];
  105635. tr4=cc[t4]+cc[t4];
  105636. tr1=cc[t3]-cc[(t4+=t6)-1];
  105637. tr2=cc[t3]+cc[t4-1];
  105638. ch[t5]=tr2+tr3;
  105639. ch[t5+=t0]=tr1-tr4;
  105640. ch[t5+=t0]=tr2-tr3;
  105641. ch[t5+=t0]=tr1+tr4;
  105642. t1+=ido;
  105643. t3+=t2;
  105644. }
  105645. if(ido<2)return;
  105646. if(ido==2)goto L105;
  105647. t1=0;
  105648. for(k=0;k<l1;k++){
  105649. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105650. t7=t1;
  105651. for(i=2;i<ido;i+=2){
  105652. t2+=2;
  105653. t3+=2;
  105654. t4-=2;
  105655. t5-=2;
  105656. t7+=2;
  105657. ti1=cc[t2]+cc[t5];
  105658. ti2=cc[t2]-cc[t5];
  105659. ti3=cc[t3]-cc[t4];
  105660. tr4=cc[t3]+cc[t4];
  105661. tr1=cc[t2-1]-cc[t5-1];
  105662. tr2=cc[t2-1]+cc[t5-1];
  105663. ti4=cc[t3-1]-cc[t4-1];
  105664. tr3=cc[t3-1]+cc[t4-1];
  105665. ch[t7-1]=tr2+tr3;
  105666. cr3=tr2-tr3;
  105667. ch[t7]=ti2+ti3;
  105668. ci3=ti2-ti3;
  105669. cr2=tr1-tr4;
  105670. cr4=tr1+tr4;
  105671. ci2=ti1+ti4;
  105672. ci4=ti1-ti4;
  105673. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105674. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105675. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105676. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105677. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105678. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105679. }
  105680. t1+=ido;
  105681. }
  105682. if(ido%2 == 1)return;
  105683. L105:
  105684. t1=ido;
  105685. t2=ido<<2;
  105686. t3=ido-1;
  105687. t4=ido+(ido<<1);
  105688. for(k=0;k<l1;k++){
  105689. t5=t3;
  105690. ti1=cc[t1]+cc[t4];
  105691. ti2=cc[t4]-cc[t1];
  105692. tr1=cc[t1-1]-cc[t4-1];
  105693. tr2=cc[t1-1]+cc[t4-1];
  105694. ch[t5]=tr2+tr2;
  105695. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105696. ch[t5+=t0]=ti2+ti2;
  105697. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105698. t3+=ido;
  105699. t1+=t2;
  105700. t4+=t2;
  105701. }
  105702. }
  105703. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105704. float *c2,float *ch,float *ch2,float *wa){
  105705. static float tpi=6.283185307179586f;
  105706. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105707. t11,t12;
  105708. float dc2,ai1,ai2,ar1,ar2,ds2;
  105709. int nbd;
  105710. float dcp,arg,dsp,ar1h,ar2h;
  105711. int ipp2;
  105712. t10=ip*ido;
  105713. t0=l1*ido;
  105714. arg=tpi/(float)ip;
  105715. dcp=cos(arg);
  105716. dsp=sin(arg);
  105717. nbd=(ido-1)>>1;
  105718. ipp2=ip;
  105719. ipph=(ip+1)>>1;
  105720. if(ido<l1)goto L103;
  105721. t1=0;
  105722. t2=0;
  105723. for(k=0;k<l1;k++){
  105724. t3=t1;
  105725. t4=t2;
  105726. for(i=0;i<ido;i++){
  105727. ch[t3]=cc[t4];
  105728. t3++;
  105729. t4++;
  105730. }
  105731. t1+=ido;
  105732. t2+=t10;
  105733. }
  105734. goto L106;
  105735. L103:
  105736. t1=0;
  105737. for(i=0;i<ido;i++){
  105738. t2=t1;
  105739. t3=t1;
  105740. for(k=0;k<l1;k++){
  105741. ch[t2]=cc[t3];
  105742. t2+=ido;
  105743. t3+=t10;
  105744. }
  105745. t1++;
  105746. }
  105747. L106:
  105748. t1=0;
  105749. t2=ipp2*t0;
  105750. t7=(t5=ido<<1);
  105751. for(j=1;j<ipph;j++){
  105752. t1+=t0;
  105753. t2-=t0;
  105754. t3=t1;
  105755. t4=t2;
  105756. t6=t5;
  105757. for(k=0;k<l1;k++){
  105758. ch[t3]=cc[t6-1]+cc[t6-1];
  105759. ch[t4]=cc[t6]+cc[t6];
  105760. t3+=ido;
  105761. t4+=ido;
  105762. t6+=t10;
  105763. }
  105764. t5+=t7;
  105765. }
  105766. if (ido == 1)goto L116;
  105767. if(nbd<l1)goto L112;
  105768. t1=0;
  105769. t2=ipp2*t0;
  105770. t7=0;
  105771. for(j=1;j<ipph;j++){
  105772. t1+=t0;
  105773. t2-=t0;
  105774. t3=t1;
  105775. t4=t2;
  105776. t7+=(ido<<1);
  105777. t8=t7;
  105778. for(k=0;k<l1;k++){
  105779. t5=t3;
  105780. t6=t4;
  105781. t9=t8;
  105782. t11=t8;
  105783. for(i=2;i<ido;i+=2){
  105784. t5+=2;
  105785. t6+=2;
  105786. t9+=2;
  105787. t11-=2;
  105788. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105789. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105790. ch[t5]=cc[t9]-cc[t11];
  105791. ch[t6]=cc[t9]+cc[t11];
  105792. }
  105793. t3+=ido;
  105794. t4+=ido;
  105795. t8+=t10;
  105796. }
  105797. }
  105798. goto L116;
  105799. L112:
  105800. t1=0;
  105801. t2=ipp2*t0;
  105802. t7=0;
  105803. for(j=1;j<ipph;j++){
  105804. t1+=t0;
  105805. t2-=t0;
  105806. t3=t1;
  105807. t4=t2;
  105808. t7+=(ido<<1);
  105809. t8=t7;
  105810. t9=t7;
  105811. for(i=2;i<ido;i+=2){
  105812. t3+=2;
  105813. t4+=2;
  105814. t8+=2;
  105815. t9-=2;
  105816. t5=t3;
  105817. t6=t4;
  105818. t11=t8;
  105819. t12=t9;
  105820. for(k=0;k<l1;k++){
  105821. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105822. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105823. ch[t5]=cc[t11]-cc[t12];
  105824. ch[t6]=cc[t11]+cc[t12];
  105825. t5+=ido;
  105826. t6+=ido;
  105827. t11+=t10;
  105828. t12+=t10;
  105829. }
  105830. }
  105831. }
  105832. L116:
  105833. ar1=1.f;
  105834. ai1=0.f;
  105835. t1=0;
  105836. t9=(t2=ipp2*idl1);
  105837. t3=(ip-1)*idl1;
  105838. for(l=1;l<ipph;l++){
  105839. t1+=idl1;
  105840. t2-=idl1;
  105841. ar1h=dcp*ar1-dsp*ai1;
  105842. ai1=dcp*ai1+dsp*ar1;
  105843. ar1=ar1h;
  105844. t4=t1;
  105845. t5=t2;
  105846. t6=0;
  105847. t7=idl1;
  105848. t8=t3;
  105849. for(ik=0;ik<idl1;ik++){
  105850. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105851. c2[t5++]=ai1*ch2[t8++];
  105852. }
  105853. dc2=ar1;
  105854. ds2=ai1;
  105855. ar2=ar1;
  105856. ai2=ai1;
  105857. t6=idl1;
  105858. t7=t9-idl1;
  105859. for(j=2;j<ipph;j++){
  105860. t6+=idl1;
  105861. t7-=idl1;
  105862. ar2h=dc2*ar2-ds2*ai2;
  105863. ai2=dc2*ai2+ds2*ar2;
  105864. ar2=ar2h;
  105865. t4=t1;
  105866. t5=t2;
  105867. t11=t6;
  105868. t12=t7;
  105869. for(ik=0;ik<idl1;ik++){
  105870. c2[t4++]+=ar2*ch2[t11++];
  105871. c2[t5++]+=ai2*ch2[t12++];
  105872. }
  105873. }
  105874. }
  105875. t1=0;
  105876. for(j=1;j<ipph;j++){
  105877. t1+=idl1;
  105878. t2=t1;
  105879. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105880. }
  105881. t1=0;
  105882. t2=ipp2*t0;
  105883. for(j=1;j<ipph;j++){
  105884. t1+=t0;
  105885. t2-=t0;
  105886. t3=t1;
  105887. t4=t2;
  105888. for(k=0;k<l1;k++){
  105889. ch[t3]=c1[t3]-c1[t4];
  105890. ch[t4]=c1[t3]+c1[t4];
  105891. t3+=ido;
  105892. t4+=ido;
  105893. }
  105894. }
  105895. if(ido==1)goto L132;
  105896. if(nbd<l1)goto L128;
  105897. t1=0;
  105898. t2=ipp2*t0;
  105899. for(j=1;j<ipph;j++){
  105900. t1+=t0;
  105901. t2-=t0;
  105902. t3=t1;
  105903. t4=t2;
  105904. for(k=0;k<l1;k++){
  105905. t5=t3;
  105906. t6=t4;
  105907. for(i=2;i<ido;i+=2){
  105908. t5+=2;
  105909. t6+=2;
  105910. ch[t5-1]=c1[t5-1]-c1[t6];
  105911. ch[t6-1]=c1[t5-1]+c1[t6];
  105912. ch[t5]=c1[t5]+c1[t6-1];
  105913. ch[t6]=c1[t5]-c1[t6-1];
  105914. }
  105915. t3+=ido;
  105916. t4+=ido;
  105917. }
  105918. }
  105919. goto L132;
  105920. L128:
  105921. t1=0;
  105922. t2=ipp2*t0;
  105923. for(j=1;j<ipph;j++){
  105924. t1+=t0;
  105925. t2-=t0;
  105926. t3=t1;
  105927. t4=t2;
  105928. for(i=2;i<ido;i+=2){
  105929. t3+=2;
  105930. t4+=2;
  105931. t5=t3;
  105932. t6=t4;
  105933. for(k=0;k<l1;k++){
  105934. ch[t5-1]=c1[t5-1]-c1[t6];
  105935. ch[t6-1]=c1[t5-1]+c1[t6];
  105936. ch[t5]=c1[t5]+c1[t6-1];
  105937. ch[t6]=c1[t5]-c1[t6-1];
  105938. t5+=ido;
  105939. t6+=ido;
  105940. }
  105941. }
  105942. }
  105943. L132:
  105944. if(ido==1)return;
  105945. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105946. t1=0;
  105947. for(j=1;j<ip;j++){
  105948. t2=(t1+=t0);
  105949. for(k=0;k<l1;k++){
  105950. c1[t2]=ch[t2];
  105951. t2+=ido;
  105952. }
  105953. }
  105954. if(nbd>l1)goto L139;
  105955. is= -ido-1;
  105956. t1=0;
  105957. for(j=1;j<ip;j++){
  105958. is+=ido;
  105959. t1+=t0;
  105960. idij=is;
  105961. t2=t1;
  105962. for(i=2;i<ido;i+=2){
  105963. t2+=2;
  105964. idij+=2;
  105965. t3=t2;
  105966. for(k=0;k<l1;k++){
  105967. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105968. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105969. t3+=ido;
  105970. }
  105971. }
  105972. }
  105973. return;
  105974. L139:
  105975. is= -ido-1;
  105976. t1=0;
  105977. for(j=1;j<ip;j++){
  105978. is+=ido;
  105979. t1+=t0;
  105980. t2=t1;
  105981. for(k=0;k<l1;k++){
  105982. idij=is;
  105983. t3=t2;
  105984. for(i=2;i<ido;i+=2){
  105985. idij+=2;
  105986. t3+=2;
  105987. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105988. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105989. }
  105990. t2+=ido;
  105991. }
  105992. }
  105993. }
  105994. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  105995. int i,k1,l1,l2;
  105996. int na;
  105997. int nf,ip,iw,ix2,ix3,ido,idl1;
  105998. nf=ifac[1];
  105999. na=0;
  106000. l1=1;
  106001. iw=1;
  106002. for(k1=0;k1<nf;k1++){
  106003. ip=ifac[k1 + 2];
  106004. l2=ip*l1;
  106005. ido=n/l2;
  106006. idl1=ido*l1;
  106007. if(ip!=4)goto L103;
  106008. ix2=iw+ido;
  106009. ix3=ix2+ido;
  106010. if(na!=0)
  106011. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106012. else
  106013. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106014. na=1-na;
  106015. goto L115;
  106016. L103:
  106017. if(ip!=2)goto L106;
  106018. if(na!=0)
  106019. dradb2(ido,l1,ch,c,wa+iw-1);
  106020. else
  106021. dradb2(ido,l1,c,ch,wa+iw-1);
  106022. na=1-na;
  106023. goto L115;
  106024. L106:
  106025. if(ip!=3)goto L109;
  106026. ix2=iw+ido;
  106027. if(na!=0)
  106028. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106029. else
  106030. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106031. na=1-na;
  106032. goto L115;
  106033. L109:
  106034. if(na!=0)
  106035. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106036. else
  106037. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106038. if(ido==1)na=1-na;
  106039. L115:
  106040. l1=l2;
  106041. iw+=(ip-1)*ido;
  106042. }
  106043. if(na==0)return;
  106044. for(i=0;i<n;i++)c[i]=ch[i];
  106045. }
  106046. void drft_forward(drft_lookup *l,float *data){
  106047. if(l->n==1)return;
  106048. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106049. }
  106050. void drft_backward(drft_lookup *l,float *data){
  106051. if (l->n==1)return;
  106052. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106053. }
  106054. void drft_init(drft_lookup *l,int n){
  106055. l->n=n;
  106056. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106057. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106058. fdrffti(n, l->trigcache, l->splitcache);
  106059. }
  106060. void drft_clear(drft_lookup *l){
  106061. if(l){
  106062. if(l->trigcache)_ogg_free(l->trigcache);
  106063. if(l->splitcache)_ogg_free(l->splitcache);
  106064. memset(l,0,sizeof(*l));
  106065. }
  106066. }
  106067. #endif
  106068. /*** End of inlined file: smallft.c ***/
  106069. /*** Start of inlined file: synthesis.c ***/
  106070. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106071. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106072. // tasks..
  106073. #if JUCE_MSVC
  106074. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106075. #endif
  106076. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106077. #if JUCE_USE_OGGVORBIS
  106078. #include <stdio.h>
  106079. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106080. vorbis_dsp_state *vd=vb->vd;
  106081. private_state *b=(private_state*)vd->backend_state;
  106082. vorbis_info *vi=vd->vi;
  106083. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106084. oggpack_buffer *opb=&vb->opb;
  106085. int type,mode,i;
  106086. _vorbis_block_ripcord(vb);
  106087. oggpack_readinit(opb,op->packet,op->bytes);
  106088. if(oggpack_read(opb,1)!=0){
  106089. return(OV_ENOTAUDIO);
  106090. }
  106091. mode=oggpack_read(opb,b->modebits);
  106092. if(mode==-1)return(OV_EBADPACKET);
  106093. vb->mode=mode;
  106094. vb->W=ci->mode_param[mode]->blockflag;
  106095. if(vb->W){
  106096. vb->lW=oggpack_read(opb,1);
  106097. vb->nW=oggpack_read(opb,1);
  106098. if(vb->nW==-1) return(OV_EBADPACKET);
  106099. }else{
  106100. vb->lW=0;
  106101. vb->nW=0;
  106102. }
  106103. vb->granulepos=op->granulepos;
  106104. vb->sequence=op->packetno;
  106105. vb->eofflag=op->e_o_s;
  106106. vb->pcmend=ci->blocksizes[vb->W];
  106107. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106108. for(i=0;i<vi->channels;i++)
  106109. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106110. type=ci->map_type[ci->mode_param[mode]->mapping];
  106111. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106112. mapping]));
  106113. }
  106114. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106115. vorbis_dsp_state *vd=vb->vd;
  106116. private_state *b=(private_state*)vd->backend_state;
  106117. vorbis_info *vi=vd->vi;
  106118. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106119. oggpack_buffer *opb=&vb->opb;
  106120. int mode;
  106121. _vorbis_block_ripcord(vb);
  106122. oggpack_readinit(opb,op->packet,op->bytes);
  106123. if(oggpack_read(opb,1)!=0){
  106124. return(OV_ENOTAUDIO);
  106125. }
  106126. mode=oggpack_read(opb,b->modebits);
  106127. if(mode==-1)return(OV_EBADPACKET);
  106128. vb->mode=mode;
  106129. vb->W=ci->mode_param[mode]->blockflag;
  106130. if(vb->W){
  106131. vb->lW=oggpack_read(opb,1);
  106132. vb->nW=oggpack_read(opb,1);
  106133. if(vb->nW==-1) return(OV_EBADPACKET);
  106134. }else{
  106135. vb->lW=0;
  106136. vb->nW=0;
  106137. }
  106138. vb->granulepos=op->granulepos;
  106139. vb->sequence=op->packetno;
  106140. vb->eofflag=op->e_o_s;
  106141. vb->pcmend=0;
  106142. vb->pcm=NULL;
  106143. return(0);
  106144. }
  106145. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106146. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106147. oggpack_buffer opb;
  106148. int mode;
  106149. oggpack_readinit(&opb,op->packet,op->bytes);
  106150. if(oggpack_read(&opb,1)!=0){
  106151. return(OV_ENOTAUDIO);
  106152. }
  106153. {
  106154. int modebits=0;
  106155. int v=ci->modes;
  106156. while(v>1){
  106157. modebits++;
  106158. v>>=1;
  106159. }
  106160. mode=oggpack_read(&opb,modebits);
  106161. }
  106162. if(mode==-1)return(OV_EBADPACKET);
  106163. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106164. }
  106165. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106166. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106167. if(ci->blocksizes[0]<=64 && flag)return -1;
  106168. ci->halfrate_flag=(flag?1:0);
  106169. return 0;
  106170. }
  106171. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106172. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106173. return ci->halfrate_flag;
  106174. }
  106175. #endif
  106176. /*** End of inlined file: synthesis.c ***/
  106177. /*** Start of inlined file: vorbisenc.c ***/
  106178. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106179. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106180. // tasks..
  106181. #if JUCE_MSVC
  106182. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106183. #endif
  106184. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106185. #if JUCE_USE_OGGVORBIS
  106186. #include <stdlib.h>
  106187. #include <string.h>
  106188. #include <math.h>
  106189. typedef struct {
  106190. static_codebook *books[12][3];
  106191. } static_bookblock;
  106192. typedef struct {
  106193. int res_type;
  106194. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106195. vorbis_info_residue0 *res;
  106196. static_codebook *book_aux;
  106197. static_codebook *book_aux_managed;
  106198. static_bookblock *books_base;
  106199. static_bookblock *books_base_managed;
  106200. } vorbis_residue_template;
  106201. typedef struct {
  106202. vorbis_info_mapping0 *map;
  106203. vorbis_residue_template *res;
  106204. } vorbis_mapping_template;
  106205. typedef struct vp_adjblock{
  106206. int block[P_BANDS];
  106207. } vp_adjblock;
  106208. typedef struct {
  106209. int data[NOISE_COMPAND_LEVELS];
  106210. } compandblock;
  106211. typedef struct {
  106212. int att[P_NOISECURVES];
  106213. float boost;
  106214. float decay;
  106215. } att3;
  106216. typedef struct { int data[P_NOISECURVES]; } adj3;
  106217. typedef struct {
  106218. int pre[PACKETBLOBS];
  106219. int post[PACKETBLOBS];
  106220. float kHz[PACKETBLOBS];
  106221. float lowpasskHz[PACKETBLOBS];
  106222. } adj_stereo;
  106223. typedef struct {
  106224. int lo;
  106225. int hi;
  106226. int fixed;
  106227. } noiseguard;
  106228. typedef struct {
  106229. int data[P_NOISECURVES][17];
  106230. } noise3;
  106231. typedef struct {
  106232. int mappings;
  106233. double *rate_mapping;
  106234. double *quality_mapping;
  106235. int coupling_restriction;
  106236. long samplerate_min_restriction;
  106237. long samplerate_max_restriction;
  106238. int *blocksize_short;
  106239. int *blocksize_long;
  106240. att3 *psy_tone_masteratt;
  106241. int *psy_tone_0dB;
  106242. int *psy_tone_dBsuppress;
  106243. vp_adjblock *psy_tone_adj_impulse;
  106244. vp_adjblock *psy_tone_adj_long;
  106245. vp_adjblock *psy_tone_adj_other;
  106246. noiseguard *psy_noiseguards;
  106247. noise3 *psy_noise_bias_impulse;
  106248. noise3 *psy_noise_bias_padding;
  106249. noise3 *psy_noise_bias_trans;
  106250. noise3 *psy_noise_bias_long;
  106251. int *psy_noise_dBsuppress;
  106252. compandblock *psy_noise_compand;
  106253. double *psy_noise_compand_short_mapping;
  106254. double *psy_noise_compand_long_mapping;
  106255. int *psy_noise_normal_start[2];
  106256. int *psy_noise_normal_partition[2];
  106257. double *psy_noise_normal_thresh;
  106258. int *psy_ath_float;
  106259. int *psy_ath_abs;
  106260. double *psy_lowpass;
  106261. vorbis_info_psy_global *global_params;
  106262. double *global_mapping;
  106263. adj_stereo *stereo_modes;
  106264. static_codebook ***floor_books;
  106265. vorbis_info_floor1 *floor_params;
  106266. int *floor_short_mapping;
  106267. int *floor_long_mapping;
  106268. vorbis_mapping_template *maps;
  106269. } ve_setup_data_template;
  106270. static vorbis_info_mode _mode_template[2]={
  106271. {0,0,0,0},
  106272. {1,0,0,1}
  106273. };
  106274. static vorbis_info_mapping0 _map_nominal[2]={
  106275. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106276. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106277. };
  106278. /*** Start of inlined file: setup_44.h ***/
  106279. /*** Start of inlined file: floor_all.h ***/
  106280. /*** Start of inlined file: floor_books.h ***/
  106281. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106282. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106283. };
  106284. static static_codebook _huff_book_line_256x7_0sub1 = {
  106285. 1, 9,
  106286. _huff_lengthlist_line_256x7_0sub1,
  106287. 0, 0, 0, 0, 0,
  106288. NULL,
  106289. NULL,
  106290. NULL,
  106291. NULL,
  106292. 0
  106293. };
  106294. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106296. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106297. };
  106298. static static_codebook _huff_book_line_256x7_0sub2 = {
  106299. 1, 25,
  106300. _huff_lengthlist_line_256x7_0sub2,
  106301. 0, 0, 0, 0, 0,
  106302. NULL,
  106303. NULL,
  106304. NULL,
  106305. NULL,
  106306. 0
  106307. };
  106308. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106311. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106312. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106313. };
  106314. static static_codebook _huff_book_line_256x7_0sub3 = {
  106315. 1, 64,
  106316. _huff_lengthlist_line_256x7_0sub3,
  106317. 0, 0, 0, 0, 0,
  106318. NULL,
  106319. NULL,
  106320. NULL,
  106321. NULL,
  106322. 0
  106323. };
  106324. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106325. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106326. };
  106327. static static_codebook _huff_book_line_256x7_1sub1 = {
  106328. 1, 9,
  106329. _huff_lengthlist_line_256x7_1sub1,
  106330. 0, 0, 0, 0, 0,
  106331. NULL,
  106332. NULL,
  106333. NULL,
  106334. NULL,
  106335. 0
  106336. };
  106337. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106339. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106340. };
  106341. static static_codebook _huff_book_line_256x7_1sub2 = {
  106342. 1, 25,
  106343. _huff_lengthlist_line_256x7_1sub2,
  106344. 0, 0, 0, 0, 0,
  106345. NULL,
  106346. NULL,
  106347. NULL,
  106348. NULL,
  106349. 0
  106350. };
  106351. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106354. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106355. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106356. };
  106357. static static_codebook _huff_book_line_256x7_1sub3 = {
  106358. 1, 64,
  106359. _huff_lengthlist_line_256x7_1sub3,
  106360. 0, 0, 0, 0, 0,
  106361. NULL,
  106362. NULL,
  106363. NULL,
  106364. NULL,
  106365. 0
  106366. };
  106367. static long _huff_lengthlist_line_256x7_class0[] = {
  106368. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106369. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106370. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106371. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106372. };
  106373. static static_codebook _huff_book_line_256x7_class0 = {
  106374. 1, 64,
  106375. _huff_lengthlist_line_256x7_class0,
  106376. 0, 0, 0, 0, 0,
  106377. NULL,
  106378. NULL,
  106379. NULL,
  106380. NULL,
  106381. 0
  106382. };
  106383. static long _huff_lengthlist_line_256x7_class1[] = {
  106384. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106385. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106386. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106387. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106388. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106389. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106390. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106391. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106392. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106393. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106394. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106395. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106396. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106397. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106398. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106399. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106400. };
  106401. static static_codebook _huff_book_line_256x7_class1 = {
  106402. 1, 256,
  106403. _huff_lengthlist_line_256x7_class1,
  106404. 0, 0, 0, 0, 0,
  106405. NULL,
  106406. NULL,
  106407. NULL,
  106408. NULL,
  106409. 0
  106410. };
  106411. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106412. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106413. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106414. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106415. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106416. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106417. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106418. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106419. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106420. };
  106421. static static_codebook _huff_book_line_512x17_0sub0 = {
  106422. 1, 128,
  106423. _huff_lengthlist_line_512x17_0sub0,
  106424. 0, 0, 0, 0, 0,
  106425. NULL,
  106426. NULL,
  106427. NULL,
  106428. NULL,
  106429. 0
  106430. };
  106431. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106432. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106433. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106434. };
  106435. static static_codebook _huff_book_line_512x17_1sub0 = {
  106436. 1, 32,
  106437. _huff_lengthlist_line_512x17_1sub0,
  106438. 0, 0, 0, 0, 0,
  106439. NULL,
  106440. NULL,
  106441. NULL,
  106442. NULL,
  106443. 0
  106444. };
  106445. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106448. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106449. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106450. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106451. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106452. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106453. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106454. };
  106455. static static_codebook _huff_book_line_512x17_1sub1 = {
  106456. 1, 128,
  106457. _huff_lengthlist_line_512x17_1sub1,
  106458. 0, 0, 0, 0, 0,
  106459. NULL,
  106460. NULL,
  106461. NULL,
  106462. NULL,
  106463. 0
  106464. };
  106465. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106466. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106467. 5, 3,
  106468. };
  106469. static static_codebook _huff_book_line_512x17_2sub1 = {
  106470. 1, 18,
  106471. _huff_lengthlist_line_512x17_2sub1,
  106472. 0, 0, 0, 0, 0,
  106473. NULL,
  106474. NULL,
  106475. NULL,
  106476. NULL,
  106477. 0
  106478. };
  106479. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106481. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106482. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106483. 9, 8,
  106484. };
  106485. static static_codebook _huff_book_line_512x17_2sub2 = {
  106486. 1, 50,
  106487. _huff_lengthlist_line_512x17_2sub2,
  106488. 0, 0, 0, 0, 0,
  106489. NULL,
  106490. NULL,
  106491. NULL,
  106492. NULL,
  106493. 0
  106494. };
  106495. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106499. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106500. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106501. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106502. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106503. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106504. };
  106505. static static_codebook _huff_book_line_512x17_2sub3 = {
  106506. 1, 128,
  106507. _huff_lengthlist_line_512x17_2sub3,
  106508. 0, 0, 0, 0, 0,
  106509. NULL,
  106510. NULL,
  106511. NULL,
  106512. NULL,
  106513. 0
  106514. };
  106515. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106516. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106517. 5, 5,
  106518. };
  106519. static static_codebook _huff_book_line_512x17_3sub1 = {
  106520. 1, 18,
  106521. _huff_lengthlist_line_512x17_3sub1,
  106522. 0, 0, 0, 0, 0,
  106523. NULL,
  106524. NULL,
  106525. NULL,
  106526. NULL,
  106527. 0
  106528. };
  106529. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106531. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106532. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106533. 11,14,
  106534. };
  106535. static static_codebook _huff_book_line_512x17_3sub2 = {
  106536. 1, 50,
  106537. _huff_lengthlist_line_512x17_3sub2,
  106538. 0, 0, 0, 0, 0,
  106539. NULL,
  106540. NULL,
  106541. NULL,
  106542. NULL,
  106543. 0
  106544. };
  106545. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106549. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106550. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106551. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106552. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106553. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106554. };
  106555. static static_codebook _huff_book_line_512x17_3sub3 = {
  106556. 1, 128,
  106557. _huff_lengthlist_line_512x17_3sub3,
  106558. 0, 0, 0, 0, 0,
  106559. NULL,
  106560. NULL,
  106561. NULL,
  106562. NULL,
  106563. 0
  106564. };
  106565. static long _huff_lengthlist_line_512x17_class1[] = {
  106566. 1, 2, 3, 6, 5, 4, 7, 7,
  106567. };
  106568. static static_codebook _huff_book_line_512x17_class1 = {
  106569. 1, 8,
  106570. _huff_lengthlist_line_512x17_class1,
  106571. 0, 0, 0, 0, 0,
  106572. NULL,
  106573. NULL,
  106574. NULL,
  106575. NULL,
  106576. 0
  106577. };
  106578. static long _huff_lengthlist_line_512x17_class2[] = {
  106579. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106580. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106581. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106582. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106583. };
  106584. static static_codebook _huff_book_line_512x17_class2 = {
  106585. 1, 64,
  106586. _huff_lengthlist_line_512x17_class2,
  106587. 0, 0, 0, 0, 0,
  106588. NULL,
  106589. NULL,
  106590. NULL,
  106591. NULL,
  106592. 0
  106593. };
  106594. static long _huff_lengthlist_line_512x17_class3[] = {
  106595. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106596. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106597. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106598. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106599. };
  106600. static static_codebook _huff_book_line_512x17_class3 = {
  106601. 1, 64,
  106602. _huff_lengthlist_line_512x17_class3,
  106603. 0, 0, 0, 0, 0,
  106604. NULL,
  106605. NULL,
  106606. NULL,
  106607. NULL,
  106608. 0
  106609. };
  106610. static long _huff_lengthlist_line_128x4_class0[] = {
  106611. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106612. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106613. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106614. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106615. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106616. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106617. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106618. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106619. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106620. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106621. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106622. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106623. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106624. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106625. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106626. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106627. };
  106628. static static_codebook _huff_book_line_128x4_class0 = {
  106629. 1, 256,
  106630. _huff_lengthlist_line_128x4_class0,
  106631. 0, 0, 0, 0, 0,
  106632. NULL,
  106633. NULL,
  106634. NULL,
  106635. NULL,
  106636. 0
  106637. };
  106638. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106639. 2, 2, 2, 2,
  106640. };
  106641. static static_codebook _huff_book_line_128x4_0sub0 = {
  106642. 1, 4,
  106643. _huff_lengthlist_line_128x4_0sub0,
  106644. 0, 0, 0, 0, 0,
  106645. NULL,
  106646. NULL,
  106647. NULL,
  106648. NULL,
  106649. 0
  106650. };
  106651. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106652. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106653. };
  106654. static static_codebook _huff_book_line_128x4_0sub1 = {
  106655. 1, 10,
  106656. _huff_lengthlist_line_128x4_0sub1,
  106657. 0, 0, 0, 0, 0,
  106658. NULL,
  106659. NULL,
  106660. NULL,
  106661. NULL,
  106662. 0
  106663. };
  106664. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106666. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106667. };
  106668. static static_codebook _huff_book_line_128x4_0sub2 = {
  106669. 1, 25,
  106670. _huff_lengthlist_line_128x4_0sub2,
  106671. 0, 0, 0, 0, 0,
  106672. NULL,
  106673. NULL,
  106674. NULL,
  106675. NULL,
  106676. 0
  106677. };
  106678. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106681. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106682. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106683. };
  106684. static static_codebook _huff_book_line_128x4_0sub3 = {
  106685. 1, 64,
  106686. _huff_lengthlist_line_128x4_0sub3,
  106687. 0, 0, 0, 0, 0,
  106688. NULL,
  106689. NULL,
  106690. NULL,
  106691. NULL,
  106692. 0
  106693. };
  106694. static long _huff_lengthlist_line_256x4_class0[] = {
  106695. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106696. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106697. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106698. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106699. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106700. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106701. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106702. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106703. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106704. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106705. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106706. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106707. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106708. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106709. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106710. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106711. };
  106712. static static_codebook _huff_book_line_256x4_class0 = {
  106713. 1, 256,
  106714. _huff_lengthlist_line_256x4_class0,
  106715. 0, 0, 0, 0, 0,
  106716. NULL,
  106717. NULL,
  106718. NULL,
  106719. NULL,
  106720. 0
  106721. };
  106722. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106723. 2, 2, 2, 2,
  106724. };
  106725. static static_codebook _huff_book_line_256x4_0sub0 = {
  106726. 1, 4,
  106727. _huff_lengthlist_line_256x4_0sub0,
  106728. 0, 0, 0, 0, 0,
  106729. NULL,
  106730. NULL,
  106731. NULL,
  106732. NULL,
  106733. 0
  106734. };
  106735. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106736. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106737. };
  106738. static static_codebook _huff_book_line_256x4_0sub1 = {
  106739. 1, 10,
  106740. _huff_lengthlist_line_256x4_0sub1,
  106741. 0, 0, 0, 0, 0,
  106742. NULL,
  106743. NULL,
  106744. NULL,
  106745. NULL,
  106746. 0
  106747. };
  106748. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106750. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106751. };
  106752. static static_codebook _huff_book_line_256x4_0sub2 = {
  106753. 1, 25,
  106754. _huff_lengthlist_line_256x4_0sub2,
  106755. 0, 0, 0, 0, 0,
  106756. NULL,
  106757. NULL,
  106758. NULL,
  106759. NULL,
  106760. 0
  106761. };
  106762. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106765. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106766. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106767. };
  106768. static static_codebook _huff_book_line_256x4_0sub3 = {
  106769. 1, 64,
  106770. _huff_lengthlist_line_256x4_0sub3,
  106771. 0, 0, 0, 0, 0,
  106772. NULL,
  106773. NULL,
  106774. NULL,
  106775. NULL,
  106776. 0
  106777. };
  106778. static long _huff_lengthlist_line_128x7_class0[] = {
  106779. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106780. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106781. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106782. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106783. };
  106784. static static_codebook _huff_book_line_128x7_class0 = {
  106785. 1, 64,
  106786. _huff_lengthlist_line_128x7_class0,
  106787. 0, 0, 0, 0, 0,
  106788. NULL,
  106789. NULL,
  106790. NULL,
  106791. NULL,
  106792. 0
  106793. };
  106794. static long _huff_lengthlist_line_128x7_class1[] = {
  106795. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106796. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106797. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106798. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106799. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106800. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106801. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106802. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106803. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106804. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106805. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106806. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106807. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106808. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106809. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106810. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106811. };
  106812. static static_codebook _huff_book_line_128x7_class1 = {
  106813. 1, 256,
  106814. _huff_lengthlist_line_128x7_class1,
  106815. 0, 0, 0, 0, 0,
  106816. NULL,
  106817. NULL,
  106818. NULL,
  106819. NULL,
  106820. 0
  106821. };
  106822. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106823. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106824. };
  106825. static static_codebook _huff_book_line_128x7_0sub1 = {
  106826. 1, 9,
  106827. _huff_lengthlist_line_128x7_0sub1,
  106828. 0, 0, 0, 0, 0,
  106829. NULL,
  106830. NULL,
  106831. NULL,
  106832. NULL,
  106833. 0
  106834. };
  106835. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106837. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106838. };
  106839. static static_codebook _huff_book_line_128x7_0sub2 = {
  106840. 1, 25,
  106841. _huff_lengthlist_line_128x7_0sub2,
  106842. 0, 0, 0, 0, 0,
  106843. NULL,
  106844. NULL,
  106845. NULL,
  106846. NULL,
  106847. 0
  106848. };
  106849. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106852. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106853. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106854. };
  106855. static static_codebook _huff_book_line_128x7_0sub3 = {
  106856. 1, 64,
  106857. _huff_lengthlist_line_128x7_0sub3,
  106858. 0, 0, 0, 0, 0,
  106859. NULL,
  106860. NULL,
  106861. NULL,
  106862. NULL,
  106863. 0
  106864. };
  106865. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106866. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106867. };
  106868. static static_codebook _huff_book_line_128x7_1sub1 = {
  106869. 1, 9,
  106870. _huff_lengthlist_line_128x7_1sub1,
  106871. 0, 0, 0, 0, 0,
  106872. NULL,
  106873. NULL,
  106874. NULL,
  106875. NULL,
  106876. 0
  106877. };
  106878. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106880. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106881. };
  106882. static static_codebook _huff_book_line_128x7_1sub2 = {
  106883. 1, 25,
  106884. _huff_lengthlist_line_128x7_1sub2,
  106885. 0, 0, 0, 0, 0,
  106886. NULL,
  106887. NULL,
  106888. NULL,
  106889. NULL,
  106890. 0
  106891. };
  106892. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106895. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106896. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106897. };
  106898. static static_codebook _huff_book_line_128x7_1sub3 = {
  106899. 1, 64,
  106900. _huff_lengthlist_line_128x7_1sub3,
  106901. 0, 0, 0, 0, 0,
  106902. NULL,
  106903. NULL,
  106904. NULL,
  106905. NULL,
  106906. 0
  106907. };
  106908. static long _huff_lengthlist_line_128x11_class1[] = {
  106909. 1, 6, 3, 7, 2, 4, 5, 7,
  106910. };
  106911. static static_codebook _huff_book_line_128x11_class1 = {
  106912. 1, 8,
  106913. _huff_lengthlist_line_128x11_class1,
  106914. 0, 0, 0, 0, 0,
  106915. NULL,
  106916. NULL,
  106917. NULL,
  106918. NULL,
  106919. 0
  106920. };
  106921. static long _huff_lengthlist_line_128x11_class2[] = {
  106922. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  106923. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  106924. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  106925. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  106926. };
  106927. static static_codebook _huff_book_line_128x11_class2 = {
  106928. 1, 64,
  106929. _huff_lengthlist_line_128x11_class2,
  106930. 0, 0, 0, 0, 0,
  106931. NULL,
  106932. NULL,
  106933. NULL,
  106934. NULL,
  106935. 0
  106936. };
  106937. static long _huff_lengthlist_line_128x11_class3[] = {
  106938. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  106939. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  106940. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  106941. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  106942. };
  106943. static static_codebook _huff_book_line_128x11_class3 = {
  106944. 1, 64,
  106945. _huff_lengthlist_line_128x11_class3,
  106946. 0, 0, 0, 0, 0,
  106947. NULL,
  106948. NULL,
  106949. NULL,
  106950. NULL,
  106951. 0
  106952. };
  106953. static long _huff_lengthlist_line_128x11_0sub0[] = {
  106954. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106955. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  106956. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  106957. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  106958. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  106959. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  106960. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  106961. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106962. };
  106963. static static_codebook _huff_book_line_128x11_0sub0 = {
  106964. 1, 128,
  106965. _huff_lengthlist_line_128x11_0sub0,
  106966. 0, 0, 0, 0, 0,
  106967. NULL,
  106968. NULL,
  106969. NULL,
  106970. NULL,
  106971. 0
  106972. };
  106973. static long _huff_lengthlist_line_128x11_1sub0[] = {
  106974. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  106975. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  106976. };
  106977. static static_codebook _huff_book_line_128x11_1sub0 = {
  106978. 1, 32,
  106979. _huff_lengthlist_line_128x11_1sub0,
  106980. 0, 0, 0, 0, 0,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. 0
  106986. };
  106987. static long _huff_lengthlist_line_128x11_1sub1[] = {
  106988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106990. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  106991. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  106992. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  106993. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  106994. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  106995. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  106996. };
  106997. static static_codebook _huff_book_line_128x11_1sub1 = {
  106998. 1, 128,
  106999. _huff_lengthlist_line_128x11_1sub1,
  107000. 0, 0, 0, 0, 0,
  107001. NULL,
  107002. NULL,
  107003. NULL,
  107004. NULL,
  107005. 0
  107006. };
  107007. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107008. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107009. 5, 5,
  107010. };
  107011. static static_codebook _huff_book_line_128x11_2sub1 = {
  107012. 1, 18,
  107013. _huff_lengthlist_line_128x11_2sub1,
  107014. 0, 0, 0, 0, 0,
  107015. NULL,
  107016. NULL,
  107017. NULL,
  107018. NULL,
  107019. 0
  107020. };
  107021. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107023. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107024. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107025. 8,11,
  107026. };
  107027. static static_codebook _huff_book_line_128x11_2sub2 = {
  107028. 1, 50,
  107029. _huff_lengthlist_line_128x11_2sub2,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107041. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107042. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107043. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107044. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107045. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107046. };
  107047. static static_codebook _huff_book_line_128x11_2sub3 = {
  107048. 1, 128,
  107049. _huff_lengthlist_line_128x11_2sub3,
  107050. 0, 0, 0, 0, 0,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. NULL,
  107055. 0
  107056. };
  107057. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107058. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107059. 5, 4,
  107060. };
  107061. static static_codebook _huff_book_line_128x11_3sub1 = {
  107062. 1, 18,
  107063. _huff_lengthlist_line_128x11_3sub1,
  107064. 0, 0, 0, 0, 0,
  107065. NULL,
  107066. NULL,
  107067. NULL,
  107068. NULL,
  107069. 0
  107070. };
  107071. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107073. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107074. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107075. 12, 6,
  107076. };
  107077. static static_codebook _huff_book_line_128x11_3sub2 = {
  107078. 1, 50,
  107079. _huff_lengthlist_line_128x11_3sub2,
  107080. 0, 0, 0, 0, 0,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. 0
  107086. };
  107087. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107091. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107092. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107093. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107096. };
  107097. static static_codebook _huff_book_line_128x11_3sub3 = {
  107098. 1, 128,
  107099. _huff_lengthlist_line_128x11_3sub3,
  107100. 0, 0, 0, 0, 0,
  107101. NULL,
  107102. NULL,
  107103. NULL,
  107104. NULL,
  107105. 0
  107106. };
  107107. static long _huff_lengthlist_line_128x17_class1[] = {
  107108. 1, 3, 4, 7, 2, 5, 6, 7,
  107109. };
  107110. static static_codebook _huff_book_line_128x17_class1 = {
  107111. 1, 8,
  107112. _huff_lengthlist_line_128x17_class1,
  107113. 0, 0, 0, 0, 0,
  107114. NULL,
  107115. NULL,
  107116. NULL,
  107117. NULL,
  107118. 0
  107119. };
  107120. static long _huff_lengthlist_line_128x17_class2[] = {
  107121. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107122. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107123. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107124. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107125. };
  107126. static static_codebook _huff_book_line_128x17_class2 = {
  107127. 1, 64,
  107128. _huff_lengthlist_line_128x17_class2,
  107129. 0, 0, 0, 0, 0,
  107130. NULL,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. 0
  107135. };
  107136. static long _huff_lengthlist_line_128x17_class3[] = {
  107137. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107138. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107139. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107140. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107141. };
  107142. static static_codebook _huff_book_line_128x17_class3 = {
  107143. 1, 64,
  107144. _huff_lengthlist_line_128x17_class3,
  107145. 0, 0, 0, 0, 0,
  107146. NULL,
  107147. NULL,
  107148. NULL,
  107149. NULL,
  107150. 0
  107151. };
  107152. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107153. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107154. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107155. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107156. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107157. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107158. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107159. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107160. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107161. };
  107162. static static_codebook _huff_book_line_128x17_0sub0 = {
  107163. 1, 128,
  107164. _huff_lengthlist_line_128x17_0sub0,
  107165. 0, 0, 0, 0, 0,
  107166. NULL,
  107167. NULL,
  107168. NULL,
  107169. NULL,
  107170. 0
  107171. };
  107172. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107173. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107174. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107175. };
  107176. static static_codebook _huff_book_line_128x17_1sub0 = {
  107177. 1, 32,
  107178. _huff_lengthlist_line_128x17_1sub0,
  107179. 0, 0, 0, 0, 0,
  107180. NULL,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. 0
  107185. };
  107186. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107189. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107190. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107191. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107192. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107193. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107194. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107195. };
  107196. static static_codebook _huff_book_line_128x17_1sub1 = {
  107197. 1, 128,
  107198. _huff_lengthlist_line_128x17_1sub1,
  107199. 0, 0, 0, 0, 0,
  107200. NULL,
  107201. NULL,
  107202. NULL,
  107203. NULL,
  107204. 0
  107205. };
  107206. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107207. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107208. 9, 4,
  107209. };
  107210. static static_codebook _huff_book_line_128x17_2sub1 = {
  107211. 1, 18,
  107212. _huff_lengthlist_line_128x17_2sub1,
  107213. 0, 0, 0, 0, 0,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. NULL,
  107218. 0
  107219. };
  107220. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107222. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107223. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107224. 13,13,
  107225. };
  107226. static static_codebook _huff_book_line_128x17_2sub2 = {
  107227. 1, 50,
  107228. _huff_lengthlist_line_128x17_2sub2,
  107229. 0, 0, 0, 0, 0,
  107230. NULL,
  107231. NULL,
  107232. NULL,
  107233. NULL,
  107234. 0
  107235. };
  107236. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107240. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107241. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107242. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107243. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107244. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107245. };
  107246. static static_codebook _huff_book_line_128x17_2sub3 = {
  107247. 1, 128,
  107248. _huff_lengthlist_line_128x17_2sub3,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107257. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107258. 6, 4,
  107259. };
  107260. static static_codebook _huff_book_line_128x17_3sub1 = {
  107261. 1, 18,
  107262. _huff_lengthlist_line_128x17_3sub1,
  107263. 0, 0, 0, 0, 0,
  107264. NULL,
  107265. NULL,
  107266. NULL,
  107267. NULL,
  107268. 0
  107269. };
  107270. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107272. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107273. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107274. 10, 8,
  107275. };
  107276. static static_codebook _huff_book_line_128x17_3sub2 = {
  107277. 1, 50,
  107278. _huff_lengthlist_line_128x17_3sub2,
  107279. 0, 0, 0, 0, 0,
  107280. NULL,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. 0
  107285. };
  107286. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107290. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107291. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107292. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107293. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107294. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107295. };
  107296. static static_codebook _huff_book_line_128x17_3sub3 = {
  107297. 1, 128,
  107298. _huff_lengthlist_line_128x17_3sub3,
  107299. 0, 0, 0, 0, 0,
  107300. NULL,
  107301. NULL,
  107302. NULL,
  107303. NULL,
  107304. 0
  107305. };
  107306. static long _huff_lengthlist_line_1024x27_class1[] = {
  107307. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107308. };
  107309. static static_codebook _huff_book_line_1024x27_class1 = {
  107310. 1, 16,
  107311. _huff_lengthlist_line_1024x27_class1,
  107312. 0, 0, 0, 0, 0,
  107313. NULL,
  107314. NULL,
  107315. NULL,
  107316. NULL,
  107317. 0
  107318. };
  107319. static long _huff_lengthlist_line_1024x27_class2[] = {
  107320. 1, 4, 2, 6, 3, 7, 5, 7,
  107321. };
  107322. static static_codebook _huff_book_line_1024x27_class2 = {
  107323. 1, 8,
  107324. _huff_lengthlist_line_1024x27_class2,
  107325. 0, 0, 0, 0, 0,
  107326. NULL,
  107327. NULL,
  107328. NULL,
  107329. NULL,
  107330. 0
  107331. };
  107332. static long _huff_lengthlist_line_1024x27_class3[] = {
  107333. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107334. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107335. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107336. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107337. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107338. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107339. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107340. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107341. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107342. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107343. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107344. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107345. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107346. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107347. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107348. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107349. };
  107350. static static_codebook _huff_book_line_1024x27_class3 = {
  107351. 1, 256,
  107352. _huff_lengthlist_line_1024x27_class3,
  107353. 0, 0, 0, 0, 0,
  107354. NULL,
  107355. NULL,
  107356. NULL,
  107357. NULL,
  107358. 0
  107359. };
  107360. static long _huff_lengthlist_line_1024x27_class4[] = {
  107361. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107362. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107363. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107364. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107365. };
  107366. static static_codebook _huff_book_line_1024x27_class4 = {
  107367. 1, 64,
  107368. _huff_lengthlist_line_1024x27_class4,
  107369. 0, 0, 0, 0, 0,
  107370. NULL,
  107371. NULL,
  107372. NULL,
  107373. NULL,
  107374. 0
  107375. };
  107376. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107377. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107378. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107379. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107380. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107381. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107382. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107383. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107384. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107385. };
  107386. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107387. 1, 128,
  107388. _huff_lengthlist_line_1024x27_0sub0,
  107389. 0, 0, 0, 0, 0,
  107390. NULL,
  107391. NULL,
  107392. NULL,
  107393. NULL,
  107394. 0
  107395. };
  107396. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107397. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107398. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107399. };
  107400. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107401. 1, 32,
  107402. _huff_lengthlist_line_1024x27_1sub0,
  107403. 0, 0, 0, 0, 0,
  107404. NULL,
  107405. NULL,
  107406. NULL,
  107407. NULL,
  107408. 0
  107409. };
  107410. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107413. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107414. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107415. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107416. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107417. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107418. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107419. };
  107420. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107421. 1, 128,
  107422. _huff_lengthlist_line_1024x27_1sub1,
  107423. 0, 0, 0, 0, 0,
  107424. NULL,
  107425. NULL,
  107426. NULL,
  107427. NULL,
  107428. 0
  107429. };
  107430. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107431. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107432. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107433. };
  107434. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107435. 1, 32,
  107436. _huff_lengthlist_line_1024x27_2sub0,
  107437. 0, 0, 0, 0, 0,
  107438. NULL,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. 0
  107443. };
  107444. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107447. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107448. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107449. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107450. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107451. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107452. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107453. };
  107454. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107455. 1, 128,
  107456. _huff_lengthlist_line_1024x27_2sub1,
  107457. 0, 0, 0, 0, 0,
  107458. NULL,
  107459. NULL,
  107460. NULL,
  107461. NULL,
  107462. 0
  107463. };
  107464. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107465. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107466. 5, 5,
  107467. };
  107468. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107469. 1, 18,
  107470. _huff_lengthlist_line_1024x27_3sub1,
  107471. 0, 0, 0, 0, 0,
  107472. NULL,
  107473. NULL,
  107474. NULL,
  107475. NULL,
  107476. 0
  107477. };
  107478. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107480. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107481. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107482. 9,11,
  107483. };
  107484. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107485. 1, 50,
  107486. _huff_lengthlist_line_1024x27_3sub2,
  107487. 0, 0, 0, 0, 0,
  107488. NULL,
  107489. NULL,
  107490. NULL,
  107491. NULL,
  107492. 0
  107493. };
  107494. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107498. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107499. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107500. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107501. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107502. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107503. };
  107504. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107505. 1, 128,
  107506. _huff_lengthlist_line_1024x27_3sub3,
  107507. 0, 0, 0, 0, 0,
  107508. NULL,
  107509. NULL,
  107510. NULL,
  107511. NULL,
  107512. 0
  107513. };
  107514. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107515. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107516. 5, 4,
  107517. };
  107518. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107519. 1, 18,
  107520. _huff_lengthlist_line_1024x27_4sub1,
  107521. 0, 0, 0, 0, 0,
  107522. NULL,
  107523. NULL,
  107524. NULL,
  107525. NULL,
  107526. 0
  107527. };
  107528. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107530. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107531. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107532. 9,12,
  107533. };
  107534. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107535. 1, 50,
  107536. _huff_lengthlist_line_1024x27_4sub2,
  107537. 0, 0, 0, 0, 0,
  107538. NULL,
  107539. NULL,
  107540. NULL,
  107541. NULL,
  107542. 0
  107543. };
  107544. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107548. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107549. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107550. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107551. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107552. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107553. };
  107554. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107555. 1, 128,
  107556. _huff_lengthlist_line_1024x27_4sub3,
  107557. 0, 0, 0, 0, 0,
  107558. NULL,
  107559. NULL,
  107560. NULL,
  107561. NULL,
  107562. 0
  107563. };
  107564. static long _huff_lengthlist_line_2048x27_class1[] = {
  107565. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107566. };
  107567. static static_codebook _huff_book_line_2048x27_class1 = {
  107568. 1, 16,
  107569. _huff_lengthlist_line_2048x27_class1,
  107570. 0, 0, 0, 0, 0,
  107571. NULL,
  107572. NULL,
  107573. NULL,
  107574. NULL,
  107575. 0
  107576. };
  107577. static long _huff_lengthlist_line_2048x27_class2[] = {
  107578. 1, 2, 3, 6, 4, 7, 5, 7,
  107579. };
  107580. static static_codebook _huff_book_line_2048x27_class2 = {
  107581. 1, 8,
  107582. _huff_lengthlist_line_2048x27_class2,
  107583. 0, 0, 0, 0, 0,
  107584. NULL,
  107585. NULL,
  107586. NULL,
  107587. NULL,
  107588. 0
  107589. };
  107590. static long _huff_lengthlist_line_2048x27_class3[] = {
  107591. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107592. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107593. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107594. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107595. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107596. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107597. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107598. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107599. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107600. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107601. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107602. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107603. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107604. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107605. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107606. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107607. };
  107608. static static_codebook _huff_book_line_2048x27_class3 = {
  107609. 1, 256,
  107610. _huff_lengthlist_line_2048x27_class3,
  107611. 0, 0, 0, 0, 0,
  107612. NULL,
  107613. NULL,
  107614. NULL,
  107615. NULL,
  107616. 0
  107617. };
  107618. static long _huff_lengthlist_line_2048x27_class4[] = {
  107619. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107620. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107621. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107622. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107623. };
  107624. static static_codebook _huff_book_line_2048x27_class4 = {
  107625. 1, 64,
  107626. _huff_lengthlist_line_2048x27_class4,
  107627. 0, 0, 0, 0, 0,
  107628. NULL,
  107629. NULL,
  107630. NULL,
  107631. NULL,
  107632. 0
  107633. };
  107634. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107635. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107636. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107637. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107638. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107639. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107640. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107641. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107642. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107643. };
  107644. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107645. 1, 128,
  107646. _huff_lengthlist_line_2048x27_0sub0,
  107647. 0, 0, 0, 0, 0,
  107648. NULL,
  107649. NULL,
  107650. NULL,
  107651. NULL,
  107652. 0
  107653. };
  107654. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107655. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107656. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107657. };
  107658. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107659. 1, 32,
  107660. _huff_lengthlist_line_2048x27_1sub0,
  107661. 0, 0, 0, 0, 0,
  107662. NULL,
  107663. NULL,
  107664. NULL,
  107665. NULL,
  107666. 0
  107667. };
  107668. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107671. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107672. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107673. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107674. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107675. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107676. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107677. };
  107678. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107679. 1, 128,
  107680. _huff_lengthlist_line_2048x27_1sub1,
  107681. 0, 0, 0, 0, 0,
  107682. NULL,
  107683. NULL,
  107684. NULL,
  107685. NULL,
  107686. 0
  107687. };
  107688. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107689. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107690. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107691. };
  107692. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107693. 1, 32,
  107694. _huff_lengthlist_line_2048x27_2sub0,
  107695. 0, 0, 0, 0, 0,
  107696. NULL,
  107697. NULL,
  107698. NULL,
  107699. NULL,
  107700. 0
  107701. };
  107702. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107705. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107706. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107707. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107708. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107709. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107710. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107711. };
  107712. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107713. 1, 128,
  107714. _huff_lengthlist_line_2048x27_2sub1,
  107715. 0, 0, 0, 0, 0,
  107716. NULL,
  107717. NULL,
  107718. NULL,
  107719. NULL,
  107720. 0
  107721. };
  107722. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107723. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107724. 5, 5,
  107725. };
  107726. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107727. 1, 18,
  107728. _huff_lengthlist_line_2048x27_3sub1,
  107729. 0, 0, 0, 0, 0,
  107730. NULL,
  107731. NULL,
  107732. NULL,
  107733. NULL,
  107734. 0
  107735. };
  107736. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107738. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107739. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107740. 10,12,
  107741. };
  107742. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107743. 1, 50,
  107744. _huff_lengthlist_line_2048x27_3sub2,
  107745. 0, 0, 0, 0, 0,
  107746. NULL,
  107747. NULL,
  107748. NULL,
  107749. NULL,
  107750. 0
  107751. };
  107752. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107756. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107757. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107758. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107759. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107760. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107761. };
  107762. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107763. 1, 128,
  107764. _huff_lengthlist_line_2048x27_3sub3,
  107765. 0, 0, 0, 0, 0,
  107766. NULL,
  107767. NULL,
  107768. NULL,
  107769. NULL,
  107770. 0
  107771. };
  107772. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107773. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107774. 4, 5,
  107775. };
  107776. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107777. 1, 18,
  107778. _huff_lengthlist_line_2048x27_4sub1,
  107779. 0, 0, 0, 0, 0,
  107780. NULL,
  107781. NULL,
  107782. NULL,
  107783. NULL,
  107784. 0
  107785. };
  107786. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107788. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107789. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107790. 10,10,
  107791. };
  107792. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107793. 1, 50,
  107794. _huff_lengthlist_line_2048x27_4sub2,
  107795. 0, 0, 0, 0, 0,
  107796. NULL,
  107797. NULL,
  107798. NULL,
  107799. NULL,
  107800. 0
  107801. };
  107802. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107806. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107807. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107808. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107809. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107810. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107811. };
  107812. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107813. 1, 128,
  107814. _huff_lengthlist_line_2048x27_4sub3,
  107815. 0, 0, 0, 0, 0,
  107816. NULL,
  107817. NULL,
  107818. NULL,
  107819. NULL,
  107820. 0
  107821. };
  107822. static long _huff_lengthlist_line_256x4low_class0[] = {
  107823. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107824. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107825. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107826. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107827. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107828. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107829. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107830. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107831. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107832. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107833. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107834. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107835. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107836. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107837. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107838. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107839. };
  107840. static static_codebook _huff_book_line_256x4low_class0 = {
  107841. 1, 256,
  107842. _huff_lengthlist_line_256x4low_class0,
  107843. 0, 0, 0, 0, 0,
  107844. NULL,
  107845. NULL,
  107846. NULL,
  107847. NULL,
  107848. 0
  107849. };
  107850. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107851. 1, 3, 2, 3,
  107852. };
  107853. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107854. 1, 4,
  107855. _huff_lengthlist_line_256x4low_0sub0,
  107856. 0, 0, 0, 0, 0,
  107857. NULL,
  107858. NULL,
  107859. NULL,
  107860. NULL,
  107861. 0
  107862. };
  107863. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107864. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107865. };
  107866. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107867. 1, 10,
  107868. _huff_lengthlist_line_256x4low_0sub1,
  107869. 0, 0, 0, 0, 0,
  107870. NULL,
  107871. NULL,
  107872. NULL,
  107873. NULL,
  107874. 0
  107875. };
  107876. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107878. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107879. };
  107880. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107881. 1, 25,
  107882. _huff_lengthlist_line_256x4low_0sub2,
  107883. 0, 0, 0, 0, 0,
  107884. NULL,
  107885. NULL,
  107886. NULL,
  107887. NULL,
  107888. 0
  107889. };
  107890. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107893. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107894. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107895. };
  107896. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107897. 1, 64,
  107898. _huff_lengthlist_line_256x4low_0sub3,
  107899. 0, 0, 0, 0, 0,
  107900. NULL,
  107901. NULL,
  107902. NULL,
  107903. NULL,
  107904. 0
  107905. };
  107906. /*** End of inlined file: floor_books.h ***/
  107907. static static_codebook *_floor_128x4_books[]={
  107908. &_huff_book_line_128x4_class0,
  107909. &_huff_book_line_128x4_0sub0,
  107910. &_huff_book_line_128x4_0sub1,
  107911. &_huff_book_line_128x4_0sub2,
  107912. &_huff_book_line_128x4_0sub3,
  107913. };
  107914. static static_codebook *_floor_256x4_books[]={
  107915. &_huff_book_line_256x4_class0,
  107916. &_huff_book_line_256x4_0sub0,
  107917. &_huff_book_line_256x4_0sub1,
  107918. &_huff_book_line_256x4_0sub2,
  107919. &_huff_book_line_256x4_0sub3,
  107920. };
  107921. static static_codebook *_floor_128x7_books[]={
  107922. &_huff_book_line_128x7_class0,
  107923. &_huff_book_line_128x7_class1,
  107924. &_huff_book_line_128x7_0sub1,
  107925. &_huff_book_line_128x7_0sub2,
  107926. &_huff_book_line_128x7_0sub3,
  107927. &_huff_book_line_128x7_1sub1,
  107928. &_huff_book_line_128x7_1sub2,
  107929. &_huff_book_line_128x7_1sub3,
  107930. };
  107931. static static_codebook *_floor_256x7_books[]={
  107932. &_huff_book_line_256x7_class0,
  107933. &_huff_book_line_256x7_class1,
  107934. &_huff_book_line_256x7_0sub1,
  107935. &_huff_book_line_256x7_0sub2,
  107936. &_huff_book_line_256x7_0sub3,
  107937. &_huff_book_line_256x7_1sub1,
  107938. &_huff_book_line_256x7_1sub2,
  107939. &_huff_book_line_256x7_1sub3,
  107940. };
  107941. static static_codebook *_floor_128x11_books[]={
  107942. &_huff_book_line_128x11_class1,
  107943. &_huff_book_line_128x11_class2,
  107944. &_huff_book_line_128x11_class3,
  107945. &_huff_book_line_128x11_0sub0,
  107946. &_huff_book_line_128x11_1sub0,
  107947. &_huff_book_line_128x11_1sub1,
  107948. &_huff_book_line_128x11_2sub1,
  107949. &_huff_book_line_128x11_2sub2,
  107950. &_huff_book_line_128x11_2sub3,
  107951. &_huff_book_line_128x11_3sub1,
  107952. &_huff_book_line_128x11_3sub2,
  107953. &_huff_book_line_128x11_3sub3,
  107954. };
  107955. static static_codebook *_floor_128x17_books[]={
  107956. &_huff_book_line_128x17_class1,
  107957. &_huff_book_line_128x17_class2,
  107958. &_huff_book_line_128x17_class3,
  107959. &_huff_book_line_128x17_0sub0,
  107960. &_huff_book_line_128x17_1sub0,
  107961. &_huff_book_line_128x17_1sub1,
  107962. &_huff_book_line_128x17_2sub1,
  107963. &_huff_book_line_128x17_2sub2,
  107964. &_huff_book_line_128x17_2sub3,
  107965. &_huff_book_line_128x17_3sub1,
  107966. &_huff_book_line_128x17_3sub2,
  107967. &_huff_book_line_128x17_3sub3,
  107968. };
  107969. static static_codebook *_floor_256x4low_books[]={
  107970. &_huff_book_line_256x4low_class0,
  107971. &_huff_book_line_256x4low_0sub0,
  107972. &_huff_book_line_256x4low_0sub1,
  107973. &_huff_book_line_256x4low_0sub2,
  107974. &_huff_book_line_256x4low_0sub3,
  107975. };
  107976. static static_codebook *_floor_1024x27_books[]={
  107977. &_huff_book_line_1024x27_class1,
  107978. &_huff_book_line_1024x27_class2,
  107979. &_huff_book_line_1024x27_class3,
  107980. &_huff_book_line_1024x27_class4,
  107981. &_huff_book_line_1024x27_0sub0,
  107982. &_huff_book_line_1024x27_1sub0,
  107983. &_huff_book_line_1024x27_1sub1,
  107984. &_huff_book_line_1024x27_2sub0,
  107985. &_huff_book_line_1024x27_2sub1,
  107986. &_huff_book_line_1024x27_3sub1,
  107987. &_huff_book_line_1024x27_3sub2,
  107988. &_huff_book_line_1024x27_3sub3,
  107989. &_huff_book_line_1024x27_4sub1,
  107990. &_huff_book_line_1024x27_4sub2,
  107991. &_huff_book_line_1024x27_4sub3,
  107992. };
  107993. static static_codebook *_floor_2048x27_books[]={
  107994. &_huff_book_line_2048x27_class1,
  107995. &_huff_book_line_2048x27_class2,
  107996. &_huff_book_line_2048x27_class3,
  107997. &_huff_book_line_2048x27_class4,
  107998. &_huff_book_line_2048x27_0sub0,
  107999. &_huff_book_line_2048x27_1sub0,
  108000. &_huff_book_line_2048x27_1sub1,
  108001. &_huff_book_line_2048x27_2sub0,
  108002. &_huff_book_line_2048x27_2sub1,
  108003. &_huff_book_line_2048x27_3sub1,
  108004. &_huff_book_line_2048x27_3sub2,
  108005. &_huff_book_line_2048x27_3sub3,
  108006. &_huff_book_line_2048x27_4sub1,
  108007. &_huff_book_line_2048x27_4sub2,
  108008. &_huff_book_line_2048x27_4sub3,
  108009. };
  108010. static static_codebook *_floor_512x17_books[]={
  108011. &_huff_book_line_512x17_class1,
  108012. &_huff_book_line_512x17_class2,
  108013. &_huff_book_line_512x17_class3,
  108014. &_huff_book_line_512x17_0sub0,
  108015. &_huff_book_line_512x17_1sub0,
  108016. &_huff_book_line_512x17_1sub1,
  108017. &_huff_book_line_512x17_2sub1,
  108018. &_huff_book_line_512x17_2sub2,
  108019. &_huff_book_line_512x17_2sub3,
  108020. &_huff_book_line_512x17_3sub1,
  108021. &_huff_book_line_512x17_3sub2,
  108022. &_huff_book_line_512x17_3sub3,
  108023. };
  108024. static static_codebook **_floor_books[10]={
  108025. _floor_128x4_books,
  108026. _floor_256x4_books,
  108027. _floor_128x7_books,
  108028. _floor_256x7_books,
  108029. _floor_128x11_books,
  108030. _floor_128x17_books,
  108031. _floor_256x4low_books,
  108032. _floor_1024x27_books,
  108033. _floor_2048x27_books,
  108034. _floor_512x17_books,
  108035. };
  108036. static vorbis_info_floor1 _floor[10]={
  108037. {
  108038. 1,{0},{4},{2},{0},
  108039. {{1,2,3,4}},
  108040. 4,{0,128, 33,8,16,70},
  108041. 60,30,500, 1.,18., -1
  108042. },
  108043. {
  108044. 1,{0},{4},{2},{0},
  108045. {{1,2,3,4}},
  108046. 4,{0,256, 66,16,32,140},
  108047. 60,30,500, 1.,18., -1
  108048. },
  108049. {
  108050. 2,{0,1},{3,4},{2,2},{0,1},
  108051. {{-1,2,3,4},{-1,5,6,7}},
  108052. 4,{0,128, 14,4,58, 2,8,28,90},
  108053. 60,30,500, 1.,18., -1
  108054. },
  108055. {
  108056. 2,{0,1},{3,4},{2,2},{0,1},
  108057. {{-1,2,3,4},{-1,5,6,7}},
  108058. 4,{0,256, 28,8,116, 4,16,56,180},
  108059. 60,30,500, 1.,18., -1
  108060. },
  108061. {
  108062. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108063. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108064. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108065. 60,30,500, 1,18., -1
  108066. },
  108067. {
  108068. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108069. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108070. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108071. 60,30,500, 1,18., -1
  108072. },
  108073. {
  108074. 1,{0},{4},{2},{0},
  108075. {{1,2,3,4}},
  108076. 4,{0,256, 66,16,32,140},
  108077. 60,30,500, 1.,18., -1
  108078. },
  108079. {
  108080. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108081. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108082. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108083. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108084. 60,30,500, 3,18., -1 /* lowpass */
  108085. },
  108086. {
  108087. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108088. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108089. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108090. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108091. 60,30,500, 3,18., -1 /* lowpass */
  108092. },
  108093. {
  108094. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108095. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108096. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108097. 7,23,39, 55,79,110, 156,232,360},
  108098. 60,30,500, 1,18., -1 /* lowpass! */
  108099. },
  108100. };
  108101. /*** End of inlined file: floor_all.h ***/
  108102. /*** Start of inlined file: residue_44.h ***/
  108103. /*** Start of inlined file: res_books_stereo.h ***/
  108104. static long _vq_quantlist__16c0_s_p1_0[] = {
  108105. 1,
  108106. 0,
  108107. 2,
  108108. };
  108109. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108110. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108111. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108115. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108116. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108120. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108121. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108156. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108161. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108166. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108179. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108184. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108189. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108202. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108207. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108212. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  108224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  108229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  108234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  108521. };
  108522. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108523. -0.5, 0.5,
  108524. };
  108525. static long _vq_quantmap__16c0_s_p1_0[] = {
  108526. 1, 0, 2,
  108527. };
  108528. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108529. _vq_quantthresh__16c0_s_p1_0,
  108530. _vq_quantmap__16c0_s_p1_0,
  108531. 3,
  108532. 3
  108533. };
  108534. static static_codebook _16c0_s_p1_0 = {
  108535. 8, 6561,
  108536. _vq_lengthlist__16c0_s_p1_0,
  108537. 1, -535822336, 1611661312, 2, 0,
  108538. _vq_quantlist__16c0_s_p1_0,
  108539. NULL,
  108540. &_vq_auxt__16c0_s_p1_0,
  108541. NULL,
  108542. 0
  108543. };
  108544. static long _vq_quantlist__16c0_s_p2_0[] = {
  108545. 2,
  108546. 1,
  108547. 3,
  108548. 0,
  108549. 4,
  108550. };
  108551. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0,
  108592. };
  108593. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108594. -1.5, -0.5, 0.5, 1.5,
  108595. };
  108596. static long _vq_quantmap__16c0_s_p2_0[] = {
  108597. 3, 1, 0, 2, 4,
  108598. };
  108599. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108600. _vq_quantthresh__16c0_s_p2_0,
  108601. _vq_quantmap__16c0_s_p2_0,
  108602. 5,
  108603. 5
  108604. };
  108605. static static_codebook _16c0_s_p2_0 = {
  108606. 4, 625,
  108607. _vq_lengthlist__16c0_s_p2_0,
  108608. 1, -533725184, 1611661312, 3, 0,
  108609. _vq_quantlist__16c0_s_p2_0,
  108610. NULL,
  108611. &_vq_auxt__16c0_s_p2_0,
  108612. NULL,
  108613. 0
  108614. };
  108615. static long _vq_quantlist__16c0_s_p3_0[] = {
  108616. 2,
  108617. 1,
  108618. 3,
  108619. 0,
  108620. 4,
  108621. };
  108622. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108623. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108629. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108662. 0,
  108663. };
  108664. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108665. -1.5, -0.5, 0.5, 1.5,
  108666. };
  108667. static long _vq_quantmap__16c0_s_p3_0[] = {
  108668. 3, 1, 0, 2, 4,
  108669. };
  108670. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108671. _vq_quantthresh__16c0_s_p3_0,
  108672. _vq_quantmap__16c0_s_p3_0,
  108673. 5,
  108674. 5
  108675. };
  108676. static static_codebook _16c0_s_p3_0 = {
  108677. 4, 625,
  108678. _vq_lengthlist__16c0_s_p3_0,
  108679. 1, -533725184, 1611661312, 3, 0,
  108680. _vq_quantlist__16c0_s_p3_0,
  108681. NULL,
  108682. &_vq_auxt__16c0_s_p3_0,
  108683. NULL,
  108684. 0
  108685. };
  108686. static long _vq_quantlist__16c0_s_p4_0[] = {
  108687. 4,
  108688. 3,
  108689. 5,
  108690. 2,
  108691. 6,
  108692. 1,
  108693. 7,
  108694. 0,
  108695. 8,
  108696. };
  108697. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108698. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108699. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108700. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108701. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108702. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0,
  108704. };
  108705. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108706. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108707. };
  108708. static long _vq_quantmap__16c0_s_p4_0[] = {
  108709. 7, 5, 3, 1, 0, 2, 4, 6,
  108710. 8,
  108711. };
  108712. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108713. _vq_quantthresh__16c0_s_p4_0,
  108714. _vq_quantmap__16c0_s_p4_0,
  108715. 9,
  108716. 9
  108717. };
  108718. static static_codebook _16c0_s_p4_0 = {
  108719. 2, 81,
  108720. _vq_lengthlist__16c0_s_p4_0,
  108721. 1, -531628032, 1611661312, 4, 0,
  108722. _vq_quantlist__16c0_s_p4_0,
  108723. NULL,
  108724. &_vq_auxt__16c0_s_p4_0,
  108725. NULL,
  108726. 0
  108727. };
  108728. static long _vq_quantlist__16c0_s_p5_0[] = {
  108729. 4,
  108730. 3,
  108731. 5,
  108732. 2,
  108733. 6,
  108734. 1,
  108735. 7,
  108736. 0,
  108737. 8,
  108738. };
  108739. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108740. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108741. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108742. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108743. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108744. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108745. 10,
  108746. };
  108747. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108748. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108749. };
  108750. static long _vq_quantmap__16c0_s_p5_0[] = {
  108751. 7, 5, 3, 1, 0, 2, 4, 6,
  108752. 8,
  108753. };
  108754. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108755. _vq_quantthresh__16c0_s_p5_0,
  108756. _vq_quantmap__16c0_s_p5_0,
  108757. 9,
  108758. 9
  108759. };
  108760. static static_codebook _16c0_s_p5_0 = {
  108761. 2, 81,
  108762. _vq_lengthlist__16c0_s_p5_0,
  108763. 1, -531628032, 1611661312, 4, 0,
  108764. _vq_quantlist__16c0_s_p5_0,
  108765. NULL,
  108766. &_vq_auxt__16c0_s_p5_0,
  108767. NULL,
  108768. 0
  108769. };
  108770. static long _vq_quantlist__16c0_s_p6_0[] = {
  108771. 8,
  108772. 7,
  108773. 9,
  108774. 6,
  108775. 10,
  108776. 5,
  108777. 11,
  108778. 4,
  108779. 12,
  108780. 3,
  108781. 13,
  108782. 2,
  108783. 14,
  108784. 1,
  108785. 15,
  108786. 0,
  108787. 16,
  108788. };
  108789. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108790. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108791. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108792. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108793. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108794. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108795. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108796. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108797. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108798. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108799. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108800. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108801. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108802. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108803. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108804. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108805. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108806. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108808. 14,
  108809. };
  108810. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108811. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108812. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108813. };
  108814. static long _vq_quantmap__16c0_s_p6_0[] = {
  108815. 15, 13, 11, 9, 7, 5, 3, 1,
  108816. 0, 2, 4, 6, 8, 10, 12, 14,
  108817. 16,
  108818. };
  108819. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108820. _vq_quantthresh__16c0_s_p6_0,
  108821. _vq_quantmap__16c0_s_p6_0,
  108822. 17,
  108823. 17
  108824. };
  108825. static static_codebook _16c0_s_p6_0 = {
  108826. 2, 289,
  108827. _vq_lengthlist__16c0_s_p6_0,
  108828. 1, -529530880, 1611661312, 5, 0,
  108829. _vq_quantlist__16c0_s_p6_0,
  108830. NULL,
  108831. &_vq_auxt__16c0_s_p6_0,
  108832. NULL,
  108833. 0
  108834. };
  108835. static long _vq_quantlist__16c0_s_p7_0[] = {
  108836. 1,
  108837. 0,
  108838. 2,
  108839. };
  108840. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108841. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108842. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108843. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108844. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108845. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108846. 13,
  108847. };
  108848. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108849. -5.5, 5.5,
  108850. };
  108851. static long _vq_quantmap__16c0_s_p7_0[] = {
  108852. 1, 0, 2,
  108853. };
  108854. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108855. _vq_quantthresh__16c0_s_p7_0,
  108856. _vq_quantmap__16c0_s_p7_0,
  108857. 3,
  108858. 3
  108859. };
  108860. static static_codebook _16c0_s_p7_0 = {
  108861. 4, 81,
  108862. _vq_lengthlist__16c0_s_p7_0,
  108863. 1, -529137664, 1618345984, 2, 0,
  108864. _vq_quantlist__16c0_s_p7_0,
  108865. NULL,
  108866. &_vq_auxt__16c0_s_p7_0,
  108867. NULL,
  108868. 0
  108869. };
  108870. static long _vq_quantlist__16c0_s_p7_1[] = {
  108871. 5,
  108872. 4,
  108873. 6,
  108874. 3,
  108875. 7,
  108876. 2,
  108877. 8,
  108878. 1,
  108879. 9,
  108880. 0,
  108881. 10,
  108882. };
  108883. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108884. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108885. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108886. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108887. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108888. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108889. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108890. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108891. 11,11,11, 9, 9, 9, 9,10,10,
  108892. };
  108893. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108894. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108895. 3.5, 4.5,
  108896. };
  108897. static long _vq_quantmap__16c0_s_p7_1[] = {
  108898. 9, 7, 5, 3, 1, 0, 2, 4,
  108899. 6, 8, 10,
  108900. };
  108901. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108902. _vq_quantthresh__16c0_s_p7_1,
  108903. _vq_quantmap__16c0_s_p7_1,
  108904. 11,
  108905. 11
  108906. };
  108907. static static_codebook _16c0_s_p7_1 = {
  108908. 2, 121,
  108909. _vq_lengthlist__16c0_s_p7_1,
  108910. 1, -531365888, 1611661312, 4, 0,
  108911. _vq_quantlist__16c0_s_p7_1,
  108912. NULL,
  108913. &_vq_auxt__16c0_s_p7_1,
  108914. NULL,
  108915. 0
  108916. };
  108917. static long _vq_quantlist__16c0_s_p8_0[] = {
  108918. 6,
  108919. 5,
  108920. 7,
  108921. 4,
  108922. 8,
  108923. 3,
  108924. 9,
  108925. 2,
  108926. 10,
  108927. 1,
  108928. 11,
  108929. 0,
  108930. 12,
  108931. };
  108932. static long _vq_lengthlist__16c0_s_p8_0[] = {
  108933. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  108934. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  108935. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  108936. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  108937. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  108938. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  108939. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  108940. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  108941. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  108942. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  108943. 0,12,13,13,12,13,14,14,14,
  108944. };
  108945. static float _vq_quantthresh__16c0_s_p8_0[] = {
  108946. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  108947. 12.5, 17.5, 22.5, 27.5,
  108948. };
  108949. static long _vq_quantmap__16c0_s_p8_0[] = {
  108950. 11, 9, 7, 5, 3, 1, 0, 2,
  108951. 4, 6, 8, 10, 12,
  108952. };
  108953. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  108954. _vq_quantthresh__16c0_s_p8_0,
  108955. _vq_quantmap__16c0_s_p8_0,
  108956. 13,
  108957. 13
  108958. };
  108959. static static_codebook _16c0_s_p8_0 = {
  108960. 2, 169,
  108961. _vq_lengthlist__16c0_s_p8_0,
  108962. 1, -526516224, 1616117760, 4, 0,
  108963. _vq_quantlist__16c0_s_p8_0,
  108964. NULL,
  108965. &_vq_auxt__16c0_s_p8_0,
  108966. NULL,
  108967. 0
  108968. };
  108969. static long _vq_quantlist__16c0_s_p8_1[] = {
  108970. 2,
  108971. 1,
  108972. 3,
  108973. 0,
  108974. 4,
  108975. };
  108976. static long _vq_lengthlist__16c0_s_p8_1[] = {
  108977. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  108978. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  108979. };
  108980. static float _vq_quantthresh__16c0_s_p8_1[] = {
  108981. -1.5, -0.5, 0.5, 1.5,
  108982. };
  108983. static long _vq_quantmap__16c0_s_p8_1[] = {
  108984. 3, 1, 0, 2, 4,
  108985. };
  108986. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  108987. _vq_quantthresh__16c0_s_p8_1,
  108988. _vq_quantmap__16c0_s_p8_1,
  108989. 5,
  108990. 5
  108991. };
  108992. static static_codebook _16c0_s_p8_1 = {
  108993. 2, 25,
  108994. _vq_lengthlist__16c0_s_p8_1,
  108995. 1, -533725184, 1611661312, 3, 0,
  108996. _vq_quantlist__16c0_s_p8_1,
  108997. NULL,
  108998. &_vq_auxt__16c0_s_p8_1,
  108999. NULL,
  109000. 0
  109001. };
  109002. static long _vq_quantlist__16c0_s_p9_0[] = {
  109003. 1,
  109004. 0,
  109005. 2,
  109006. };
  109007. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109008. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109009. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109010. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109011. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109012. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109013. 7,
  109014. };
  109015. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109016. -157.5, 157.5,
  109017. };
  109018. static long _vq_quantmap__16c0_s_p9_0[] = {
  109019. 1, 0, 2,
  109020. };
  109021. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109022. _vq_quantthresh__16c0_s_p9_0,
  109023. _vq_quantmap__16c0_s_p9_0,
  109024. 3,
  109025. 3
  109026. };
  109027. static static_codebook _16c0_s_p9_0 = {
  109028. 4, 81,
  109029. _vq_lengthlist__16c0_s_p9_0,
  109030. 1, -518803456, 1628680192, 2, 0,
  109031. _vq_quantlist__16c0_s_p9_0,
  109032. NULL,
  109033. &_vq_auxt__16c0_s_p9_0,
  109034. NULL,
  109035. 0
  109036. };
  109037. static long _vq_quantlist__16c0_s_p9_1[] = {
  109038. 7,
  109039. 6,
  109040. 8,
  109041. 5,
  109042. 9,
  109043. 4,
  109044. 10,
  109045. 3,
  109046. 11,
  109047. 2,
  109048. 12,
  109049. 1,
  109050. 13,
  109051. 0,
  109052. 14,
  109053. };
  109054. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109055. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109056. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109057. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109058. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109059. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109060. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109061. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109062. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109063. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109064. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109065. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109066. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109067. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109068. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109069. 10,
  109070. };
  109071. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109072. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109073. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109074. };
  109075. static long _vq_quantmap__16c0_s_p9_1[] = {
  109076. 13, 11, 9, 7, 5, 3, 1, 0,
  109077. 2, 4, 6, 8, 10, 12, 14,
  109078. };
  109079. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109080. _vq_quantthresh__16c0_s_p9_1,
  109081. _vq_quantmap__16c0_s_p9_1,
  109082. 15,
  109083. 15
  109084. };
  109085. static static_codebook _16c0_s_p9_1 = {
  109086. 2, 225,
  109087. _vq_lengthlist__16c0_s_p9_1,
  109088. 1, -520986624, 1620377600, 4, 0,
  109089. _vq_quantlist__16c0_s_p9_1,
  109090. NULL,
  109091. &_vq_auxt__16c0_s_p9_1,
  109092. NULL,
  109093. 0
  109094. };
  109095. static long _vq_quantlist__16c0_s_p9_2[] = {
  109096. 10,
  109097. 9,
  109098. 11,
  109099. 8,
  109100. 12,
  109101. 7,
  109102. 13,
  109103. 6,
  109104. 14,
  109105. 5,
  109106. 15,
  109107. 4,
  109108. 16,
  109109. 3,
  109110. 17,
  109111. 2,
  109112. 18,
  109113. 1,
  109114. 19,
  109115. 0,
  109116. 20,
  109117. };
  109118. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109119. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109120. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109121. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109122. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109123. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109124. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109125. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109126. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109127. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109128. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109129. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109130. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109131. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109132. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109133. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109134. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109135. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109136. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109137. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109138. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109139. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109140. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109141. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109142. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109143. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109144. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109145. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109146. 10,11,10,10,11, 9,10,10,10,
  109147. };
  109148. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109149. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109150. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109151. 6.5, 7.5, 8.5, 9.5,
  109152. };
  109153. static long _vq_quantmap__16c0_s_p9_2[] = {
  109154. 19, 17, 15, 13, 11, 9, 7, 5,
  109155. 3, 1, 0, 2, 4, 6, 8, 10,
  109156. 12, 14, 16, 18, 20,
  109157. };
  109158. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109159. _vq_quantthresh__16c0_s_p9_2,
  109160. _vq_quantmap__16c0_s_p9_2,
  109161. 21,
  109162. 21
  109163. };
  109164. static static_codebook _16c0_s_p9_2 = {
  109165. 2, 441,
  109166. _vq_lengthlist__16c0_s_p9_2,
  109167. 1, -529268736, 1611661312, 5, 0,
  109168. _vq_quantlist__16c0_s_p9_2,
  109169. NULL,
  109170. &_vq_auxt__16c0_s_p9_2,
  109171. NULL,
  109172. 0
  109173. };
  109174. static long _huff_lengthlist__16c0_s_single[] = {
  109175. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109176. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109177. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109178. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109179. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109180. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109181. 16,16,18,18,
  109182. };
  109183. static static_codebook _huff_book__16c0_s_single = {
  109184. 2, 100,
  109185. _huff_lengthlist__16c0_s_single,
  109186. 0, 0, 0, 0, 0,
  109187. NULL,
  109188. NULL,
  109189. NULL,
  109190. NULL,
  109191. 0
  109192. };
  109193. static long _huff_lengthlist__16c1_s_long[] = {
  109194. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109195. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109196. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109197. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109198. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109199. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109200. 12,11,11,13,
  109201. };
  109202. static static_codebook _huff_book__16c1_s_long = {
  109203. 2, 100,
  109204. _huff_lengthlist__16c1_s_long,
  109205. 0, 0, 0, 0, 0,
  109206. NULL,
  109207. NULL,
  109208. NULL,
  109209. NULL,
  109210. 0
  109211. };
  109212. static long _vq_quantlist__16c1_s_p1_0[] = {
  109213. 1,
  109214. 0,
  109215. 2,
  109216. };
  109217. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109218. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109219. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109224. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109229. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109264. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109269. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109274. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109287. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109292. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109310. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109315. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109320. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109629. };
  109630. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109631. -0.5, 0.5,
  109632. };
  109633. static long _vq_quantmap__16c1_s_p1_0[] = {
  109634. 1, 0, 2,
  109635. };
  109636. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109637. _vq_quantthresh__16c1_s_p1_0,
  109638. _vq_quantmap__16c1_s_p1_0,
  109639. 3,
  109640. 3
  109641. };
  109642. static static_codebook _16c1_s_p1_0 = {
  109643. 8, 6561,
  109644. _vq_lengthlist__16c1_s_p1_0,
  109645. 1, -535822336, 1611661312, 2, 0,
  109646. _vq_quantlist__16c1_s_p1_0,
  109647. NULL,
  109648. &_vq_auxt__16c1_s_p1_0,
  109649. NULL,
  109650. 0
  109651. };
  109652. static long _vq_quantlist__16c1_s_p2_0[] = {
  109653. 2,
  109654. 1,
  109655. 3,
  109656. 0,
  109657. 4,
  109658. };
  109659. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0,
  109700. };
  109701. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109702. -1.5, -0.5, 0.5, 1.5,
  109703. };
  109704. static long _vq_quantmap__16c1_s_p2_0[] = {
  109705. 3, 1, 0, 2, 4,
  109706. };
  109707. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109708. _vq_quantthresh__16c1_s_p2_0,
  109709. _vq_quantmap__16c1_s_p2_0,
  109710. 5,
  109711. 5
  109712. };
  109713. static static_codebook _16c1_s_p2_0 = {
  109714. 4, 625,
  109715. _vq_lengthlist__16c1_s_p2_0,
  109716. 1, -533725184, 1611661312, 3, 0,
  109717. _vq_quantlist__16c1_s_p2_0,
  109718. NULL,
  109719. &_vq_auxt__16c1_s_p2_0,
  109720. NULL,
  109721. 0
  109722. };
  109723. static long _vq_quantlist__16c1_s_p3_0[] = {
  109724. 2,
  109725. 1,
  109726. 3,
  109727. 0,
  109728. 4,
  109729. };
  109730. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109731. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109737. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109770. 0,
  109771. };
  109772. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109773. -1.5, -0.5, 0.5, 1.5,
  109774. };
  109775. static long _vq_quantmap__16c1_s_p3_0[] = {
  109776. 3, 1, 0, 2, 4,
  109777. };
  109778. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109779. _vq_quantthresh__16c1_s_p3_0,
  109780. _vq_quantmap__16c1_s_p3_0,
  109781. 5,
  109782. 5
  109783. };
  109784. static static_codebook _16c1_s_p3_0 = {
  109785. 4, 625,
  109786. _vq_lengthlist__16c1_s_p3_0,
  109787. 1, -533725184, 1611661312, 3, 0,
  109788. _vq_quantlist__16c1_s_p3_0,
  109789. NULL,
  109790. &_vq_auxt__16c1_s_p3_0,
  109791. NULL,
  109792. 0
  109793. };
  109794. static long _vq_quantlist__16c1_s_p4_0[] = {
  109795. 4,
  109796. 3,
  109797. 5,
  109798. 2,
  109799. 6,
  109800. 1,
  109801. 7,
  109802. 0,
  109803. 8,
  109804. };
  109805. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109806. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109807. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109808. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109809. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109810. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0,
  109812. };
  109813. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109814. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109815. };
  109816. static long _vq_quantmap__16c1_s_p4_0[] = {
  109817. 7, 5, 3, 1, 0, 2, 4, 6,
  109818. 8,
  109819. };
  109820. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109821. _vq_quantthresh__16c1_s_p4_0,
  109822. _vq_quantmap__16c1_s_p4_0,
  109823. 9,
  109824. 9
  109825. };
  109826. static static_codebook _16c1_s_p4_0 = {
  109827. 2, 81,
  109828. _vq_lengthlist__16c1_s_p4_0,
  109829. 1, -531628032, 1611661312, 4, 0,
  109830. _vq_quantlist__16c1_s_p4_0,
  109831. NULL,
  109832. &_vq_auxt__16c1_s_p4_0,
  109833. NULL,
  109834. 0
  109835. };
  109836. static long _vq_quantlist__16c1_s_p5_0[] = {
  109837. 4,
  109838. 3,
  109839. 5,
  109840. 2,
  109841. 6,
  109842. 1,
  109843. 7,
  109844. 0,
  109845. 8,
  109846. };
  109847. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109848. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109849. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109850. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109851. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109852. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109853. 10,
  109854. };
  109855. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109856. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109857. };
  109858. static long _vq_quantmap__16c1_s_p5_0[] = {
  109859. 7, 5, 3, 1, 0, 2, 4, 6,
  109860. 8,
  109861. };
  109862. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109863. _vq_quantthresh__16c1_s_p5_0,
  109864. _vq_quantmap__16c1_s_p5_0,
  109865. 9,
  109866. 9
  109867. };
  109868. static static_codebook _16c1_s_p5_0 = {
  109869. 2, 81,
  109870. _vq_lengthlist__16c1_s_p5_0,
  109871. 1, -531628032, 1611661312, 4, 0,
  109872. _vq_quantlist__16c1_s_p5_0,
  109873. NULL,
  109874. &_vq_auxt__16c1_s_p5_0,
  109875. NULL,
  109876. 0
  109877. };
  109878. static long _vq_quantlist__16c1_s_p6_0[] = {
  109879. 8,
  109880. 7,
  109881. 9,
  109882. 6,
  109883. 10,
  109884. 5,
  109885. 11,
  109886. 4,
  109887. 12,
  109888. 3,
  109889. 13,
  109890. 2,
  109891. 14,
  109892. 1,
  109893. 15,
  109894. 0,
  109895. 16,
  109896. };
  109897. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109898. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109899. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109900. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109901. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109902. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109903. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109904. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109905. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109906. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109907. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109908. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109909. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109910. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109911. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109912. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109913. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109914. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109916. 14,
  109917. };
  109918. static float _vq_quantthresh__16c1_s_p6_0[] = {
  109919. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109920. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109921. };
  109922. static long _vq_quantmap__16c1_s_p6_0[] = {
  109923. 15, 13, 11, 9, 7, 5, 3, 1,
  109924. 0, 2, 4, 6, 8, 10, 12, 14,
  109925. 16,
  109926. };
  109927. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  109928. _vq_quantthresh__16c1_s_p6_0,
  109929. _vq_quantmap__16c1_s_p6_0,
  109930. 17,
  109931. 17
  109932. };
  109933. static static_codebook _16c1_s_p6_0 = {
  109934. 2, 289,
  109935. _vq_lengthlist__16c1_s_p6_0,
  109936. 1, -529530880, 1611661312, 5, 0,
  109937. _vq_quantlist__16c1_s_p6_0,
  109938. NULL,
  109939. &_vq_auxt__16c1_s_p6_0,
  109940. NULL,
  109941. 0
  109942. };
  109943. static long _vq_quantlist__16c1_s_p7_0[] = {
  109944. 1,
  109945. 0,
  109946. 2,
  109947. };
  109948. static long _vq_lengthlist__16c1_s_p7_0[] = {
  109949. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  109950. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109951. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  109952. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  109953. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  109954. 11,
  109955. };
  109956. static float _vq_quantthresh__16c1_s_p7_0[] = {
  109957. -5.5, 5.5,
  109958. };
  109959. static long _vq_quantmap__16c1_s_p7_0[] = {
  109960. 1, 0, 2,
  109961. };
  109962. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  109963. _vq_quantthresh__16c1_s_p7_0,
  109964. _vq_quantmap__16c1_s_p7_0,
  109965. 3,
  109966. 3
  109967. };
  109968. static static_codebook _16c1_s_p7_0 = {
  109969. 4, 81,
  109970. _vq_lengthlist__16c1_s_p7_0,
  109971. 1, -529137664, 1618345984, 2, 0,
  109972. _vq_quantlist__16c1_s_p7_0,
  109973. NULL,
  109974. &_vq_auxt__16c1_s_p7_0,
  109975. NULL,
  109976. 0
  109977. };
  109978. static long _vq_quantlist__16c1_s_p7_1[] = {
  109979. 5,
  109980. 4,
  109981. 6,
  109982. 3,
  109983. 7,
  109984. 2,
  109985. 8,
  109986. 1,
  109987. 9,
  109988. 0,
  109989. 10,
  109990. };
  109991. static long _vq_lengthlist__16c1_s_p7_1[] = {
  109992. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  109993. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  109994. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  109995. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  109996. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  109997. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  109998. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  109999. 10,10,10, 8, 8, 8, 8, 9, 9,
  110000. };
  110001. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110002. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110003. 3.5, 4.5,
  110004. };
  110005. static long _vq_quantmap__16c1_s_p7_1[] = {
  110006. 9, 7, 5, 3, 1, 0, 2, 4,
  110007. 6, 8, 10,
  110008. };
  110009. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110010. _vq_quantthresh__16c1_s_p7_1,
  110011. _vq_quantmap__16c1_s_p7_1,
  110012. 11,
  110013. 11
  110014. };
  110015. static static_codebook _16c1_s_p7_1 = {
  110016. 2, 121,
  110017. _vq_lengthlist__16c1_s_p7_1,
  110018. 1, -531365888, 1611661312, 4, 0,
  110019. _vq_quantlist__16c1_s_p7_1,
  110020. NULL,
  110021. &_vq_auxt__16c1_s_p7_1,
  110022. NULL,
  110023. 0
  110024. };
  110025. static long _vq_quantlist__16c1_s_p8_0[] = {
  110026. 6,
  110027. 5,
  110028. 7,
  110029. 4,
  110030. 8,
  110031. 3,
  110032. 9,
  110033. 2,
  110034. 10,
  110035. 1,
  110036. 11,
  110037. 0,
  110038. 12,
  110039. };
  110040. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110041. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110042. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110043. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110044. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110045. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110046. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110047. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110048. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110049. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110050. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110051. 0,12,12,12,12,13,13,14,15,
  110052. };
  110053. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110054. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110055. 12.5, 17.5, 22.5, 27.5,
  110056. };
  110057. static long _vq_quantmap__16c1_s_p8_0[] = {
  110058. 11, 9, 7, 5, 3, 1, 0, 2,
  110059. 4, 6, 8, 10, 12,
  110060. };
  110061. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110062. _vq_quantthresh__16c1_s_p8_0,
  110063. _vq_quantmap__16c1_s_p8_0,
  110064. 13,
  110065. 13
  110066. };
  110067. static static_codebook _16c1_s_p8_0 = {
  110068. 2, 169,
  110069. _vq_lengthlist__16c1_s_p8_0,
  110070. 1, -526516224, 1616117760, 4, 0,
  110071. _vq_quantlist__16c1_s_p8_0,
  110072. NULL,
  110073. &_vq_auxt__16c1_s_p8_0,
  110074. NULL,
  110075. 0
  110076. };
  110077. static long _vq_quantlist__16c1_s_p8_1[] = {
  110078. 2,
  110079. 1,
  110080. 3,
  110081. 0,
  110082. 4,
  110083. };
  110084. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110085. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110086. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110087. };
  110088. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110089. -1.5, -0.5, 0.5, 1.5,
  110090. };
  110091. static long _vq_quantmap__16c1_s_p8_1[] = {
  110092. 3, 1, 0, 2, 4,
  110093. };
  110094. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110095. _vq_quantthresh__16c1_s_p8_1,
  110096. _vq_quantmap__16c1_s_p8_1,
  110097. 5,
  110098. 5
  110099. };
  110100. static static_codebook _16c1_s_p8_1 = {
  110101. 2, 25,
  110102. _vq_lengthlist__16c1_s_p8_1,
  110103. 1, -533725184, 1611661312, 3, 0,
  110104. _vq_quantlist__16c1_s_p8_1,
  110105. NULL,
  110106. &_vq_auxt__16c1_s_p8_1,
  110107. NULL,
  110108. 0
  110109. };
  110110. static long _vq_quantlist__16c1_s_p9_0[] = {
  110111. 6,
  110112. 5,
  110113. 7,
  110114. 4,
  110115. 8,
  110116. 3,
  110117. 9,
  110118. 2,
  110119. 10,
  110120. 1,
  110121. 11,
  110122. 0,
  110123. 12,
  110124. };
  110125. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110126. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110127. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110128. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110129. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110130. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110131. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110132. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110133. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110134. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110135. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110136. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110137. };
  110138. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110139. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110140. 787.5, 1102.5, 1417.5, 1732.5,
  110141. };
  110142. static long _vq_quantmap__16c1_s_p9_0[] = {
  110143. 11, 9, 7, 5, 3, 1, 0, 2,
  110144. 4, 6, 8, 10, 12,
  110145. };
  110146. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110147. _vq_quantthresh__16c1_s_p9_0,
  110148. _vq_quantmap__16c1_s_p9_0,
  110149. 13,
  110150. 13
  110151. };
  110152. static static_codebook _16c1_s_p9_0 = {
  110153. 2, 169,
  110154. _vq_lengthlist__16c1_s_p9_0,
  110155. 1, -513964032, 1628680192, 4, 0,
  110156. _vq_quantlist__16c1_s_p9_0,
  110157. NULL,
  110158. &_vq_auxt__16c1_s_p9_0,
  110159. NULL,
  110160. 0
  110161. };
  110162. static long _vq_quantlist__16c1_s_p9_1[] = {
  110163. 7,
  110164. 6,
  110165. 8,
  110166. 5,
  110167. 9,
  110168. 4,
  110169. 10,
  110170. 3,
  110171. 11,
  110172. 2,
  110173. 12,
  110174. 1,
  110175. 13,
  110176. 0,
  110177. 14,
  110178. };
  110179. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110180. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110181. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110182. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110183. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110184. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110185. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110186. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110187. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110188. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110189. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110190. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110191. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110192. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110193. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110194. 13,
  110195. };
  110196. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110197. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110198. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110199. };
  110200. static long _vq_quantmap__16c1_s_p9_1[] = {
  110201. 13, 11, 9, 7, 5, 3, 1, 0,
  110202. 2, 4, 6, 8, 10, 12, 14,
  110203. };
  110204. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110205. _vq_quantthresh__16c1_s_p9_1,
  110206. _vq_quantmap__16c1_s_p9_1,
  110207. 15,
  110208. 15
  110209. };
  110210. static static_codebook _16c1_s_p9_1 = {
  110211. 2, 225,
  110212. _vq_lengthlist__16c1_s_p9_1,
  110213. 1, -520986624, 1620377600, 4, 0,
  110214. _vq_quantlist__16c1_s_p9_1,
  110215. NULL,
  110216. &_vq_auxt__16c1_s_p9_1,
  110217. NULL,
  110218. 0
  110219. };
  110220. static long _vq_quantlist__16c1_s_p9_2[] = {
  110221. 10,
  110222. 9,
  110223. 11,
  110224. 8,
  110225. 12,
  110226. 7,
  110227. 13,
  110228. 6,
  110229. 14,
  110230. 5,
  110231. 15,
  110232. 4,
  110233. 16,
  110234. 3,
  110235. 17,
  110236. 2,
  110237. 18,
  110238. 1,
  110239. 19,
  110240. 0,
  110241. 20,
  110242. };
  110243. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110244. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110245. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110246. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110247. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110248. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110249. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110250. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110251. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110252. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110253. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110254. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110255. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110256. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110257. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110258. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110259. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110260. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110261. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110262. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110263. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110264. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110265. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110266. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110267. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110268. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110269. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110270. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110271. 11,11,11,11,12,11,11,12,11,
  110272. };
  110273. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110274. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110275. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110276. 6.5, 7.5, 8.5, 9.5,
  110277. };
  110278. static long _vq_quantmap__16c1_s_p9_2[] = {
  110279. 19, 17, 15, 13, 11, 9, 7, 5,
  110280. 3, 1, 0, 2, 4, 6, 8, 10,
  110281. 12, 14, 16, 18, 20,
  110282. };
  110283. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110284. _vq_quantthresh__16c1_s_p9_2,
  110285. _vq_quantmap__16c1_s_p9_2,
  110286. 21,
  110287. 21
  110288. };
  110289. static static_codebook _16c1_s_p9_2 = {
  110290. 2, 441,
  110291. _vq_lengthlist__16c1_s_p9_2,
  110292. 1, -529268736, 1611661312, 5, 0,
  110293. _vq_quantlist__16c1_s_p9_2,
  110294. NULL,
  110295. &_vq_auxt__16c1_s_p9_2,
  110296. NULL,
  110297. 0
  110298. };
  110299. static long _huff_lengthlist__16c1_s_short[] = {
  110300. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110301. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110302. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110303. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110304. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110305. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110306. 9, 9,10,13,
  110307. };
  110308. static static_codebook _huff_book__16c1_s_short = {
  110309. 2, 100,
  110310. _huff_lengthlist__16c1_s_short,
  110311. 0, 0, 0, 0, 0,
  110312. NULL,
  110313. NULL,
  110314. NULL,
  110315. NULL,
  110316. 0
  110317. };
  110318. static long _huff_lengthlist__16c2_s_long[] = {
  110319. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110320. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110321. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110322. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110323. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110324. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110325. 14,14,16,18,
  110326. };
  110327. static static_codebook _huff_book__16c2_s_long = {
  110328. 2, 100,
  110329. _huff_lengthlist__16c2_s_long,
  110330. 0, 0, 0, 0, 0,
  110331. NULL,
  110332. NULL,
  110333. NULL,
  110334. NULL,
  110335. 0
  110336. };
  110337. static long _vq_quantlist__16c2_s_p1_0[] = {
  110338. 1,
  110339. 0,
  110340. 2,
  110341. };
  110342. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110343. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110344. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0,
  110349. };
  110350. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110351. -0.5, 0.5,
  110352. };
  110353. static long _vq_quantmap__16c2_s_p1_0[] = {
  110354. 1, 0, 2,
  110355. };
  110356. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110357. _vq_quantthresh__16c2_s_p1_0,
  110358. _vq_quantmap__16c2_s_p1_0,
  110359. 3,
  110360. 3
  110361. };
  110362. static static_codebook _16c2_s_p1_0 = {
  110363. 4, 81,
  110364. _vq_lengthlist__16c2_s_p1_0,
  110365. 1, -535822336, 1611661312, 2, 0,
  110366. _vq_quantlist__16c2_s_p1_0,
  110367. NULL,
  110368. &_vq_auxt__16c2_s_p1_0,
  110369. NULL,
  110370. 0
  110371. };
  110372. static long _vq_quantlist__16c2_s_p2_0[] = {
  110373. 2,
  110374. 1,
  110375. 3,
  110376. 0,
  110377. 4,
  110378. };
  110379. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110380. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110381. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110382. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110383. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110384. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110385. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110386. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110387. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110392. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110393. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110394. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110395. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110400. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110401. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110402. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110403. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110408. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110409. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110410. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110411. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110412. 0, 0, 0, 0, 0, 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, 8,
  110416. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110417. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110418. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110419. 13,
  110420. };
  110421. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110422. -1.5, -0.5, 0.5, 1.5,
  110423. };
  110424. static long _vq_quantmap__16c2_s_p2_0[] = {
  110425. 3, 1, 0, 2, 4,
  110426. };
  110427. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110428. _vq_quantthresh__16c2_s_p2_0,
  110429. _vq_quantmap__16c2_s_p2_0,
  110430. 5,
  110431. 5
  110432. };
  110433. static static_codebook _16c2_s_p2_0 = {
  110434. 4, 625,
  110435. _vq_lengthlist__16c2_s_p2_0,
  110436. 1, -533725184, 1611661312, 3, 0,
  110437. _vq_quantlist__16c2_s_p2_0,
  110438. NULL,
  110439. &_vq_auxt__16c2_s_p2_0,
  110440. NULL,
  110441. 0
  110442. };
  110443. static long _vq_quantlist__16c2_s_p3_0[] = {
  110444. 4,
  110445. 3,
  110446. 5,
  110447. 2,
  110448. 6,
  110449. 1,
  110450. 7,
  110451. 0,
  110452. 8,
  110453. };
  110454. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110455. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110456. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110457. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110458. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110460. 0,
  110461. };
  110462. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110463. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110464. };
  110465. static long _vq_quantmap__16c2_s_p3_0[] = {
  110466. 7, 5, 3, 1, 0, 2, 4, 6,
  110467. 8,
  110468. };
  110469. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110470. _vq_quantthresh__16c2_s_p3_0,
  110471. _vq_quantmap__16c2_s_p3_0,
  110472. 9,
  110473. 9
  110474. };
  110475. static static_codebook _16c2_s_p3_0 = {
  110476. 2, 81,
  110477. _vq_lengthlist__16c2_s_p3_0,
  110478. 1, -531628032, 1611661312, 4, 0,
  110479. _vq_quantlist__16c2_s_p3_0,
  110480. NULL,
  110481. &_vq_auxt__16c2_s_p3_0,
  110482. NULL,
  110483. 0
  110484. };
  110485. static long _vq_quantlist__16c2_s_p4_0[] = {
  110486. 8,
  110487. 7,
  110488. 9,
  110489. 6,
  110490. 10,
  110491. 5,
  110492. 11,
  110493. 4,
  110494. 12,
  110495. 3,
  110496. 13,
  110497. 2,
  110498. 14,
  110499. 1,
  110500. 15,
  110501. 0,
  110502. 16,
  110503. };
  110504. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110505. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110506. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110507. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110508. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110509. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110510. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110511. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110512. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110513. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110514. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110523. 0,
  110524. };
  110525. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110526. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110527. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110528. };
  110529. static long _vq_quantmap__16c2_s_p4_0[] = {
  110530. 15, 13, 11, 9, 7, 5, 3, 1,
  110531. 0, 2, 4, 6, 8, 10, 12, 14,
  110532. 16,
  110533. };
  110534. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110535. _vq_quantthresh__16c2_s_p4_0,
  110536. _vq_quantmap__16c2_s_p4_0,
  110537. 17,
  110538. 17
  110539. };
  110540. static static_codebook _16c2_s_p4_0 = {
  110541. 2, 289,
  110542. _vq_lengthlist__16c2_s_p4_0,
  110543. 1, -529530880, 1611661312, 5, 0,
  110544. _vq_quantlist__16c2_s_p4_0,
  110545. NULL,
  110546. &_vq_auxt__16c2_s_p4_0,
  110547. NULL,
  110548. 0
  110549. };
  110550. static long _vq_quantlist__16c2_s_p5_0[] = {
  110551. 1,
  110552. 0,
  110553. 2,
  110554. };
  110555. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110556. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110557. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110558. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110559. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110560. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110561. 12,
  110562. };
  110563. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110564. -5.5, 5.5,
  110565. };
  110566. static long _vq_quantmap__16c2_s_p5_0[] = {
  110567. 1, 0, 2,
  110568. };
  110569. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110570. _vq_quantthresh__16c2_s_p5_0,
  110571. _vq_quantmap__16c2_s_p5_0,
  110572. 3,
  110573. 3
  110574. };
  110575. static static_codebook _16c2_s_p5_0 = {
  110576. 4, 81,
  110577. _vq_lengthlist__16c2_s_p5_0,
  110578. 1, -529137664, 1618345984, 2, 0,
  110579. _vq_quantlist__16c2_s_p5_0,
  110580. NULL,
  110581. &_vq_auxt__16c2_s_p5_0,
  110582. NULL,
  110583. 0
  110584. };
  110585. static long _vq_quantlist__16c2_s_p5_1[] = {
  110586. 5,
  110587. 4,
  110588. 6,
  110589. 3,
  110590. 7,
  110591. 2,
  110592. 8,
  110593. 1,
  110594. 9,
  110595. 0,
  110596. 10,
  110597. };
  110598. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110599. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110600. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110601. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110602. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110603. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110604. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110605. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110606. 11,11,11, 7, 7, 8, 8, 8, 8,
  110607. };
  110608. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110609. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110610. 3.5, 4.5,
  110611. };
  110612. static long _vq_quantmap__16c2_s_p5_1[] = {
  110613. 9, 7, 5, 3, 1, 0, 2, 4,
  110614. 6, 8, 10,
  110615. };
  110616. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110617. _vq_quantthresh__16c2_s_p5_1,
  110618. _vq_quantmap__16c2_s_p5_1,
  110619. 11,
  110620. 11
  110621. };
  110622. static static_codebook _16c2_s_p5_1 = {
  110623. 2, 121,
  110624. _vq_lengthlist__16c2_s_p5_1,
  110625. 1, -531365888, 1611661312, 4, 0,
  110626. _vq_quantlist__16c2_s_p5_1,
  110627. NULL,
  110628. &_vq_auxt__16c2_s_p5_1,
  110629. NULL,
  110630. 0
  110631. };
  110632. static long _vq_quantlist__16c2_s_p6_0[] = {
  110633. 6,
  110634. 5,
  110635. 7,
  110636. 4,
  110637. 8,
  110638. 3,
  110639. 9,
  110640. 2,
  110641. 10,
  110642. 1,
  110643. 11,
  110644. 0,
  110645. 12,
  110646. };
  110647. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110648. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110649. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110650. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110651. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110652. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110653. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110658. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110659. };
  110660. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110661. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110662. 12.5, 17.5, 22.5, 27.5,
  110663. };
  110664. static long _vq_quantmap__16c2_s_p6_0[] = {
  110665. 11, 9, 7, 5, 3, 1, 0, 2,
  110666. 4, 6, 8, 10, 12,
  110667. };
  110668. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110669. _vq_quantthresh__16c2_s_p6_0,
  110670. _vq_quantmap__16c2_s_p6_0,
  110671. 13,
  110672. 13
  110673. };
  110674. static static_codebook _16c2_s_p6_0 = {
  110675. 2, 169,
  110676. _vq_lengthlist__16c2_s_p6_0,
  110677. 1, -526516224, 1616117760, 4, 0,
  110678. _vq_quantlist__16c2_s_p6_0,
  110679. NULL,
  110680. &_vq_auxt__16c2_s_p6_0,
  110681. NULL,
  110682. 0
  110683. };
  110684. static long _vq_quantlist__16c2_s_p6_1[] = {
  110685. 2,
  110686. 1,
  110687. 3,
  110688. 0,
  110689. 4,
  110690. };
  110691. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110692. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110693. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110694. };
  110695. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110696. -1.5, -0.5, 0.5, 1.5,
  110697. };
  110698. static long _vq_quantmap__16c2_s_p6_1[] = {
  110699. 3, 1, 0, 2, 4,
  110700. };
  110701. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110702. _vq_quantthresh__16c2_s_p6_1,
  110703. _vq_quantmap__16c2_s_p6_1,
  110704. 5,
  110705. 5
  110706. };
  110707. static static_codebook _16c2_s_p6_1 = {
  110708. 2, 25,
  110709. _vq_lengthlist__16c2_s_p6_1,
  110710. 1, -533725184, 1611661312, 3, 0,
  110711. _vq_quantlist__16c2_s_p6_1,
  110712. NULL,
  110713. &_vq_auxt__16c2_s_p6_1,
  110714. NULL,
  110715. 0
  110716. };
  110717. static long _vq_quantlist__16c2_s_p7_0[] = {
  110718. 6,
  110719. 5,
  110720. 7,
  110721. 4,
  110722. 8,
  110723. 3,
  110724. 9,
  110725. 2,
  110726. 10,
  110727. 1,
  110728. 11,
  110729. 0,
  110730. 12,
  110731. };
  110732. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110733. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110734. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110735. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110736. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110737. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110738. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110739. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110740. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110741. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110742. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110743. 18,13,14,13,13,14,13,15,14,
  110744. };
  110745. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110746. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110747. 27.5, 38.5, 49.5, 60.5,
  110748. };
  110749. static long _vq_quantmap__16c2_s_p7_0[] = {
  110750. 11, 9, 7, 5, 3, 1, 0, 2,
  110751. 4, 6, 8, 10, 12,
  110752. };
  110753. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110754. _vq_quantthresh__16c2_s_p7_0,
  110755. _vq_quantmap__16c2_s_p7_0,
  110756. 13,
  110757. 13
  110758. };
  110759. static static_codebook _16c2_s_p7_0 = {
  110760. 2, 169,
  110761. _vq_lengthlist__16c2_s_p7_0,
  110762. 1, -523206656, 1618345984, 4, 0,
  110763. _vq_quantlist__16c2_s_p7_0,
  110764. NULL,
  110765. &_vq_auxt__16c2_s_p7_0,
  110766. NULL,
  110767. 0
  110768. };
  110769. static long _vq_quantlist__16c2_s_p7_1[] = {
  110770. 5,
  110771. 4,
  110772. 6,
  110773. 3,
  110774. 7,
  110775. 2,
  110776. 8,
  110777. 1,
  110778. 9,
  110779. 0,
  110780. 10,
  110781. };
  110782. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110783. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110784. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110785. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110786. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110787. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110788. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110789. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110790. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110791. };
  110792. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110793. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110794. 3.5, 4.5,
  110795. };
  110796. static long _vq_quantmap__16c2_s_p7_1[] = {
  110797. 9, 7, 5, 3, 1, 0, 2, 4,
  110798. 6, 8, 10,
  110799. };
  110800. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110801. _vq_quantthresh__16c2_s_p7_1,
  110802. _vq_quantmap__16c2_s_p7_1,
  110803. 11,
  110804. 11
  110805. };
  110806. static static_codebook _16c2_s_p7_1 = {
  110807. 2, 121,
  110808. _vq_lengthlist__16c2_s_p7_1,
  110809. 1, -531365888, 1611661312, 4, 0,
  110810. _vq_quantlist__16c2_s_p7_1,
  110811. NULL,
  110812. &_vq_auxt__16c2_s_p7_1,
  110813. NULL,
  110814. 0
  110815. };
  110816. static long _vq_quantlist__16c2_s_p8_0[] = {
  110817. 7,
  110818. 6,
  110819. 8,
  110820. 5,
  110821. 9,
  110822. 4,
  110823. 10,
  110824. 3,
  110825. 11,
  110826. 2,
  110827. 12,
  110828. 1,
  110829. 13,
  110830. 0,
  110831. 14,
  110832. };
  110833. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110834. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110835. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110836. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110837. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110838. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110839. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110840. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110841. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110842. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110843. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110844. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110845. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110846. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110847. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110848. 13,
  110849. };
  110850. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110851. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110852. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110853. };
  110854. static long _vq_quantmap__16c2_s_p8_0[] = {
  110855. 13, 11, 9, 7, 5, 3, 1, 0,
  110856. 2, 4, 6, 8, 10, 12, 14,
  110857. };
  110858. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110859. _vq_quantthresh__16c2_s_p8_0,
  110860. _vq_quantmap__16c2_s_p8_0,
  110861. 15,
  110862. 15
  110863. };
  110864. static static_codebook _16c2_s_p8_0 = {
  110865. 2, 225,
  110866. _vq_lengthlist__16c2_s_p8_0,
  110867. 1, -520986624, 1620377600, 4, 0,
  110868. _vq_quantlist__16c2_s_p8_0,
  110869. NULL,
  110870. &_vq_auxt__16c2_s_p8_0,
  110871. NULL,
  110872. 0
  110873. };
  110874. static long _vq_quantlist__16c2_s_p8_1[] = {
  110875. 10,
  110876. 9,
  110877. 11,
  110878. 8,
  110879. 12,
  110880. 7,
  110881. 13,
  110882. 6,
  110883. 14,
  110884. 5,
  110885. 15,
  110886. 4,
  110887. 16,
  110888. 3,
  110889. 17,
  110890. 2,
  110891. 18,
  110892. 1,
  110893. 19,
  110894. 0,
  110895. 20,
  110896. };
  110897. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110898. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110899. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110900. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110901. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110902. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110903. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110904. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110905. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110906. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110907. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110908. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110909. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110910. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110911. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110912. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110913. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110914. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110915. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110916. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  110917. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  110918. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  110919. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  110920. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  110921. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  110922. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  110923. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  110924. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  110925. 10,11,10,10,10,10,10,10,10,
  110926. };
  110927. static float _vq_quantthresh__16c2_s_p8_1[] = {
  110928. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110929. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110930. 6.5, 7.5, 8.5, 9.5,
  110931. };
  110932. static long _vq_quantmap__16c2_s_p8_1[] = {
  110933. 19, 17, 15, 13, 11, 9, 7, 5,
  110934. 3, 1, 0, 2, 4, 6, 8, 10,
  110935. 12, 14, 16, 18, 20,
  110936. };
  110937. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  110938. _vq_quantthresh__16c2_s_p8_1,
  110939. _vq_quantmap__16c2_s_p8_1,
  110940. 21,
  110941. 21
  110942. };
  110943. static static_codebook _16c2_s_p8_1 = {
  110944. 2, 441,
  110945. _vq_lengthlist__16c2_s_p8_1,
  110946. 1, -529268736, 1611661312, 5, 0,
  110947. _vq_quantlist__16c2_s_p8_1,
  110948. NULL,
  110949. &_vq_auxt__16c2_s_p8_1,
  110950. NULL,
  110951. 0
  110952. };
  110953. static long _vq_quantlist__16c2_s_p9_0[] = {
  110954. 6,
  110955. 5,
  110956. 7,
  110957. 4,
  110958. 8,
  110959. 3,
  110960. 9,
  110961. 2,
  110962. 10,
  110963. 1,
  110964. 11,
  110965. 0,
  110966. 12,
  110967. };
  110968. static long _vq_lengthlist__16c2_s_p9_0[] = {
  110969. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110970. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110971. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110972. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110973. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110974. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110975. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110976. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110977. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110978. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110979. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110980. };
  110981. static float _vq_quantthresh__16c2_s_p9_0[] = {
  110982. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  110983. 2327.5, 3258.5, 4189.5, 5120.5,
  110984. };
  110985. static long _vq_quantmap__16c2_s_p9_0[] = {
  110986. 11, 9, 7, 5, 3, 1, 0, 2,
  110987. 4, 6, 8, 10, 12,
  110988. };
  110989. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  110990. _vq_quantthresh__16c2_s_p9_0,
  110991. _vq_quantmap__16c2_s_p9_0,
  110992. 13,
  110993. 13
  110994. };
  110995. static static_codebook _16c2_s_p9_0 = {
  110996. 2, 169,
  110997. _vq_lengthlist__16c2_s_p9_0,
  110998. 1, -510275072, 1631393792, 4, 0,
  110999. _vq_quantlist__16c2_s_p9_0,
  111000. NULL,
  111001. &_vq_auxt__16c2_s_p9_0,
  111002. NULL,
  111003. 0
  111004. };
  111005. static long _vq_quantlist__16c2_s_p9_1[] = {
  111006. 8,
  111007. 7,
  111008. 9,
  111009. 6,
  111010. 10,
  111011. 5,
  111012. 11,
  111013. 4,
  111014. 12,
  111015. 3,
  111016. 13,
  111017. 2,
  111018. 14,
  111019. 1,
  111020. 15,
  111021. 0,
  111022. 16,
  111023. };
  111024. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111025. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111026. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111027. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111028. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111029. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111030. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111031. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111032. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111033. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111034. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111035. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111036. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111037. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111038. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111039. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111040. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111041. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111042. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111043. 10,
  111044. };
  111045. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111046. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111047. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111048. };
  111049. static long _vq_quantmap__16c2_s_p9_1[] = {
  111050. 15, 13, 11, 9, 7, 5, 3, 1,
  111051. 0, 2, 4, 6, 8, 10, 12, 14,
  111052. 16,
  111053. };
  111054. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111055. _vq_quantthresh__16c2_s_p9_1,
  111056. _vq_quantmap__16c2_s_p9_1,
  111057. 17,
  111058. 17
  111059. };
  111060. static static_codebook _16c2_s_p9_1 = {
  111061. 2, 289,
  111062. _vq_lengthlist__16c2_s_p9_1,
  111063. 1, -518488064, 1622704128, 5, 0,
  111064. _vq_quantlist__16c2_s_p9_1,
  111065. NULL,
  111066. &_vq_auxt__16c2_s_p9_1,
  111067. NULL,
  111068. 0
  111069. };
  111070. static long _vq_quantlist__16c2_s_p9_2[] = {
  111071. 13,
  111072. 12,
  111073. 14,
  111074. 11,
  111075. 15,
  111076. 10,
  111077. 16,
  111078. 9,
  111079. 17,
  111080. 8,
  111081. 18,
  111082. 7,
  111083. 19,
  111084. 6,
  111085. 20,
  111086. 5,
  111087. 21,
  111088. 4,
  111089. 22,
  111090. 3,
  111091. 23,
  111092. 2,
  111093. 24,
  111094. 1,
  111095. 25,
  111096. 0,
  111097. 26,
  111098. };
  111099. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111100. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111101. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111102. };
  111103. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111104. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111105. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111106. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111107. 11.5, 12.5,
  111108. };
  111109. static long _vq_quantmap__16c2_s_p9_2[] = {
  111110. 25, 23, 21, 19, 17, 15, 13, 11,
  111111. 9, 7, 5, 3, 1, 0, 2, 4,
  111112. 6, 8, 10, 12, 14, 16, 18, 20,
  111113. 22, 24, 26,
  111114. };
  111115. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111116. _vq_quantthresh__16c2_s_p9_2,
  111117. _vq_quantmap__16c2_s_p9_2,
  111118. 27,
  111119. 27
  111120. };
  111121. static static_codebook _16c2_s_p9_2 = {
  111122. 1, 27,
  111123. _vq_lengthlist__16c2_s_p9_2,
  111124. 1, -528875520, 1611661312, 5, 0,
  111125. _vq_quantlist__16c2_s_p9_2,
  111126. NULL,
  111127. &_vq_auxt__16c2_s_p9_2,
  111128. NULL,
  111129. 0
  111130. };
  111131. static long _huff_lengthlist__16c2_s_short[] = {
  111132. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111133. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111134. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111135. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111136. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111137. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111138. 15,12,14,14,
  111139. };
  111140. static static_codebook _huff_book__16c2_s_short = {
  111141. 2, 100,
  111142. _huff_lengthlist__16c2_s_short,
  111143. 0, 0, 0, 0, 0,
  111144. NULL,
  111145. NULL,
  111146. NULL,
  111147. NULL,
  111148. 0
  111149. };
  111150. static long _vq_quantlist__8c0_s_p1_0[] = {
  111151. 1,
  111152. 0,
  111153. 2,
  111154. };
  111155. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111156. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111157. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111161. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111162. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111166. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111167. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111202. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111207. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111212. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111225. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111230. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111235. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111248. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111253. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111258. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  111270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  111275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  111280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  111567. };
  111568. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111569. -0.5, 0.5,
  111570. };
  111571. static long _vq_quantmap__8c0_s_p1_0[] = {
  111572. 1, 0, 2,
  111573. };
  111574. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111575. _vq_quantthresh__8c0_s_p1_0,
  111576. _vq_quantmap__8c0_s_p1_0,
  111577. 3,
  111578. 3
  111579. };
  111580. static static_codebook _8c0_s_p1_0 = {
  111581. 8, 6561,
  111582. _vq_lengthlist__8c0_s_p1_0,
  111583. 1, -535822336, 1611661312, 2, 0,
  111584. _vq_quantlist__8c0_s_p1_0,
  111585. NULL,
  111586. &_vq_auxt__8c0_s_p1_0,
  111587. NULL,
  111588. 0
  111589. };
  111590. static long _vq_quantlist__8c0_s_p2_0[] = {
  111591. 2,
  111592. 1,
  111593. 3,
  111594. 0,
  111595. 4,
  111596. };
  111597. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0,
  111638. };
  111639. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111640. -1.5, -0.5, 0.5, 1.5,
  111641. };
  111642. static long _vq_quantmap__8c0_s_p2_0[] = {
  111643. 3, 1, 0, 2, 4,
  111644. };
  111645. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111646. _vq_quantthresh__8c0_s_p2_0,
  111647. _vq_quantmap__8c0_s_p2_0,
  111648. 5,
  111649. 5
  111650. };
  111651. static static_codebook _8c0_s_p2_0 = {
  111652. 4, 625,
  111653. _vq_lengthlist__8c0_s_p2_0,
  111654. 1, -533725184, 1611661312, 3, 0,
  111655. _vq_quantlist__8c0_s_p2_0,
  111656. NULL,
  111657. &_vq_auxt__8c0_s_p2_0,
  111658. NULL,
  111659. 0
  111660. };
  111661. static long _vq_quantlist__8c0_s_p3_0[] = {
  111662. 2,
  111663. 1,
  111664. 3,
  111665. 0,
  111666. 4,
  111667. };
  111668. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111669. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111675. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111708. 0,
  111709. };
  111710. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111711. -1.5, -0.5, 0.5, 1.5,
  111712. };
  111713. static long _vq_quantmap__8c0_s_p3_0[] = {
  111714. 3, 1, 0, 2, 4,
  111715. };
  111716. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111717. _vq_quantthresh__8c0_s_p3_0,
  111718. _vq_quantmap__8c0_s_p3_0,
  111719. 5,
  111720. 5
  111721. };
  111722. static static_codebook _8c0_s_p3_0 = {
  111723. 4, 625,
  111724. _vq_lengthlist__8c0_s_p3_0,
  111725. 1, -533725184, 1611661312, 3, 0,
  111726. _vq_quantlist__8c0_s_p3_0,
  111727. NULL,
  111728. &_vq_auxt__8c0_s_p3_0,
  111729. NULL,
  111730. 0
  111731. };
  111732. static long _vq_quantlist__8c0_s_p4_0[] = {
  111733. 4,
  111734. 3,
  111735. 5,
  111736. 2,
  111737. 6,
  111738. 1,
  111739. 7,
  111740. 0,
  111741. 8,
  111742. };
  111743. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111744. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111745. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111746. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111747. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111748. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0,
  111750. };
  111751. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111752. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111753. };
  111754. static long _vq_quantmap__8c0_s_p4_0[] = {
  111755. 7, 5, 3, 1, 0, 2, 4, 6,
  111756. 8,
  111757. };
  111758. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111759. _vq_quantthresh__8c0_s_p4_0,
  111760. _vq_quantmap__8c0_s_p4_0,
  111761. 9,
  111762. 9
  111763. };
  111764. static static_codebook _8c0_s_p4_0 = {
  111765. 2, 81,
  111766. _vq_lengthlist__8c0_s_p4_0,
  111767. 1, -531628032, 1611661312, 4, 0,
  111768. _vq_quantlist__8c0_s_p4_0,
  111769. NULL,
  111770. &_vq_auxt__8c0_s_p4_0,
  111771. NULL,
  111772. 0
  111773. };
  111774. static long _vq_quantlist__8c0_s_p5_0[] = {
  111775. 4,
  111776. 3,
  111777. 5,
  111778. 2,
  111779. 6,
  111780. 1,
  111781. 7,
  111782. 0,
  111783. 8,
  111784. };
  111785. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111786. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111787. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111788. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111789. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111790. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111791. 10,
  111792. };
  111793. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111794. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111795. };
  111796. static long _vq_quantmap__8c0_s_p5_0[] = {
  111797. 7, 5, 3, 1, 0, 2, 4, 6,
  111798. 8,
  111799. };
  111800. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111801. _vq_quantthresh__8c0_s_p5_0,
  111802. _vq_quantmap__8c0_s_p5_0,
  111803. 9,
  111804. 9
  111805. };
  111806. static static_codebook _8c0_s_p5_0 = {
  111807. 2, 81,
  111808. _vq_lengthlist__8c0_s_p5_0,
  111809. 1, -531628032, 1611661312, 4, 0,
  111810. _vq_quantlist__8c0_s_p5_0,
  111811. NULL,
  111812. &_vq_auxt__8c0_s_p5_0,
  111813. NULL,
  111814. 0
  111815. };
  111816. static long _vq_quantlist__8c0_s_p6_0[] = {
  111817. 8,
  111818. 7,
  111819. 9,
  111820. 6,
  111821. 10,
  111822. 5,
  111823. 11,
  111824. 4,
  111825. 12,
  111826. 3,
  111827. 13,
  111828. 2,
  111829. 14,
  111830. 1,
  111831. 15,
  111832. 0,
  111833. 16,
  111834. };
  111835. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111836. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111837. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111838. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111839. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111840. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111841. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111842. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111843. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111844. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111845. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111846. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111847. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111848. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111849. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111850. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111851. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111852. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111854. 14,
  111855. };
  111856. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111857. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111858. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111859. };
  111860. static long _vq_quantmap__8c0_s_p6_0[] = {
  111861. 15, 13, 11, 9, 7, 5, 3, 1,
  111862. 0, 2, 4, 6, 8, 10, 12, 14,
  111863. 16,
  111864. };
  111865. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111866. _vq_quantthresh__8c0_s_p6_0,
  111867. _vq_quantmap__8c0_s_p6_0,
  111868. 17,
  111869. 17
  111870. };
  111871. static static_codebook _8c0_s_p6_0 = {
  111872. 2, 289,
  111873. _vq_lengthlist__8c0_s_p6_0,
  111874. 1, -529530880, 1611661312, 5, 0,
  111875. _vq_quantlist__8c0_s_p6_0,
  111876. NULL,
  111877. &_vq_auxt__8c0_s_p6_0,
  111878. NULL,
  111879. 0
  111880. };
  111881. static long _vq_quantlist__8c0_s_p7_0[] = {
  111882. 1,
  111883. 0,
  111884. 2,
  111885. };
  111886. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111887. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111888. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111889. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111890. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111891. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111892. 10,
  111893. };
  111894. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111895. -5.5, 5.5,
  111896. };
  111897. static long _vq_quantmap__8c0_s_p7_0[] = {
  111898. 1, 0, 2,
  111899. };
  111900. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111901. _vq_quantthresh__8c0_s_p7_0,
  111902. _vq_quantmap__8c0_s_p7_0,
  111903. 3,
  111904. 3
  111905. };
  111906. static static_codebook _8c0_s_p7_0 = {
  111907. 4, 81,
  111908. _vq_lengthlist__8c0_s_p7_0,
  111909. 1, -529137664, 1618345984, 2, 0,
  111910. _vq_quantlist__8c0_s_p7_0,
  111911. NULL,
  111912. &_vq_auxt__8c0_s_p7_0,
  111913. NULL,
  111914. 0
  111915. };
  111916. static long _vq_quantlist__8c0_s_p7_1[] = {
  111917. 5,
  111918. 4,
  111919. 6,
  111920. 3,
  111921. 7,
  111922. 2,
  111923. 8,
  111924. 1,
  111925. 9,
  111926. 0,
  111927. 10,
  111928. };
  111929. static long _vq_lengthlist__8c0_s_p7_1[] = {
  111930. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  111931. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  111932. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  111933. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  111934. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  111935. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  111936. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  111937. 10,10,10, 9, 9, 9,10,10,10,
  111938. };
  111939. static float _vq_quantthresh__8c0_s_p7_1[] = {
  111940. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111941. 3.5, 4.5,
  111942. };
  111943. static long _vq_quantmap__8c0_s_p7_1[] = {
  111944. 9, 7, 5, 3, 1, 0, 2, 4,
  111945. 6, 8, 10,
  111946. };
  111947. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  111948. _vq_quantthresh__8c0_s_p7_1,
  111949. _vq_quantmap__8c0_s_p7_1,
  111950. 11,
  111951. 11
  111952. };
  111953. static static_codebook _8c0_s_p7_1 = {
  111954. 2, 121,
  111955. _vq_lengthlist__8c0_s_p7_1,
  111956. 1, -531365888, 1611661312, 4, 0,
  111957. _vq_quantlist__8c0_s_p7_1,
  111958. NULL,
  111959. &_vq_auxt__8c0_s_p7_1,
  111960. NULL,
  111961. 0
  111962. };
  111963. static long _vq_quantlist__8c0_s_p8_0[] = {
  111964. 6,
  111965. 5,
  111966. 7,
  111967. 4,
  111968. 8,
  111969. 3,
  111970. 9,
  111971. 2,
  111972. 10,
  111973. 1,
  111974. 11,
  111975. 0,
  111976. 12,
  111977. };
  111978. static long _vq_lengthlist__8c0_s_p8_0[] = {
  111979. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  111980. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  111981. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  111982. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  111983. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  111984. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  111985. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  111986. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  111987. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  111988. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  111989. 0, 0,13,13,11,13,13,11,12,
  111990. };
  111991. static float _vq_quantthresh__8c0_s_p8_0[] = {
  111992. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111993. 12.5, 17.5, 22.5, 27.5,
  111994. };
  111995. static long _vq_quantmap__8c0_s_p8_0[] = {
  111996. 11, 9, 7, 5, 3, 1, 0, 2,
  111997. 4, 6, 8, 10, 12,
  111998. };
  111999. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112000. _vq_quantthresh__8c0_s_p8_0,
  112001. _vq_quantmap__8c0_s_p8_0,
  112002. 13,
  112003. 13
  112004. };
  112005. static static_codebook _8c0_s_p8_0 = {
  112006. 2, 169,
  112007. _vq_lengthlist__8c0_s_p8_0,
  112008. 1, -526516224, 1616117760, 4, 0,
  112009. _vq_quantlist__8c0_s_p8_0,
  112010. NULL,
  112011. &_vq_auxt__8c0_s_p8_0,
  112012. NULL,
  112013. 0
  112014. };
  112015. static long _vq_quantlist__8c0_s_p8_1[] = {
  112016. 2,
  112017. 1,
  112018. 3,
  112019. 0,
  112020. 4,
  112021. };
  112022. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112023. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112024. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112025. };
  112026. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112027. -1.5, -0.5, 0.5, 1.5,
  112028. };
  112029. static long _vq_quantmap__8c0_s_p8_1[] = {
  112030. 3, 1, 0, 2, 4,
  112031. };
  112032. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112033. _vq_quantthresh__8c0_s_p8_1,
  112034. _vq_quantmap__8c0_s_p8_1,
  112035. 5,
  112036. 5
  112037. };
  112038. static static_codebook _8c0_s_p8_1 = {
  112039. 2, 25,
  112040. _vq_lengthlist__8c0_s_p8_1,
  112041. 1, -533725184, 1611661312, 3, 0,
  112042. _vq_quantlist__8c0_s_p8_1,
  112043. NULL,
  112044. &_vq_auxt__8c0_s_p8_1,
  112045. NULL,
  112046. 0
  112047. };
  112048. static long _vq_quantlist__8c0_s_p9_0[] = {
  112049. 1,
  112050. 0,
  112051. 2,
  112052. };
  112053. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112054. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112055. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112056. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112057. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112058. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112059. 7,
  112060. };
  112061. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112062. -157.5, 157.5,
  112063. };
  112064. static long _vq_quantmap__8c0_s_p9_0[] = {
  112065. 1, 0, 2,
  112066. };
  112067. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112068. _vq_quantthresh__8c0_s_p9_0,
  112069. _vq_quantmap__8c0_s_p9_0,
  112070. 3,
  112071. 3
  112072. };
  112073. static static_codebook _8c0_s_p9_0 = {
  112074. 4, 81,
  112075. _vq_lengthlist__8c0_s_p9_0,
  112076. 1, -518803456, 1628680192, 2, 0,
  112077. _vq_quantlist__8c0_s_p9_0,
  112078. NULL,
  112079. &_vq_auxt__8c0_s_p9_0,
  112080. NULL,
  112081. 0
  112082. };
  112083. static long _vq_quantlist__8c0_s_p9_1[] = {
  112084. 7,
  112085. 6,
  112086. 8,
  112087. 5,
  112088. 9,
  112089. 4,
  112090. 10,
  112091. 3,
  112092. 11,
  112093. 2,
  112094. 12,
  112095. 1,
  112096. 13,
  112097. 0,
  112098. 14,
  112099. };
  112100. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112101. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112102. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112103. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112104. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112105. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112106. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112107. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112108. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112109. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112110. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112111. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112112. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112115. 11,
  112116. };
  112117. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112118. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112119. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112120. };
  112121. static long _vq_quantmap__8c0_s_p9_1[] = {
  112122. 13, 11, 9, 7, 5, 3, 1, 0,
  112123. 2, 4, 6, 8, 10, 12, 14,
  112124. };
  112125. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112126. _vq_quantthresh__8c0_s_p9_1,
  112127. _vq_quantmap__8c0_s_p9_1,
  112128. 15,
  112129. 15
  112130. };
  112131. static static_codebook _8c0_s_p9_1 = {
  112132. 2, 225,
  112133. _vq_lengthlist__8c0_s_p9_1,
  112134. 1, -520986624, 1620377600, 4, 0,
  112135. _vq_quantlist__8c0_s_p9_1,
  112136. NULL,
  112137. &_vq_auxt__8c0_s_p9_1,
  112138. NULL,
  112139. 0
  112140. };
  112141. static long _vq_quantlist__8c0_s_p9_2[] = {
  112142. 10,
  112143. 9,
  112144. 11,
  112145. 8,
  112146. 12,
  112147. 7,
  112148. 13,
  112149. 6,
  112150. 14,
  112151. 5,
  112152. 15,
  112153. 4,
  112154. 16,
  112155. 3,
  112156. 17,
  112157. 2,
  112158. 18,
  112159. 1,
  112160. 19,
  112161. 0,
  112162. 20,
  112163. };
  112164. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112165. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112166. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112167. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112168. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112169. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112170. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112171. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112172. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112173. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112174. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112175. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112176. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112177. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112178. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112179. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112180. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112181. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112182. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112183. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112184. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112185. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112186. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112187. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112188. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112189. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112190. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112191. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112192. 10,11, 9,11,10, 9,10, 9,10,
  112193. };
  112194. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112195. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112196. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112197. 6.5, 7.5, 8.5, 9.5,
  112198. };
  112199. static long _vq_quantmap__8c0_s_p9_2[] = {
  112200. 19, 17, 15, 13, 11, 9, 7, 5,
  112201. 3, 1, 0, 2, 4, 6, 8, 10,
  112202. 12, 14, 16, 18, 20,
  112203. };
  112204. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112205. _vq_quantthresh__8c0_s_p9_2,
  112206. _vq_quantmap__8c0_s_p9_2,
  112207. 21,
  112208. 21
  112209. };
  112210. static static_codebook _8c0_s_p9_2 = {
  112211. 2, 441,
  112212. _vq_lengthlist__8c0_s_p9_2,
  112213. 1, -529268736, 1611661312, 5, 0,
  112214. _vq_quantlist__8c0_s_p9_2,
  112215. NULL,
  112216. &_vq_auxt__8c0_s_p9_2,
  112217. NULL,
  112218. 0
  112219. };
  112220. static long _huff_lengthlist__8c0_s_single[] = {
  112221. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112222. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112223. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112224. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112225. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112226. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112227. 17,16,17,17,
  112228. };
  112229. static static_codebook _huff_book__8c0_s_single = {
  112230. 2, 100,
  112231. _huff_lengthlist__8c0_s_single,
  112232. 0, 0, 0, 0, 0,
  112233. NULL,
  112234. NULL,
  112235. NULL,
  112236. NULL,
  112237. 0
  112238. };
  112239. static long _vq_quantlist__8c1_s_p1_0[] = {
  112240. 1,
  112241. 0,
  112242. 2,
  112243. };
  112244. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112245. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112246. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112251. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112256. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112291. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112296. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112301. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112314. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112319. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112324. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112337. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112342. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112347. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112656. };
  112657. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112658. -0.5, 0.5,
  112659. };
  112660. static long _vq_quantmap__8c1_s_p1_0[] = {
  112661. 1, 0, 2,
  112662. };
  112663. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112664. _vq_quantthresh__8c1_s_p1_0,
  112665. _vq_quantmap__8c1_s_p1_0,
  112666. 3,
  112667. 3
  112668. };
  112669. static static_codebook _8c1_s_p1_0 = {
  112670. 8, 6561,
  112671. _vq_lengthlist__8c1_s_p1_0,
  112672. 1, -535822336, 1611661312, 2, 0,
  112673. _vq_quantlist__8c1_s_p1_0,
  112674. NULL,
  112675. &_vq_auxt__8c1_s_p1_0,
  112676. NULL,
  112677. 0
  112678. };
  112679. static long _vq_quantlist__8c1_s_p2_0[] = {
  112680. 2,
  112681. 1,
  112682. 3,
  112683. 0,
  112684. 4,
  112685. };
  112686. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0,
  112727. };
  112728. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112729. -1.5, -0.5, 0.5, 1.5,
  112730. };
  112731. static long _vq_quantmap__8c1_s_p2_0[] = {
  112732. 3, 1, 0, 2, 4,
  112733. };
  112734. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112735. _vq_quantthresh__8c1_s_p2_0,
  112736. _vq_quantmap__8c1_s_p2_0,
  112737. 5,
  112738. 5
  112739. };
  112740. static static_codebook _8c1_s_p2_0 = {
  112741. 4, 625,
  112742. _vq_lengthlist__8c1_s_p2_0,
  112743. 1, -533725184, 1611661312, 3, 0,
  112744. _vq_quantlist__8c1_s_p2_0,
  112745. NULL,
  112746. &_vq_auxt__8c1_s_p2_0,
  112747. NULL,
  112748. 0
  112749. };
  112750. static long _vq_quantlist__8c1_s_p3_0[] = {
  112751. 2,
  112752. 1,
  112753. 3,
  112754. 0,
  112755. 4,
  112756. };
  112757. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112758. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112764. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112797. 0,
  112798. };
  112799. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112800. -1.5, -0.5, 0.5, 1.5,
  112801. };
  112802. static long _vq_quantmap__8c1_s_p3_0[] = {
  112803. 3, 1, 0, 2, 4,
  112804. };
  112805. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112806. _vq_quantthresh__8c1_s_p3_0,
  112807. _vq_quantmap__8c1_s_p3_0,
  112808. 5,
  112809. 5
  112810. };
  112811. static static_codebook _8c1_s_p3_0 = {
  112812. 4, 625,
  112813. _vq_lengthlist__8c1_s_p3_0,
  112814. 1, -533725184, 1611661312, 3, 0,
  112815. _vq_quantlist__8c1_s_p3_0,
  112816. NULL,
  112817. &_vq_auxt__8c1_s_p3_0,
  112818. NULL,
  112819. 0
  112820. };
  112821. static long _vq_quantlist__8c1_s_p4_0[] = {
  112822. 4,
  112823. 3,
  112824. 5,
  112825. 2,
  112826. 6,
  112827. 1,
  112828. 7,
  112829. 0,
  112830. 8,
  112831. };
  112832. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112833. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112834. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112835. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112836. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112837. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0,
  112839. };
  112840. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112841. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112842. };
  112843. static long _vq_quantmap__8c1_s_p4_0[] = {
  112844. 7, 5, 3, 1, 0, 2, 4, 6,
  112845. 8,
  112846. };
  112847. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112848. _vq_quantthresh__8c1_s_p4_0,
  112849. _vq_quantmap__8c1_s_p4_0,
  112850. 9,
  112851. 9
  112852. };
  112853. static static_codebook _8c1_s_p4_0 = {
  112854. 2, 81,
  112855. _vq_lengthlist__8c1_s_p4_0,
  112856. 1, -531628032, 1611661312, 4, 0,
  112857. _vq_quantlist__8c1_s_p4_0,
  112858. NULL,
  112859. &_vq_auxt__8c1_s_p4_0,
  112860. NULL,
  112861. 0
  112862. };
  112863. static long _vq_quantlist__8c1_s_p5_0[] = {
  112864. 4,
  112865. 3,
  112866. 5,
  112867. 2,
  112868. 6,
  112869. 1,
  112870. 7,
  112871. 0,
  112872. 8,
  112873. };
  112874. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112875. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112876. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112877. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112878. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112879. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112880. 10,
  112881. };
  112882. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112883. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112884. };
  112885. static long _vq_quantmap__8c1_s_p5_0[] = {
  112886. 7, 5, 3, 1, 0, 2, 4, 6,
  112887. 8,
  112888. };
  112889. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112890. _vq_quantthresh__8c1_s_p5_0,
  112891. _vq_quantmap__8c1_s_p5_0,
  112892. 9,
  112893. 9
  112894. };
  112895. static static_codebook _8c1_s_p5_0 = {
  112896. 2, 81,
  112897. _vq_lengthlist__8c1_s_p5_0,
  112898. 1, -531628032, 1611661312, 4, 0,
  112899. _vq_quantlist__8c1_s_p5_0,
  112900. NULL,
  112901. &_vq_auxt__8c1_s_p5_0,
  112902. NULL,
  112903. 0
  112904. };
  112905. static long _vq_quantlist__8c1_s_p6_0[] = {
  112906. 8,
  112907. 7,
  112908. 9,
  112909. 6,
  112910. 10,
  112911. 5,
  112912. 11,
  112913. 4,
  112914. 12,
  112915. 3,
  112916. 13,
  112917. 2,
  112918. 14,
  112919. 1,
  112920. 15,
  112921. 0,
  112922. 16,
  112923. };
  112924. static long _vq_lengthlist__8c1_s_p6_0[] = {
  112925. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  112926. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112927. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112928. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  112929. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  112930. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  112931. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  112932. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  112933. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  112934. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112935. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  112936. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  112937. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  112938. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  112939. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  112940. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  112941. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  112943. 14,
  112944. };
  112945. static float _vq_quantthresh__8c1_s_p6_0[] = {
  112946. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112947. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112948. };
  112949. static long _vq_quantmap__8c1_s_p6_0[] = {
  112950. 15, 13, 11, 9, 7, 5, 3, 1,
  112951. 0, 2, 4, 6, 8, 10, 12, 14,
  112952. 16,
  112953. };
  112954. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  112955. _vq_quantthresh__8c1_s_p6_0,
  112956. _vq_quantmap__8c1_s_p6_0,
  112957. 17,
  112958. 17
  112959. };
  112960. static static_codebook _8c1_s_p6_0 = {
  112961. 2, 289,
  112962. _vq_lengthlist__8c1_s_p6_0,
  112963. 1, -529530880, 1611661312, 5, 0,
  112964. _vq_quantlist__8c1_s_p6_0,
  112965. NULL,
  112966. &_vq_auxt__8c1_s_p6_0,
  112967. NULL,
  112968. 0
  112969. };
  112970. static long _vq_quantlist__8c1_s_p7_0[] = {
  112971. 1,
  112972. 0,
  112973. 2,
  112974. };
  112975. static long _vq_lengthlist__8c1_s_p7_0[] = {
  112976. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  112977. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  112978. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  112979. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  112980. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  112981. 9,
  112982. };
  112983. static float _vq_quantthresh__8c1_s_p7_0[] = {
  112984. -5.5, 5.5,
  112985. };
  112986. static long _vq_quantmap__8c1_s_p7_0[] = {
  112987. 1, 0, 2,
  112988. };
  112989. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  112990. _vq_quantthresh__8c1_s_p7_0,
  112991. _vq_quantmap__8c1_s_p7_0,
  112992. 3,
  112993. 3
  112994. };
  112995. static static_codebook _8c1_s_p7_0 = {
  112996. 4, 81,
  112997. _vq_lengthlist__8c1_s_p7_0,
  112998. 1, -529137664, 1618345984, 2, 0,
  112999. _vq_quantlist__8c1_s_p7_0,
  113000. NULL,
  113001. &_vq_auxt__8c1_s_p7_0,
  113002. NULL,
  113003. 0
  113004. };
  113005. static long _vq_quantlist__8c1_s_p7_1[] = {
  113006. 5,
  113007. 4,
  113008. 6,
  113009. 3,
  113010. 7,
  113011. 2,
  113012. 8,
  113013. 1,
  113014. 9,
  113015. 0,
  113016. 10,
  113017. };
  113018. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113019. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113020. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113021. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113022. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113023. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113024. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113025. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113026. 10,10,10, 8, 8, 8, 8, 8, 8,
  113027. };
  113028. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113029. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113030. 3.5, 4.5,
  113031. };
  113032. static long _vq_quantmap__8c1_s_p7_1[] = {
  113033. 9, 7, 5, 3, 1, 0, 2, 4,
  113034. 6, 8, 10,
  113035. };
  113036. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113037. _vq_quantthresh__8c1_s_p7_1,
  113038. _vq_quantmap__8c1_s_p7_1,
  113039. 11,
  113040. 11
  113041. };
  113042. static static_codebook _8c1_s_p7_1 = {
  113043. 2, 121,
  113044. _vq_lengthlist__8c1_s_p7_1,
  113045. 1, -531365888, 1611661312, 4, 0,
  113046. _vq_quantlist__8c1_s_p7_1,
  113047. NULL,
  113048. &_vq_auxt__8c1_s_p7_1,
  113049. NULL,
  113050. 0
  113051. };
  113052. static long _vq_quantlist__8c1_s_p8_0[] = {
  113053. 6,
  113054. 5,
  113055. 7,
  113056. 4,
  113057. 8,
  113058. 3,
  113059. 9,
  113060. 2,
  113061. 10,
  113062. 1,
  113063. 11,
  113064. 0,
  113065. 12,
  113066. };
  113067. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113068. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113069. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113070. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113071. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113072. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113073. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113074. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113075. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113076. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113077. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113078. 0,12,12,11,10,12,11,13,12,
  113079. };
  113080. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113081. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113082. 12.5, 17.5, 22.5, 27.5,
  113083. };
  113084. static long _vq_quantmap__8c1_s_p8_0[] = {
  113085. 11, 9, 7, 5, 3, 1, 0, 2,
  113086. 4, 6, 8, 10, 12,
  113087. };
  113088. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113089. _vq_quantthresh__8c1_s_p8_0,
  113090. _vq_quantmap__8c1_s_p8_0,
  113091. 13,
  113092. 13
  113093. };
  113094. static static_codebook _8c1_s_p8_0 = {
  113095. 2, 169,
  113096. _vq_lengthlist__8c1_s_p8_0,
  113097. 1, -526516224, 1616117760, 4, 0,
  113098. _vq_quantlist__8c1_s_p8_0,
  113099. NULL,
  113100. &_vq_auxt__8c1_s_p8_0,
  113101. NULL,
  113102. 0
  113103. };
  113104. static long _vq_quantlist__8c1_s_p8_1[] = {
  113105. 2,
  113106. 1,
  113107. 3,
  113108. 0,
  113109. 4,
  113110. };
  113111. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113112. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113113. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113114. };
  113115. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113116. -1.5, -0.5, 0.5, 1.5,
  113117. };
  113118. static long _vq_quantmap__8c1_s_p8_1[] = {
  113119. 3, 1, 0, 2, 4,
  113120. };
  113121. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113122. _vq_quantthresh__8c1_s_p8_1,
  113123. _vq_quantmap__8c1_s_p8_1,
  113124. 5,
  113125. 5
  113126. };
  113127. static static_codebook _8c1_s_p8_1 = {
  113128. 2, 25,
  113129. _vq_lengthlist__8c1_s_p8_1,
  113130. 1, -533725184, 1611661312, 3, 0,
  113131. _vq_quantlist__8c1_s_p8_1,
  113132. NULL,
  113133. &_vq_auxt__8c1_s_p8_1,
  113134. NULL,
  113135. 0
  113136. };
  113137. static long _vq_quantlist__8c1_s_p9_0[] = {
  113138. 6,
  113139. 5,
  113140. 7,
  113141. 4,
  113142. 8,
  113143. 3,
  113144. 9,
  113145. 2,
  113146. 10,
  113147. 1,
  113148. 11,
  113149. 0,
  113150. 12,
  113151. };
  113152. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113153. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113154. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113155. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113156. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113157. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113158. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113159. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113160. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113163. 10,10,10,10,10, 9, 9, 9, 9,
  113164. };
  113165. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113166. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113167. 787.5, 1102.5, 1417.5, 1732.5,
  113168. };
  113169. static long _vq_quantmap__8c1_s_p9_0[] = {
  113170. 11, 9, 7, 5, 3, 1, 0, 2,
  113171. 4, 6, 8, 10, 12,
  113172. };
  113173. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113174. _vq_quantthresh__8c1_s_p9_0,
  113175. _vq_quantmap__8c1_s_p9_0,
  113176. 13,
  113177. 13
  113178. };
  113179. static static_codebook _8c1_s_p9_0 = {
  113180. 2, 169,
  113181. _vq_lengthlist__8c1_s_p9_0,
  113182. 1, -513964032, 1628680192, 4, 0,
  113183. _vq_quantlist__8c1_s_p9_0,
  113184. NULL,
  113185. &_vq_auxt__8c1_s_p9_0,
  113186. NULL,
  113187. 0
  113188. };
  113189. static long _vq_quantlist__8c1_s_p9_1[] = {
  113190. 7,
  113191. 6,
  113192. 8,
  113193. 5,
  113194. 9,
  113195. 4,
  113196. 10,
  113197. 3,
  113198. 11,
  113199. 2,
  113200. 12,
  113201. 1,
  113202. 13,
  113203. 0,
  113204. 14,
  113205. };
  113206. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113207. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113208. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113209. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113210. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113211. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113212. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113213. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113214. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113215. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113216. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113217. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113218. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113219. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113220. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113221. 15,
  113222. };
  113223. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113224. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113225. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113226. };
  113227. static long _vq_quantmap__8c1_s_p9_1[] = {
  113228. 13, 11, 9, 7, 5, 3, 1, 0,
  113229. 2, 4, 6, 8, 10, 12, 14,
  113230. };
  113231. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113232. _vq_quantthresh__8c1_s_p9_1,
  113233. _vq_quantmap__8c1_s_p9_1,
  113234. 15,
  113235. 15
  113236. };
  113237. static static_codebook _8c1_s_p9_1 = {
  113238. 2, 225,
  113239. _vq_lengthlist__8c1_s_p9_1,
  113240. 1, -520986624, 1620377600, 4, 0,
  113241. _vq_quantlist__8c1_s_p9_1,
  113242. NULL,
  113243. &_vq_auxt__8c1_s_p9_1,
  113244. NULL,
  113245. 0
  113246. };
  113247. static long _vq_quantlist__8c1_s_p9_2[] = {
  113248. 10,
  113249. 9,
  113250. 11,
  113251. 8,
  113252. 12,
  113253. 7,
  113254. 13,
  113255. 6,
  113256. 14,
  113257. 5,
  113258. 15,
  113259. 4,
  113260. 16,
  113261. 3,
  113262. 17,
  113263. 2,
  113264. 18,
  113265. 1,
  113266. 19,
  113267. 0,
  113268. 20,
  113269. };
  113270. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113271. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113272. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113273. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113274. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113275. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113276. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113277. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113278. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113279. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113280. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113281. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113282. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113283. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113284. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113285. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113286. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113287. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113288. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113289. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113290. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113291. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113292. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113293. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113294. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113295. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113296. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113297. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113298. 10,10,10,10,10,10,10,10,10,
  113299. };
  113300. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113301. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113302. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113303. 6.5, 7.5, 8.5, 9.5,
  113304. };
  113305. static long _vq_quantmap__8c1_s_p9_2[] = {
  113306. 19, 17, 15, 13, 11, 9, 7, 5,
  113307. 3, 1, 0, 2, 4, 6, 8, 10,
  113308. 12, 14, 16, 18, 20,
  113309. };
  113310. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113311. _vq_quantthresh__8c1_s_p9_2,
  113312. _vq_quantmap__8c1_s_p9_2,
  113313. 21,
  113314. 21
  113315. };
  113316. static static_codebook _8c1_s_p9_2 = {
  113317. 2, 441,
  113318. _vq_lengthlist__8c1_s_p9_2,
  113319. 1, -529268736, 1611661312, 5, 0,
  113320. _vq_quantlist__8c1_s_p9_2,
  113321. NULL,
  113322. &_vq_auxt__8c1_s_p9_2,
  113323. NULL,
  113324. 0
  113325. };
  113326. static long _huff_lengthlist__8c1_s_single[] = {
  113327. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113328. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113329. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113330. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113331. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113332. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113333. 9, 7, 7, 8,
  113334. };
  113335. static static_codebook _huff_book__8c1_s_single = {
  113336. 2, 100,
  113337. _huff_lengthlist__8c1_s_single,
  113338. 0, 0, 0, 0, 0,
  113339. NULL,
  113340. NULL,
  113341. NULL,
  113342. NULL,
  113343. 0
  113344. };
  113345. static long _huff_lengthlist__44c2_s_long[] = {
  113346. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113347. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113348. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113349. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113350. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113351. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113352. 10, 8, 8, 9,
  113353. };
  113354. static static_codebook _huff_book__44c2_s_long = {
  113355. 2, 100,
  113356. _huff_lengthlist__44c2_s_long,
  113357. 0, 0, 0, 0, 0,
  113358. NULL,
  113359. NULL,
  113360. NULL,
  113361. NULL,
  113362. 0
  113363. };
  113364. static long _vq_quantlist__44c2_s_p1_0[] = {
  113365. 1,
  113366. 0,
  113367. 2,
  113368. };
  113369. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113370. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113371. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113376. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113381. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113416. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113421. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113426. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113439. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113444. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113449. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113462. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113467. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113472. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  113781. };
  113782. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113783. -0.5, 0.5,
  113784. };
  113785. static long _vq_quantmap__44c2_s_p1_0[] = {
  113786. 1, 0, 2,
  113787. };
  113788. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113789. _vq_quantthresh__44c2_s_p1_0,
  113790. _vq_quantmap__44c2_s_p1_0,
  113791. 3,
  113792. 3
  113793. };
  113794. static static_codebook _44c2_s_p1_0 = {
  113795. 8, 6561,
  113796. _vq_lengthlist__44c2_s_p1_0,
  113797. 1, -535822336, 1611661312, 2, 0,
  113798. _vq_quantlist__44c2_s_p1_0,
  113799. NULL,
  113800. &_vq_auxt__44c2_s_p1_0,
  113801. NULL,
  113802. 0
  113803. };
  113804. static long _vq_quantlist__44c2_s_p2_0[] = {
  113805. 2,
  113806. 1,
  113807. 3,
  113808. 0,
  113809. 4,
  113810. };
  113811. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113812. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113813. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113814. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113815. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113816. 0, 0, 9, 9, 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, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113822. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113823. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113824. 12, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113830. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113831. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113838. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113839. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0,
  113852. };
  113853. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113854. -1.5, -0.5, 0.5, 1.5,
  113855. };
  113856. static long _vq_quantmap__44c2_s_p2_0[] = {
  113857. 3, 1, 0, 2, 4,
  113858. };
  113859. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113860. _vq_quantthresh__44c2_s_p2_0,
  113861. _vq_quantmap__44c2_s_p2_0,
  113862. 5,
  113863. 5
  113864. };
  113865. static static_codebook _44c2_s_p2_0 = {
  113866. 4, 625,
  113867. _vq_lengthlist__44c2_s_p2_0,
  113868. 1, -533725184, 1611661312, 3, 0,
  113869. _vq_quantlist__44c2_s_p2_0,
  113870. NULL,
  113871. &_vq_auxt__44c2_s_p2_0,
  113872. NULL,
  113873. 0
  113874. };
  113875. static long _vq_quantlist__44c2_s_p3_0[] = {
  113876. 2,
  113877. 1,
  113878. 3,
  113879. 0,
  113880. 4,
  113881. };
  113882. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113883. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113889. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113922. 0,
  113923. };
  113924. static float _vq_quantthresh__44c2_s_p3_0[] = {
  113925. -1.5, -0.5, 0.5, 1.5,
  113926. };
  113927. static long _vq_quantmap__44c2_s_p3_0[] = {
  113928. 3, 1, 0, 2, 4,
  113929. };
  113930. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  113931. _vq_quantthresh__44c2_s_p3_0,
  113932. _vq_quantmap__44c2_s_p3_0,
  113933. 5,
  113934. 5
  113935. };
  113936. static static_codebook _44c2_s_p3_0 = {
  113937. 4, 625,
  113938. _vq_lengthlist__44c2_s_p3_0,
  113939. 1, -533725184, 1611661312, 3, 0,
  113940. _vq_quantlist__44c2_s_p3_0,
  113941. NULL,
  113942. &_vq_auxt__44c2_s_p3_0,
  113943. NULL,
  113944. 0
  113945. };
  113946. static long _vq_quantlist__44c2_s_p4_0[] = {
  113947. 4,
  113948. 3,
  113949. 5,
  113950. 2,
  113951. 6,
  113952. 1,
  113953. 7,
  113954. 0,
  113955. 8,
  113956. };
  113957. static long _vq_lengthlist__44c2_s_p4_0[] = {
  113958. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  113959. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  113960. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  113961. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  113962. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0,
  113964. };
  113965. static float _vq_quantthresh__44c2_s_p4_0[] = {
  113966. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113967. };
  113968. static long _vq_quantmap__44c2_s_p4_0[] = {
  113969. 7, 5, 3, 1, 0, 2, 4, 6,
  113970. 8,
  113971. };
  113972. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  113973. _vq_quantthresh__44c2_s_p4_0,
  113974. _vq_quantmap__44c2_s_p4_0,
  113975. 9,
  113976. 9
  113977. };
  113978. static static_codebook _44c2_s_p4_0 = {
  113979. 2, 81,
  113980. _vq_lengthlist__44c2_s_p4_0,
  113981. 1, -531628032, 1611661312, 4, 0,
  113982. _vq_quantlist__44c2_s_p4_0,
  113983. NULL,
  113984. &_vq_auxt__44c2_s_p4_0,
  113985. NULL,
  113986. 0
  113987. };
  113988. static long _vq_quantlist__44c2_s_p5_0[] = {
  113989. 4,
  113990. 3,
  113991. 5,
  113992. 2,
  113993. 6,
  113994. 1,
  113995. 7,
  113996. 0,
  113997. 8,
  113998. };
  113999. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114000. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114001. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114002. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114003. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114004. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114005. 11,
  114006. };
  114007. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114008. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114009. };
  114010. static long _vq_quantmap__44c2_s_p5_0[] = {
  114011. 7, 5, 3, 1, 0, 2, 4, 6,
  114012. 8,
  114013. };
  114014. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114015. _vq_quantthresh__44c2_s_p5_0,
  114016. _vq_quantmap__44c2_s_p5_0,
  114017. 9,
  114018. 9
  114019. };
  114020. static static_codebook _44c2_s_p5_0 = {
  114021. 2, 81,
  114022. _vq_lengthlist__44c2_s_p5_0,
  114023. 1, -531628032, 1611661312, 4, 0,
  114024. _vq_quantlist__44c2_s_p5_0,
  114025. NULL,
  114026. &_vq_auxt__44c2_s_p5_0,
  114027. NULL,
  114028. 0
  114029. };
  114030. static long _vq_quantlist__44c2_s_p6_0[] = {
  114031. 8,
  114032. 7,
  114033. 9,
  114034. 6,
  114035. 10,
  114036. 5,
  114037. 11,
  114038. 4,
  114039. 12,
  114040. 3,
  114041. 13,
  114042. 2,
  114043. 14,
  114044. 1,
  114045. 15,
  114046. 0,
  114047. 16,
  114048. };
  114049. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114050. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114051. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114052. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114053. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114054. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114055. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114056. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114057. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114058. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114059. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114060. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114061. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114062. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114063. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114064. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114065. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114066. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114068. 14,
  114069. };
  114070. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114071. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114072. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114073. };
  114074. static long _vq_quantmap__44c2_s_p6_0[] = {
  114075. 15, 13, 11, 9, 7, 5, 3, 1,
  114076. 0, 2, 4, 6, 8, 10, 12, 14,
  114077. 16,
  114078. };
  114079. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114080. _vq_quantthresh__44c2_s_p6_0,
  114081. _vq_quantmap__44c2_s_p6_0,
  114082. 17,
  114083. 17
  114084. };
  114085. static static_codebook _44c2_s_p6_0 = {
  114086. 2, 289,
  114087. _vq_lengthlist__44c2_s_p6_0,
  114088. 1, -529530880, 1611661312, 5, 0,
  114089. _vq_quantlist__44c2_s_p6_0,
  114090. NULL,
  114091. &_vq_auxt__44c2_s_p6_0,
  114092. NULL,
  114093. 0
  114094. };
  114095. static long _vq_quantlist__44c2_s_p7_0[] = {
  114096. 1,
  114097. 0,
  114098. 2,
  114099. };
  114100. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114101. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114102. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114103. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114104. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114105. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114106. 11,
  114107. };
  114108. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114109. -5.5, 5.5,
  114110. };
  114111. static long _vq_quantmap__44c2_s_p7_0[] = {
  114112. 1, 0, 2,
  114113. };
  114114. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114115. _vq_quantthresh__44c2_s_p7_0,
  114116. _vq_quantmap__44c2_s_p7_0,
  114117. 3,
  114118. 3
  114119. };
  114120. static static_codebook _44c2_s_p7_0 = {
  114121. 4, 81,
  114122. _vq_lengthlist__44c2_s_p7_0,
  114123. 1, -529137664, 1618345984, 2, 0,
  114124. _vq_quantlist__44c2_s_p7_0,
  114125. NULL,
  114126. &_vq_auxt__44c2_s_p7_0,
  114127. NULL,
  114128. 0
  114129. };
  114130. static long _vq_quantlist__44c2_s_p7_1[] = {
  114131. 5,
  114132. 4,
  114133. 6,
  114134. 3,
  114135. 7,
  114136. 2,
  114137. 8,
  114138. 1,
  114139. 9,
  114140. 0,
  114141. 10,
  114142. };
  114143. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114144. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114145. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114146. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114147. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114148. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114149. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114150. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114151. 10,10,10, 8, 8, 8, 8, 8, 8,
  114152. };
  114153. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114154. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114155. 3.5, 4.5,
  114156. };
  114157. static long _vq_quantmap__44c2_s_p7_1[] = {
  114158. 9, 7, 5, 3, 1, 0, 2, 4,
  114159. 6, 8, 10,
  114160. };
  114161. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114162. _vq_quantthresh__44c2_s_p7_1,
  114163. _vq_quantmap__44c2_s_p7_1,
  114164. 11,
  114165. 11
  114166. };
  114167. static static_codebook _44c2_s_p7_1 = {
  114168. 2, 121,
  114169. _vq_lengthlist__44c2_s_p7_1,
  114170. 1, -531365888, 1611661312, 4, 0,
  114171. _vq_quantlist__44c2_s_p7_1,
  114172. NULL,
  114173. &_vq_auxt__44c2_s_p7_1,
  114174. NULL,
  114175. 0
  114176. };
  114177. static long _vq_quantlist__44c2_s_p8_0[] = {
  114178. 6,
  114179. 5,
  114180. 7,
  114181. 4,
  114182. 8,
  114183. 3,
  114184. 9,
  114185. 2,
  114186. 10,
  114187. 1,
  114188. 11,
  114189. 0,
  114190. 12,
  114191. };
  114192. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114193. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114194. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114195. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114196. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114197. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114198. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114199. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114200. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114201. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114202. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114203. 0,12,12,12,12,13,12,14,14,
  114204. };
  114205. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114206. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114207. 12.5, 17.5, 22.5, 27.5,
  114208. };
  114209. static long _vq_quantmap__44c2_s_p8_0[] = {
  114210. 11, 9, 7, 5, 3, 1, 0, 2,
  114211. 4, 6, 8, 10, 12,
  114212. };
  114213. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114214. _vq_quantthresh__44c2_s_p8_0,
  114215. _vq_quantmap__44c2_s_p8_0,
  114216. 13,
  114217. 13
  114218. };
  114219. static static_codebook _44c2_s_p8_0 = {
  114220. 2, 169,
  114221. _vq_lengthlist__44c2_s_p8_0,
  114222. 1, -526516224, 1616117760, 4, 0,
  114223. _vq_quantlist__44c2_s_p8_0,
  114224. NULL,
  114225. &_vq_auxt__44c2_s_p8_0,
  114226. NULL,
  114227. 0
  114228. };
  114229. static long _vq_quantlist__44c2_s_p8_1[] = {
  114230. 2,
  114231. 1,
  114232. 3,
  114233. 0,
  114234. 4,
  114235. };
  114236. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114237. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114238. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114239. };
  114240. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114241. -1.5, -0.5, 0.5, 1.5,
  114242. };
  114243. static long _vq_quantmap__44c2_s_p8_1[] = {
  114244. 3, 1, 0, 2, 4,
  114245. };
  114246. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114247. _vq_quantthresh__44c2_s_p8_1,
  114248. _vq_quantmap__44c2_s_p8_1,
  114249. 5,
  114250. 5
  114251. };
  114252. static static_codebook _44c2_s_p8_1 = {
  114253. 2, 25,
  114254. _vq_lengthlist__44c2_s_p8_1,
  114255. 1, -533725184, 1611661312, 3, 0,
  114256. _vq_quantlist__44c2_s_p8_1,
  114257. NULL,
  114258. &_vq_auxt__44c2_s_p8_1,
  114259. NULL,
  114260. 0
  114261. };
  114262. static long _vq_quantlist__44c2_s_p9_0[] = {
  114263. 6,
  114264. 5,
  114265. 7,
  114266. 4,
  114267. 8,
  114268. 3,
  114269. 9,
  114270. 2,
  114271. 10,
  114272. 1,
  114273. 11,
  114274. 0,
  114275. 12,
  114276. };
  114277. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114278. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114279. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114281. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114283. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114288. 11,11,11,11,11,11,11,11,11,
  114289. };
  114290. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114291. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114292. 552.5, 773.5, 994.5, 1215.5,
  114293. };
  114294. static long _vq_quantmap__44c2_s_p9_0[] = {
  114295. 11, 9, 7, 5, 3, 1, 0, 2,
  114296. 4, 6, 8, 10, 12,
  114297. };
  114298. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114299. _vq_quantthresh__44c2_s_p9_0,
  114300. _vq_quantmap__44c2_s_p9_0,
  114301. 13,
  114302. 13
  114303. };
  114304. static static_codebook _44c2_s_p9_0 = {
  114305. 2, 169,
  114306. _vq_lengthlist__44c2_s_p9_0,
  114307. 1, -514541568, 1627103232, 4, 0,
  114308. _vq_quantlist__44c2_s_p9_0,
  114309. NULL,
  114310. &_vq_auxt__44c2_s_p9_0,
  114311. NULL,
  114312. 0
  114313. };
  114314. static long _vq_quantlist__44c2_s_p9_1[] = {
  114315. 6,
  114316. 5,
  114317. 7,
  114318. 4,
  114319. 8,
  114320. 3,
  114321. 9,
  114322. 2,
  114323. 10,
  114324. 1,
  114325. 11,
  114326. 0,
  114327. 12,
  114328. };
  114329. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114330. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114331. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114332. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114333. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114334. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114335. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114336. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114337. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114338. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114339. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114340. 17,13,12,12,10,13,11,14,14,
  114341. };
  114342. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114343. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114344. 42.5, 59.5, 76.5, 93.5,
  114345. };
  114346. static long _vq_quantmap__44c2_s_p9_1[] = {
  114347. 11, 9, 7, 5, 3, 1, 0, 2,
  114348. 4, 6, 8, 10, 12,
  114349. };
  114350. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114351. _vq_quantthresh__44c2_s_p9_1,
  114352. _vq_quantmap__44c2_s_p9_1,
  114353. 13,
  114354. 13
  114355. };
  114356. static static_codebook _44c2_s_p9_1 = {
  114357. 2, 169,
  114358. _vq_lengthlist__44c2_s_p9_1,
  114359. 1, -522616832, 1620115456, 4, 0,
  114360. _vq_quantlist__44c2_s_p9_1,
  114361. NULL,
  114362. &_vq_auxt__44c2_s_p9_1,
  114363. NULL,
  114364. 0
  114365. };
  114366. static long _vq_quantlist__44c2_s_p9_2[] = {
  114367. 8,
  114368. 7,
  114369. 9,
  114370. 6,
  114371. 10,
  114372. 5,
  114373. 11,
  114374. 4,
  114375. 12,
  114376. 3,
  114377. 13,
  114378. 2,
  114379. 14,
  114380. 1,
  114381. 15,
  114382. 0,
  114383. 16,
  114384. };
  114385. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114386. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114387. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114388. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114389. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114390. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114391. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114392. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114393. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114394. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114395. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114396. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114397. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114398. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114399. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114400. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114401. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114402. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114403. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114404. 10,
  114405. };
  114406. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114407. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114408. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114409. };
  114410. static long _vq_quantmap__44c2_s_p9_2[] = {
  114411. 15, 13, 11, 9, 7, 5, 3, 1,
  114412. 0, 2, 4, 6, 8, 10, 12, 14,
  114413. 16,
  114414. };
  114415. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114416. _vq_quantthresh__44c2_s_p9_2,
  114417. _vq_quantmap__44c2_s_p9_2,
  114418. 17,
  114419. 17
  114420. };
  114421. static static_codebook _44c2_s_p9_2 = {
  114422. 2, 289,
  114423. _vq_lengthlist__44c2_s_p9_2,
  114424. 1, -529530880, 1611661312, 5, 0,
  114425. _vq_quantlist__44c2_s_p9_2,
  114426. NULL,
  114427. &_vq_auxt__44c2_s_p9_2,
  114428. NULL,
  114429. 0
  114430. };
  114431. static long _huff_lengthlist__44c2_s_short[] = {
  114432. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114433. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114434. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114435. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114436. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114437. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114438. 6, 8, 9,12,
  114439. };
  114440. static static_codebook _huff_book__44c2_s_short = {
  114441. 2, 100,
  114442. _huff_lengthlist__44c2_s_short,
  114443. 0, 0, 0, 0, 0,
  114444. NULL,
  114445. NULL,
  114446. NULL,
  114447. NULL,
  114448. 0
  114449. };
  114450. static long _huff_lengthlist__44c3_s_long[] = {
  114451. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114452. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114453. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114454. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114455. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114456. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114457. 9, 8, 8, 8,
  114458. };
  114459. static static_codebook _huff_book__44c3_s_long = {
  114460. 2, 100,
  114461. _huff_lengthlist__44c3_s_long,
  114462. 0, 0, 0, 0, 0,
  114463. NULL,
  114464. NULL,
  114465. NULL,
  114466. NULL,
  114467. 0
  114468. };
  114469. static long _vq_quantlist__44c3_s_p1_0[] = {
  114470. 1,
  114471. 0,
  114472. 2,
  114473. };
  114474. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114475. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114476. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114481. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114486. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114521. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114526. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114531. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114544. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114549. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114554. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114567. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114572. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114577. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  114886. };
  114887. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114888. -0.5, 0.5,
  114889. };
  114890. static long _vq_quantmap__44c3_s_p1_0[] = {
  114891. 1, 0, 2,
  114892. };
  114893. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114894. _vq_quantthresh__44c3_s_p1_0,
  114895. _vq_quantmap__44c3_s_p1_0,
  114896. 3,
  114897. 3
  114898. };
  114899. static static_codebook _44c3_s_p1_0 = {
  114900. 8, 6561,
  114901. _vq_lengthlist__44c3_s_p1_0,
  114902. 1, -535822336, 1611661312, 2, 0,
  114903. _vq_quantlist__44c3_s_p1_0,
  114904. NULL,
  114905. &_vq_auxt__44c3_s_p1_0,
  114906. NULL,
  114907. 0
  114908. };
  114909. static long _vq_quantlist__44c3_s_p2_0[] = {
  114910. 2,
  114911. 1,
  114912. 3,
  114913. 0,
  114914. 4,
  114915. };
  114916. static long _vq_lengthlist__44c3_s_p2_0[] = {
  114917. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  114918. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  114919. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114920. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  114921. 0, 0,10,10, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  114927. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  114928. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  114929. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  114935. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  114936. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  114943. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  114944. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0,
  114957. };
  114958. static float _vq_quantthresh__44c3_s_p2_0[] = {
  114959. -1.5, -0.5, 0.5, 1.5,
  114960. };
  114961. static long _vq_quantmap__44c3_s_p2_0[] = {
  114962. 3, 1, 0, 2, 4,
  114963. };
  114964. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  114965. _vq_quantthresh__44c3_s_p2_0,
  114966. _vq_quantmap__44c3_s_p2_0,
  114967. 5,
  114968. 5
  114969. };
  114970. static static_codebook _44c3_s_p2_0 = {
  114971. 4, 625,
  114972. _vq_lengthlist__44c3_s_p2_0,
  114973. 1, -533725184, 1611661312, 3, 0,
  114974. _vq_quantlist__44c3_s_p2_0,
  114975. NULL,
  114976. &_vq_auxt__44c3_s_p2_0,
  114977. NULL,
  114978. 0
  114979. };
  114980. static long _vq_quantlist__44c3_s_p3_0[] = {
  114981. 2,
  114982. 1,
  114983. 3,
  114984. 0,
  114985. 4,
  114986. };
  114987. static long _vq_lengthlist__44c3_s_p3_0[] = {
  114988. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114994. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115027. 0,
  115028. };
  115029. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115030. -1.5, -0.5, 0.5, 1.5,
  115031. };
  115032. static long _vq_quantmap__44c3_s_p3_0[] = {
  115033. 3, 1, 0, 2, 4,
  115034. };
  115035. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115036. _vq_quantthresh__44c3_s_p3_0,
  115037. _vq_quantmap__44c3_s_p3_0,
  115038. 5,
  115039. 5
  115040. };
  115041. static static_codebook _44c3_s_p3_0 = {
  115042. 4, 625,
  115043. _vq_lengthlist__44c3_s_p3_0,
  115044. 1, -533725184, 1611661312, 3, 0,
  115045. _vq_quantlist__44c3_s_p3_0,
  115046. NULL,
  115047. &_vq_auxt__44c3_s_p3_0,
  115048. NULL,
  115049. 0
  115050. };
  115051. static long _vq_quantlist__44c3_s_p4_0[] = {
  115052. 4,
  115053. 3,
  115054. 5,
  115055. 2,
  115056. 6,
  115057. 1,
  115058. 7,
  115059. 0,
  115060. 8,
  115061. };
  115062. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115063. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115064. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115065. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115066. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115067. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0,
  115069. };
  115070. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115071. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115072. };
  115073. static long _vq_quantmap__44c3_s_p4_0[] = {
  115074. 7, 5, 3, 1, 0, 2, 4, 6,
  115075. 8,
  115076. };
  115077. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115078. _vq_quantthresh__44c3_s_p4_0,
  115079. _vq_quantmap__44c3_s_p4_0,
  115080. 9,
  115081. 9
  115082. };
  115083. static static_codebook _44c3_s_p4_0 = {
  115084. 2, 81,
  115085. _vq_lengthlist__44c3_s_p4_0,
  115086. 1, -531628032, 1611661312, 4, 0,
  115087. _vq_quantlist__44c3_s_p4_0,
  115088. NULL,
  115089. &_vq_auxt__44c3_s_p4_0,
  115090. NULL,
  115091. 0
  115092. };
  115093. static long _vq_quantlist__44c3_s_p5_0[] = {
  115094. 4,
  115095. 3,
  115096. 5,
  115097. 2,
  115098. 6,
  115099. 1,
  115100. 7,
  115101. 0,
  115102. 8,
  115103. };
  115104. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115105. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115106. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115107. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115108. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115109. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115110. 11,
  115111. };
  115112. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115113. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115114. };
  115115. static long _vq_quantmap__44c3_s_p5_0[] = {
  115116. 7, 5, 3, 1, 0, 2, 4, 6,
  115117. 8,
  115118. };
  115119. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115120. _vq_quantthresh__44c3_s_p5_0,
  115121. _vq_quantmap__44c3_s_p5_0,
  115122. 9,
  115123. 9
  115124. };
  115125. static static_codebook _44c3_s_p5_0 = {
  115126. 2, 81,
  115127. _vq_lengthlist__44c3_s_p5_0,
  115128. 1, -531628032, 1611661312, 4, 0,
  115129. _vq_quantlist__44c3_s_p5_0,
  115130. NULL,
  115131. &_vq_auxt__44c3_s_p5_0,
  115132. NULL,
  115133. 0
  115134. };
  115135. static long _vq_quantlist__44c3_s_p6_0[] = {
  115136. 8,
  115137. 7,
  115138. 9,
  115139. 6,
  115140. 10,
  115141. 5,
  115142. 11,
  115143. 4,
  115144. 12,
  115145. 3,
  115146. 13,
  115147. 2,
  115148. 14,
  115149. 1,
  115150. 15,
  115151. 0,
  115152. 16,
  115153. };
  115154. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115155. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115156. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115157. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115158. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115159. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115160. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115161. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115162. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115163. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115164. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115165. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115166. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115167. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115168. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115169. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115170. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115171. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115173. 13,
  115174. };
  115175. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115176. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115177. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115178. };
  115179. static long _vq_quantmap__44c3_s_p6_0[] = {
  115180. 15, 13, 11, 9, 7, 5, 3, 1,
  115181. 0, 2, 4, 6, 8, 10, 12, 14,
  115182. 16,
  115183. };
  115184. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115185. _vq_quantthresh__44c3_s_p6_0,
  115186. _vq_quantmap__44c3_s_p6_0,
  115187. 17,
  115188. 17
  115189. };
  115190. static static_codebook _44c3_s_p6_0 = {
  115191. 2, 289,
  115192. _vq_lengthlist__44c3_s_p6_0,
  115193. 1, -529530880, 1611661312, 5, 0,
  115194. _vq_quantlist__44c3_s_p6_0,
  115195. NULL,
  115196. &_vq_auxt__44c3_s_p6_0,
  115197. NULL,
  115198. 0
  115199. };
  115200. static long _vq_quantlist__44c3_s_p7_0[] = {
  115201. 1,
  115202. 0,
  115203. 2,
  115204. };
  115205. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115206. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115207. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115208. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115209. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115210. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115211. 10,
  115212. };
  115213. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115214. -5.5, 5.5,
  115215. };
  115216. static long _vq_quantmap__44c3_s_p7_0[] = {
  115217. 1, 0, 2,
  115218. };
  115219. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115220. _vq_quantthresh__44c3_s_p7_0,
  115221. _vq_quantmap__44c3_s_p7_0,
  115222. 3,
  115223. 3
  115224. };
  115225. static static_codebook _44c3_s_p7_0 = {
  115226. 4, 81,
  115227. _vq_lengthlist__44c3_s_p7_0,
  115228. 1, -529137664, 1618345984, 2, 0,
  115229. _vq_quantlist__44c3_s_p7_0,
  115230. NULL,
  115231. &_vq_auxt__44c3_s_p7_0,
  115232. NULL,
  115233. 0
  115234. };
  115235. static long _vq_quantlist__44c3_s_p7_1[] = {
  115236. 5,
  115237. 4,
  115238. 6,
  115239. 3,
  115240. 7,
  115241. 2,
  115242. 8,
  115243. 1,
  115244. 9,
  115245. 0,
  115246. 10,
  115247. };
  115248. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115249. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115250. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115251. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115252. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115253. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115254. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115255. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115256. 10,10,10, 8, 8, 8, 8, 8, 8,
  115257. };
  115258. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115259. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115260. 3.5, 4.5,
  115261. };
  115262. static long _vq_quantmap__44c3_s_p7_1[] = {
  115263. 9, 7, 5, 3, 1, 0, 2, 4,
  115264. 6, 8, 10,
  115265. };
  115266. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115267. _vq_quantthresh__44c3_s_p7_1,
  115268. _vq_quantmap__44c3_s_p7_1,
  115269. 11,
  115270. 11
  115271. };
  115272. static static_codebook _44c3_s_p7_1 = {
  115273. 2, 121,
  115274. _vq_lengthlist__44c3_s_p7_1,
  115275. 1, -531365888, 1611661312, 4, 0,
  115276. _vq_quantlist__44c3_s_p7_1,
  115277. NULL,
  115278. &_vq_auxt__44c3_s_p7_1,
  115279. NULL,
  115280. 0
  115281. };
  115282. static long _vq_quantlist__44c3_s_p8_0[] = {
  115283. 6,
  115284. 5,
  115285. 7,
  115286. 4,
  115287. 8,
  115288. 3,
  115289. 9,
  115290. 2,
  115291. 10,
  115292. 1,
  115293. 11,
  115294. 0,
  115295. 12,
  115296. };
  115297. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115298. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115299. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115300. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115301. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115302. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115303. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115304. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115305. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115306. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115307. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115308. 0,13,13,12,12,13,12,14,13,
  115309. };
  115310. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115311. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115312. 12.5, 17.5, 22.5, 27.5,
  115313. };
  115314. static long _vq_quantmap__44c3_s_p8_0[] = {
  115315. 11, 9, 7, 5, 3, 1, 0, 2,
  115316. 4, 6, 8, 10, 12,
  115317. };
  115318. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115319. _vq_quantthresh__44c3_s_p8_0,
  115320. _vq_quantmap__44c3_s_p8_0,
  115321. 13,
  115322. 13
  115323. };
  115324. static static_codebook _44c3_s_p8_0 = {
  115325. 2, 169,
  115326. _vq_lengthlist__44c3_s_p8_0,
  115327. 1, -526516224, 1616117760, 4, 0,
  115328. _vq_quantlist__44c3_s_p8_0,
  115329. NULL,
  115330. &_vq_auxt__44c3_s_p8_0,
  115331. NULL,
  115332. 0
  115333. };
  115334. static long _vq_quantlist__44c3_s_p8_1[] = {
  115335. 2,
  115336. 1,
  115337. 3,
  115338. 0,
  115339. 4,
  115340. };
  115341. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115342. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115343. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115344. };
  115345. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115346. -1.5, -0.5, 0.5, 1.5,
  115347. };
  115348. static long _vq_quantmap__44c3_s_p8_1[] = {
  115349. 3, 1, 0, 2, 4,
  115350. };
  115351. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115352. _vq_quantthresh__44c3_s_p8_1,
  115353. _vq_quantmap__44c3_s_p8_1,
  115354. 5,
  115355. 5
  115356. };
  115357. static static_codebook _44c3_s_p8_1 = {
  115358. 2, 25,
  115359. _vq_lengthlist__44c3_s_p8_1,
  115360. 1, -533725184, 1611661312, 3, 0,
  115361. _vq_quantlist__44c3_s_p8_1,
  115362. NULL,
  115363. &_vq_auxt__44c3_s_p8_1,
  115364. NULL,
  115365. 0
  115366. };
  115367. static long _vq_quantlist__44c3_s_p9_0[] = {
  115368. 6,
  115369. 5,
  115370. 7,
  115371. 4,
  115372. 8,
  115373. 3,
  115374. 9,
  115375. 2,
  115376. 10,
  115377. 1,
  115378. 11,
  115379. 0,
  115380. 12,
  115381. };
  115382. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115383. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115384. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115385. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115386. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115387. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115388. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115389. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115390. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115391. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115392. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115393. 11,11,11,11,11,11,11,11,11,
  115394. };
  115395. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115396. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115397. 637.5, 892.5, 1147.5, 1402.5,
  115398. };
  115399. static long _vq_quantmap__44c3_s_p9_0[] = {
  115400. 11, 9, 7, 5, 3, 1, 0, 2,
  115401. 4, 6, 8, 10, 12,
  115402. };
  115403. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115404. _vq_quantthresh__44c3_s_p9_0,
  115405. _vq_quantmap__44c3_s_p9_0,
  115406. 13,
  115407. 13
  115408. };
  115409. static static_codebook _44c3_s_p9_0 = {
  115410. 2, 169,
  115411. _vq_lengthlist__44c3_s_p9_0,
  115412. 1, -514332672, 1627381760, 4, 0,
  115413. _vq_quantlist__44c3_s_p9_0,
  115414. NULL,
  115415. &_vq_auxt__44c3_s_p9_0,
  115416. NULL,
  115417. 0
  115418. };
  115419. static long _vq_quantlist__44c3_s_p9_1[] = {
  115420. 7,
  115421. 6,
  115422. 8,
  115423. 5,
  115424. 9,
  115425. 4,
  115426. 10,
  115427. 3,
  115428. 11,
  115429. 2,
  115430. 12,
  115431. 1,
  115432. 13,
  115433. 0,
  115434. 14,
  115435. };
  115436. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115437. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115438. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115439. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115440. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115441. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115442. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115443. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115444. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115445. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115446. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115447. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115448. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115449. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115450. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115451. 15,
  115452. };
  115453. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115454. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115455. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115456. };
  115457. static long _vq_quantmap__44c3_s_p9_1[] = {
  115458. 13, 11, 9, 7, 5, 3, 1, 0,
  115459. 2, 4, 6, 8, 10, 12, 14,
  115460. };
  115461. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115462. _vq_quantthresh__44c3_s_p9_1,
  115463. _vq_quantmap__44c3_s_p9_1,
  115464. 15,
  115465. 15
  115466. };
  115467. static static_codebook _44c3_s_p9_1 = {
  115468. 2, 225,
  115469. _vq_lengthlist__44c3_s_p9_1,
  115470. 1, -522338304, 1620115456, 4, 0,
  115471. _vq_quantlist__44c3_s_p9_1,
  115472. NULL,
  115473. &_vq_auxt__44c3_s_p9_1,
  115474. NULL,
  115475. 0
  115476. };
  115477. static long _vq_quantlist__44c3_s_p9_2[] = {
  115478. 8,
  115479. 7,
  115480. 9,
  115481. 6,
  115482. 10,
  115483. 5,
  115484. 11,
  115485. 4,
  115486. 12,
  115487. 3,
  115488. 13,
  115489. 2,
  115490. 14,
  115491. 1,
  115492. 15,
  115493. 0,
  115494. 16,
  115495. };
  115496. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115497. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115498. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115499. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115500. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115501. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115502. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115503. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115504. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115505. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115506. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115507. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115508. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115509. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115510. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115511. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115512. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115513. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115514. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115515. 10,
  115516. };
  115517. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115518. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115519. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115520. };
  115521. static long _vq_quantmap__44c3_s_p9_2[] = {
  115522. 15, 13, 11, 9, 7, 5, 3, 1,
  115523. 0, 2, 4, 6, 8, 10, 12, 14,
  115524. 16,
  115525. };
  115526. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115527. _vq_quantthresh__44c3_s_p9_2,
  115528. _vq_quantmap__44c3_s_p9_2,
  115529. 17,
  115530. 17
  115531. };
  115532. static static_codebook _44c3_s_p9_2 = {
  115533. 2, 289,
  115534. _vq_lengthlist__44c3_s_p9_2,
  115535. 1, -529530880, 1611661312, 5, 0,
  115536. _vq_quantlist__44c3_s_p9_2,
  115537. NULL,
  115538. &_vq_auxt__44c3_s_p9_2,
  115539. NULL,
  115540. 0
  115541. };
  115542. static long _huff_lengthlist__44c3_s_short[] = {
  115543. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115544. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115545. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115546. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115547. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115548. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115549. 6, 8, 9,11,
  115550. };
  115551. static static_codebook _huff_book__44c3_s_short = {
  115552. 2, 100,
  115553. _huff_lengthlist__44c3_s_short,
  115554. 0, 0, 0, 0, 0,
  115555. NULL,
  115556. NULL,
  115557. NULL,
  115558. NULL,
  115559. 0
  115560. };
  115561. static long _huff_lengthlist__44c4_s_long[] = {
  115562. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115563. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115564. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115565. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115566. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115567. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115568. 9, 8, 7, 7,
  115569. };
  115570. static static_codebook _huff_book__44c4_s_long = {
  115571. 2, 100,
  115572. _huff_lengthlist__44c4_s_long,
  115573. 0, 0, 0, 0, 0,
  115574. NULL,
  115575. NULL,
  115576. NULL,
  115577. NULL,
  115578. 0
  115579. };
  115580. static long _vq_quantlist__44c4_s_p1_0[] = {
  115581. 1,
  115582. 0,
  115583. 2,
  115584. };
  115585. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115586. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115587. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115592. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115597. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115632. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115637. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115642. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115655. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115665. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115678. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115683. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115688. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  115997. };
  115998. static float _vq_quantthresh__44c4_s_p1_0[] = {
  115999. -0.5, 0.5,
  116000. };
  116001. static long _vq_quantmap__44c4_s_p1_0[] = {
  116002. 1, 0, 2,
  116003. };
  116004. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116005. _vq_quantthresh__44c4_s_p1_0,
  116006. _vq_quantmap__44c4_s_p1_0,
  116007. 3,
  116008. 3
  116009. };
  116010. static static_codebook _44c4_s_p1_0 = {
  116011. 8, 6561,
  116012. _vq_lengthlist__44c4_s_p1_0,
  116013. 1, -535822336, 1611661312, 2, 0,
  116014. _vq_quantlist__44c4_s_p1_0,
  116015. NULL,
  116016. &_vq_auxt__44c4_s_p1_0,
  116017. NULL,
  116018. 0
  116019. };
  116020. static long _vq_quantlist__44c4_s_p2_0[] = {
  116021. 2,
  116022. 1,
  116023. 3,
  116024. 0,
  116025. 4,
  116026. };
  116027. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116028. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116029. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116030. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116031. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116032. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116038. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116039. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116040. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116046. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116047. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116054. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116055. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0,
  116068. };
  116069. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116070. -1.5, -0.5, 0.5, 1.5,
  116071. };
  116072. static long _vq_quantmap__44c4_s_p2_0[] = {
  116073. 3, 1, 0, 2, 4,
  116074. };
  116075. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116076. _vq_quantthresh__44c4_s_p2_0,
  116077. _vq_quantmap__44c4_s_p2_0,
  116078. 5,
  116079. 5
  116080. };
  116081. static static_codebook _44c4_s_p2_0 = {
  116082. 4, 625,
  116083. _vq_lengthlist__44c4_s_p2_0,
  116084. 1, -533725184, 1611661312, 3, 0,
  116085. _vq_quantlist__44c4_s_p2_0,
  116086. NULL,
  116087. &_vq_auxt__44c4_s_p2_0,
  116088. NULL,
  116089. 0
  116090. };
  116091. static long _vq_quantlist__44c4_s_p3_0[] = {
  116092. 2,
  116093. 1,
  116094. 3,
  116095. 0,
  116096. 4,
  116097. };
  116098. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116099. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116105. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116138. 0,
  116139. };
  116140. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116141. -1.5, -0.5, 0.5, 1.5,
  116142. };
  116143. static long _vq_quantmap__44c4_s_p3_0[] = {
  116144. 3, 1, 0, 2, 4,
  116145. };
  116146. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116147. _vq_quantthresh__44c4_s_p3_0,
  116148. _vq_quantmap__44c4_s_p3_0,
  116149. 5,
  116150. 5
  116151. };
  116152. static static_codebook _44c4_s_p3_0 = {
  116153. 4, 625,
  116154. _vq_lengthlist__44c4_s_p3_0,
  116155. 1, -533725184, 1611661312, 3, 0,
  116156. _vq_quantlist__44c4_s_p3_0,
  116157. NULL,
  116158. &_vq_auxt__44c4_s_p3_0,
  116159. NULL,
  116160. 0
  116161. };
  116162. static long _vq_quantlist__44c4_s_p4_0[] = {
  116163. 4,
  116164. 3,
  116165. 5,
  116166. 2,
  116167. 6,
  116168. 1,
  116169. 7,
  116170. 0,
  116171. 8,
  116172. };
  116173. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116174. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116175. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116176. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116177. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116178. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0,
  116180. };
  116181. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116182. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116183. };
  116184. static long _vq_quantmap__44c4_s_p4_0[] = {
  116185. 7, 5, 3, 1, 0, 2, 4, 6,
  116186. 8,
  116187. };
  116188. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116189. _vq_quantthresh__44c4_s_p4_0,
  116190. _vq_quantmap__44c4_s_p4_0,
  116191. 9,
  116192. 9
  116193. };
  116194. static static_codebook _44c4_s_p4_0 = {
  116195. 2, 81,
  116196. _vq_lengthlist__44c4_s_p4_0,
  116197. 1, -531628032, 1611661312, 4, 0,
  116198. _vq_quantlist__44c4_s_p4_0,
  116199. NULL,
  116200. &_vq_auxt__44c4_s_p4_0,
  116201. NULL,
  116202. 0
  116203. };
  116204. static long _vq_quantlist__44c4_s_p5_0[] = {
  116205. 4,
  116206. 3,
  116207. 5,
  116208. 2,
  116209. 6,
  116210. 1,
  116211. 7,
  116212. 0,
  116213. 8,
  116214. };
  116215. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116216. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116217. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116218. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116219. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116220. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116221. 10,
  116222. };
  116223. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116224. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116225. };
  116226. static long _vq_quantmap__44c4_s_p5_0[] = {
  116227. 7, 5, 3, 1, 0, 2, 4, 6,
  116228. 8,
  116229. };
  116230. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116231. _vq_quantthresh__44c4_s_p5_0,
  116232. _vq_quantmap__44c4_s_p5_0,
  116233. 9,
  116234. 9
  116235. };
  116236. static static_codebook _44c4_s_p5_0 = {
  116237. 2, 81,
  116238. _vq_lengthlist__44c4_s_p5_0,
  116239. 1, -531628032, 1611661312, 4, 0,
  116240. _vq_quantlist__44c4_s_p5_0,
  116241. NULL,
  116242. &_vq_auxt__44c4_s_p5_0,
  116243. NULL,
  116244. 0
  116245. };
  116246. static long _vq_quantlist__44c4_s_p6_0[] = {
  116247. 8,
  116248. 7,
  116249. 9,
  116250. 6,
  116251. 10,
  116252. 5,
  116253. 11,
  116254. 4,
  116255. 12,
  116256. 3,
  116257. 13,
  116258. 2,
  116259. 14,
  116260. 1,
  116261. 15,
  116262. 0,
  116263. 16,
  116264. };
  116265. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116266. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116267. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116268. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116269. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116270. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116271. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116272. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116273. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116274. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116275. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116276. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116277. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116278. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116279. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116280. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116281. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116282. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116284. 13,
  116285. };
  116286. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116287. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116288. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116289. };
  116290. static long _vq_quantmap__44c4_s_p6_0[] = {
  116291. 15, 13, 11, 9, 7, 5, 3, 1,
  116292. 0, 2, 4, 6, 8, 10, 12, 14,
  116293. 16,
  116294. };
  116295. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116296. _vq_quantthresh__44c4_s_p6_0,
  116297. _vq_quantmap__44c4_s_p6_0,
  116298. 17,
  116299. 17
  116300. };
  116301. static static_codebook _44c4_s_p6_0 = {
  116302. 2, 289,
  116303. _vq_lengthlist__44c4_s_p6_0,
  116304. 1, -529530880, 1611661312, 5, 0,
  116305. _vq_quantlist__44c4_s_p6_0,
  116306. NULL,
  116307. &_vq_auxt__44c4_s_p6_0,
  116308. NULL,
  116309. 0
  116310. };
  116311. static long _vq_quantlist__44c4_s_p7_0[] = {
  116312. 1,
  116313. 0,
  116314. 2,
  116315. };
  116316. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116317. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116318. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116319. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116320. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116321. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116322. 10,
  116323. };
  116324. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116325. -5.5, 5.5,
  116326. };
  116327. static long _vq_quantmap__44c4_s_p7_0[] = {
  116328. 1, 0, 2,
  116329. };
  116330. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116331. _vq_quantthresh__44c4_s_p7_0,
  116332. _vq_quantmap__44c4_s_p7_0,
  116333. 3,
  116334. 3
  116335. };
  116336. static static_codebook _44c4_s_p7_0 = {
  116337. 4, 81,
  116338. _vq_lengthlist__44c4_s_p7_0,
  116339. 1, -529137664, 1618345984, 2, 0,
  116340. _vq_quantlist__44c4_s_p7_0,
  116341. NULL,
  116342. &_vq_auxt__44c4_s_p7_0,
  116343. NULL,
  116344. 0
  116345. };
  116346. static long _vq_quantlist__44c4_s_p7_1[] = {
  116347. 5,
  116348. 4,
  116349. 6,
  116350. 3,
  116351. 7,
  116352. 2,
  116353. 8,
  116354. 1,
  116355. 9,
  116356. 0,
  116357. 10,
  116358. };
  116359. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116360. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116361. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116362. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116363. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116364. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116365. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116366. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116367. 10,10,10, 8, 8, 8, 8, 9, 9,
  116368. };
  116369. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116370. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116371. 3.5, 4.5,
  116372. };
  116373. static long _vq_quantmap__44c4_s_p7_1[] = {
  116374. 9, 7, 5, 3, 1, 0, 2, 4,
  116375. 6, 8, 10,
  116376. };
  116377. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116378. _vq_quantthresh__44c4_s_p7_1,
  116379. _vq_quantmap__44c4_s_p7_1,
  116380. 11,
  116381. 11
  116382. };
  116383. static static_codebook _44c4_s_p7_1 = {
  116384. 2, 121,
  116385. _vq_lengthlist__44c4_s_p7_1,
  116386. 1, -531365888, 1611661312, 4, 0,
  116387. _vq_quantlist__44c4_s_p7_1,
  116388. NULL,
  116389. &_vq_auxt__44c4_s_p7_1,
  116390. NULL,
  116391. 0
  116392. };
  116393. static long _vq_quantlist__44c4_s_p8_0[] = {
  116394. 6,
  116395. 5,
  116396. 7,
  116397. 4,
  116398. 8,
  116399. 3,
  116400. 9,
  116401. 2,
  116402. 10,
  116403. 1,
  116404. 11,
  116405. 0,
  116406. 12,
  116407. };
  116408. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116409. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116410. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116411. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116412. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116413. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116414. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116415. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116416. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116417. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116418. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116419. 0,13,12,12,12,12,12,13,13,
  116420. };
  116421. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116422. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116423. 12.5, 17.5, 22.5, 27.5,
  116424. };
  116425. static long _vq_quantmap__44c4_s_p8_0[] = {
  116426. 11, 9, 7, 5, 3, 1, 0, 2,
  116427. 4, 6, 8, 10, 12,
  116428. };
  116429. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116430. _vq_quantthresh__44c4_s_p8_0,
  116431. _vq_quantmap__44c4_s_p8_0,
  116432. 13,
  116433. 13
  116434. };
  116435. static static_codebook _44c4_s_p8_0 = {
  116436. 2, 169,
  116437. _vq_lengthlist__44c4_s_p8_0,
  116438. 1, -526516224, 1616117760, 4, 0,
  116439. _vq_quantlist__44c4_s_p8_0,
  116440. NULL,
  116441. &_vq_auxt__44c4_s_p8_0,
  116442. NULL,
  116443. 0
  116444. };
  116445. static long _vq_quantlist__44c4_s_p8_1[] = {
  116446. 2,
  116447. 1,
  116448. 3,
  116449. 0,
  116450. 4,
  116451. };
  116452. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116453. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116454. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116455. };
  116456. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116457. -1.5, -0.5, 0.5, 1.5,
  116458. };
  116459. static long _vq_quantmap__44c4_s_p8_1[] = {
  116460. 3, 1, 0, 2, 4,
  116461. };
  116462. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116463. _vq_quantthresh__44c4_s_p8_1,
  116464. _vq_quantmap__44c4_s_p8_1,
  116465. 5,
  116466. 5
  116467. };
  116468. static static_codebook _44c4_s_p8_1 = {
  116469. 2, 25,
  116470. _vq_lengthlist__44c4_s_p8_1,
  116471. 1, -533725184, 1611661312, 3, 0,
  116472. _vq_quantlist__44c4_s_p8_1,
  116473. NULL,
  116474. &_vq_auxt__44c4_s_p8_1,
  116475. NULL,
  116476. 0
  116477. };
  116478. static long _vq_quantlist__44c4_s_p9_0[] = {
  116479. 6,
  116480. 5,
  116481. 7,
  116482. 4,
  116483. 8,
  116484. 3,
  116485. 9,
  116486. 2,
  116487. 10,
  116488. 1,
  116489. 11,
  116490. 0,
  116491. 12,
  116492. };
  116493. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116494. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116495. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116496. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116497. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116498. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116499. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116500. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116501. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116502. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116503. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116504. 12,12,12,12,12,12,12,12,12,
  116505. };
  116506. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116507. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116508. 787.5, 1102.5, 1417.5, 1732.5,
  116509. };
  116510. static long _vq_quantmap__44c4_s_p9_0[] = {
  116511. 11, 9, 7, 5, 3, 1, 0, 2,
  116512. 4, 6, 8, 10, 12,
  116513. };
  116514. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116515. _vq_quantthresh__44c4_s_p9_0,
  116516. _vq_quantmap__44c4_s_p9_0,
  116517. 13,
  116518. 13
  116519. };
  116520. static static_codebook _44c4_s_p9_0 = {
  116521. 2, 169,
  116522. _vq_lengthlist__44c4_s_p9_0,
  116523. 1, -513964032, 1628680192, 4, 0,
  116524. _vq_quantlist__44c4_s_p9_0,
  116525. NULL,
  116526. &_vq_auxt__44c4_s_p9_0,
  116527. NULL,
  116528. 0
  116529. };
  116530. static long _vq_quantlist__44c4_s_p9_1[] = {
  116531. 7,
  116532. 6,
  116533. 8,
  116534. 5,
  116535. 9,
  116536. 4,
  116537. 10,
  116538. 3,
  116539. 11,
  116540. 2,
  116541. 12,
  116542. 1,
  116543. 13,
  116544. 0,
  116545. 14,
  116546. };
  116547. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116548. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116549. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116550. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116551. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116552. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116553. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116554. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116555. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116556. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116557. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116558. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116559. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116560. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116561. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116562. 15,
  116563. };
  116564. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116565. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116566. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116567. };
  116568. static long _vq_quantmap__44c4_s_p9_1[] = {
  116569. 13, 11, 9, 7, 5, 3, 1, 0,
  116570. 2, 4, 6, 8, 10, 12, 14,
  116571. };
  116572. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116573. _vq_quantthresh__44c4_s_p9_1,
  116574. _vq_quantmap__44c4_s_p9_1,
  116575. 15,
  116576. 15
  116577. };
  116578. static static_codebook _44c4_s_p9_1 = {
  116579. 2, 225,
  116580. _vq_lengthlist__44c4_s_p9_1,
  116581. 1, -520986624, 1620377600, 4, 0,
  116582. _vq_quantlist__44c4_s_p9_1,
  116583. NULL,
  116584. &_vq_auxt__44c4_s_p9_1,
  116585. NULL,
  116586. 0
  116587. };
  116588. static long _vq_quantlist__44c4_s_p9_2[] = {
  116589. 10,
  116590. 9,
  116591. 11,
  116592. 8,
  116593. 12,
  116594. 7,
  116595. 13,
  116596. 6,
  116597. 14,
  116598. 5,
  116599. 15,
  116600. 4,
  116601. 16,
  116602. 3,
  116603. 17,
  116604. 2,
  116605. 18,
  116606. 1,
  116607. 19,
  116608. 0,
  116609. 20,
  116610. };
  116611. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116612. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116613. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116614. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116615. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116616. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116617. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116618. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116619. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116620. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116621. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116622. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116623. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116624. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116625. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116626. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116627. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116628. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116629. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116630. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116631. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116632. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116633. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116634. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116635. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116636. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116637. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116638. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116639. 10,10,10,10,10,10,10,10,10,
  116640. };
  116641. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116642. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116643. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116644. 6.5, 7.5, 8.5, 9.5,
  116645. };
  116646. static long _vq_quantmap__44c4_s_p9_2[] = {
  116647. 19, 17, 15, 13, 11, 9, 7, 5,
  116648. 3, 1, 0, 2, 4, 6, 8, 10,
  116649. 12, 14, 16, 18, 20,
  116650. };
  116651. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116652. _vq_quantthresh__44c4_s_p9_2,
  116653. _vq_quantmap__44c4_s_p9_2,
  116654. 21,
  116655. 21
  116656. };
  116657. static static_codebook _44c4_s_p9_2 = {
  116658. 2, 441,
  116659. _vq_lengthlist__44c4_s_p9_2,
  116660. 1, -529268736, 1611661312, 5, 0,
  116661. _vq_quantlist__44c4_s_p9_2,
  116662. NULL,
  116663. &_vq_auxt__44c4_s_p9_2,
  116664. NULL,
  116665. 0
  116666. };
  116667. static long _huff_lengthlist__44c4_s_short[] = {
  116668. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116669. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116670. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116671. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116672. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116673. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116674. 7, 9,12,17,
  116675. };
  116676. static static_codebook _huff_book__44c4_s_short = {
  116677. 2, 100,
  116678. _huff_lengthlist__44c4_s_short,
  116679. 0, 0, 0, 0, 0,
  116680. NULL,
  116681. NULL,
  116682. NULL,
  116683. NULL,
  116684. 0
  116685. };
  116686. static long _huff_lengthlist__44c5_s_long[] = {
  116687. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116688. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116689. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116690. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116691. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116692. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116693. 9, 8, 7, 7,
  116694. };
  116695. static static_codebook _huff_book__44c5_s_long = {
  116696. 2, 100,
  116697. _huff_lengthlist__44c5_s_long,
  116698. 0, 0, 0, 0, 0,
  116699. NULL,
  116700. NULL,
  116701. NULL,
  116702. NULL,
  116703. 0
  116704. };
  116705. static long _vq_quantlist__44c5_s_p1_0[] = {
  116706. 1,
  116707. 0,
  116708. 2,
  116709. };
  116710. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116711. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116712. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116717. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116722. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116757. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116762. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116767. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116780. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116785. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116790. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116803. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116808. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116813. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  117122. };
  117123. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117124. -0.5, 0.5,
  117125. };
  117126. static long _vq_quantmap__44c5_s_p1_0[] = {
  117127. 1, 0, 2,
  117128. };
  117129. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117130. _vq_quantthresh__44c5_s_p1_0,
  117131. _vq_quantmap__44c5_s_p1_0,
  117132. 3,
  117133. 3
  117134. };
  117135. static static_codebook _44c5_s_p1_0 = {
  117136. 8, 6561,
  117137. _vq_lengthlist__44c5_s_p1_0,
  117138. 1, -535822336, 1611661312, 2, 0,
  117139. _vq_quantlist__44c5_s_p1_0,
  117140. NULL,
  117141. &_vq_auxt__44c5_s_p1_0,
  117142. NULL,
  117143. 0
  117144. };
  117145. static long _vq_quantlist__44c5_s_p2_0[] = {
  117146. 2,
  117147. 1,
  117148. 3,
  117149. 0,
  117150. 4,
  117151. };
  117152. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117153. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117154. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117155. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117156. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117157. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117163. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117164. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117165. 10, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117171. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117172. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117179. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117180. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0,
  117193. };
  117194. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117195. -1.5, -0.5, 0.5, 1.5,
  117196. };
  117197. static long _vq_quantmap__44c5_s_p2_0[] = {
  117198. 3, 1, 0, 2, 4,
  117199. };
  117200. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117201. _vq_quantthresh__44c5_s_p2_0,
  117202. _vq_quantmap__44c5_s_p2_0,
  117203. 5,
  117204. 5
  117205. };
  117206. static static_codebook _44c5_s_p2_0 = {
  117207. 4, 625,
  117208. _vq_lengthlist__44c5_s_p2_0,
  117209. 1, -533725184, 1611661312, 3, 0,
  117210. _vq_quantlist__44c5_s_p2_0,
  117211. NULL,
  117212. &_vq_auxt__44c5_s_p2_0,
  117213. NULL,
  117214. 0
  117215. };
  117216. static long _vq_quantlist__44c5_s_p3_0[] = {
  117217. 2,
  117218. 1,
  117219. 3,
  117220. 0,
  117221. 4,
  117222. };
  117223. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117224. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117230. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117263. 0,
  117264. };
  117265. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117266. -1.5, -0.5, 0.5, 1.5,
  117267. };
  117268. static long _vq_quantmap__44c5_s_p3_0[] = {
  117269. 3, 1, 0, 2, 4,
  117270. };
  117271. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117272. _vq_quantthresh__44c5_s_p3_0,
  117273. _vq_quantmap__44c5_s_p3_0,
  117274. 5,
  117275. 5
  117276. };
  117277. static static_codebook _44c5_s_p3_0 = {
  117278. 4, 625,
  117279. _vq_lengthlist__44c5_s_p3_0,
  117280. 1, -533725184, 1611661312, 3, 0,
  117281. _vq_quantlist__44c5_s_p3_0,
  117282. NULL,
  117283. &_vq_auxt__44c5_s_p3_0,
  117284. NULL,
  117285. 0
  117286. };
  117287. static long _vq_quantlist__44c5_s_p4_0[] = {
  117288. 4,
  117289. 3,
  117290. 5,
  117291. 2,
  117292. 6,
  117293. 1,
  117294. 7,
  117295. 0,
  117296. 8,
  117297. };
  117298. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117299. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117300. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117301. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117302. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117303. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0,
  117305. };
  117306. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117307. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117308. };
  117309. static long _vq_quantmap__44c5_s_p4_0[] = {
  117310. 7, 5, 3, 1, 0, 2, 4, 6,
  117311. 8,
  117312. };
  117313. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117314. _vq_quantthresh__44c5_s_p4_0,
  117315. _vq_quantmap__44c5_s_p4_0,
  117316. 9,
  117317. 9
  117318. };
  117319. static static_codebook _44c5_s_p4_0 = {
  117320. 2, 81,
  117321. _vq_lengthlist__44c5_s_p4_0,
  117322. 1, -531628032, 1611661312, 4, 0,
  117323. _vq_quantlist__44c5_s_p4_0,
  117324. NULL,
  117325. &_vq_auxt__44c5_s_p4_0,
  117326. NULL,
  117327. 0
  117328. };
  117329. static long _vq_quantlist__44c5_s_p5_0[] = {
  117330. 4,
  117331. 3,
  117332. 5,
  117333. 2,
  117334. 6,
  117335. 1,
  117336. 7,
  117337. 0,
  117338. 8,
  117339. };
  117340. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117341. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117342. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117343. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117344. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117345. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117346. 10,
  117347. };
  117348. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117349. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117350. };
  117351. static long _vq_quantmap__44c5_s_p5_0[] = {
  117352. 7, 5, 3, 1, 0, 2, 4, 6,
  117353. 8,
  117354. };
  117355. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117356. _vq_quantthresh__44c5_s_p5_0,
  117357. _vq_quantmap__44c5_s_p5_0,
  117358. 9,
  117359. 9
  117360. };
  117361. static static_codebook _44c5_s_p5_0 = {
  117362. 2, 81,
  117363. _vq_lengthlist__44c5_s_p5_0,
  117364. 1, -531628032, 1611661312, 4, 0,
  117365. _vq_quantlist__44c5_s_p5_0,
  117366. NULL,
  117367. &_vq_auxt__44c5_s_p5_0,
  117368. NULL,
  117369. 0
  117370. };
  117371. static long _vq_quantlist__44c5_s_p6_0[] = {
  117372. 8,
  117373. 7,
  117374. 9,
  117375. 6,
  117376. 10,
  117377. 5,
  117378. 11,
  117379. 4,
  117380. 12,
  117381. 3,
  117382. 13,
  117383. 2,
  117384. 14,
  117385. 1,
  117386. 15,
  117387. 0,
  117388. 16,
  117389. };
  117390. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117391. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117392. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117393. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117394. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117395. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117396. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117397. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117398. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117399. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117400. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117401. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117402. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117403. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117404. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117405. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117406. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117407. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117409. 13,
  117410. };
  117411. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117412. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117413. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117414. };
  117415. static long _vq_quantmap__44c5_s_p6_0[] = {
  117416. 15, 13, 11, 9, 7, 5, 3, 1,
  117417. 0, 2, 4, 6, 8, 10, 12, 14,
  117418. 16,
  117419. };
  117420. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117421. _vq_quantthresh__44c5_s_p6_0,
  117422. _vq_quantmap__44c5_s_p6_0,
  117423. 17,
  117424. 17
  117425. };
  117426. static static_codebook _44c5_s_p6_0 = {
  117427. 2, 289,
  117428. _vq_lengthlist__44c5_s_p6_0,
  117429. 1, -529530880, 1611661312, 5, 0,
  117430. _vq_quantlist__44c5_s_p6_0,
  117431. NULL,
  117432. &_vq_auxt__44c5_s_p6_0,
  117433. NULL,
  117434. 0
  117435. };
  117436. static long _vq_quantlist__44c5_s_p7_0[] = {
  117437. 1,
  117438. 0,
  117439. 2,
  117440. };
  117441. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117442. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117443. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117444. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117445. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117446. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117447. 10,
  117448. };
  117449. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117450. -5.5, 5.5,
  117451. };
  117452. static long _vq_quantmap__44c5_s_p7_0[] = {
  117453. 1, 0, 2,
  117454. };
  117455. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117456. _vq_quantthresh__44c5_s_p7_0,
  117457. _vq_quantmap__44c5_s_p7_0,
  117458. 3,
  117459. 3
  117460. };
  117461. static static_codebook _44c5_s_p7_0 = {
  117462. 4, 81,
  117463. _vq_lengthlist__44c5_s_p7_0,
  117464. 1, -529137664, 1618345984, 2, 0,
  117465. _vq_quantlist__44c5_s_p7_0,
  117466. NULL,
  117467. &_vq_auxt__44c5_s_p7_0,
  117468. NULL,
  117469. 0
  117470. };
  117471. static long _vq_quantlist__44c5_s_p7_1[] = {
  117472. 5,
  117473. 4,
  117474. 6,
  117475. 3,
  117476. 7,
  117477. 2,
  117478. 8,
  117479. 1,
  117480. 9,
  117481. 0,
  117482. 10,
  117483. };
  117484. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117485. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117486. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117487. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117488. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117489. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117490. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117491. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117492. 10,10,10, 8, 8, 8, 8, 8, 8,
  117493. };
  117494. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117495. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117496. 3.5, 4.5,
  117497. };
  117498. static long _vq_quantmap__44c5_s_p7_1[] = {
  117499. 9, 7, 5, 3, 1, 0, 2, 4,
  117500. 6, 8, 10,
  117501. };
  117502. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117503. _vq_quantthresh__44c5_s_p7_1,
  117504. _vq_quantmap__44c5_s_p7_1,
  117505. 11,
  117506. 11
  117507. };
  117508. static static_codebook _44c5_s_p7_1 = {
  117509. 2, 121,
  117510. _vq_lengthlist__44c5_s_p7_1,
  117511. 1, -531365888, 1611661312, 4, 0,
  117512. _vq_quantlist__44c5_s_p7_1,
  117513. NULL,
  117514. &_vq_auxt__44c5_s_p7_1,
  117515. NULL,
  117516. 0
  117517. };
  117518. static long _vq_quantlist__44c5_s_p8_0[] = {
  117519. 6,
  117520. 5,
  117521. 7,
  117522. 4,
  117523. 8,
  117524. 3,
  117525. 9,
  117526. 2,
  117527. 10,
  117528. 1,
  117529. 11,
  117530. 0,
  117531. 12,
  117532. };
  117533. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117534. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117535. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117536. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117537. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117538. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117539. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117540. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117541. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117542. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117543. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117544. 0,12,12,12,12,12,12,13,13,
  117545. };
  117546. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117547. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117548. 12.5, 17.5, 22.5, 27.5,
  117549. };
  117550. static long _vq_quantmap__44c5_s_p8_0[] = {
  117551. 11, 9, 7, 5, 3, 1, 0, 2,
  117552. 4, 6, 8, 10, 12,
  117553. };
  117554. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117555. _vq_quantthresh__44c5_s_p8_0,
  117556. _vq_quantmap__44c5_s_p8_0,
  117557. 13,
  117558. 13
  117559. };
  117560. static static_codebook _44c5_s_p8_0 = {
  117561. 2, 169,
  117562. _vq_lengthlist__44c5_s_p8_0,
  117563. 1, -526516224, 1616117760, 4, 0,
  117564. _vq_quantlist__44c5_s_p8_0,
  117565. NULL,
  117566. &_vq_auxt__44c5_s_p8_0,
  117567. NULL,
  117568. 0
  117569. };
  117570. static long _vq_quantlist__44c5_s_p8_1[] = {
  117571. 2,
  117572. 1,
  117573. 3,
  117574. 0,
  117575. 4,
  117576. };
  117577. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117578. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117579. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117580. };
  117581. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117582. -1.5, -0.5, 0.5, 1.5,
  117583. };
  117584. static long _vq_quantmap__44c5_s_p8_1[] = {
  117585. 3, 1, 0, 2, 4,
  117586. };
  117587. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117588. _vq_quantthresh__44c5_s_p8_1,
  117589. _vq_quantmap__44c5_s_p8_1,
  117590. 5,
  117591. 5
  117592. };
  117593. static static_codebook _44c5_s_p8_1 = {
  117594. 2, 25,
  117595. _vq_lengthlist__44c5_s_p8_1,
  117596. 1, -533725184, 1611661312, 3, 0,
  117597. _vq_quantlist__44c5_s_p8_1,
  117598. NULL,
  117599. &_vq_auxt__44c5_s_p8_1,
  117600. NULL,
  117601. 0
  117602. };
  117603. static long _vq_quantlist__44c5_s_p9_0[] = {
  117604. 7,
  117605. 6,
  117606. 8,
  117607. 5,
  117608. 9,
  117609. 4,
  117610. 10,
  117611. 3,
  117612. 11,
  117613. 2,
  117614. 12,
  117615. 1,
  117616. 13,
  117617. 0,
  117618. 14,
  117619. };
  117620. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117621. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117622. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117623. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117624. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117625. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117626. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117627. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117628. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117629. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117630. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117631. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117632. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117633. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117634. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117635. 12,
  117636. };
  117637. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117638. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117639. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117640. };
  117641. static long _vq_quantmap__44c5_s_p9_0[] = {
  117642. 13, 11, 9, 7, 5, 3, 1, 0,
  117643. 2, 4, 6, 8, 10, 12, 14,
  117644. };
  117645. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117646. _vq_quantthresh__44c5_s_p9_0,
  117647. _vq_quantmap__44c5_s_p9_0,
  117648. 15,
  117649. 15
  117650. };
  117651. static static_codebook _44c5_s_p9_0 = {
  117652. 2, 225,
  117653. _vq_lengthlist__44c5_s_p9_0,
  117654. 1, -512522752, 1628852224, 4, 0,
  117655. _vq_quantlist__44c5_s_p9_0,
  117656. NULL,
  117657. &_vq_auxt__44c5_s_p9_0,
  117658. NULL,
  117659. 0
  117660. };
  117661. static long _vq_quantlist__44c5_s_p9_1[] = {
  117662. 8,
  117663. 7,
  117664. 9,
  117665. 6,
  117666. 10,
  117667. 5,
  117668. 11,
  117669. 4,
  117670. 12,
  117671. 3,
  117672. 13,
  117673. 2,
  117674. 14,
  117675. 1,
  117676. 15,
  117677. 0,
  117678. 16,
  117679. };
  117680. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117681. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117682. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117683. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117684. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117685. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117686. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117687. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117688. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117689. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117690. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117691. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117692. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117693. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117694. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117695. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117696. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117697. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117698. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117699. 15,
  117700. };
  117701. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117702. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117703. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117704. };
  117705. static long _vq_quantmap__44c5_s_p9_1[] = {
  117706. 15, 13, 11, 9, 7, 5, 3, 1,
  117707. 0, 2, 4, 6, 8, 10, 12, 14,
  117708. 16,
  117709. };
  117710. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117711. _vq_quantthresh__44c5_s_p9_1,
  117712. _vq_quantmap__44c5_s_p9_1,
  117713. 17,
  117714. 17
  117715. };
  117716. static static_codebook _44c5_s_p9_1 = {
  117717. 2, 289,
  117718. _vq_lengthlist__44c5_s_p9_1,
  117719. 1, -520814592, 1620377600, 5, 0,
  117720. _vq_quantlist__44c5_s_p9_1,
  117721. NULL,
  117722. &_vq_auxt__44c5_s_p9_1,
  117723. NULL,
  117724. 0
  117725. };
  117726. static long _vq_quantlist__44c5_s_p9_2[] = {
  117727. 10,
  117728. 9,
  117729. 11,
  117730. 8,
  117731. 12,
  117732. 7,
  117733. 13,
  117734. 6,
  117735. 14,
  117736. 5,
  117737. 15,
  117738. 4,
  117739. 16,
  117740. 3,
  117741. 17,
  117742. 2,
  117743. 18,
  117744. 1,
  117745. 19,
  117746. 0,
  117747. 20,
  117748. };
  117749. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117750. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117751. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117752. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117753. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117754. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117755. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117756. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117757. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117758. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117759. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117760. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117761. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117762. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117763. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117764. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117765. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117766. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117767. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117768. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117769. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117770. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117771. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117772. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117773. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117774. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117775. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117776. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117777. 10,10,10,10,10,10,10,10,10,
  117778. };
  117779. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117780. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117781. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117782. 6.5, 7.5, 8.5, 9.5,
  117783. };
  117784. static long _vq_quantmap__44c5_s_p9_2[] = {
  117785. 19, 17, 15, 13, 11, 9, 7, 5,
  117786. 3, 1, 0, 2, 4, 6, 8, 10,
  117787. 12, 14, 16, 18, 20,
  117788. };
  117789. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117790. _vq_quantthresh__44c5_s_p9_2,
  117791. _vq_quantmap__44c5_s_p9_2,
  117792. 21,
  117793. 21
  117794. };
  117795. static static_codebook _44c5_s_p9_2 = {
  117796. 2, 441,
  117797. _vq_lengthlist__44c5_s_p9_2,
  117798. 1, -529268736, 1611661312, 5, 0,
  117799. _vq_quantlist__44c5_s_p9_2,
  117800. NULL,
  117801. &_vq_auxt__44c5_s_p9_2,
  117802. NULL,
  117803. 0
  117804. };
  117805. static long _huff_lengthlist__44c5_s_short[] = {
  117806. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117807. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117808. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117809. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117810. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117811. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117812. 6, 8,11,16,
  117813. };
  117814. static static_codebook _huff_book__44c5_s_short = {
  117815. 2, 100,
  117816. _huff_lengthlist__44c5_s_short,
  117817. 0, 0, 0, 0, 0,
  117818. NULL,
  117819. NULL,
  117820. NULL,
  117821. NULL,
  117822. 0
  117823. };
  117824. static long _huff_lengthlist__44c6_s_long[] = {
  117825. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117826. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117827. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117828. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117829. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117830. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117831. 11,10,10,12,
  117832. };
  117833. static static_codebook _huff_book__44c6_s_long = {
  117834. 2, 100,
  117835. _huff_lengthlist__44c6_s_long,
  117836. 0, 0, 0, 0, 0,
  117837. NULL,
  117838. NULL,
  117839. NULL,
  117840. NULL,
  117841. 0
  117842. };
  117843. static long _vq_quantlist__44c6_s_p1_0[] = {
  117844. 1,
  117845. 0,
  117846. 2,
  117847. };
  117848. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117849. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117850. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117851. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117852. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117853. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117854. 8,
  117855. };
  117856. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117857. -0.5, 0.5,
  117858. };
  117859. static long _vq_quantmap__44c6_s_p1_0[] = {
  117860. 1, 0, 2,
  117861. };
  117862. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117863. _vq_quantthresh__44c6_s_p1_0,
  117864. _vq_quantmap__44c6_s_p1_0,
  117865. 3,
  117866. 3
  117867. };
  117868. static static_codebook _44c6_s_p1_0 = {
  117869. 4, 81,
  117870. _vq_lengthlist__44c6_s_p1_0,
  117871. 1, -535822336, 1611661312, 2, 0,
  117872. _vq_quantlist__44c6_s_p1_0,
  117873. NULL,
  117874. &_vq_auxt__44c6_s_p1_0,
  117875. NULL,
  117876. 0
  117877. };
  117878. static long _vq_quantlist__44c6_s_p2_0[] = {
  117879. 2,
  117880. 1,
  117881. 3,
  117882. 0,
  117883. 4,
  117884. };
  117885. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117886. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117887. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117888. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117889. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117890. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117891. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117892. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117893. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117895. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117896. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117897. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117898. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117899. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117900. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117901. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117903. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117904. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117905. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117906. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117907. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117908. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117909. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117911. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117912. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117913. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117914. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117915. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117916. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  117917. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  117922. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  117923. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  117924. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  117925. 13,
  117926. };
  117927. static float _vq_quantthresh__44c6_s_p2_0[] = {
  117928. -1.5, -0.5, 0.5, 1.5,
  117929. };
  117930. static long _vq_quantmap__44c6_s_p2_0[] = {
  117931. 3, 1, 0, 2, 4,
  117932. };
  117933. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  117934. _vq_quantthresh__44c6_s_p2_0,
  117935. _vq_quantmap__44c6_s_p2_0,
  117936. 5,
  117937. 5
  117938. };
  117939. static static_codebook _44c6_s_p2_0 = {
  117940. 4, 625,
  117941. _vq_lengthlist__44c6_s_p2_0,
  117942. 1, -533725184, 1611661312, 3, 0,
  117943. _vq_quantlist__44c6_s_p2_0,
  117944. NULL,
  117945. &_vq_auxt__44c6_s_p2_0,
  117946. NULL,
  117947. 0
  117948. };
  117949. static long _vq_quantlist__44c6_s_p3_0[] = {
  117950. 4,
  117951. 3,
  117952. 5,
  117953. 2,
  117954. 6,
  117955. 1,
  117956. 7,
  117957. 0,
  117958. 8,
  117959. };
  117960. static long _vq_lengthlist__44c6_s_p3_0[] = {
  117961. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117962. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  117963. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  117964. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  117965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117966. 0,
  117967. };
  117968. static float _vq_quantthresh__44c6_s_p3_0[] = {
  117969. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117970. };
  117971. static long _vq_quantmap__44c6_s_p3_0[] = {
  117972. 7, 5, 3, 1, 0, 2, 4, 6,
  117973. 8,
  117974. };
  117975. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  117976. _vq_quantthresh__44c6_s_p3_0,
  117977. _vq_quantmap__44c6_s_p3_0,
  117978. 9,
  117979. 9
  117980. };
  117981. static static_codebook _44c6_s_p3_0 = {
  117982. 2, 81,
  117983. _vq_lengthlist__44c6_s_p3_0,
  117984. 1, -531628032, 1611661312, 4, 0,
  117985. _vq_quantlist__44c6_s_p3_0,
  117986. NULL,
  117987. &_vq_auxt__44c6_s_p3_0,
  117988. NULL,
  117989. 0
  117990. };
  117991. static long _vq_quantlist__44c6_s_p4_0[] = {
  117992. 8,
  117993. 7,
  117994. 9,
  117995. 6,
  117996. 10,
  117997. 5,
  117998. 11,
  117999. 4,
  118000. 12,
  118001. 3,
  118002. 13,
  118003. 2,
  118004. 14,
  118005. 1,
  118006. 15,
  118007. 0,
  118008. 16,
  118009. };
  118010. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118011. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118012. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118013. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118014. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118015. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118016. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118017. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118018. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118019. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118020. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118029. 0,
  118030. };
  118031. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118032. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118033. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118034. };
  118035. static long _vq_quantmap__44c6_s_p4_0[] = {
  118036. 15, 13, 11, 9, 7, 5, 3, 1,
  118037. 0, 2, 4, 6, 8, 10, 12, 14,
  118038. 16,
  118039. };
  118040. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118041. _vq_quantthresh__44c6_s_p4_0,
  118042. _vq_quantmap__44c6_s_p4_0,
  118043. 17,
  118044. 17
  118045. };
  118046. static static_codebook _44c6_s_p4_0 = {
  118047. 2, 289,
  118048. _vq_lengthlist__44c6_s_p4_0,
  118049. 1, -529530880, 1611661312, 5, 0,
  118050. _vq_quantlist__44c6_s_p4_0,
  118051. NULL,
  118052. &_vq_auxt__44c6_s_p4_0,
  118053. NULL,
  118054. 0
  118055. };
  118056. static long _vq_quantlist__44c6_s_p5_0[] = {
  118057. 1,
  118058. 0,
  118059. 2,
  118060. };
  118061. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118062. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118063. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118064. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118065. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118066. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118067. 12,
  118068. };
  118069. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118070. -5.5, 5.5,
  118071. };
  118072. static long _vq_quantmap__44c6_s_p5_0[] = {
  118073. 1, 0, 2,
  118074. };
  118075. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118076. _vq_quantthresh__44c6_s_p5_0,
  118077. _vq_quantmap__44c6_s_p5_0,
  118078. 3,
  118079. 3
  118080. };
  118081. static static_codebook _44c6_s_p5_0 = {
  118082. 4, 81,
  118083. _vq_lengthlist__44c6_s_p5_0,
  118084. 1, -529137664, 1618345984, 2, 0,
  118085. _vq_quantlist__44c6_s_p5_0,
  118086. NULL,
  118087. &_vq_auxt__44c6_s_p5_0,
  118088. NULL,
  118089. 0
  118090. };
  118091. static long _vq_quantlist__44c6_s_p5_1[] = {
  118092. 5,
  118093. 4,
  118094. 6,
  118095. 3,
  118096. 7,
  118097. 2,
  118098. 8,
  118099. 1,
  118100. 9,
  118101. 0,
  118102. 10,
  118103. };
  118104. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118105. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118106. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118107. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118108. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118109. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118110. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118111. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118112. 11,10,10, 7, 7, 8, 8, 8, 8,
  118113. };
  118114. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118115. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118116. 3.5, 4.5,
  118117. };
  118118. static long _vq_quantmap__44c6_s_p5_1[] = {
  118119. 9, 7, 5, 3, 1, 0, 2, 4,
  118120. 6, 8, 10,
  118121. };
  118122. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118123. _vq_quantthresh__44c6_s_p5_1,
  118124. _vq_quantmap__44c6_s_p5_1,
  118125. 11,
  118126. 11
  118127. };
  118128. static static_codebook _44c6_s_p5_1 = {
  118129. 2, 121,
  118130. _vq_lengthlist__44c6_s_p5_1,
  118131. 1, -531365888, 1611661312, 4, 0,
  118132. _vq_quantlist__44c6_s_p5_1,
  118133. NULL,
  118134. &_vq_auxt__44c6_s_p5_1,
  118135. NULL,
  118136. 0
  118137. };
  118138. static long _vq_quantlist__44c6_s_p6_0[] = {
  118139. 6,
  118140. 5,
  118141. 7,
  118142. 4,
  118143. 8,
  118144. 3,
  118145. 9,
  118146. 2,
  118147. 10,
  118148. 1,
  118149. 11,
  118150. 0,
  118151. 12,
  118152. };
  118153. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118154. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118155. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118156. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118157. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118158. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118159. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118164. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118165. };
  118166. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118167. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118168. 12.5, 17.5, 22.5, 27.5,
  118169. };
  118170. static long _vq_quantmap__44c6_s_p6_0[] = {
  118171. 11, 9, 7, 5, 3, 1, 0, 2,
  118172. 4, 6, 8, 10, 12,
  118173. };
  118174. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118175. _vq_quantthresh__44c6_s_p6_0,
  118176. _vq_quantmap__44c6_s_p6_0,
  118177. 13,
  118178. 13
  118179. };
  118180. static static_codebook _44c6_s_p6_0 = {
  118181. 2, 169,
  118182. _vq_lengthlist__44c6_s_p6_0,
  118183. 1, -526516224, 1616117760, 4, 0,
  118184. _vq_quantlist__44c6_s_p6_0,
  118185. NULL,
  118186. &_vq_auxt__44c6_s_p6_0,
  118187. NULL,
  118188. 0
  118189. };
  118190. static long _vq_quantlist__44c6_s_p6_1[] = {
  118191. 2,
  118192. 1,
  118193. 3,
  118194. 0,
  118195. 4,
  118196. };
  118197. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118198. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118199. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118200. };
  118201. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118202. -1.5, -0.5, 0.5, 1.5,
  118203. };
  118204. static long _vq_quantmap__44c6_s_p6_1[] = {
  118205. 3, 1, 0, 2, 4,
  118206. };
  118207. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118208. _vq_quantthresh__44c6_s_p6_1,
  118209. _vq_quantmap__44c6_s_p6_1,
  118210. 5,
  118211. 5
  118212. };
  118213. static static_codebook _44c6_s_p6_1 = {
  118214. 2, 25,
  118215. _vq_lengthlist__44c6_s_p6_1,
  118216. 1, -533725184, 1611661312, 3, 0,
  118217. _vq_quantlist__44c6_s_p6_1,
  118218. NULL,
  118219. &_vq_auxt__44c6_s_p6_1,
  118220. NULL,
  118221. 0
  118222. };
  118223. static long _vq_quantlist__44c6_s_p7_0[] = {
  118224. 6,
  118225. 5,
  118226. 7,
  118227. 4,
  118228. 8,
  118229. 3,
  118230. 9,
  118231. 2,
  118232. 10,
  118233. 1,
  118234. 11,
  118235. 0,
  118236. 12,
  118237. };
  118238. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118239. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118240. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118241. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118242. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118243. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118244. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118245. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118246. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118247. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118248. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118249. 20,13,13,13,13,13,13,14,14,
  118250. };
  118251. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118252. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118253. 27.5, 38.5, 49.5, 60.5,
  118254. };
  118255. static long _vq_quantmap__44c6_s_p7_0[] = {
  118256. 11, 9, 7, 5, 3, 1, 0, 2,
  118257. 4, 6, 8, 10, 12,
  118258. };
  118259. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118260. _vq_quantthresh__44c6_s_p7_0,
  118261. _vq_quantmap__44c6_s_p7_0,
  118262. 13,
  118263. 13
  118264. };
  118265. static static_codebook _44c6_s_p7_0 = {
  118266. 2, 169,
  118267. _vq_lengthlist__44c6_s_p7_0,
  118268. 1, -523206656, 1618345984, 4, 0,
  118269. _vq_quantlist__44c6_s_p7_0,
  118270. NULL,
  118271. &_vq_auxt__44c6_s_p7_0,
  118272. NULL,
  118273. 0
  118274. };
  118275. static long _vq_quantlist__44c6_s_p7_1[] = {
  118276. 5,
  118277. 4,
  118278. 6,
  118279. 3,
  118280. 7,
  118281. 2,
  118282. 8,
  118283. 1,
  118284. 9,
  118285. 0,
  118286. 10,
  118287. };
  118288. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118289. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118290. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118291. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118292. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118293. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118294. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118295. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118296. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118297. };
  118298. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118299. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118300. 3.5, 4.5,
  118301. };
  118302. static long _vq_quantmap__44c6_s_p7_1[] = {
  118303. 9, 7, 5, 3, 1, 0, 2, 4,
  118304. 6, 8, 10,
  118305. };
  118306. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118307. _vq_quantthresh__44c6_s_p7_1,
  118308. _vq_quantmap__44c6_s_p7_1,
  118309. 11,
  118310. 11
  118311. };
  118312. static static_codebook _44c6_s_p7_1 = {
  118313. 2, 121,
  118314. _vq_lengthlist__44c6_s_p7_1,
  118315. 1, -531365888, 1611661312, 4, 0,
  118316. _vq_quantlist__44c6_s_p7_1,
  118317. NULL,
  118318. &_vq_auxt__44c6_s_p7_1,
  118319. NULL,
  118320. 0
  118321. };
  118322. static long _vq_quantlist__44c6_s_p8_0[] = {
  118323. 7,
  118324. 6,
  118325. 8,
  118326. 5,
  118327. 9,
  118328. 4,
  118329. 10,
  118330. 3,
  118331. 11,
  118332. 2,
  118333. 12,
  118334. 1,
  118335. 13,
  118336. 0,
  118337. 14,
  118338. };
  118339. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118340. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118341. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118342. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118343. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118344. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118345. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118346. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118347. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118348. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118349. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118350. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118351. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118352. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118353. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118354. 14,
  118355. };
  118356. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118357. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118358. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118359. };
  118360. static long _vq_quantmap__44c6_s_p8_0[] = {
  118361. 13, 11, 9, 7, 5, 3, 1, 0,
  118362. 2, 4, 6, 8, 10, 12, 14,
  118363. };
  118364. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118365. _vq_quantthresh__44c6_s_p8_0,
  118366. _vq_quantmap__44c6_s_p8_0,
  118367. 15,
  118368. 15
  118369. };
  118370. static static_codebook _44c6_s_p8_0 = {
  118371. 2, 225,
  118372. _vq_lengthlist__44c6_s_p8_0,
  118373. 1, -520986624, 1620377600, 4, 0,
  118374. _vq_quantlist__44c6_s_p8_0,
  118375. NULL,
  118376. &_vq_auxt__44c6_s_p8_0,
  118377. NULL,
  118378. 0
  118379. };
  118380. static long _vq_quantlist__44c6_s_p8_1[] = {
  118381. 10,
  118382. 9,
  118383. 11,
  118384. 8,
  118385. 12,
  118386. 7,
  118387. 13,
  118388. 6,
  118389. 14,
  118390. 5,
  118391. 15,
  118392. 4,
  118393. 16,
  118394. 3,
  118395. 17,
  118396. 2,
  118397. 18,
  118398. 1,
  118399. 19,
  118400. 0,
  118401. 20,
  118402. };
  118403. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118404. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118405. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118406. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118407. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118408. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118409. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118410. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118411. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118412. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118413. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118414. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118415. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118416. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118417. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118418. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118419. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118420. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118421. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118422. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118423. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118424. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118425. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118426. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118427. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118428. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118429. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118430. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118431. 10,10,10,10,10,10,10,10,10,
  118432. };
  118433. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118434. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118435. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118436. 6.5, 7.5, 8.5, 9.5,
  118437. };
  118438. static long _vq_quantmap__44c6_s_p8_1[] = {
  118439. 19, 17, 15, 13, 11, 9, 7, 5,
  118440. 3, 1, 0, 2, 4, 6, 8, 10,
  118441. 12, 14, 16, 18, 20,
  118442. };
  118443. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118444. _vq_quantthresh__44c6_s_p8_1,
  118445. _vq_quantmap__44c6_s_p8_1,
  118446. 21,
  118447. 21
  118448. };
  118449. static static_codebook _44c6_s_p8_1 = {
  118450. 2, 441,
  118451. _vq_lengthlist__44c6_s_p8_1,
  118452. 1, -529268736, 1611661312, 5, 0,
  118453. _vq_quantlist__44c6_s_p8_1,
  118454. NULL,
  118455. &_vq_auxt__44c6_s_p8_1,
  118456. NULL,
  118457. 0
  118458. };
  118459. static long _vq_quantlist__44c6_s_p9_0[] = {
  118460. 6,
  118461. 5,
  118462. 7,
  118463. 4,
  118464. 8,
  118465. 3,
  118466. 9,
  118467. 2,
  118468. 10,
  118469. 1,
  118470. 11,
  118471. 0,
  118472. 12,
  118473. };
  118474. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118475. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118476. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118477. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118478. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118479. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118480. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118481. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118482. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118483. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118484. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118485. 10,10,10,10,10,10,10,10,10,
  118486. };
  118487. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118488. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118489. 1592.5, 2229.5, 2866.5, 3503.5,
  118490. };
  118491. static long _vq_quantmap__44c6_s_p9_0[] = {
  118492. 11, 9, 7, 5, 3, 1, 0, 2,
  118493. 4, 6, 8, 10, 12,
  118494. };
  118495. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118496. _vq_quantthresh__44c6_s_p9_0,
  118497. _vq_quantmap__44c6_s_p9_0,
  118498. 13,
  118499. 13
  118500. };
  118501. static static_codebook _44c6_s_p9_0 = {
  118502. 2, 169,
  118503. _vq_lengthlist__44c6_s_p9_0,
  118504. 1, -511845376, 1630791680, 4, 0,
  118505. _vq_quantlist__44c6_s_p9_0,
  118506. NULL,
  118507. &_vq_auxt__44c6_s_p9_0,
  118508. NULL,
  118509. 0
  118510. };
  118511. static long _vq_quantlist__44c6_s_p9_1[] = {
  118512. 6,
  118513. 5,
  118514. 7,
  118515. 4,
  118516. 8,
  118517. 3,
  118518. 9,
  118519. 2,
  118520. 10,
  118521. 1,
  118522. 11,
  118523. 0,
  118524. 12,
  118525. };
  118526. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118527. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118528. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118529. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118530. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118531. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118532. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118533. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118534. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118535. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118536. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118537. 15,12,10,11,11,13,11,12,13,
  118538. };
  118539. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118540. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118541. 122.5, 171.5, 220.5, 269.5,
  118542. };
  118543. static long _vq_quantmap__44c6_s_p9_1[] = {
  118544. 11, 9, 7, 5, 3, 1, 0, 2,
  118545. 4, 6, 8, 10, 12,
  118546. };
  118547. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118548. _vq_quantthresh__44c6_s_p9_1,
  118549. _vq_quantmap__44c6_s_p9_1,
  118550. 13,
  118551. 13
  118552. };
  118553. static static_codebook _44c6_s_p9_1 = {
  118554. 2, 169,
  118555. _vq_lengthlist__44c6_s_p9_1,
  118556. 1, -518889472, 1622704128, 4, 0,
  118557. _vq_quantlist__44c6_s_p9_1,
  118558. NULL,
  118559. &_vq_auxt__44c6_s_p9_1,
  118560. NULL,
  118561. 0
  118562. };
  118563. static long _vq_quantlist__44c6_s_p9_2[] = {
  118564. 24,
  118565. 23,
  118566. 25,
  118567. 22,
  118568. 26,
  118569. 21,
  118570. 27,
  118571. 20,
  118572. 28,
  118573. 19,
  118574. 29,
  118575. 18,
  118576. 30,
  118577. 17,
  118578. 31,
  118579. 16,
  118580. 32,
  118581. 15,
  118582. 33,
  118583. 14,
  118584. 34,
  118585. 13,
  118586. 35,
  118587. 12,
  118588. 36,
  118589. 11,
  118590. 37,
  118591. 10,
  118592. 38,
  118593. 9,
  118594. 39,
  118595. 8,
  118596. 40,
  118597. 7,
  118598. 41,
  118599. 6,
  118600. 42,
  118601. 5,
  118602. 43,
  118603. 4,
  118604. 44,
  118605. 3,
  118606. 45,
  118607. 2,
  118608. 46,
  118609. 1,
  118610. 47,
  118611. 0,
  118612. 48,
  118613. };
  118614. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118615. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118616. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118617. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118618. 7,
  118619. };
  118620. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118621. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118622. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118623. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118624. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118625. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118626. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118627. };
  118628. static long _vq_quantmap__44c6_s_p9_2[] = {
  118629. 47, 45, 43, 41, 39, 37, 35, 33,
  118630. 31, 29, 27, 25, 23, 21, 19, 17,
  118631. 15, 13, 11, 9, 7, 5, 3, 1,
  118632. 0, 2, 4, 6, 8, 10, 12, 14,
  118633. 16, 18, 20, 22, 24, 26, 28, 30,
  118634. 32, 34, 36, 38, 40, 42, 44, 46,
  118635. 48,
  118636. };
  118637. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118638. _vq_quantthresh__44c6_s_p9_2,
  118639. _vq_quantmap__44c6_s_p9_2,
  118640. 49,
  118641. 49
  118642. };
  118643. static static_codebook _44c6_s_p9_2 = {
  118644. 1, 49,
  118645. _vq_lengthlist__44c6_s_p9_2,
  118646. 1, -526909440, 1611661312, 6, 0,
  118647. _vq_quantlist__44c6_s_p9_2,
  118648. NULL,
  118649. &_vq_auxt__44c6_s_p9_2,
  118650. NULL,
  118651. 0
  118652. };
  118653. static long _huff_lengthlist__44c6_s_short[] = {
  118654. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118655. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118656. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118657. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118658. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118659. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118660. 9,10,17,18,
  118661. };
  118662. static static_codebook _huff_book__44c6_s_short = {
  118663. 2, 100,
  118664. _huff_lengthlist__44c6_s_short,
  118665. 0, 0, 0, 0, 0,
  118666. NULL,
  118667. NULL,
  118668. NULL,
  118669. NULL,
  118670. 0
  118671. };
  118672. static long _huff_lengthlist__44c7_s_long[] = {
  118673. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118674. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118675. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118676. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118677. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118678. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118679. 11,10,10,12,
  118680. };
  118681. static static_codebook _huff_book__44c7_s_long = {
  118682. 2, 100,
  118683. _huff_lengthlist__44c7_s_long,
  118684. 0, 0, 0, 0, 0,
  118685. NULL,
  118686. NULL,
  118687. NULL,
  118688. NULL,
  118689. 0
  118690. };
  118691. static long _vq_quantlist__44c7_s_p1_0[] = {
  118692. 1,
  118693. 0,
  118694. 2,
  118695. };
  118696. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118697. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118698. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118699. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118700. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118701. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118702. 8,
  118703. };
  118704. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118705. -0.5, 0.5,
  118706. };
  118707. static long _vq_quantmap__44c7_s_p1_0[] = {
  118708. 1, 0, 2,
  118709. };
  118710. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118711. _vq_quantthresh__44c7_s_p1_0,
  118712. _vq_quantmap__44c7_s_p1_0,
  118713. 3,
  118714. 3
  118715. };
  118716. static static_codebook _44c7_s_p1_0 = {
  118717. 4, 81,
  118718. _vq_lengthlist__44c7_s_p1_0,
  118719. 1, -535822336, 1611661312, 2, 0,
  118720. _vq_quantlist__44c7_s_p1_0,
  118721. NULL,
  118722. &_vq_auxt__44c7_s_p1_0,
  118723. NULL,
  118724. 0
  118725. };
  118726. static long _vq_quantlist__44c7_s_p2_0[] = {
  118727. 2,
  118728. 1,
  118729. 3,
  118730. 0,
  118731. 4,
  118732. };
  118733. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118734. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118735. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118736. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118737. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118738. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118739. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118740. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118741. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118743. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118744. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118745. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118746. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118747. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118748. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118749. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118751. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118752. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118753. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118754. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118755. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118756. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118757. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118759. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118760. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118761. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118762. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118763. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118764. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118765. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118770. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118771. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118772. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118773. 13,
  118774. };
  118775. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118776. -1.5, -0.5, 0.5, 1.5,
  118777. };
  118778. static long _vq_quantmap__44c7_s_p2_0[] = {
  118779. 3, 1, 0, 2, 4,
  118780. };
  118781. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118782. _vq_quantthresh__44c7_s_p2_0,
  118783. _vq_quantmap__44c7_s_p2_0,
  118784. 5,
  118785. 5
  118786. };
  118787. static static_codebook _44c7_s_p2_0 = {
  118788. 4, 625,
  118789. _vq_lengthlist__44c7_s_p2_0,
  118790. 1, -533725184, 1611661312, 3, 0,
  118791. _vq_quantlist__44c7_s_p2_0,
  118792. NULL,
  118793. &_vq_auxt__44c7_s_p2_0,
  118794. NULL,
  118795. 0
  118796. };
  118797. static long _vq_quantlist__44c7_s_p3_0[] = {
  118798. 4,
  118799. 3,
  118800. 5,
  118801. 2,
  118802. 6,
  118803. 1,
  118804. 7,
  118805. 0,
  118806. 8,
  118807. };
  118808. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118809. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118810. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118811. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118812. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118814. 0,
  118815. };
  118816. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118817. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118818. };
  118819. static long _vq_quantmap__44c7_s_p3_0[] = {
  118820. 7, 5, 3, 1, 0, 2, 4, 6,
  118821. 8,
  118822. };
  118823. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118824. _vq_quantthresh__44c7_s_p3_0,
  118825. _vq_quantmap__44c7_s_p3_0,
  118826. 9,
  118827. 9
  118828. };
  118829. static static_codebook _44c7_s_p3_0 = {
  118830. 2, 81,
  118831. _vq_lengthlist__44c7_s_p3_0,
  118832. 1, -531628032, 1611661312, 4, 0,
  118833. _vq_quantlist__44c7_s_p3_0,
  118834. NULL,
  118835. &_vq_auxt__44c7_s_p3_0,
  118836. NULL,
  118837. 0
  118838. };
  118839. static long _vq_quantlist__44c7_s_p4_0[] = {
  118840. 8,
  118841. 7,
  118842. 9,
  118843. 6,
  118844. 10,
  118845. 5,
  118846. 11,
  118847. 4,
  118848. 12,
  118849. 3,
  118850. 13,
  118851. 2,
  118852. 14,
  118853. 1,
  118854. 15,
  118855. 0,
  118856. 16,
  118857. };
  118858. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118859. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118860. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118861. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118862. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118863. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118864. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118865. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118866. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118867. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118868. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118877. 0,
  118878. };
  118879. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118880. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118881. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118882. };
  118883. static long _vq_quantmap__44c7_s_p4_0[] = {
  118884. 15, 13, 11, 9, 7, 5, 3, 1,
  118885. 0, 2, 4, 6, 8, 10, 12, 14,
  118886. 16,
  118887. };
  118888. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118889. _vq_quantthresh__44c7_s_p4_0,
  118890. _vq_quantmap__44c7_s_p4_0,
  118891. 17,
  118892. 17
  118893. };
  118894. static static_codebook _44c7_s_p4_0 = {
  118895. 2, 289,
  118896. _vq_lengthlist__44c7_s_p4_0,
  118897. 1, -529530880, 1611661312, 5, 0,
  118898. _vq_quantlist__44c7_s_p4_0,
  118899. NULL,
  118900. &_vq_auxt__44c7_s_p4_0,
  118901. NULL,
  118902. 0
  118903. };
  118904. static long _vq_quantlist__44c7_s_p5_0[] = {
  118905. 1,
  118906. 0,
  118907. 2,
  118908. };
  118909. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118910. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118911. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118912. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118913. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118914. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118915. 12,
  118916. };
  118917. static float _vq_quantthresh__44c7_s_p5_0[] = {
  118918. -5.5, 5.5,
  118919. };
  118920. static long _vq_quantmap__44c7_s_p5_0[] = {
  118921. 1, 0, 2,
  118922. };
  118923. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  118924. _vq_quantthresh__44c7_s_p5_0,
  118925. _vq_quantmap__44c7_s_p5_0,
  118926. 3,
  118927. 3
  118928. };
  118929. static static_codebook _44c7_s_p5_0 = {
  118930. 4, 81,
  118931. _vq_lengthlist__44c7_s_p5_0,
  118932. 1, -529137664, 1618345984, 2, 0,
  118933. _vq_quantlist__44c7_s_p5_0,
  118934. NULL,
  118935. &_vq_auxt__44c7_s_p5_0,
  118936. NULL,
  118937. 0
  118938. };
  118939. static long _vq_quantlist__44c7_s_p5_1[] = {
  118940. 5,
  118941. 4,
  118942. 6,
  118943. 3,
  118944. 7,
  118945. 2,
  118946. 8,
  118947. 1,
  118948. 9,
  118949. 0,
  118950. 10,
  118951. };
  118952. static long _vq_lengthlist__44c7_s_p5_1[] = {
  118953. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118954. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  118955. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  118956. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  118957. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  118958. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  118959. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  118960. 11,11,11, 7, 7, 8, 8, 8, 8,
  118961. };
  118962. static float _vq_quantthresh__44c7_s_p5_1[] = {
  118963. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118964. 3.5, 4.5,
  118965. };
  118966. static long _vq_quantmap__44c7_s_p5_1[] = {
  118967. 9, 7, 5, 3, 1, 0, 2, 4,
  118968. 6, 8, 10,
  118969. };
  118970. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  118971. _vq_quantthresh__44c7_s_p5_1,
  118972. _vq_quantmap__44c7_s_p5_1,
  118973. 11,
  118974. 11
  118975. };
  118976. static static_codebook _44c7_s_p5_1 = {
  118977. 2, 121,
  118978. _vq_lengthlist__44c7_s_p5_1,
  118979. 1, -531365888, 1611661312, 4, 0,
  118980. _vq_quantlist__44c7_s_p5_1,
  118981. NULL,
  118982. &_vq_auxt__44c7_s_p5_1,
  118983. NULL,
  118984. 0
  118985. };
  118986. static long _vq_quantlist__44c7_s_p6_0[] = {
  118987. 6,
  118988. 5,
  118989. 7,
  118990. 4,
  118991. 8,
  118992. 3,
  118993. 9,
  118994. 2,
  118995. 10,
  118996. 1,
  118997. 11,
  118998. 0,
  118999. 12,
  119000. };
  119001. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119002. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119003. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119004. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119005. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119006. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119007. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119012. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119013. };
  119014. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119015. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119016. 12.5, 17.5, 22.5, 27.5,
  119017. };
  119018. static long _vq_quantmap__44c7_s_p6_0[] = {
  119019. 11, 9, 7, 5, 3, 1, 0, 2,
  119020. 4, 6, 8, 10, 12,
  119021. };
  119022. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119023. _vq_quantthresh__44c7_s_p6_0,
  119024. _vq_quantmap__44c7_s_p6_0,
  119025. 13,
  119026. 13
  119027. };
  119028. static static_codebook _44c7_s_p6_0 = {
  119029. 2, 169,
  119030. _vq_lengthlist__44c7_s_p6_0,
  119031. 1, -526516224, 1616117760, 4, 0,
  119032. _vq_quantlist__44c7_s_p6_0,
  119033. NULL,
  119034. &_vq_auxt__44c7_s_p6_0,
  119035. NULL,
  119036. 0
  119037. };
  119038. static long _vq_quantlist__44c7_s_p6_1[] = {
  119039. 2,
  119040. 1,
  119041. 3,
  119042. 0,
  119043. 4,
  119044. };
  119045. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119046. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119047. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119048. };
  119049. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119050. -1.5, -0.5, 0.5, 1.5,
  119051. };
  119052. static long _vq_quantmap__44c7_s_p6_1[] = {
  119053. 3, 1, 0, 2, 4,
  119054. };
  119055. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119056. _vq_quantthresh__44c7_s_p6_1,
  119057. _vq_quantmap__44c7_s_p6_1,
  119058. 5,
  119059. 5
  119060. };
  119061. static static_codebook _44c7_s_p6_1 = {
  119062. 2, 25,
  119063. _vq_lengthlist__44c7_s_p6_1,
  119064. 1, -533725184, 1611661312, 3, 0,
  119065. _vq_quantlist__44c7_s_p6_1,
  119066. NULL,
  119067. &_vq_auxt__44c7_s_p6_1,
  119068. NULL,
  119069. 0
  119070. };
  119071. static long _vq_quantlist__44c7_s_p7_0[] = {
  119072. 6,
  119073. 5,
  119074. 7,
  119075. 4,
  119076. 8,
  119077. 3,
  119078. 9,
  119079. 2,
  119080. 10,
  119081. 1,
  119082. 11,
  119083. 0,
  119084. 12,
  119085. };
  119086. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119087. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119088. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119089. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119090. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119091. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119092. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119093. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119094. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119095. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119096. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119097. 19,13,13,13,13,14,14,15,15,
  119098. };
  119099. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119100. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119101. 27.5, 38.5, 49.5, 60.5,
  119102. };
  119103. static long _vq_quantmap__44c7_s_p7_0[] = {
  119104. 11, 9, 7, 5, 3, 1, 0, 2,
  119105. 4, 6, 8, 10, 12,
  119106. };
  119107. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119108. _vq_quantthresh__44c7_s_p7_0,
  119109. _vq_quantmap__44c7_s_p7_0,
  119110. 13,
  119111. 13
  119112. };
  119113. static static_codebook _44c7_s_p7_0 = {
  119114. 2, 169,
  119115. _vq_lengthlist__44c7_s_p7_0,
  119116. 1, -523206656, 1618345984, 4, 0,
  119117. _vq_quantlist__44c7_s_p7_0,
  119118. NULL,
  119119. &_vq_auxt__44c7_s_p7_0,
  119120. NULL,
  119121. 0
  119122. };
  119123. static long _vq_quantlist__44c7_s_p7_1[] = {
  119124. 5,
  119125. 4,
  119126. 6,
  119127. 3,
  119128. 7,
  119129. 2,
  119130. 8,
  119131. 1,
  119132. 9,
  119133. 0,
  119134. 10,
  119135. };
  119136. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119137. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119138. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119139. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119140. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119141. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119142. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119143. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119144. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119145. };
  119146. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119147. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119148. 3.5, 4.5,
  119149. };
  119150. static long _vq_quantmap__44c7_s_p7_1[] = {
  119151. 9, 7, 5, 3, 1, 0, 2, 4,
  119152. 6, 8, 10,
  119153. };
  119154. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119155. _vq_quantthresh__44c7_s_p7_1,
  119156. _vq_quantmap__44c7_s_p7_1,
  119157. 11,
  119158. 11
  119159. };
  119160. static static_codebook _44c7_s_p7_1 = {
  119161. 2, 121,
  119162. _vq_lengthlist__44c7_s_p7_1,
  119163. 1, -531365888, 1611661312, 4, 0,
  119164. _vq_quantlist__44c7_s_p7_1,
  119165. NULL,
  119166. &_vq_auxt__44c7_s_p7_1,
  119167. NULL,
  119168. 0
  119169. };
  119170. static long _vq_quantlist__44c7_s_p8_0[] = {
  119171. 7,
  119172. 6,
  119173. 8,
  119174. 5,
  119175. 9,
  119176. 4,
  119177. 10,
  119178. 3,
  119179. 11,
  119180. 2,
  119181. 12,
  119182. 1,
  119183. 13,
  119184. 0,
  119185. 14,
  119186. };
  119187. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119188. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119189. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119190. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119191. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119192. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119193. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119194. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119195. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119196. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119197. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119198. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119199. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119200. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119201. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119202. 14,
  119203. };
  119204. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119205. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119206. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119207. };
  119208. static long _vq_quantmap__44c7_s_p8_0[] = {
  119209. 13, 11, 9, 7, 5, 3, 1, 0,
  119210. 2, 4, 6, 8, 10, 12, 14,
  119211. };
  119212. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119213. _vq_quantthresh__44c7_s_p8_0,
  119214. _vq_quantmap__44c7_s_p8_0,
  119215. 15,
  119216. 15
  119217. };
  119218. static static_codebook _44c7_s_p8_0 = {
  119219. 2, 225,
  119220. _vq_lengthlist__44c7_s_p8_0,
  119221. 1, -520986624, 1620377600, 4, 0,
  119222. _vq_quantlist__44c7_s_p8_0,
  119223. NULL,
  119224. &_vq_auxt__44c7_s_p8_0,
  119225. NULL,
  119226. 0
  119227. };
  119228. static long _vq_quantlist__44c7_s_p8_1[] = {
  119229. 10,
  119230. 9,
  119231. 11,
  119232. 8,
  119233. 12,
  119234. 7,
  119235. 13,
  119236. 6,
  119237. 14,
  119238. 5,
  119239. 15,
  119240. 4,
  119241. 16,
  119242. 3,
  119243. 17,
  119244. 2,
  119245. 18,
  119246. 1,
  119247. 19,
  119248. 0,
  119249. 20,
  119250. };
  119251. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119252. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119253. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119254. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119255. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119256. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119257. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119258. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119259. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119260. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119261. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119262. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119263. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119264. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119265. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119266. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119267. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119268. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119269. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119270. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119271. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119272. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119273. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119274. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119275. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119276. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119277. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119278. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119279. 10,10,10,10,10,10,10,10,10,
  119280. };
  119281. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119282. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119283. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119284. 6.5, 7.5, 8.5, 9.5,
  119285. };
  119286. static long _vq_quantmap__44c7_s_p8_1[] = {
  119287. 19, 17, 15, 13, 11, 9, 7, 5,
  119288. 3, 1, 0, 2, 4, 6, 8, 10,
  119289. 12, 14, 16, 18, 20,
  119290. };
  119291. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119292. _vq_quantthresh__44c7_s_p8_1,
  119293. _vq_quantmap__44c7_s_p8_1,
  119294. 21,
  119295. 21
  119296. };
  119297. static static_codebook _44c7_s_p8_1 = {
  119298. 2, 441,
  119299. _vq_lengthlist__44c7_s_p8_1,
  119300. 1, -529268736, 1611661312, 5, 0,
  119301. _vq_quantlist__44c7_s_p8_1,
  119302. NULL,
  119303. &_vq_auxt__44c7_s_p8_1,
  119304. NULL,
  119305. 0
  119306. };
  119307. static long _vq_quantlist__44c7_s_p9_0[] = {
  119308. 6,
  119309. 5,
  119310. 7,
  119311. 4,
  119312. 8,
  119313. 3,
  119314. 9,
  119315. 2,
  119316. 10,
  119317. 1,
  119318. 11,
  119319. 0,
  119320. 12,
  119321. };
  119322. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119323. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119324. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119325. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119326. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119327. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119328. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119329. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119330. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119331. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119332. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119333. 11,11,11,11,11,11,11,11,11,
  119334. };
  119335. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119336. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119337. 1592.5, 2229.5, 2866.5, 3503.5,
  119338. };
  119339. static long _vq_quantmap__44c7_s_p9_0[] = {
  119340. 11, 9, 7, 5, 3, 1, 0, 2,
  119341. 4, 6, 8, 10, 12,
  119342. };
  119343. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119344. _vq_quantthresh__44c7_s_p9_0,
  119345. _vq_quantmap__44c7_s_p9_0,
  119346. 13,
  119347. 13
  119348. };
  119349. static static_codebook _44c7_s_p9_0 = {
  119350. 2, 169,
  119351. _vq_lengthlist__44c7_s_p9_0,
  119352. 1, -511845376, 1630791680, 4, 0,
  119353. _vq_quantlist__44c7_s_p9_0,
  119354. NULL,
  119355. &_vq_auxt__44c7_s_p9_0,
  119356. NULL,
  119357. 0
  119358. };
  119359. static long _vq_quantlist__44c7_s_p9_1[] = {
  119360. 6,
  119361. 5,
  119362. 7,
  119363. 4,
  119364. 8,
  119365. 3,
  119366. 9,
  119367. 2,
  119368. 10,
  119369. 1,
  119370. 11,
  119371. 0,
  119372. 12,
  119373. };
  119374. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119375. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119376. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119377. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119378. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119379. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119380. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119381. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119382. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119383. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119384. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119385. 15,11,11,10,10,12,12,12,12,
  119386. };
  119387. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119388. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119389. 122.5, 171.5, 220.5, 269.5,
  119390. };
  119391. static long _vq_quantmap__44c7_s_p9_1[] = {
  119392. 11, 9, 7, 5, 3, 1, 0, 2,
  119393. 4, 6, 8, 10, 12,
  119394. };
  119395. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119396. _vq_quantthresh__44c7_s_p9_1,
  119397. _vq_quantmap__44c7_s_p9_1,
  119398. 13,
  119399. 13
  119400. };
  119401. static static_codebook _44c7_s_p9_1 = {
  119402. 2, 169,
  119403. _vq_lengthlist__44c7_s_p9_1,
  119404. 1, -518889472, 1622704128, 4, 0,
  119405. _vq_quantlist__44c7_s_p9_1,
  119406. NULL,
  119407. &_vq_auxt__44c7_s_p9_1,
  119408. NULL,
  119409. 0
  119410. };
  119411. static long _vq_quantlist__44c7_s_p9_2[] = {
  119412. 24,
  119413. 23,
  119414. 25,
  119415. 22,
  119416. 26,
  119417. 21,
  119418. 27,
  119419. 20,
  119420. 28,
  119421. 19,
  119422. 29,
  119423. 18,
  119424. 30,
  119425. 17,
  119426. 31,
  119427. 16,
  119428. 32,
  119429. 15,
  119430. 33,
  119431. 14,
  119432. 34,
  119433. 13,
  119434. 35,
  119435. 12,
  119436. 36,
  119437. 11,
  119438. 37,
  119439. 10,
  119440. 38,
  119441. 9,
  119442. 39,
  119443. 8,
  119444. 40,
  119445. 7,
  119446. 41,
  119447. 6,
  119448. 42,
  119449. 5,
  119450. 43,
  119451. 4,
  119452. 44,
  119453. 3,
  119454. 45,
  119455. 2,
  119456. 46,
  119457. 1,
  119458. 47,
  119459. 0,
  119460. 48,
  119461. };
  119462. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119463. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119464. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119465. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119466. 7,
  119467. };
  119468. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119469. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119470. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119471. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119472. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119473. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119474. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119475. };
  119476. static long _vq_quantmap__44c7_s_p9_2[] = {
  119477. 47, 45, 43, 41, 39, 37, 35, 33,
  119478. 31, 29, 27, 25, 23, 21, 19, 17,
  119479. 15, 13, 11, 9, 7, 5, 3, 1,
  119480. 0, 2, 4, 6, 8, 10, 12, 14,
  119481. 16, 18, 20, 22, 24, 26, 28, 30,
  119482. 32, 34, 36, 38, 40, 42, 44, 46,
  119483. 48,
  119484. };
  119485. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119486. _vq_quantthresh__44c7_s_p9_2,
  119487. _vq_quantmap__44c7_s_p9_2,
  119488. 49,
  119489. 49
  119490. };
  119491. static static_codebook _44c7_s_p9_2 = {
  119492. 1, 49,
  119493. _vq_lengthlist__44c7_s_p9_2,
  119494. 1, -526909440, 1611661312, 6, 0,
  119495. _vq_quantlist__44c7_s_p9_2,
  119496. NULL,
  119497. &_vq_auxt__44c7_s_p9_2,
  119498. NULL,
  119499. 0
  119500. };
  119501. static long _huff_lengthlist__44c7_s_short[] = {
  119502. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119503. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119504. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119505. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119506. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119507. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119508. 10, 9,11,14,
  119509. };
  119510. static static_codebook _huff_book__44c7_s_short = {
  119511. 2, 100,
  119512. _huff_lengthlist__44c7_s_short,
  119513. 0, 0, 0, 0, 0,
  119514. NULL,
  119515. NULL,
  119516. NULL,
  119517. NULL,
  119518. 0
  119519. };
  119520. static long _huff_lengthlist__44c8_s_long[] = {
  119521. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119522. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119523. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119524. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119525. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119526. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119527. 11, 9, 9,10,
  119528. };
  119529. static static_codebook _huff_book__44c8_s_long = {
  119530. 2, 100,
  119531. _huff_lengthlist__44c8_s_long,
  119532. 0, 0, 0, 0, 0,
  119533. NULL,
  119534. NULL,
  119535. NULL,
  119536. NULL,
  119537. 0
  119538. };
  119539. static long _vq_quantlist__44c8_s_p1_0[] = {
  119540. 1,
  119541. 0,
  119542. 2,
  119543. };
  119544. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119545. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119546. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119547. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119548. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119549. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119550. 8,
  119551. };
  119552. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119553. -0.5, 0.5,
  119554. };
  119555. static long _vq_quantmap__44c8_s_p1_0[] = {
  119556. 1, 0, 2,
  119557. };
  119558. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119559. _vq_quantthresh__44c8_s_p1_0,
  119560. _vq_quantmap__44c8_s_p1_0,
  119561. 3,
  119562. 3
  119563. };
  119564. static static_codebook _44c8_s_p1_0 = {
  119565. 4, 81,
  119566. _vq_lengthlist__44c8_s_p1_0,
  119567. 1, -535822336, 1611661312, 2, 0,
  119568. _vq_quantlist__44c8_s_p1_0,
  119569. NULL,
  119570. &_vq_auxt__44c8_s_p1_0,
  119571. NULL,
  119572. 0
  119573. };
  119574. static long _vq_quantlist__44c8_s_p2_0[] = {
  119575. 2,
  119576. 1,
  119577. 3,
  119578. 0,
  119579. 4,
  119580. };
  119581. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119582. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119583. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119584. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119585. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119586. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119587. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119588. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119589. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119591. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119592. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119593. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119594. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119595. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119596. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119597. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119599. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119600. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119601. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119602. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119603. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119604. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119605. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119607. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119608. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119609. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119610. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119611. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119612. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119613. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119618. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119619. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119620. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119621. 13,
  119622. };
  119623. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119624. -1.5, -0.5, 0.5, 1.5,
  119625. };
  119626. static long _vq_quantmap__44c8_s_p2_0[] = {
  119627. 3, 1, 0, 2, 4,
  119628. };
  119629. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119630. _vq_quantthresh__44c8_s_p2_0,
  119631. _vq_quantmap__44c8_s_p2_0,
  119632. 5,
  119633. 5
  119634. };
  119635. static static_codebook _44c8_s_p2_0 = {
  119636. 4, 625,
  119637. _vq_lengthlist__44c8_s_p2_0,
  119638. 1, -533725184, 1611661312, 3, 0,
  119639. _vq_quantlist__44c8_s_p2_0,
  119640. NULL,
  119641. &_vq_auxt__44c8_s_p2_0,
  119642. NULL,
  119643. 0
  119644. };
  119645. static long _vq_quantlist__44c8_s_p3_0[] = {
  119646. 4,
  119647. 3,
  119648. 5,
  119649. 2,
  119650. 6,
  119651. 1,
  119652. 7,
  119653. 0,
  119654. 8,
  119655. };
  119656. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119657. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119658. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119659. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119660. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119662. 0,
  119663. };
  119664. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119665. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119666. };
  119667. static long _vq_quantmap__44c8_s_p3_0[] = {
  119668. 7, 5, 3, 1, 0, 2, 4, 6,
  119669. 8,
  119670. };
  119671. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119672. _vq_quantthresh__44c8_s_p3_0,
  119673. _vq_quantmap__44c8_s_p3_0,
  119674. 9,
  119675. 9
  119676. };
  119677. static static_codebook _44c8_s_p3_0 = {
  119678. 2, 81,
  119679. _vq_lengthlist__44c8_s_p3_0,
  119680. 1, -531628032, 1611661312, 4, 0,
  119681. _vq_quantlist__44c8_s_p3_0,
  119682. NULL,
  119683. &_vq_auxt__44c8_s_p3_0,
  119684. NULL,
  119685. 0
  119686. };
  119687. static long _vq_quantlist__44c8_s_p4_0[] = {
  119688. 8,
  119689. 7,
  119690. 9,
  119691. 6,
  119692. 10,
  119693. 5,
  119694. 11,
  119695. 4,
  119696. 12,
  119697. 3,
  119698. 13,
  119699. 2,
  119700. 14,
  119701. 1,
  119702. 15,
  119703. 0,
  119704. 16,
  119705. };
  119706. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119707. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119708. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119709. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119710. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119711. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119712. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119713. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119714. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119715. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119716. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119725. 0,
  119726. };
  119727. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119728. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119729. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119730. };
  119731. static long _vq_quantmap__44c8_s_p4_0[] = {
  119732. 15, 13, 11, 9, 7, 5, 3, 1,
  119733. 0, 2, 4, 6, 8, 10, 12, 14,
  119734. 16,
  119735. };
  119736. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119737. _vq_quantthresh__44c8_s_p4_0,
  119738. _vq_quantmap__44c8_s_p4_0,
  119739. 17,
  119740. 17
  119741. };
  119742. static static_codebook _44c8_s_p4_0 = {
  119743. 2, 289,
  119744. _vq_lengthlist__44c8_s_p4_0,
  119745. 1, -529530880, 1611661312, 5, 0,
  119746. _vq_quantlist__44c8_s_p4_0,
  119747. NULL,
  119748. &_vq_auxt__44c8_s_p4_0,
  119749. NULL,
  119750. 0
  119751. };
  119752. static long _vq_quantlist__44c8_s_p5_0[] = {
  119753. 1,
  119754. 0,
  119755. 2,
  119756. };
  119757. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119758. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119759. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119760. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119761. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119762. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119763. 12,
  119764. };
  119765. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119766. -5.5, 5.5,
  119767. };
  119768. static long _vq_quantmap__44c8_s_p5_0[] = {
  119769. 1, 0, 2,
  119770. };
  119771. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119772. _vq_quantthresh__44c8_s_p5_0,
  119773. _vq_quantmap__44c8_s_p5_0,
  119774. 3,
  119775. 3
  119776. };
  119777. static static_codebook _44c8_s_p5_0 = {
  119778. 4, 81,
  119779. _vq_lengthlist__44c8_s_p5_0,
  119780. 1, -529137664, 1618345984, 2, 0,
  119781. _vq_quantlist__44c8_s_p5_0,
  119782. NULL,
  119783. &_vq_auxt__44c8_s_p5_0,
  119784. NULL,
  119785. 0
  119786. };
  119787. static long _vq_quantlist__44c8_s_p5_1[] = {
  119788. 5,
  119789. 4,
  119790. 6,
  119791. 3,
  119792. 7,
  119793. 2,
  119794. 8,
  119795. 1,
  119796. 9,
  119797. 0,
  119798. 10,
  119799. };
  119800. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119801. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119802. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119803. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119804. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119805. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119806. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119807. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119808. 11,11,11, 7, 7, 7, 7, 8, 8,
  119809. };
  119810. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119811. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119812. 3.5, 4.5,
  119813. };
  119814. static long _vq_quantmap__44c8_s_p5_1[] = {
  119815. 9, 7, 5, 3, 1, 0, 2, 4,
  119816. 6, 8, 10,
  119817. };
  119818. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119819. _vq_quantthresh__44c8_s_p5_1,
  119820. _vq_quantmap__44c8_s_p5_1,
  119821. 11,
  119822. 11
  119823. };
  119824. static static_codebook _44c8_s_p5_1 = {
  119825. 2, 121,
  119826. _vq_lengthlist__44c8_s_p5_1,
  119827. 1, -531365888, 1611661312, 4, 0,
  119828. _vq_quantlist__44c8_s_p5_1,
  119829. NULL,
  119830. &_vq_auxt__44c8_s_p5_1,
  119831. NULL,
  119832. 0
  119833. };
  119834. static long _vq_quantlist__44c8_s_p6_0[] = {
  119835. 6,
  119836. 5,
  119837. 7,
  119838. 4,
  119839. 8,
  119840. 3,
  119841. 9,
  119842. 2,
  119843. 10,
  119844. 1,
  119845. 11,
  119846. 0,
  119847. 12,
  119848. };
  119849. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119850. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119851. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119852. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119853. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119854. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119855. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119860. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119861. };
  119862. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119863. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119864. 12.5, 17.5, 22.5, 27.5,
  119865. };
  119866. static long _vq_quantmap__44c8_s_p6_0[] = {
  119867. 11, 9, 7, 5, 3, 1, 0, 2,
  119868. 4, 6, 8, 10, 12,
  119869. };
  119870. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119871. _vq_quantthresh__44c8_s_p6_0,
  119872. _vq_quantmap__44c8_s_p6_0,
  119873. 13,
  119874. 13
  119875. };
  119876. static static_codebook _44c8_s_p6_0 = {
  119877. 2, 169,
  119878. _vq_lengthlist__44c8_s_p6_0,
  119879. 1, -526516224, 1616117760, 4, 0,
  119880. _vq_quantlist__44c8_s_p6_0,
  119881. NULL,
  119882. &_vq_auxt__44c8_s_p6_0,
  119883. NULL,
  119884. 0
  119885. };
  119886. static long _vq_quantlist__44c8_s_p6_1[] = {
  119887. 2,
  119888. 1,
  119889. 3,
  119890. 0,
  119891. 4,
  119892. };
  119893. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119894. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119895. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119896. };
  119897. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119898. -1.5, -0.5, 0.5, 1.5,
  119899. };
  119900. static long _vq_quantmap__44c8_s_p6_1[] = {
  119901. 3, 1, 0, 2, 4,
  119902. };
  119903. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119904. _vq_quantthresh__44c8_s_p6_1,
  119905. _vq_quantmap__44c8_s_p6_1,
  119906. 5,
  119907. 5
  119908. };
  119909. static static_codebook _44c8_s_p6_1 = {
  119910. 2, 25,
  119911. _vq_lengthlist__44c8_s_p6_1,
  119912. 1, -533725184, 1611661312, 3, 0,
  119913. _vq_quantlist__44c8_s_p6_1,
  119914. NULL,
  119915. &_vq_auxt__44c8_s_p6_1,
  119916. NULL,
  119917. 0
  119918. };
  119919. static long _vq_quantlist__44c8_s_p7_0[] = {
  119920. 6,
  119921. 5,
  119922. 7,
  119923. 4,
  119924. 8,
  119925. 3,
  119926. 9,
  119927. 2,
  119928. 10,
  119929. 1,
  119930. 11,
  119931. 0,
  119932. 12,
  119933. };
  119934. static long _vq_lengthlist__44c8_s_p7_0[] = {
  119935. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  119936. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119937. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  119938. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  119939. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  119940. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  119941. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  119942. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  119943. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  119944. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  119945. 20,13,13,13,13,14,13,15,15,
  119946. };
  119947. static float _vq_quantthresh__44c8_s_p7_0[] = {
  119948. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119949. 27.5, 38.5, 49.5, 60.5,
  119950. };
  119951. static long _vq_quantmap__44c8_s_p7_0[] = {
  119952. 11, 9, 7, 5, 3, 1, 0, 2,
  119953. 4, 6, 8, 10, 12,
  119954. };
  119955. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  119956. _vq_quantthresh__44c8_s_p7_0,
  119957. _vq_quantmap__44c8_s_p7_0,
  119958. 13,
  119959. 13
  119960. };
  119961. static static_codebook _44c8_s_p7_0 = {
  119962. 2, 169,
  119963. _vq_lengthlist__44c8_s_p7_0,
  119964. 1, -523206656, 1618345984, 4, 0,
  119965. _vq_quantlist__44c8_s_p7_0,
  119966. NULL,
  119967. &_vq_auxt__44c8_s_p7_0,
  119968. NULL,
  119969. 0
  119970. };
  119971. static long _vq_quantlist__44c8_s_p7_1[] = {
  119972. 5,
  119973. 4,
  119974. 6,
  119975. 3,
  119976. 7,
  119977. 2,
  119978. 8,
  119979. 1,
  119980. 9,
  119981. 0,
  119982. 10,
  119983. };
  119984. static long _vq_lengthlist__44c8_s_p7_1[] = {
  119985. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  119986. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  119987. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119988. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119989. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119990. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119991. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119992. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119993. };
  119994. static float _vq_quantthresh__44c8_s_p7_1[] = {
  119995. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119996. 3.5, 4.5,
  119997. };
  119998. static long _vq_quantmap__44c8_s_p7_1[] = {
  119999. 9, 7, 5, 3, 1, 0, 2, 4,
  120000. 6, 8, 10,
  120001. };
  120002. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120003. _vq_quantthresh__44c8_s_p7_1,
  120004. _vq_quantmap__44c8_s_p7_1,
  120005. 11,
  120006. 11
  120007. };
  120008. static static_codebook _44c8_s_p7_1 = {
  120009. 2, 121,
  120010. _vq_lengthlist__44c8_s_p7_1,
  120011. 1, -531365888, 1611661312, 4, 0,
  120012. _vq_quantlist__44c8_s_p7_1,
  120013. NULL,
  120014. &_vq_auxt__44c8_s_p7_1,
  120015. NULL,
  120016. 0
  120017. };
  120018. static long _vq_quantlist__44c8_s_p8_0[] = {
  120019. 7,
  120020. 6,
  120021. 8,
  120022. 5,
  120023. 9,
  120024. 4,
  120025. 10,
  120026. 3,
  120027. 11,
  120028. 2,
  120029. 12,
  120030. 1,
  120031. 13,
  120032. 0,
  120033. 14,
  120034. };
  120035. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120036. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120037. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120038. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120039. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120040. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120041. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120042. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120043. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120044. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120045. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120046. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120047. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120048. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120049. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120050. 15,
  120051. };
  120052. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120053. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120054. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120055. };
  120056. static long _vq_quantmap__44c8_s_p8_0[] = {
  120057. 13, 11, 9, 7, 5, 3, 1, 0,
  120058. 2, 4, 6, 8, 10, 12, 14,
  120059. };
  120060. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120061. _vq_quantthresh__44c8_s_p8_0,
  120062. _vq_quantmap__44c8_s_p8_0,
  120063. 15,
  120064. 15
  120065. };
  120066. static static_codebook _44c8_s_p8_0 = {
  120067. 2, 225,
  120068. _vq_lengthlist__44c8_s_p8_0,
  120069. 1, -520986624, 1620377600, 4, 0,
  120070. _vq_quantlist__44c8_s_p8_0,
  120071. NULL,
  120072. &_vq_auxt__44c8_s_p8_0,
  120073. NULL,
  120074. 0
  120075. };
  120076. static long _vq_quantlist__44c8_s_p8_1[] = {
  120077. 10,
  120078. 9,
  120079. 11,
  120080. 8,
  120081. 12,
  120082. 7,
  120083. 13,
  120084. 6,
  120085. 14,
  120086. 5,
  120087. 15,
  120088. 4,
  120089. 16,
  120090. 3,
  120091. 17,
  120092. 2,
  120093. 18,
  120094. 1,
  120095. 19,
  120096. 0,
  120097. 20,
  120098. };
  120099. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120100. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120101. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120102. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120103. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120104. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120105. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120106. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120107. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120108. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120109. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120110. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120111. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120112. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120113. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120114. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120115. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120116. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120117. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120118. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120119. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120120. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120121. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120122. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120123. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120124. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120125. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120126. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120127. 10, 9, 9,10,10, 9,10, 9, 9,
  120128. };
  120129. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120130. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120131. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120132. 6.5, 7.5, 8.5, 9.5,
  120133. };
  120134. static long _vq_quantmap__44c8_s_p8_1[] = {
  120135. 19, 17, 15, 13, 11, 9, 7, 5,
  120136. 3, 1, 0, 2, 4, 6, 8, 10,
  120137. 12, 14, 16, 18, 20,
  120138. };
  120139. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120140. _vq_quantthresh__44c8_s_p8_1,
  120141. _vq_quantmap__44c8_s_p8_1,
  120142. 21,
  120143. 21
  120144. };
  120145. static static_codebook _44c8_s_p8_1 = {
  120146. 2, 441,
  120147. _vq_lengthlist__44c8_s_p8_1,
  120148. 1, -529268736, 1611661312, 5, 0,
  120149. _vq_quantlist__44c8_s_p8_1,
  120150. NULL,
  120151. &_vq_auxt__44c8_s_p8_1,
  120152. NULL,
  120153. 0
  120154. };
  120155. static long _vq_quantlist__44c8_s_p9_0[] = {
  120156. 8,
  120157. 7,
  120158. 9,
  120159. 6,
  120160. 10,
  120161. 5,
  120162. 11,
  120163. 4,
  120164. 12,
  120165. 3,
  120166. 13,
  120167. 2,
  120168. 14,
  120169. 1,
  120170. 15,
  120171. 0,
  120172. 16,
  120173. };
  120174. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120175. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120176. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120177. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120181. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120182. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120183. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120184. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120185. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120186. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120187. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120188. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120189. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120190. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120191. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120192. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120193. 10,
  120194. };
  120195. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120196. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120197. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120198. };
  120199. static long _vq_quantmap__44c8_s_p9_0[] = {
  120200. 15, 13, 11, 9, 7, 5, 3, 1,
  120201. 0, 2, 4, 6, 8, 10, 12, 14,
  120202. 16,
  120203. };
  120204. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120205. _vq_quantthresh__44c8_s_p9_0,
  120206. _vq_quantmap__44c8_s_p9_0,
  120207. 17,
  120208. 17
  120209. };
  120210. static static_codebook _44c8_s_p9_0 = {
  120211. 2, 289,
  120212. _vq_lengthlist__44c8_s_p9_0,
  120213. 1, -509798400, 1631393792, 5, 0,
  120214. _vq_quantlist__44c8_s_p9_0,
  120215. NULL,
  120216. &_vq_auxt__44c8_s_p9_0,
  120217. NULL,
  120218. 0
  120219. };
  120220. static long _vq_quantlist__44c8_s_p9_1[] = {
  120221. 9,
  120222. 8,
  120223. 10,
  120224. 7,
  120225. 11,
  120226. 6,
  120227. 12,
  120228. 5,
  120229. 13,
  120230. 4,
  120231. 14,
  120232. 3,
  120233. 15,
  120234. 2,
  120235. 16,
  120236. 1,
  120237. 17,
  120238. 0,
  120239. 18,
  120240. };
  120241. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120242. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120243. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120244. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120245. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120246. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120247. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120248. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120249. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120250. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120251. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120252. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120253. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120254. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120255. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120256. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120257. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120258. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120259. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120260. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120261. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120262. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120263. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120264. 14,13,13,14,14,15,14,15,14,
  120265. };
  120266. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120267. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120268. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120269. 367.5, 416.5,
  120270. };
  120271. static long _vq_quantmap__44c8_s_p9_1[] = {
  120272. 17, 15, 13, 11, 9, 7, 5, 3,
  120273. 1, 0, 2, 4, 6, 8, 10, 12,
  120274. 14, 16, 18,
  120275. };
  120276. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120277. _vq_quantthresh__44c8_s_p9_1,
  120278. _vq_quantmap__44c8_s_p9_1,
  120279. 19,
  120280. 19
  120281. };
  120282. static static_codebook _44c8_s_p9_1 = {
  120283. 2, 361,
  120284. _vq_lengthlist__44c8_s_p9_1,
  120285. 1, -518287360, 1622704128, 5, 0,
  120286. _vq_quantlist__44c8_s_p9_1,
  120287. NULL,
  120288. &_vq_auxt__44c8_s_p9_1,
  120289. NULL,
  120290. 0
  120291. };
  120292. static long _vq_quantlist__44c8_s_p9_2[] = {
  120293. 24,
  120294. 23,
  120295. 25,
  120296. 22,
  120297. 26,
  120298. 21,
  120299. 27,
  120300. 20,
  120301. 28,
  120302. 19,
  120303. 29,
  120304. 18,
  120305. 30,
  120306. 17,
  120307. 31,
  120308. 16,
  120309. 32,
  120310. 15,
  120311. 33,
  120312. 14,
  120313. 34,
  120314. 13,
  120315. 35,
  120316. 12,
  120317. 36,
  120318. 11,
  120319. 37,
  120320. 10,
  120321. 38,
  120322. 9,
  120323. 39,
  120324. 8,
  120325. 40,
  120326. 7,
  120327. 41,
  120328. 6,
  120329. 42,
  120330. 5,
  120331. 43,
  120332. 4,
  120333. 44,
  120334. 3,
  120335. 45,
  120336. 2,
  120337. 46,
  120338. 1,
  120339. 47,
  120340. 0,
  120341. 48,
  120342. };
  120343. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120344. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120345. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120346. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120347. 7,
  120348. };
  120349. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120350. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120351. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120352. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120353. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120354. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120355. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120356. };
  120357. static long _vq_quantmap__44c8_s_p9_2[] = {
  120358. 47, 45, 43, 41, 39, 37, 35, 33,
  120359. 31, 29, 27, 25, 23, 21, 19, 17,
  120360. 15, 13, 11, 9, 7, 5, 3, 1,
  120361. 0, 2, 4, 6, 8, 10, 12, 14,
  120362. 16, 18, 20, 22, 24, 26, 28, 30,
  120363. 32, 34, 36, 38, 40, 42, 44, 46,
  120364. 48,
  120365. };
  120366. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120367. _vq_quantthresh__44c8_s_p9_2,
  120368. _vq_quantmap__44c8_s_p9_2,
  120369. 49,
  120370. 49
  120371. };
  120372. static static_codebook _44c8_s_p9_2 = {
  120373. 1, 49,
  120374. _vq_lengthlist__44c8_s_p9_2,
  120375. 1, -526909440, 1611661312, 6, 0,
  120376. _vq_quantlist__44c8_s_p9_2,
  120377. NULL,
  120378. &_vq_auxt__44c8_s_p9_2,
  120379. NULL,
  120380. 0
  120381. };
  120382. static long _huff_lengthlist__44c8_s_short[] = {
  120383. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120384. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120385. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120386. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120387. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120388. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120389. 10, 9,11,14,
  120390. };
  120391. static static_codebook _huff_book__44c8_s_short = {
  120392. 2, 100,
  120393. _huff_lengthlist__44c8_s_short,
  120394. 0, 0, 0, 0, 0,
  120395. NULL,
  120396. NULL,
  120397. NULL,
  120398. NULL,
  120399. 0
  120400. };
  120401. static long _huff_lengthlist__44c9_s_long[] = {
  120402. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120403. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120404. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120405. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120406. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120407. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120408. 10, 9, 8, 9,
  120409. };
  120410. static static_codebook _huff_book__44c9_s_long = {
  120411. 2, 100,
  120412. _huff_lengthlist__44c9_s_long,
  120413. 0, 0, 0, 0, 0,
  120414. NULL,
  120415. NULL,
  120416. NULL,
  120417. NULL,
  120418. 0
  120419. };
  120420. static long _vq_quantlist__44c9_s_p1_0[] = {
  120421. 1,
  120422. 0,
  120423. 2,
  120424. };
  120425. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120426. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120427. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120428. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120429. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120430. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120431. 7,
  120432. };
  120433. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120434. -0.5, 0.5,
  120435. };
  120436. static long _vq_quantmap__44c9_s_p1_0[] = {
  120437. 1, 0, 2,
  120438. };
  120439. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120440. _vq_quantthresh__44c9_s_p1_0,
  120441. _vq_quantmap__44c9_s_p1_0,
  120442. 3,
  120443. 3
  120444. };
  120445. static static_codebook _44c9_s_p1_0 = {
  120446. 4, 81,
  120447. _vq_lengthlist__44c9_s_p1_0,
  120448. 1, -535822336, 1611661312, 2, 0,
  120449. _vq_quantlist__44c9_s_p1_0,
  120450. NULL,
  120451. &_vq_auxt__44c9_s_p1_0,
  120452. NULL,
  120453. 0
  120454. };
  120455. static long _vq_quantlist__44c9_s_p2_0[] = {
  120456. 2,
  120457. 1,
  120458. 3,
  120459. 0,
  120460. 4,
  120461. };
  120462. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120463. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120464. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120465. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120466. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120467. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120468. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120469. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120470. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120472. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120473. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120474. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120475. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120476. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120477. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120478. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120480. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120481. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120482. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120483. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120484. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120485. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120486. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120488. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120489. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120490. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120491. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120492. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120493. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120494. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120499. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120500. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120501. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120502. 12,
  120503. };
  120504. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120505. -1.5, -0.5, 0.5, 1.5,
  120506. };
  120507. static long _vq_quantmap__44c9_s_p2_0[] = {
  120508. 3, 1, 0, 2, 4,
  120509. };
  120510. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120511. _vq_quantthresh__44c9_s_p2_0,
  120512. _vq_quantmap__44c9_s_p2_0,
  120513. 5,
  120514. 5
  120515. };
  120516. static static_codebook _44c9_s_p2_0 = {
  120517. 4, 625,
  120518. _vq_lengthlist__44c9_s_p2_0,
  120519. 1, -533725184, 1611661312, 3, 0,
  120520. _vq_quantlist__44c9_s_p2_0,
  120521. NULL,
  120522. &_vq_auxt__44c9_s_p2_0,
  120523. NULL,
  120524. 0
  120525. };
  120526. static long _vq_quantlist__44c9_s_p3_0[] = {
  120527. 4,
  120528. 3,
  120529. 5,
  120530. 2,
  120531. 6,
  120532. 1,
  120533. 7,
  120534. 0,
  120535. 8,
  120536. };
  120537. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120538. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120539. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120540. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120541. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120543. 0,
  120544. };
  120545. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120546. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120547. };
  120548. static long _vq_quantmap__44c9_s_p3_0[] = {
  120549. 7, 5, 3, 1, 0, 2, 4, 6,
  120550. 8,
  120551. };
  120552. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120553. _vq_quantthresh__44c9_s_p3_0,
  120554. _vq_quantmap__44c9_s_p3_0,
  120555. 9,
  120556. 9
  120557. };
  120558. static static_codebook _44c9_s_p3_0 = {
  120559. 2, 81,
  120560. _vq_lengthlist__44c9_s_p3_0,
  120561. 1, -531628032, 1611661312, 4, 0,
  120562. _vq_quantlist__44c9_s_p3_0,
  120563. NULL,
  120564. &_vq_auxt__44c9_s_p3_0,
  120565. NULL,
  120566. 0
  120567. };
  120568. static long _vq_quantlist__44c9_s_p4_0[] = {
  120569. 8,
  120570. 7,
  120571. 9,
  120572. 6,
  120573. 10,
  120574. 5,
  120575. 11,
  120576. 4,
  120577. 12,
  120578. 3,
  120579. 13,
  120580. 2,
  120581. 14,
  120582. 1,
  120583. 15,
  120584. 0,
  120585. 16,
  120586. };
  120587. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120588. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120589. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120590. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120591. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120592. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120593. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120594. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120595. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120596. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120597. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120606. 0,
  120607. };
  120608. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120609. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120610. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120611. };
  120612. static long _vq_quantmap__44c9_s_p4_0[] = {
  120613. 15, 13, 11, 9, 7, 5, 3, 1,
  120614. 0, 2, 4, 6, 8, 10, 12, 14,
  120615. 16,
  120616. };
  120617. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120618. _vq_quantthresh__44c9_s_p4_0,
  120619. _vq_quantmap__44c9_s_p4_0,
  120620. 17,
  120621. 17
  120622. };
  120623. static static_codebook _44c9_s_p4_0 = {
  120624. 2, 289,
  120625. _vq_lengthlist__44c9_s_p4_0,
  120626. 1, -529530880, 1611661312, 5, 0,
  120627. _vq_quantlist__44c9_s_p4_0,
  120628. NULL,
  120629. &_vq_auxt__44c9_s_p4_0,
  120630. NULL,
  120631. 0
  120632. };
  120633. static long _vq_quantlist__44c9_s_p5_0[] = {
  120634. 1,
  120635. 0,
  120636. 2,
  120637. };
  120638. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120639. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120640. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120641. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120642. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120643. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120644. 12,
  120645. };
  120646. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120647. -5.5, 5.5,
  120648. };
  120649. static long _vq_quantmap__44c9_s_p5_0[] = {
  120650. 1, 0, 2,
  120651. };
  120652. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120653. _vq_quantthresh__44c9_s_p5_0,
  120654. _vq_quantmap__44c9_s_p5_0,
  120655. 3,
  120656. 3
  120657. };
  120658. static static_codebook _44c9_s_p5_0 = {
  120659. 4, 81,
  120660. _vq_lengthlist__44c9_s_p5_0,
  120661. 1, -529137664, 1618345984, 2, 0,
  120662. _vq_quantlist__44c9_s_p5_0,
  120663. NULL,
  120664. &_vq_auxt__44c9_s_p5_0,
  120665. NULL,
  120666. 0
  120667. };
  120668. static long _vq_quantlist__44c9_s_p5_1[] = {
  120669. 5,
  120670. 4,
  120671. 6,
  120672. 3,
  120673. 7,
  120674. 2,
  120675. 8,
  120676. 1,
  120677. 9,
  120678. 0,
  120679. 10,
  120680. };
  120681. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120682. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120683. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120684. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120685. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120686. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120687. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120688. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120689. 11,11,11, 7, 7, 7, 7, 7, 7,
  120690. };
  120691. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120692. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120693. 3.5, 4.5,
  120694. };
  120695. static long _vq_quantmap__44c9_s_p5_1[] = {
  120696. 9, 7, 5, 3, 1, 0, 2, 4,
  120697. 6, 8, 10,
  120698. };
  120699. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120700. _vq_quantthresh__44c9_s_p5_1,
  120701. _vq_quantmap__44c9_s_p5_1,
  120702. 11,
  120703. 11
  120704. };
  120705. static static_codebook _44c9_s_p5_1 = {
  120706. 2, 121,
  120707. _vq_lengthlist__44c9_s_p5_1,
  120708. 1, -531365888, 1611661312, 4, 0,
  120709. _vq_quantlist__44c9_s_p5_1,
  120710. NULL,
  120711. &_vq_auxt__44c9_s_p5_1,
  120712. NULL,
  120713. 0
  120714. };
  120715. static long _vq_quantlist__44c9_s_p6_0[] = {
  120716. 6,
  120717. 5,
  120718. 7,
  120719. 4,
  120720. 8,
  120721. 3,
  120722. 9,
  120723. 2,
  120724. 10,
  120725. 1,
  120726. 11,
  120727. 0,
  120728. 12,
  120729. };
  120730. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120731. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120732. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120733. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120734. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120735. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120736. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120741. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120742. };
  120743. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120744. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120745. 12.5, 17.5, 22.5, 27.5,
  120746. };
  120747. static long _vq_quantmap__44c9_s_p6_0[] = {
  120748. 11, 9, 7, 5, 3, 1, 0, 2,
  120749. 4, 6, 8, 10, 12,
  120750. };
  120751. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120752. _vq_quantthresh__44c9_s_p6_0,
  120753. _vq_quantmap__44c9_s_p6_0,
  120754. 13,
  120755. 13
  120756. };
  120757. static static_codebook _44c9_s_p6_0 = {
  120758. 2, 169,
  120759. _vq_lengthlist__44c9_s_p6_0,
  120760. 1, -526516224, 1616117760, 4, 0,
  120761. _vq_quantlist__44c9_s_p6_0,
  120762. NULL,
  120763. &_vq_auxt__44c9_s_p6_0,
  120764. NULL,
  120765. 0
  120766. };
  120767. static long _vq_quantlist__44c9_s_p6_1[] = {
  120768. 2,
  120769. 1,
  120770. 3,
  120771. 0,
  120772. 4,
  120773. };
  120774. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120775. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120776. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120777. };
  120778. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120779. -1.5, -0.5, 0.5, 1.5,
  120780. };
  120781. static long _vq_quantmap__44c9_s_p6_1[] = {
  120782. 3, 1, 0, 2, 4,
  120783. };
  120784. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120785. _vq_quantthresh__44c9_s_p6_1,
  120786. _vq_quantmap__44c9_s_p6_1,
  120787. 5,
  120788. 5
  120789. };
  120790. static static_codebook _44c9_s_p6_1 = {
  120791. 2, 25,
  120792. _vq_lengthlist__44c9_s_p6_1,
  120793. 1, -533725184, 1611661312, 3, 0,
  120794. _vq_quantlist__44c9_s_p6_1,
  120795. NULL,
  120796. &_vq_auxt__44c9_s_p6_1,
  120797. NULL,
  120798. 0
  120799. };
  120800. static long _vq_quantlist__44c9_s_p7_0[] = {
  120801. 6,
  120802. 5,
  120803. 7,
  120804. 4,
  120805. 8,
  120806. 3,
  120807. 9,
  120808. 2,
  120809. 10,
  120810. 1,
  120811. 11,
  120812. 0,
  120813. 12,
  120814. };
  120815. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120816. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120817. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120818. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120819. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120820. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120821. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120822. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120823. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120824. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120825. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120826. 19,12,12,12,12,13,13,14,14,
  120827. };
  120828. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120829. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120830. 27.5, 38.5, 49.5, 60.5,
  120831. };
  120832. static long _vq_quantmap__44c9_s_p7_0[] = {
  120833. 11, 9, 7, 5, 3, 1, 0, 2,
  120834. 4, 6, 8, 10, 12,
  120835. };
  120836. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120837. _vq_quantthresh__44c9_s_p7_0,
  120838. _vq_quantmap__44c9_s_p7_0,
  120839. 13,
  120840. 13
  120841. };
  120842. static static_codebook _44c9_s_p7_0 = {
  120843. 2, 169,
  120844. _vq_lengthlist__44c9_s_p7_0,
  120845. 1, -523206656, 1618345984, 4, 0,
  120846. _vq_quantlist__44c9_s_p7_0,
  120847. NULL,
  120848. &_vq_auxt__44c9_s_p7_0,
  120849. NULL,
  120850. 0
  120851. };
  120852. static long _vq_quantlist__44c9_s_p7_1[] = {
  120853. 5,
  120854. 4,
  120855. 6,
  120856. 3,
  120857. 7,
  120858. 2,
  120859. 8,
  120860. 1,
  120861. 9,
  120862. 0,
  120863. 10,
  120864. };
  120865. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120866. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120867. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120868. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120869. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120870. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120871. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120872. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120873. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120874. };
  120875. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120876. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120877. 3.5, 4.5,
  120878. };
  120879. static long _vq_quantmap__44c9_s_p7_1[] = {
  120880. 9, 7, 5, 3, 1, 0, 2, 4,
  120881. 6, 8, 10,
  120882. };
  120883. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120884. _vq_quantthresh__44c9_s_p7_1,
  120885. _vq_quantmap__44c9_s_p7_1,
  120886. 11,
  120887. 11
  120888. };
  120889. static static_codebook _44c9_s_p7_1 = {
  120890. 2, 121,
  120891. _vq_lengthlist__44c9_s_p7_1,
  120892. 1, -531365888, 1611661312, 4, 0,
  120893. _vq_quantlist__44c9_s_p7_1,
  120894. NULL,
  120895. &_vq_auxt__44c9_s_p7_1,
  120896. NULL,
  120897. 0
  120898. };
  120899. static long _vq_quantlist__44c9_s_p8_0[] = {
  120900. 7,
  120901. 6,
  120902. 8,
  120903. 5,
  120904. 9,
  120905. 4,
  120906. 10,
  120907. 3,
  120908. 11,
  120909. 2,
  120910. 12,
  120911. 1,
  120912. 13,
  120913. 0,
  120914. 14,
  120915. };
  120916. static long _vq_lengthlist__44c9_s_p8_0[] = {
  120917. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  120918. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  120919. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  120920. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  120921. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  120922. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  120923. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  120924. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  120925. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  120926. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  120927. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  120928. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  120929. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  120930. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  120931. 14,
  120932. };
  120933. static float _vq_quantthresh__44c9_s_p8_0[] = {
  120934. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120935. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120936. };
  120937. static long _vq_quantmap__44c9_s_p8_0[] = {
  120938. 13, 11, 9, 7, 5, 3, 1, 0,
  120939. 2, 4, 6, 8, 10, 12, 14,
  120940. };
  120941. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  120942. _vq_quantthresh__44c9_s_p8_0,
  120943. _vq_quantmap__44c9_s_p8_0,
  120944. 15,
  120945. 15
  120946. };
  120947. static static_codebook _44c9_s_p8_0 = {
  120948. 2, 225,
  120949. _vq_lengthlist__44c9_s_p8_0,
  120950. 1, -520986624, 1620377600, 4, 0,
  120951. _vq_quantlist__44c9_s_p8_0,
  120952. NULL,
  120953. &_vq_auxt__44c9_s_p8_0,
  120954. NULL,
  120955. 0
  120956. };
  120957. static long _vq_quantlist__44c9_s_p8_1[] = {
  120958. 10,
  120959. 9,
  120960. 11,
  120961. 8,
  120962. 12,
  120963. 7,
  120964. 13,
  120965. 6,
  120966. 14,
  120967. 5,
  120968. 15,
  120969. 4,
  120970. 16,
  120971. 3,
  120972. 17,
  120973. 2,
  120974. 18,
  120975. 1,
  120976. 19,
  120977. 0,
  120978. 20,
  120979. };
  120980. static long _vq_lengthlist__44c9_s_p8_1[] = {
  120981. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120982. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120983. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120984. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120985. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120986. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120987. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  120988. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120989. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120990. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120991. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120992. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120993. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120994. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120995. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120996. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  120997. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  120998. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  120999. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121000. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121001. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121002. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121003. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121004. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121005. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121006. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121007. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121008. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121009. };
  121010. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121011. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121012. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121013. 6.5, 7.5, 8.5, 9.5,
  121014. };
  121015. static long _vq_quantmap__44c9_s_p8_1[] = {
  121016. 19, 17, 15, 13, 11, 9, 7, 5,
  121017. 3, 1, 0, 2, 4, 6, 8, 10,
  121018. 12, 14, 16, 18, 20,
  121019. };
  121020. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121021. _vq_quantthresh__44c9_s_p8_1,
  121022. _vq_quantmap__44c9_s_p8_1,
  121023. 21,
  121024. 21
  121025. };
  121026. static static_codebook _44c9_s_p8_1 = {
  121027. 2, 441,
  121028. _vq_lengthlist__44c9_s_p8_1,
  121029. 1, -529268736, 1611661312, 5, 0,
  121030. _vq_quantlist__44c9_s_p8_1,
  121031. NULL,
  121032. &_vq_auxt__44c9_s_p8_1,
  121033. NULL,
  121034. 0
  121035. };
  121036. static long _vq_quantlist__44c9_s_p9_0[] = {
  121037. 9,
  121038. 8,
  121039. 10,
  121040. 7,
  121041. 11,
  121042. 6,
  121043. 12,
  121044. 5,
  121045. 13,
  121046. 4,
  121047. 14,
  121048. 3,
  121049. 15,
  121050. 2,
  121051. 16,
  121052. 1,
  121053. 17,
  121054. 0,
  121055. 18,
  121056. };
  121057. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121058. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121059. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121060. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121061. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121062. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121063. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121064. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121065. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121066. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121067. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121068. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121069. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121070. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121071. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121072. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121073. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121074. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121075. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121076. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121077. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121078. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121079. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121080. 11,11,11,11,11,11,11,11,11,
  121081. };
  121082. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121083. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121084. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121085. 6982.5, 7913.5,
  121086. };
  121087. static long _vq_quantmap__44c9_s_p9_0[] = {
  121088. 17, 15, 13, 11, 9, 7, 5, 3,
  121089. 1, 0, 2, 4, 6, 8, 10, 12,
  121090. 14, 16, 18,
  121091. };
  121092. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121093. _vq_quantthresh__44c9_s_p9_0,
  121094. _vq_quantmap__44c9_s_p9_0,
  121095. 19,
  121096. 19
  121097. };
  121098. static static_codebook _44c9_s_p9_0 = {
  121099. 2, 361,
  121100. _vq_lengthlist__44c9_s_p9_0,
  121101. 1, -508535424, 1631393792, 5, 0,
  121102. _vq_quantlist__44c9_s_p9_0,
  121103. NULL,
  121104. &_vq_auxt__44c9_s_p9_0,
  121105. NULL,
  121106. 0
  121107. };
  121108. static long _vq_quantlist__44c9_s_p9_1[] = {
  121109. 9,
  121110. 8,
  121111. 10,
  121112. 7,
  121113. 11,
  121114. 6,
  121115. 12,
  121116. 5,
  121117. 13,
  121118. 4,
  121119. 14,
  121120. 3,
  121121. 15,
  121122. 2,
  121123. 16,
  121124. 1,
  121125. 17,
  121126. 0,
  121127. 18,
  121128. };
  121129. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121130. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121131. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121132. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121133. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121134. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121135. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121136. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121137. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121138. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121139. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121140. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121141. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121142. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121143. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121144. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121145. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121146. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121147. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121148. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121149. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121150. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121151. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121152. 13,13,13,14,13,14,15,15,15,
  121153. };
  121154. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121155. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121156. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121157. 367.5, 416.5,
  121158. };
  121159. static long _vq_quantmap__44c9_s_p9_1[] = {
  121160. 17, 15, 13, 11, 9, 7, 5, 3,
  121161. 1, 0, 2, 4, 6, 8, 10, 12,
  121162. 14, 16, 18,
  121163. };
  121164. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121165. _vq_quantthresh__44c9_s_p9_1,
  121166. _vq_quantmap__44c9_s_p9_1,
  121167. 19,
  121168. 19
  121169. };
  121170. static static_codebook _44c9_s_p9_1 = {
  121171. 2, 361,
  121172. _vq_lengthlist__44c9_s_p9_1,
  121173. 1, -518287360, 1622704128, 5, 0,
  121174. _vq_quantlist__44c9_s_p9_1,
  121175. NULL,
  121176. &_vq_auxt__44c9_s_p9_1,
  121177. NULL,
  121178. 0
  121179. };
  121180. static long _vq_quantlist__44c9_s_p9_2[] = {
  121181. 24,
  121182. 23,
  121183. 25,
  121184. 22,
  121185. 26,
  121186. 21,
  121187. 27,
  121188. 20,
  121189. 28,
  121190. 19,
  121191. 29,
  121192. 18,
  121193. 30,
  121194. 17,
  121195. 31,
  121196. 16,
  121197. 32,
  121198. 15,
  121199. 33,
  121200. 14,
  121201. 34,
  121202. 13,
  121203. 35,
  121204. 12,
  121205. 36,
  121206. 11,
  121207. 37,
  121208. 10,
  121209. 38,
  121210. 9,
  121211. 39,
  121212. 8,
  121213. 40,
  121214. 7,
  121215. 41,
  121216. 6,
  121217. 42,
  121218. 5,
  121219. 43,
  121220. 4,
  121221. 44,
  121222. 3,
  121223. 45,
  121224. 2,
  121225. 46,
  121226. 1,
  121227. 47,
  121228. 0,
  121229. 48,
  121230. };
  121231. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121232. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121233. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121234. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121235. 7,
  121236. };
  121237. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121238. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121239. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121240. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121241. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121242. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121243. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121244. };
  121245. static long _vq_quantmap__44c9_s_p9_2[] = {
  121246. 47, 45, 43, 41, 39, 37, 35, 33,
  121247. 31, 29, 27, 25, 23, 21, 19, 17,
  121248. 15, 13, 11, 9, 7, 5, 3, 1,
  121249. 0, 2, 4, 6, 8, 10, 12, 14,
  121250. 16, 18, 20, 22, 24, 26, 28, 30,
  121251. 32, 34, 36, 38, 40, 42, 44, 46,
  121252. 48,
  121253. };
  121254. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121255. _vq_quantthresh__44c9_s_p9_2,
  121256. _vq_quantmap__44c9_s_p9_2,
  121257. 49,
  121258. 49
  121259. };
  121260. static static_codebook _44c9_s_p9_2 = {
  121261. 1, 49,
  121262. _vq_lengthlist__44c9_s_p9_2,
  121263. 1, -526909440, 1611661312, 6, 0,
  121264. _vq_quantlist__44c9_s_p9_2,
  121265. NULL,
  121266. &_vq_auxt__44c9_s_p9_2,
  121267. NULL,
  121268. 0
  121269. };
  121270. static long _huff_lengthlist__44c9_s_short[] = {
  121271. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121272. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121273. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121274. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121275. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121276. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121277. 9, 8,10,13,
  121278. };
  121279. static static_codebook _huff_book__44c9_s_short = {
  121280. 2, 100,
  121281. _huff_lengthlist__44c9_s_short,
  121282. 0, 0, 0, 0, 0,
  121283. NULL,
  121284. NULL,
  121285. NULL,
  121286. NULL,
  121287. 0
  121288. };
  121289. static long _huff_lengthlist__44c0_s_long[] = {
  121290. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121291. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121292. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121293. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121294. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121295. 12,
  121296. };
  121297. static static_codebook _huff_book__44c0_s_long = {
  121298. 2, 81,
  121299. _huff_lengthlist__44c0_s_long,
  121300. 0, 0, 0, 0, 0,
  121301. NULL,
  121302. NULL,
  121303. NULL,
  121304. NULL,
  121305. 0
  121306. };
  121307. static long _vq_quantlist__44c0_s_p1_0[] = {
  121308. 1,
  121309. 0,
  121310. 2,
  121311. };
  121312. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121313. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121314. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121318. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121319. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121323. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121324. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121359. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121364. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121369. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121382. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121387. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121392. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121405. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121410. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121415. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0,
  121427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  121432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  121437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  121724. };
  121725. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121726. -0.5, 0.5,
  121727. };
  121728. static long _vq_quantmap__44c0_s_p1_0[] = {
  121729. 1, 0, 2,
  121730. };
  121731. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121732. _vq_quantthresh__44c0_s_p1_0,
  121733. _vq_quantmap__44c0_s_p1_0,
  121734. 3,
  121735. 3
  121736. };
  121737. static static_codebook _44c0_s_p1_0 = {
  121738. 8, 6561,
  121739. _vq_lengthlist__44c0_s_p1_0,
  121740. 1, -535822336, 1611661312, 2, 0,
  121741. _vq_quantlist__44c0_s_p1_0,
  121742. NULL,
  121743. &_vq_auxt__44c0_s_p1_0,
  121744. NULL,
  121745. 0
  121746. };
  121747. static long _vq_quantlist__44c0_s_p2_0[] = {
  121748. 2,
  121749. 1,
  121750. 3,
  121751. 0,
  121752. 4,
  121753. };
  121754. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121755. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0,
  121795. };
  121796. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121797. -1.5, -0.5, 0.5, 1.5,
  121798. };
  121799. static long _vq_quantmap__44c0_s_p2_0[] = {
  121800. 3, 1, 0, 2, 4,
  121801. };
  121802. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121803. _vq_quantthresh__44c0_s_p2_0,
  121804. _vq_quantmap__44c0_s_p2_0,
  121805. 5,
  121806. 5
  121807. };
  121808. static static_codebook _44c0_s_p2_0 = {
  121809. 4, 625,
  121810. _vq_lengthlist__44c0_s_p2_0,
  121811. 1, -533725184, 1611661312, 3, 0,
  121812. _vq_quantlist__44c0_s_p2_0,
  121813. NULL,
  121814. &_vq_auxt__44c0_s_p2_0,
  121815. NULL,
  121816. 0
  121817. };
  121818. static long _vq_quantlist__44c0_s_p3_0[] = {
  121819. 4,
  121820. 3,
  121821. 5,
  121822. 2,
  121823. 6,
  121824. 1,
  121825. 7,
  121826. 0,
  121827. 8,
  121828. };
  121829. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121830. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121831. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121832. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121833. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121834. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121835. 0,
  121836. };
  121837. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121838. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121839. };
  121840. static long _vq_quantmap__44c0_s_p3_0[] = {
  121841. 7, 5, 3, 1, 0, 2, 4, 6,
  121842. 8,
  121843. };
  121844. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121845. _vq_quantthresh__44c0_s_p3_0,
  121846. _vq_quantmap__44c0_s_p3_0,
  121847. 9,
  121848. 9
  121849. };
  121850. static static_codebook _44c0_s_p3_0 = {
  121851. 2, 81,
  121852. _vq_lengthlist__44c0_s_p3_0,
  121853. 1, -531628032, 1611661312, 4, 0,
  121854. _vq_quantlist__44c0_s_p3_0,
  121855. NULL,
  121856. &_vq_auxt__44c0_s_p3_0,
  121857. NULL,
  121858. 0
  121859. };
  121860. static long _vq_quantlist__44c0_s_p4_0[] = {
  121861. 4,
  121862. 3,
  121863. 5,
  121864. 2,
  121865. 6,
  121866. 1,
  121867. 7,
  121868. 0,
  121869. 8,
  121870. };
  121871. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121872. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121873. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121874. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121875. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121876. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121877. 10,
  121878. };
  121879. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121880. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121881. };
  121882. static long _vq_quantmap__44c0_s_p4_0[] = {
  121883. 7, 5, 3, 1, 0, 2, 4, 6,
  121884. 8,
  121885. };
  121886. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121887. _vq_quantthresh__44c0_s_p4_0,
  121888. _vq_quantmap__44c0_s_p4_0,
  121889. 9,
  121890. 9
  121891. };
  121892. static static_codebook _44c0_s_p4_0 = {
  121893. 2, 81,
  121894. _vq_lengthlist__44c0_s_p4_0,
  121895. 1, -531628032, 1611661312, 4, 0,
  121896. _vq_quantlist__44c0_s_p4_0,
  121897. NULL,
  121898. &_vq_auxt__44c0_s_p4_0,
  121899. NULL,
  121900. 0
  121901. };
  121902. static long _vq_quantlist__44c0_s_p5_0[] = {
  121903. 8,
  121904. 7,
  121905. 9,
  121906. 6,
  121907. 10,
  121908. 5,
  121909. 11,
  121910. 4,
  121911. 12,
  121912. 3,
  121913. 13,
  121914. 2,
  121915. 14,
  121916. 1,
  121917. 15,
  121918. 0,
  121919. 16,
  121920. };
  121921. static long _vq_lengthlist__44c0_s_p5_0[] = {
  121922. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  121923. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  121924. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  121925. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  121926. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  121927. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  121928. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  121929. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  121930. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  121931. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  121932. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  121933. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  121934. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  121935. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  121936. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  121937. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  121938. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  121940. 14,
  121941. };
  121942. static float _vq_quantthresh__44c0_s_p5_0[] = {
  121943. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121944. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121945. };
  121946. static long _vq_quantmap__44c0_s_p5_0[] = {
  121947. 15, 13, 11, 9, 7, 5, 3, 1,
  121948. 0, 2, 4, 6, 8, 10, 12, 14,
  121949. 16,
  121950. };
  121951. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  121952. _vq_quantthresh__44c0_s_p5_0,
  121953. _vq_quantmap__44c0_s_p5_0,
  121954. 17,
  121955. 17
  121956. };
  121957. static static_codebook _44c0_s_p5_0 = {
  121958. 2, 289,
  121959. _vq_lengthlist__44c0_s_p5_0,
  121960. 1, -529530880, 1611661312, 5, 0,
  121961. _vq_quantlist__44c0_s_p5_0,
  121962. NULL,
  121963. &_vq_auxt__44c0_s_p5_0,
  121964. NULL,
  121965. 0
  121966. };
  121967. static long _vq_quantlist__44c0_s_p6_0[] = {
  121968. 1,
  121969. 0,
  121970. 2,
  121971. };
  121972. static long _vq_lengthlist__44c0_s_p6_0[] = {
  121973. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  121974. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  121975. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  121976. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  121977. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  121978. 10,
  121979. };
  121980. static float _vq_quantthresh__44c0_s_p6_0[] = {
  121981. -5.5, 5.5,
  121982. };
  121983. static long _vq_quantmap__44c0_s_p6_0[] = {
  121984. 1, 0, 2,
  121985. };
  121986. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  121987. _vq_quantthresh__44c0_s_p6_0,
  121988. _vq_quantmap__44c0_s_p6_0,
  121989. 3,
  121990. 3
  121991. };
  121992. static static_codebook _44c0_s_p6_0 = {
  121993. 4, 81,
  121994. _vq_lengthlist__44c0_s_p6_0,
  121995. 1, -529137664, 1618345984, 2, 0,
  121996. _vq_quantlist__44c0_s_p6_0,
  121997. NULL,
  121998. &_vq_auxt__44c0_s_p6_0,
  121999. NULL,
  122000. 0
  122001. };
  122002. static long _vq_quantlist__44c0_s_p6_1[] = {
  122003. 5,
  122004. 4,
  122005. 6,
  122006. 3,
  122007. 7,
  122008. 2,
  122009. 8,
  122010. 1,
  122011. 9,
  122012. 0,
  122013. 10,
  122014. };
  122015. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122016. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122017. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122018. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122019. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122020. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122021. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122022. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122023. 10,10,10, 8, 8, 8, 8, 8, 8,
  122024. };
  122025. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122026. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122027. 3.5, 4.5,
  122028. };
  122029. static long _vq_quantmap__44c0_s_p6_1[] = {
  122030. 9, 7, 5, 3, 1, 0, 2, 4,
  122031. 6, 8, 10,
  122032. };
  122033. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122034. _vq_quantthresh__44c0_s_p6_1,
  122035. _vq_quantmap__44c0_s_p6_1,
  122036. 11,
  122037. 11
  122038. };
  122039. static static_codebook _44c0_s_p6_1 = {
  122040. 2, 121,
  122041. _vq_lengthlist__44c0_s_p6_1,
  122042. 1, -531365888, 1611661312, 4, 0,
  122043. _vq_quantlist__44c0_s_p6_1,
  122044. NULL,
  122045. &_vq_auxt__44c0_s_p6_1,
  122046. NULL,
  122047. 0
  122048. };
  122049. static long _vq_quantlist__44c0_s_p7_0[] = {
  122050. 6,
  122051. 5,
  122052. 7,
  122053. 4,
  122054. 8,
  122055. 3,
  122056. 9,
  122057. 2,
  122058. 10,
  122059. 1,
  122060. 11,
  122061. 0,
  122062. 12,
  122063. };
  122064. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122065. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122066. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122067. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122068. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122069. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122070. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122071. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122072. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122073. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122074. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122075. 0,12,12,11,11,12,12,13,13,
  122076. };
  122077. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122078. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122079. 12.5, 17.5, 22.5, 27.5,
  122080. };
  122081. static long _vq_quantmap__44c0_s_p7_0[] = {
  122082. 11, 9, 7, 5, 3, 1, 0, 2,
  122083. 4, 6, 8, 10, 12,
  122084. };
  122085. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122086. _vq_quantthresh__44c0_s_p7_0,
  122087. _vq_quantmap__44c0_s_p7_0,
  122088. 13,
  122089. 13
  122090. };
  122091. static static_codebook _44c0_s_p7_0 = {
  122092. 2, 169,
  122093. _vq_lengthlist__44c0_s_p7_0,
  122094. 1, -526516224, 1616117760, 4, 0,
  122095. _vq_quantlist__44c0_s_p7_0,
  122096. NULL,
  122097. &_vq_auxt__44c0_s_p7_0,
  122098. NULL,
  122099. 0
  122100. };
  122101. static long _vq_quantlist__44c0_s_p7_1[] = {
  122102. 2,
  122103. 1,
  122104. 3,
  122105. 0,
  122106. 4,
  122107. };
  122108. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122109. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122110. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122111. };
  122112. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122113. -1.5, -0.5, 0.5, 1.5,
  122114. };
  122115. static long _vq_quantmap__44c0_s_p7_1[] = {
  122116. 3, 1, 0, 2, 4,
  122117. };
  122118. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122119. _vq_quantthresh__44c0_s_p7_1,
  122120. _vq_quantmap__44c0_s_p7_1,
  122121. 5,
  122122. 5
  122123. };
  122124. static static_codebook _44c0_s_p7_1 = {
  122125. 2, 25,
  122126. _vq_lengthlist__44c0_s_p7_1,
  122127. 1, -533725184, 1611661312, 3, 0,
  122128. _vq_quantlist__44c0_s_p7_1,
  122129. NULL,
  122130. &_vq_auxt__44c0_s_p7_1,
  122131. NULL,
  122132. 0
  122133. };
  122134. static long _vq_quantlist__44c0_s_p8_0[] = {
  122135. 2,
  122136. 1,
  122137. 3,
  122138. 0,
  122139. 4,
  122140. };
  122141. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122142. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122143. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122144. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122145. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122146. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122147. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122148. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122149. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122150. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122151. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122152. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122153. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122154. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122155. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122156. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122157. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122158. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122162. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122163. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122164. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122165. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122166. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122167. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122168. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122169. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122170. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122171. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122172. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122173. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122181. 11,
  122182. };
  122183. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122184. -331.5, -110.5, 110.5, 331.5,
  122185. };
  122186. static long _vq_quantmap__44c0_s_p8_0[] = {
  122187. 3, 1, 0, 2, 4,
  122188. };
  122189. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122190. _vq_quantthresh__44c0_s_p8_0,
  122191. _vq_quantmap__44c0_s_p8_0,
  122192. 5,
  122193. 5
  122194. };
  122195. static static_codebook _44c0_s_p8_0 = {
  122196. 4, 625,
  122197. _vq_lengthlist__44c0_s_p8_0,
  122198. 1, -518283264, 1627103232, 3, 0,
  122199. _vq_quantlist__44c0_s_p8_0,
  122200. NULL,
  122201. &_vq_auxt__44c0_s_p8_0,
  122202. NULL,
  122203. 0
  122204. };
  122205. static long _vq_quantlist__44c0_s_p8_1[] = {
  122206. 6,
  122207. 5,
  122208. 7,
  122209. 4,
  122210. 8,
  122211. 3,
  122212. 9,
  122213. 2,
  122214. 10,
  122215. 1,
  122216. 11,
  122217. 0,
  122218. 12,
  122219. };
  122220. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122221. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122222. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122223. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122224. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122225. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122226. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122227. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122228. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122229. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122230. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122231. 16,13,13,12,12,14,14,15,13,
  122232. };
  122233. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122234. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122235. 42.5, 59.5, 76.5, 93.5,
  122236. };
  122237. static long _vq_quantmap__44c0_s_p8_1[] = {
  122238. 11, 9, 7, 5, 3, 1, 0, 2,
  122239. 4, 6, 8, 10, 12,
  122240. };
  122241. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122242. _vq_quantthresh__44c0_s_p8_1,
  122243. _vq_quantmap__44c0_s_p8_1,
  122244. 13,
  122245. 13
  122246. };
  122247. static static_codebook _44c0_s_p8_1 = {
  122248. 2, 169,
  122249. _vq_lengthlist__44c0_s_p8_1,
  122250. 1, -522616832, 1620115456, 4, 0,
  122251. _vq_quantlist__44c0_s_p8_1,
  122252. NULL,
  122253. &_vq_auxt__44c0_s_p8_1,
  122254. NULL,
  122255. 0
  122256. };
  122257. static long _vq_quantlist__44c0_s_p8_2[] = {
  122258. 8,
  122259. 7,
  122260. 9,
  122261. 6,
  122262. 10,
  122263. 5,
  122264. 11,
  122265. 4,
  122266. 12,
  122267. 3,
  122268. 13,
  122269. 2,
  122270. 14,
  122271. 1,
  122272. 15,
  122273. 0,
  122274. 16,
  122275. };
  122276. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122277. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122278. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122279. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122280. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122281. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122282. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122283. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122284. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122285. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122286. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122287. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122288. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122289. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122290. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122291. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122292. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122293. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122294. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122295. 10,
  122296. };
  122297. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122298. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122299. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122300. };
  122301. static long _vq_quantmap__44c0_s_p8_2[] = {
  122302. 15, 13, 11, 9, 7, 5, 3, 1,
  122303. 0, 2, 4, 6, 8, 10, 12, 14,
  122304. 16,
  122305. };
  122306. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122307. _vq_quantthresh__44c0_s_p8_2,
  122308. _vq_quantmap__44c0_s_p8_2,
  122309. 17,
  122310. 17
  122311. };
  122312. static static_codebook _44c0_s_p8_2 = {
  122313. 2, 289,
  122314. _vq_lengthlist__44c0_s_p8_2,
  122315. 1, -529530880, 1611661312, 5, 0,
  122316. _vq_quantlist__44c0_s_p8_2,
  122317. NULL,
  122318. &_vq_auxt__44c0_s_p8_2,
  122319. NULL,
  122320. 0
  122321. };
  122322. static long _huff_lengthlist__44c0_s_short[] = {
  122323. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122324. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122325. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122326. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122327. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122328. 12,
  122329. };
  122330. static static_codebook _huff_book__44c0_s_short = {
  122331. 2, 81,
  122332. _huff_lengthlist__44c0_s_short,
  122333. 0, 0, 0, 0, 0,
  122334. NULL,
  122335. NULL,
  122336. NULL,
  122337. NULL,
  122338. 0
  122339. };
  122340. static long _huff_lengthlist__44c0_sm_long[] = {
  122341. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122342. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122343. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122344. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122345. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122346. 13,
  122347. };
  122348. static static_codebook _huff_book__44c0_sm_long = {
  122349. 2, 81,
  122350. _huff_lengthlist__44c0_sm_long,
  122351. 0, 0, 0, 0, 0,
  122352. NULL,
  122353. NULL,
  122354. NULL,
  122355. NULL,
  122356. 0
  122357. };
  122358. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122359. 1,
  122360. 0,
  122361. 2,
  122362. };
  122363. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122364. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122365. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122370. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122375. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122410. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122415. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122420. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122433. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122438. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122443. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122456. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122461. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122466. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  122775. };
  122776. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122777. -0.5, 0.5,
  122778. };
  122779. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122780. 1, 0, 2,
  122781. };
  122782. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122783. _vq_quantthresh__44c0_sm_p1_0,
  122784. _vq_quantmap__44c0_sm_p1_0,
  122785. 3,
  122786. 3
  122787. };
  122788. static static_codebook _44c0_sm_p1_0 = {
  122789. 8, 6561,
  122790. _vq_lengthlist__44c0_sm_p1_0,
  122791. 1, -535822336, 1611661312, 2, 0,
  122792. _vq_quantlist__44c0_sm_p1_0,
  122793. NULL,
  122794. &_vq_auxt__44c0_sm_p1_0,
  122795. NULL,
  122796. 0
  122797. };
  122798. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122799. 2,
  122800. 1,
  122801. 3,
  122802. 0,
  122803. 4,
  122804. };
  122805. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122806. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0,
  122846. };
  122847. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122848. -1.5, -0.5, 0.5, 1.5,
  122849. };
  122850. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122851. 3, 1, 0, 2, 4,
  122852. };
  122853. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122854. _vq_quantthresh__44c0_sm_p2_0,
  122855. _vq_quantmap__44c0_sm_p2_0,
  122856. 5,
  122857. 5
  122858. };
  122859. static static_codebook _44c0_sm_p2_0 = {
  122860. 4, 625,
  122861. _vq_lengthlist__44c0_sm_p2_0,
  122862. 1, -533725184, 1611661312, 3, 0,
  122863. _vq_quantlist__44c0_sm_p2_0,
  122864. NULL,
  122865. &_vq_auxt__44c0_sm_p2_0,
  122866. NULL,
  122867. 0
  122868. };
  122869. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122870. 4,
  122871. 3,
  122872. 5,
  122873. 2,
  122874. 6,
  122875. 1,
  122876. 7,
  122877. 0,
  122878. 8,
  122879. };
  122880. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122881. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122882. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122883. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122884. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122885. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122886. 0,
  122887. };
  122888. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122889. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122890. };
  122891. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122892. 7, 5, 3, 1, 0, 2, 4, 6,
  122893. 8,
  122894. };
  122895. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122896. _vq_quantthresh__44c0_sm_p3_0,
  122897. _vq_quantmap__44c0_sm_p3_0,
  122898. 9,
  122899. 9
  122900. };
  122901. static static_codebook _44c0_sm_p3_0 = {
  122902. 2, 81,
  122903. _vq_lengthlist__44c0_sm_p3_0,
  122904. 1, -531628032, 1611661312, 4, 0,
  122905. _vq_quantlist__44c0_sm_p3_0,
  122906. NULL,
  122907. &_vq_auxt__44c0_sm_p3_0,
  122908. NULL,
  122909. 0
  122910. };
  122911. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122912. 4,
  122913. 3,
  122914. 5,
  122915. 2,
  122916. 6,
  122917. 1,
  122918. 7,
  122919. 0,
  122920. 8,
  122921. };
  122922. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  122923. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  122924. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  122925. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  122926. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  122927. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  122928. 11,
  122929. };
  122930. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  122931. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122932. };
  122933. static long _vq_quantmap__44c0_sm_p4_0[] = {
  122934. 7, 5, 3, 1, 0, 2, 4, 6,
  122935. 8,
  122936. };
  122937. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  122938. _vq_quantthresh__44c0_sm_p4_0,
  122939. _vq_quantmap__44c0_sm_p4_0,
  122940. 9,
  122941. 9
  122942. };
  122943. static static_codebook _44c0_sm_p4_0 = {
  122944. 2, 81,
  122945. _vq_lengthlist__44c0_sm_p4_0,
  122946. 1, -531628032, 1611661312, 4, 0,
  122947. _vq_quantlist__44c0_sm_p4_0,
  122948. NULL,
  122949. &_vq_auxt__44c0_sm_p4_0,
  122950. NULL,
  122951. 0
  122952. };
  122953. static long _vq_quantlist__44c0_sm_p5_0[] = {
  122954. 8,
  122955. 7,
  122956. 9,
  122957. 6,
  122958. 10,
  122959. 5,
  122960. 11,
  122961. 4,
  122962. 12,
  122963. 3,
  122964. 13,
  122965. 2,
  122966. 14,
  122967. 1,
  122968. 15,
  122969. 0,
  122970. 16,
  122971. };
  122972. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  122973. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  122974. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  122975. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122976. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  122977. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  122978. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  122979. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  122980. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122981. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  122982. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  122983. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122984. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122985. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  122986. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  122987. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  122988. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  122989. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122991. 14,
  122992. };
  122993. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  122994. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122995. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122996. };
  122997. static long _vq_quantmap__44c0_sm_p5_0[] = {
  122998. 15, 13, 11, 9, 7, 5, 3, 1,
  122999. 0, 2, 4, 6, 8, 10, 12, 14,
  123000. 16,
  123001. };
  123002. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123003. _vq_quantthresh__44c0_sm_p5_0,
  123004. _vq_quantmap__44c0_sm_p5_0,
  123005. 17,
  123006. 17
  123007. };
  123008. static static_codebook _44c0_sm_p5_0 = {
  123009. 2, 289,
  123010. _vq_lengthlist__44c0_sm_p5_0,
  123011. 1, -529530880, 1611661312, 5, 0,
  123012. _vq_quantlist__44c0_sm_p5_0,
  123013. NULL,
  123014. &_vq_auxt__44c0_sm_p5_0,
  123015. NULL,
  123016. 0
  123017. };
  123018. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123019. 1,
  123020. 0,
  123021. 2,
  123022. };
  123023. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123024. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123025. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123026. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123027. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123028. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123029. 11,
  123030. };
  123031. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123032. -5.5, 5.5,
  123033. };
  123034. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123035. 1, 0, 2,
  123036. };
  123037. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123038. _vq_quantthresh__44c0_sm_p6_0,
  123039. _vq_quantmap__44c0_sm_p6_0,
  123040. 3,
  123041. 3
  123042. };
  123043. static static_codebook _44c0_sm_p6_0 = {
  123044. 4, 81,
  123045. _vq_lengthlist__44c0_sm_p6_0,
  123046. 1, -529137664, 1618345984, 2, 0,
  123047. _vq_quantlist__44c0_sm_p6_0,
  123048. NULL,
  123049. &_vq_auxt__44c0_sm_p6_0,
  123050. NULL,
  123051. 0
  123052. };
  123053. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123054. 5,
  123055. 4,
  123056. 6,
  123057. 3,
  123058. 7,
  123059. 2,
  123060. 8,
  123061. 1,
  123062. 9,
  123063. 0,
  123064. 10,
  123065. };
  123066. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123067. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123068. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123069. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123070. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123071. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123072. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123073. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123074. 10,10,10, 8, 8, 8, 8, 8, 8,
  123075. };
  123076. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123077. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123078. 3.5, 4.5,
  123079. };
  123080. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123081. 9, 7, 5, 3, 1, 0, 2, 4,
  123082. 6, 8, 10,
  123083. };
  123084. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123085. _vq_quantthresh__44c0_sm_p6_1,
  123086. _vq_quantmap__44c0_sm_p6_1,
  123087. 11,
  123088. 11
  123089. };
  123090. static static_codebook _44c0_sm_p6_1 = {
  123091. 2, 121,
  123092. _vq_lengthlist__44c0_sm_p6_1,
  123093. 1, -531365888, 1611661312, 4, 0,
  123094. _vq_quantlist__44c0_sm_p6_1,
  123095. NULL,
  123096. &_vq_auxt__44c0_sm_p6_1,
  123097. NULL,
  123098. 0
  123099. };
  123100. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123101. 6,
  123102. 5,
  123103. 7,
  123104. 4,
  123105. 8,
  123106. 3,
  123107. 9,
  123108. 2,
  123109. 10,
  123110. 1,
  123111. 11,
  123112. 0,
  123113. 12,
  123114. };
  123115. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123116. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123117. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123118. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123119. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123120. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123121. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123122. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123123. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123124. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123125. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123126. 0,12,12,11,11,13,12,14,14,
  123127. };
  123128. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123129. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123130. 12.5, 17.5, 22.5, 27.5,
  123131. };
  123132. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123133. 11, 9, 7, 5, 3, 1, 0, 2,
  123134. 4, 6, 8, 10, 12,
  123135. };
  123136. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123137. _vq_quantthresh__44c0_sm_p7_0,
  123138. _vq_quantmap__44c0_sm_p7_0,
  123139. 13,
  123140. 13
  123141. };
  123142. static static_codebook _44c0_sm_p7_0 = {
  123143. 2, 169,
  123144. _vq_lengthlist__44c0_sm_p7_0,
  123145. 1, -526516224, 1616117760, 4, 0,
  123146. _vq_quantlist__44c0_sm_p7_0,
  123147. NULL,
  123148. &_vq_auxt__44c0_sm_p7_0,
  123149. NULL,
  123150. 0
  123151. };
  123152. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123153. 2,
  123154. 1,
  123155. 3,
  123156. 0,
  123157. 4,
  123158. };
  123159. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123160. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123161. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123162. };
  123163. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123164. -1.5, -0.5, 0.5, 1.5,
  123165. };
  123166. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123167. 3, 1, 0, 2, 4,
  123168. };
  123169. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123170. _vq_quantthresh__44c0_sm_p7_1,
  123171. _vq_quantmap__44c0_sm_p7_1,
  123172. 5,
  123173. 5
  123174. };
  123175. static static_codebook _44c0_sm_p7_1 = {
  123176. 2, 25,
  123177. _vq_lengthlist__44c0_sm_p7_1,
  123178. 1, -533725184, 1611661312, 3, 0,
  123179. _vq_quantlist__44c0_sm_p7_1,
  123180. NULL,
  123181. &_vq_auxt__44c0_sm_p7_1,
  123182. NULL,
  123183. 0
  123184. };
  123185. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123186. 4,
  123187. 3,
  123188. 5,
  123189. 2,
  123190. 6,
  123191. 1,
  123192. 7,
  123193. 0,
  123194. 8,
  123195. };
  123196. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123197. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123198. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123199. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123200. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123201. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123202. 12,
  123203. };
  123204. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123205. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123206. };
  123207. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123208. 7, 5, 3, 1, 0, 2, 4, 6,
  123209. 8,
  123210. };
  123211. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123212. _vq_quantthresh__44c0_sm_p8_0,
  123213. _vq_quantmap__44c0_sm_p8_0,
  123214. 9,
  123215. 9
  123216. };
  123217. static static_codebook _44c0_sm_p8_0 = {
  123218. 2, 81,
  123219. _vq_lengthlist__44c0_sm_p8_0,
  123220. 1, -516186112, 1627103232, 4, 0,
  123221. _vq_quantlist__44c0_sm_p8_0,
  123222. NULL,
  123223. &_vq_auxt__44c0_sm_p8_0,
  123224. NULL,
  123225. 0
  123226. };
  123227. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123228. 6,
  123229. 5,
  123230. 7,
  123231. 4,
  123232. 8,
  123233. 3,
  123234. 9,
  123235. 2,
  123236. 10,
  123237. 1,
  123238. 11,
  123239. 0,
  123240. 12,
  123241. };
  123242. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123243. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123244. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123245. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123246. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123247. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123248. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123249. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123250. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123251. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123252. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123253. 20,13,13,12,12,16,13,15,13,
  123254. };
  123255. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123256. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123257. 42.5, 59.5, 76.5, 93.5,
  123258. };
  123259. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123260. 11, 9, 7, 5, 3, 1, 0, 2,
  123261. 4, 6, 8, 10, 12,
  123262. };
  123263. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123264. _vq_quantthresh__44c0_sm_p8_1,
  123265. _vq_quantmap__44c0_sm_p8_1,
  123266. 13,
  123267. 13
  123268. };
  123269. static static_codebook _44c0_sm_p8_1 = {
  123270. 2, 169,
  123271. _vq_lengthlist__44c0_sm_p8_1,
  123272. 1, -522616832, 1620115456, 4, 0,
  123273. _vq_quantlist__44c0_sm_p8_1,
  123274. NULL,
  123275. &_vq_auxt__44c0_sm_p8_1,
  123276. NULL,
  123277. 0
  123278. };
  123279. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123280. 8,
  123281. 7,
  123282. 9,
  123283. 6,
  123284. 10,
  123285. 5,
  123286. 11,
  123287. 4,
  123288. 12,
  123289. 3,
  123290. 13,
  123291. 2,
  123292. 14,
  123293. 1,
  123294. 15,
  123295. 0,
  123296. 16,
  123297. };
  123298. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123299. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123300. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123301. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123302. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123303. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123304. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123305. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123306. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123307. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123308. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123309. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123310. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123311. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123312. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123313. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123314. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123315. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123316. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123317. 9,
  123318. };
  123319. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123320. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123321. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123322. };
  123323. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123324. 15, 13, 11, 9, 7, 5, 3, 1,
  123325. 0, 2, 4, 6, 8, 10, 12, 14,
  123326. 16,
  123327. };
  123328. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123329. _vq_quantthresh__44c0_sm_p8_2,
  123330. _vq_quantmap__44c0_sm_p8_2,
  123331. 17,
  123332. 17
  123333. };
  123334. static static_codebook _44c0_sm_p8_2 = {
  123335. 2, 289,
  123336. _vq_lengthlist__44c0_sm_p8_2,
  123337. 1, -529530880, 1611661312, 5, 0,
  123338. _vq_quantlist__44c0_sm_p8_2,
  123339. NULL,
  123340. &_vq_auxt__44c0_sm_p8_2,
  123341. NULL,
  123342. 0
  123343. };
  123344. static long _huff_lengthlist__44c0_sm_short[] = {
  123345. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123346. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123347. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123348. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123349. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123350. 12,
  123351. };
  123352. static static_codebook _huff_book__44c0_sm_short = {
  123353. 2, 81,
  123354. _huff_lengthlist__44c0_sm_short,
  123355. 0, 0, 0, 0, 0,
  123356. NULL,
  123357. NULL,
  123358. NULL,
  123359. NULL,
  123360. 0
  123361. };
  123362. static long _huff_lengthlist__44c1_s_long[] = {
  123363. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123364. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123365. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123366. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123367. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123368. 11,
  123369. };
  123370. static static_codebook _huff_book__44c1_s_long = {
  123371. 2, 81,
  123372. _huff_lengthlist__44c1_s_long,
  123373. 0, 0, 0, 0, 0,
  123374. NULL,
  123375. NULL,
  123376. NULL,
  123377. NULL,
  123378. 0
  123379. };
  123380. static long _vq_quantlist__44c1_s_p1_0[] = {
  123381. 1,
  123382. 0,
  123383. 2,
  123384. };
  123385. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123386. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123387. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123392. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123397. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123432. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123437. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123442. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123455. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123460. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123465. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123478. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123483. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123488. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  123797. };
  123798. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123799. -0.5, 0.5,
  123800. };
  123801. static long _vq_quantmap__44c1_s_p1_0[] = {
  123802. 1, 0, 2,
  123803. };
  123804. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123805. _vq_quantthresh__44c1_s_p1_0,
  123806. _vq_quantmap__44c1_s_p1_0,
  123807. 3,
  123808. 3
  123809. };
  123810. static static_codebook _44c1_s_p1_0 = {
  123811. 8, 6561,
  123812. _vq_lengthlist__44c1_s_p1_0,
  123813. 1, -535822336, 1611661312, 2, 0,
  123814. _vq_quantlist__44c1_s_p1_0,
  123815. NULL,
  123816. &_vq_auxt__44c1_s_p1_0,
  123817. NULL,
  123818. 0
  123819. };
  123820. static long _vq_quantlist__44c1_s_p2_0[] = {
  123821. 2,
  123822. 1,
  123823. 3,
  123824. 0,
  123825. 4,
  123826. };
  123827. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123828. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0,
  123868. };
  123869. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123870. -1.5, -0.5, 0.5, 1.5,
  123871. };
  123872. static long _vq_quantmap__44c1_s_p2_0[] = {
  123873. 3, 1, 0, 2, 4,
  123874. };
  123875. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123876. _vq_quantthresh__44c1_s_p2_0,
  123877. _vq_quantmap__44c1_s_p2_0,
  123878. 5,
  123879. 5
  123880. };
  123881. static static_codebook _44c1_s_p2_0 = {
  123882. 4, 625,
  123883. _vq_lengthlist__44c1_s_p2_0,
  123884. 1, -533725184, 1611661312, 3, 0,
  123885. _vq_quantlist__44c1_s_p2_0,
  123886. NULL,
  123887. &_vq_auxt__44c1_s_p2_0,
  123888. NULL,
  123889. 0
  123890. };
  123891. static long _vq_quantlist__44c1_s_p3_0[] = {
  123892. 4,
  123893. 3,
  123894. 5,
  123895. 2,
  123896. 6,
  123897. 1,
  123898. 7,
  123899. 0,
  123900. 8,
  123901. };
  123902. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123903. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123904. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123905. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123906. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123907. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123908. 0,
  123909. };
  123910. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123911. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123912. };
  123913. static long _vq_quantmap__44c1_s_p3_0[] = {
  123914. 7, 5, 3, 1, 0, 2, 4, 6,
  123915. 8,
  123916. };
  123917. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  123918. _vq_quantthresh__44c1_s_p3_0,
  123919. _vq_quantmap__44c1_s_p3_0,
  123920. 9,
  123921. 9
  123922. };
  123923. static static_codebook _44c1_s_p3_0 = {
  123924. 2, 81,
  123925. _vq_lengthlist__44c1_s_p3_0,
  123926. 1, -531628032, 1611661312, 4, 0,
  123927. _vq_quantlist__44c1_s_p3_0,
  123928. NULL,
  123929. &_vq_auxt__44c1_s_p3_0,
  123930. NULL,
  123931. 0
  123932. };
  123933. static long _vq_quantlist__44c1_s_p4_0[] = {
  123934. 4,
  123935. 3,
  123936. 5,
  123937. 2,
  123938. 6,
  123939. 1,
  123940. 7,
  123941. 0,
  123942. 8,
  123943. };
  123944. static long _vq_lengthlist__44c1_s_p4_0[] = {
  123945. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  123946. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  123947. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  123948. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  123949. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123950. 11,
  123951. };
  123952. static float _vq_quantthresh__44c1_s_p4_0[] = {
  123953. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123954. };
  123955. static long _vq_quantmap__44c1_s_p4_0[] = {
  123956. 7, 5, 3, 1, 0, 2, 4, 6,
  123957. 8,
  123958. };
  123959. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  123960. _vq_quantthresh__44c1_s_p4_0,
  123961. _vq_quantmap__44c1_s_p4_0,
  123962. 9,
  123963. 9
  123964. };
  123965. static static_codebook _44c1_s_p4_0 = {
  123966. 2, 81,
  123967. _vq_lengthlist__44c1_s_p4_0,
  123968. 1, -531628032, 1611661312, 4, 0,
  123969. _vq_quantlist__44c1_s_p4_0,
  123970. NULL,
  123971. &_vq_auxt__44c1_s_p4_0,
  123972. NULL,
  123973. 0
  123974. };
  123975. static long _vq_quantlist__44c1_s_p5_0[] = {
  123976. 8,
  123977. 7,
  123978. 9,
  123979. 6,
  123980. 10,
  123981. 5,
  123982. 11,
  123983. 4,
  123984. 12,
  123985. 3,
  123986. 13,
  123987. 2,
  123988. 14,
  123989. 1,
  123990. 15,
  123991. 0,
  123992. 16,
  123993. };
  123994. static long _vq_lengthlist__44c1_s_p5_0[] = {
  123995. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  123996. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  123997. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123998. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  123999. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124000. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124001. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124002. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124003. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124004. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124005. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124006. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124007. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124008. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124009. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124010. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124011. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124013. 14,
  124014. };
  124015. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124016. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124017. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124018. };
  124019. static long _vq_quantmap__44c1_s_p5_0[] = {
  124020. 15, 13, 11, 9, 7, 5, 3, 1,
  124021. 0, 2, 4, 6, 8, 10, 12, 14,
  124022. 16,
  124023. };
  124024. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124025. _vq_quantthresh__44c1_s_p5_0,
  124026. _vq_quantmap__44c1_s_p5_0,
  124027. 17,
  124028. 17
  124029. };
  124030. static static_codebook _44c1_s_p5_0 = {
  124031. 2, 289,
  124032. _vq_lengthlist__44c1_s_p5_0,
  124033. 1, -529530880, 1611661312, 5, 0,
  124034. _vq_quantlist__44c1_s_p5_0,
  124035. NULL,
  124036. &_vq_auxt__44c1_s_p5_0,
  124037. NULL,
  124038. 0
  124039. };
  124040. static long _vq_quantlist__44c1_s_p6_0[] = {
  124041. 1,
  124042. 0,
  124043. 2,
  124044. };
  124045. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124046. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124047. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124048. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124049. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124050. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124051. 11,
  124052. };
  124053. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124054. -5.5, 5.5,
  124055. };
  124056. static long _vq_quantmap__44c1_s_p6_0[] = {
  124057. 1, 0, 2,
  124058. };
  124059. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124060. _vq_quantthresh__44c1_s_p6_0,
  124061. _vq_quantmap__44c1_s_p6_0,
  124062. 3,
  124063. 3
  124064. };
  124065. static static_codebook _44c1_s_p6_0 = {
  124066. 4, 81,
  124067. _vq_lengthlist__44c1_s_p6_0,
  124068. 1, -529137664, 1618345984, 2, 0,
  124069. _vq_quantlist__44c1_s_p6_0,
  124070. NULL,
  124071. &_vq_auxt__44c1_s_p6_0,
  124072. NULL,
  124073. 0
  124074. };
  124075. static long _vq_quantlist__44c1_s_p6_1[] = {
  124076. 5,
  124077. 4,
  124078. 6,
  124079. 3,
  124080. 7,
  124081. 2,
  124082. 8,
  124083. 1,
  124084. 9,
  124085. 0,
  124086. 10,
  124087. };
  124088. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124089. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124090. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124091. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124092. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124093. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124094. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124095. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124096. 10,10,10, 8, 8, 8, 8, 8, 8,
  124097. };
  124098. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124099. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124100. 3.5, 4.5,
  124101. };
  124102. static long _vq_quantmap__44c1_s_p6_1[] = {
  124103. 9, 7, 5, 3, 1, 0, 2, 4,
  124104. 6, 8, 10,
  124105. };
  124106. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124107. _vq_quantthresh__44c1_s_p6_1,
  124108. _vq_quantmap__44c1_s_p6_1,
  124109. 11,
  124110. 11
  124111. };
  124112. static static_codebook _44c1_s_p6_1 = {
  124113. 2, 121,
  124114. _vq_lengthlist__44c1_s_p6_1,
  124115. 1, -531365888, 1611661312, 4, 0,
  124116. _vq_quantlist__44c1_s_p6_1,
  124117. NULL,
  124118. &_vq_auxt__44c1_s_p6_1,
  124119. NULL,
  124120. 0
  124121. };
  124122. static long _vq_quantlist__44c1_s_p7_0[] = {
  124123. 6,
  124124. 5,
  124125. 7,
  124126. 4,
  124127. 8,
  124128. 3,
  124129. 9,
  124130. 2,
  124131. 10,
  124132. 1,
  124133. 11,
  124134. 0,
  124135. 12,
  124136. };
  124137. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124138. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124139. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124140. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124141. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124142. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124143. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124144. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124145. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124146. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124147. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124148. 0,12,11,11,11,13,10,14,13,
  124149. };
  124150. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124151. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124152. 12.5, 17.5, 22.5, 27.5,
  124153. };
  124154. static long _vq_quantmap__44c1_s_p7_0[] = {
  124155. 11, 9, 7, 5, 3, 1, 0, 2,
  124156. 4, 6, 8, 10, 12,
  124157. };
  124158. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124159. _vq_quantthresh__44c1_s_p7_0,
  124160. _vq_quantmap__44c1_s_p7_0,
  124161. 13,
  124162. 13
  124163. };
  124164. static static_codebook _44c1_s_p7_0 = {
  124165. 2, 169,
  124166. _vq_lengthlist__44c1_s_p7_0,
  124167. 1, -526516224, 1616117760, 4, 0,
  124168. _vq_quantlist__44c1_s_p7_0,
  124169. NULL,
  124170. &_vq_auxt__44c1_s_p7_0,
  124171. NULL,
  124172. 0
  124173. };
  124174. static long _vq_quantlist__44c1_s_p7_1[] = {
  124175. 2,
  124176. 1,
  124177. 3,
  124178. 0,
  124179. 4,
  124180. };
  124181. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124182. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124183. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124184. };
  124185. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124186. -1.5, -0.5, 0.5, 1.5,
  124187. };
  124188. static long _vq_quantmap__44c1_s_p7_1[] = {
  124189. 3, 1, 0, 2, 4,
  124190. };
  124191. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124192. _vq_quantthresh__44c1_s_p7_1,
  124193. _vq_quantmap__44c1_s_p7_1,
  124194. 5,
  124195. 5
  124196. };
  124197. static static_codebook _44c1_s_p7_1 = {
  124198. 2, 25,
  124199. _vq_lengthlist__44c1_s_p7_1,
  124200. 1, -533725184, 1611661312, 3, 0,
  124201. _vq_quantlist__44c1_s_p7_1,
  124202. NULL,
  124203. &_vq_auxt__44c1_s_p7_1,
  124204. NULL,
  124205. 0
  124206. };
  124207. static long _vq_quantlist__44c1_s_p8_0[] = {
  124208. 6,
  124209. 5,
  124210. 7,
  124211. 4,
  124212. 8,
  124213. 3,
  124214. 9,
  124215. 2,
  124216. 10,
  124217. 1,
  124218. 11,
  124219. 0,
  124220. 12,
  124221. };
  124222. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124223. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124224. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124225. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124226. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124227. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124228. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124229. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124230. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124231. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124232. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124233. 10,10,10,10,10,10,10,10,10,
  124234. };
  124235. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124236. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124237. 552.5, 773.5, 994.5, 1215.5,
  124238. };
  124239. static long _vq_quantmap__44c1_s_p8_0[] = {
  124240. 11, 9, 7, 5, 3, 1, 0, 2,
  124241. 4, 6, 8, 10, 12,
  124242. };
  124243. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124244. _vq_quantthresh__44c1_s_p8_0,
  124245. _vq_quantmap__44c1_s_p8_0,
  124246. 13,
  124247. 13
  124248. };
  124249. static static_codebook _44c1_s_p8_0 = {
  124250. 2, 169,
  124251. _vq_lengthlist__44c1_s_p8_0,
  124252. 1, -514541568, 1627103232, 4, 0,
  124253. _vq_quantlist__44c1_s_p8_0,
  124254. NULL,
  124255. &_vq_auxt__44c1_s_p8_0,
  124256. NULL,
  124257. 0
  124258. };
  124259. static long _vq_quantlist__44c1_s_p8_1[] = {
  124260. 6,
  124261. 5,
  124262. 7,
  124263. 4,
  124264. 8,
  124265. 3,
  124266. 9,
  124267. 2,
  124268. 10,
  124269. 1,
  124270. 11,
  124271. 0,
  124272. 12,
  124273. };
  124274. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124275. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124276. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124277. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124278. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124279. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124280. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124281. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124282. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124283. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124284. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124285. 16,13,12,12,11,14,12,15,13,
  124286. };
  124287. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124288. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124289. 42.5, 59.5, 76.5, 93.5,
  124290. };
  124291. static long _vq_quantmap__44c1_s_p8_1[] = {
  124292. 11, 9, 7, 5, 3, 1, 0, 2,
  124293. 4, 6, 8, 10, 12,
  124294. };
  124295. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124296. _vq_quantthresh__44c1_s_p8_1,
  124297. _vq_quantmap__44c1_s_p8_1,
  124298. 13,
  124299. 13
  124300. };
  124301. static static_codebook _44c1_s_p8_1 = {
  124302. 2, 169,
  124303. _vq_lengthlist__44c1_s_p8_1,
  124304. 1, -522616832, 1620115456, 4, 0,
  124305. _vq_quantlist__44c1_s_p8_1,
  124306. NULL,
  124307. &_vq_auxt__44c1_s_p8_1,
  124308. NULL,
  124309. 0
  124310. };
  124311. static long _vq_quantlist__44c1_s_p8_2[] = {
  124312. 8,
  124313. 7,
  124314. 9,
  124315. 6,
  124316. 10,
  124317. 5,
  124318. 11,
  124319. 4,
  124320. 12,
  124321. 3,
  124322. 13,
  124323. 2,
  124324. 14,
  124325. 1,
  124326. 15,
  124327. 0,
  124328. 16,
  124329. };
  124330. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124331. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124332. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124333. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124334. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124335. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124336. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124337. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124338. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124339. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124340. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124341. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124342. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124343. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124344. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124345. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124346. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124347. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124348. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124349. 9,
  124350. };
  124351. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124352. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124353. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124354. };
  124355. static long _vq_quantmap__44c1_s_p8_2[] = {
  124356. 15, 13, 11, 9, 7, 5, 3, 1,
  124357. 0, 2, 4, 6, 8, 10, 12, 14,
  124358. 16,
  124359. };
  124360. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124361. _vq_quantthresh__44c1_s_p8_2,
  124362. _vq_quantmap__44c1_s_p8_2,
  124363. 17,
  124364. 17
  124365. };
  124366. static static_codebook _44c1_s_p8_2 = {
  124367. 2, 289,
  124368. _vq_lengthlist__44c1_s_p8_2,
  124369. 1, -529530880, 1611661312, 5, 0,
  124370. _vq_quantlist__44c1_s_p8_2,
  124371. NULL,
  124372. &_vq_auxt__44c1_s_p8_2,
  124373. NULL,
  124374. 0
  124375. };
  124376. static long _huff_lengthlist__44c1_s_short[] = {
  124377. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124378. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124379. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124380. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124381. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124382. 11,
  124383. };
  124384. static static_codebook _huff_book__44c1_s_short = {
  124385. 2, 81,
  124386. _huff_lengthlist__44c1_s_short,
  124387. 0, 0, 0, 0, 0,
  124388. NULL,
  124389. NULL,
  124390. NULL,
  124391. NULL,
  124392. 0
  124393. };
  124394. static long _huff_lengthlist__44c1_sm_long[] = {
  124395. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124396. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124397. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124398. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124399. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124400. 11,
  124401. };
  124402. static static_codebook _huff_book__44c1_sm_long = {
  124403. 2, 81,
  124404. _huff_lengthlist__44c1_sm_long,
  124405. 0, 0, 0, 0, 0,
  124406. NULL,
  124407. NULL,
  124408. NULL,
  124409. NULL,
  124410. 0
  124411. };
  124412. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124413. 1,
  124414. 0,
  124415. 2,
  124416. };
  124417. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124418. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124419. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124424. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124429. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124464. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124469. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124474. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124487. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124492. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124497. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124510. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124515. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124520. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  124829. };
  124830. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124831. -0.5, 0.5,
  124832. };
  124833. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124834. 1, 0, 2,
  124835. };
  124836. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124837. _vq_quantthresh__44c1_sm_p1_0,
  124838. _vq_quantmap__44c1_sm_p1_0,
  124839. 3,
  124840. 3
  124841. };
  124842. static static_codebook _44c1_sm_p1_0 = {
  124843. 8, 6561,
  124844. _vq_lengthlist__44c1_sm_p1_0,
  124845. 1, -535822336, 1611661312, 2, 0,
  124846. _vq_quantlist__44c1_sm_p1_0,
  124847. NULL,
  124848. &_vq_auxt__44c1_sm_p1_0,
  124849. NULL,
  124850. 0
  124851. };
  124852. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124853. 2,
  124854. 1,
  124855. 3,
  124856. 0,
  124857. 4,
  124858. };
  124859. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124860. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0,
  124900. };
  124901. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124902. -1.5, -0.5, 0.5, 1.5,
  124903. };
  124904. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124905. 3, 1, 0, 2, 4,
  124906. };
  124907. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124908. _vq_quantthresh__44c1_sm_p2_0,
  124909. _vq_quantmap__44c1_sm_p2_0,
  124910. 5,
  124911. 5
  124912. };
  124913. static static_codebook _44c1_sm_p2_0 = {
  124914. 4, 625,
  124915. _vq_lengthlist__44c1_sm_p2_0,
  124916. 1, -533725184, 1611661312, 3, 0,
  124917. _vq_quantlist__44c1_sm_p2_0,
  124918. NULL,
  124919. &_vq_auxt__44c1_sm_p2_0,
  124920. NULL,
  124921. 0
  124922. };
  124923. static long _vq_quantlist__44c1_sm_p3_0[] = {
  124924. 4,
  124925. 3,
  124926. 5,
  124927. 2,
  124928. 6,
  124929. 1,
  124930. 7,
  124931. 0,
  124932. 8,
  124933. };
  124934. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  124935. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  124936. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  124937. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124938. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124939. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124940. 0,
  124941. };
  124942. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  124943. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124944. };
  124945. static long _vq_quantmap__44c1_sm_p3_0[] = {
  124946. 7, 5, 3, 1, 0, 2, 4, 6,
  124947. 8,
  124948. };
  124949. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  124950. _vq_quantthresh__44c1_sm_p3_0,
  124951. _vq_quantmap__44c1_sm_p3_0,
  124952. 9,
  124953. 9
  124954. };
  124955. static static_codebook _44c1_sm_p3_0 = {
  124956. 2, 81,
  124957. _vq_lengthlist__44c1_sm_p3_0,
  124958. 1, -531628032, 1611661312, 4, 0,
  124959. _vq_quantlist__44c1_sm_p3_0,
  124960. NULL,
  124961. &_vq_auxt__44c1_sm_p3_0,
  124962. NULL,
  124963. 0
  124964. };
  124965. static long _vq_quantlist__44c1_sm_p4_0[] = {
  124966. 4,
  124967. 3,
  124968. 5,
  124969. 2,
  124970. 6,
  124971. 1,
  124972. 7,
  124973. 0,
  124974. 8,
  124975. };
  124976. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  124977. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  124978. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  124979. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  124980. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  124981. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124982. 11,
  124983. };
  124984. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  124985. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124986. };
  124987. static long _vq_quantmap__44c1_sm_p4_0[] = {
  124988. 7, 5, 3, 1, 0, 2, 4, 6,
  124989. 8,
  124990. };
  124991. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  124992. _vq_quantthresh__44c1_sm_p4_0,
  124993. _vq_quantmap__44c1_sm_p4_0,
  124994. 9,
  124995. 9
  124996. };
  124997. static static_codebook _44c1_sm_p4_0 = {
  124998. 2, 81,
  124999. _vq_lengthlist__44c1_sm_p4_0,
  125000. 1, -531628032, 1611661312, 4, 0,
  125001. _vq_quantlist__44c1_sm_p4_0,
  125002. NULL,
  125003. &_vq_auxt__44c1_sm_p4_0,
  125004. NULL,
  125005. 0
  125006. };
  125007. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125008. 8,
  125009. 7,
  125010. 9,
  125011. 6,
  125012. 10,
  125013. 5,
  125014. 11,
  125015. 4,
  125016. 12,
  125017. 3,
  125018. 13,
  125019. 2,
  125020. 14,
  125021. 1,
  125022. 15,
  125023. 0,
  125024. 16,
  125025. };
  125026. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125027. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125028. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125029. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125030. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125031. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125032. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125033. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125034. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125035. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125036. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125037. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125038. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125039. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125040. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125041. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125042. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125043. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125045. 14,
  125046. };
  125047. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125048. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125049. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125050. };
  125051. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125052. 15, 13, 11, 9, 7, 5, 3, 1,
  125053. 0, 2, 4, 6, 8, 10, 12, 14,
  125054. 16,
  125055. };
  125056. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125057. _vq_quantthresh__44c1_sm_p5_0,
  125058. _vq_quantmap__44c1_sm_p5_0,
  125059. 17,
  125060. 17
  125061. };
  125062. static static_codebook _44c1_sm_p5_0 = {
  125063. 2, 289,
  125064. _vq_lengthlist__44c1_sm_p5_0,
  125065. 1, -529530880, 1611661312, 5, 0,
  125066. _vq_quantlist__44c1_sm_p5_0,
  125067. NULL,
  125068. &_vq_auxt__44c1_sm_p5_0,
  125069. NULL,
  125070. 0
  125071. };
  125072. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125073. 1,
  125074. 0,
  125075. 2,
  125076. };
  125077. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125078. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125079. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125080. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125081. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125082. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125083. 11,
  125084. };
  125085. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125086. -5.5, 5.5,
  125087. };
  125088. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125089. 1, 0, 2,
  125090. };
  125091. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125092. _vq_quantthresh__44c1_sm_p6_0,
  125093. _vq_quantmap__44c1_sm_p6_0,
  125094. 3,
  125095. 3
  125096. };
  125097. static static_codebook _44c1_sm_p6_0 = {
  125098. 4, 81,
  125099. _vq_lengthlist__44c1_sm_p6_0,
  125100. 1, -529137664, 1618345984, 2, 0,
  125101. _vq_quantlist__44c1_sm_p6_0,
  125102. NULL,
  125103. &_vq_auxt__44c1_sm_p6_0,
  125104. NULL,
  125105. 0
  125106. };
  125107. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125108. 5,
  125109. 4,
  125110. 6,
  125111. 3,
  125112. 7,
  125113. 2,
  125114. 8,
  125115. 1,
  125116. 9,
  125117. 0,
  125118. 10,
  125119. };
  125120. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125121. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125122. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125123. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125124. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125125. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125126. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125127. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125128. 10,10,10, 8, 8, 8, 8, 8, 8,
  125129. };
  125130. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125131. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125132. 3.5, 4.5,
  125133. };
  125134. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125135. 9, 7, 5, 3, 1, 0, 2, 4,
  125136. 6, 8, 10,
  125137. };
  125138. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125139. _vq_quantthresh__44c1_sm_p6_1,
  125140. _vq_quantmap__44c1_sm_p6_1,
  125141. 11,
  125142. 11
  125143. };
  125144. static static_codebook _44c1_sm_p6_1 = {
  125145. 2, 121,
  125146. _vq_lengthlist__44c1_sm_p6_1,
  125147. 1, -531365888, 1611661312, 4, 0,
  125148. _vq_quantlist__44c1_sm_p6_1,
  125149. NULL,
  125150. &_vq_auxt__44c1_sm_p6_1,
  125151. NULL,
  125152. 0
  125153. };
  125154. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125155. 6,
  125156. 5,
  125157. 7,
  125158. 4,
  125159. 8,
  125160. 3,
  125161. 9,
  125162. 2,
  125163. 10,
  125164. 1,
  125165. 11,
  125166. 0,
  125167. 12,
  125168. };
  125169. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125170. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125171. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125172. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125173. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125174. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125175. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125176. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125177. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125178. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125179. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125180. 0,12,12,11,11,13,12,14,13,
  125181. };
  125182. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125183. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125184. 12.5, 17.5, 22.5, 27.5,
  125185. };
  125186. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125187. 11, 9, 7, 5, 3, 1, 0, 2,
  125188. 4, 6, 8, 10, 12,
  125189. };
  125190. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125191. _vq_quantthresh__44c1_sm_p7_0,
  125192. _vq_quantmap__44c1_sm_p7_0,
  125193. 13,
  125194. 13
  125195. };
  125196. static static_codebook _44c1_sm_p7_0 = {
  125197. 2, 169,
  125198. _vq_lengthlist__44c1_sm_p7_0,
  125199. 1, -526516224, 1616117760, 4, 0,
  125200. _vq_quantlist__44c1_sm_p7_0,
  125201. NULL,
  125202. &_vq_auxt__44c1_sm_p7_0,
  125203. NULL,
  125204. 0
  125205. };
  125206. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125207. 2,
  125208. 1,
  125209. 3,
  125210. 0,
  125211. 4,
  125212. };
  125213. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125214. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125215. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125216. };
  125217. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125218. -1.5, -0.5, 0.5, 1.5,
  125219. };
  125220. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125221. 3, 1, 0, 2, 4,
  125222. };
  125223. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125224. _vq_quantthresh__44c1_sm_p7_1,
  125225. _vq_quantmap__44c1_sm_p7_1,
  125226. 5,
  125227. 5
  125228. };
  125229. static static_codebook _44c1_sm_p7_1 = {
  125230. 2, 25,
  125231. _vq_lengthlist__44c1_sm_p7_1,
  125232. 1, -533725184, 1611661312, 3, 0,
  125233. _vq_quantlist__44c1_sm_p7_1,
  125234. NULL,
  125235. &_vq_auxt__44c1_sm_p7_1,
  125236. NULL,
  125237. 0
  125238. };
  125239. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125240. 6,
  125241. 5,
  125242. 7,
  125243. 4,
  125244. 8,
  125245. 3,
  125246. 9,
  125247. 2,
  125248. 10,
  125249. 1,
  125250. 11,
  125251. 0,
  125252. 12,
  125253. };
  125254. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125255. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125256. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125257. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125258. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125259. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125260. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125261. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125262. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125263. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125264. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125265. 13,13,13,13,13,13,13,13,13,
  125266. };
  125267. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125268. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125269. 552.5, 773.5, 994.5, 1215.5,
  125270. };
  125271. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125272. 11, 9, 7, 5, 3, 1, 0, 2,
  125273. 4, 6, 8, 10, 12,
  125274. };
  125275. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125276. _vq_quantthresh__44c1_sm_p8_0,
  125277. _vq_quantmap__44c1_sm_p8_0,
  125278. 13,
  125279. 13
  125280. };
  125281. static static_codebook _44c1_sm_p8_0 = {
  125282. 2, 169,
  125283. _vq_lengthlist__44c1_sm_p8_0,
  125284. 1, -514541568, 1627103232, 4, 0,
  125285. _vq_quantlist__44c1_sm_p8_0,
  125286. NULL,
  125287. &_vq_auxt__44c1_sm_p8_0,
  125288. NULL,
  125289. 0
  125290. };
  125291. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125292. 6,
  125293. 5,
  125294. 7,
  125295. 4,
  125296. 8,
  125297. 3,
  125298. 9,
  125299. 2,
  125300. 10,
  125301. 1,
  125302. 11,
  125303. 0,
  125304. 12,
  125305. };
  125306. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125307. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125308. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125309. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125310. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125311. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125312. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125313. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125314. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125315. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125316. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125317. 20,13,12,12,12,14,12,14,13,
  125318. };
  125319. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125320. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125321. 42.5, 59.5, 76.5, 93.5,
  125322. };
  125323. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125324. 11, 9, 7, 5, 3, 1, 0, 2,
  125325. 4, 6, 8, 10, 12,
  125326. };
  125327. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125328. _vq_quantthresh__44c1_sm_p8_1,
  125329. _vq_quantmap__44c1_sm_p8_1,
  125330. 13,
  125331. 13
  125332. };
  125333. static static_codebook _44c1_sm_p8_1 = {
  125334. 2, 169,
  125335. _vq_lengthlist__44c1_sm_p8_1,
  125336. 1, -522616832, 1620115456, 4, 0,
  125337. _vq_quantlist__44c1_sm_p8_1,
  125338. NULL,
  125339. &_vq_auxt__44c1_sm_p8_1,
  125340. NULL,
  125341. 0
  125342. };
  125343. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125344. 8,
  125345. 7,
  125346. 9,
  125347. 6,
  125348. 10,
  125349. 5,
  125350. 11,
  125351. 4,
  125352. 12,
  125353. 3,
  125354. 13,
  125355. 2,
  125356. 14,
  125357. 1,
  125358. 15,
  125359. 0,
  125360. 16,
  125361. };
  125362. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125363. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125364. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125365. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125366. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125367. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125368. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125369. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125370. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125371. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125372. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125373. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125374. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125375. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125376. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125377. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125378. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125379. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125380. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125381. 9,
  125382. };
  125383. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125384. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125385. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125386. };
  125387. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125388. 15, 13, 11, 9, 7, 5, 3, 1,
  125389. 0, 2, 4, 6, 8, 10, 12, 14,
  125390. 16,
  125391. };
  125392. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125393. _vq_quantthresh__44c1_sm_p8_2,
  125394. _vq_quantmap__44c1_sm_p8_2,
  125395. 17,
  125396. 17
  125397. };
  125398. static static_codebook _44c1_sm_p8_2 = {
  125399. 2, 289,
  125400. _vq_lengthlist__44c1_sm_p8_2,
  125401. 1, -529530880, 1611661312, 5, 0,
  125402. _vq_quantlist__44c1_sm_p8_2,
  125403. NULL,
  125404. &_vq_auxt__44c1_sm_p8_2,
  125405. NULL,
  125406. 0
  125407. };
  125408. static long _huff_lengthlist__44c1_sm_short[] = {
  125409. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125410. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125411. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125412. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125413. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125414. 11,
  125415. };
  125416. static static_codebook _huff_book__44c1_sm_short = {
  125417. 2, 81,
  125418. _huff_lengthlist__44c1_sm_short,
  125419. 0, 0, 0, 0, 0,
  125420. NULL,
  125421. NULL,
  125422. NULL,
  125423. NULL,
  125424. 0
  125425. };
  125426. static long _huff_lengthlist__44cn1_s_long[] = {
  125427. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125428. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125429. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125430. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125431. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125432. 20,
  125433. };
  125434. static static_codebook _huff_book__44cn1_s_long = {
  125435. 2, 81,
  125436. _huff_lengthlist__44cn1_s_long,
  125437. 0, 0, 0, 0, 0,
  125438. NULL,
  125439. NULL,
  125440. NULL,
  125441. NULL,
  125442. 0
  125443. };
  125444. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125445. 1,
  125446. 0,
  125447. 2,
  125448. };
  125449. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125450. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125451. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125456. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125461. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125496. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125501. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125506. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125519. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125524. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125529. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125542. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125547. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125552. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  125861. };
  125862. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125863. -0.5, 0.5,
  125864. };
  125865. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125866. 1, 0, 2,
  125867. };
  125868. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125869. _vq_quantthresh__44cn1_s_p1_0,
  125870. _vq_quantmap__44cn1_s_p1_0,
  125871. 3,
  125872. 3
  125873. };
  125874. static static_codebook _44cn1_s_p1_0 = {
  125875. 8, 6561,
  125876. _vq_lengthlist__44cn1_s_p1_0,
  125877. 1, -535822336, 1611661312, 2, 0,
  125878. _vq_quantlist__44cn1_s_p1_0,
  125879. NULL,
  125880. &_vq_auxt__44cn1_s_p1_0,
  125881. NULL,
  125882. 0
  125883. };
  125884. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125885. 2,
  125886. 1,
  125887. 3,
  125888. 0,
  125889. 4,
  125890. };
  125891. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125892. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0,
  125932. };
  125933. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  125934. -1.5, -0.5, 0.5, 1.5,
  125935. };
  125936. static long _vq_quantmap__44cn1_s_p2_0[] = {
  125937. 3, 1, 0, 2, 4,
  125938. };
  125939. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  125940. _vq_quantthresh__44cn1_s_p2_0,
  125941. _vq_quantmap__44cn1_s_p2_0,
  125942. 5,
  125943. 5
  125944. };
  125945. static static_codebook _44cn1_s_p2_0 = {
  125946. 4, 625,
  125947. _vq_lengthlist__44cn1_s_p2_0,
  125948. 1, -533725184, 1611661312, 3, 0,
  125949. _vq_quantlist__44cn1_s_p2_0,
  125950. NULL,
  125951. &_vq_auxt__44cn1_s_p2_0,
  125952. NULL,
  125953. 0
  125954. };
  125955. static long _vq_quantlist__44cn1_s_p3_0[] = {
  125956. 4,
  125957. 3,
  125958. 5,
  125959. 2,
  125960. 6,
  125961. 1,
  125962. 7,
  125963. 0,
  125964. 8,
  125965. };
  125966. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  125967. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  125968. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  125969. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125970. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125971. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125972. 0,
  125973. };
  125974. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  125975. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125976. };
  125977. static long _vq_quantmap__44cn1_s_p3_0[] = {
  125978. 7, 5, 3, 1, 0, 2, 4, 6,
  125979. 8,
  125980. };
  125981. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  125982. _vq_quantthresh__44cn1_s_p3_0,
  125983. _vq_quantmap__44cn1_s_p3_0,
  125984. 9,
  125985. 9
  125986. };
  125987. static static_codebook _44cn1_s_p3_0 = {
  125988. 2, 81,
  125989. _vq_lengthlist__44cn1_s_p3_0,
  125990. 1, -531628032, 1611661312, 4, 0,
  125991. _vq_quantlist__44cn1_s_p3_0,
  125992. NULL,
  125993. &_vq_auxt__44cn1_s_p3_0,
  125994. NULL,
  125995. 0
  125996. };
  125997. static long _vq_quantlist__44cn1_s_p4_0[] = {
  125998. 4,
  125999. 3,
  126000. 5,
  126001. 2,
  126002. 6,
  126003. 1,
  126004. 7,
  126005. 0,
  126006. 8,
  126007. };
  126008. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126009. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126010. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126011. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126012. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126013. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126014. 11,
  126015. };
  126016. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126017. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126018. };
  126019. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126020. 7, 5, 3, 1, 0, 2, 4, 6,
  126021. 8,
  126022. };
  126023. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126024. _vq_quantthresh__44cn1_s_p4_0,
  126025. _vq_quantmap__44cn1_s_p4_0,
  126026. 9,
  126027. 9
  126028. };
  126029. static static_codebook _44cn1_s_p4_0 = {
  126030. 2, 81,
  126031. _vq_lengthlist__44cn1_s_p4_0,
  126032. 1, -531628032, 1611661312, 4, 0,
  126033. _vq_quantlist__44cn1_s_p4_0,
  126034. NULL,
  126035. &_vq_auxt__44cn1_s_p4_0,
  126036. NULL,
  126037. 0
  126038. };
  126039. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126040. 8,
  126041. 7,
  126042. 9,
  126043. 6,
  126044. 10,
  126045. 5,
  126046. 11,
  126047. 4,
  126048. 12,
  126049. 3,
  126050. 13,
  126051. 2,
  126052. 14,
  126053. 1,
  126054. 15,
  126055. 0,
  126056. 16,
  126057. };
  126058. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126059. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126060. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126061. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126062. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126063. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126064. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126065. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126066. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126067. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126068. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126069. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126070. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126071. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126072. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126073. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126074. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126075. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126077. 14,
  126078. };
  126079. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126080. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126081. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126082. };
  126083. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126084. 15, 13, 11, 9, 7, 5, 3, 1,
  126085. 0, 2, 4, 6, 8, 10, 12, 14,
  126086. 16,
  126087. };
  126088. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126089. _vq_quantthresh__44cn1_s_p5_0,
  126090. _vq_quantmap__44cn1_s_p5_0,
  126091. 17,
  126092. 17
  126093. };
  126094. static static_codebook _44cn1_s_p5_0 = {
  126095. 2, 289,
  126096. _vq_lengthlist__44cn1_s_p5_0,
  126097. 1, -529530880, 1611661312, 5, 0,
  126098. _vq_quantlist__44cn1_s_p5_0,
  126099. NULL,
  126100. &_vq_auxt__44cn1_s_p5_0,
  126101. NULL,
  126102. 0
  126103. };
  126104. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126105. 1,
  126106. 0,
  126107. 2,
  126108. };
  126109. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126110. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126111. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126112. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126113. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126114. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126115. 10,
  126116. };
  126117. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126118. -5.5, 5.5,
  126119. };
  126120. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126121. 1, 0, 2,
  126122. };
  126123. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126124. _vq_quantthresh__44cn1_s_p6_0,
  126125. _vq_quantmap__44cn1_s_p6_0,
  126126. 3,
  126127. 3
  126128. };
  126129. static static_codebook _44cn1_s_p6_0 = {
  126130. 4, 81,
  126131. _vq_lengthlist__44cn1_s_p6_0,
  126132. 1, -529137664, 1618345984, 2, 0,
  126133. _vq_quantlist__44cn1_s_p6_0,
  126134. NULL,
  126135. &_vq_auxt__44cn1_s_p6_0,
  126136. NULL,
  126137. 0
  126138. };
  126139. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126140. 5,
  126141. 4,
  126142. 6,
  126143. 3,
  126144. 7,
  126145. 2,
  126146. 8,
  126147. 1,
  126148. 9,
  126149. 0,
  126150. 10,
  126151. };
  126152. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126153. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126154. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126155. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126156. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126157. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126158. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126159. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126160. 10,10,10, 9, 9, 9, 9, 9, 9,
  126161. };
  126162. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126163. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126164. 3.5, 4.5,
  126165. };
  126166. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126167. 9, 7, 5, 3, 1, 0, 2, 4,
  126168. 6, 8, 10,
  126169. };
  126170. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126171. _vq_quantthresh__44cn1_s_p6_1,
  126172. _vq_quantmap__44cn1_s_p6_1,
  126173. 11,
  126174. 11
  126175. };
  126176. static static_codebook _44cn1_s_p6_1 = {
  126177. 2, 121,
  126178. _vq_lengthlist__44cn1_s_p6_1,
  126179. 1, -531365888, 1611661312, 4, 0,
  126180. _vq_quantlist__44cn1_s_p6_1,
  126181. NULL,
  126182. &_vq_auxt__44cn1_s_p6_1,
  126183. NULL,
  126184. 0
  126185. };
  126186. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126187. 6,
  126188. 5,
  126189. 7,
  126190. 4,
  126191. 8,
  126192. 3,
  126193. 9,
  126194. 2,
  126195. 10,
  126196. 1,
  126197. 11,
  126198. 0,
  126199. 12,
  126200. };
  126201. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126202. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126203. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126204. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126205. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126206. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126207. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126208. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126209. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126210. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126211. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126212. 0,13,13,12,12,13,13,13,14,
  126213. };
  126214. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126215. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126216. 12.5, 17.5, 22.5, 27.5,
  126217. };
  126218. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126219. 11, 9, 7, 5, 3, 1, 0, 2,
  126220. 4, 6, 8, 10, 12,
  126221. };
  126222. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126223. _vq_quantthresh__44cn1_s_p7_0,
  126224. _vq_quantmap__44cn1_s_p7_0,
  126225. 13,
  126226. 13
  126227. };
  126228. static static_codebook _44cn1_s_p7_0 = {
  126229. 2, 169,
  126230. _vq_lengthlist__44cn1_s_p7_0,
  126231. 1, -526516224, 1616117760, 4, 0,
  126232. _vq_quantlist__44cn1_s_p7_0,
  126233. NULL,
  126234. &_vq_auxt__44cn1_s_p7_0,
  126235. NULL,
  126236. 0
  126237. };
  126238. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126239. 2,
  126240. 1,
  126241. 3,
  126242. 0,
  126243. 4,
  126244. };
  126245. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126246. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126247. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126248. };
  126249. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126250. -1.5, -0.5, 0.5, 1.5,
  126251. };
  126252. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126253. 3, 1, 0, 2, 4,
  126254. };
  126255. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126256. _vq_quantthresh__44cn1_s_p7_1,
  126257. _vq_quantmap__44cn1_s_p7_1,
  126258. 5,
  126259. 5
  126260. };
  126261. static static_codebook _44cn1_s_p7_1 = {
  126262. 2, 25,
  126263. _vq_lengthlist__44cn1_s_p7_1,
  126264. 1, -533725184, 1611661312, 3, 0,
  126265. _vq_quantlist__44cn1_s_p7_1,
  126266. NULL,
  126267. &_vq_auxt__44cn1_s_p7_1,
  126268. NULL,
  126269. 0
  126270. };
  126271. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126272. 2,
  126273. 1,
  126274. 3,
  126275. 0,
  126276. 4,
  126277. };
  126278. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126279. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126280. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126282. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126283. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126286. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126288. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126289. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126290. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126291. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126292. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126293. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126294. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126295. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126296. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126297. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126298. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126299. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126300. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126301. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126302. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126303. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126304. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126305. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126306. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126307. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126312. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126313. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126314. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126315. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126316. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126317. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126318. 12,
  126319. };
  126320. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126321. -331.5, -110.5, 110.5, 331.5,
  126322. };
  126323. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126324. 3, 1, 0, 2, 4,
  126325. };
  126326. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126327. _vq_quantthresh__44cn1_s_p8_0,
  126328. _vq_quantmap__44cn1_s_p8_0,
  126329. 5,
  126330. 5
  126331. };
  126332. static static_codebook _44cn1_s_p8_0 = {
  126333. 4, 625,
  126334. _vq_lengthlist__44cn1_s_p8_0,
  126335. 1, -518283264, 1627103232, 3, 0,
  126336. _vq_quantlist__44cn1_s_p8_0,
  126337. NULL,
  126338. &_vq_auxt__44cn1_s_p8_0,
  126339. NULL,
  126340. 0
  126341. };
  126342. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126343. 6,
  126344. 5,
  126345. 7,
  126346. 4,
  126347. 8,
  126348. 3,
  126349. 9,
  126350. 2,
  126351. 10,
  126352. 1,
  126353. 11,
  126354. 0,
  126355. 12,
  126356. };
  126357. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126358. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126359. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126360. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126361. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126362. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126363. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126364. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126365. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126366. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126367. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126368. 15,12,12,11,11,14,12,13,14,
  126369. };
  126370. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126371. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126372. 42.5, 59.5, 76.5, 93.5,
  126373. };
  126374. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126375. 11, 9, 7, 5, 3, 1, 0, 2,
  126376. 4, 6, 8, 10, 12,
  126377. };
  126378. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126379. _vq_quantthresh__44cn1_s_p8_1,
  126380. _vq_quantmap__44cn1_s_p8_1,
  126381. 13,
  126382. 13
  126383. };
  126384. static static_codebook _44cn1_s_p8_1 = {
  126385. 2, 169,
  126386. _vq_lengthlist__44cn1_s_p8_1,
  126387. 1, -522616832, 1620115456, 4, 0,
  126388. _vq_quantlist__44cn1_s_p8_1,
  126389. NULL,
  126390. &_vq_auxt__44cn1_s_p8_1,
  126391. NULL,
  126392. 0
  126393. };
  126394. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126395. 8,
  126396. 7,
  126397. 9,
  126398. 6,
  126399. 10,
  126400. 5,
  126401. 11,
  126402. 4,
  126403. 12,
  126404. 3,
  126405. 13,
  126406. 2,
  126407. 14,
  126408. 1,
  126409. 15,
  126410. 0,
  126411. 16,
  126412. };
  126413. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126414. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126415. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126416. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126417. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126418. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126419. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126420. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126421. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126422. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126423. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126424. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126425. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126426. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126427. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126428. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126429. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126430. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126431. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126432. 9,
  126433. };
  126434. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126435. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126436. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126437. };
  126438. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126439. 15, 13, 11, 9, 7, 5, 3, 1,
  126440. 0, 2, 4, 6, 8, 10, 12, 14,
  126441. 16,
  126442. };
  126443. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126444. _vq_quantthresh__44cn1_s_p8_2,
  126445. _vq_quantmap__44cn1_s_p8_2,
  126446. 17,
  126447. 17
  126448. };
  126449. static static_codebook _44cn1_s_p8_2 = {
  126450. 2, 289,
  126451. _vq_lengthlist__44cn1_s_p8_2,
  126452. 1, -529530880, 1611661312, 5, 0,
  126453. _vq_quantlist__44cn1_s_p8_2,
  126454. NULL,
  126455. &_vq_auxt__44cn1_s_p8_2,
  126456. NULL,
  126457. 0
  126458. };
  126459. static long _huff_lengthlist__44cn1_s_short[] = {
  126460. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126461. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126462. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126463. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126464. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126465. 10,
  126466. };
  126467. static static_codebook _huff_book__44cn1_s_short = {
  126468. 2, 81,
  126469. _huff_lengthlist__44cn1_s_short,
  126470. 0, 0, 0, 0, 0,
  126471. NULL,
  126472. NULL,
  126473. NULL,
  126474. NULL,
  126475. 0
  126476. };
  126477. static long _huff_lengthlist__44cn1_sm_long[] = {
  126478. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126479. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126480. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126481. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126482. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126483. 17,
  126484. };
  126485. static static_codebook _huff_book__44cn1_sm_long = {
  126486. 2, 81,
  126487. _huff_lengthlist__44cn1_sm_long,
  126488. 0, 0, 0, 0, 0,
  126489. NULL,
  126490. NULL,
  126491. NULL,
  126492. NULL,
  126493. 0
  126494. };
  126495. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126496. 1,
  126497. 0,
  126498. 2,
  126499. };
  126500. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126501. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126502. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126507. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126512. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126547. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126552. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126557. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126570. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126575. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126580. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126593. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126598. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126603. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  126912. };
  126913. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126914. -0.5, 0.5,
  126915. };
  126916. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  126917. 1, 0, 2,
  126918. };
  126919. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  126920. _vq_quantthresh__44cn1_sm_p1_0,
  126921. _vq_quantmap__44cn1_sm_p1_0,
  126922. 3,
  126923. 3
  126924. };
  126925. static static_codebook _44cn1_sm_p1_0 = {
  126926. 8, 6561,
  126927. _vq_lengthlist__44cn1_sm_p1_0,
  126928. 1, -535822336, 1611661312, 2, 0,
  126929. _vq_quantlist__44cn1_sm_p1_0,
  126930. NULL,
  126931. &_vq_auxt__44cn1_sm_p1_0,
  126932. NULL,
  126933. 0
  126934. };
  126935. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  126936. 2,
  126937. 1,
  126938. 3,
  126939. 0,
  126940. 4,
  126941. };
  126942. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  126943. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0,
  126983. };
  126984. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  126985. -1.5, -0.5, 0.5, 1.5,
  126986. };
  126987. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  126988. 3, 1, 0, 2, 4,
  126989. };
  126990. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  126991. _vq_quantthresh__44cn1_sm_p2_0,
  126992. _vq_quantmap__44cn1_sm_p2_0,
  126993. 5,
  126994. 5
  126995. };
  126996. static static_codebook _44cn1_sm_p2_0 = {
  126997. 4, 625,
  126998. _vq_lengthlist__44cn1_sm_p2_0,
  126999. 1, -533725184, 1611661312, 3, 0,
  127000. _vq_quantlist__44cn1_sm_p2_0,
  127001. NULL,
  127002. &_vq_auxt__44cn1_sm_p2_0,
  127003. NULL,
  127004. 0
  127005. };
  127006. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127007. 4,
  127008. 3,
  127009. 5,
  127010. 2,
  127011. 6,
  127012. 1,
  127013. 7,
  127014. 0,
  127015. 8,
  127016. };
  127017. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127018. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127019. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127020. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127021. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127022. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127023. 0,
  127024. };
  127025. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127026. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127027. };
  127028. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127029. 7, 5, 3, 1, 0, 2, 4, 6,
  127030. 8,
  127031. };
  127032. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127033. _vq_quantthresh__44cn1_sm_p3_0,
  127034. _vq_quantmap__44cn1_sm_p3_0,
  127035. 9,
  127036. 9
  127037. };
  127038. static static_codebook _44cn1_sm_p3_0 = {
  127039. 2, 81,
  127040. _vq_lengthlist__44cn1_sm_p3_0,
  127041. 1, -531628032, 1611661312, 4, 0,
  127042. _vq_quantlist__44cn1_sm_p3_0,
  127043. NULL,
  127044. &_vq_auxt__44cn1_sm_p3_0,
  127045. NULL,
  127046. 0
  127047. };
  127048. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127049. 4,
  127050. 3,
  127051. 5,
  127052. 2,
  127053. 6,
  127054. 1,
  127055. 7,
  127056. 0,
  127057. 8,
  127058. };
  127059. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127060. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127061. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127062. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127063. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127064. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127065. 11,
  127066. };
  127067. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127068. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127069. };
  127070. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127071. 7, 5, 3, 1, 0, 2, 4, 6,
  127072. 8,
  127073. };
  127074. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127075. _vq_quantthresh__44cn1_sm_p4_0,
  127076. _vq_quantmap__44cn1_sm_p4_0,
  127077. 9,
  127078. 9
  127079. };
  127080. static static_codebook _44cn1_sm_p4_0 = {
  127081. 2, 81,
  127082. _vq_lengthlist__44cn1_sm_p4_0,
  127083. 1, -531628032, 1611661312, 4, 0,
  127084. _vq_quantlist__44cn1_sm_p4_0,
  127085. NULL,
  127086. &_vq_auxt__44cn1_sm_p4_0,
  127087. NULL,
  127088. 0
  127089. };
  127090. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127091. 8,
  127092. 7,
  127093. 9,
  127094. 6,
  127095. 10,
  127096. 5,
  127097. 11,
  127098. 4,
  127099. 12,
  127100. 3,
  127101. 13,
  127102. 2,
  127103. 14,
  127104. 1,
  127105. 15,
  127106. 0,
  127107. 16,
  127108. };
  127109. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127110. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127111. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127112. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127113. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127114. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127115. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127116. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127117. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127118. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127119. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127120. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127121. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127122. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127123. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127124. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127125. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127126. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127128. 14,
  127129. };
  127130. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127131. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127132. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127133. };
  127134. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127135. 15, 13, 11, 9, 7, 5, 3, 1,
  127136. 0, 2, 4, 6, 8, 10, 12, 14,
  127137. 16,
  127138. };
  127139. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127140. _vq_quantthresh__44cn1_sm_p5_0,
  127141. _vq_quantmap__44cn1_sm_p5_0,
  127142. 17,
  127143. 17
  127144. };
  127145. static static_codebook _44cn1_sm_p5_0 = {
  127146. 2, 289,
  127147. _vq_lengthlist__44cn1_sm_p5_0,
  127148. 1, -529530880, 1611661312, 5, 0,
  127149. _vq_quantlist__44cn1_sm_p5_0,
  127150. NULL,
  127151. &_vq_auxt__44cn1_sm_p5_0,
  127152. NULL,
  127153. 0
  127154. };
  127155. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127156. 1,
  127157. 0,
  127158. 2,
  127159. };
  127160. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127161. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127162. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127163. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127164. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127165. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127166. 10,
  127167. };
  127168. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127169. -5.5, 5.5,
  127170. };
  127171. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127172. 1, 0, 2,
  127173. };
  127174. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127175. _vq_quantthresh__44cn1_sm_p6_0,
  127176. _vq_quantmap__44cn1_sm_p6_0,
  127177. 3,
  127178. 3
  127179. };
  127180. static static_codebook _44cn1_sm_p6_0 = {
  127181. 4, 81,
  127182. _vq_lengthlist__44cn1_sm_p6_0,
  127183. 1, -529137664, 1618345984, 2, 0,
  127184. _vq_quantlist__44cn1_sm_p6_0,
  127185. NULL,
  127186. &_vq_auxt__44cn1_sm_p6_0,
  127187. NULL,
  127188. 0
  127189. };
  127190. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127191. 5,
  127192. 4,
  127193. 6,
  127194. 3,
  127195. 7,
  127196. 2,
  127197. 8,
  127198. 1,
  127199. 9,
  127200. 0,
  127201. 10,
  127202. };
  127203. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127204. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127205. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127206. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127207. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127208. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127209. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127210. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127211. 10,10,10, 8, 9, 8, 8, 9, 8,
  127212. };
  127213. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127214. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127215. 3.5, 4.5,
  127216. };
  127217. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127218. 9, 7, 5, 3, 1, 0, 2, 4,
  127219. 6, 8, 10,
  127220. };
  127221. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127222. _vq_quantthresh__44cn1_sm_p6_1,
  127223. _vq_quantmap__44cn1_sm_p6_1,
  127224. 11,
  127225. 11
  127226. };
  127227. static static_codebook _44cn1_sm_p6_1 = {
  127228. 2, 121,
  127229. _vq_lengthlist__44cn1_sm_p6_1,
  127230. 1, -531365888, 1611661312, 4, 0,
  127231. _vq_quantlist__44cn1_sm_p6_1,
  127232. NULL,
  127233. &_vq_auxt__44cn1_sm_p6_1,
  127234. NULL,
  127235. 0
  127236. };
  127237. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127238. 6,
  127239. 5,
  127240. 7,
  127241. 4,
  127242. 8,
  127243. 3,
  127244. 9,
  127245. 2,
  127246. 10,
  127247. 1,
  127248. 11,
  127249. 0,
  127250. 12,
  127251. };
  127252. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127253. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127254. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127255. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127256. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127257. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127258. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127259. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127260. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127261. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127262. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127263. 0,13,12,12,12,13,13,13,14,
  127264. };
  127265. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127266. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127267. 12.5, 17.5, 22.5, 27.5,
  127268. };
  127269. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127270. 11, 9, 7, 5, 3, 1, 0, 2,
  127271. 4, 6, 8, 10, 12,
  127272. };
  127273. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127274. _vq_quantthresh__44cn1_sm_p7_0,
  127275. _vq_quantmap__44cn1_sm_p7_0,
  127276. 13,
  127277. 13
  127278. };
  127279. static static_codebook _44cn1_sm_p7_0 = {
  127280. 2, 169,
  127281. _vq_lengthlist__44cn1_sm_p7_0,
  127282. 1, -526516224, 1616117760, 4, 0,
  127283. _vq_quantlist__44cn1_sm_p7_0,
  127284. NULL,
  127285. &_vq_auxt__44cn1_sm_p7_0,
  127286. NULL,
  127287. 0
  127288. };
  127289. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127290. 2,
  127291. 1,
  127292. 3,
  127293. 0,
  127294. 4,
  127295. };
  127296. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127297. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127298. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127299. };
  127300. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127301. -1.5, -0.5, 0.5, 1.5,
  127302. };
  127303. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127304. 3, 1, 0, 2, 4,
  127305. };
  127306. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127307. _vq_quantthresh__44cn1_sm_p7_1,
  127308. _vq_quantmap__44cn1_sm_p7_1,
  127309. 5,
  127310. 5
  127311. };
  127312. static static_codebook _44cn1_sm_p7_1 = {
  127313. 2, 25,
  127314. _vq_lengthlist__44cn1_sm_p7_1,
  127315. 1, -533725184, 1611661312, 3, 0,
  127316. _vq_quantlist__44cn1_sm_p7_1,
  127317. NULL,
  127318. &_vq_auxt__44cn1_sm_p7_1,
  127319. NULL,
  127320. 0
  127321. };
  127322. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127323. 4,
  127324. 3,
  127325. 5,
  127326. 2,
  127327. 6,
  127328. 1,
  127329. 7,
  127330. 0,
  127331. 8,
  127332. };
  127333. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127334. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127335. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127336. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127337. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127338. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127339. 14,
  127340. };
  127341. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127342. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127343. };
  127344. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127345. 7, 5, 3, 1, 0, 2, 4, 6,
  127346. 8,
  127347. };
  127348. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127349. _vq_quantthresh__44cn1_sm_p8_0,
  127350. _vq_quantmap__44cn1_sm_p8_0,
  127351. 9,
  127352. 9
  127353. };
  127354. static static_codebook _44cn1_sm_p8_0 = {
  127355. 2, 81,
  127356. _vq_lengthlist__44cn1_sm_p8_0,
  127357. 1, -516186112, 1627103232, 4, 0,
  127358. _vq_quantlist__44cn1_sm_p8_0,
  127359. NULL,
  127360. &_vq_auxt__44cn1_sm_p8_0,
  127361. NULL,
  127362. 0
  127363. };
  127364. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127365. 6,
  127366. 5,
  127367. 7,
  127368. 4,
  127369. 8,
  127370. 3,
  127371. 9,
  127372. 2,
  127373. 10,
  127374. 1,
  127375. 11,
  127376. 0,
  127377. 12,
  127378. };
  127379. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127380. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127381. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127382. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127383. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127384. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127385. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127386. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127387. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127388. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127389. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127390. 17,12,12,11,10,13,11,13,13,
  127391. };
  127392. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127393. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127394. 42.5, 59.5, 76.5, 93.5,
  127395. };
  127396. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127397. 11, 9, 7, 5, 3, 1, 0, 2,
  127398. 4, 6, 8, 10, 12,
  127399. };
  127400. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127401. _vq_quantthresh__44cn1_sm_p8_1,
  127402. _vq_quantmap__44cn1_sm_p8_1,
  127403. 13,
  127404. 13
  127405. };
  127406. static static_codebook _44cn1_sm_p8_1 = {
  127407. 2, 169,
  127408. _vq_lengthlist__44cn1_sm_p8_1,
  127409. 1, -522616832, 1620115456, 4, 0,
  127410. _vq_quantlist__44cn1_sm_p8_1,
  127411. NULL,
  127412. &_vq_auxt__44cn1_sm_p8_1,
  127413. NULL,
  127414. 0
  127415. };
  127416. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127417. 8,
  127418. 7,
  127419. 9,
  127420. 6,
  127421. 10,
  127422. 5,
  127423. 11,
  127424. 4,
  127425. 12,
  127426. 3,
  127427. 13,
  127428. 2,
  127429. 14,
  127430. 1,
  127431. 15,
  127432. 0,
  127433. 16,
  127434. };
  127435. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127436. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127437. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127438. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127439. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127440. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127441. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127442. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127443. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127444. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127445. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127446. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127447. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127448. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127449. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127450. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127451. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127452. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127453. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127454. 9,
  127455. };
  127456. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127457. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127458. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127459. };
  127460. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127461. 15, 13, 11, 9, 7, 5, 3, 1,
  127462. 0, 2, 4, 6, 8, 10, 12, 14,
  127463. 16,
  127464. };
  127465. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127466. _vq_quantthresh__44cn1_sm_p8_2,
  127467. _vq_quantmap__44cn1_sm_p8_2,
  127468. 17,
  127469. 17
  127470. };
  127471. static static_codebook _44cn1_sm_p8_2 = {
  127472. 2, 289,
  127473. _vq_lengthlist__44cn1_sm_p8_2,
  127474. 1, -529530880, 1611661312, 5, 0,
  127475. _vq_quantlist__44cn1_sm_p8_2,
  127476. NULL,
  127477. &_vq_auxt__44cn1_sm_p8_2,
  127478. NULL,
  127479. 0
  127480. };
  127481. static long _huff_lengthlist__44cn1_sm_short[] = {
  127482. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127483. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127484. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127485. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127486. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127487. 9,
  127488. };
  127489. static static_codebook _huff_book__44cn1_sm_short = {
  127490. 2, 81,
  127491. _huff_lengthlist__44cn1_sm_short,
  127492. 0, 0, 0, 0, 0,
  127493. NULL,
  127494. NULL,
  127495. NULL,
  127496. NULL,
  127497. 0
  127498. };
  127499. /*** End of inlined file: res_books_stereo.h ***/
  127500. static vorbis_info_residue0 _residue_44_low={
  127501. 0,-1, -1, 9,-1,
  127502. {0},
  127503. {-1},
  127504. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127505. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127506. };
  127507. static vorbis_info_residue0 _residue_44_mid={
  127508. 0,-1, -1, 10,-1,
  127509. {0},
  127510. {-1},
  127511. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127512. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127513. };
  127514. static vorbis_info_residue0 _residue_44_high={
  127515. 0,-1, -1, 10,-1,
  127516. {0},
  127517. {-1},
  127518. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127519. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127520. };
  127521. static static_bookblock _resbook_44s_n1={
  127522. {
  127523. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127524. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127525. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127526. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127527. }
  127528. };
  127529. static static_bookblock _resbook_44sm_n1={
  127530. {
  127531. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127532. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127533. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127534. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127535. }
  127536. };
  127537. static static_bookblock _resbook_44s_0={
  127538. {
  127539. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127540. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127541. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127542. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127543. }
  127544. };
  127545. static static_bookblock _resbook_44sm_0={
  127546. {
  127547. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127548. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127549. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127550. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127551. }
  127552. };
  127553. static static_bookblock _resbook_44s_1={
  127554. {
  127555. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127556. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127557. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127558. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127559. }
  127560. };
  127561. static static_bookblock _resbook_44sm_1={
  127562. {
  127563. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127564. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127565. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127566. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127567. }
  127568. };
  127569. static static_bookblock _resbook_44s_2={
  127570. {
  127571. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127572. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127573. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127574. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127575. }
  127576. };
  127577. static static_bookblock _resbook_44s_3={
  127578. {
  127579. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127580. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127581. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127582. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127583. }
  127584. };
  127585. static static_bookblock _resbook_44s_4={
  127586. {
  127587. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127588. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127589. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127590. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127591. }
  127592. };
  127593. static static_bookblock _resbook_44s_5={
  127594. {
  127595. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127596. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127597. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127598. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127599. }
  127600. };
  127601. static static_bookblock _resbook_44s_6={
  127602. {
  127603. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127604. {0,0,&_44c6_s_p4_0},
  127605. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127606. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127607. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127608. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127609. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127610. }
  127611. };
  127612. static static_bookblock _resbook_44s_7={
  127613. {
  127614. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127615. {0,0,&_44c7_s_p4_0},
  127616. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127617. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127618. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127619. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127620. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127621. }
  127622. };
  127623. static static_bookblock _resbook_44s_8={
  127624. {
  127625. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127626. {0,0,&_44c8_s_p4_0},
  127627. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127628. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127629. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127630. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127631. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127632. }
  127633. };
  127634. static static_bookblock _resbook_44s_9={
  127635. {
  127636. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127637. {0,0,&_44c9_s_p4_0},
  127638. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127639. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127640. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127641. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127642. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127643. }
  127644. };
  127645. static vorbis_residue_template _res_44s_n1[]={
  127646. {2,0, &_residue_44_low,
  127647. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127648. &_resbook_44s_n1,&_resbook_44sm_n1},
  127649. {2,0, &_residue_44_low,
  127650. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127651. &_resbook_44s_n1,&_resbook_44sm_n1}
  127652. };
  127653. static vorbis_residue_template _res_44s_0[]={
  127654. {2,0, &_residue_44_low,
  127655. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127656. &_resbook_44s_0,&_resbook_44sm_0},
  127657. {2,0, &_residue_44_low,
  127658. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127659. &_resbook_44s_0,&_resbook_44sm_0}
  127660. };
  127661. static vorbis_residue_template _res_44s_1[]={
  127662. {2,0, &_residue_44_low,
  127663. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127664. &_resbook_44s_1,&_resbook_44sm_1},
  127665. {2,0, &_residue_44_low,
  127666. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127667. &_resbook_44s_1,&_resbook_44sm_1}
  127668. };
  127669. static vorbis_residue_template _res_44s_2[]={
  127670. {2,0, &_residue_44_mid,
  127671. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127672. &_resbook_44s_2,&_resbook_44s_2},
  127673. {2,0, &_residue_44_mid,
  127674. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127675. &_resbook_44s_2,&_resbook_44s_2}
  127676. };
  127677. static vorbis_residue_template _res_44s_3[]={
  127678. {2,0, &_residue_44_mid,
  127679. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127680. &_resbook_44s_3,&_resbook_44s_3},
  127681. {2,0, &_residue_44_mid,
  127682. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127683. &_resbook_44s_3,&_resbook_44s_3}
  127684. };
  127685. static vorbis_residue_template _res_44s_4[]={
  127686. {2,0, &_residue_44_mid,
  127687. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127688. &_resbook_44s_4,&_resbook_44s_4},
  127689. {2,0, &_residue_44_mid,
  127690. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127691. &_resbook_44s_4,&_resbook_44s_4}
  127692. };
  127693. static vorbis_residue_template _res_44s_5[]={
  127694. {2,0, &_residue_44_mid,
  127695. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127696. &_resbook_44s_5,&_resbook_44s_5},
  127697. {2,0, &_residue_44_mid,
  127698. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127699. &_resbook_44s_5,&_resbook_44s_5}
  127700. };
  127701. static vorbis_residue_template _res_44s_6[]={
  127702. {2,0, &_residue_44_high,
  127703. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127704. &_resbook_44s_6,&_resbook_44s_6},
  127705. {2,0, &_residue_44_high,
  127706. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127707. &_resbook_44s_6,&_resbook_44s_6}
  127708. };
  127709. static vorbis_residue_template _res_44s_7[]={
  127710. {2,0, &_residue_44_high,
  127711. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127712. &_resbook_44s_7,&_resbook_44s_7},
  127713. {2,0, &_residue_44_high,
  127714. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127715. &_resbook_44s_7,&_resbook_44s_7}
  127716. };
  127717. static vorbis_residue_template _res_44s_8[]={
  127718. {2,0, &_residue_44_high,
  127719. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127720. &_resbook_44s_8,&_resbook_44s_8},
  127721. {2,0, &_residue_44_high,
  127722. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127723. &_resbook_44s_8,&_resbook_44s_8}
  127724. };
  127725. static vorbis_residue_template _res_44s_9[]={
  127726. {2,0, &_residue_44_high,
  127727. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127728. &_resbook_44s_9,&_resbook_44s_9},
  127729. {2,0, &_residue_44_high,
  127730. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127731. &_resbook_44s_9,&_resbook_44s_9}
  127732. };
  127733. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127734. { _map_nominal, _res_44s_n1 }, /* -1 */
  127735. { _map_nominal, _res_44s_0 }, /* 0 */
  127736. { _map_nominal, _res_44s_1 }, /* 1 */
  127737. { _map_nominal, _res_44s_2 }, /* 2 */
  127738. { _map_nominal, _res_44s_3 }, /* 3 */
  127739. { _map_nominal, _res_44s_4 }, /* 4 */
  127740. { _map_nominal, _res_44s_5 }, /* 5 */
  127741. { _map_nominal, _res_44s_6 }, /* 6 */
  127742. { _map_nominal, _res_44s_7 }, /* 7 */
  127743. { _map_nominal, _res_44s_8 }, /* 8 */
  127744. { _map_nominal, _res_44s_9 }, /* 9 */
  127745. };
  127746. /*** End of inlined file: residue_44.h ***/
  127747. /*** Start of inlined file: psych_44.h ***/
  127748. static vorbis_info_psy_global _psy_global_44[5]={
  127749. {8, /* lines per eighth octave */
  127750. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127751. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127752. -6.f,
  127753. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127754. },
  127755. {8, /* lines per eighth octave */
  127756. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127757. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127758. -6.f,
  127759. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127760. },
  127761. {8, /* lines per eighth octave */
  127762. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127763. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127764. -6.f,
  127765. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127766. },
  127767. {8, /* lines per eighth octave */
  127768. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127769. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127770. -6.f,
  127771. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127772. },
  127773. {8, /* lines per eighth octave */
  127774. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127775. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127776. -6.f,
  127777. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127778. },
  127779. };
  127780. static compandblock _psy_compand_44[6]={
  127781. {{
  127782. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127783. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127784. 16,17,18,19,20,21,22, 23, /* 23dB */
  127785. 24,25,26,27,28,29,30, 31, /* 31dB */
  127786. 32,33,34,35,36,37,38, 39, /* 39dB */
  127787. }},
  127788. {{
  127789. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127790. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127791. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127792. 15,16,17,17,17,18,18, 19, /* 31dB */
  127793. 19,19,20,21,22,23,24, 25, /* 39dB */
  127794. }},
  127795. {{
  127796. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127797. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127798. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127799. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127800. 11,12,13,14,15,16,17, 18, /* 39dB */
  127801. }},
  127802. {{
  127803. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127804. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127805. 16,17,18,19,20,21,22, 23, /* 23dB */
  127806. 24,25,26,27,28,29,30, 31, /* 31dB */
  127807. 32,33,34,35,36,37,38, 39, /* 39dB */
  127808. }},
  127809. {{
  127810. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127811. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127812. 13,14,14,14,15,15,15, 15, /* 23dB */
  127813. 16,16,17,17,17,18,18, 19, /* 31dB */
  127814. 19,19,20,21,22,23,24, 25, /* 39dB */
  127815. }},
  127816. {{
  127817. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127818. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127819. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127820. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127821. 11,12,13,14,15,16,17, 18, /* 39dB */
  127822. }}
  127823. };
  127824. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127825. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127826. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127827. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127828. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127829. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127830. /* 4 */
  127831. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127832. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127833. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127834. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127835. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127836. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127837. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127838. };
  127839. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127840. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127841. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127842. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127843. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127844. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127845. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127846. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127847. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127848. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127849. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127850. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127851. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127852. };
  127853. static noise3 _psy_noisebias_trans[12]={
  127854. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127855. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127856. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127857. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127858. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127859. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127860. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127861. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127862. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127863. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127864. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127865. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127866. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127867. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127868. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127869. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127870. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127871. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127872. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127873. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127874. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127875. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127876. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127877. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127878. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127879. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127880. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127881. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127882. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127883. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127884. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127885. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127886. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127887. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127888. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127889. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127890. };
  127891. static noise3 _psy_noisebias_long[12]={
  127892. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127893. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127894. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127895. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127896. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127897. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127898. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127899. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127900. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127901. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127902. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127903. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127904. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127905. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127906. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127907. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127908. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127909. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127910. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127911. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127912. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127913. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127914. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127915. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127916. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127917. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  127918. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127919. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  127920. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  127921. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127922. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127923. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  127924. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127925. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  127926. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  127927. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127928. };
  127929. static noise3 _psy_noisebias_impulse[12]={
  127930. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127931. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127932. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127933. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  127934. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  127935. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127936. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127937. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  127938. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  127939. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127940. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127941. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127942. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127943. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127944. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127945. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127946. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127947. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127948. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127949. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  127950. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  127951. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127952. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  127953. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  127954. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  127955. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  127956. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127957. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  127958. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  127959. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127960. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127961. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  127962. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127963. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  127964. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  127965. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127966. };
  127967. static noise3 _psy_noisebias_padding[12]={
  127968. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127969. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127970. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127971. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127972. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  127973. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  127974. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127975. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  127976. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  127977. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127978. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127979. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127980. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127981. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127982. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127983. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127984. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  127985. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127986. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127987. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  127988. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  127989. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127990. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  127991. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  127992. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127993. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  127994. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  127995. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  127996. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  127997. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  127998. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  127999. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128000. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128001. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128002. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128003. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128004. };
  128005. static noiseguard _psy_noiseguards_44[4]={
  128006. {3,3,15},
  128007. {3,3,15},
  128008. {10,10,100},
  128009. {10,10,100},
  128010. };
  128011. static int _psy_tone_suppress[12]={
  128012. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128013. };
  128014. static int _psy_tone_0dB[12]={
  128015. 90,90,95,95,95,95,105,105,105,105,105,105,
  128016. };
  128017. static int _psy_noise_suppress[12]={
  128018. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128019. };
  128020. static vorbis_info_psy _psy_info_template={
  128021. -1,
  128022. -140.,-140.,
  128023. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128024. 1, -0.f, .5f, .5f, 0,0,0,
  128025. {{-1},{-1},{-1}},{-1},105.f,
  128026. 0,0,-1,-1,0.,
  128027. };
  128028. static int _psy_ath_floater[12]={
  128029. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128030. };
  128031. static int _psy_ath_abs[12]={
  128032. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128033. };
  128034. static adj_stereo _psy_stereo_modes_44[12]={
  128035. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128036. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128037. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128038. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128039. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128040. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128041. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128042. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128043. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128044. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128045. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128046. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128047. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128048. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128049. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128050. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128051. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128052. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128053. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128054. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128055. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128056. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128057. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128058. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128059. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128060. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128061. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128062. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128063. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128064. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128065. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128066. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128067. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128068. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128069. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128070. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128071. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128072. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128073. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128074. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128075. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128076. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128077. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128078. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128079. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128080. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128081. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128082. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128083. };
  128084. static att3 _psy_tone_masteratt_44[12]={
  128085. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128086. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128087. /* 1 */
  128088. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128089. /* 2 */
  128090. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128091. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128092. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128093. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128094. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128095. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128096. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128097. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128098. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128099. };
  128100. static double _psy_lowpass_44[12]={
  128101. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128102. };
  128103. static int _noise_start_short_44[11]={
  128104. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128105. };
  128106. static int _noise_start_long_44[11]={
  128107. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128108. };
  128109. static int _noise_part_short_44[11]={
  128110. 8,8,8,8,8,8,8,8,8,8,8
  128111. };
  128112. static int _noise_part_long_44[11]={
  128113. 32,32,32,32,32,32,32,32,32,32,32
  128114. };
  128115. static double _noise_thresh_44[11]={
  128116. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128117. };
  128118. static double _noise_thresh_5only[2]={
  128119. .5,.5,
  128120. };
  128121. /*** End of inlined file: psych_44.h ***/
  128122. static double rate_mapping_44_stereo[12]={
  128123. 22500.,32000.,40000.,48000.,56000.,64000.,
  128124. 80000.,96000.,112000.,128000.,160000.,250001.
  128125. };
  128126. static double quality_mapping_44[12]={
  128127. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128128. };
  128129. static int blocksize_short_44[11]={
  128130. 512,256,256,256,256,256,256,256,256,256,256
  128131. };
  128132. static int blocksize_long_44[11]={
  128133. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128134. };
  128135. static double _psy_compand_short_mapping[12]={
  128136. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128137. };
  128138. static double _psy_compand_long_mapping[12]={
  128139. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128140. };
  128141. static double _global_mapping_44[12]={
  128142. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128143. };
  128144. static int _floor_short_mapping_44[11]={
  128145. 1,0,0,2,2,4,5,5,5,5,5
  128146. };
  128147. static int _floor_long_mapping_44[11]={
  128148. 8,7,7,7,7,7,7,7,7,7,7
  128149. };
  128150. ve_setup_data_template ve_setup_44_stereo={
  128151. 11,
  128152. rate_mapping_44_stereo,
  128153. quality_mapping_44,
  128154. 2,
  128155. 40000,
  128156. 50000,
  128157. blocksize_short_44,
  128158. blocksize_long_44,
  128159. _psy_tone_masteratt_44,
  128160. _psy_tone_0dB,
  128161. _psy_tone_suppress,
  128162. _vp_tonemask_adj_otherblock,
  128163. _vp_tonemask_adj_longblock,
  128164. _vp_tonemask_adj_otherblock,
  128165. _psy_noiseguards_44,
  128166. _psy_noisebias_impulse,
  128167. _psy_noisebias_padding,
  128168. _psy_noisebias_trans,
  128169. _psy_noisebias_long,
  128170. _psy_noise_suppress,
  128171. _psy_compand_44,
  128172. _psy_compand_short_mapping,
  128173. _psy_compand_long_mapping,
  128174. {_noise_start_short_44,_noise_start_long_44},
  128175. {_noise_part_short_44,_noise_part_long_44},
  128176. _noise_thresh_44,
  128177. _psy_ath_floater,
  128178. _psy_ath_abs,
  128179. _psy_lowpass_44,
  128180. _psy_global_44,
  128181. _global_mapping_44,
  128182. _psy_stereo_modes_44,
  128183. _floor_books,
  128184. _floor,
  128185. _floor_short_mapping_44,
  128186. _floor_long_mapping_44,
  128187. _mapres_template_44_stereo
  128188. };
  128189. /*** End of inlined file: setup_44.h ***/
  128190. /*** Start of inlined file: setup_44u.h ***/
  128191. /*** Start of inlined file: residue_44u.h ***/
  128192. /*** Start of inlined file: res_books_uncoupled.h ***/
  128193. static long _vq_quantlist__16u0__p1_0[] = {
  128194. 1,
  128195. 0,
  128196. 2,
  128197. };
  128198. static long _vq_lengthlist__16u0__p1_0[] = {
  128199. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128200. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128201. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128202. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128203. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128204. 12,
  128205. };
  128206. static float _vq_quantthresh__16u0__p1_0[] = {
  128207. -0.5, 0.5,
  128208. };
  128209. static long _vq_quantmap__16u0__p1_0[] = {
  128210. 1, 0, 2,
  128211. };
  128212. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128213. _vq_quantthresh__16u0__p1_0,
  128214. _vq_quantmap__16u0__p1_0,
  128215. 3,
  128216. 3
  128217. };
  128218. static static_codebook _16u0__p1_0 = {
  128219. 4, 81,
  128220. _vq_lengthlist__16u0__p1_0,
  128221. 1, -535822336, 1611661312, 2, 0,
  128222. _vq_quantlist__16u0__p1_0,
  128223. NULL,
  128224. &_vq_auxt__16u0__p1_0,
  128225. NULL,
  128226. 0
  128227. };
  128228. static long _vq_quantlist__16u0__p2_0[] = {
  128229. 1,
  128230. 0,
  128231. 2,
  128232. };
  128233. static long _vq_lengthlist__16u0__p2_0[] = {
  128234. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128235. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128236. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128237. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128238. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128239. 8,
  128240. };
  128241. static float _vq_quantthresh__16u0__p2_0[] = {
  128242. -0.5, 0.5,
  128243. };
  128244. static long _vq_quantmap__16u0__p2_0[] = {
  128245. 1, 0, 2,
  128246. };
  128247. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128248. _vq_quantthresh__16u0__p2_0,
  128249. _vq_quantmap__16u0__p2_0,
  128250. 3,
  128251. 3
  128252. };
  128253. static static_codebook _16u0__p2_0 = {
  128254. 4, 81,
  128255. _vq_lengthlist__16u0__p2_0,
  128256. 1, -535822336, 1611661312, 2, 0,
  128257. _vq_quantlist__16u0__p2_0,
  128258. NULL,
  128259. &_vq_auxt__16u0__p2_0,
  128260. NULL,
  128261. 0
  128262. };
  128263. static long _vq_quantlist__16u0__p3_0[] = {
  128264. 2,
  128265. 1,
  128266. 3,
  128267. 0,
  128268. 4,
  128269. };
  128270. static long _vq_lengthlist__16u0__p3_0[] = {
  128271. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128272. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128273. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128274. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128275. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128276. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128277. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128278. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128279. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128280. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128281. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128282. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128283. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128284. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128285. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128286. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128287. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128288. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128289. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128290. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128291. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128292. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128293. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128294. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128295. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128296. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128297. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128298. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128299. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128300. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128301. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128302. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128303. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128304. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128305. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128306. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128307. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128308. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128309. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128310. 18,
  128311. };
  128312. static float _vq_quantthresh__16u0__p3_0[] = {
  128313. -1.5, -0.5, 0.5, 1.5,
  128314. };
  128315. static long _vq_quantmap__16u0__p3_0[] = {
  128316. 3, 1, 0, 2, 4,
  128317. };
  128318. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128319. _vq_quantthresh__16u0__p3_0,
  128320. _vq_quantmap__16u0__p3_0,
  128321. 5,
  128322. 5
  128323. };
  128324. static static_codebook _16u0__p3_0 = {
  128325. 4, 625,
  128326. _vq_lengthlist__16u0__p3_0,
  128327. 1, -533725184, 1611661312, 3, 0,
  128328. _vq_quantlist__16u0__p3_0,
  128329. NULL,
  128330. &_vq_auxt__16u0__p3_0,
  128331. NULL,
  128332. 0
  128333. };
  128334. static long _vq_quantlist__16u0__p4_0[] = {
  128335. 2,
  128336. 1,
  128337. 3,
  128338. 0,
  128339. 4,
  128340. };
  128341. static long _vq_lengthlist__16u0__p4_0[] = {
  128342. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128343. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128344. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128345. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128346. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128347. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128348. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128349. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128350. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128351. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128352. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128353. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128354. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128355. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128356. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128357. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128358. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128359. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128360. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128361. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128362. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128363. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128364. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128365. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128366. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128367. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128368. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128369. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128370. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128371. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128372. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128373. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128374. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128375. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128376. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128377. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128378. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128379. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128380. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128381. 11,
  128382. };
  128383. static float _vq_quantthresh__16u0__p4_0[] = {
  128384. -1.5, -0.5, 0.5, 1.5,
  128385. };
  128386. static long _vq_quantmap__16u0__p4_0[] = {
  128387. 3, 1, 0, 2, 4,
  128388. };
  128389. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128390. _vq_quantthresh__16u0__p4_0,
  128391. _vq_quantmap__16u0__p4_0,
  128392. 5,
  128393. 5
  128394. };
  128395. static static_codebook _16u0__p4_0 = {
  128396. 4, 625,
  128397. _vq_lengthlist__16u0__p4_0,
  128398. 1, -533725184, 1611661312, 3, 0,
  128399. _vq_quantlist__16u0__p4_0,
  128400. NULL,
  128401. &_vq_auxt__16u0__p4_0,
  128402. NULL,
  128403. 0
  128404. };
  128405. static long _vq_quantlist__16u0__p5_0[] = {
  128406. 4,
  128407. 3,
  128408. 5,
  128409. 2,
  128410. 6,
  128411. 1,
  128412. 7,
  128413. 0,
  128414. 8,
  128415. };
  128416. static long _vq_lengthlist__16u0__p5_0[] = {
  128417. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128418. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128419. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128420. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128421. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128422. 12,
  128423. };
  128424. static float _vq_quantthresh__16u0__p5_0[] = {
  128425. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128426. };
  128427. static long _vq_quantmap__16u0__p5_0[] = {
  128428. 7, 5, 3, 1, 0, 2, 4, 6,
  128429. 8,
  128430. };
  128431. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128432. _vq_quantthresh__16u0__p5_0,
  128433. _vq_quantmap__16u0__p5_0,
  128434. 9,
  128435. 9
  128436. };
  128437. static static_codebook _16u0__p5_0 = {
  128438. 2, 81,
  128439. _vq_lengthlist__16u0__p5_0,
  128440. 1, -531628032, 1611661312, 4, 0,
  128441. _vq_quantlist__16u0__p5_0,
  128442. NULL,
  128443. &_vq_auxt__16u0__p5_0,
  128444. NULL,
  128445. 0
  128446. };
  128447. static long _vq_quantlist__16u0__p6_0[] = {
  128448. 6,
  128449. 5,
  128450. 7,
  128451. 4,
  128452. 8,
  128453. 3,
  128454. 9,
  128455. 2,
  128456. 10,
  128457. 1,
  128458. 11,
  128459. 0,
  128460. 12,
  128461. };
  128462. static long _vq_lengthlist__16u0__p6_0[] = {
  128463. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128464. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128465. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128466. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128467. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128468. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128469. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128470. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128471. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128472. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128473. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128474. };
  128475. static float _vq_quantthresh__16u0__p6_0[] = {
  128476. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128477. 12.5, 17.5, 22.5, 27.5,
  128478. };
  128479. static long _vq_quantmap__16u0__p6_0[] = {
  128480. 11, 9, 7, 5, 3, 1, 0, 2,
  128481. 4, 6, 8, 10, 12,
  128482. };
  128483. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128484. _vq_quantthresh__16u0__p6_0,
  128485. _vq_quantmap__16u0__p6_0,
  128486. 13,
  128487. 13
  128488. };
  128489. static static_codebook _16u0__p6_0 = {
  128490. 2, 169,
  128491. _vq_lengthlist__16u0__p6_0,
  128492. 1, -526516224, 1616117760, 4, 0,
  128493. _vq_quantlist__16u0__p6_0,
  128494. NULL,
  128495. &_vq_auxt__16u0__p6_0,
  128496. NULL,
  128497. 0
  128498. };
  128499. static long _vq_quantlist__16u0__p6_1[] = {
  128500. 2,
  128501. 1,
  128502. 3,
  128503. 0,
  128504. 4,
  128505. };
  128506. static long _vq_lengthlist__16u0__p6_1[] = {
  128507. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128508. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128509. };
  128510. static float _vq_quantthresh__16u0__p6_1[] = {
  128511. -1.5, -0.5, 0.5, 1.5,
  128512. };
  128513. static long _vq_quantmap__16u0__p6_1[] = {
  128514. 3, 1, 0, 2, 4,
  128515. };
  128516. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128517. _vq_quantthresh__16u0__p6_1,
  128518. _vq_quantmap__16u0__p6_1,
  128519. 5,
  128520. 5
  128521. };
  128522. static static_codebook _16u0__p6_1 = {
  128523. 2, 25,
  128524. _vq_lengthlist__16u0__p6_1,
  128525. 1, -533725184, 1611661312, 3, 0,
  128526. _vq_quantlist__16u0__p6_1,
  128527. NULL,
  128528. &_vq_auxt__16u0__p6_1,
  128529. NULL,
  128530. 0
  128531. };
  128532. static long _vq_quantlist__16u0__p7_0[] = {
  128533. 1,
  128534. 0,
  128535. 2,
  128536. };
  128537. static long _vq_lengthlist__16u0__p7_0[] = {
  128538. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128539. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128540. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128541. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128542. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128543. 7,
  128544. };
  128545. static float _vq_quantthresh__16u0__p7_0[] = {
  128546. -157.5, 157.5,
  128547. };
  128548. static long _vq_quantmap__16u0__p7_0[] = {
  128549. 1, 0, 2,
  128550. };
  128551. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128552. _vq_quantthresh__16u0__p7_0,
  128553. _vq_quantmap__16u0__p7_0,
  128554. 3,
  128555. 3
  128556. };
  128557. static static_codebook _16u0__p7_0 = {
  128558. 4, 81,
  128559. _vq_lengthlist__16u0__p7_0,
  128560. 1, -518803456, 1628680192, 2, 0,
  128561. _vq_quantlist__16u0__p7_0,
  128562. NULL,
  128563. &_vq_auxt__16u0__p7_0,
  128564. NULL,
  128565. 0
  128566. };
  128567. static long _vq_quantlist__16u0__p7_1[] = {
  128568. 7,
  128569. 6,
  128570. 8,
  128571. 5,
  128572. 9,
  128573. 4,
  128574. 10,
  128575. 3,
  128576. 11,
  128577. 2,
  128578. 12,
  128579. 1,
  128580. 13,
  128581. 0,
  128582. 14,
  128583. };
  128584. static long _vq_lengthlist__16u0__p7_1[] = {
  128585. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128586. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128587. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128588. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128589. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128590. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128591. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128592. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128593. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128594. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128595. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128596. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128597. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128598. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128599. 10,
  128600. };
  128601. static float _vq_quantthresh__16u0__p7_1[] = {
  128602. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128603. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128604. };
  128605. static long _vq_quantmap__16u0__p7_1[] = {
  128606. 13, 11, 9, 7, 5, 3, 1, 0,
  128607. 2, 4, 6, 8, 10, 12, 14,
  128608. };
  128609. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128610. _vq_quantthresh__16u0__p7_1,
  128611. _vq_quantmap__16u0__p7_1,
  128612. 15,
  128613. 15
  128614. };
  128615. static static_codebook _16u0__p7_1 = {
  128616. 2, 225,
  128617. _vq_lengthlist__16u0__p7_1,
  128618. 1, -520986624, 1620377600, 4, 0,
  128619. _vq_quantlist__16u0__p7_1,
  128620. NULL,
  128621. &_vq_auxt__16u0__p7_1,
  128622. NULL,
  128623. 0
  128624. };
  128625. static long _vq_quantlist__16u0__p7_2[] = {
  128626. 10,
  128627. 9,
  128628. 11,
  128629. 8,
  128630. 12,
  128631. 7,
  128632. 13,
  128633. 6,
  128634. 14,
  128635. 5,
  128636. 15,
  128637. 4,
  128638. 16,
  128639. 3,
  128640. 17,
  128641. 2,
  128642. 18,
  128643. 1,
  128644. 19,
  128645. 0,
  128646. 20,
  128647. };
  128648. static long _vq_lengthlist__16u0__p7_2[] = {
  128649. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128650. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128651. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128652. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128653. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128654. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128655. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128656. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128657. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128658. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128659. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128660. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128661. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128662. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128663. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128664. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128665. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128666. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128667. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128668. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128669. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128670. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128671. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128672. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128673. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128674. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128675. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128676. 10,10,12,11,10,11,11,11,10,
  128677. };
  128678. static float _vq_quantthresh__16u0__p7_2[] = {
  128679. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128680. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128681. 6.5, 7.5, 8.5, 9.5,
  128682. };
  128683. static long _vq_quantmap__16u0__p7_2[] = {
  128684. 19, 17, 15, 13, 11, 9, 7, 5,
  128685. 3, 1, 0, 2, 4, 6, 8, 10,
  128686. 12, 14, 16, 18, 20,
  128687. };
  128688. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128689. _vq_quantthresh__16u0__p7_2,
  128690. _vq_quantmap__16u0__p7_2,
  128691. 21,
  128692. 21
  128693. };
  128694. static static_codebook _16u0__p7_2 = {
  128695. 2, 441,
  128696. _vq_lengthlist__16u0__p7_2,
  128697. 1, -529268736, 1611661312, 5, 0,
  128698. _vq_quantlist__16u0__p7_2,
  128699. NULL,
  128700. &_vq_auxt__16u0__p7_2,
  128701. NULL,
  128702. 0
  128703. };
  128704. static long _huff_lengthlist__16u0__single[] = {
  128705. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128706. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128707. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128708. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128709. };
  128710. static static_codebook _huff_book__16u0__single = {
  128711. 2, 64,
  128712. _huff_lengthlist__16u0__single,
  128713. 0, 0, 0, 0, 0,
  128714. NULL,
  128715. NULL,
  128716. NULL,
  128717. NULL,
  128718. 0
  128719. };
  128720. static long _huff_lengthlist__16u1__long[] = {
  128721. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128722. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128723. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128724. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128725. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128726. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128727. 16,13,16,18,
  128728. };
  128729. static static_codebook _huff_book__16u1__long = {
  128730. 2, 100,
  128731. _huff_lengthlist__16u1__long,
  128732. 0, 0, 0, 0, 0,
  128733. NULL,
  128734. NULL,
  128735. NULL,
  128736. NULL,
  128737. 0
  128738. };
  128739. static long _vq_quantlist__16u1__p1_0[] = {
  128740. 1,
  128741. 0,
  128742. 2,
  128743. };
  128744. static long _vq_lengthlist__16u1__p1_0[] = {
  128745. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128746. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128747. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128748. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128749. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128750. 11,
  128751. };
  128752. static float _vq_quantthresh__16u1__p1_0[] = {
  128753. -0.5, 0.5,
  128754. };
  128755. static long _vq_quantmap__16u1__p1_0[] = {
  128756. 1, 0, 2,
  128757. };
  128758. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128759. _vq_quantthresh__16u1__p1_0,
  128760. _vq_quantmap__16u1__p1_0,
  128761. 3,
  128762. 3
  128763. };
  128764. static static_codebook _16u1__p1_0 = {
  128765. 4, 81,
  128766. _vq_lengthlist__16u1__p1_0,
  128767. 1, -535822336, 1611661312, 2, 0,
  128768. _vq_quantlist__16u1__p1_0,
  128769. NULL,
  128770. &_vq_auxt__16u1__p1_0,
  128771. NULL,
  128772. 0
  128773. };
  128774. static long _vq_quantlist__16u1__p2_0[] = {
  128775. 1,
  128776. 0,
  128777. 2,
  128778. };
  128779. static long _vq_lengthlist__16u1__p2_0[] = {
  128780. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128781. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128782. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128783. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128784. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128785. 8,
  128786. };
  128787. static float _vq_quantthresh__16u1__p2_0[] = {
  128788. -0.5, 0.5,
  128789. };
  128790. static long _vq_quantmap__16u1__p2_0[] = {
  128791. 1, 0, 2,
  128792. };
  128793. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128794. _vq_quantthresh__16u1__p2_0,
  128795. _vq_quantmap__16u1__p2_0,
  128796. 3,
  128797. 3
  128798. };
  128799. static static_codebook _16u1__p2_0 = {
  128800. 4, 81,
  128801. _vq_lengthlist__16u1__p2_0,
  128802. 1, -535822336, 1611661312, 2, 0,
  128803. _vq_quantlist__16u1__p2_0,
  128804. NULL,
  128805. &_vq_auxt__16u1__p2_0,
  128806. NULL,
  128807. 0
  128808. };
  128809. static long _vq_quantlist__16u1__p3_0[] = {
  128810. 2,
  128811. 1,
  128812. 3,
  128813. 0,
  128814. 4,
  128815. };
  128816. static long _vq_lengthlist__16u1__p3_0[] = {
  128817. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128818. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128819. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128820. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128821. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128822. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128823. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128824. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128825. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128826. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128827. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128828. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128829. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128830. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128831. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128832. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128833. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128834. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128835. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128836. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128837. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128838. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128839. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128840. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128841. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128842. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128843. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128844. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128845. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128846. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128847. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128848. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128849. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128850. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128851. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128852. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128853. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128854. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128855. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128856. 16,
  128857. };
  128858. static float _vq_quantthresh__16u1__p3_0[] = {
  128859. -1.5, -0.5, 0.5, 1.5,
  128860. };
  128861. static long _vq_quantmap__16u1__p3_0[] = {
  128862. 3, 1, 0, 2, 4,
  128863. };
  128864. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128865. _vq_quantthresh__16u1__p3_0,
  128866. _vq_quantmap__16u1__p3_0,
  128867. 5,
  128868. 5
  128869. };
  128870. static static_codebook _16u1__p3_0 = {
  128871. 4, 625,
  128872. _vq_lengthlist__16u1__p3_0,
  128873. 1, -533725184, 1611661312, 3, 0,
  128874. _vq_quantlist__16u1__p3_0,
  128875. NULL,
  128876. &_vq_auxt__16u1__p3_0,
  128877. NULL,
  128878. 0
  128879. };
  128880. static long _vq_quantlist__16u1__p4_0[] = {
  128881. 2,
  128882. 1,
  128883. 3,
  128884. 0,
  128885. 4,
  128886. };
  128887. static long _vq_lengthlist__16u1__p4_0[] = {
  128888. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128889. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128890. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128891. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128892. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128893. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128894. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128895. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128896. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128897. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128898. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128899. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128900. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128901. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128902. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128903. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128904. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128905. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128906. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128907. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128908. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128909. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128910. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128911. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128912. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128913. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128914. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128915. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128916. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  128917. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  128918. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  128919. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  128920. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  128921. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  128922. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  128923. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  128924. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  128925. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  128926. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  128927. 11,
  128928. };
  128929. static float _vq_quantthresh__16u1__p4_0[] = {
  128930. -1.5, -0.5, 0.5, 1.5,
  128931. };
  128932. static long _vq_quantmap__16u1__p4_0[] = {
  128933. 3, 1, 0, 2, 4,
  128934. };
  128935. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  128936. _vq_quantthresh__16u1__p4_0,
  128937. _vq_quantmap__16u1__p4_0,
  128938. 5,
  128939. 5
  128940. };
  128941. static static_codebook _16u1__p4_0 = {
  128942. 4, 625,
  128943. _vq_lengthlist__16u1__p4_0,
  128944. 1, -533725184, 1611661312, 3, 0,
  128945. _vq_quantlist__16u1__p4_0,
  128946. NULL,
  128947. &_vq_auxt__16u1__p4_0,
  128948. NULL,
  128949. 0
  128950. };
  128951. static long _vq_quantlist__16u1__p5_0[] = {
  128952. 4,
  128953. 3,
  128954. 5,
  128955. 2,
  128956. 6,
  128957. 1,
  128958. 7,
  128959. 0,
  128960. 8,
  128961. };
  128962. static long _vq_lengthlist__16u1__p5_0[] = {
  128963. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128964. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  128965. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  128966. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  128967. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  128968. 13,
  128969. };
  128970. static float _vq_quantthresh__16u1__p5_0[] = {
  128971. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128972. };
  128973. static long _vq_quantmap__16u1__p5_0[] = {
  128974. 7, 5, 3, 1, 0, 2, 4, 6,
  128975. 8,
  128976. };
  128977. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  128978. _vq_quantthresh__16u1__p5_0,
  128979. _vq_quantmap__16u1__p5_0,
  128980. 9,
  128981. 9
  128982. };
  128983. static static_codebook _16u1__p5_0 = {
  128984. 2, 81,
  128985. _vq_lengthlist__16u1__p5_0,
  128986. 1, -531628032, 1611661312, 4, 0,
  128987. _vq_quantlist__16u1__p5_0,
  128988. NULL,
  128989. &_vq_auxt__16u1__p5_0,
  128990. NULL,
  128991. 0
  128992. };
  128993. static long _vq_quantlist__16u1__p6_0[] = {
  128994. 4,
  128995. 3,
  128996. 5,
  128997. 2,
  128998. 6,
  128999. 1,
  129000. 7,
  129001. 0,
  129002. 8,
  129003. };
  129004. static long _vq_lengthlist__16u1__p6_0[] = {
  129005. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129006. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129007. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129008. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129009. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129010. 11,
  129011. };
  129012. static float _vq_quantthresh__16u1__p6_0[] = {
  129013. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129014. };
  129015. static long _vq_quantmap__16u1__p6_0[] = {
  129016. 7, 5, 3, 1, 0, 2, 4, 6,
  129017. 8,
  129018. };
  129019. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129020. _vq_quantthresh__16u1__p6_0,
  129021. _vq_quantmap__16u1__p6_0,
  129022. 9,
  129023. 9
  129024. };
  129025. static static_codebook _16u1__p6_0 = {
  129026. 2, 81,
  129027. _vq_lengthlist__16u1__p6_0,
  129028. 1, -531628032, 1611661312, 4, 0,
  129029. _vq_quantlist__16u1__p6_0,
  129030. NULL,
  129031. &_vq_auxt__16u1__p6_0,
  129032. NULL,
  129033. 0
  129034. };
  129035. static long _vq_quantlist__16u1__p7_0[] = {
  129036. 1,
  129037. 0,
  129038. 2,
  129039. };
  129040. static long _vq_lengthlist__16u1__p7_0[] = {
  129041. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129042. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129043. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129044. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129045. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129046. 13,
  129047. };
  129048. static float _vq_quantthresh__16u1__p7_0[] = {
  129049. -5.5, 5.5,
  129050. };
  129051. static long _vq_quantmap__16u1__p7_0[] = {
  129052. 1, 0, 2,
  129053. };
  129054. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129055. _vq_quantthresh__16u1__p7_0,
  129056. _vq_quantmap__16u1__p7_0,
  129057. 3,
  129058. 3
  129059. };
  129060. static static_codebook _16u1__p7_0 = {
  129061. 4, 81,
  129062. _vq_lengthlist__16u1__p7_0,
  129063. 1, -529137664, 1618345984, 2, 0,
  129064. _vq_quantlist__16u1__p7_0,
  129065. NULL,
  129066. &_vq_auxt__16u1__p7_0,
  129067. NULL,
  129068. 0
  129069. };
  129070. static long _vq_quantlist__16u1__p7_1[] = {
  129071. 5,
  129072. 4,
  129073. 6,
  129074. 3,
  129075. 7,
  129076. 2,
  129077. 8,
  129078. 1,
  129079. 9,
  129080. 0,
  129081. 10,
  129082. };
  129083. static long _vq_lengthlist__16u1__p7_1[] = {
  129084. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129085. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129086. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129087. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129088. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129089. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129090. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129091. 8, 9, 9,10,10,10,10,10,10,
  129092. };
  129093. static float _vq_quantthresh__16u1__p7_1[] = {
  129094. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129095. 3.5, 4.5,
  129096. };
  129097. static long _vq_quantmap__16u1__p7_1[] = {
  129098. 9, 7, 5, 3, 1, 0, 2, 4,
  129099. 6, 8, 10,
  129100. };
  129101. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129102. _vq_quantthresh__16u1__p7_1,
  129103. _vq_quantmap__16u1__p7_1,
  129104. 11,
  129105. 11
  129106. };
  129107. static static_codebook _16u1__p7_1 = {
  129108. 2, 121,
  129109. _vq_lengthlist__16u1__p7_1,
  129110. 1, -531365888, 1611661312, 4, 0,
  129111. _vq_quantlist__16u1__p7_1,
  129112. NULL,
  129113. &_vq_auxt__16u1__p7_1,
  129114. NULL,
  129115. 0
  129116. };
  129117. static long _vq_quantlist__16u1__p8_0[] = {
  129118. 5,
  129119. 4,
  129120. 6,
  129121. 3,
  129122. 7,
  129123. 2,
  129124. 8,
  129125. 1,
  129126. 9,
  129127. 0,
  129128. 10,
  129129. };
  129130. static long _vq_lengthlist__16u1__p8_0[] = {
  129131. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129132. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129133. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129134. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129135. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129136. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129137. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129138. 13,14,14,15,15,16,16,15,16,
  129139. };
  129140. static float _vq_quantthresh__16u1__p8_0[] = {
  129141. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129142. 38.5, 49.5,
  129143. };
  129144. static long _vq_quantmap__16u1__p8_0[] = {
  129145. 9, 7, 5, 3, 1, 0, 2, 4,
  129146. 6, 8, 10,
  129147. };
  129148. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129149. _vq_quantthresh__16u1__p8_0,
  129150. _vq_quantmap__16u1__p8_0,
  129151. 11,
  129152. 11
  129153. };
  129154. static static_codebook _16u1__p8_0 = {
  129155. 2, 121,
  129156. _vq_lengthlist__16u1__p8_0,
  129157. 1, -524582912, 1618345984, 4, 0,
  129158. _vq_quantlist__16u1__p8_0,
  129159. NULL,
  129160. &_vq_auxt__16u1__p8_0,
  129161. NULL,
  129162. 0
  129163. };
  129164. static long _vq_quantlist__16u1__p8_1[] = {
  129165. 5,
  129166. 4,
  129167. 6,
  129168. 3,
  129169. 7,
  129170. 2,
  129171. 8,
  129172. 1,
  129173. 9,
  129174. 0,
  129175. 10,
  129176. };
  129177. static long _vq_lengthlist__16u1__p8_1[] = {
  129178. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129179. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129180. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129181. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129182. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129183. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129184. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129185. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129186. };
  129187. static float _vq_quantthresh__16u1__p8_1[] = {
  129188. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129189. 3.5, 4.5,
  129190. };
  129191. static long _vq_quantmap__16u1__p8_1[] = {
  129192. 9, 7, 5, 3, 1, 0, 2, 4,
  129193. 6, 8, 10,
  129194. };
  129195. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129196. _vq_quantthresh__16u1__p8_1,
  129197. _vq_quantmap__16u1__p8_1,
  129198. 11,
  129199. 11
  129200. };
  129201. static static_codebook _16u1__p8_1 = {
  129202. 2, 121,
  129203. _vq_lengthlist__16u1__p8_1,
  129204. 1, -531365888, 1611661312, 4, 0,
  129205. _vq_quantlist__16u1__p8_1,
  129206. NULL,
  129207. &_vq_auxt__16u1__p8_1,
  129208. NULL,
  129209. 0
  129210. };
  129211. static long _vq_quantlist__16u1__p9_0[] = {
  129212. 7,
  129213. 6,
  129214. 8,
  129215. 5,
  129216. 9,
  129217. 4,
  129218. 10,
  129219. 3,
  129220. 11,
  129221. 2,
  129222. 12,
  129223. 1,
  129224. 13,
  129225. 0,
  129226. 14,
  129227. };
  129228. static long _vq_lengthlist__16u1__p9_0[] = {
  129229. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129230. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129231. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129232. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129233. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129234. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129235. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129236. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129237. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129238. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129239. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129240. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129241. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129242. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129243. 8,
  129244. };
  129245. static float _vq_quantthresh__16u1__p9_0[] = {
  129246. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129247. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129248. };
  129249. static long _vq_quantmap__16u1__p9_0[] = {
  129250. 13, 11, 9, 7, 5, 3, 1, 0,
  129251. 2, 4, 6, 8, 10, 12, 14,
  129252. };
  129253. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129254. _vq_quantthresh__16u1__p9_0,
  129255. _vq_quantmap__16u1__p9_0,
  129256. 15,
  129257. 15
  129258. };
  129259. static static_codebook _16u1__p9_0 = {
  129260. 2, 225,
  129261. _vq_lengthlist__16u1__p9_0,
  129262. 1, -514071552, 1627381760, 4, 0,
  129263. _vq_quantlist__16u1__p9_0,
  129264. NULL,
  129265. &_vq_auxt__16u1__p9_0,
  129266. NULL,
  129267. 0
  129268. };
  129269. static long _vq_quantlist__16u1__p9_1[] = {
  129270. 7,
  129271. 6,
  129272. 8,
  129273. 5,
  129274. 9,
  129275. 4,
  129276. 10,
  129277. 3,
  129278. 11,
  129279. 2,
  129280. 12,
  129281. 1,
  129282. 13,
  129283. 0,
  129284. 14,
  129285. };
  129286. static long _vq_lengthlist__16u1__p9_1[] = {
  129287. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129288. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129289. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129290. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129291. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129292. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129293. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129294. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129295. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129297. 10,10,10,10,10,10,10,10, 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,
  129302. };
  129303. static float _vq_quantthresh__16u1__p9_1[] = {
  129304. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129305. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129306. };
  129307. static long _vq_quantmap__16u1__p9_1[] = {
  129308. 13, 11, 9, 7, 5, 3, 1, 0,
  129309. 2, 4, 6, 8, 10, 12, 14,
  129310. };
  129311. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129312. _vq_quantthresh__16u1__p9_1,
  129313. _vq_quantmap__16u1__p9_1,
  129314. 15,
  129315. 15
  129316. };
  129317. static static_codebook _16u1__p9_1 = {
  129318. 2, 225,
  129319. _vq_lengthlist__16u1__p9_1,
  129320. 1, -522338304, 1620115456, 4, 0,
  129321. _vq_quantlist__16u1__p9_1,
  129322. NULL,
  129323. &_vq_auxt__16u1__p9_1,
  129324. NULL,
  129325. 0
  129326. };
  129327. static long _vq_quantlist__16u1__p9_2[] = {
  129328. 8,
  129329. 7,
  129330. 9,
  129331. 6,
  129332. 10,
  129333. 5,
  129334. 11,
  129335. 4,
  129336. 12,
  129337. 3,
  129338. 13,
  129339. 2,
  129340. 14,
  129341. 1,
  129342. 15,
  129343. 0,
  129344. 16,
  129345. };
  129346. static long _vq_lengthlist__16u1__p9_2[] = {
  129347. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129348. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129349. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129350. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129351. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129352. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129353. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129354. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129355. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129356. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129357. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129358. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129359. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129360. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129361. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129362. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129363. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129364. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129365. 10,
  129366. };
  129367. static float _vq_quantthresh__16u1__p9_2[] = {
  129368. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129369. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129370. };
  129371. static long _vq_quantmap__16u1__p9_2[] = {
  129372. 15, 13, 11, 9, 7, 5, 3, 1,
  129373. 0, 2, 4, 6, 8, 10, 12, 14,
  129374. 16,
  129375. };
  129376. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129377. _vq_quantthresh__16u1__p9_2,
  129378. _vq_quantmap__16u1__p9_2,
  129379. 17,
  129380. 17
  129381. };
  129382. static static_codebook _16u1__p9_2 = {
  129383. 2, 289,
  129384. _vq_lengthlist__16u1__p9_2,
  129385. 1, -529530880, 1611661312, 5, 0,
  129386. _vq_quantlist__16u1__p9_2,
  129387. NULL,
  129388. &_vq_auxt__16u1__p9_2,
  129389. NULL,
  129390. 0
  129391. };
  129392. static long _huff_lengthlist__16u1__short[] = {
  129393. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129394. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129395. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129396. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129397. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129398. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129399. 16,16,16,16,
  129400. };
  129401. static static_codebook _huff_book__16u1__short = {
  129402. 2, 100,
  129403. _huff_lengthlist__16u1__short,
  129404. 0, 0, 0, 0, 0,
  129405. NULL,
  129406. NULL,
  129407. NULL,
  129408. NULL,
  129409. 0
  129410. };
  129411. static long _huff_lengthlist__16u2__long[] = {
  129412. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129413. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129414. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129415. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129416. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129417. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129418. 13,14,18,18,
  129419. };
  129420. static static_codebook _huff_book__16u2__long = {
  129421. 2, 100,
  129422. _huff_lengthlist__16u2__long,
  129423. 0, 0, 0, 0, 0,
  129424. NULL,
  129425. NULL,
  129426. NULL,
  129427. NULL,
  129428. 0
  129429. };
  129430. static long _huff_lengthlist__16u2__short[] = {
  129431. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129432. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129433. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129434. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129435. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129436. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129437. 16,16,16,16,
  129438. };
  129439. static static_codebook _huff_book__16u2__short = {
  129440. 2, 100,
  129441. _huff_lengthlist__16u2__short,
  129442. 0, 0, 0, 0, 0,
  129443. NULL,
  129444. NULL,
  129445. NULL,
  129446. NULL,
  129447. 0
  129448. };
  129449. static long _vq_quantlist__16u2_p1_0[] = {
  129450. 1,
  129451. 0,
  129452. 2,
  129453. };
  129454. static long _vq_lengthlist__16u2_p1_0[] = {
  129455. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129456. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129457. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129458. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129459. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129460. 10,
  129461. };
  129462. static float _vq_quantthresh__16u2_p1_0[] = {
  129463. -0.5, 0.5,
  129464. };
  129465. static long _vq_quantmap__16u2_p1_0[] = {
  129466. 1, 0, 2,
  129467. };
  129468. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129469. _vq_quantthresh__16u2_p1_0,
  129470. _vq_quantmap__16u2_p1_0,
  129471. 3,
  129472. 3
  129473. };
  129474. static static_codebook _16u2_p1_0 = {
  129475. 4, 81,
  129476. _vq_lengthlist__16u2_p1_0,
  129477. 1, -535822336, 1611661312, 2, 0,
  129478. _vq_quantlist__16u2_p1_0,
  129479. NULL,
  129480. &_vq_auxt__16u2_p1_0,
  129481. NULL,
  129482. 0
  129483. };
  129484. static long _vq_quantlist__16u2_p2_0[] = {
  129485. 2,
  129486. 1,
  129487. 3,
  129488. 0,
  129489. 4,
  129490. };
  129491. static long _vq_lengthlist__16u2_p2_0[] = {
  129492. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129493. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129494. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129495. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129496. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129497. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129498. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129499. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129500. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129501. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129502. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129503. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129504. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129505. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129506. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129507. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129508. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129509. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129510. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129511. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129512. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129513. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129514. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129515. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129516. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129517. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129518. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129519. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129520. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129521. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129522. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129523. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129524. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129525. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129526. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129527. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129528. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129529. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129530. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129531. 13,
  129532. };
  129533. static float _vq_quantthresh__16u2_p2_0[] = {
  129534. -1.5, -0.5, 0.5, 1.5,
  129535. };
  129536. static long _vq_quantmap__16u2_p2_0[] = {
  129537. 3, 1, 0, 2, 4,
  129538. };
  129539. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129540. _vq_quantthresh__16u2_p2_0,
  129541. _vq_quantmap__16u2_p2_0,
  129542. 5,
  129543. 5
  129544. };
  129545. static static_codebook _16u2_p2_0 = {
  129546. 4, 625,
  129547. _vq_lengthlist__16u2_p2_0,
  129548. 1, -533725184, 1611661312, 3, 0,
  129549. _vq_quantlist__16u2_p2_0,
  129550. NULL,
  129551. &_vq_auxt__16u2_p2_0,
  129552. NULL,
  129553. 0
  129554. };
  129555. static long _vq_quantlist__16u2_p3_0[] = {
  129556. 4,
  129557. 3,
  129558. 5,
  129559. 2,
  129560. 6,
  129561. 1,
  129562. 7,
  129563. 0,
  129564. 8,
  129565. };
  129566. static long _vq_lengthlist__16u2_p3_0[] = {
  129567. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129568. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129569. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129570. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129571. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129572. 11,
  129573. };
  129574. static float _vq_quantthresh__16u2_p3_0[] = {
  129575. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129576. };
  129577. static long _vq_quantmap__16u2_p3_0[] = {
  129578. 7, 5, 3, 1, 0, 2, 4, 6,
  129579. 8,
  129580. };
  129581. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129582. _vq_quantthresh__16u2_p3_0,
  129583. _vq_quantmap__16u2_p3_0,
  129584. 9,
  129585. 9
  129586. };
  129587. static static_codebook _16u2_p3_0 = {
  129588. 2, 81,
  129589. _vq_lengthlist__16u2_p3_0,
  129590. 1, -531628032, 1611661312, 4, 0,
  129591. _vq_quantlist__16u2_p3_0,
  129592. NULL,
  129593. &_vq_auxt__16u2_p3_0,
  129594. NULL,
  129595. 0
  129596. };
  129597. static long _vq_quantlist__16u2_p4_0[] = {
  129598. 8,
  129599. 7,
  129600. 9,
  129601. 6,
  129602. 10,
  129603. 5,
  129604. 11,
  129605. 4,
  129606. 12,
  129607. 3,
  129608. 13,
  129609. 2,
  129610. 14,
  129611. 1,
  129612. 15,
  129613. 0,
  129614. 16,
  129615. };
  129616. static long _vq_lengthlist__16u2_p4_0[] = {
  129617. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129618. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129619. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129620. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129621. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129622. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129623. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129624. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129625. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129626. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129627. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129628. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129629. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129630. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129631. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129632. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129633. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129634. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129635. 14,
  129636. };
  129637. static float _vq_quantthresh__16u2_p4_0[] = {
  129638. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129639. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129640. };
  129641. static long _vq_quantmap__16u2_p4_0[] = {
  129642. 15, 13, 11, 9, 7, 5, 3, 1,
  129643. 0, 2, 4, 6, 8, 10, 12, 14,
  129644. 16,
  129645. };
  129646. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129647. _vq_quantthresh__16u2_p4_0,
  129648. _vq_quantmap__16u2_p4_0,
  129649. 17,
  129650. 17
  129651. };
  129652. static static_codebook _16u2_p4_0 = {
  129653. 2, 289,
  129654. _vq_lengthlist__16u2_p4_0,
  129655. 1, -529530880, 1611661312, 5, 0,
  129656. _vq_quantlist__16u2_p4_0,
  129657. NULL,
  129658. &_vq_auxt__16u2_p4_0,
  129659. NULL,
  129660. 0
  129661. };
  129662. static long _vq_quantlist__16u2_p5_0[] = {
  129663. 1,
  129664. 0,
  129665. 2,
  129666. };
  129667. static long _vq_lengthlist__16u2_p5_0[] = {
  129668. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129669. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129670. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129671. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129672. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129673. 10,
  129674. };
  129675. static float _vq_quantthresh__16u2_p5_0[] = {
  129676. -5.5, 5.5,
  129677. };
  129678. static long _vq_quantmap__16u2_p5_0[] = {
  129679. 1, 0, 2,
  129680. };
  129681. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129682. _vq_quantthresh__16u2_p5_0,
  129683. _vq_quantmap__16u2_p5_0,
  129684. 3,
  129685. 3
  129686. };
  129687. static static_codebook _16u2_p5_0 = {
  129688. 4, 81,
  129689. _vq_lengthlist__16u2_p5_0,
  129690. 1, -529137664, 1618345984, 2, 0,
  129691. _vq_quantlist__16u2_p5_0,
  129692. NULL,
  129693. &_vq_auxt__16u2_p5_0,
  129694. NULL,
  129695. 0
  129696. };
  129697. static long _vq_quantlist__16u2_p5_1[] = {
  129698. 5,
  129699. 4,
  129700. 6,
  129701. 3,
  129702. 7,
  129703. 2,
  129704. 8,
  129705. 1,
  129706. 9,
  129707. 0,
  129708. 10,
  129709. };
  129710. static long _vq_lengthlist__16u2_p5_1[] = {
  129711. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129712. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129713. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129714. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129715. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129716. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129717. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129718. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129719. };
  129720. static float _vq_quantthresh__16u2_p5_1[] = {
  129721. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129722. 3.5, 4.5,
  129723. };
  129724. static long _vq_quantmap__16u2_p5_1[] = {
  129725. 9, 7, 5, 3, 1, 0, 2, 4,
  129726. 6, 8, 10,
  129727. };
  129728. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129729. _vq_quantthresh__16u2_p5_1,
  129730. _vq_quantmap__16u2_p5_1,
  129731. 11,
  129732. 11
  129733. };
  129734. static static_codebook _16u2_p5_1 = {
  129735. 2, 121,
  129736. _vq_lengthlist__16u2_p5_1,
  129737. 1, -531365888, 1611661312, 4, 0,
  129738. _vq_quantlist__16u2_p5_1,
  129739. NULL,
  129740. &_vq_auxt__16u2_p5_1,
  129741. NULL,
  129742. 0
  129743. };
  129744. static long _vq_quantlist__16u2_p6_0[] = {
  129745. 6,
  129746. 5,
  129747. 7,
  129748. 4,
  129749. 8,
  129750. 3,
  129751. 9,
  129752. 2,
  129753. 10,
  129754. 1,
  129755. 11,
  129756. 0,
  129757. 12,
  129758. };
  129759. static long _vq_lengthlist__16u2_p6_0[] = {
  129760. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129761. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129762. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129763. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129764. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129765. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129766. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129767. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129768. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129769. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129770. 12,13,13,14,14,14,14,15,15,
  129771. };
  129772. static float _vq_quantthresh__16u2_p6_0[] = {
  129773. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129774. 12.5, 17.5, 22.5, 27.5,
  129775. };
  129776. static long _vq_quantmap__16u2_p6_0[] = {
  129777. 11, 9, 7, 5, 3, 1, 0, 2,
  129778. 4, 6, 8, 10, 12,
  129779. };
  129780. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129781. _vq_quantthresh__16u2_p6_0,
  129782. _vq_quantmap__16u2_p6_0,
  129783. 13,
  129784. 13
  129785. };
  129786. static static_codebook _16u2_p6_0 = {
  129787. 2, 169,
  129788. _vq_lengthlist__16u2_p6_0,
  129789. 1, -526516224, 1616117760, 4, 0,
  129790. _vq_quantlist__16u2_p6_0,
  129791. NULL,
  129792. &_vq_auxt__16u2_p6_0,
  129793. NULL,
  129794. 0
  129795. };
  129796. static long _vq_quantlist__16u2_p6_1[] = {
  129797. 2,
  129798. 1,
  129799. 3,
  129800. 0,
  129801. 4,
  129802. };
  129803. static long _vq_lengthlist__16u2_p6_1[] = {
  129804. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129805. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129806. };
  129807. static float _vq_quantthresh__16u2_p6_1[] = {
  129808. -1.5, -0.5, 0.5, 1.5,
  129809. };
  129810. static long _vq_quantmap__16u2_p6_1[] = {
  129811. 3, 1, 0, 2, 4,
  129812. };
  129813. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129814. _vq_quantthresh__16u2_p6_1,
  129815. _vq_quantmap__16u2_p6_1,
  129816. 5,
  129817. 5
  129818. };
  129819. static static_codebook _16u2_p6_1 = {
  129820. 2, 25,
  129821. _vq_lengthlist__16u2_p6_1,
  129822. 1, -533725184, 1611661312, 3, 0,
  129823. _vq_quantlist__16u2_p6_1,
  129824. NULL,
  129825. &_vq_auxt__16u2_p6_1,
  129826. NULL,
  129827. 0
  129828. };
  129829. static long _vq_quantlist__16u2_p7_0[] = {
  129830. 6,
  129831. 5,
  129832. 7,
  129833. 4,
  129834. 8,
  129835. 3,
  129836. 9,
  129837. 2,
  129838. 10,
  129839. 1,
  129840. 11,
  129841. 0,
  129842. 12,
  129843. };
  129844. static long _vq_lengthlist__16u2_p7_0[] = {
  129845. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129846. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129847. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129848. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129849. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129850. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129851. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129852. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129853. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129854. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129855. 12,13,13,13,14,14,14,15,14,
  129856. };
  129857. static float _vq_quantthresh__16u2_p7_0[] = {
  129858. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129859. 27.5, 38.5, 49.5, 60.5,
  129860. };
  129861. static long _vq_quantmap__16u2_p7_0[] = {
  129862. 11, 9, 7, 5, 3, 1, 0, 2,
  129863. 4, 6, 8, 10, 12,
  129864. };
  129865. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129866. _vq_quantthresh__16u2_p7_0,
  129867. _vq_quantmap__16u2_p7_0,
  129868. 13,
  129869. 13
  129870. };
  129871. static static_codebook _16u2_p7_0 = {
  129872. 2, 169,
  129873. _vq_lengthlist__16u2_p7_0,
  129874. 1, -523206656, 1618345984, 4, 0,
  129875. _vq_quantlist__16u2_p7_0,
  129876. NULL,
  129877. &_vq_auxt__16u2_p7_0,
  129878. NULL,
  129879. 0
  129880. };
  129881. static long _vq_quantlist__16u2_p7_1[] = {
  129882. 5,
  129883. 4,
  129884. 6,
  129885. 3,
  129886. 7,
  129887. 2,
  129888. 8,
  129889. 1,
  129890. 9,
  129891. 0,
  129892. 10,
  129893. };
  129894. static long _vq_lengthlist__16u2_p7_1[] = {
  129895. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129896. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129897. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129898. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129899. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129900. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129901. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129902. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129903. };
  129904. static float _vq_quantthresh__16u2_p7_1[] = {
  129905. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129906. 3.5, 4.5,
  129907. };
  129908. static long _vq_quantmap__16u2_p7_1[] = {
  129909. 9, 7, 5, 3, 1, 0, 2, 4,
  129910. 6, 8, 10,
  129911. };
  129912. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129913. _vq_quantthresh__16u2_p7_1,
  129914. _vq_quantmap__16u2_p7_1,
  129915. 11,
  129916. 11
  129917. };
  129918. static static_codebook _16u2_p7_1 = {
  129919. 2, 121,
  129920. _vq_lengthlist__16u2_p7_1,
  129921. 1, -531365888, 1611661312, 4, 0,
  129922. _vq_quantlist__16u2_p7_1,
  129923. NULL,
  129924. &_vq_auxt__16u2_p7_1,
  129925. NULL,
  129926. 0
  129927. };
  129928. static long _vq_quantlist__16u2_p8_0[] = {
  129929. 7,
  129930. 6,
  129931. 8,
  129932. 5,
  129933. 9,
  129934. 4,
  129935. 10,
  129936. 3,
  129937. 11,
  129938. 2,
  129939. 12,
  129940. 1,
  129941. 13,
  129942. 0,
  129943. 14,
  129944. };
  129945. static long _vq_lengthlist__16u2_p8_0[] = {
  129946. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  129947. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  129948. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  129949. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  129950. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  129951. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  129952. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  129953. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  129954. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  129955. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  129956. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  129957. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  129958. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  129959. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  129960. 14,
  129961. };
  129962. static float _vq_quantthresh__16u2_p8_0[] = {
  129963. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129964. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129965. };
  129966. static long _vq_quantmap__16u2_p8_0[] = {
  129967. 13, 11, 9, 7, 5, 3, 1, 0,
  129968. 2, 4, 6, 8, 10, 12, 14,
  129969. };
  129970. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  129971. _vq_quantthresh__16u2_p8_0,
  129972. _vq_quantmap__16u2_p8_0,
  129973. 15,
  129974. 15
  129975. };
  129976. static static_codebook _16u2_p8_0 = {
  129977. 2, 225,
  129978. _vq_lengthlist__16u2_p8_0,
  129979. 1, -520986624, 1620377600, 4, 0,
  129980. _vq_quantlist__16u2_p8_0,
  129981. NULL,
  129982. &_vq_auxt__16u2_p8_0,
  129983. NULL,
  129984. 0
  129985. };
  129986. static long _vq_quantlist__16u2_p8_1[] = {
  129987. 10,
  129988. 9,
  129989. 11,
  129990. 8,
  129991. 12,
  129992. 7,
  129993. 13,
  129994. 6,
  129995. 14,
  129996. 5,
  129997. 15,
  129998. 4,
  129999. 16,
  130000. 3,
  130001. 17,
  130002. 2,
  130003. 18,
  130004. 1,
  130005. 19,
  130006. 0,
  130007. 20,
  130008. };
  130009. static long _vq_lengthlist__16u2_p8_1[] = {
  130010. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130011. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130012. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130013. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130014. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130015. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130016. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130017. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130018. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130019. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130020. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130021. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130022. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130023. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130024. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130025. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130026. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130027. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130028. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130029. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130030. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130031. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130032. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130033. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130034. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130035. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130036. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130037. 11,11,10,11,11,11,10,11,11,
  130038. };
  130039. static float _vq_quantthresh__16u2_p8_1[] = {
  130040. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130041. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130042. 6.5, 7.5, 8.5, 9.5,
  130043. };
  130044. static long _vq_quantmap__16u2_p8_1[] = {
  130045. 19, 17, 15, 13, 11, 9, 7, 5,
  130046. 3, 1, 0, 2, 4, 6, 8, 10,
  130047. 12, 14, 16, 18, 20,
  130048. };
  130049. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130050. _vq_quantthresh__16u2_p8_1,
  130051. _vq_quantmap__16u2_p8_1,
  130052. 21,
  130053. 21
  130054. };
  130055. static static_codebook _16u2_p8_1 = {
  130056. 2, 441,
  130057. _vq_lengthlist__16u2_p8_1,
  130058. 1, -529268736, 1611661312, 5, 0,
  130059. _vq_quantlist__16u2_p8_1,
  130060. NULL,
  130061. &_vq_auxt__16u2_p8_1,
  130062. NULL,
  130063. 0
  130064. };
  130065. static long _vq_quantlist__16u2_p9_0[] = {
  130066. 5586,
  130067. 4655,
  130068. 6517,
  130069. 3724,
  130070. 7448,
  130071. 2793,
  130072. 8379,
  130073. 1862,
  130074. 9310,
  130075. 931,
  130076. 10241,
  130077. 0,
  130078. 11172,
  130079. 5521,
  130080. 5651,
  130081. };
  130082. static long _vq_lengthlist__16u2_p9_0[] = {
  130083. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130084. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130085. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130086. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130087. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130088. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130089. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130090. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130091. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130092. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130093. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130095. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130096. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130097. 5,
  130098. };
  130099. static float _vq_quantthresh__16u2_p9_0[] = {
  130100. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130101. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130102. };
  130103. static long _vq_quantmap__16u2_p9_0[] = {
  130104. 11, 9, 7, 5, 3, 1, 13, 0,
  130105. 14, 2, 4, 6, 8, 10, 12,
  130106. };
  130107. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130108. _vq_quantthresh__16u2_p9_0,
  130109. _vq_quantmap__16u2_p9_0,
  130110. 15,
  130111. 15
  130112. };
  130113. static static_codebook _16u2_p9_0 = {
  130114. 2, 225,
  130115. _vq_lengthlist__16u2_p9_0,
  130116. 1, -510275072, 1611661312, 14, 0,
  130117. _vq_quantlist__16u2_p9_0,
  130118. NULL,
  130119. &_vq_auxt__16u2_p9_0,
  130120. NULL,
  130121. 0
  130122. };
  130123. static long _vq_quantlist__16u2_p9_1[] = {
  130124. 392,
  130125. 343,
  130126. 441,
  130127. 294,
  130128. 490,
  130129. 245,
  130130. 539,
  130131. 196,
  130132. 588,
  130133. 147,
  130134. 637,
  130135. 98,
  130136. 686,
  130137. 49,
  130138. 735,
  130139. 0,
  130140. 784,
  130141. 388,
  130142. 396,
  130143. };
  130144. static long _vq_lengthlist__16u2_p9_1[] = {
  130145. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130146. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130147. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130148. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130149. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130150. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130151. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130152. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130153. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130154. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130155. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130156. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130157. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130158. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130159. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130162. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130163. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130164. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130165. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130166. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130167. 11,11,11,11,11,11,11, 5, 4,
  130168. };
  130169. static float _vq_quantthresh__16u2_p9_1[] = {
  130170. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130171. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130172. 318.5, 367.5,
  130173. };
  130174. static long _vq_quantmap__16u2_p9_1[] = {
  130175. 15, 13, 11, 9, 7, 5, 3, 1,
  130176. 17, 0, 18, 2, 4, 6, 8, 10,
  130177. 12, 14, 16,
  130178. };
  130179. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130180. _vq_quantthresh__16u2_p9_1,
  130181. _vq_quantmap__16u2_p9_1,
  130182. 19,
  130183. 19
  130184. };
  130185. static static_codebook _16u2_p9_1 = {
  130186. 2, 361,
  130187. _vq_lengthlist__16u2_p9_1,
  130188. 1, -518488064, 1611661312, 10, 0,
  130189. _vq_quantlist__16u2_p9_1,
  130190. NULL,
  130191. &_vq_auxt__16u2_p9_1,
  130192. NULL,
  130193. 0
  130194. };
  130195. static long _vq_quantlist__16u2_p9_2[] = {
  130196. 24,
  130197. 23,
  130198. 25,
  130199. 22,
  130200. 26,
  130201. 21,
  130202. 27,
  130203. 20,
  130204. 28,
  130205. 19,
  130206. 29,
  130207. 18,
  130208. 30,
  130209. 17,
  130210. 31,
  130211. 16,
  130212. 32,
  130213. 15,
  130214. 33,
  130215. 14,
  130216. 34,
  130217. 13,
  130218. 35,
  130219. 12,
  130220. 36,
  130221. 11,
  130222. 37,
  130223. 10,
  130224. 38,
  130225. 9,
  130226. 39,
  130227. 8,
  130228. 40,
  130229. 7,
  130230. 41,
  130231. 6,
  130232. 42,
  130233. 5,
  130234. 43,
  130235. 4,
  130236. 44,
  130237. 3,
  130238. 45,
  130239. 2,
  130240. 46,
  130241. 1,
  130242. 47,
  130243. 0,
  130244. 48,
  130245. };
  130246. static long _vq_lengthlist__16u2_p9_2[] = {
  130247. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130248. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130249. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130250. 11,
  130251. };
  130252. static float _vq_quantthresh__16u2_p9_2[] = {
  130253. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130254. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130255. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130256. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130257. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130258. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130259. };
  130260. static long _vq_quantmap__16u2_p9_2[] = {
  130261. 47, 45, 43, 41, 39, 37, 35, 33,
  130262. 31, 29, 27, 25, 23, 21, 19, 17,
  130263. 15, 13, 11, 9, 7, 5, 3, 1,
  130264. 0, 2, 4, 6, 8, 10, 12, 14,
  130265. 16, 18, 20, 22, 24, 26, 28, 30,
  130266. 32, 34, 36, 38, 40, 42, 44, 46,
  130267. 48,
  130268. };
  130269. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130270. _vq_quantthresh__16u2_p9_2,
  130271. _vq_quantmap__16u2_p9_2,
  130272. 49,
  130273. 49
  130274. };
  130275. static static_codebook _16u2_p9_2 = {
  130276. 1, 49,
  130277. _vq_lengthlist__16u2_p9_2,
  130278. 1, -526909440, 1611661312, 6, 0,
  130279. _vq_quantlist__16u2_p9_2,
  130280. NULL,
  130281. &_vq_auxt__16u2_p9_2,
  130282. NULL,
  130283. 0
  130284. };
  130285. static long _vq_quantlist__8u0__p1_0[] = {
  130286. 1,
  130287. 0,
  130288. 2,
  130289. };
  130290. static long _vq_lengthlist__8u0__p1_0[] = {
  130291. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130292. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130293. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130294. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130295. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130296. 11,
  130297. };
  130298. static float _vq_quantthresh__8u0__p1_0[] = {
  130299. -0.5, 0.5,
  130300. };
  130301. static long _vq_quantmap__8u0__p1_0[] = {
  130302. 1, 0, 2,
  130303. };
  130304. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130305. _vq_quantthresh__8u0__p1_0,
  130306. _vq_quantmap__8u0__p1_0,
  130307. 3,
  130308. 3
  130309. };
  130310. static static_codebook _8u0__p1_0 = {
  130311. 4, 81,
  130312. _vq_lengthlist__8u0__p1_0,
  130313. 1, -535822336, 1611661312, 2, 0,
  130314. _vq_quantlist__8u0__p1_0,
  130315. NULL,
  130316. &_vq_auxt__8u0__p1_0,
  130317. NULL,
  130318. 0
  130319. };
  130320. static long _vq_quantlist__8u0__p2_0[] = {
  130321. 1,
  130322. 0,
  130323. 2,
  130324. };
  130325. static long _vq_lengthlist__8u0__p2_0[] = {
  130326. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130327. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130328. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130329. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130330. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130331. 8,
  130332. };
  130333. static float _vq_quantthresh__8u0__p2_0[] = {
  130334. -0.5, 0.5,
  130335. };
  130336. static long _vq_quantmap__8u0__p2_0[] = {
  130337. 1, 0, 2,
  130338. };
  130339. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130340. _vq_quantthresh__8u0__p2_0,
  130341. _vq_quantmap__8u0__p2_0,
  130342. 3,
  130343. 3
  130344. };
  130345. static static_codebook _8u0__p2_0 = {
  130346. 4, 81,
  130347. _vq_lengthlist__8u0__p2_0,
  130348. 1, -535822336, 1611661312, 2, 0,
  130349. _vq_quantlist__8u0__p2_0,
  130350. NULL,
  130351. &_vq_auxt__8u0__p2_0,
  130352. NULL,
  130353. 0
  130354. };
  130355. static long _vq_quantlist__8u0__p3_0[] = {
  130356. 2,
  130357. 1,
  130358. 3,
  130359. 0,
  130360. 4,
  130361. };
  130362. static long _vq_lengthlist__8u0__p3_0[] = {
  130363. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130364. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130365. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130366. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130367. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130368. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130369. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130370. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130371. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130372. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130373. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130374. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130375. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130376. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130377. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130378. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130379. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130380. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130381. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130382. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130383. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130384. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130385. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130386. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130387. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130388. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130389. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130390. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130391. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130392. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130393. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130394. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130395. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130396. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130397. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130398. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130399. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130400. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130401. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130402. 16,
  130403. };
  130404. static float _vq_quantthresh__8u0__p3_0[] = {
  130405. -1.5, -0.5, 0.5, 1.5,
  130406. };
  130407. static long _vq_quantmap__8u0__p3_0[] = {
  130408. 3, 1, 0, 2, 4,
  130409. };
  130410. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130411. _vq_quantthresh__8u0__p3_0,
  130412. _vq_quantmap__8u0__p3_0,
  130413. 5,
  130414. 5
  130415. };
  130416. static static_codebook _8u0__p3_0 = {
  130417. 4, 625,
  130418. _vq_lengthlist__8u0__p3_0,
  130419. 1, -533725184, 1611661312, 3, 0,
  130420. _vq_quantlist__8u0__p3_0,
  130421. NULL,
  130422. &_vq_auxt__8u0__p3_0,
  130423. NULL,
  130424. 0
  130425. };
  130426. static long _vq_quantlist__8u0__p4_0[] = {
  130427. 2,
  130428. 1,
  130429. 3,
  130430. 0,
  130431. 4,
  130432. };
  130433. static long _vq_lengthlist__8u0__p4_0[] = {
  130434. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130435. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130436. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130437. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130438. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130439. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130440. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130441. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130442. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130443. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130444. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130445. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130446. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130447. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130448. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130449. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130450. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130451. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130452. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130453. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130454. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130455. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130456. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130457. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130458. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130459. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130460. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130461. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130462. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130463. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130464. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130465. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130466. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130467. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130468. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130469. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130470. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130471. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130472. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130473. 12,
  130474. };
  130475. static float _vq_quantthresh__8u0__p4_0[] = {
  130476. -1.5, -0.5, 0.5, 1.5,
  130477. };
  130478. static long _vq_quantmap__8u0__p4_0[] = {
  130479. 3, 1, 0, 2, 4,
  130480. };
  130481. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130482. _vq_quantthresh__8u0__p4_0,
  130483. _vq_quantmap__8u0__p4_0,
  130484. 5,
  130485. 5
  130486. };
  130487. static static_codebook _8u0__p4_0 = {
  130488. 4, 625,
  130489. _vq_lengthlist__8u0__p4_0,
  130490. 1, -533725184, 1611661312, 3, 0,
  130491. _vq_quantlist__8u0__p4_0,
  130492. NULL,
  130493. &_vq_auxt__8u0__p4_0,
  130494. NULL,
  130495. 0
  130496. };
  130497. static long _vq_quantlist__8u0__p5_0[] = {
  130498. 4,
  130499. 3,
  130500. 5,
  130501. 2,
  130502. 6,
  130503. 1,
  130504. 7,
  130505. 0,
  130506. 8,
  130507. };
  130508. static long _vq_lengthlist__8u0__p5_0[] = {
  130509. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130510. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130511. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130512. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130513. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130514. 12,
  130515. };
  130516. static float _vq_quantthresh__8u0__p5_0[] = {
  130517. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130518. };
  130519. static long _vq_quantmap__8u0__p5_0[] = {
  130520. 7, 5, 3, 1, 0, 2, 4, 6,
  130521. 8,
  130522. };
  130523. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130524. _vq_quantthresh__8u0__p5_0,
  130525. _vq_quantmap__8u0__p5_0,
  130526. 9,
  130527. 9
  130528. };
  130529. static static_codebook _8u0__p5_0 = {
  130530. 2, 81,
  130531. _vq_lengthlist__8u0__p5_0,
  130532. 1, -531628032, 1611661312, 4, 0,
  130533. _vq_quantlist__8u0__p5_0,
  130534. NULL,
  130535. &_vq_auxt__8u0__p5_0,
  130536. NULL,
  130537. 0
  130538. };
  130539. static long _vq_quantlist__8u0__p6_0[] = {
  130540. 6,
  130541. 5,
  130542. 7,
  130543. 4,
  130544. 8,
  130545. 3,
  130546. 9,
  130547. 2,
  130548. 10,
  130549. 1,
  130550. 11,
  130551. 0,
  130552. 12,
  130553. };
  130554. static long _vq_lengthlist__8u0__p6_0[] = {
  130555. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130556. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130557. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130558. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130559. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130560. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130561. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130562. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130563. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130564. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130565. 16, 0,15, 0,17, 0, 0, 0, 0,
  130566. };
  130567. static float _vq_quantthresh__8u0__p6_0[] = {
  130568. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130569. 12.5, 17.5, 22.5, 27.5,
  130570. };
  130571. static long _vq_quantmap__8u0__p6_0[] = {
  130572. 11, 9, 7, 5, 3, 1, 0, 2,
  130573. 4, 6, 8, 10, 12,
  130574. };
  130575. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130576. _vq_quantthresh__8u0__p6_0,
  130577. _vq_quantmap__8u0__p6_0,
  130578. 13,
  130579. 13
  130580. };
  130581. static static_codebook _8u0__p6_0 = {
  130582. 2, 169,
  130583. _vq_lengthlist__8u0__p6_0,
  130584. 1, -526516224, 1616117760, 4, 0,
  130585. _vq_quantlist__8u0__p6_0,
  130586. NULL,
  130587. &_vq_auxt__8u0__p6_0,
  130588. NULL,
  130589. 0
  130590. };
  130591. static long _vq_quantlist__8u0__p6_1[] = {
  130592. 2,
  130593. 1,
  130594. 3,
  130595. 0,
  130596. 4,
  130597. };
  130598. static long _vq_lengthlist__8u0__p6_1[] = {
  130599. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130600. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130601. };
  130602. static float _vq_quantthresh__8u0__p6_1[] = {
  130603. -1.5, -0.5, 0.5, 1.5,
  130604. };
  130605. static long _vq_quantmap__8u0__p6_1[] = {
  130606. 3, 1, 0, 2, 4,
  130607. };
  130608. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130609. _vq_quantthresh__8u0__p6_1,
  130610. _vq_quantmap__8u0__p6_1,
  130611. 5,
  130612. 5
  130613. };
  130614. static static_codebook _8u0__p6_1 = {
  130615. 2, 25,
  130616. _vq_lengthlist__8u0__p6_1,
  130617. 1, -533725184, 1611661312, 3, 0,
  130618. _vq_quantlist__8u0__p6_1,
  130619. NULL,
  130620. &_vq_auxt__8u0__p6_1,
  130621. NULL,
  130622. 0
  130623. };
  130624. static long _vq_quantlist__8u0__p7_0[] = {
  130625. 1,
  130626. 0,
  130627. 2,
  130628. };
  130629. static long _vq_lengthlist__8u0__p7_0[] = {
  130630. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130631. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130632. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130633. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130634. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130635. 7,
  130636. };
  130637. static float _vq_quantthresh__8u0__p7_0[] = {
  130638. -157.5, 157.5,
  130639. };
  130640. static long _vq_quantmap__8u0__p7_0[] = {
  130641. 1, 0, 2,
  130642. };
  130643. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130644. _vq_quantthresh__8u0__p7_0,
  130645. _vq_quantmap__8u0__p7_0,
  130646. 3,
  130647. 3
  130648. };
  130649. static static_codebook _8u0__p7_0 = {
  130650. 4, 81,
  130651. _vq_lengthlist__8u0__p7_0,
  130652. 1, -518803456, 1628680192, 2, 0,
  130653. _vq_quantlist__8u0__p7_0,
  130654. NULL,
  130655. &_vq_auxt__8u0__p7_0,
  130656. NULL,
  130657. 0
  130658. };
  130659. static long _vq_quantlist__8u0__p7_1[] = {
  130660. 7,
  130661. 6,
  130662. 8,
  130663. 5,
  130664. 9,
  130665. 4,
  130666. 10,
  130667. 3,
  130668. 11,
  130669. 2,
  130670. 12,
  130671. 1,
  130672. 13,
  130673. 0,
  130674. 14,
  130675. };
  130676. static long _vq_lengthlist__8u0__p7_1[] = {
  130677. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130678. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130679. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130680. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130681. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130682. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130683. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130684. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130685. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130686. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130687. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130688. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130689. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130690. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130691. 10,
  130692. };
  130693. static float _vq_quantthresh__8u0__p7_1[] = {
  130694. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130695. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130696. };
  130697. static long _vq_quantmap__8u0__p7_1[] = {
  130698. 13, 11, 9, 7, 5, 3, 1, 0,
  130699. 2, 4, 6, 8, 10, 12, 14,
  130700. };
  130701. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130702. _vq_quantthresh__8u0__p7_1,
  130703. _vq_quantmap__8u0__p7_1,
  130704. 15,
  130705. 15
  130706. };
  130707. static static_codebook _8u0__p7_1 = {
  130708. 2, 225,
  130709. _vq_lengthlist__8u0__p7_1,
  130710. 1, -520986624, 1620377600, 4, 0,
  130711. _vq_quantlist__8u0__p7_1,
  130712. NULL,
  130713. &_vq_auxt__8u0__p7_1,
  130714. NULL,
  130715. 0
  130716. };
  130717. static long _vq_quantlist__8u0__p7_2[] = {
  130718. 10,
  130719. 9,
  130720. 11,
  130721. 8,
  130722. 12,
  130723. 7,
  130724. 13,
  130725. 6,
  130726. 14,
  130727. 5,
  130728. 15,
  130729. 4,
  130730. 16,
  130731. 3,
  130732. 17,
  130733. 2,
  130734. 18,
  130735. 1,
  130736. 19,
  130737. 0,
  130738. 20,
  130739. };
  130740. static long _vq_lengthlist__8u0__p7_2[] = {
  130741. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130742. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130743. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130744. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130745. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130746. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130747. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130748. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130749. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130750. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130751. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130752. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130753. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130754. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130755. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130756. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130757. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130758. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130759. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130760. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130761. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130762. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130763. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130764. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130765. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130766. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130767. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130768. 11,12,11,11,11,10,10,11,11,
  130769. };
  130770. static float _vq_quantthresh__8u0__p7_2[] = {
  130771. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130772. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130773. 6.5, 7.5, 8.5, 9.5,
  130774. };
  130775. static long _vq_quantmap__8u0__p7_2[] = {
  130776. 19, 17, 15, 13, 11, 9, 7, 5,
  130777. 3, 1, 0, 2, 4, 6, 8, 10,
  130778. 12, 14, 16, 18, 20,
  130779. };
  130780. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130781. _vq_quantthresh__8u0__p7_2,
  130782. _vq_quantmap__8u0__p7_2,
  130783. 21,
  130784. 21
  130785. };
  130786. static static_codebook _8u0__p7_2 = {
  130787. 2, 441,
  130788. _vq_lengthlist__8u0__p7_2,
  130789. 1, -529268736, 1611661312, 5, 0,
  130790. _vq_quantlist__8u0__p7_2,
  130791. NULL,
  130792. &_vq_auxt__8u0__p7_2,
  130793. NULL,
  130794. 0
  130795. };
  130796. static long _huff_lengthlist__8u0__single[] = {
  130797. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130798. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130799. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130800. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130801. };
  130802. static static_codebook _huff_book__8u0__single = {
  130803. 2, 64,
  130804. _huff_lengthlist__8u0__single,
  130805. 0, 0, 0, 0, 0,
  130806. NULL,
  130807. NULL,
  130808. NULL,
  130809. NULL,
  130810. 0
  130811. };
  130812. static long _vq_quantlist__8u1__p1_0[] = {
  130813. 1,
  130814. 0,
  130815. 2,
  130816. };
  130817. static long _vq_lengthlist__8u1__p1_0[] = {
  130818. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130819. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130820. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130821. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130822. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130823. 10,
  130824. };
  130825. static float _vq_quantthresh__8u1__p1_0[] = {
  130826. -0.5, 0.5,
  130827. };
  130828. static long _vq_quantmap__8u1__p1_0[] = {
  130829. 1, 0, 2,
  130830. };
  130831. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130832. _vq_quantthresh__8u1__p1_0,
  130833. _vq_quantmap__8u1__p1_0,
  130834. 3,
  130835. 3
  130836. };
  130837. static static_codebook _8u1__p1_0 = {
  130838. 4, 81,
  130839. _vq_lengthlist__8u1__p1_0,
  130840. 1, -535822336, 1611661312, 2, 0,
  130841. _vq_quantlist__8u1__p1_0,
  130842. NULL,
  130843. &_vq_auxt__8u1__p1_0,
  130844. NULL,
  130845. 0
  130846. };
  130847. static long _vq_quantlist__8u1__p2_0[] = {
  130848. 1,
  130849. 0,
  130850. 2,
  130851. };
  130852. static long _vq_lengthlist__8u1__p2_0[] = {
  130853. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130854. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130855. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130856. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130857. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130858. 7,
  130859. };
  130860. static float _vq_quantthresh__8u1__p2_0[] = {
  130861. -0.5, 0.5,
  130862. };
  130863. static long _vq_quantmap__8u1__p2_0[] = {
  130864. 1, 0, 2,
  130865. };
  130866. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130867. _vq_quantthresh__8u1__p2_0,
  130868. _vq_quantmap__8u1__p2_0,
  130869. 3,
  130870. 3
  130871. };
  130872. static static_codebook _8u1__p2_0 = {
  130873. 4, 81,
  130874. _vq_lengthlist__8u1__p2_0,
  130875. 1, -535822336, 1611661312, 2, 0,
  130876. _vq_quantlist__8u1__p2_0,
  130877. NULL,
  130878. &_vq_auxt__8u1__p2_0,
  130879. NULL,
  130880. 0
  130881. };
  130882. static long _vq_quantlist__8u1__p3_0[] = {
  130883. 2,
  130884. 1,
  130885. 3,
  130886. 0,
  130887. 4,
  130888. };
  130889. static long _vq_lengthlist__8u1__p3_0[] = {
  130890. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130891. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130892. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130893. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130894. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130895. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130896. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130897. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130898. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130899. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130900. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130901. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130902. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130903. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130904. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130905. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130906. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130907. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130908. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130909. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130910. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130911. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130912. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130913. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130914. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130915. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130916. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  130917. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  130918. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  130919. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  130920. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  130921. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  130922. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  130923. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  130924. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  130925. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  130926. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  130927. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  130928. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  130929. 16,
  130930. };
  130931. static float _vq_quantthresh__8u1__p3_0[] = {
  130932. -1.5, -0.5, 0.5, 1.5,
  130933. };
  130934. static long _vq_quantmap__8u1__p3_0[] = {
  130935. 3, 1, 0, 2, 4,
  130936. };
  130937. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  130938. _vq_quantthresh__8u1__p3_0,
  130939. _vq_quantmap__8u1__p3_0,
  130940. 5,
  130941. 5
  130942. };
  130943. static static_codebook _8u1__p3_0 = {
  130944. 4, 625,
  130945. _vq_lengthlist__8u1__p3_0,
  130946. 1, -533725184, 1611661312, 3, 0,
  130947. _vq_quantlist__8u1__p3_0,
  130948. NULL,
  130949. &_vq_auxt__8u1__p3_0,
  130950. NULL,
  130951. 0
  130952. };
  130953. static long _vq_quantlist__8u1__p4_0[] = {
  130954. 2,
  130955. 1,
  130956. 3,
  130957. 0,
  130958. 4,
  130959. };
  130960. static long _vq_lengthlist__8u1__p4_0[] = {
  130961. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  130962. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  130963. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  130964. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  130965. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  130966. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  130967. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  130968. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  130969. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  130970. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  130971. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  130972. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  130973. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  130974. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  130975. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  130976. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  130977. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  130978. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  130979. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  130980. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  130981. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  130982. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  130983. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  130984. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  130985. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  130986. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  130987. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  130988. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  130989. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  130990. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  130991. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  130992. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  130993. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  130994. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  130995. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  130996. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  130997. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  130998. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  130999. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131000. 10,
  131001. };
  131002. static float _vq_quantthresh__8u1__p4_0[] = {
  131003. -1.5, -0.5, 0.5, 1.5,
  131004. };
  131005. static long _vq_quantmap__8u1__p4_0[] = {
  131006. 3, 1, 0, 2, 4,
  131007. };
  131008. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131009. _vq_quantthresh__8u1__p4_0,
  131010. _vq_quantmap__8u1__p4_0,
  131011. 5,
  131012. 5
  131013. };
  131014. static static_codebook _8u1__p4_0 = {
  131015. 4, 625,
  131016. _vq_lengthlist__8u1__p4_0,
  131017. 1, -533725184, 1611661312, 3, 0,
  131018. _vq_quantlist__8u1__p4_0,
  131019. NULL,
  131020. &_vq_auxt__8u1__p4_0,
  131021. NULL,
  131022. 0
  131023. };
  131024. static long _vq_quantlist__8u1__p5_0[] = {
  131025. 4,
  131026. 3,
  131027. 5,
  131028. 2,
  131029. 6,
  131030. 1,
  131031. 7,
  131032. 0,
  131033. 8,
  131034. };
  131035. static long _vq_lengthlist__8u1__p5_0[] = {
  131036. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131037. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131038. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131039. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131040. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131041. 13,
  131042. };
  131043. static float _vq_quantthresh__8u1__p5_0[] = {
  131044. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131045. };
  131046. static long _vq_quantmap__8u1__p5_0[] = {
  131047. 7, 5, 3, 1, 0, 2, 4, 6,
  131048. 8,
  131049. };
  131050. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131051. _vq_quantthresh__8u1__p5_0,
  131052. _vq_quantmap__8u1__p5_0,
  131053. 9,
  131054. 9
  131055. };
  131056. static static_codebook _8u1__p5_0 = {
  131057. 2, 81,
  131058. _vq_lengthlist__8u1__p5_0,
  131059. 1, -531628032, 1611661312, 4, 0,
  131060. _vq_quantlist__8u1__p5_0,
  131061. NULL,
  131062. &_vq_auxt__8u1__p5_0,
  131063. NULL,
  131064. 0
  131065. };
  131066. static long _vq_quantlist__8u1__p6_0[] = {
  131067. 4,
  131068. 3,
  131069. 5,
  131070. 2,
  131071. 6,
  131072. 1,
  131073. 7,
  131074. 0,
  131075. 8,
  131076. };
  131077. static long _vq_lengthlist__8u1__p6_0[] = {
  131078. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131079. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131080. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131081. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131082. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131083. 10,
  131084. };
  131085. static float _vq_quantthresh__8u1__p6_0[] = {
  131086. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131087. };
  131088. static long _vq_quantmap__8u1__p6_0[] = {
  131089. 7, 5, 3, 1, 0, 2, 4, 6,
  131090. 8,
  131091. };
  131092. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131093. _vq_quantthresh__8u1__p6_0,
  131094. _vq_quantmap__8u1__p6_0,
  131095. 9,
  131096. 9
  131097. };
  131098. static static_codebook _8u1__p6_0 = {
  131099. 2, 81,
  131100. _vq_lengthlist__8u1__p6_0,
  131101. 1, -531628032, 1611661312, 4, 0,
  131102. _vq_quantlist__8u1__p6_0,
  131103. NULL,
  131104. &_vq_auxt__8u1__p6_0,
  131105. NULL,
  131106. 0
  131107. };
  131108. static long _vq_quantlist__8u1__p7_0[] = {
  131109. 1,
  131110. 0,
  131111. 2,
  131112. };
  131113. static long _vq_lengthlist__8u1__p7_0[] = {
  131114. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131115. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131116. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131117. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131118. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131119. 11,
  131120. };
  131121. static float _vq_quantthresh__8u1__p7_0[] = {
  131122. -5.5, 5.5,
  131123. };
  131124. static long _vq_quantmap__8u1__p7_0[] = {
  131125. 1, 0, 2,
  131126. };
  131127. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131128. _vq_quantthresh__8u1__p7_0,
  131129. _vq_quantmap__8u1__p7_0,
  131130. 3,
  131131. 3
  131132. };
  131133. static static_codebook _8u1__p7_0 = {
  131134. 4, 81,
  131135. _vq_lengthlist__8u1__p7_0,
  131136. 1, -529137664, 1618345984, 2, 0,
  131137. _vq_quantlist__8u1__p7_0,
  131138. NULL,
  131139. &_vq_auxt__8u1__p7_0,
  131140. NULL,
  131141. 0
  131142. };
  131143. static long _vq_quantlist__8u1__p7_1[] = {
  131144. 5,
  131145. 4,
  131146. 6,
  131147. 3,
  131148. 7,
  131149. 2,
  131150. 8,
  131151. 1,
  131152. 9,
  131153. 0,
  131154. 10,
  131155. };
  131156. static long _vq_lengthlist__8u1__p7_1[] = {
  131157. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131158. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131159. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131160. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131161. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131162. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131163. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131164. 9, 9, 9, 9, 9,10,10,10,10,
  131165. };
  131166. static float _vq_quantthresh__8u1__p7_1[] = {
  131167. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131168. 3.5, 4.5,
  131169. };
  131170. static long _vq_quantmap__8u1__p7_1[] = {
  131171. 9, 7, 5, 3, 1, 0, 2, 4,
  131172. 6, 8, 10,
  131173. };
  131174. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131175. _vq_quantthresh__8u1__p7_1,
  131176. _vq_quantmap__8u1__p7_1,
  131177. 11,
  131178. 11
  131179. };
  131180. static static_codebook _8u1__p7_1 = {
  131181. 2, 121,
  131182. _vq_lengthlist__8u1__p7_1,
  131183. 1, -531365888, 1611661312, 4, 0,
  131184. _vq_quantlist__8u1__p7_1,
  131185. NULL,
  131186. &_vq_auxt__8u1__p7_1,
  131187. NULL,
  131188. 0
  131189. };
  131190. static long _vq_quantlist__8u1__p8_0[] = {
  131191. 5,
  131192. 4,
  131193. 6,
  131194. 3,
  131195. 7,
  131196. 2,
  131197. 8,
  131198. 1,
  131199. 9,
  131200. 0,
  131201. 10,
  131202. };
  131203. static long _vq_lengthlist__8u1__p8_0[] = {
  131204. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131205. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131206. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131207. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131208. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131209. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131210. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131211. 12,13,13,14,14,15,15,15,15,
  131212. };
  131213. static float _vq_quantthresh__8u1__p8_0[] = {
  131214. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131215. 38.5, 49.5,
  131216. };
  131217. static long _vq_quantmap__8u1__p8_0[] = {
  131218. 9, 7, 5, 3, 1, 0, 2, 4,
  131219. 6, 8, 10,
  131220. };
  131221. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131222. _vq_quantthresh__8u1__p8_0,
  131223. _vq_quantmap__8u1__p8_0,
  131224. 11,
  131225. 11
  131226. };
  131227. static static_codebook _8u1__p8_0 = {
  131228. 2, 121,
  131229. _vq_lengthlist__8u1__p8_0,
  131230. 1, -524582912, 1618345984, 4, 0,
  131231. _vq_quantlist__8u1__p8_0,
  131232. NULL,
  131233. &_vq_auxt__8u1__p8_0,
  131234. NULL,
  131235. 0
  131236. };
  131237. static long _vq_quantlist__8u1__p8_1[] = {
  131238. 5,
  131239. 4,
  131240. 6,
  131241. 3,
  131242. 7,
  131243. 2,
  131244. 8,
  131245. 1,
  131246. 9,
  131247. 0,
  131248. 10,
  131249. };
  131250. static long _vq_lengthlist__8u1__p8_1[] = {
  131251. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131252. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131253. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131254. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131255. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131256. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131257. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131258. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131259. };
  131260. static float _vq_quantthresh__8u1__p8_1[] = {
  131261. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131262. 3.5, 4.5,
  131263. };
  131264. static long _vq_quantmap__8u1__p8_1[] = {
  131265. 9, 7, 5, 3, 1, 0, 2, 4,
  131266. 6, 8, 10,
  131267. };
  131268. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131269. _vq_quantthresh__8u1__p8_1,
  131270. _vq_quantmap__8u1__p8_1,
  131271. 11,
  131272. 11
  131273. };
  131274. static static_codebook _8u1__p8_1 = {
  131275. 2, 121,
  131276. _vq_lengthlist__8u1__p8_1,
  131277. 1, -531365888, 1611661312, 4, 0,
  131278. _vq_quantlist__8u1__p8_1,
  131279. NULL,
  131280. &_vq_auxt__8u1__p8_1,
  131281. NULL,
  131282. 0
  131283. };
  131284. static long _vq_quantlist__8u1__p9_0[] = {
  131285. 7,
  131286. 6,
  131287. 8,
  131288. 5,
  131289. 9,
  131290. 4,
  131291. 10,
  131292. 3,
  131293. 11,
  131294. 2,
  131295. 12,
  131296. 1,
  131297. 13,
  131298. 0,
  131299. 14,
  131300. };
  131301. static long _vq_lengthlist__8u1__p9_0[] = {
  131302. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131303. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131304. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131305. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131306. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131307. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131314. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131315. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131316. 10,
  131317. };
  131318. static float _vq_quantthresh__8u1__p9_0[] = {
  131319. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131320. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131321. };
  131322. static long _vq_quantmap__8u1__p9_0[] = {
  131323. 13, 11, 9, 7, 5, 3, 1, 0,
  131324. 2, 4, 6, 8, 10, 12, 14,
  131325. };
  131326. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131327. _vq_quantthresh__8u1__p9_0,
  131328. _vq_quantmap__8u1__p9_0,
  131329. 15,
  131330. 15
  131331. };
  131332. static static_codebook _8u1__p9_0 = {
  131333. 2, 225,
  131334. _vq_lengthlist__8u1__p9_0,
  131335. 1, -514071552, 1627381760, 4, 0,
  131336. _vq_quantlist__8u1__p9_0,
  131337. NULL,
  131338. &_vq_auxt__8u1__p9_0,
  131339. NULL,
  131340. 0
  131341. };
  131342. static long _vq_quantlist__8u1__p9_1[] = {
  131343. 7,
  131344. 6,
  131345. 8,
  131346. 5,
  131347. 9,
  131348. 4,
  131349. 10,
  131350. 3,
  131351. 11,
  131352. 2,
  131353. 12,
  131354. 1,
  131355. 13,
  131356. 0,
  131357. 14,
  131358. };
  131359. static long _vq_lengthlist__8u1__p9_1[] = {
  131360. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131361. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131362. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131363. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131364. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131365. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131366. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131367. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131368. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131369. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131370. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131371. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131372. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131373. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131374. 13,
  131375. };
  131376. static float _vq_quantthresh__8u1__p9_1[] = {
  131377. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131378. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131379. };
  131380. static long _vq_quantmap__8u1__p9_1[] = {
  131381. 13, 11, 9, 7, 5, 3, 1, 0,
  131382. 2, 4, 6, 8, 10, 12, 14,
  131383. };
  131384. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131385. _vq_quantthresh__8u1__p9_1,
  131386. _vq_quantmap__8u1__p9_1,
  131387. 15,
  131388. 15
  131389. };
  131390. static static_codebook _8u1__p9_1 = {
  131391. 2, 225,
  131392. _vq_lengthlist__8u1__p9_1,
  131393. 1, -522338304, 1620115456, 4, 0,
  131394. _vq_quantlist__8u1__p9_1,
  131395. NULL,
  131396. &_vq_auxt__8u1__p9_1,
  131397. NULL,
  131398. 0
  131399. };
  131400. static long _vq_quantlist__8u1__p9_2[] = {
  131401. 8,
  131402. 7,
  131403. 9,
  131404. 6,
  131405. 10,
  131406. 5,
  131407. 11,
  131408. 4,
  131409. 12,
  131410. 3,
  131411. 13,
  131412. 2,
  131413. 14,
  131414. 1,
  131415. 15,
  131416. 0,
  131417. 16,
  131418. };
  131419. static long _vq_lengthlist__8u1__p9_2[] = {
  131420. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131421. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131422. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131423. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131424. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131425. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131426. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131427. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131428. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131429. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131430. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131431. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131432. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131433. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131434. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131435. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131436. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131437. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131438. 10,
  131439. };
  131440. static float _vq_quantthresh__8u1__p9_2[] = {
  131441. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131442. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131443. };
  131444. static long _vq_quantmap__8u1__p9_2[] = {
  131445. 15, 13, 11, 9, 7, 5, 3, 1,
  131446. 0, 2, 4, 6, 8, 10, 12, 14,
  131447. 16,
  131448. };
  131449. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131450. _vq_quantthresh__8u1__p9_2,
  131451. _vq_quantmap__8u1__p9_2,
  131452. 17,
  131453. 17
  131454. };
  131455. static static_codebook _8u1__p9_2 = {
  131456. 2, 289,
  131457. _vq_lengthlist__8u1__p9_2,
  131458. 1, -529530880, 1611661312, 5, 0,
  131459. _vq_quantlist__8u1__p9_2,
  131460. NULL,
  131461. &_vq_auxt__8u1__p9_2,
  131462. NULL,
  131463. 0
  131464. };
  131465. static long _huff_lengthlist__8u1__single[] = {
  131466. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131467. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131468. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131469. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131470. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131471. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131472. 13, 8, 8,15,
  131473. };
  131474. static static_codebook _huff_book__8u1__single = {
  131475. 2, 100,
  131476. _huff_lengthlist__8u1__single,
  131477. 0, 0, 0, 0, 0,
  131478. NULL,
  131479. NULL,
  131480. NULL,
  131481. NULL,
  131482. 0
  131483. };
  131484. static long _huff_lengthlist__44u0__long[] = {
  131485. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131486. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131487. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131488. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131489. };
  131490. static static_codebook _huff_book__44u0__long = {
  131491. 2, 64,
  131492. _huff_lengthlist__44u0__long,
  131493. 0, 0, 0, 0, 0,
  131494. NULL,
  131495. NULL,
  131496. NULL,
  131497. NULL,
  131498. 0
  131499. };
  131500. static long _vq_quantlist__44u0__p1_0[] = {
  131501. 1,
  131502. 0,
  131503. 2,
  131504. };
  131505. static long _vq_lengthlist__44u0__p1_0[] = {
  131506. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131507. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131508. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131509. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131510. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131511. 13,
  131512. };
  131513. static float _vq_quantthresh__44u0__p1_0[] = {
  131514. -0.5, 0.5,
  131515. };
  131516. static long _vq_quantmap__44u0__p1_0[] = {
  131517. 1, 0, 2,
  131518. };
  131519. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131520. _vq_quantthresh__44u0__p1_0,
  131521. _vq_quantmap__44u0__p1_0,
  131522. 3,
  131523. 3
  131524. };
  131525. static static_codebook _44u0__p1_0 = {
  131526. 4, 81,
  131527. _vq_lengthlist__44u0__p1_0,
  131528. 1, -535822336, 1611661312, 2, 0,
  131529. _vq_quantlist__44u0__p1_0,
  131530. NULL,
  131531. &_vq_auxt__44u0__p1_0,
  131532. NULL,
  131533. 0
  131534. };
  131535. static long _vq_quantlist__44u0__p2_0[] = {
  131536. 1,
  131537. 0,
  131538. 2,
  131539. };
  131540. static long _vq_lengthlist__44u0__p2_0[] = {
  131541. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131542. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131543. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131544. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131545. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131546. 9,
  131547. };
  131548. static float _vq_quantthresh__44u0__p2_0[] = {
  131549. -0.5, 0.5,
  131550. };
  131551. static long _vq_quantmap__44u0__p2_0[] = {
  131552. 1, 0, 2,
  131553. };
  131554. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131555. _vq_quantthresh__44u0__p2_0,
  131556. _vq_quantmap__44u0__p2_0,
  131557. 3,
  131558. 3
  131559. };
  131560. static static_codebook _44u0__p2_0 = {
  131561. 4, 81,
  131562. _vq_lengthlist__44u0__p2_0,
  131563. 1, -535822336, 1611661312, 2, 0,
  131564. _vq_quantlist__44u0__p2_0,
  131565. NULL,
  131566. &_vq_auxt__44u0__p2_0,
  131567. NULL,
  131568. 0
  131569. };
  131570. static long _vq_quantlist__44u0__p3_0[] = {
  131571. 2,
  131572. 1,
  131573. 3,
  131574. 0,
  131575. 4,
  131576. };
  131577. static long _vq_lengthlist__44u0__p3_0[] = {
  131578. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131579. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131580. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131581. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131582. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131583. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131584. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131585. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131586. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131587. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131588. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131589. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131590. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131591. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131592. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131593. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131594. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131595. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131596. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131597. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131598. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131599. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131600. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131601. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131602. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131603. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131604. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131605. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131606. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131607. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131608. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131609. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131610. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131611. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131612. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131613. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131614. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131615. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131616. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131617. 19,
  131618. };
  131619. static float _vq_quantthresh__44u0__p3_0[] = {
  131620. -1.5, -0.5, 0.5, 1.5,
  131621. };
  131622. static long _vq_quantmap__44u0__p3_0[] = {
  131623. 3, 1, 0, 2, 4,
  131624. };
  131625. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131626. _vq_quantthresh__44u0__p3_0,
  131627. _vq_quantmap__44u0__p3_0,
  131628. 5,
  131629. 5
  131630. };
  131631. static static_codebook _44u0__p3_0 = {
  131632. 4, 625,
  131633. _vq_lengthlist__44u0__p3_0,
  131634. 1, -533725184, 1611661312, 3, 0,
  131635. _vq_quantlist__44u0__p3_0,
  131636. NULL,
  131637. &_vq_auxt__44u0__p3_0,
  131638. NULL,
  131639. 0
  131640. };
  131641. static long _vq_quantlist__44u0__p4_0[] = {
  131642. 2,
  131643. 1,
  131644. 3,
  131645. 0,
  131646. 4,
  131647. };
  131648. static long _vq_lengthlist__44u0__p4_0[] = {
  131649. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131650. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131651. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131652. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131653. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131654. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131655. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131656. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131657. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131658. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131659. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131660. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131661. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131662. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131663. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131664. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131665. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131666. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131667. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131668. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131669. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131670. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131671. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131672. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131673. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131674. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131675. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131676. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131677. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131678. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131679. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131680. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131681. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131682. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131683. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131684. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131685. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131686. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131687. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131688. 12,
  131689. };
  131690. static float _vq_quantthresh__44u0__p4_0[] = {
  131691. -1.5, -0.5, 0.5, 1.5,
  131692. };
  131693. static long _vq_quantmap__44u0__p4_0[] = {
  131694. 3, 1, 0, 2, 4,
  131695. };
  131696. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131697. _vq_quantthresh__44u0__p4_0,
  131698. _vq_quantmap__44u0__p4_0,
  131699. 5,
  131700. 5
  131701. };
  131702. static static_codebook _44u0__p4_0 = {
  131703. 4, 625,
  131704. _vq_lengthlist__44u0__p4_0,
  131705. 1, -533725184, 1611661312, 3, 0,
  131706. _vq_quantlist__44u0__p4_0,
  131707. NULL,
  131708. &_vq_auxt__44u0__p4_0,
  131709. NULL,
  131710. 0
  131711. };
  131712. static long _vq_quantlist__44u0__p5_0[] = {
  131713. 4,
  131714. 3,
  131715. 5,
  131716. 2,
  131717. 6,
  131718. 1,
  131719. 7,
  131720. 0,
  131721. 8,
  131722. };
  131723. static long _vq_lengthlist__44u0__p5_0[] = {
  131724. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131725. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131726. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131727. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131728. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131729. 12,
  131730. };
  131731. static float _vq_quantthresh__44u0__p5_0[] = {
  131732. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131733. };
  131734. static long _vq_quantmap__44u0__p5_0[] = {
  131735. 7, 5, 3, 1, 0, 2, 4, 6,
  131736. 8,
  131737. };
  131738. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131739. _vq_quantthresh__44u0__p5_0,
  131740. _vq_quantmap__44u0__p5_0,
  131741. 9,
  131742. 9
  131743. };
  131744. static static_codebook _44u0__p5_0 = {
  131745. 2, 81,
  131746. _vq_lengthlist__44u0__p5_0,
  131747. 1, -531628032, 1611661312, 4, 0,
  131748. _vq_quantlist__44u0__p5_0,
  131749. NULL,
  131750. &_vq_auxt__44u0__p5_0,
  131751. NULL,
  131752. 0
  131753. };
  131754. static long _vq_quantlist__44u0__p6_0[] = {
  131755. 6,
  131756. 5,
  131757. 7,
  131758. 4,
  131759. 8,
  131760. 3,
  131761. 9,
  131762. 2,
  131763. 10,
  131764. 1,
  131765. 11,
  131766. 0,
  131767. 12,
  131768. };
  131769. static long _vq_lengthlist__44u0__p6_0[] = {
  131770. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131771. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131772. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131773. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131774. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131775. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131776. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131777. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131778. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131779. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131780. 15,17,16,17,18,17,17,18, 0,
  131781. };
  131782. static float _vq_quantthresh__44u0__p6_0[] = {
  131783. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131784. 12.5, 17.5, 22.5, 27.5,
  131785. };
  131786. static long _vq_quantmap__44u0__p6_0[] = {
  131787. 11, 9, 7, 5, 3, 1, 0, 2,
  131788. 4, 6, 8, 10, 12,
  131789. };
  131790. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131791. _vq_quantthresh__44u0__p6_0,
  131792. _vq_quantmap__44u0__p6_0,
  131793. 13,
  131794. 13
  131795. };
  131796. static static_codebook _44u0__p6_0 = {
  131797. 2, 169,
  131798. _vq_lengthlist__44u0__p6_0,
  131799. 1, -526516224, 1616117760, 4, 0,
  131800. _vq_quantlist__44u0__p6_0,
  131801. NULL,
  131802. &_vq_auxt__44u0__p6_0,
  131803. NULL,
  131804. 0
  131805. };
  131806. static long _vq_quantlist__44u0__p6_1[] = {
  131807. 2,
  131808. 1,
  131809. 3,
  131810. 0,
  131811. 4,
  131812. };
  131813. static long _vq_lengthlist__44u0__p6_1[] = {
  131814. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131815. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131816. };
  131817. static float _vq_quantthresh__44u0__p6_1[] = {
  131818. -1.5, -0.5, 0.5, 1.5,
  131819. };
  131820. static long _vq_quantmap__44u0__p6_1[] = {
  131821. 3, 1, 0, 2, 4,
  131822. };
  131823. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131824. _vq_quantthresh__44u0__p6_1,
  131825. _vq_quantmap__44u0__p6_1,
  131826. 5,
  131827. 5
  131828. };
  131829. static static_codebook _44u0__p6_1 = {
  131830. 2, 25,
  131831. _vq_lengthlist__44u0__p6_1,
  131832. 1, -533725184, 1611661312, 3, 0,
  131833. _vq_quantlist__44u0__p6_1,
  131834. NULL,
  131835. &_vq_auxt__44u0__p6_1,
  131836. NULL,
  131837. 0
  131838. };
  131839. static long _vq_quantlist__44u0__p7_0[] = {
  131840. 2,
  131841. 1,
  131842. 3,
  131843. 0,
  131844. 4,
  131845. };
  131846. static long _vq_lengthlist__44u0__p7_0[] = {
  131847. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131850. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131853. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131854. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131855. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131856. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131857. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131858. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131859. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131860. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131861. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131862. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131863. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131865. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131866. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131867. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131868. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131869. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131870. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131871. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131873. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131874. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131876. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131877. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131878. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131879. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131880. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131881. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131882. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131883. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131884. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131885. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131886. 10,
  131887. };
  131888. static float _vq_quantthresh__44u0__p7_0[] = {
  131889. -253.5, -84.5, 84.5, 253.5,
  131890. };
  131891. static long _vq_quantmap__44u0__p7_0[] = {
  131892. 3, 1, 0, 2, 4,
  131893. };
  131894. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131895. _vq_quantthresh__44u0__p7_0,
  131896. _vq_quantmap__44u0__p7_0,
  131897. 5,
  131898. 5
  131899. };
  131900. static static_codebook _44u0__p7_0 = {
  131901. 4, 625,
  131902. _vq_lengthlist__44u0__p7_0,
  131903. 1, -518709248, 1626677248, 3, 0,
  131904. _vq_quantlist__44u0__p7_0,
  131905. NULL,
  131906. &_vq_auxt__44u0__p7_0,
  131907. NULL,
  131908. 0
  131909. };
  131910. static long _vq_quantlist__44u0__p7_1[] = {
  131911. 6,
  131912. 5,
  131913. 7,
  131914. 4,
  131915. 8,
  131916. 3,
  131917. 9,
  131918. 2,
  131919. 10,
  131920. 1,
  131921. 11,
  131922. 0,
  131923. 12,
  131924. };
  131925. static long _vq_lengthlist__44u0__p7_1[] = {
  131926. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  131927. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  131928. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  131929. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  131930. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  131931. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  131932. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  131933. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  131934. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  131935. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  131936. 15,15,15,15,15,15,15,15,15,
  131937. };
  131938. static float _vq_quantthresh__44u0__p7_1[] = {
  131939. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  131940. 32.5, 45.5, 58.5, 71.5,
  131941. };
  131942. static long _vq_quantmap__44u0__p7_1[] = {
  131943. 11, 9, 7, 5, 3, 1, 0, 2,
  131944. 4, 6, 8, 10, 12,
  131945. };
  131946. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  131947. _vq_quantthresh__44u0__p7_1,
  131948. _vq_quantmap__44u0__p7_1,
  131949. 13,
  131950. 13
  131951. };
  131952. static static_codebook _44u0__p7_1 = {
  131953. 2, 169,
  131954. _vq_lengthlist__44u0__p7_1,
  131955. 1, -523010048, 1618608128, 4, 0,
  131956. _vq_quantlist__44u0__p7_1,
  131957. NULL,
  131958. &_vq_auxt__44u0__p7_1,
  131959. NULL,
  131960. 0
  131961. };
  131962. static long _vq_quantlist__44u0__p7_2[] = {
  131963. 6,
  131964. 5,
  131965. 7,
  131966. 4,
  131967. 8,
  131968. 3,
  131969. 9,
  131970. 2,
  131971. 10,
  131972. 1,
  131973. 11,
  131974. 0,
  131975. 12,
  131976. };
  131977. static long _vq_lengthlist__44u0__p7_2[] = {
  131978. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  131979. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  131980. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  131981. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  131982. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  131983. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  131984. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  131985. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131986. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131987. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  131988. 9, 9, 9,10, 9, 9,10,10, 9,
  131989. };
  131990. static float _vq_quantthresh__44u0__p7_2[] = {
  131991. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  131992. 2.5, 3.5, 4.5, 5.5,
  131993. };
  131994. static long _vq_quantmap__44u0__p7_2[] = {
  131995. 11, 9, 7, 5, 3, 1, 0, 2,
  131996. 4, 6, 8, 10, 12,
  131997. };
  131998. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  131999. _vq_quantthresh__44u0__p7_2,
  132000. _vq_quantmap__44u0__p7_2,
  132001. 13,
  132002. 13
  132003. };
  132004. static static_codebook _44u0__p7_2 = {
  132005. 2, 169,
  132006. _vq_lengthlist__44u0__p7_2,
  132007. 1, -531103744, 1611661312, 4, 0,
  132008. _vq_quantlist__44u0__p7_2,
  132009. NULL,
  132010. &_vq_auxt__44u0__p7_2,
  132011. NULL,
  132012. 0
  132013. };
  132014. static long _huff_lengthlist__44u0__short[] = {
  132015. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132016. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132017. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132018. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132019. };
  132020. static static_codebook _huff_book__44u0__short = {
  132021. 2, 64,
  132022. _huff_lengthlist__44u0__short,
  132023. 0, 0, 0, 0, 0,
  132024. NULL,
  132025. NULL,
  132026. NULL,
  132027. NULL,
  132028. 0
  132029. };
  132030. static long _huff_lengthlist__44u1__long[] = {
  132031. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132032. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132033. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132034. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132035. };
  132036. static static_codebook _huff_book__44u1__long = {
  132037. 2, 64,
  132038. _huff_lengthlist__44u1__long,
  132039. 0, 0, 0, 0, 0,
  132040. NULL,
  132041. NULL,
  132042. NULL,
  132043. NULL,
  132044. 0
  132045. };
  132046. static long _vq_quantlist__44u1__p1_0[] = {
  132047. 1,
  132048. 0,
  132049. 2,
  132050. };
  132051. static long _vq_lengthlist__44u1__p1_0[] = {
  132052. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132053. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132054. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132055. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132056. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132057. 13,
  132058. };
  132059. static float _vq_quantthresh__44u1__p1_0[] = {
  132060. -0.5, 0.5,
  132061. };
  132062. static long _vq_quantmap__44u1__p1_0[] = {
  132063. 1, 0, 2,
  132064. };
  132065. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132066. _vq_quantthresh__44u1__p1_0,
  132067. _vq_quantmap__44u1__p1_0,
  132068. 3,
  132069. 3
  132070. };
  132071. static static_codebook _44u1__p1_0 = {
  132072. 4, 81,
  132073. _vq_lengthlist__44u1__p1_0,
  132074. 1, -535822336, 1611661312, 2, 0,
  132075. _vq_quantlist__44u1__p1_0,
  132076. NULL,
  132077. &_vq_auxt__44u1__p1_0,
  132078. NULL,
  132079. 0
  132080. };
  132081. static long _vq_quantlist__44u1__p2_0[] = {
  132082. 1,
  132083. 0,
  132084. 2,
  132085. };
  132086. static long _vq_lengthlist__44u1__p2_0[] = {
  132087. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132088. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132089. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132090. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132091. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132092. 9,
  132093. };
  132094. static float _vq_quantthresh__44u1__p2_0[] = {
  132095. -0.5, 0.5,
  132096. };
  132097. static long _vq_quantmap__44u1__p2_0[] = {
  132098. 1, 0, 2,
  132099. };
  132100. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132101. _vq_quantthresh__44u1__p2_0,
  132102. _vq_quantmap__44u1__p2_0,
  132103. 3,
  132104. 3
  132105. };
  132106. static static_codebook _44u1__p2_0 = {
  132107. 4, 81,
  132108. _vq_lengthlist__44u1__p2_0,
  132109. 1, -535822336, 1611661312, 2, 0,
  132110. _vq_quantlist__44u1__p2_0,
  132111. NULL,
  132112. &_vq_auxt__44u1__p2_0,
  132113. NULL,
  132114. 0
  132115. };
  132116. static long _vq_quantlist__44u1__p3_0[] = {
  132117. 2,
  132118. 1,
  132119. 3,
  132120. 0,
  132121. 4,
  132122. };
  132123. static long _vq_lengthlist__44u1__p3_0[] = {
  132124. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132125. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132126. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132127. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132128. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132129. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132130. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132131. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132132. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132133. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132134. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132135. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132136. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132137. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132138. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132139. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132140. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132141. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132142. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132143. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132144. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132145. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132146. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132147. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132148. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132149. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132150. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132151. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132152. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132153. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132154. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132155. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132156. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132157. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132158. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132159. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132160. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132161. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132162. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132163. 19,
  132164. };
  132165. static float _vq_quantthresh__44u1__p3_0[] = {
  132166. -1.5, -0.5, 0.5, 1.5,
  132167. };
  132168. static long _vq_quantmap__44u1__p3_0[] = {
  132169. 3, 1, 0, 2, 4,
  132170. };
  132171. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132172. _vq_quantthresh__44u1__p3_0,
  132173. _vq_quantmap__44u1__p3_0,
  132174. 5,
  132175. 5
  132176. };
  132177. static static_codebook _44u1__p3_0 = {
  132178. 4, 625,
  132179. _vq_lengthlist__44u1__p3_0,
  132180. 1, -533725184, 1611661312, 3, 0,
  132181. _vq_quantlist__44u1__p3_0,
  132182. NULL,
  132183. &_vq_auxt__44u1__p3_0,
  132184. NULL,
  132185. 0
  132186. };
  132187. static long _vq_quantlist__44u1__p4_0[] = {
  132188. 2,
  132189. 1,
  132190. 3,
  132191. 0,
  132192. 4,
  132193. };
  132194. static long _vq_lengthlist__44u1__p4_0[] = {
  132195. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132196. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132197. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132198. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132199. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132200. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132201. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132202. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132203. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132204. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132205. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132206. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132207. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132208. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132209. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132210. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132211. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132212. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132213. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132214. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132215. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132216. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132217. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132218. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132219. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132220. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132221. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132222. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132223. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132224. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132225. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132226. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132227. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132228. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132229. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132230. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132231. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132232. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132233. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132234. 12,
  132235. };
  132236. static float _vq_quantthresh__44u1__p4_0[] = {
  132237. -1.5, -0.5, 0.5, 1.5,
  132238. };
  132239. static long _vq_quantmap__44u1__p4_0[] = {
  132240. 3, 1, 0, 2, 4,
  132241. };
  132242. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132243. _vq_quantthresh__44u1__p4_0,
  132244. _vq_quantmap__44u1__p4_0,
  132245. 5,
  132246. 5
  132247. };
  132248. static static_codebook _44u1__p4_0 = {
  132249. 4, 625,
  132250. _vq_lengthlist__44u1__p4_0,
  132251. 1, -533725184, 1611661312, 3, 0,
  132252. _vq_quantlist__44u1__p4_0,
  132253. NULL,
  132254. &_vq_auxt__44u1__p4_0,
  132255. NULL,
  132256. 0
  132257. };
  132258. static long _vq_quantlist__44u1__p5_0[] = {
  132259. 4,
  132260. 3,
  132261. 5,
  132262. 2,
  132263. 6,
  132264. 1,
  132265. 7,
  132266. 0,
  132267. 8,
  132268. };
  132269. static long _vq_lengthlist__44u1__p5_0[] = {
  132270. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132271. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132272. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132273. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132274. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132275. 12,
  132276. };
  132277. static float _vq_quantthresh__44u1__p5_0[] = {
  132278. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132279. };
  132280. static long _vq_quantmap__44u1__p5_0[] = {
  132281. 7, 5, 3, 1, 0, 2, 4, 6,
  132282. 8,
  132283. };
  132284. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132285. _vq_quantthresh__44u1__p5_0,
  132286. _vq_quantmap__44u1__p5_0,
  132287. 9,
  132288. 9
  132289. };
  132290. static static_codebook _44u1__p5_0 = {
  132291. 2, 81,
  132292. _vq_lengthlist__44u1__p5_0,
  132293. 1, -531628032, 1611661312, 4, 0,
  132294. _vq_quantlist__44u1__p5_0,
  132295. NULL,
  132296. &_vq_auxt__44u1__p5_0,
  132297. NULL,
  132298. 0
  132299. };
  132300. static long _vq_quantlist__44u1__p6_0[] = {
  132301. 6,
  132302. 5,
  132303. 7,
  132304. 4,
  132305. 8,
  132306. 3,
  132307. 9,
  132308. 2,
  132309. 10,
  132310. 1,
  132311. 11,
  132312. 0,
  132313. 12,
  132314. };
  132315. static long _vq_lengthlist__44u1__p6_0[] = {
  132316. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132317. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132318. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132319. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132320. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132321. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132322. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132323. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132324. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132325. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132326. 15,17,16,17,18,17,17,18, 0,
  132327. };
  132328. static float _vq_quantthresh__44u1__p6_0[] = {
  132329. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132330. 12.5, 17.5, 22.5, 27.5,
  132331. };
  132332. static long _vq_quantmap__44u1__p6_0[] = {
  132333. 11, 9, 7, 5, 3, 1, 0, 2,
  132334. 4, 6, 8, 10, 12,
  132335. };
  132336. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132337. _vq_quantthresh__44u1__p6_0,
  132338. _vq_quantmap__44u1__p6_0,
  132339. 13,
  132340. 13
  132341. };
  132342. static static_codebook _44u1__p6_0 = {
  132343. 2, 169,
  132344. _vq_lengthlist__44u1__p6_0,
  132345. 1, -526516224, 1616117760, 4, 0,
  132346. _vq_quantlist__44u1__p6_0,
  132347. NULL,
  132348. &_vq_auxt__44u1__p6_0,
  132349. NULL,
  132350. 0
  132351. };
  132352. static long _vq_quantlist__44u1__p6_1[] = {
  132353. 2,
  132354. 1,
  132355. 3,
  132356. 0,
  132357. 4,
  132358. };
  132359. static long _vq_lengthlist__44u1__p6_1[] = {
  132360. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132361. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132362. };
  132363. static float _vq_quantthresh__44u1__p6_1[] = {
  132364. -1.5, -0.5, 0.5, 1.5,
  132365. };
  132366. static long _vq_quantmap__44u1__p6_1[] = {
  132367. 3, 1, 0, 2, 4,
  132368. };
  132369. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132370. _vq_quantthresh__44u1__p6_1,
  132371. _vq_quantmap__44u1__p6_1,
  132372. 5,
  132373. 5
  132374. };
  132375. static static_codebook _44u1__p6_1 = {
  132376. 2, 25,
  132377. _vq_lengthlist__44u1__p6_1,
  132378. 1, -533725184, 1611661312, 3, 0,
  132379. _vq_quantlist__44u1__p6_1,
  132380. NULL,
  132381. &_vq_auxt__44u1__p6_1,
  132382. NULL,
  132383. 0
  132384. };
  132385. static long _vq_quantlist__44u1__p7_0[] = {
  132386. 3,
  132387. 2,
  132388. 4,
  132389. 1,
  132390. 5,
  132391. 0,
  132392. 6,
  132393. };
  132394. static long _vq_lengthlist__44u1__p7_0[] = {
  132395. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132396. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132397. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132398. 8,
  132399. };
  132400. static float _vq_quantthresh__44u1__p7_0[] = {
  132401. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132402. };
  132403. static long _vq_quantmap__44u1__p7_0[] = {
  132404. 5, 3, 1, 0, 2, 4, 6,
  132405. };
  132406. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132407. _vq_quantthresh__44u1__p7_0,
  132408. _vq_quantmap__44u1__p7_0,
  132409. 7,
  132410. 7
  132411. };
  132412. static static_codebook _44u1__p7_0 = {
  132413. 2, 49,
  132414. _vq_lengthlist__44u1__p7_0,
  132415. 1, -518017024, 1626677248, 3, 0,
  132416. _vq_quantlist__44u1__p7_0,
  132417. NULL,
  132418. &_vq_auxt__44u1__p7_0,
  132419. NULL,
  132420. 0
  132421. };
  132422. static long _vq_quantlist__44u1__p7_1[] = {
  132423. 6,
  132424. 5,
  132425. 7,
  132426. 4,
  132427. 8,
  132428. 3,
  132429. 9,
  132430. 2,
  132431. 10,
  132432. 1,
  132433. 11,
  132434. 0,
  132435. 12,
  132436. };
  132437. static long _vq_lengthlist__44u1__p7_1[] = {
  132438. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132439. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132440. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132441. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132442. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132443. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132444. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132445. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132446. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132447. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132448. 15,15,15,15,15,15,15,15,15,
  132449. };
  132450. static float _vq_quantthresh__44u1__p7_1[] = {
  132451. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132452. 32.5, 45.5, 58.5, 71.5,
  132453. };
  132454. static long _vq_quantmap__44u1__p7_1[] = {
  132455. 11, 9, 7, 5, 3, 1, 0, 2,
  132456. 4, 6, 8, 10, 12,
  132457. };
  132458. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132459. _vq_quantthresh__44u1__p7_1,
  132460. _vq_quantmap__44u1__p7_1,
  132461. 13,
  132462. 13
  132463. };
  132464. static static_codebook _44u1__p7_1 = {
  132465. 2, 169,
  132466. _vq_lengthlist__44u1__p7_1,
  132467. 1, -523010048, 1618608128, 4, 0,
  132468. _vq_quantlist__44u1__p7_1,
  132469. NULL,
  132470. &_vq_auxt__44u1__p7_1,
  132471. NULL,
  132472. 0
  132473. };
  132474. static long _vq_quantlist__44u1__p7_2[] = {
  132475. 6,
  132476. 5,
  132477. 7,
  132478. 4,
  132479. 8,
  132480. 3,
  132481. 9,
  132482. 2,
  132483. 10,
  132484. 1,
  132485. 11,
  132486. 0,
  132487. 12,
  132488. };
  132489. static long _vq_lengthlist__44u1__p7_2[] = {
  132490. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132491. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132492. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132493. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132494. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132495. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132496. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132497. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132498. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132499. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132500. 9, 9, 9,10, 9, 9,10,10, 9,
  132501. };
  132502. static float _vq_quantthresh__44u1__p7_2[] = {
  132503. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132504. 2.5, 3.5, 4.5, 5.5,
  132505. };
  132506. static long _vq_quantmap__44u1__p7_2[] = {
  132507. 11, 9, 7, 5, 3, 1, 0, 2,
  132508. 4, 6, 8, 10, 12,
  132509. };
  132510. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132511. _vq_quantthresh__44u1__p7_2,
  132512. _vq_quantmap__44u1__p7_2,
  132513. 13,
  132514. 13
  132515. };
  132516. static static_codebook _44u1__p7_2 = {
  132517. 2, 169,
  132518. _vq_lengthlist__44u1__p7_2,
  132519. 1, -531103744, 1611661312, 4, 0,
  132520. _vq_quantlist__44u1__p7_2,
  132521. NULL,
  132522. &_vq_auxt__44u1__p7_2,
  132523. NULL,
  132524. 0
  132525. };
  132526. static long _huff_lengthlist__44u1__short[] = {
  132527. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132528. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132529. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132530. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132531. };
  132532. static static_codebook _huff_book__44u1__short = {
  132533. 2, 64,
  132534. _huff_lengthlist__44u1__short,
  132535. 0, 0, 0, 0, 0,
  132536. NULL,
  132537. NULL,
  132538. NULL,
  132539. NULL,
  132540. 0
  132541. };
  132542. static long _huff_lengthlist__44u2__long[] = {
  132543. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132544. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132545. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132546. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132547. };
  132548. static static_codebook _huff_book__44u2__long = {
  132549. 2, 64,
  132550. _huff_lengthlist__44u2__long,
  132551. 0, 0, 0, 0, 0,
  132552. NULL,
  132553. NULL,
  132554. NULL,
  132555. NULL,
  132556. 0
  132557. };
  132558. static long _vq_quantlist__44u2__p1_0[] = {
  132559. 1,
  132560. 0,
  132561. 2,
  132562. };
  132563. static long _vq_lengthlist__44u2__p1_0[] = {
  132564. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132565. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132566. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132567. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132568. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132569. 13,
  132570. };
  132571. static float _vq_quantthresh__44u2__p1_0[] = {
  132572. -0.5, 0.5,
  132573. };
  132574. static long _vq_quantmap__44u2__p1_0[] = {
  132575. 1, 0, 2,
  132576. };
  132577. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132578. _vq_quantthresh__44u2__p1_0,
  132579. _vq_quantmap__44u2__p1_0,
  132580. 3,
  132581. 3
  132582. };
  132583. static static_codebook _44u2__p1_0 = {
  132584. 4, 81,
  132585. _vq_lengthlist__44u2__p1_0,
  132586. 1, -535822336, 1611661312, 2, 0,
  132587. _vq_quantlist__44u2__p1_0,
  132588. NULL,
  132589. &_vq_auxt__44u2__p1_0,
  132590. NULL,
  132591. 0
  132592. };
  132593. static long _vq_quantlist__44u2__p2_0[] = {
  132594. 1,
  132595. 0,
  132596. 2,
  132597. };
  132598. static long _vq_lengthlist__44u2__p2_0[] = {
  132599. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132600. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132601. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132602. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132603. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132604. 9,
  132605. };
  132606. static float _vq_quantthresh__44u2__p2_0[] = {
  132607. -0.5, 0.5,
  132608. };
  132609. static long _vq_quantmap__44u2__p2_0[] = {
  132610. 1, 0, 2,
  132611. };
  132612. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132613. _vq_quantthresh__44u2__p2_0,
  132614. _vq_quantmap__44u2__p2_0,
  132615. 3,
  132616. 3
  132617. };
  132618. static static_codebook _44u2__p2_0 = {
  132619. 4, 81,
  132620. _vq_lengthlist__44u2__p2_0,
  132621. 1, -535822336, 1611661312, 2, 0,
  132622. _vq_quantlist__44u2__p2_0,
  132623. NULL,
  132624. &_vq_auxt__44u2__p2_0,
  132625. NULL,
  132626. 0
  132627. };
  132628. static long _vq_quantlist__44u2__p3_0[] = {
  132629. 2,
  132630. 1,
  132631. 3,
  132632. 0,
  132633. 4,
  132634. };
  132635. static long _vq_lengthlist__44u2__p3_0[] = {
  132636. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132637. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132638. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132639. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132640. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132641. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132642. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132643. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132644. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132645. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132646. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132647. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132648. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132649. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132650. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132651. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132652. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132653. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132654. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132655. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132656. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132657. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132658. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132659. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132660. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132661. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132662. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132663. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132664. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132665. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132666. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132667. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132668. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132669. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132670. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132671. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132672. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132673. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132674. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132675. 0,
  132676. };
  132677. static float _vq_quantthresh__44u2__p3_0[] = {
  132678. -1.5, -0.5, 0.5, 1.5,
  132679. };
  132680. static long _vq_quantmap__44u2__p3_0[] = {
  132681. 3, 1, 0, 2, 4,
  132682. };
  132683. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132684. _vq_quantthresh__44u2__p3_0,
  132685. _vq_quantmap__44u2__p3_0,
  132686. 5,
  132687. 5
  132688. };
  132689. static static_codebook _44u2__p3_0 = {
  132690. 4, 625,
  132691. _vq_lengthlist__44u2__p3_0,
  132692. 1, -533725184, 1611661312, 3, 0,
  132693. _vq_quantlist__44u2__p3_0,
  132694. NULL,
  132695. &_vq_auxt__44u2__p3_0,
  132696. NULL,
  132697. 0
  132698. };
  132699. static long _vq_quantlist__44u2__p4_0[] = {
  132700. 2,
  132701. 1,
  132702. 3,
  132703. 0,
  132704. 4,
  132705. };
  132706. static long _vq_lengthlist__44u2__p4_0[] = {
  132707. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132708. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132709. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132710. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132711. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132712. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132713. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132714. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132715. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132716. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132717. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132718. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132719. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132720. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132721. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132722. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132723. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132724. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132725. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132726. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132727. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132728. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132729. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132730. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132731. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132732. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132733. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132734. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132735. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132736. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132737. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132738. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132739. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132740. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132741. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132742. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132743. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132744. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132745. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132746. 13,
  132747. };
  132748. static float _vq_quantthresh__44u2__p4_0[] = {
  132749. -1.5, -0.5, 0.5, 1.5,
  132750. };
  132751. static long _vq_quantmap__44u2__p4_0[] = {
  132752. 3, 1, 0, 2, 4,
  132753. };
  132754. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132755. _vq_quantthresh__44u2__p4_0,
  132756. _vq_quantmap__44u2__p4_0,
  132757. 5,
  132758. 5
  132759. };
  132760. static static_codebook _44u2__p4_0 = {
  132761. 4, 625,
  132762. _vq_lengthlist__44u2__p4_0,
  132763. 1, -533725184, 1611661312, 3, 0,
  132764. _vq_quantlist__44u2__p4_0,
  132765. NULL,
  132766. &_vq_auxt__44u2__p4_0,
  132767. NULL,
  132768. 0
  132769. };
  132770. static long _vq_quantlist__44u2__p5_0[] = {
  132771. 4,
  132772. 3,
  132773. 5,
  132774. 2,
  132775. 6,
  132776. 1,
  132777. 7,
  132778. 0,
  132779. 8,
  132780. };
  132781. static long _vq_lengthlist__44u2__p5_0[] = {
  132782. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132783. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132784. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132785. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132786. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132787. 13,
  132788. };
  132789. static float _vq_quantthresh__44u2__p5_0[] = {
  132790. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132791. };
  132792. static long _vq_quantmap__44u2__p5_0[] = {
  132793. 7, 5, 3, 1, 0, 2, 4, 6,
  132794. 8,
  132795. };
  132796. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132797. _vq_quantthresh__44u2__p5_0,
  132798. _vq_quantmap__44u2__p5_0,
  132799. 9,
  132800. 9
  132801. };
  132802. static static_codebook _44u2__p5_0 = {
  132803. 2, 81,
  132804. _vq_lengthlist__44u2__p5_0,
  132805. 1, -531628032, 1611661312, 4, 0,
  132806. _vq_quantlist__44u2__p5_0,
  132807. NULL,
  132808. &_vq_auxt__44u2__p5_0,
  132809. NULL,
  132810. 0
  132811. };
  132812. static long _vq_quantlist__44u2__p6_0[] = {
  132813. 6,
  132814. 5,
  132815. 7,
  132816. 4,
  132817. 8,
  132818. 3,
  132819. 9,
  132820. 2,
  132821. 10,
  132822. 1,
  132823. 11,
  132824. 0,
  132825. 12,
  132826. };
  132827. static long _vq_lengthlist__44u2__p6_0[] = {
  132828. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132829. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132830. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132831. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132832. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132833. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132834. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132835. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132836. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132837. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132838. 15,17,17,16,18,17,18, 0, 0,
  132839. };
  132840. static float _vq_quantthresh__44u2__p6_0[] = {
  132841. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132842. 12.5, 17.5, 22.5, 27.5,
  132843. };
  132844. static long _vq_quantmap__44u2__p6_0[] = {
  132845. 11, 9, 7, 5, 3, 1, 0, 2,
  132846. 4, 6, 8, 10, 12,
  132847. };
  132848. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132849. _vq_quantthresh__44u2__p6_0,
  132850. _vq_quantmap__44u2__p6_0,
  132851. 13,
  132852. 13
  132853. };
  132854. static static_codebook _44u2__p6_0 = {
  132855. 2, 169,
  132856. _vq_lengthlist__44u2__p6_0,
  132857. 1, -526516224, 1616117760, 4, 0,
  132858. _vq_quantlist__44u2__p6_0,
  132859. NULL,
  132860. &_vq_auxt__44u2__p6_0,
  132861. NULL,
  132862. 0
  132863. };
  132864. static long _vq_quantlist__44u2__p6_1[] = {
  132865. 2,
  132866. 1,
  132867. 3,
  132868. 0,
  132869. 4,
  132870. };
  132871. static long _vq_lengthlist__44u2__p6_1[] = {
  132872. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132873. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132874. };
  132875. static float _vq_quantthresh__44u2__p6_1[] = {
  132876. -1.5, -0.5, 0.5, 1.5,
  132877. };
  132878. static long _vq_quantmap__44u2__p6_1[] = {
  132879. 3, 1, 0, 2, 4,
  132880. };
  132881. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132882. _vq_quantthresh__44u2__p6_1,
  132883. _vq_quantmap__44u2__p6_1,
  132884. 5,
  132885. 5
  132886. };
  132887. static static_codebook _44u2__p6_1 = {
  132888. 2, 25,
  132889. _vq_lengthlist__44u2__p6_1,
  132890. 1, -533725184, 1611661312, 3, 0,
  132891. _vq_quantlist__44u2__p6_1,
  132892. NULL,
  132893. &_vq_auxt__44u2__p6_1,
  132894. NULL,
  132895. 0
  132896. };
  132897. static long _vq_quantlist__44u2__p7_0[] = {
  132898. 4,
  132899. 3,
  132900. 5,
  132901. 2,
  132902. 6,
  132903. 1,
  132904. 7,
  132905. 0,
  132906. 8,
  132907. };
  132908. static long _vq_lengthlist__44u2__p7_0[] = {
  132909. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132910. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132911. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132912. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132913. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132914. 11,
  132915. };
  132916. static float _vq_quantthresh__44u2__p7_0[] = {
  132917. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  132918. };
  132919. static long _vq_quantmap__44u2__p7_0[] = {
  132920. 7, 5, 3, 1, 0, 2, 4, 6,
  132921. 8,
  132922. };
  132923. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  132924. _vq_quantthresh__44u2__p7_0,
  132925. _vq_quantmap__44u2__p7_0,
  132926. 9,
  132927. 9
  132928. };
  132929. static static_codebook _44u2__p7_0 = {
  132930. 2, 81,
  132931. _vq_lengthlist__44u2__p7_0,
  132932. 1, -516612096, 1626677248, 4, 0,
  132933. _vq_quantlist__44u2__p7_0,
  132934. NULL,
  132935. &_vq_auxt__44u2__p7_0,
  132936. NULL,
  132937. 0
  132938. };
  132939. static long _vq_quantlist__44u2__p7_1[] = {
  132940. 6,
  132941. 5,
  132942. 7,
  132943. 4,
  132944. 8,
  132945. 3,
  132946. 9,
  132947. 2,
  132948. 10,
  132949. 1,
  132950. 11,
  132951. 0,
  132952. 12,
  132953. };
  132954. static long _vq_lengthlist__44u2__p7_1[] = {
  132955. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  132956. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  132957. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  132958. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  132959. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  132960. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  132961. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  132962. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  132963. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  132964. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  132965. 14,14,14,17,15,17,17,17,17,
  132966. };
  132967. static float _vq_quantthresh__44u2__p7_1[] = {
  132968. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132969. 32.5, 45.5, 58.5, 71.5,
  132970. };
  132971. static long _vq_quantmap__44u2__p7_1[] = {
  132972. 11, 9, 7, 5, 3, 1, 0, 2,
  132973. 4, 6, 8, 10, 12,
  132974. };
  132975. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  132976. _vq_quantthresh__44u2__p7_1,
  132977. _vq_quantmap__44u2__p7_1,
  132978. 13,
  132979. 13
  132980. };
  132981. static static_codebook _44u2__p7_1 = {
  132982. 2, 169,
  132983. _vq_lengthlist__44u2__p7_1,
  132984. 1, -523010048, 1618608128, 4, 0,
  132985. _vq_quantlist__44u2__p7_1,
  132986. NULL,
  132987. &_vq_auxt__44u2__p7_1,
  132988. NULL,
  132989. 0
  132990. };
  132991. static long _vq_quantlist__44u2__p7_2[] = {
  132992. 6,
  132993. 5,
  132994. 7,
  132995. 4,
  132996. 8,
  132997. 3,
  132998. 9,
  132999. 2,
  133000. 10,
  133001. 1,
  133002. 11,
  133003. 0,
  133004. 12,
  133005. };
  133006. static long _vq_lengthlist__44u2__p7_2[] = {
  133007. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133008. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133009. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133010. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133011. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133012. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133013. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133014. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133015. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133016. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133017. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133018. };
  133019. static float _vq_quantthresh__44u2__p7_2[] = {
  133020. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133021. 2.5, 3.5, 4.5, 5.5,
  133022. };
  133023. static long _vq_quantmap__44u2__p7_2[] = {
  133024. 11, 9, 7, 5, 3, 1, 0, 2,
  133025. 4, 6, 8, 10, 12,
  133026. };
  133027. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133028. _vq_quantthresh__44u2__p7_2,
  133029. _vq_quantmap__44u2__p7_2,
  133030. 13,
  133031. 13
  133032. };
  133033. static static_codebook _44u2__p7_2 = {
  133034. 2, 169,
  133035. _vq_lengthlist__44u2__p7_2,
  133036. 1, -531103744, 1611661312, 4, 0,
  133037. _vq_quantlist__44u2__p7_2,
  133038. NULL,
  133039. &_vq_auxt__44u2__p7_2,
  133040. NULL,
  133041. 0
  133042. };
  133043. static long _huff_lengthlist__44u2__short[] = {
  133044. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133045. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133046. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133047. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133048. };
  133049. static static_codebook _huff_book__44u2__short = {
  133050. 2, 64,
  133051. _huff_lengthlist__44u2__short,
  133052. 0, 0, 0, 0, 0,
  133053. NULL,
  133054. NULL,
  133055. NULL,
  133056. NULL,
  133057. 0
  133058. };
  133059. static long _huff_lengthlist__44u3__long[] = {
  133060. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133061. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133062. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133063. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133064. };
  133065. static static_codebook _huff_book__44u3__long = {
  133066. 2, 64,
  133067. _huff_lengthlist__44u3__long,
  133068. 0, 0, 0, 0, 0,
  133069. NULL,
  133070. NULL,
  133071. NULL,
  133072. NULL,
  133073. 0
  133074. };
  133075. static long _vq_quantlist__44u3__p1_0[] = {
  133076. 1,
  133077. 0,
  133078. 2,
  133079. };
  133080. static long _vq_lengthlist__44u3__p1_0[] = {
  133081. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133082. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133083. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133084. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133085. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133086. 13,
  133087. };
  133088. static float _vq_quantthresh__44u3__p1_0[] = {
  133089. -0.5, 0.5,
  133090. };
  133091. static long _vq_quantmap__44u3__p1_0[] = {
  133092. 1, 0, 2,
  133093. };
  133094. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133095. _vq_quantthresh__44u3__p1_0,
  133096. _vq_quantmap__44u3__p1_0,
  133097. 3,
  133098. 3
  133099. };
  133100. static static_codebook _44u3__p1_0 = {
  133101. 4, 81,
  133102. _vq_lengthlist__44u3__p1_0,
  133103. 1, -535822336, 1611661312, 2, 0,
  133104. _vq_quantlist__44u3__p1_0,
  133105. NULL,
  133106. &_vq_auxt__44u3__p1_0,
  133107. NULL,
  133108. 0
  133109. };
  133110. static long _vq_quantlist__44u3__p2_0[] = {
  133111. 1,
  133112. 0,
  133113. 2,
  133114. };
  133115. static long _vq_lengthlist__44u3__p2_0[] = {
  133116. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133117. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133118. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133119. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133120. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133121. 9,
  133122. };
  133123. static float _vq_quantthresh__44u3__p2_0[] = {
  133124. -0.5, 0.5,
  133125. };
  133126. static long _vq_quantmap__44u3__p2_0[] = {
  133127. 1, 0, 2,
  133128. };
  133129. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133130. _vq_quantthresh__44u3__p2_0,
  133131. _vq_quantmap__44u3__p2_0,
  133132. 3,
  133133. 3
  133134. };
  133135. static static_codebook _44u3__p2_0 = {
  133136. 4, 81,
  133137. _vq_lengthlist__44u3__p2_0,
  133138. 1, -535822336, 1611661312, 2, 0,
  133139. _vq_quantlist__44u3__p2_0,
  133140. NULL,
  133141. &_vq_auxt__44u3__p2_0,
  133142. NULL,
  133143. 0
  133144. };
  133145. static long _vq_quantlist__44u3__p3_0[] = {
  133146. 2,
  133147. 1,
  133148. 3,
  133149. 0,
  133150. 4,
  133151. };
  133152. static long _vq_lengthlist__44u3__p3_0[] = {
  133153. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133154. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133155. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133156. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133157. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133158. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133159. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133160. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133161. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133162. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133163. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133164. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133165. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133166. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133167. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133168. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133169. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133170. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133171. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133172. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133173. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133174. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133175. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133176. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133177. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133178. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133179. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133180. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133181. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133182. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133183. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133184. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133185. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133186. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133187. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133188. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133189. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133190. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133191. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133192. 0,
  133193. };
  133194. static float _vq_quantthresh__44u3__p3_0[] = {
  133195. -1.5, -0.5, 0.5, 1.5,
  133196. };
  133197. static long _vq_quantmap__44u3__p3_0[] = {
  133198. 3, 1, 0, 2, 4,
  133199. };
  133200. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133201. _vq_quantthresh__44u3__p3_0,
  133202. _vq_quantmap__44u3__p3_0,
  133203. 5,
  133204. 5
  133205. };
  133206. static static_codebook _44u3__p3_0 = {
  133207. 4, 625,
  133208. _vq_lengthlist__44u3__p3_0,
  133209. 1, -533725184, 1611661312, 3, 0,
  133210. _vq_quantlist__44u3__p3_0,
  133211. NULL,
  133212. &_vq_auxt__44u3__p3_0,
  133213. NULL,
  133214. 0
  133215. };
  133216. static long _vq_quantlist__44u3__p4_0[] = {
  133217. 2,
  133218. 1,
  133219. 3,
  133220. 0,
  133221. 4,
  133222. };
  133223. static long _vq_lengthlist__44u3__p4_0[] = {
  133224. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133225. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133226. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133227. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133228. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133229. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133230. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133231. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133232. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133233. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133234. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133235. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133236. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133237. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133238. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133239. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133240. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133241. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133242. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133243. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133244. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133245. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133246. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133247. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133248. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133249. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133250. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133251. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133252. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133253. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133254. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133255. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133256. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133257. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133258. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133259. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133260. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133261. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133262. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133263. 13,
  133264. };
  133265. static float _vq_quantthresh__44u3__p4_0[] = {
  133266. -1.5, -0.5, 0.5, 1.5,
  133267. };
  133268. static long _vq_quantmap__44u3__p4_0[] = {
  133269. 3, 1, 0, 2, 4,
  133270. };
  133271. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133272. _vq_quantthresh__44u3__p4_0,
  133273. _vq_quantmap__44u3__p4_0,
  133274. 5,
  133275. 5
  133276. };
  133277. static static_codebook _44u3__p4_0 = {
  133278. 4, 625,
  133279. _vq_lengthlist__44u3__p4_0,
  133280. 1, -533725184, 1611661312, 3, 0,
  133281. _vq_quantlist__44u3__p4_0,
  133282. NULL,
  133283. &_vq_auxt__44u3__p4_0,
  133284. NULL,
  133285. 0
  133286. };
  133287. static long _vq_quantlist__44u3__p5_0[] = {
  133288. 4,
  133289. 3,
  133290. 5,
  133291. 2,
  133292. 6,
  133293. 1,
  133294. 7,
  133295. 0,
  133296. 8,
  133297. };
  133298. static long _vq_lengthlist__44u3__p5_0[] = {
  133299. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133300. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133301. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133302. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133303. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133304. 12,
  133305. };
  133306. static float _vq_quantthresh__44u3__p5_0[] = {
  133307. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133308. };
  133309. static long _vq_quantmap__44u3__p5_0[] = {
  133310. 7, 5, 3, 1, 0, 2, 4, 6,
  133311. 8,
  133312. };
  133313. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133314. _vq_quantthresh__44u3__p5_0,
  133315. _vq_quantmap__44u3__p5_0,
  133316. 9,
  133317. 9
  133318. };
  133319. static static_codebook _44u3__p5_0 = {
  133320. 2, 81,
  133321. _vq_lengthlist__44u3__p5_0,
  133322. 1, -531628032, 1611661312, 4, 0,
  133323. _vq_quantlist__44u3__p5_0,
  133324. NULL,
  133325. &_vq_auxt__44u3__p5_0,
  133326. NULL,
  133327. 0
  133328. };
  133329. static long _vq_quantlist__44u3__p6_0[] = {
  133330. 6,
  133331. 5,
  133332. 7,
  133333. 4,
  133334. 8,
  133335. 3,
  133336. 9,
  133337. 2,
  133338. 10,
  133339. 1,
  133340. 11,
  133341. 0,
  133342. 12,
  133343. };
  133344. static long _vq_lengthlist__44u3__p6_0[] = {
  133345. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133346. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133347. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133348. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133349. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133350. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133351. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133352. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133353. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133354. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133355. 15,16,16,16,17,18,16,20,18,
  133356. };
  133357. static float _vq_quantthresh__44u3__p6_0[] = {
  133358. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133359. 12.5, 17.5, 22.5, 27.5,
  133360. };
  133361. static long _vq_quantmap__44u3__p6_0[] = {
  133362. 11, 9, 7, 5, 3, 1, 0, 2,
  133363. 4, 6, 8, 10, 12,
  133364. };
  133365. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133366. _vq_quantthresh__44u3__p6_0,
  133367. _vq_quantmap__44u3__p6_0,
  133368. 13,
  133369. 13
  133370. };
  133371. static static_codebook _44u3__p6_0 = {
  133372. 2, 169,
  133373. _vq_lengthlist__44u3__p6_0,
  133374. 1, -526516224, 1616117760, 4, 0,
  133375. _vq_quantlist__44u3__p6_0,
  133376. NULL,
  133377. &_vq_auxt__44u3__p6_0,
  133378. NULL,
  133379. 0
  133380. };
  133381. static long _vq_quantlist__44u3__p6_1[] = {
  133382. 2,
  133383. 1,
  133384. 3,
  133385. 0,
  133386. 4,
  133387. };
  133388. static long _vq_lengthlist__44u3__p6_1[] = {
  133389. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133390. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133391. };
  133392. static float _vq_quantthresh__44u3__p6_1[] = {
  133393. -1.5, -0.5, 0.5, 1.5,
  133394. };
  133395. static long _vq_quantmap__44u3__p6_1[] = {
  133396. 3, 1, 0, 2, 4,
  133397. };
  133398. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133399. _vq_quantthresh__44u3__p6_1,
  133400. _vq_quantmap__44u3__p6_1,
  133401. 5,
  133402. 5
  133403. };
  133404. static static_codebook _44u3__p6_1 = {
  133405. 2, 25,
  133406. _vq_lengthlist__44u3__p6_1,
  133407. 1, -533725184, 1611661312, 3, 0,
  133408. _vq_quantlist__44u3__p6_1,
  133409. NULL,
  133410. &_vq_auxt__44u3__p6_1,
  133411. NULL,
  133412. 0
  133413. };
  133414. static long _vq_quantlist__44u3__p7_0[] = {
  133415. 4,
  133416. 3,
  133417. 5,
  133418. 2,
  133419. 6,
  133420. 1,
  133421. 7,
  133422. 0,
  133423. 8,
  133424. };
  133425. static long _vq_lengthlist__44u3__p7_0[] = {
  133426. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133427. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133428. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133429. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133430. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133431. 9,
  133432. };
  133433. static float _vq_quantthresh__44u3__p7_0[] = {
  133434. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133435. };
  133436. static long _vq_quantmap__44u3__p7_0[] = {
  133437. 7, 5, 3, 1, 0, 2, 4, 6,
  133438. 8,
  133439. };
  133440. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133441. _vq_quantthresh__44u3__p7_0,
  133442. _vq_quantmap__44u3__p7_0,
  133443. 9,
  133444. 9
  133445. };
  133446. static static_codebook _44u3__p7_0 = {
  133447. 2, 81,
  133448. _vq_lengthlist__44u3__p7_0,
  133449. 1, -515907584, 1627381760, 4, 0,
  133450. _vq_quantlist__44u3__p7_0,
  133451. NULL,
  133452. &_vq_auxt__44u3__p7_0,
  133453. NULL,
  133454. 0
  133455. };
  133456. static long _vq_quantlist__44u3__p7_1[] = {
  133457. 7,
  133458. 6,
  133459. 8,
  133460. 5,
  133461. 9,
  133462. 4,
  133463. 10,
  133464. 3,
  133465. 11,
  133466. 2,
  133467. 12,
  133468. 1,
  133469. 13,
  133470. 0,
  133471. 14,
  133472. };
  133473. static long _vq_lengthlist__44u3__p7_1[] = {
  133474. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133475. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133476. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133477. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133478. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133479. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133480. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133481. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133482. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133483. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133484. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133485. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133486. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133487. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133488. 17,
  133489. };
  133490. static float _vq_quantthresh__44u3__p7_1[] = {
  133491. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133492. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133493. };
  133494. static long _vq_quantmap__44u3__p7_1[] = {
  133495. 13, 11, 9, 7, 5, 3, 1, 0,
  133496. 2, 4, 6, 8, 10, 12, 14,
  133497. };
  133498. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133499. _vq_quantthresh__44u3__p7_1,
  133500. _vq_quantmap__44u3__p7_1,
  133501. 15,
  133502. 15
  133503. };
  133504. static static_codebook _44u3__p7_1 = {
  133505. 2, 225,
  133506. _vq_lengthlist__44u3__p7_1,
  133507. 1, -522338304, 1620115456, 4, 0,
  133508. _vq_quantlist__44u3__p7_1,
  133509. NULL,
  133510. &_vq_auxt__44u3__p7_1,
  133511. NULL,
  133512. 0
  133513. };
  133514. static long _vq_quantlist__44u3__p7_2[] = {
  133515. 8,
  133516. 7,
  133517. 9,
  133518. 6,
  133519. 10,
  133520. 5,
  133521. 11,
  133522. 4,
  133523. 12,
  133524. 3,
  133525. 13,
  133526. 2,
  133527. 14,
  133528. 1,
  133529. 15,
  133530. 0,
  133531. 16,
  133532. };
  133533. static long _vq_lengthlist__44u3__p7_2[] = {
  133534. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133535. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133536. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133537. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133538. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133539. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133540. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133541. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133542. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133543. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133544. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133545. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133546. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133547. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133548. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133549. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133550. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133551. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133552. 11,
  133553. };
  133554. static float _vq_quantthresh__44u3__p7_2[] = {
  133555. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133556. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133557. };
  133558. static long _vq_quantmap__44u3__p7_2[] = {
  133559. 15, 13, 11, 9, 7, 5, 3, 1,
  133560. 0, 2, 4, 6, 8, 10, 12, 14,
  133561. 16,
  133562. };
  133563. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133564. _vq_quantthresh__44u3__p7_2,
  133565. _vq_quantmap__44u3__p7_2,
  133566. 17,
  133567. 17
  133568. };
  133569. static static_codebook _44u3__p7_2 = {
  133570. 2, 289,
  133571. _vq_lengthlist__44u3__p7_2,
  133572. 1, -529530880, 1611661312, 5, 0,
  133573. _vq_quantlist__44u3__p7_2,
  133574. NULL,
  133575. &_vq_auxt__44u3__p7_2,
  133576. NULL,
  133577. 0
  133578. };
  133579. static long _huff_lengthlist__44u3__short[] = {
  133580. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133581. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133582. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133583. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133584. };
  133585. static static_codebook _huff_book__44u3__short = {
  133586. 2, 64,
  133587. _huff_lengthlist__44u3__short,
  133588. 0, 0, 0, 0, 0,
  133589. NULL,
  133590. NULL,
  133591. NULL,
  133592. NULL,
  133593. 0
  133594. };
  133595. static long _huff_lengthlist__44u4__long[] = {
  133596. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133597. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133598. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133599. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133600. };
  133601. static static_codebook _huff_book__44u4__long = {
  133602. 2, 64,
  133603. _huff_lengthlist__44u4__long,
  133604. 0, 0, 0, 0, 0,
  133605. NULL,
  133606. NULL,
  133607. NULL,
  133608. NULL,
  133609. 0
  133610. };
  133611. static long _vq_quantlist__44u4__p1_0[] = {
  133612. 1,
  133613. 0,
  133614. 2,
  133615. };
  133616. static long _vq_lengthlist__44u4__p1_0[] = {
  133617. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133618. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133619. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133620. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133621. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133622. 13,
  133623. };
  133624. static float _vq_quantthresh__44u4__p1_0[] = {
  133625. -0.5, 0.5,
  133626. };
  133627. static long _vq_quantmap__44u4__p1_0[] = {
  133628. 1, 0, 2,
  133629. };
  133630. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133631. _vq_quantthresh__44u4__p1_0,
  133632. _vq_quantmap__44u4__p1_0,
  133633. 3,
  133634. 3
  133635. };
  133636. static static_codebook _44u4__p1_0 = {
  133637. 4, 81,
  133638. _vq_lengthlist__44u4__p1_0,
  133639. 1, -535822336, 1611661312, 2, 0,
  133640. _vq_quantlist__44u4__p1_0,
  133641. NULL,
  133642. &_vq_auxt__44u4__p1_0,
  133643. NULL,
  133644. 0
  133645. };
  133646. static long _vq_quantlist__44u4__p2_0[] = {
  133647. 1,
  133648. 0,
  133649. 2,
  133650. };
  133651. static long _vq_lengthlist__44u4__p2_0[] = {
  133652. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133653. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133654. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133655. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133656. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133657. 9,
  133658. };
  133659. static float _vq_quantthresh__44u4__p2_0[] = {
  133660. -0.5, 0.5,
  133661. };
  133662. static long _vq_quantmap__44u4__p2_0[] = {
  133663. 1, 0, 2,
  133664. };
  133665. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133666. _vq_quantthresh__44u4__p2_0,
  133667. _vq_quantmap__44u4__p2_0,
  133668. 3,
  133669. 3
  133670. };
  133671. static static_codebook _44u4__p2_0 = {
  133672. 4, 81,
  133673. _vq_lengthlist__44u4__p2_0,
  133674. 1, -535822336, 1611661312, 2, 0,
  133675. _vq_quantlist__44u4__p2_0,
  133676. NULL,
  133677. &_vq_auxt__44u4__p2_0,
  133678. NULL,
  133679. 0
  133680. };
  133681. static long _vq_quantlist__44u4__p3_0[] = {
  133682. 2,
  133683. 1,
  133684. 3,
  133685. 0,
  133686. 4,
  133687. };
  133688. static long _vq_lengthlist__44u4__p3_0[] = {
  133689. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133690. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133691. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133692. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133693. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133694. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133695. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133696. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133697. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133698. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133699. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133700. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133701. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133702. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133703. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133704. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133705. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133706. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133707. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133708. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133709. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133710. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133711. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133712. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133713. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133714. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133715. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133716. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133717. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133718. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133719. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133720. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133721. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133722. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133723. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133724. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133725. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133726. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133727. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133728. 0,
  133729. };
  133730. static float _vq_quantthresh__44u4__p3_0[] = {
  133731. -1.5, -0.5, 0.5, 1.5,
  133732. };
  133733. static long _vq_quantmap__44u4__p3_0[] = {
  133734. 3, 1, 0, 2, 4,
  133735. };
  133736. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133737. _vq_quantthresh__44u4__p3_0,
  133738. _vq_quantmap__44u4__p3_0,
  133739. 5,
  133740. 5
  133741. };
  133742. static static_codebook _44u4__p3_0 = {
  133743. 4, 625,
  133744. _vq_lengthlist__44u4__p3_0,
  133745. 1, -533725184, 1611661312, 3, 0,
  133746. _vq_quantlist__44u4__p3_0,
  133747. NULL,
  133748. &_vq_auxt__44u4__p3_0,
  133749. NULL,
  133750. 0
  133751. };
  133752. static long _vq_quantlist__44u4__p4_0[] = {
  133753. 2,
  133754. 1,
  133755. 3,
  133756. 0,
  133757. 4,
  133758. };
  133759. static long _vq_lengthlist__44u4__p4_0[] = {
  133760. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133761. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133762. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133763. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133764. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133765. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133766. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133767. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133768. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133769. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133770. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133771. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133772. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133773. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133774. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133775. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133776. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133777. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133778. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133779. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133780. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133781. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133782. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133783. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133784. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133785. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133786. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133787. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133788. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133789. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133790. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133791. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133792. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133793. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133794. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133795. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133796. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133797. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133798. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133799. 13,
  133800. };
  133801. static float _vq_quantthresh__44u4__p4_0[] = {
  133802. -1.5, -0.5, 0.5, 1.5,
  133803. };
  133804. static long _vq_quantmap__44u4__p4_0[] = {
  133805. 3, 1, 0, 2, 4,
  133806. };
  133807. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133808. _vq_quantthresh__44u4__p4_0,
  133809. _vq_quantmap__44u4__p4_0,
  133810. 5,
  133811. 5
  133812. };
  133813. static static_codebook _44u4__p4_0 = {
  133814. 4, 625,
  133815. _vq_lengthlist__44u4__p4_0,
  133816. 1, -533725184, 1611661312, 3, 0,
  133817. _vq_quantlist__44u4__p4_0,
  133818. NULL,
  133819. &_vq_auxt__44u4__p4_0,
  133820. NULL,
  133821. 0
  133822. };
  133823. static long _vq_quantlist__44u4__p5_0[] = {
  133824. 4,
  133825. 3,
  133826. 5,
  133827. 2,
  133828. 6,
  133829. 1,
  133830. 7,
  133831. 0,
  133832. 8,
  133833. };
  133834. static long _vq_lengthlist__44u4__p5_0[] = {
  133835. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133836. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133837. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133838. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133839. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133840. 12,
  133841. };
  133842. static float _vq_quantthresh__44u4__p5_0[] = {
  133843. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133844. };
  133845. static long _vq_quantmap__44u4__p5_0[] = {
  133846. 7, 5, 3, 1, 0, 2, 4, 6,
  133847. 8,
  133848. };
  133849. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133850. _vq_quantthresh__44u4__p5_0,
  133851. _vq_quantmap__44u4__p5_0,
  133852. 9,
  133853. 9
  133854. };
  133855. static static_codebook _44u4__p5_0 = {
  133856. 2, 81,
  133857. _vq_lengthlist__44u4__p5_0,
  133858. 1, -531628032, 1611661312, 4, 0,
  133859. _vq_quantlist__44u4__p5_0,
  133860. NULL,
  133861. &_vq_auxt__44u4__p5_0,
  133862. NULL,
  133863. 0
  133864. };
  133865. static long _vq_quantlist__44u4__p6_0[] = {
  133866. 6,
  133867. 5,
  133868. 7,
  133869. 4,
  133870. 8,
  133871. 3,
  133872. 9,
  133873. 2,
  133874. 10,
  133875. 1,
  133876. 11,
  133877. 0,
  133878. 12,
  133879. };
  133880. static long _vq_lengthlist__44u4__p6_0[] = {
  133881. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133882. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133883. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133884. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133885. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133886. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133887. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133888. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133889. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133890. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133891. 16,16,16,17,17,18,17,20,21,
  133892. };
  133893. static float _vq_quantthresh__44u4__p6_0[] = {
  133894. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133895. 12.5, 17.5, 22.5, 27.5,
  133896. };
  133897. static long _vq_quantmap__44u4__p6_0[] = {
  133898. 11, 9, 7, 5, 3, 1, 0, 2,
  133899. 4, 6, 8, 10, 12,
  133900. };
  133901. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133902. _vq_quantthresh__44u4__p6_0,
  133903. _vq_quantmap__44u4__p6_0,
  133904. 13,
  133905. 13
  133906. };
  133907. static static_codebook _44u4__p6_0 = {
  133908. 2, 169,
  133909. _vq_lengthlist__44u4__p6_0,
  133910. 1, -526516224, 1616117760, 4, 0,
  133911. _vq_quantlist__44u4__p6_0,
  133912. NULL,
  133913. &_vq_auxt__44u4__p6_0,
  133914. NULL,
  133915. 0
  133916. };
  133917. static long _vq_quantlist__44u4__p6_1[] = {
  133918. 2,
  133919. 1,
  133920. 3,
  133921. 0,
  133922. 4,
  133923. };
  133924. static long _vq_lengthlist__44u4__p6_1[] = {
  133925. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133926. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133927. };
  133928. static float _vq_quantthresh__44u4__p6_1[] = {
  133929. -1.5, -0.5, 0.5, 1.5,
  133930. };
  133931. static long _vq_quantmap__44u4__p6_1[] = {
  133932. 3, 1, 0, 2, 4,
  133933. };
  133934. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  133935. _vq_quantthresh__44u4__p6_1,
  133936. _vq_quantmap__44u4__p6_1,
  133937. 5,
  133938. 5
  133939. };
  133940. static static_codebook _44u4__p6_1 = {
  133941. 2, 25,
  133942. _vq_lengthlist__44u4__p6_1,
  133943. 1, -533725184, 1611661312, 3, 0,
  133944. _vq_quantlist__44u4__p6_1,
  133945. NULL,
  133946. &_vq_auxt__44u4__p6_1,
  133947. NULL,
  133948. 0
  133949. };
  133950. static long _vq_quantlist__44u4__p7_0[] = {
  133951. 6,
  133952. 5,
  133953. 7,
  133954. 4,
  133955. 8,
  133956. 3,
  133957. 9,
  133958. 2,
  133959. 10,
  133960. 1,
  133961. 11,
  133962. 0,
  133963. 12,
  133964. };
  133965. static long _vq_lengthlist__44u4__p7_0[] = {
  133966. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  133967. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  133968. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133969. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133970. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133971. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133972. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133973. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133974. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133975. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133976. 11,11,11,11,11,11,11,11,11,
  133977. };
  133978. static float _vq_quantthresh__44u4__p7_0[] = {
  133979. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  133980. 637.5, 892.5, 1147.5, 1402.5,
  133981. };
  133982. static long _vq_quantmap__44u4__p7_0[] = {
  133983. 11, 9, 7, 5, 3, 1, 0, 2,
  133984. 4, 6, 8, 10, 12,
  133985. };
  133986. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  133987. _vq_quantthresh__44u4__p7_0,
  133988. _vq_quantmap__44u4__p7_0,
  133989. 13,
  133990. 13
  133991. };
  133992. static static_codebook _44u4__p7_0 = {
  133993. 2, 169,
  133994. _vq_lengthlist__44u4__p7_0,
  133995. 1, -514332672, 1627381760, 4, 0,
  133996. _vq_quantlist__44u4__p7_0,
  133997. NULL,
  133998. &_vq_auxt__44u4__p7_0,
  133999. NULL,
  134000. 0
  134001. };
  134002. static long _vq_quantlist__44u4__p7_1[] = {
  134003. 7,
  134004. 6,
  134005. 8,
  134006. 5,
  134007. 9,
  134008. 4,
  134009. 10,
  134010. 3,
  134011. 11,
  134012. 2,
  134013. 12,
  134014. 1,
  134015. 13,
  134016. 0,
  134017. 14,
  134018. };
  134019. static long _vq_lengthlist__44u4__p7_1[] = {
  134020. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134021. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134022. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134023. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134024. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134025. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134026. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134027. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134028. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134029. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134030. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134031. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134032. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134033. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134034. 16,
  134035. };
  134036. static float _vq_quantthresh__44u4__p7_1[] = {
  134037. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134038. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134039. };
  134040. static long _vq_quantmap__44u4__p7_1[] = {
  134041. 13, 11, 9, 7, 5, 3, 1, 0,
  134042. 2, 4, 6, 8, 10, 12, 14,
  134043. };
  134044. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134045. _vq_quantthresh__44u4__p7_1,
  134046. _vq_quantmap__44u4__p7_1,
  134047. 15,
  134048. 15
  134049. };
  134050. static static_codebook _44u4__p7_1 = {
  134051. 2, 225,
  134052. _vq_lengthlist__44u4__p7_1,
  134053. 1, -522338304, 1620115456, 4, 0,
  134054. _vq_quantlist__44u4__p7_1,
  134055. NULL,
  134056. &_vq_auxt__44u4__p7_1,
  134057. NULL,
  134058. 0
  134059. };
  134060. static long _vq_quantlist__44u4__p7_2[] = {
  134061. 8,
  134062. 7,
  134063. 9,
  134064. 6,
  134065. 10,
  134066. 5,
  134067. 11,
  134068. 4,
  134069. 12,
  134070. 3,
  134071. 13,
  134072. 2,
  134073. 14,
  134074. 1,
  134075. 15,
  134076. 0,
  134077. 16,
  134078. };
  134079. static long _vq_lengthlist__44u4__p7_2[] = {
  134080. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134081. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134082. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134083. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134084. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134085. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134086. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134087. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134088. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134089. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134090. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134091. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134092. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134093. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134095. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134096. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134097. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134098. 10,
  134099. };
  134100. static float _vq_quantthresh__44u4__p7_2[] = {
  134101. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134102. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134103. };
  134104. static long _vq_quantmap__44u4__p7_2[] = {
  134105. 15, 13, 11, 9, 7, 5, 3, 1,
  134106. 0, 2, 4, 6, 8, 10, 12, 14,
  134107. 16,
  134108. };
  134109. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134110. _vq_quantthresh__44u4__p7_2,
  134111. _vq_quantmap__44u4__p7_2,
  134112. 17,
  134113. 17
  134114. };
  134115. static static_codebook _44u4__p7_2 = {
  134116. 2, 289,
  134117. _vq_lengthlist__44u4__p7_2,
  134118. 1, -529530880, 1611661312, 5, 0,
  134119. _vq_quantlist__44u4__p7_2,
  134120. NULL,
  134121. &_vq_auxt__44u4__p7_2,
  134122. NULL,
  134123. 0
  134124. };
  134125. static long _huff_lengthlist__44u4__short[] = {
  134126. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134127. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134128. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134129. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134130. };
  134131. static static_codebook _huff_book__44u4__short = {
  134132. 2, 64,
  134133. _huff_lengthlist__44u4__short,
  134134. 0, 0, 0, 0, 0,
  134135. NULL,
  134136. NULL,
  134137. NULL,
  134138. NULL,
  134139. 0
  134140. };
  134141. static long _huff_lengthlist__44u5__long[] = {
  134142. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134143. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134144. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134145. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134146. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134147. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134148. 14, 8, 7, 8,
  134149. };
  134150. static static_codebook _huff_book__44u5__long = {
  134151. 2, 100,
  134152. _huff_lengthlist__44u5__long,
  134153. 0, 0, 0, 0, 0,
  134154. NULL,
  134155. NULL,
  134156. NULL,
  134157. NULL,
  134158. 0
  134159. };
  134160. static long _vq_quantlist__44u5__p1_0[] = {
  134161. 1,
  134162. 0,
  134163. 2,
  134164. };
  134165. static long _vq_lengthlist__44u5__p1_0[] = {
  134166. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134167. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134168. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134169. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134170. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134171. 12,
  134172. };
  134173. static float _vq_quantthresh__44u5__p1_0[] = {
  134174. -0.5, 0.5,
  134175. };
  134176. static long _vq_quantmap__44u5__p1_0[] = {
  134177. 1, 0, 2,
  134178. };
  134179. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134180. _vq_quantthresh__44u5__p1_0,
  134181. _vq_quantmap__44u5__p1_0,
  134182. 3,
  134183. 3
  134184. };
  134185. static static_codebook _44u5__p1_0 = {
  134186. 4, 81,
  134187. _vq_lengthlist__44u5__p1_0,
  134188. 1, -535822336, 1611661312, 2, 0,
  134189. _vq_quantlist__44u5__p1_0,
  134190. NULL,
  134191. &_vq_auxt__44u5__p1_0,
  134192. NULL,
  134193. 0
  134194. };
  134195. static long _vq_quantlist__44u5__p2_0[] = {
  134196. 1,
  134197. 0,
  134198. 2,
  134199. };
  134200. static long _vq_lengthlist__44u5__p2_0[] = {
  134201. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134202. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134203. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134204. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134205. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134206. 9,
  134207. };
  134208. static float _vq_quantthresh__44u5__p2_0[] = {
  134209. -0.5, 0.5,
  134210. };
  134211. static long _vq_quantmap__44u5__p2_0[] = {
  134212. 1, 0, 2,
  134213. };
  134214. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134215. _vq_quantthresh__44u5__p2_0,
  134216. _vq_quantmap__44u5__p2_0,
  134217. 3,
  134218. 3
  134219. };
  134220. static static_codebook _44u5__p2_0 = {
  134221. 4, 81,
  134222. _vq_lengthlist__44u5__p2_0,
  134223. 1, -535822336, 1611661312, 2, 0,
  134224. _vq_quantlist__44u5__p2_0,
  134225. NULL,
  134226. &_vq_auxt__44u5__p2_0,
  134227. NULL,
  134228. 0
  134229. };
  134230. static long _vq_quantlist__44u5__p3_0[] = {
  134231. 2,
  134232. 1,
  134233. 3,
  134234. 0,
  134235. 4,
  134236. };
  134237. static long _vq_lengthlist__44u5__p3_0[] = {
  134238. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134239. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134240. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134241. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134242. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134243. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134244. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134245. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134246. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134247. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134248. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134249. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134250. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134251. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134252. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134253. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134254. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134255. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134256. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134257. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134258. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134259. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134260. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134261. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134262. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134263. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134264. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134265. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134266. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134267. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134268. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134269. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134270. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134271. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134272. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134273. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134274. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134275. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134276. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134277. 0,
  134278. };
  134279. static float _vq_quantthresh__44u5__p3_0[] = {
  134280. -1.5, -0.5, 0.5, 1.5,
  134281. };
  134282. static long _vq_quantmap__44u5__p3_0[] = {
  134283. 3, 1, 0, 2, 4,
  134284. };
  134285. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134286. _vq_quantthresh__44u5__p3_0,
  134287. _vq_quantmap__44u5__p3_0,
  134288. 5,
  134289. 5
  134290. };
  134291. static static_codebook _44u5__p3_0 = {
  134292. 4, 625,
  134293. _vq_lengthlist__44u5__p3_0,
  134294. 1, -533725184, 1611661312, 3, 0,
  134295. _vq_quantlist__44u5__p3_0,
  134296. NULL,
  134297. &_vq_auxt__44u5__p3_0,
  134298. NULL,
  134299. 0
  134300. };
  134301. static long _vq_quantlist__44u5__p4_0[] = {
  134302. 2,
  134303. 1,
  134304. 3,
  134305. 0,
  134306. 4,
  134307. };
  134308. static long _vq_lengthlist__44u5__p4_0[] = {
  134309. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134310. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134311. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134312. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134313. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134314. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134315. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134316. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134317. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134318. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134319. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134320. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134321. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134322. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134323. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134324. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134325. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134326. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134327. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134328. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134329. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134330. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134331. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134332. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134333. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134334. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134335. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134336. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134337. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134338. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134339. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134340. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134341. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134342. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134343. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134344. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134345. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134346. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134347. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134348. 12,
  134349. };
  134350. static float _vq_quantthresh__44u5__p4_0[] = {
  134351. -1.5, -0.5, 0.5, 1.5,
  134352. };
  134353. static long _vq_quantmap__44u5__p4_0[] = {
  134354. 3, 1, 0, 2, 4,
  134355. };
  134356. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134357. _vq_quantthresh__44u5__p4_0,
  134358. _vq_quantmap__44u5__p4_0,
  134359. 5,
  134360. 5
  134361. };
  134362. static static_codebook _44u5__p4_0 = {
  134363. 4, 625,
  134364. _vq_lengthlist__44u5__p4_0,
  134365. 1, -533725184, 1611661312, 3, 0,
  134366. _vq_quantlist__44u5__p4_0,
  134367. NULL,
  134368. &_vq_auxt__44u5__p4_0,
  134369. NULL,
  134370. 0
  134371. };
  134372. static long _vq_quantlist__44u5__p5_0[] = {
  134373. 4,
  134374. 3,
  134375. 5,
  134376. 2,
  134377. 6,
  134378. 1,
  134379. 7,
  134380. 0,
  134381. 8,
  134382. };
  134383. static long _vq_lengthlist__44u5__p5_0[] = {
  134384. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134385. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134386. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134387. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134388. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134389. 14,
  134390. };
  134391. static float _vq_quantthresh__44u5__p5_0[] = {
  134392. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134393. };
  134394. static long _vq_quantmap__44u5__p5_0[] = {
  134395. 7, 5, 3, 1, 0, 2, 4, 6,
  134396. 8,
  134397. };
  134398. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134399. _vq_quantthresh__44u5__p5_0,
  134400. _vq_quantmap__44u5__p5_0,
  134401. 9,
  134402. 9
  134403. };
  134404. static static_codebook _44u5__p5_0 = {
  134405. 2, 81,
  134406. _vq_lengthlist__44u5__p5_0,
  134407. 1, -531628032, 1611661312, 4, 0,
  134408. _vq_quantlist__44u5__p5_0,
  134409. NULL,
  134410. &_vq_auxt__44u5__p5_0,
  134411. NULL,
  134412. 0
  134413. };
  134414. static long _vq_quantlist__44u5__p6_0[] = {
  134415. 4,
  134416. 3,
  134417. 5,
  134418. 2,
  134419. 6,
  134420. 1,
  134421. 7,
  134422. 0,
  134423. 8,
  134424. };
  134425. static long _vq_lengthlist__44u5__p6_0[] = {
  134426. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134427. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134428. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134429. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134430. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134431. 11,
  134432. };
  134433. static float _vq_quantthresh__44u5__p6_0[] = {
  134434. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134435. };
  134436. static long _vq_quantmap__44u5__p6_0[] = {
  134437. 7, 5, 3, 1, 0, 2, 4, 6,
  134438. 8,
  134439. };
  134440. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134441. _vq_quantthresh__44u5__p6_0,
  134442. _vq_quantmap__44u5__p6_0,
  134443. 9,
  134444. 9
  134445. };
  134446. static static_codebook _44u5__p6_0 = {
  134447. 2, 81,
  134448. _vq_lengthlist__44u5__p6_0,
  134449. 1, -531628032, 1611661312, 4, 0,
  134450. _vq_quantlist__44u5__p6_0,
  134451. NULL,
  134452. &_vq_auxt__44u5__p6_0,
  134453. NULL,
  134454. 0
  134455. };
  134456. static long _vq_quantlist__44u5__p7_0[] = {
  134457. 1,
  134458. 0,
  134459. 2,
  134460. };
  134461. static long _vq_lengthlist__44u5__p7_0[] = {
  134462. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134463. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134464. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134465. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134466. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134467. 12,
  134468. };
  134469. static float _vq_quantthresh__44u5__p7_0[] = {
  134470. -5.5, 5.5,
  134471. };
  134472. static long _vq_quantmap__44u5__p7_0[] = {
  134473. 1, 0, 2,
  134474. };
  134475. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134476. _vq_quantthresh__44u5__p7_0,
  134477. _vq_quantmap__44u5__p7_0,
  134478. 3,
  134479. 3
  134480. };
  134481. static static_codebook _44u5__p7_0 = {
  134482. 4, 81,
  134483. _vq_lengthlist__44u5__p7_0,
  134484. 1, -529137664, 1618345984, 2, 0,
  134485. _vq_quantlist__44u5__p7_0,
  134486. NULL,
  134487. &_vq_auxt__44u5__p7_0,
  134488. NULL,
  134489. 0
  134490. };
  134491. static long _vq_quantlist__44u5__p7_1[] = {
  134492. 5,
  134493. 4,
  134494. 6,
  134495. 3,
  134496. 7,
  134497. 2,
  134498. 8,
  134499. 1,
  134500. 9,
  134501. 0,
  134502. 10,
  134503. };
  134504. static long _vq_lengthlist__44u5__p7_1[] = {
  134505. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134506. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134507. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134508. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134509. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134510. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134511. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134512. 9, 9, 9, 9, 9,10,10,10,10,
  134513. };
  134514. static float _vq_quantthresh__44u5__p7_1[] = {
  134515. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134516. 3.5, 4.5,
  134517. };
  134518. static long _vq_quantmap__44u5__p7_1[] = {
  134519. 9, 7, 5, 3, 1, 0, 2, 4,
  134520. 6, 8, 10,
  134521. };
  134522. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134523. _vq_quantthresh__44u5__p7_1,
  134524. _vq_quantmap__44u5__p7_1,
  134525. 11,
  134526. 11
  134527. };
  134528. static static_codebook _44u5__p7_1 = {
  134529. 2, 121,
  134530. _vq_lengthlist__44u5__p7_1,
  134531. 1, -531365888, 1611661312, 4, 0,
  134532. _vq_quantlist__44u5__p7_1,
  134533. NULL,
  134534. &_vq_auxt__44u5__p7_1,
  134535. NULL,
  134536. 0
  134537. };
  134538. static long _vq_quantlist__44u5__p8_0[] = {
  134539. 5,
  134540. 4,
  134541. 6,
  134542. 3,
  134543. 7,
  134544. 2,
  134545. 8,
  134546. 1,
  134547. 9,
  134548. 0,
  134549. 10,
  134550. };
  134551. static long _vq_lengthlist__44u5__p8_0[] = {
  134552. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134553. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134554. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134555. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134556. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134557. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134558. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134559. 12,13,13,14,14,14,14,15,15,
  134560. };
  134561. static float _vq_quantthresh__44u5__p8_0[] = {
  134562. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134563. 38.5, 49.5,
  134564. };
  134565. static long _vq_quantmap__44u5__p8_0[] = {
  134566. 9, 7, 5, 3, 1, 0, 2, 4,
  134567. 6, 8, 10,
  134568. };
  134569. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134570. _vq_quantthresh__44u5__p8_0,
  134571. _vq_quantmap__44u5__p8_0,
  134572. 11,
  134573. 11
  134574. };
  134575. static static_codebook _44u5__p8_0 = {
  134576. 2, 121,
  134577. _vq_lengthlist__44u5__p8_0,
  134578. 1, -524582912, 1618345984, 4, 0,
  134579. _vq_quantlist__44u5__p8_0,
  134580. NULL,
  134581. &_vq_auxt__44u5__p8_0,
  134582. NULL,
  134583. 0
  134584. };
  134585. static long _vq_quantlist__44u5__p8_1[] = {
  134586. 5,
  134587. 4,
  134588. 6,
  134589. 3,
  134590. 7,
  134591. 2,
  134592. 8,
  134593. 1,
  134594. 9,
  134595. 0,
  134596. 10,
  134597. };
  134598. static long _vq_lengthlist__44u5__p8_1[] = {
  134599. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134600. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134601. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134602. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134603. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134604. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134605. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134606. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134607. };
  134608. static float _vq_quantthresh__44u5__p8_1[] = {
  134609. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134610. 3.5, 4.5,
  134611. };
  134612. static long _vq_quantmap__44u5__p8_1[] = {
  134613. 9, 7, 5, 3, 1, 0, 2, 4,
  134614. 6, 8, 10,
  134615. };
  134616. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134617. _vq_quantthresh__44u5__p8_1,
  134618. _vq_quantmap__44u5__p8_1,
  134619. 11,
  134620. 11
  134621. };
  134622. static static_codebook _44u5__p8_1 = {
  134623. 2, 121,
  134624. _vq_lengthlist__44u5__p8_1,
  134625. 1, -531365888, 1611661312, 4, 0,
  134626. _vq_quantlist__44u5__p8_1,
  134627. NULL,
  134628. &_vq_auxt__44u5__p8_1,
  134629. NULL,
  134630. 0
  134631. };
  134632. static long _vq_quantlist__44u5__p9_0[] = {
  134633. 6,
  134634. 5,
  134635. 7,
  134636. 4,
  134637. 8,
  134638. 3,
  134639. 9,
  134640. 2,
  134641. 10,
  134642. 1,
  134643. 11,
  134644. 0,
  134645. 12,
  134646. };
  134647. static long _vq_lengthlist__44u5__p9_0[] = {
  134648. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134649. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134650. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134651. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134652. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134653. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134654. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134655. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134656. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134657. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134658. 12,12,12,12,12,12,12,12,12,
  134659. };
  134660. static float _vq_quantthresh__44u5__p9_0[] = {
  134661. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134662. 637.5, 892.5, 1147.5, 1402.5,
  134663. };
  134664. static long _vq_quantmap__44u5__p9_0[] = {
  134665. 11, 9, 7, 5, 3, 1, 0, 2,
  134666. 4, 6, 8, 10, 12,
  134667. };
  134668. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134669. _vq_quantthresh__44u5__p9_0,
  134670. _vq_quantmap__44u5__p9_0,
  134671. 13,
  134672. 13
  134673. };
  134674. static static_codebook _44u5__p9_0 = {
  134675. 2, 169,
  134676. _vq_lengthlist__44u5__p9_0,
  134677. 1, -514332672, 1627381760, 4, 0,
  134678. _vq_quantlist__44u5__p9_0,
  134679. NULL,
  134680. &_vq_auxt__44u5__p9_0,
  134681. NULL,
  134682. 0
  134683. };
  134684. static long _vq_quantlist__44u5__p9_1[] = {
  134685. 7,
  134686. 6,
  134687. 8,
  134688. 5,
  134689. 9,
  134690. 4,
  134691. 10,
  134692. 3,
  134693. 11,
  134694. 2,
  134695. 12,
  134696. 1,
  134697. 13,
  134698. 0,
  134699. 14,
  134700. };
  134701. static long _vq_lengthlist__44u5__p9_1[] = {
  134702. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134703. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134704. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134705. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134706. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134707. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134708. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134709. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134710. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134711. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134712. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134713. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134714. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134715. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134716. 14,
  134717. };
  134718. static float _vq_quantthresh__44u5__p9_1[] = {
  134719. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134720. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134721. };
  134722. static long _vq_quantmap__44u5__p9_1[] = {
  134723. 13, 11, 9, 7, 5, 3, 1, 0,
  134724. 2, 4, 6, 8, 10, 12, 14,
  134725. };
  134726. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134727. _vq_quantthresh__44u5__p9_1,
  134728. _vq_quantmap__44u5__p9_1,
  134729. 15,
  134730. 15
  134731. };
  134732. static static_codebook _44u5__p9_1 = {
  134733. 2, 225,
  134734. _vq_lengthlist__44u5__p9_1,
  134735. 1, -522338304, 1620115456, 4, 0,
  134736. _vq_quantlist__44u5__p9_1,
  134737. NULL,
  134738. &_vq_auxt__44u5__p9_1,
  134739. NULL,
  134740. 0
  134741. };
  134742. static long _vq_quantlist__44u5__p9_2[] = {
  134743. 8,
  134744. 7,
  134745. 9,
  134746. 6,
  134747. 10,
  134748. 5,
  134749. 11,
  134750. 4,
  134751. 12,
  134752. 3,
  134753. 13,
  134754. 2,
  134755. 14,
  134756. 1,
  134757. 15,
  134758. 0,
  134759. 16,
  134760. };
  134761. static long _vq_lengthlist__44u5__p9_2[] = {
  134762. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134763. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134764. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134765. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134766. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134767. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134768. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134769. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134770. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134771. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134772. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134773. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134774. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134775. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134776. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134777. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134778. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134779. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134780. 10,
  134781. };
  134782. static float _vq_quantthresh__44u5__p9_2[] = {
  134783. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134784. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134785. };
  134786. static long _vq_quantmap__44u5__p9_2[] = {
  134787. 15, 13, 11, 9, 7, 5, 3, 1,
  134788. 0, 2, 4, 6, 8, 10, 12, 14,
  134789. 16,
  134790. };
  134791. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134792. _vq_quantthresh__44u5__p9_2,
  134793. _vq_quantmap__44u5__p9_2,
  134794. 17,
  134795. 17
  134796. };
  134797. static static_codebook _44u5__p9_2 = {
  134798. 2, 289,
  134799. _vq_lengthlist__44u5__p9_2,
  134800. 1, -529530880, 1611661312, 5, 0,
  134801. _vq_quantlist__44u5__p9_2,
  134802. NULL,
  134803. &_vq_auxt__44u5__p9_2,
  134804. NULL,
  134805. 0
  134806. };
  134807. static long _huff_lengthlist__44u5__short[] = {
  134808. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134809. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134810. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134811. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134812. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134813. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134814. 6, 8,15,17,
  134815. };
  134816. static static_codebook _huff_book__44u5__short = {
  134817. 2, 100,
  134818. _huff_lengthlist__44u5__short,
  134819. 0, 0, 0, 0, 0,
  134820. NULL,
  134821. NULL,
  134822. NULL,
  134823. NULL,
  134824. 0
  134825. };
  134826. static long _huff_lengthlist__44u6__long[] = {
  134827. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134828. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134829. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134830. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134831. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134832. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134833. 13, 8, 7, 7,
  134834. };
  134835. static static_codebook _huff_book__44u6__long = {
  134836. 2, 100,
  134837. _huff_lengthlist__44u6__long,
  134838. 0, 0, 0, 0, 0,
  134839. NULL,
  134840. NULL,
  134841. NULL,
  134842. NULL,
  134843. 0
  134844. };
  134845. static long _vq_quantlist__44u6__p1_0[] = {
  134846. 1,
  134847. 0,
  134848. 2,
  134849. };
  134850. static long _vq_lengthlist__44u6__p1_0[] = {
  134851. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134852. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134853. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134854. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134855. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134856. 12,
  134857. };
  134858. static float _vq_quantthresh__44u6__p1_0[] = {
  134859. -0.5, 0.5,
  134860. };
  134861. static long _vq_quantmap__44u6__p1_0[] = {
  134862. 1, 0, 2,
  134863. };
  134864. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134865. _vq_quantthresh__44u6__p1_0,
  134866. _vq_quantmap__44u6__p1_0,
  134867. 3,
  134868. 3
  134869. };
  134870. static static_codebook _44u6__p1_0 = {
  134871. 4, 81,
  134872. _vq_lengthlist__44u6__p1_0,
  134873. 1, -535822336, 1611661312, 2, 0,
  134874. _vq_quantlist__44u6__p1_0,
  134875. NULL,
  134876. &_vq_auxt__44u6__p1_0,
  134877. NULL,
  134878. 0
  134879. };
  134880. static long _vq_quantlist__44u6__p2_0[] = {
  134881. 1,
  134882. 0,
  134883. 2,
  134884. };
  134885. static long _vq_lengthlist__44u6__p2_0[] = {
  134886. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134887. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134888. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134889. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134890. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134891. 9,
  134892. };
  134893. static float _vq_quantthresh__44u6__p2_0[] = {
  134894. -0.5, 0.5,
  134895. };
  134896. static long _vq_quantmap__44u6__p2_0[] = {
  134897. 1, 0, 2,
  134898. };
  134899. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134900. _vq_quantthresh__44u6__p2_0,
  134901. _vq_quantmap__44u6__p2_0,
  134902. 3,
  134903. 3
  134904. };
  134905. static static_codebook _44u6__p2_0 = {
  134906. 4, 81,
  134907. _vq_lengthlist__44u6__p2_0,
  134908. 1, -535822336, 1611661312, 2, 0,
  134909. _vq_quantlist__44u6__p2_0,
  134910. NULL,
  134911. &_vq_auxt__44u6__p2_0,
  134912. NULL,
  134913. 0
  134914. };
  134915. static long _vq_quantlist__44u6__p3_0[] = {
  134916. 2,
  134917. 1,
  134918. 3,
  134919. 0,
  134920. 4,
  134921. };
  134922. static long _vq_lengthlist__44u6__p3_0[] = {
  134923. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134924. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  134925. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134926. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  134927. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  134928. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  134929. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  134930. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  134931. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  134932. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134933. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  134934. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134935. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  134936. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  134937. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  134938. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  134939. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134940. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  134941. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  134942. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  134943. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  134944. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  134945. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  134946. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  134947. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  134948. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  134949. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  134950. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  134951. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  134952. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  134953. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  134954. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  134955. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  134956. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  134957. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  134958. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  134959. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  134960. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  134961. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  134962. 19,
  134963. };
  134964. static float _vq_quantthresh__44u6__p3_0[] = {
  134965. -1.5, -0.5, 0.5, 1.5,
  134966. };
  134967. static long _vq_quantmap__44u6__p3_0[] = {
  134968. 3, 1, 0, 2, 4,
  134969. };
  134970. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  134971. _vq_quantthresh__44u6__p3_0,
  134972. _vq_quantmap__44u6__p3_0,
  134973. 5,
  134974. 5
  134975. };
  134976. static static_codebook _44u6__p3_0 = {
  134977. 4, 625,
  134978. _vq_lengthlist__44u6__p3_0,
  134979. 1, -533725184, 1611661312, 3, 0,
  134980. _vq_quantlist__44u6__p3_0,
  134981. NULL,
  134982. &_vq_auxt__44u6__p3_0,
  134983. NULL,
  134984. 0
  134985. };
  134986. static long _vq_quantlist__44u6__p4_0[] = {
  134987. 2,
  134988. 1,
  134989. 3,
  134990. 0,
  134991. 4,
  134992. };
  134993. static long _vq_lengthlist__44u6__p4_0[] = {
  134994. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134995. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134996. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  134997. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  134998. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  134999. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135000. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135001. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135002. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135003. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135004. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135005. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135006. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135007. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135008. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135009. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135010. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135011. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135012. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135013. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135014. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135015. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135016. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135017. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135018. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135019. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135020. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135021. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135022. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135023. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135024. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135025. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135026. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135027. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135028. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135029. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135030. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135031. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135032. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135033. 13,
  135034. };
  135035. static float _vq_quantthresh__44u6__p4_0[] = {
  135036. -1.5, -0.5, 0.5, 1.5,
  135037. };
  135038. static long _vq_quantmap__44u6__p4_0[] = {
  135039. 3, 1, 0, 2, 4,
  135040. };
  135041. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135042. _vq_quantthresh__44u6__p4_0,
  135043. _vq_quantmap__44u6__p4_0,
  135044. 5,
  135045. 5
  135046. };
  135047. static static_codebook _44u6__p4_0 = {
  135048. 4, 625,
  135049. _vq_lengthlist__44u6__p4_0,
  135050. 1, -533725184, 1611661312, 3, 0,
  135051. _vq_quantlist__44u6__p4_0,
  135052. NULL,
  135053. &_vq_auxt__44u6__p4_0,
  135054. NULL,
  135055. 0
  135056. };
  135057. static long _vq_quantlist__44u6__p5_0[] = {
  135058. 4,
  135059. 3,
  135060. 5,
  135061. 2,
  135062. 6,
  135063. 1,
  135064. 7,
  135065. 0,
  135066. 8,
  135067. };
  135068. static long _vq_lengthlist__44u6__p5_0[] = {
  135069. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135070. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135071. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135072. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135073. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135074. 14,
  135075. };
  135076. static float _vq_quantthresh__44u6__p5_0[] = {
  135077. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135078. };
  135079. static long _vq_quantmap__44u6__p5_0[] = {
  135080. 7, 5, 3, 1, 0, 2, 4, 6,
  135081. 8,
  135082. };
  135083. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135084. _vq_quantthresh__44u6__p5_0,
  135085. _vq_quantmap__44u6__p5_0,
  135086. 9,
  135087. 9
  135088. };
  135089. static static_codebook _44u6__p5_0 = {
  135090. 2, 81,
  135091. _vq_lengthlist__44u6__p5_0,
  135092. 1, -531628032, 1611661312, 4, 0,
  135093. _vq_quantlist__44u6__p5_0,
  135094. NULL,
  135095. &_vq_auxt__44u6__p5_0,
  135096. NULL,
  135097. 0
  135098. };
  135099. static long _vq_quantlist__44u6__p6_0[] = {
  135100. 4,
  135101. 3,
  135102. 5,
  135103. 2,
  135104. 6,
  135105. 1,
  135106. 7,
  135107. 0,
  135108. 8,
  135109. };
  135110. static long _vq_lengthlist__44u6__p6_0[] = {
  135111. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135112. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135113. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135114. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135115. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135116. 12,
  135117. };
  135118. static float _vq_quantthresh__44u6__p6_0[] = {
  135119. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135120. };
  135121. static long _vq_quantmap__44u6__p6_0[] = {
  135122. 7, 5, 3, 1, 0, 2, 4, 6,
  135123. 8,
  135124. };
  135125. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135126. _vq_quantthresh__44u6__p6_0,
  135127. _vq_quantmap__44u6__p6_0,
  135128. 9,
  135129. 9
  135130. };
  135131. static static_codebook _44u6__p6_0 = {
  135132. 2, 81,
  135133. _vq_lengthlist__44u6__p6_0,
  135134. 1, -531628032, 1611661312, 4, 0,
  135135. _vq_quantlist__44u6__p6_0,
  135136. NULL,
  135137. &_vq_auxt__44u6__p6_0,
  135138. NULL,
  135139. 0
  135140. };
  135141. static long _vq_quantlist__44u6__p7_0[] = {
  135142. 1,
  135143. 0,
  135144. 2,
  135145. };
  135146. static long _vq_lengthlist__44u6__p7_0[] = {
  135147. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135148. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135149. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135150. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135151. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135152. 10,
  135153. };
  135154. static float _vq_quantthresh__44u6__p7_0[] = {
  135155. -5.5, 5.5,
  135156. };
  135157. static long _vq_quantmap__44u6__p7_0[] = {
  135158. 1, 0, 2,
  135159. };
  135160. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135161. _vq_quantthresh__44u6__p7_0,
  135162. _vq_quantmap__44u6__p7_0,
  135163. 3,
  135164. 3
  135165. };
  135166. static static_codebook _44u6__p7_0 = {
  135167. 4, 81,
  135168. _vq_lengthlist__44u6__p7_0,
  135169. 1, -529137664, 1618345984, 2, 0,
  135170. _vq_quantlist__44u6__p7_0,
  135171. NULL,
  135172. &_vq_auxt__44u6__p7_0,
  135173. NULL,
  135174. 0
  135175. };
  135176. static long _vq_quantlist__44u6__p7_1[] = {
  135177. 5,
  135178. 4,
  135179. 6,
  135180. 3,
  135181. 7,
  135182. 2,
  135183. 8,
  135184. 1,
  135185. 9,
  135186. 0,
  135187. 10,
  135188. };
  135189. static long _vq_lengthlist__44u6__p7_1[] = {
  135190. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135191. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135192. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135193. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135194. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135195. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135196. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135197. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135198. };
  135199. static float _vq_quantthresh__44u6__p7_1[] = {
  135200. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135201. 3.5, 4.5,
  135202. };
  135203. static long _vq_quantmap__44u6__p7_1[] = {
  135204. 9, 7, 5, 3, 1, 0, 2, 4,
  135205. 6, 8, 10,
  135206. };
  135207. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135208. _vq_quantthresh__44u6__p7_1,
  135209. _vq_quantmap__44u6__p7_1,
  135210. 11,
  135211. 11
  135212. };
  135213. static static_codebook _44u6__p7_1 = {
  135214. 2, 121,
  135215. _vq_lengthlist__44u6__p7_1,
  135216. 1, -531365888, 1611661312, 4, 0,
  135217. _vq_quantlist__44u6__p7_1,
  135218. NULL,
  135219. &_vq_auxt__44u6__p7_1,
  135220. NULL,
  135221. 0
  135222. };
  135223. static long _vq_quantlist__44u6__p8_0[] = {
  135224. 5,
  135225. 4,
  135226. 6,
  135227. 3,
  135228. 7,
  135229. 2,
  135230. 8,
  135231. 1,
  135232. 9,
  135233. 0,
  135234. 10,
  135235. };
  135236. static long _vq_lengthlist__44u6__p8_0[] = {
  135237. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135238. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135239. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135240. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135241. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135242. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135243. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135244. 12,13,13,14,14,14,15,15,15,
  135245. };
  135246. static float _vq_quantthresh__44u6__p8_0[] = {
  135247. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135248. 38.5, 49.5,
  135249. };
  135250. static long _vq_quantmap__44u6__p8_0[] = {
  135251. 9, 7, 5, 3, 1, 0, 2, 4,
  135252. 6, 8, 10,
  135253. };
  135254. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135255. _vq_quantthresh__44u6__p8_0,
  135256. _vq_quantmap__44u6__p8_0,
  135257. 11,
  135258. 11
  135259. };
  135260. static static_codebook _44u6__p8_0 = {
  135261. 2, 121,
  135262. _vq_lengthlist__44u6__p8_0,
  135263. 1, -524582912, 1618345984, 4, 0,
  135264. _vq_quantlist__44u6__p8_0,
  135265. NULL,
  135266. &_vq_auxt__44u6__p8_0,
  135267. NULL,
  135268. 0
  135269. };
  135270. static long _vq_quantlist__44u6__p8_1[] = {
  135271. 5,
  135272. 4,
  135273. 6,
  135274. 3,
  135275. 7,
  135276. 2,
  135277. 8,
  135278. 1,
  135279. 9,
  135280. 0,
  135281. 10,
  135282. };
  135283. static long _vq_lengthlist__44u6__p8_1[] = {
  135284. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135285. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135286. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135287. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135288. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135289. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135290. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135291. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135292. };
  135293. static float _vq_quantthresh__44u6__p8_1[] = {
  135294. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135295. 3.5, 4.5,
  135296. };
  135297. static long _vq_quantmap__44u6__p8_1[] = {
  135298. 9, 7, 5, 3, 1, 0, 2, 4,
  135299. 6, 8, 10,
  135300. };
  135301. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135302. _vq_quantthresh__44u6__p8_1,
  135303. _vq_quantmap__44u6__p8_1,
  135304. 11,
  135305. 11
  135306. };
  135307. static static_codebook _44u6__p8_1 = {
  135308. 2, 121,
  135309. _vq_lengthlist__44u6__p8_1,
  135310. 1, -531365888, 1611661312, 4, 0,
  135311. _vq_quantlist__44u6__p8_1,
  135312. NULL,
  135313. &_vq_auxt__44u6__p8_1,
  135314. NULL,
  135315. 0
  135316. };
  135317. static long _vq_quantlist__44u6__p9_0[] = {
  135318. 7,
  135319. 6,
  135320. 8,
  135321. 5,
  135322. 9,
  135323. 4,
  135324. 10,
  135325. 3,
  135326. 11,
  135327. 2,
  135328. 12,
  135329. 1,
  135330. 13,
  135331. 0,
  135332. 14,
  135333. };
  135334. static long _vq_lengthlist__44u6__p9_0[] = {
  135335. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135336. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135337. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135338. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135339. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135340. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135341. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135342. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135343. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135344. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135345. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135346. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135347. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135348. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135349. 14,
  135350. };
  135351. static float _vq_quantthresh__44u6__p9_0[] = {
  135352. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135353. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135354. };
  135355. static long _vq_quantmap__44u6__p9_0[] = {
  135356. 13, 11, 9, 7, 5, 3, 1, 0,
  135357. 2, 4, 6, 8, 10, 12, 14,
  135358. };
  135359. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135360. _vq_quantthresh__44u6__p9_0,
  135361. _vq_quantmap__44u6__p9_0,
  135362. 15,
  135363. 15
  135364. };
  135365. static static_codebook _44u6__p9_0 = {
  135366. 2, 225,
  135367. _vq_lengthlist__44u6__p9_0,
  135368. 1, -514071552, 1627381760, 4, 0,
  135369. _vq_quantlist__44u6__p9_0,
  135370. NULL,
  135371. &_vq_auxt__44u6__p9_0,
  135372. NULL,
  135373. 0
  135374. };
  135375. static long _vq_quantlist__44u6__p9_1[] = {
  135376. 7,
  135377. 6,
  135378. 8,
  135379. 5,
  135380. 9,
  135381. 4,
  135382. 10,
  135383. 3,
  135384. 11,
  135385. 2,
  135386. 12,
  135387. 1,
  135388. 13,
  135389. 0,
  135390. 14,
  135391. };
  135392. static long _vq_lengthlist__44u6__p9_1[] = {
  135393. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135394. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135395. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135396. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135397. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135398. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135399. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135400. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135401. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135402. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135403. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135404. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135405. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135406. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135407. 13,
  135408. };
  135409. static float _vq_quantthresh__44u6__p9_1[] = {
  135410. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135411. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135412. };
  135413. static long _vq_quantmap__44u6__p9_1[] = {
  135414. 13, 11, 9, 7, 5, 3, 1, 0,
  135415. 2, 4, 6, 8, 10, 12, 14,
  135416. };
  135417. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135418. _vq_quantthresh__44u6__p9_1,
  135419. _vq_quantmap__44u6__p9_1,
  135420. 15,
  135421. 15
  135422. };
  135423. static static_codebook _44u6__p9_1 = {
  135424. 2, 225,
  135425. _vq_lengthlist__44u6__p9_1,
  135426. 1, -522338304, 1620115456, 4, 0,
  135427. _vq_quantlist__44u6__p9_1,
  135428. NULL,
  135429. &_vq_auxt__44u6__p9_1,
  135430. NULL,
  135431. 0
  135432. };
  135433. static long _vq_quantlist__44u6__p9_2[] = {
  135434. 8,
  135435. 7,
  135436. 9,
  135437. 6,
  135438. 10,
  135439. 5,
  135440. 11,
  135441. 4,
  135442. 12,
  135443. 3,
  135444. 13,
  135445. 2,
  135446. 14,
  135447. 1,
  135448. 15,
  135449. 0,
  135450. 16,
  135451. };
  135452. static long _vq_lengthlist__44u6__p9_2[] = {
  135453. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135454. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135455. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135456. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135457. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135458. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135459. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135460. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135461. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135462. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135463. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135464. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135465. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135466. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135467. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135468. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135469. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135470. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135471. 10,
  135472. };
  135473. static float _vq_quantthresh__44u6__p9_2[] = {
  135474. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135475. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135476. };
  135477. static long _vq_quantmap__44u6__p9_2[] = {
  135478. 15, 13, 11, 9, 7, 5, 3, 1,
  135479. 0, 2, 4, 6, 8, 10, 12, 14,
  135480. 16,
  135481. };
  135482. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135483. _vq_quantthresh__44u6__p9_2,
  135484. _vq_quantmap__44u6__p9_2,
  135485. 17,
  135486. 17
  135487. };
  135488. static static_codebook _44u6__p9_2 = {
  135489. 2, 289,
  135490. _vq_lengthlist__44u6__p9_2,
  135491. 1, -529530880, 1611661312, 5, 0,
  135492. _vq_quantlist__44u6__p9_2,
  135493. NULL,
  135494. &_vq_auxt__44u6__p9_2,
  135495. NULL,
  135496. 0
  135497. };
  135498. static long _huff_lengthlist__44u6__short[] = {
  135499. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135500. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135501. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135502. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135503. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135504. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135505. 7, 6, 9,16,
  135506. };
  135507. static static_codebook _huff_book__44u6__short = {
  135508. 2, 100,
  135509. _huff_lengthlist__44u6__short,
  135510. 0, 0, 0, 0, 0,
  135511. NULL,
  135512. NULL,
  135513. NULL,
  135514. NULL,
  135515. 0
  135516. };
  135517. static long _huff_lengthlist__44u7__long[] = {
  135518. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135519. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135520. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135521. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135522. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135523. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135524. 12, 8, 6, 7,
  135525. };
  135526. static static_codebook _huff_book__44u7__long = {
  135527. 2, 100,
  135528. _huff_lengthlist__44u7__long,
  135529. 0, 0, 0, 0, 0,
  135530. NULL,
  135531. NULL,
  135532. NULL,
  135533. NULL,
  135534. 0
  135535. };
  135536. static long _vq_quantlist__44u7__p1_0[] = {
  135537. 1,
  135538. 0,
  135539. 2,
  135540. };
  135541. static long _vq_lengthlist__44u7__p1_0[] = {
  135542. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135543. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135544. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135545. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135546. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135547. 12,
  135548. };
  135549. static float _vq_quantthresh__44u7__p1_0[] = {
  135550. -0.5, 0.5,
  135551. };
  135552. static long _vq_quantmap__44u7__p1_0[] = {
  135553. 1, 0, 2,
  135554. };
  135555. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135556. _vq_quantthresh__44u7__p1_0,
  135557. _vq_quantmap__44u7__p1_0,
  135558. 3,
  135559. 3
  135560. };
  135561. static static_codebook _44u7__p1_0 = {
  135562. 4, 81,
  135563. _vq_lengthlist__44u7__p1_0,
  135564. 1, -535822336, 1611661312, 2, 0,
  135565. _vq_quantlist__44u7__p1_0,
  135566. NULL,
  135567. &_vq_auxt__44u7__p1_0,
  135568. NULL,
  135569. 0
  135570. };
  135571. static long _vq_quantlist__44u7__p2_0[] = {
  135572. 1,
  135573. 0,
  135574. 2,
  135575. };
  135576. static long _vq_lengthlist__44u7__p2_0[] = {
  135577. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135578. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135579. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135580. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135581. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135582. 9,
  135583. };
  135584. static float _vq_quantthresh__44u7__p2_0[] = {
  135585. -0.5, 0.5,
  135586. };
  135587. static long _vq_quantmap__44u7__p2_0[] = {
  135588. 1, 0, 2,
  135589. };
  135590. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135591. _vq_quantthresh__44u7__p2_0,
  135592. _vq_quantmap__44u7__p2_0,
  135593. 3,
  135594. 3
  135595. };
  135596. static static_codebook _44u7__p2_0 = {
  135597. 4, 81,
  135598. _vq_lengthlist__44u7__p2_0,
  135599. 1, -535822336, 1611661312, 2, 0,
  135600. _vq_quantlist__44u7__p2_0,
  135601. NULL,
  135602. &_vq_auxt__44u7__p2_0,
  135603. NULL,
  135604. 0
  135605. };
  135606. static long _vq_quantlist__44u7__p3_0[] = {
  135607. 2,
  135608. 1,
  135609. 3,
  135610. 0,
  135611. 4,
  135612. };
  135613. static long _vq_lengthlist__44u7__p3_0[] = {
  135614. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135615. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135616. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135617. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135618. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135619. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135620. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135621. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135622. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135623. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135624. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135625. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135626. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135627. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135628. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135629. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135630. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135631. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135632. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135633. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135634. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135635. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135636. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135637. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135638. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135639. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135640. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135641. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135642. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135643. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135644. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135645. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135646. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135647. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135648. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135649. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135650. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135651. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135652. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135653. 0,
  135654. };
  135655. static float _vq_quantthresh__44u7__p3_0[] = {
  135656. -1.5, -0.5, 0.5, 1.5,
  135657. };
  135658. static long _vq_quantmap__44u7__p3_0[] = {
  135659. 3, 1, 0, 2, 4,
  135660. };
  135661. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135662. _vq_quantthresh__44u7__p3_0,
  135663. _vq_quantmap__44u7__p3_0,
  135664. 5,
  135665. 5
  135666. };
  135667. static static_codebook _44u7__p3_0 = {
  135668. 4, 625,
  135669. _vq_lengthlist__44u7__p3_0,
  135670. 1, -533725184, 1611661312, 3, 0,
  135671. _vq_quantlist__44u7__p3_0,
  135672. NULL,
  135673. &_vq_auxt__44u7__p3_0,
  135674. NULL,
  135675. 0
  135676. };
  135677. static long _vq_quantlist__44u7__p4_0[] = {
  135678. 2,
  135679. 1,
  135680. 3,
  135681. 0,
  135682. 4,
  135683. };
  135684. static long _vq_lengthlist__44u7__p4_0[] = {
  135685. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135686. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135687. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135688. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135689. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135690. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135691. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135692. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135693. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135694. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135695. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135696. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135697. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135698. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135699. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135700. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135701. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135702. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135703. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135704. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135705. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135706. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135707. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135708. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135709. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135710. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135711. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135712. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135713. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135714. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135715. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135716. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135717. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135718. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135719. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135720. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135721. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135722. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135723. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135724. 14,
  135725. };
  135726. static float _vq_quantthresh__44u7__p4_0[] = {
  135727. -1.5, -0.5, 0.5, 1.5,
  135728. };
  135729. static long _vq_quantmap__44u7__p4_0[] = {
  135730. 3, 1, 0, 2, 4,
  135731. };
  135732. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135733. _vq_quantthresh__44u7__p4_0,
  135734. _vq_quantmap__44u7__p4_0,
  135735. 5,
  135736. 5
  135737. };
  135738. static static_codebook _44u7__p4_0 = {
  135739. 4, 625,
  135740. _vq_lengthlist__44u7__p4_0,
  135741. 1, -533725184, 1611661312, 3, 0,
  135742. _vq_quantlist__44u7__p4_0,
  135743. NULL,
  135744. &_vq_auxt__44u7__p4_0,
  135745. NULL,
  135746. 0
  135747. };
  135748. static long _vq_quantlist__44u7__p5_0[] = {
  135749. 4,
  135750. 3,
  135751. 5,
  135752. 2,
  135753. 6,
  135754. 1,
  135755. 7,
  135756. 0,
  135757. 8,
  135758. };
  135759. static long _vq_lengthlist__44u7__p5_0[] = {
  135760. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135761. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135762. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135763. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135764. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135765. 14,
  135766. };
  135767. static float _vq_quantthresh__44u7__p5_0[] = {
  135768. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135769. };
  135770. static long _vq_quantmap__44u7__p5_0[] = {
  135771. 7, 5, 3, 1, 0, 2, 4, 6,
  135772. 8,
  135773. };
  135774. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135775. _vq_quantthresh__44u7__p5_0,
  135776. _vq_quantmap__44u7__p5_0,
  135777. 9,
  135778. 9
  135779. };
  135780. static static_codebook _44u7__p5_0 = {
  135781. 2, 81,
  135782. _vq_lengthlist__44u7__p5_0,
  135783. 1, -531628032, 1611661312, 4, 0,
  135784. _vq_quantlist__44u7__p5_0,
  135785. NULL,
  135786. &_vq_auxt__44u7__p5_0,
  135787. NULL,
  135788. 0
  135789. };
  135790. static long _vq_quantlist__44u7__p6_0[] = {
  135791. 4,
  135792. 3,
  135793. 5,
  135794. 2,
  135795. 6,
  135796. 1,
  135797. 7,
  135798. 0,
  135799. 8,
  135800. };
  135801. static long _vq_lengthlist__44u7__p6_0[] = {
  135802. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135803. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135804. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135805. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135806. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135807. 12,
  135808. };
  135809. static float _vq_quantthresh__44u7__p6_0[] = {
  135810. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135811. };
  135812. static long _vq_quantmap__44u7__p6_0[] = {
  135813. 7, 5, 3, 1, 0, 2, 4, 6,
  135814. 8,
  135815. };
  135816. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135817. _vq_quantthresh__44u7__p6_0,
  135818. _vq_quantmap__44u7__p6_0,
  135819. 9,
  135820. 9
  135821. };
  135822. static static_codebook _44u7__p6_0 = {
  135823. 2, 81,
  135824. _vq_lengthlist__44u7__p6_0,
  135825. 1, -531628032, 1611661312, 4, 0,
  135826. _vq_quantlist__44u7__p6_0,
  135827. NULL,
  135828. &_vq_auxt__44u7__p6_0,
  135829. NULL,
  135830. 0
  135831. };
  135832. static long _vq_quantlist__44u7__p7_0[] = {
  135833. 1,
  135834. 0,
  135835. 2,
  135836. };
  135837. static long _vq_lengthlist__44u7__p7_0[] = {
  135838. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135839. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135840. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135841. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135842. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135843. 10,
  135844. };
  135845. static float _vq_quantthresh__44u7__p7_0[] = {
  135846. -5.5, 5.5,
  135847. };
  135848. static long _vq_quantmap__44u7__p7_0[] = {
  135849. 1, 0, 2,
  135850. };
  135851. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135852. _vq_quantthresh__44u7__p7_0,
  135853. _vq_quantmap__44u7__p7_0,
  135854. 3,
  135855. 3
  135856. };
  135857. static static_codebook _44u7__p7_0 = {
  135858. 4, 81,
  135859. _vq_lengthlist__44u7__p7_0,
  135860. 1, -529137664, 1618345984, 2, 0,
  135861. _vq_quantlist__44u7__p7_0,
  135862. NULL,
  135863. &_vq_auxt__44u7__p7_0,
  135864. NULL,
  135865. 0
  135866. };
  135867. static long _vq_quantlist__44u7__p7_1[] = {
  135868. 5,
  135869. 4,
  135870. 6,
  135871. 3,
  135872. 7,
  135873. 2,
  135874. 8,
  135875. 1,
  135876. 9,
  135877. 0,
  135878. 10,
  135879. };
  135880. static long _vq_lengthlist__44u7__p7_1[] = {
  135881. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135882. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135883. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135884. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135885. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135886. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135887. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135888. 8, 9, 9, 9, 9, 9,10,10,10,
  135889. };
  135890. static float _vq_quantthresh__44u7__p7_1[] = {
  135891. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135892. 3.5, 4.5,
  135893. };
  135894. static long _vq_quantmap__44u7__p7_1[] = {
  135895. 9, 7, 5, 3, 1, 0, 2, 4,
  135896. 6, 8, 10,
  135897. };
  135898. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135899. _vq_quantthresh__44u7__p7_1,
  135900. _vq_quantmap__44u7__p7_1,
  135901. 11,
  135902. 11
  135903. };
  135904. static static_codebook _44u7__p7_1 = {
  135905. 2, 121,
  135906. _vq_lengthlist__44u7__p7_1,
  135907. 1, -531365888, 1611661312, 4, 0,
  135908. _vq_quantlist__44u7__p7_1,
  135909. NULL,
  135910. &_vq_auxt__44u7__p7_1,
  135911. NULL,
  135912. 0
  135913. };
  135914. static long _vq_quantlist__44u7__p8_0[] = {
  135915. 5,
  135916. 4,
  135917. 6,
  135918. 3,
  135919. 7,
  135920. 2,
  135921. 8,
  135922. 1,
  135923. 9,
  135924. 0,
  135925. 10,
  135926. };
  135927. static long _vq_lengthlist__44u7__p8_0[] = {
  135928. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  135929. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  135930. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  135931. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  135932. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  135933. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  135934. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  135935. 12,13,13,14,14,15,15,15,16,
  135936. };
  135937. static float _vq_quantthresh__44u7__p8_0[] = {
  135938. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135939. 38.5, 49.5,
  135940. };
  135941. static long _vq_quantmap__44u7__p8_0[] = {
  135942. 9, 7, 5, 3, 1, 0, 2, 4,
  135943. 6, 8, 10,
  135944. };
  135945. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  135946. _vq_quantthresh__44u7__p8_0,
  135947. _vq_quantmap__44u7__p8_0,
  135948. 11,
  135949. 11
  135950. };
  135951. static static_codebook _44u7__p8_0 = {
  135952. 2, 121,
  135953. _vq_lengthlist__44u7__p8_0,
  135954. 1, -524582912, 1618345984, 4, 0,
  135955. _vq_quantlist__44u7__p8_0,
  135956. NULL,
  135957. &_vq_auxt__44u7__p8_0,
  135958. NULL,
  135959. 0
  135960. };
  135961. static long _vq_quantlist__44u7__p8_1[] = {
  135962. 5,
  135963. 4,
  135964. 6,
  135965. 3,
  135966. 7,
  135967. 2,
  135968. 8,
  135969. 1,
  135970. 9,
  135971. 0,
  135972. 10,
  135973. };
  135974. static long _vq_lengthlist__44u7__p8_1[] = {
  135975. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  135976. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  135977. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  135978. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  135979. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  135980. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  135981. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  135982. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  135983. };
  135984. static float _vq_quantthresh__44u7__p8_1[] = {
  135985. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135986. 3.5, 4.5,
  135987. };
  135988. static long _vq_quantmap__44u7__p8_1[] = {
  135989. 9, 7, 5, 3, 1, 0, 2, 4,
  135990. 6, 8, 10,
  135991. };
  135992. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  135993. _vq_quantthresh__44u7__p8_1,
  135994. _vq_quantmap__44u7__p8_1,
  135995. 11,
  135996. 11
  135997. };
  135998. static static_codebook _44u7__p8_1 = {
  135999. 2, 121,
  136000. _vq_lengthlist__44u7__p8_1,
  136001. 1, -531365888, 1611661312, 4, 0,
  136002. _vq_quantlist__44u7__p8_1,
  136003. NULL,
  136004. &_vq_auxt__44u7__p8_1,
  136005. NULL,
  136006. 0
  136007. };
  136008. static long _vq_quantlist__44u7__p9_0[] = {
  136009. 5,
  136010. 4,
  136011. 6,
  136012. 3,
  136013. 7,
  136014. 2,
  136015. 8,
  136016. 1,
  136017. 9,
  136018. 0,
  136019. 10,
  136020. };
  136021. static long _vq_lengthlist__44u7__p9_0[] = {
  136022. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136023. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136024. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136025. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136026. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136027. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136028. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136029. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136030. };
  136031. static float _vq_quantthresh__44u7__p9_0[] = {
  136032. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136033. 2229.5, 2866.5,
  136034. };
  136035. static long _vq_quantmap__44u7__p9_0[] = {
  136036. 9, 7, 5, 3, 1, 0, 2, 4,
  136037. 6, 8, 10,
  136038. };
  136039. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136040. _vq_quantthresh__44u7__p9_0,
  136041. _vq_quantmap__44u7__p9_0,
  136042. 11,
  136043. 11
  136044. };
  136045. static static_codebook _44u7__p9_0 = {
  136046. 2, 121,
  136047. _vq_lengthlist__44u7__p9_0,
  136048. 1, -512171520, 1630791680, 4, 0,
  136049. _vq_quantlist__44u7__p9_0,
  136050. NULL,
  136051. &_vq_auxt__44u7__p9_0,
  136052. NULL,
  136053. 0
  136054. };
  136055. static long _vq_quantlist__44u7__p9_1[] = {
  136056. 6,
  136057. 5,
  136058. 7,
  136059. 4,
  136060. 8,
  136061. 3,
  136062. 9,
  136063. 2,
  136064. 10,
  136065. 1,
  136066. 11,
  136067. 0,
  136068. 12,
  136069. };
  136070. static long _vq_lengthlist__44u7__p9_1[] = {
  136071. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136072. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136073. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136074. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136075. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136076. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136077. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136078. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136079. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136080. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136081. 15,15,15,15,17,17,16,17,16,
  136082. };
  136083. static float _vq_quantthresh__44u7__p9_1[] = {
  136084. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136085. 122.5, 171.5, 220.5, 269.5,
  136086. };
  136087. static long _vq_quantmap__44u7__p9_1[] = {
  136088. 11, 9, 7, 5, 3, 1, 0, 2,
  136089. 4, 6, 8, 10, 12,
  136090. };
  136091. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136092. _vq_quantthresh__44u7__p9_1,
  136093. _vq_quantmap__44u7__p9_1,
  136094. 13,
  136095. 13
  136096. };
  136097. static static_codebook _44u7__p9_1 = {
  136098. 2, 169,
  136099. _vq_lengthlist__44u7__p9_1,
  136100. 1, -518889472, 1622704128, 4, 0,
  136101. _vq_quantlist__44u7__p9_1,
  136102. NULL,
  136103. &_vq_auxt__44u7__p9_1,
  136104. NULL,
  136105. 0
  136106. };
  136107. static long _vq_quantlist__44u7__p9_2[] = {
  136108. 24,
  136109. 23,
  136110. 25,
  136111. 22,
  136112. 26,
  136113. 21,
  136114. 27,
  136115. 20,
  136116. 28,
  136117. 19,
  136118. 29,
  136119. 18,
  136120. 30,
  136121. 17,
  136122. 31,
  136123. 16,
  136124. 32,
  136125. 15,
  136126. 33,
  136127. 14,
  136128. 34,
  136129. 13,
  136130. 35,
  136131. 12,
  136132. 36,
  136133. 11,
  136134. 37,
  136135. 10,
  136136. 38,
  136137. 9,
  136138. 39,
  136139. 8,
  136140. 40,
  136141. 7,
  136142. 41,
  136143. 6,
  136144. 42,
  136145. 5,
  136146. 43,
  136147. 4,
  136148. 44,
  136149. 3,
  136150. 45,
  136151. 2,
  136152. 46,
  136153. 1,
  136154. 47,
  136155. 0,
  136156. 48,
  136157. };
  136158. static long _vq_lengthlist__44u7__p9_2[] = {
  136159. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136160. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136161. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136162. 8,
  136163. };
  136164. static float _vq_quantthresh__44u7__p9_2[] = {
  136165. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136166. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136167. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136168. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136169. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136170. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136171. };
  136172. static long _vq_quantmap__44u7__p9_2[] = {
  136173. 47, 45, 43, 41, 39, 37, 35, 33,
  136174. 31, 29, 27, 25, 23, 21, 19, 17,
  136175. 15, 13, 11, 9, 7, 5, 3, 1,
  136176. 0, 2, 4, 6, 8, 10, 12, 14,
  136177. 16, 18, 20, 22, 24, 26, 28, 30,
  136178. 32, 34, 36, 38, 40, 42, 44, 46,
  136179. 48,
  136180. };
  136181. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136182. _vq_quantthresh__44u7__p9_2,
  136183. _vq_quantmap__44u7__p9_2,
  136184. 49,
  136185. 49
  136186. };
  136187. static static_codebook _44u7__p9_2 = {
  136188. 1, 49,
  136189. _vq_lengthlist__44u7__p9_2,
  136190. 1, -526909440, 1611661312, 6, 0,
  136191. _vq_quantlist__44u7__p9_2,
  136192. NULL,
  136193. &_vq_auxt__44u7__p9_2,
  136194. NULL,
  136195. 0
  136196. };
  136197. static long _huff_lengthlist__44u7__short[] = {
  136198. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136199. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136200. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136201. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136202. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136203. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136204. 6, 8, 5, 9,
  136205. };
  136206. static static_codebook _huff_book__44u7__short = {
  136207. 2, 100,
  136208. _huff_lengthlist__44u7__short,
  136209. 0, 0, 0, 0, 0,
  136210. NULL,
  136211. NULL,
  136212. NULL,
  136213. NULL,
  136214. 0
  136215. };
  136216. static long _huff_lengthlist__44u8__long[] = {
  136217. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136218. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136219. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136220. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136221. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136222. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136223. 10, 8, 8, 9,
  136224. };
  136225. static static_codebook _huff_book__44u8__long = {
  136226. 2, 100,
  136227. _huff_lengthlist__44u8__long,
  136228. 0, 0, 0, 0, 0,
  136229. NULL,
  136230. NULL,
  136231. NULL,
  136232. NULL,
  136233. 0
  136234. };
  136235. static long _huff_lengthlist__44u8__short[] = {
  136236. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136237. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136238. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136239. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136240. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136241. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136242. 10,10,15,17,
  136243. };
  136244. static static_codebook _huff_book__44u8__short = {
  136245. 2, 100,
  136246. _huff_lengthlist__44u8__short,
  136247. 0, 0, 0, 0, 0,
  136248. NULL,
  136249. NULL,
  136250. NULL,
  136251. NULL,
  136252. 0
  136253. };
  136254. static long _vq_quantlist__44u8_p1_0[] = {
  136255. 1,
  136256. 0,
  136257. 2,
  136258. };
  136259. static long _vq_lengthlist__44u8_p1_0[] = {
  136260. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136261. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136262. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136263. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136264. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136265. 10,
  136266. };
  136267. static float _vq_quantthresh__44u8_p1_0[] = {
  136268. -0.5, 0.5,
  136269. };
  136270. static long _vq_quantmap__44u8_p1_0[] = {
  136271. 1, 0, 2,
  136272. };
  136273. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136274. _vq_quantthresh__44u8_p1_0,
  136275. _vq_quantmap__44u8_p1_0,
  136276. 3,
  136277. 3
  136278. };
  136279. static static_codebook _44u8_p1_0 = {
  136280. 4, 81,
  136281. _vq_lengthlist__44u8_p1_0,
  136282. 1, -535822336, 1611661312, 2, 0,
  136283. _vq_quantlist__44u8_p1_0,
  136284. NULL,
  136285. &_vq_auxt__44u8_p1_0,
  136286. NULL,
  136287. 0
  136288. };
  136289. static long _vq_quantlist__44u8_p2_0[] = {
  136290. 2,
  136291. 1,
  136292. 3,
  136293. 0,
  136294. 4,
  136295. };
  136296. static long _vq_lengthlist__44u8_p2_0[] = {
  136297. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136298. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136299. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136300. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136301. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136302. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136303. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136304. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136305. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136306. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136307. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136308. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136309. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136310. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136311. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136312. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136313. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136314. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136315. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136316. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136317. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136318. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136319. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136320. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136321. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136322. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136323. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136324. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136325. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136326. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136327. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136328. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136329. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136330. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136331. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136332. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136333. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136334. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136335. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136336. 14,
  136337. };
  136338. static float _vq_quantthresh__44u8_p2_0[] = {
  136339. -1.5, -0.5, 0.5, 1.5,
  136340. };
  136341. static long _vq_quantmap__44u8_p2_0[] = {
  136342. 3, 1, 0, 2, 4,
  136343. };
  136344. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136345. _vq_quantthresh__44u8_p2_0,
  136346. _vq_quantmap__44u8_p2_0,
  136347. 5,
  136348. 5
  136349. };
  136350. static static_codebook _44u8_p2_0 = {
  136351. 4, 625,
  136352. _vq_lengthlist__44u8_p2_0,
  136353. 1, -533725184, 1611661312, 3, 0,
  136354. _vq_quantlist__44u8_p2_0,
  136355. NULL,
  136356. &_vq_auxt__44u8_p2_0,
  136357. NULL,
  136358. 0
  136359. };
  136360. static long _vq_quantlist__44u8_p3_0[] = {
  136361. 4,
  136362. 3,
  136363. 5,
  136364. 2,
  136365. 6,
  136366. 1,
  136367. 7,
  136368. 0,
  136369. 8,
  136370. };
  136371. static long _vq_lengthlist__44u8_p3_0[] = {
  136372. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136373. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136374. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136375. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136376. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136377. 12,
  136378. };
  136379. static float _vq_quantthresh__44u8_p3_0[] = {
  136380. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136381. };
  136382. static long _vq_quantmap__44u8_p3_0[] = {
  136383. 7, 5, 3, 1, 0, 2, 4, 6,
  136384. 8,
  136385. };
  136386. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136387. _vq_quantthresh__44u8_p3_0,
  136388. _vq_quantmap__44u8_p3_0,
  136389. 9,
  136390. 9
  136391. };
  136392. static static_codebook _44u8_p3_0 = {
  136393. 2, 81,
  136394. _vq_lengthlist__44u8_p3_0,
  136395. 1, -531628032, 1611661312, 4, 0,
  136396. _vq_quantlist__44u8_p3_0,
  136397. NULL,
  136398. &_vq_auxt__44u8_p3_0,
  136399. NULL,
  136400. 0
  136401. };
  136402. static long _vq_quantlist__44u8_p4_0[] = {
  136403. 8,
  136404. 7,
  136405. 9,
  136406. 6,
  136407. 10,
  136408. 5,
  136409. 11,
  136410. 4,
  136411. 12,
  136412. 3,
  136413. 13,
  136414. 2,
  136415. 14,
  136416. 1,
  136417. 15,
  136418. 0,
  136419. 16,
  136420. };
  136421. static long _vq_lengthlist__44u8_p4_0[] = {
  136422. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136423. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136424. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136425. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136426. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136427. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136428. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136429. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136430. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136431. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136432. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136433. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136434. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136435. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136436. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136437. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136438. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136439. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136440. 14,
  136441. };
  136442. static float _vq_quantthresh__44u8_p4_0[] = {
  136443. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136444. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136445. };
  136446. static long _vq_quantmap__44u8_p4_0[] = {
  136447. 15, 13, 11, 9, 7, 5, 3, 1,
  136448. 0, 2, 4, 6, 8, 10, 12, 14,
  136449. 16,
  136450. };
  136451. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136452. _vq_quantthresh__44u8_p4_0,
  136453. _vq_quantmap__44u8_p4_0,
  136454. 17,
  136455. 17
  136456. };
  136457. static static_codebook _44u8_p4_0 = {
  136458. 2, 289,
  136459. _vq_lengthlist__44u8_p4_0,
  136460. 1, -529530880, 1611661312, 5, 0,
  136461. _vq_quantlist__44u8_p4_0,
  136462. NULL,
  136463. &_vq_auxt__44u8_p4_0,
  136464. NULL,
  136465. 0
  136466. };
  136467. static long _vq_quantlist__44u8_p5_0[] = {
  136468. 1,
  136469. 0,
  136470. 2,
  136471. };
  136472. static long _vq_lengthlist__44u8_p5_0[] = {
  136473. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136474. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136475. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136476. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136477. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136478. 10,
  136479. };
  136480. static float _vq_quantthresh__44u8_p5_0[] = {
  136481. -5.5, 5.5,
  136482. };
  136483. static long _vq_quantmap__44u8_p5_0[] = {
  136484. 1, 0, 2,
  136485. };
  136486. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136487. _vq_quantthresh__44u8_p5_0,
  136488. _vq_quantmap__44u8_p5_0,
  136489. 3,
  136490. 3
  136491. };
  136492. static static_codebook _44u8_p5_0 = {
  136493. 4, 81,
  136494. _vq_lengthlist__44u8_p5_0,
  136495. 1, -529137664, 1618345984, 2, 0,
  136496. _vq_quantlist__44u8_p5_0,
  136497. NULL,
  136498. &_vq_auxt__44u8_p5_0,
  136499. NULL,
  136500. 0
  136501. };
  136502. static long _vq_quantlist__44u8_p5_1[] = {
  136503. 5,
  136504. 4,
  136505. 6,
  136506. 3,
  136507. 7,
  136508. 2,
  136509. 8,
  136510. 1,
  136511. 9,
  136512. 0,
  136513. 10,
  136514. };
  136515. static long _vq_lengthlist__44u8_p5_1[] = {
  136516. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136517. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136518. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136519. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136520. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136521. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136522. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136523. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136524. };
  136525. static float _vq_quantthresh__44u8_p5_1[] = {
  136526. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136527. 3.5, 4.5,
  136528. };
  136529. static long _vq_quantmap__44u8_p5_1[] = {
  136530. 9, 7, 5, 3, 1, 0, 2, 4,
  136531. 6, 8, 10,
  136532. };
  136533. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136534. _vq_quantthresh__44u8_p5_1,
  136535. _vq_quantmap__44u8_p5_1,
  136536. 11,
  136537. 11
  136538. };
  136539. static static_codebook _44u8_p5_1 = {
  136540. 2, 121,
  136541. _vq_lengthlist__44u8_p5_1,
  136542. 1, -531365888, 1611661312, 4, 0,
  136543. _vq_quantlist__44u8_p5_1,
  136544. NULL,
  136545. &_vq_auxt__44u8_p5_1,
  136546. NULL,
  136547. 0
  136548. };
  136549. static long _vq_quantlist__44u8_p6_0[] = {
  136550. 6,
  136551. 5,
  136552. 7,
  136553. 4,
  136554. 8,
  136555. 3,
  136556. 9,
  136557. 2,
  136558. 10,
  136559. 1,
  136560. 11,
  136561. 0,
  136562. 12,
  136563. };
  136564. static long _vq_lengthlist__44u8_p6_0[] = {
  136565. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136566. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136567. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136568. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136569. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136570. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136571. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136572. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136573. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136574. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136575. 11,11,11,11,11,12,11,12,12,
  136576. };
  136577. static float _vq_quantthresh__44u8_p6_0[] = {
  136578. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136579. 12.5, 17.5, 22.5, 27.5,
  136580. };
  136581. static long _vq_quantmap__44u8_p6_0[] = {
  136582. 11, 9, 7, 5, 3, 1, 0, 2,
  136583. 4, 6, 8, 10, 12,
  136584. };
  136585. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136586. _vq_quantthresh__44u8_p6_0,
  136587. _vq_quantmap__44u8_p6_0,
  136588. 13,
  136589. 13
  136590. };
  136591. static static_codebook _44u8_p6_0 = {
  136592. 2, 169,
  136593. _vq_lengthlist__44u8_p6_0,
  136594. 1, -526516224, 1616117760, 4, 0,
  136595. _vq_quantlist__44u8_p6_0,
  136596. NULL,
  136597. &_vq_auxt__44u8_p6_0,
  136598. NULL,
  136599. 0
  136600. };
  136601. static long _vq_quantlist__44u8_p6_1[] = {
  136602. 2,
  136603. 1,
  136604. 3,
  136605. 0,
  136606. 4,
  136607. };
  136608. static long _vq_lengthlist__44u8_p6_1[] = {
  136609. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136610. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136611. };
  136612. static float _vq_quantthresh__44u8_p6_1[] = {
  136613. -1.5, -0.5, 0.5, 1.5,
  136614. };
  136615. static long _vq_quantmap__44u8_p6_1[] = {
  136616. 3, 1, 0, 2, 4,
  136617. };
  136618. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136619. _vq_quantthresh__44u8_p6_1,
  136620. _vq_quantmap__44u8_p6_1,
  136621. 5,
  136622. 5
  136623. };
  136624. static static_codebook _44u8_p6_1 = {
  136625. 2, 25,
  136626. _vq_lengthlist__44u8_p6_1,
  136627. 1, -533725184, 1611661312, 3, 0,
  136628. _vq_quantlist__44u8_p6_1,
  136629. NULL,
  136630. &_vq_auxt__44u8_p6_1,
  136631. NULL,
  136632. 0
  136633. };
  136634. static long _vq_quantlist__44u8_p7_0[] = {
  136635. 6,
  136636. 5,
  136637. 7,
  136638. 4,
  136639. 8,
  136640. 3,
  136641. 9,
  136642. 2,
  136643. 10,
  136644. 1,
  136645. 11,
  136646. 0,
  136647. 12,
  136648. };
  136649. static long _vq_lengthlist__44u8_p7_0[] = {
  136650. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136651. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136652. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136653. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136654. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136655. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136656. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136657. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136658. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136659. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136660. 13,13,14,14,14,15,15,15,16,
  136661. };
  136662. static float _vq_quantthresh__44u8_p7_0[] = {
  136663. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136664. 27.5, 38.5, 49.5, 60.5,
  136665. };
  136666. static long _vq_quantmap__44u8_p7_0[] = {
  136667. 11, 9, 7, 5, 3, 1, 0, 2,
  136668. 4, 6, 8, 10, 12,
  136669. };
  136670. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136671. _vq_quantthresh__44u8_p7_0,
  136672. _vq_quantmap__44u8_p7_0,
  136673. 13,
  136674. 13
  136675. };
  136676. static static_codebook _44u8_p7_0 = {
  136677. 2, 169,
  136678. _vq_lengthlist__44u8_p7_0,
  136679. 1, -523206656, 1618345984, 4, 0,
  136680. _vq_quantlist__44u8_p7_0,
  136681. NULL,
  136682. &_vq_auxt__44u8_p7_0,
  136683. NULL,
  136684. 0
  136685. };
  136686. static long _vq_quantlist__44u8_p7_1[] = {
  136687. 5,
  136688. 4,
  136689. 6,
  136690. 3,
  136691. 7,
  136692. 2,
  136693. 8,
  136694. 1,
  136695. 9,
  136696. 0,
  136697. 10,
  136698. };
  136699. static long _vq_lengthlist__44u8_p7_1[] = {
  136700. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136701. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136702. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136703. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136704. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136705. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136706. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136707. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136708. };
  136709. static float _vq_quantthresh__44u8_p7_1[] = {
  136710. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136711. 3.5, 4.5,
  136712. };
  136713. static long _vq_quantmap__44u8_p7_1[] = {
  136714. 9, 7, 5, 3, 1, 0, 2, 4,
  136715. 6, 8, 10,
  136716. };
  136717. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136718. _vq_quantthresh__44u8_p7_1,
  136719. _vq_quantmap__44u8_p7_1,
  136720. 11,
  136721. 11
  136722. };
  136723. static static_codebook _44u8_p7_1 = {
  136724. 2, 121,
  136725. _vq_lengthlist__44u8_p7_1,
  136726. 1, -531365888, 1611661312, 4, 0,
  136727. _vq_quantlist__44u8_p7_1,
  136728. NULL,
  136729. &_vq_auxt__44u8_p7_1,
  136730. NULL,
  136731. 0
  136732. };
  136733. static long _vq_quantlist__44u8_p8_0[] = {
  136734. 7,
  136735. 6,
  136736. 8,
  136737. 5,
  136738. 9,
  136739. 4,
  136740. 10,
  136741. 3,
  136742. 11,
  136743. 2,
  136744. 12,
  136745. 1,
  136746. 13,
  136747. 0,
  136748. 14,
  136749. };
  136750. static long _vq_lengthlist__44u8_p8_0[] = {
  136751. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136752. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136753. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136754. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136755. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136756. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136757. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136758. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136759. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136760. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136761. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136762. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136763. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136764. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136765. 17,
  136766. };
  136767. static float _vq_quantthresh__44u8_p8_0[] = {
  136768. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136769. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136770. };
  136771. static long _vq_quantmap__44u8_p8_0[] = {
  136772. 13, 11, 9, 7, 5, 3, 1, 0,
  136773. 2, 4, 6, 8, 10, 12, 14,
  136774. };
  136775. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136776. _vq_quantthresh__44u8_p8_0,
  136777. _vq_quantmap__44u8_p8_0,
  136778. 15,
  136779. 15
  136780. };
  136781. static static_codebook _44u8_p8_0 = {
  136782. 2, 225,
  136783. _vq_lengthlist__44u8_p8_0,
  136784. 1, -520986624, 1620377600, 4, 0,
  136785. _vq_quantlist__44u8_p8_0,
  136786. NULL,
  136787. &_vq_auxt__44u8_p8_0,
  136788. NULL,
  136789. 0
  136790. };
  136791. static long _vq_quantlist__44u8_p8_1[] = {
  136792. 10,
  136793. 9,
  136794. 11,
  136795. 8,
  136796. 12,
  136797. 7,
  136798. 13,
  136799. 6,
  136800. 14,
  136801. 5,
  136802. 15,
  136803. 4,
  136804. 16,
  136805. 3,
  136806. 17,
  136807. 2,
  136808. 18,
  136809. 1,
  136810. 19,
  136811. 0,
  136812. 20,
  136813. };
  136814. static long _vq_lengthlist__44u8_p8_1[] = {
  136815. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136816. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136817. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136818. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136819. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136820. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136821. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136822. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136823. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136824. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136825. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136826. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136827. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136828. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136829. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136830. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136831. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136832. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136833. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136834. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136835. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136836. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136837. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136838. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136839. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136840. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136841. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136842. 10,10,10,10,10,10,10,10,10,
  136843. };
  136844. static float _vq_quantthresh__44u8_p8_1[] = {
  136845. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136846. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136847. 6.5, 7.5, 8.5, 9.5,
  136848. };
  136849. static long _vq_quantmap__44u8_p8_1[] = {
  136850. 19, 17, 15, 13, 11, 9, 7, 5,
  136851. 3, 1, 0, 2, 4, 6, 8, 10,
  136852. 12, 14, 16, 18, 20,
  136853. };
  136854. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136855. _vq_quantthresh__44u8_p8_1,
  136856. _vq_quantmap__44u8_p8_1,
  136857. 21,
  136858. 21
  136859. };
  136860. static static_codebook _44u8_p8_1 = {
  136861. 2, 441,
  136862. _vq_lengthlist__44u8_p8_1,
  136863. 1, -529268736, 1611661312, 5, 0,
  136864. _vq_quantlist__44u8_p8_1,
  136865. NULL,
  136866. &_vq_auxt__44u8_p8_1,
  136867. NULL,
  136868. 0
  136869. };
  136870. static long _vq_quantlist__44u8_p9_0[] = {
  136871. 4,
  136872. 3,
  136873. 5,
  136874. 2,
  136875. 6,
  136876. 1,
  136877. 7,
  136878. 0,
  136879. 8,
  136880. };
  136881. static long _vq_lengthlist__44u8_p9_0[] = {
  136882. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136883. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136884. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136885. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136886. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136887. 8,
  136888. };
  136889. static float _vq_quantthresh__44u8_p9_0[] = {
  136890. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136891. };
  136892. static long _vq_quantmap__44u8_p9_0[] = {
  136893. 7, 5, 3, 1, 0, 2, 4, 6,
  136894. 8,
  136895. };
  136896. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136897. _vq_quantthresh__44u8_p9_0,
  136898. _vq_quantmap__44u8_p9_0,
  136899. 9,
  136900. 9
  136901. };
  136902. static static_codebook _44u8_p9_0 = {
  136903. 2, 81,
  136904. _vq_lengthlist__44u8_p9_0,
  136905. 1, -511895552, 1631393792, 4, 0,
  136906. _vq_quantlist__44u8_p9_0,
  136907. NULL,
  136908. &_vq_auxt__44u8_p9_0,
  136909. NULL,
  136910. 0
  136911. };
  136912. static long _vq_quantlist__44u8_p9_1[] = {
  136913. 9,
  136914. 8,
  136915. 10,
  136916. 7,
  136917. 11,
  136918. 6,
  136919. 12,
  136920. 5,
  136921. 13,
  136922. 4,
  136923. 14,
  136924. 3,
  136925. 15,
  136926. 2,
  136927. 16,
  136928. 1,
  136929. 17,
  136930. 0,
  136931. 18,
  136932. };
  136933. static long _vq_lengthlist__44u8_p9_1[] = {
  136934. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  136935. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  136936. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  136937. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  136938. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  136939. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  136940. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  136941. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  136942. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  136943. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  136944. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  136945. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  136946. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  136947. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  136948. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  136949. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  136950. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  136951. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  136952. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  136953. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  136954. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  136955. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  136956. 16,15,16,16,16,16,16,16,16,
  136957. };
  136958. static float _vq_quantthresh__44u8_p9_1[] = {
  136959. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  136960. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  136961. 367.5, 416.5,
  136962. };
  136963. static long _vq_quantmap__44u8_p9_1[] = {
  136964. 17, 15, 13, 11, 9, 7, 5, 3,
  136965. 1, 0, 2, 4, 6, 8, 10, 12,
  136966. 14, 16, 18,
  136967. };
  136968. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  136969. _vq_quantthresh__44u8_p9_1,
  136970. _vq_quantmap__44u8_p9_1,
  136971. 19,
  136972. 19
  136973. };
  136974. static static_codebook _44u8_p9_1 = {
  136975. 2, 361,
  136976. _vq_lengthlist__44u8_p9_1,
  136977. 1, -518287360, 1622704128, 5, 0,
  136978. _vq_quantlist__44u8_p9_1,
  136979. NULL,
  136980. &_vq_auxt__44u8_p9_1,
  136981. NULL,
  136982. 0
  136983. };
  136984. static long _vq_quantlist__44u8_p9_2[] = {
  136985. 24,
  136986. 23,
  136987. 25,
  136988. 22,
  136989. 26,
  136990. 21,
  136991. 27,
  136992. 20,
  136993. 28,
  136994. 19,
  136995. 29,
  136996. 18,
  136997. 30,
  136998. 17,
  136999. 31,
  137000. 16,
  137001. 32,
  137002. 15,
  137003. 33,
  137004. 14,
  137005. 34,
  137006. 13,
  137007. 35,
  137008. 12,
  137009. 36,
  137010. 11,
  137011. 37,
  137012. 10,
  137013. 38,
  137014. 9,
  137015. 39,
  137016. 8,
  137017. 40,
  137018. 7,
  137019. 41,
  137020. 6,
  137021. 42,
  137022. 5,
  137023. 43,
  137024. 4,
  137025. 44,
  137026. 3,
  137027. 45,
  137028. 2,
  137029. 46,
  137030. 1,
  137031. 47,
  137032. 0,
  137033. 48,
  137034. };
  137035. static long _vq_lengthlist__44u8_p9_2[] = {
  137036. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137037. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137038. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137039. 7,
  137040. };
  137041. static float _vq_quantthresh__44u8_p9_2[] = {
  137042. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137043. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137044. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137045. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137046. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137047. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137048. };
  137049. static long _vq_quantmap__44u8_p9_2[] = {
  137050. 47, 45, 43, 41, 39, 37, 35, 33,
  137051. 31, 29, 27, 25, 23, 21, 19, 17,
  137052. 15, 13, 11, 9, 7, 5, 3, 1,
  137053. 0, 2, 4, 6, 8, 10, 12, 14,
  137054. 16, 18, 20, 22, 24, 26, 28, 30,
  137055. 32, 34, 36, 38, 40, 42, 44, 46,
  137056. 48,
  137057. };
  137058. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137059. _vq_quantthresh__44u8_p9_2,
  137060. _vq_quantmap__44u8_p9_2,
  137061. 49,
  137062. 49
  137063. };
  137064. static static_codebook _44u8_p9_2 = {
  137065. 1, 49,
  137066. _vq_lengthlist__44u8_p9_2,
  137067. 1, -526909440, 1611661312, 6, 0,
  137068. _vq_quantlist__44u8_p9_2,
  137069. NULL,
  137070. &_vq_auxt__44u8_p9_2,
  137071. NULL,
  137072. 0
  137073. };
  137074. static long _huff_lengthlist__44u9__long[] = {
  137075. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137076. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137077. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137078. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137079. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137080. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137081. 10, 8, 8, 9,
  137082. };
  137083. static static_codebook _huff_book__44u9__long = {
  137084. 2, 100,
  137085. _huff_lengthlist__44u9__long,
  137086. 0, 0, 0, 0, 0,
  137087. NULL,
  137088. NULL,
  137089. NULL,
  137090. NULL,
  137091. 0
  137092. };
  137093. static long _huff_lengthlist__44u9__short[] = {
  137094. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137095. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137096. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137097. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137098. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137099. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137100. 9, 9,12,15,
  137101. };
  137102. static static_codebook _huff_book__44u9__short = {
  137103. 2, 100,
  137104. _huff_lengthlist__44u9__short,
  137105. 0, 0, 0, 0, 0,
  137106. NULL,
  137107. NULL,
  137108. NULL,
  137109. NULL,
  137110. 0
  137111. };
  137112. static long _vq_quantlist__44u9_p1_0[] = {
  137113. 1,
  137114. 0,
  137115. 2,
  137116. };
  137117. static long _vq_lengthlist__44u9_p1_0[] = {
  137118. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137119. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137120. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137121. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137122. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137123. 10,
  137124. };
  137125. static float _vq_quantthresh__44u9_p1_0[] = {
  137126. -0.5, 0.5,
  137127. };
  137128. static long _vq_quantmap__44u9_p1_0[] = {
  137129. 1, 0, 2,
  137130. };
  137131. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137132. _vq_quantthresh__44u9_p1_0,
  137133. _vq_quantmap__44u9_p1_0,
  137134. 3,
  137135. 3
  137136. };
  137137. static static_codebook _44u9_p1_0 = {
  137138. 4, 81,
  137139. _vq_lengthlist__44u9_p1_0,
  137140. 1, -535822336, 1611661312, 2, 0,
  137141. _vq_quantlist__44u9_p1_0,
  137142. NULL,
  137143. &_vq_auxt__44u9_p1_0,
  137144. NULL,
  137145. 0
  137146. };
  137147. static long _vq_quantlist__44u9_p2_0[] = {
  137148. 2,
  137149. 1,
  137150. 3,
  137151. 0,
  137152. 4,
  137153. };
  137154. static long _vq_lengthlist__44u9_p2_0[] = {
  137155. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137156. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137157. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137158. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137159. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137160. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137161. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137162. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137163. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137164. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137165. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137166. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137167. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137168. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137169. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137170. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137171. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137172. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137173. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137174. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137175. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137176. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137177. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137178. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137179. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137180. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137181. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137182. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137183. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137184. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137185. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137186. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137187. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137188. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137189. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137190. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137191. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137192. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137193. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137194. 14,
  137195. };
  137196. static float _vq_quantthresh__44u9_p2_0[] = {
  137197. -1.5, -0.5, 0.5, 1.5,
  137198. };
  137199. static long _vq_quantmap__44u9_p2_0[] = {
  137200. 3, 1, 0, 2, 4,
  137201. };
  137202. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137203. _vq_quantthresh__44u9_p2_0,
  137204. _vq_quantmap__44u9_p2_0,
  137205. 5,
  137206. 5
  137207. };
  137208. static static_codebook _44u9_p2_0 = {
  137209. 4, 625,
  137210. _vq_lengthlist__44u9_p2_0,
  137211. 1, -533725184, 1611661312, 3, 0,
  137212. _vq_quantlist__44u9_p2_0,
  137213. NULL,
  137214. &_vq_auxt__44u9_p2_0,
  137215. NULL,
  137216. 0
  137217. };
  137218. static long _vq_quantlist__44u9_p3_0[] = {
  137219. 4,
  137220. 3,
  137221. 5,
  137222. 2,
  137223. 6,
  137224. 1,
  137225. 7,
  137226. 0,
  137227. 8,
  137228. };
  137229. static long _vq_lengthlist__44u9_p3_0[] = {
  137230. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137231. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137232. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137233. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137234. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137235. 11,
  137236. };
  137237. static float _vq_quantthresh__44u9_p3_0[] = {
  137238. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137239. };
  137240. static long _vq_quantmap__44u9_p3_0[] = {
  137241. 7, 5, 3, 1, 0, 2, 4, 6,
  137242. 8,
  137243. };
  137244. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137245. _vq_quantthresh__44u9_p3_0,
  137246. _vq_quantmap__44u9_p3_0,
  137247. 9,
  137248. 9
  137249. };
  137250. static static_codebook _44u9_p3_0 = {
  137251. 2, 81,
  137252. _vq_lengthlist__44u9_p3_0,
  137253. 1, -531628032, 1611661312, 4, 0,
  137254. _vq_quantlist__44u9_p3_0,
  137255. NULL,
  137256. &_vq_auxt__44u9_p3_0,
  137257. NULL,
  137258. 0
  137259. };
  137260. static long _vq_quantlist__44u9_p4_0[] = {
  137261. 8,
  137262. 7,
  137263. 9,
  137264. 6,
  137265. 10,
  137266. 5,
  137267. 11,
  137268. 4,
  137269. 12,
  137270. 3,
  137271. 13,
  137272. 2,
  137273. 14,
  137274. 1,
  137275. 15,
  137276. 0,
  137277. 16,
  137278. };
  137279. static long _vq_lengthlist__44u9_p4_0[] = {
  137280. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137281. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137282. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137283. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137284. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137285. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137286. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137287. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137288. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137289. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137290. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137291. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137292. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137293. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137294. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137295. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137296. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137297. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137298. 14,
  137299. };
  137300. static float _vq_quantthresh__44u9_p4_0[] = {
  137301. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137302. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137303. };
  137304. static long _vq_quantmap__44u9_p4_0[] = {
  137305. 15, 13, 11, 9, 7, 5, 3, 1,
  137306. 0, 2, 4, 6, 8, 10, 12, 14,
  137307. 16,
  137308. };
  137309. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137310. _vq_quantthresh__44u9_p4_0,
  137311. _vq_quantmap__44u9_p4_0,
  137312. 17,
  137313. 17
  137314. };
  137315. static static_codebook _44u9_p4_0 = {
  137316. 2, 289,
  137317. _vq_lengthlist__44u9_p4_0,
  137318. 1, -529530880, 1611661312, 5, 0,
  137319. _vq_quantlist__44u9_p4_0,
  137320. NULL,
  137321. &_vq_auxt__44u9_p4_0,
  137322. NULL,
  137323. 0
  137324. };
  137325. static long _vq_quantlist__44u9_p5_0[] = {
  137326. 1,
  137327. 0,
  137328. 2,
  137329. };
  137330. static long _vq_lengthlist__44u9_p5_0[] = {
  137331. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137332. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137333. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137334. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137335. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137336. 10,
  137337. };
  137338. static float _vq_quantthresh__44u9_p5_0[] = {
  137339. -5.5, 5.5,
  137340. };
  137341. static long _vq_quantmap__44u9_p5_0[] = {
  137342. 1, 0, 2,
  137343. };
  137344. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137345. _vq_quantthresh__44u9_p5_0,
  137346. _vq_quantmap__44u9_p5_0,
  137347. 3,
  137348. 3
  137349. };
  137350. static static_codebook _44u9_p5_0 = {
  137351. 4, 81,
  137352. _vq_lengthlist__44u9_p5_0,
  137353. 1, -529137664, 1618345984, 2, 0,
  137354. _vq_quantlist__44u9_p5_0,
  137355. NULL,
  137356. &_vq_auxt__44u9_p5_0,
  137357. NULL,
  137358. 0
  137359. };
  137360. static long _vq_quantlist__44u9_p5_1[] = {
  137361. 5,
  137362. 4,
  137363. 6,
  137364. 3,
  137365. 7,
  137366. 2,
  137367. 8,
  137368. 1,
  137369. 9,
  137370. 0,
  137371. 10,
  137372. };
  137373. static long _vq_lengthlist__44u9_p5_1[] = {
  137374. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137375. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137376. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137377. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137378. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137379. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137380. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137381. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137382. };
  137383. static float _vq_quantthresh__44u9_p5_1[] = {
  137384. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137385. 3.5, 4.5,
  137386. };
  137387. static long _vq_quantmap__44u9_p5_1[] = {
  137388. 9, 7, 5, 3, 1, 0, 2, 4,
  137389. 6, 8, 10,
  137390. };
  137391. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137392. _vq_quantthresh__44u9_p5_1,
  137393. _vq_quantmap__44u9_p5_1,
  137394. 11,
  137395. 11
  137396. };
  137397. static static_codebook _44u9_p5_1 = {
  137398. 2, 121,
  137399. _vq_lengthlist__44u9_p5_1,
  137400. 1, -531365888, 1611661312, 4, 0,
  137401. _vq_quantlist__44u9_p5_1,
  137402. NULL,
  137403. &_vq_auxt__44u9_p5_1,
  137404. NULL,
  137405. 0
  137406. };
  137407. static long _vq_quantlist__44u9_p6_0[] = {
  137408. 6,
  137409. 5,
  137410. 7,
  137411. 4,
  137412. 8,
  137413. 3,
  137414. 9,
  137415. 2,
  137416. 10,
  137417. 1,
  137418. 11,
  137419. 0,
  137420. 12,
  137421. };
  137422. static long _vq_lengthlist__44u9_p6_0[] = {
  137423. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137424. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137425. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137426. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137427. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137428. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137429. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137430. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137431. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137432. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137433. 10,11,11,11,11,12,11,12,12,
  137434. };
  137435. static float _vq_quantthresh__44u9_p6_0[] = {
  137436. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137437. 12.5, 17.5, 22.5, 27.5,
  137438. };
  137439. static long _vq_quantmap__44u9_p6_0[] = {
  137440. 11, 9, 7, 5, 3, 1, 0, 2,
  137441. 4, 6, 8, 10, 12,
  137442. };
  137443. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137444. _vq_quantthresh__44u9_p6_0,
  137445. _vq_quantmap__44u9_p6_0,
  137446. 13,
  137447. 13
  137448. };
  137449. static static_codebook _44u9_p6_0 = {
  137450. 2, 169,
  137451. _vq_lengthlist__44u9_p6_0,
  137452. 1, -526516224, 1616117760, 4, 0,
  137453. _vq_quantlist__44u9_p6_0,
  137454. NULL,
  137455. &_vq_auxt__44u9_p6_0,
  137456. NULL,
  137457. 0
  137458. };
  137459. static long _vq_quantlist__44u9_p6_1[] = {
  137460. 2,
  137461. 1,
  137462. 3,
  137463. 0,
  137464. 4,
  137465. };
  137466. static long _vq_lengthlist__44u9_p6_1[] = {
  137467. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137468. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137469. };
  137470. static float _vq_quantthresh__44u9_p6_1[] = {
  137471. -1.5, -0.5, 0.5, 1.5,
  137472. };
  137473. static long _vq_quantmap__44u9_p6_1[] = {
  137474. 3, 1, 0, 2, 4,
  137475. };
  137476. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137477. _vq_quantthresh__44u9_p6_1,
  137478. _vq_quantmap__44u9_p6_1,
  137479. 5,
  137480. 5
  137481. };
  137482. static static_codebook _44u9_p6_1 = {
  137483. 2, 25,
  137484. _vq_lengthlist__44u9_p6_1,
  137485. 1, -533725184, 1611661312, 3, 0,
  137486. _vq_quantlist__44u9_p6_1,
  137487. NULL,
  137488. &_vq_auxt__44u9_p6_1,
  137489. NULL,
  137490. 0
  137491. };
  137492. static long _vq_quantlist__44u9_p7_0[] = {
  137493. 6,
  137494. 5,
  137495. 7,
  137496. 4,
  137497. 8,
  137498. 3,
  137499. 9,
  137500. 2,
  137501. 10,
  137502. 1,
  137503. 11,
  137504. 0,
  137505. 12,
  137506. };
  137507. static long _vq_lengthlist__44u9_p7_0[] = {
  137508. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137509. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137510. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137511. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137512. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137513. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137514. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137515. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137516. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137517. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137518. 12,13,13,14,14,14,15,15,15,
  137519. };
  137520. static float _vq_quantthresh__44u9_p7_0[] = {
  137521. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137522. 27.5, 38.5, 49.5, 60.5,
  137523. };
  137524. static long _vq_quantmap__44u9_p7_0[] = {
  137525. 11, 9, 7, 5, 3, 1, 0, 2,
  137526. 4, 6, 8, 10, 12,
  137527. };
  137528. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137529. _vq_quantthresh__44u9_p7_0,
  137530. _vq_quantmap__44u9_p7_0,
  137531. 13,
  137532. 13
  137533. };
  137534. static static_codebook _44u9_p7_0 = {
  137535. 2, 169,
  137536. _vq_lengthlist__44u9_p7_0,
  137537. 1, -523206656, 1618345984, 4, 0,
  137538. _vq_quantlist__44u9_p7_0,
  137539. NULL,
  137540. &_vq_auxt__44u9_p7_0,
  137541. NULL,
  137542. 0
  137543. };
  137544. static long _vq_quantlist__44u9_p7_1[] = {
  137545. 5,
  137546. 4,
  137547. 6,
  137548. 3,
  137549. 7,
  137550. 2,
  137551. 8,
  137552. 1,
  137553. 9,
  137554. 0,
  137555. 10,
  137556. };
  137557. static long _vq_lengthlist__44u9_p7_1[] = {
  137558. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137559. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137560. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137561. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137562. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137563. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137564. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137565. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137566. };
  137567. static float _vq_quantthresh__44u9_p7_1[] = {
  137568. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137569. 3.5, 4.5,
  137570. };
  137571. static long _vq_quantmap__44u9_p7_1[] = {
  137572. 9, 7, 5, 3, 1, 0, 2, 4,
  137573. 6, 8, 10,
  137574. };
  137575. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137576. _vq_quantthresh__44u9_p7_1,
  137577. _vq_quantmap__44u9_p7_1,
  137578. 11,
  137579. 11
  137580. };
  137581. static static_codebook _44u9_p7_1 = {
  137582. 2, 121,
  137583. _vq_lengthlist__44u9_p7_1,
  137584. 1, -531365888, 1611661312, 4, 0,
  137585. _vq_quantlist__44u9_p7_1,
  137586. NULL,
  137587. &_vq_auxt__44u9_p7_1,
  137588. NULL,
  137589. 0
  137590. };
  137591. static long _vq_quantlist__44u9_p8_0[] = {
  137592. 7,
  137593. 6,
  137594. 8,
  137595. 5,
  137596. 9,
  137597. 4,
  137598. 10,
  137599. 3,
  137600. 11,
  137601. 2,
  137602. 12,
  137603. 1,
  137604. 13,
  137605. 0,
  137606. 14,
  137607. };
  137608. static long _vq_lengthlist__44u9_p8_0[] = {
  137609. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137610. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137611. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137612. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137613. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137614. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137615. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137616. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137617. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137618. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137619. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137620. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137621. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137622. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137623. 15,
  137624. };
  137625. static float _vq_quantthresh__44u9_p8_0[] = {
  137626. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137627. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137628. };
  137629. static long _vq_quantmap__44u9_p8_0[] = {
  137630. 13, 11, 9, 7, 5, 3, 1, 0,
  137631. 2, 4, 6, 8, 10, 12, 14,
  137632. };
  137633. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137634. _vq_quantthresh__44u9_p8_0,
  137635. _vq_quantmap__44u9_p8_0,
  137636. 15,
  137637. 15
  137638. };
  137639. static static_codebook _44u9_p8_0 = {
  137640. 2, 225,
  137641. _vq_lengthlist__44u9_p8_0,
  137642. 1, -520986624, 1620377600, 4, 0,
  137643. _vq_quantlist__44u9_p8_0,
  137644. NULL,
  137645. &_vq_auxt__44u9_p8_0,
  137646. NULL,
  137647. 0
  137648. };
  137649. static long _vq_quantlist__44u9_p8_1[] = {
  137650. 10,
  137651. 9,
  137652. 11,
  137653. 8,
  137654. 12,
  137655. 7,
  137656. 13,
  137657. 6,
  137658. 14,
  137659. 5,
  137660. 15,
  137661. 4,
  137662. 16,
  137663. 3,
  137664. 17,
  137665. 2,
  137666. 18,
  137667. 1,
  137668. 19,
  137669. 0,
  137670. 20,
  137671. };
  137672. static long _vq_lengthlist__44u9_p8_1[] = {
  137673. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137674. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137675. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137676. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137677. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137678. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137679. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137680. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137681. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137682. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137683. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137684. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137685. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137686. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137687. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137688. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137689. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137690. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137691. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137692. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137693. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137694. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137695. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137696. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137697. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137698. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137699. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137700. 10,10,10,10,10,10,10,10,10,
  137701. };
  137702. static float _vq_quantthresh__44u9_p8_1[] = {
  137703. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137704. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137705. 6.5, 7.5, 8.5, 9.5,
  137706. };
  137707. static long _vq_quantmap__44u9_p8_1[] = {
  137708. 19, 17, 15, 13, 11, 9, 7, 5,
  137709. 3, 1, 0, 2, 4, 6, 8, 10,
  137710. 12, 14, 16, 18, 20,
  137711. };
  137712. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137713. _vq_quantthresh__44u9_p8_1,
  137714. _vq_quantmap__44u9_p8_1,
  137715. 21,
  137716. 21
  137717. };
  137718. static static_codebook _44u9_p8_1 = {
  137719. 2, 441,
  137720. _vq_lengthlist__44u9_p8_1,
  137721. 1, -529268736, 1611661312, 5, 0,
  137722. _vq_quantlist__44u9_p8_1,
  137723. NULL,
  137724. &_vq_auxt__44u9_p8_1,
  137725. NULL,
  137726. 0
  137727. };
  137728. static long _vq_quantlist__44u9_p9_0[] = {
  137729. 7,
  137730. 6,
  137731. 8,
  137732. 5,
  137733. 9,
  137734. 4,
  137735. 10,
  137736. 3,
  137737. 11,
  137738. 2,
  137739. 12,
  137740. 1,
  137741. 13,
  137742. 0,
  137743. 14,
  137744. };
  137745. static long _vq_lengthlist__44u9_p9_0[] = {
  137746. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137747. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137748. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137758. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137759. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137760. 10,
  137761. };
  137762. static float _vq_quantthresh__44u9_p9_0[] = {
  137763. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137764. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137765. };
  137766. static long _vq_quantmap__44u9_p9_0[] = {
  137767. 13, 11, 9, 7, 5, 3, 1, 0,
  137768. 2, 4, 6, 8, 10, 12, 14,
  137769. };
  137770. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137771. _vq_quantthresh__44u9_p9_0,
  137772. _vq_quantmap__44u9_p9_0,
  137773. 15,
  137774. 15
  137775. };
  137776. static static_codebook _44u9_p9_0 = {
  137777. 2, 225,
  137778. _vq_lengthlist__44u9_p9_0,
  137779. 1, -510036736, 1631393792, 4, 0,
  137780. _vq_quantlist__44u9_p9_0,
  137781. NULL,
  137782. &_vq_auxt__44u9_p9_0,
  137783. NULL,
  137784. 0
  137785. };
  137786. static long _vq_quantlist__44u9_p9_1[] = {
  137787. 9,
  137788. 8,
  137789. 10,
  137790. 7,
  137791. 11,
  137792. 6,
  137793. 12,
  137794. 5,
  137795. 13,
  137796. 4,
  137797. 14,
  137798. 3,
  137799. 15,
  137800. 2,
  137801. 16,
  137802. 1,
  137803. 17,
  137804. 0,
  137805. 18,
  137806. };
  137807. static long _vq_lengthlist__44u9_p9_1[] = {
  137808. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137809. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137810. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137811. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137812. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137813. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137814. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137815. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137816. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137817. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137818. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137819. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137820. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137821. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137822. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137823. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137824. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137825. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137826. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137827. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137828. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137829. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137830. 17,17,15,17,15,17,16,16,17,
  137831. };
  137832. static float _vq_quantthresh__44u9_p9_1[] = {
  137833. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137834. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137835. 367.5, 416.5,
  137836. };
  137837. static long _vq_quantmap__44u9_p9_1[] = {
  137838. 17, 15, 13, 11, 9, 7, 5, 3,
  137839. 1, 0, 2, 4, 6, 8, 10, 12,
  137840. 14, 16, 18,
  137841. };
  137842. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137843. _vq_quantthresh__44u9_p9_1,
  137844. _vq_quantmap__44u9_p9_1,
  137845. 19,
  137846. 19
  137847. };
  137848. static static_codebook _44u9_p9_1 = {
  137849. 2, 361,
  137850. _vq_lengthlist__44u9_p9_1,
  137851. 1, -518287360, 1622704128, 5, 0,
  137852. _vq_quantlist__44u9_p9_1,
  137853. NULL,
  137854. &_vq_auxt__44u9_p9_1,
  137855. NULL,
  137856. 0
  137857. };
  137858. static long _vq_quantlist__44u9_p9_2[] = {
  137859. 24,
  137860. 23,
  137861. 25,
  137862. 22,
  137863. 26,
  137864. 21,
  137865. 27,
  137866. 20,
  137867. 28,
  137868. 19,
  137869. 29,
  137870. 18,
  137871. 30,
  137872. 17,
  137873. 31,
  137874. 16,
  137875. 32,
  137876. 15,
  137877. 33,
  137878. 14,
  137879. 34,
  137880. 13,
  137881. 35,
  137882. 12,
  137883. 36,
  137884. 11,
  137885. 37,
  137886. 10,
  137887. 38,
  137888. 9,
  137889. 39,
  137890. 8,
  137891. 40,
  137892. 7,
  137893. 41,
  137894. 6,
  137895. 42,
  137896. 5,
  137897. 43,
  137898. 4,
  137899. 44,
  137900. 3,
  137901. 45,
  137902. 2,
  137903. 46,
  137904. 1,
  137905. 47,
  137906. 0,
  137907. 48,
  137908. };
  137909. static long _vq_lengthlist__44u9_p9_2[] = {
  137910. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137911. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137912. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137913. 7,
  137914. };
  137915. static float _vq_quantthresh__44u9_p9_2[] = {
  137916. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137917. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137918. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137919. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137920. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137921. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137922. };
  137923. static long _vq_quantmap__44u9_p9_2[] = {
  137924. 47, 45, 43, 41, 39, 37, 35, 33,
  137925. 31, 29, 27, 25, 23, 21, 19, 17,
  137926. 15, 13, 11, 9, 7, 5, 3, 1,
  137927. 0, 2, 4, 6, 8, 10, 12, 14,
  137928. 16, 18, 20, 22, 24, 26, 28, 30,
  137929. 32, 34, 36, 38, 40, 42, 44, 46,
  137930. 48,
  137931. };
  137932. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  137933. _vq_quantthresh__44u9_p9_2,
  137934. _vq_quantmap__44u9_p9_2,
  137935. 49,
  137936. 49
  137937. };
  137938. static static_codebook _44u9_p9_2 = {
  137939. 1, 49,
  137940. _vq_lengthlist__44u9_p9_2,
  137941. 1, -526909440, 1611661312, 6, 0,
  137942. _vq_quantlist__44u9_p9_2,
  137943. NULL,
  137944. &_vq_auxt__44u9_p9_2,
  137945. NULL,
  137946. 0
  137947. };
  137948. static long _huff_lengthlist__44un1__long[] = {
  137949. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  137950. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  137951. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  137952. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  137953. };
  137954. static static_codebook _huff_book__44un1__long = {
  137955. 2, 64,
  137956. _huff_lengthlist__44un1__long,
  137957. 0, 0, 0, 0, 0,
  137958. NULL,
  137959. NULL,
  137960. NULL,
  137961. NULL,
  137962. 0
  137963. };
  137964. static long _vq_quantlist__44un1__p1_0[] = {
  137965. 1,
  137966. 0,
  137967. 2,
  137968. };
  137969. static long _vq_lengthlist__44un1__p1_0[] = {
  137970. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  137971. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  137972. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  137973. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  137974. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  137975. 12,
  137976. };
  137977. static float _vq_quantthresh__44un1__p1_0[] = {
  137978. -0.5, 0.5,
  137979. };
  137980. static long _vq_quantmap__44un1__p1_0[] = {
  137981. 1, 0, 2,
  137982. };
  137983. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  137984. _vq_quantthresh__44un1__p1_0,
  137985. _vq_quantmap__44un1__p1_0,
  137986. 3,
  137987. 3
  137988. };
  137989. static static_codebook _44un1__p1_0 = {
  137990. 4, 81,
  137991. _vq_lengthlist__44un1__p1_0,
  137992. 1, -535822336, 1611661312, 2, 0,
  137993. _vq_quantlist__44un1__p1_0,
  137994. NULL,
  137995. &_vq_auxt__44un1__p1_0,
  137996. NULL,
  137997. 0
  137998. };
  137999. static long _vq_quantlist__44un1__p2_0[] = {
  138000. 1,
  138001. 0,
  138002. 2,
  138003. };
  138004. static long _vq_lengthlist__44un1__p2_0[] = {
  138005. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138006. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138007. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138008. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138009. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138010. 8,
  138011. };
  138012. static float _vq_quantthresh__44un1__p2_0[] = {
  138013. -0.5, 0.5,
  138014. };
  138015. static long _vq_quantmap__44un1__p2_0[] = {
  138016. 1, 0, 2,
  138017. };
  138018. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138019. _vq_quantthresh__44un1__p2_0,
  138020. _vq_quantmap__44un1__p2_0,
  138021. 3,
  138022. 3
  138023. };
  138024. static static_codebook _44un1__p2_0 = {
  138025. 4, 81,
  138026. _vq_lengthlist__44un1__p2_0,
  138027. 1, -535822336, 1611661312, 2, 0,
  138028. _vq_quantlist__44un1__p2_0,
  138029. NULL,
  138030. &_vq_auxt__44un1__p2_0,
  138031. NULL,
  138032. 0
  138033. };
  138034. static long _vq_quantlist__44un1__p3_0[] = {
  138035. 2,
  138036. 1,
  138037. 3,
  138038. 0,
  138039. 4,
  138040. };
  138041. static long _vq_lengthlist__44un1__p3_0[] = {
  138042. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138043. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138044. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138045. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138046. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138047. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138048. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138049. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138050. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138051. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138052. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138053. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138054. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138055. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138056. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138057. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138058. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138059. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138060. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138061. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138062. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138063. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138064. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138065. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138066. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138067. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138068. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138069. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138070. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138071. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138072. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138073. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138074. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138075. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138076. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138077. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138078. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138079. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138080. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138081. 17,
  138082. };
  138083. static float _vq_quantthresh__44un1__p3_0[] = {
  138084. -1.5, -0.5, 0.5, 1.5,
  138085. };
  138086. static long _vq_quantmap__44un1__p3_0[] = {
  138087. 3, 1, 0, 2, 4,
  138088. };
  138089. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138090. _vq_quantthresh__44un1__p3_0,
  138091. _vq_quantmap__44un1__p3_0,
  138092. 5,
  138093. 5
  138094. };
  138095. static static_codebook _44un1__p3_0 = {
  138096. 4, 625,
  138097. _vq_lengthlist__44un1__p3_0,
  138098. 1, -533725184, 1611661312, 3, 0,
  138099. _vq_quantlist__44un1__p3_0,
  138100. NULL,
  138101. &_vq_auxt__44un1__p3_0,
  138102. NULL,
  138103. 0
  138104. };
  138105. static long _vq_quantlist__44un1__p4_0[] = {
  138106. 2,
  138107. 1,
  138108. 3,
  138109. 0,
  138110. 4,
  138111. };
  138112. static long _vq_lengthlist__44un1__p4_0[] = {
  138113. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138114. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138115. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138116. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138117. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138118. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138119. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138120. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138121. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138122. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138123. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138124. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138125. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138126. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138127. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138128. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138129. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138130. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138131. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138132. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138133. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138134. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138135. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138136. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138137. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138138. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138139. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138140. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138141. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138142. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138143. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138144. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138145. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138146. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138147. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138148. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138149. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138150. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138151. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138152. 12,
  138153. };
  138154. static float _vq_quantthresh__44un1__p4_0[] = {
  138155. -1.5, -0.5, 0.5, 1.5,
  138156. };
  138157. static long _vq_quantmap__44un1__p4_0[] = {
  138158. 3, 1, 0, 2, 4,
  138159. };
  138160. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138161. _vq_quantthresh__44un1__p4_0,
  138162. _vq_quantmap__44un1__p4_0,
  138163. 5,
  138164. 5
  138165. };
  138166. static static_codebook _44un1__p4_0 = {
  138167. 4, 625,
  138168. _vq_lengthlist__44un1__p4_0,
  138169. 1, -533725184, 1611661312, 3, 0,
  138170. _vq_quantlist__44un1__p4_0,
  138171. NULL,
  138172. &_vq_auxt__44un1__p4_0,
  138173. NULL,
  138174. 0
  138175. };
  138176. static long _vq_quantlist__44un1__p5_0[] = {
  138177. 4,
  138178. 3,
  138179. 5,
  138180. 2,
  138181. 6,
  138182. 1,
  138183. 7,
  138184. 0,
  138185. 8,
  138186. };
  138187. static long _vq_lengthlist__44un1__p5_0[] = {
  138188. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138189. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138190. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138191. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138192. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138193. 12,
  138194. };
  138195. static float _vq_quantthresh__44un1__p5_0[] = {
  138196. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138197. };
  138198. static long _vq_quantmap__44un1__p5_0[] = {
  138199. 7, 5, 3, 1, 0, 2, 4, 6,
  138200. 8,
  138201. };
  138202. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138203. _vq_quantthresh__44un1__p5_0,
  138204. _vq_quantmap__44un1__p5_0,
  138205. 9,
  138206. 9
  138207. };
  138208. static static_codebook _44un1__p5_0 = {
  138209. 2, 81,
  138210. _vq_lengthlist__44un1__p5_0,
  138211. 1, -531628032, 1611661312, 4, 0,
  138212. _vq_quantlist__44un1__p5_0,
  138213. NULL,
  138214. &_vq_auxt__44un1__p5_0,
  138215. NULL,
  138216. 0
  138217. };
  138218. static long _vq_quantlist__44un1__p6_0[] = {
  138219. 6,
  138220. 5,
  138221. 7,
  138222. 4,
  138223. 8,
  138224. 3,
  138225. 9,
  138226. 2,
  138227. 10,
  138228. 1,
  138229. 11,
  138230. 0,
  138231. 12,
  138232. };
  138233. static long _vq_lengthlist__44un1__p6_0[] = {
  138234. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138235. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138236. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138237. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138238. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138239. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138240. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138241. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138242. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138243. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138244. 16, 0,15,18,18, 0,16, 0, 0,
  138245. };
  138246. static float _vq_quantthresh__44un1__p6_0[] = {
  138247. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138248. 12.5, 17.5, 22.5, 27.5,
  138249. };
  138250. static long _vq_quantmap__44un1__p6_0[] = {
  138251. 11, 9, 7, 5, 3, 1, 0, 2,
  138252. 4, 6, 8, 10, 12,
  138253. };
  138254. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138255. _vq_quantthresh__44un1__p6_0,
  138256. _vq_quantmap__44un1__p6_0,
  138257. 13,
  138258. 13
  138259. };
  138260. static static_codebook _44un1__p6_0 = {
  138261. 2, 169,
  138262. _vq_lengthlist__44un1__p6_0,
  138263. 1, -526516224, 1616117760, 4, 0,
  138264. _vq_quantlist__44un1__p6_0,
  138265. NULL,
  138266. &_vq_auxt__44un1__p6_0,
  138267. NULL,
  138268. 0
  138269. };
  138270. static long _vq_quantlist__44un1__p6_1[] = {
  138271. 2,
  138272. 1,
  138273. 3,
  138274. 0,
  138275. 4,
  138276. };
  138277. static long _vq_lengthlist__44un1__p6_1[] = {
  138278. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138279. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138280. };
  138281. static float _vq_quantthresh__44un1__p6_1[] = {
  138282. -1.5, -0.5, 0.5, 1.5,
  138283. };
  138284. static long _vq_quantmap__44un1__p6_1[] = {
  138285. 3, 1, 0, 2, 4,
  138286. };
  138287. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138288. _vq_quantthresh__44un1__p6_1,
  138289. _vq_quantmap__44un1__p6_1,
  138290. 5,
  138291. 5
  138292. };
  138293. static static_codebook _44un1__p6_1 = {
  138294. 2, 25,
  138295. _vq_lengthlist__44un1__p6_1,
  138296. 1, -533725184, 1611661312, 3, 0,
  138297. _vq_quantlist__44un1__p6_1,
  138298. NULL,
  138299. &_vq_auxt__44un1__p6_1,
  138300. NULL,
  138301. 0
  138302. };
  138303. static long _vq_quantlist__44un1__p7_0[] = {
  138304. 2,
  138305. 1,
  138306. 3,
  138307. 0,
  138308. 4,
  138309. };
  138310. static long _vq_lengthlist__44un1__p7_0[] = {
  138311. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138312. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138314. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138316. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138317. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138318. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138319. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138320. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138321. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138322. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138323. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138324. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138325. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138326. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138327. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138328. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138329. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138330. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138331. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138332. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138333. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138334. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138335. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138336. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138337. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138338. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138346. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138347. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138348. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138349. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138350. 10,
  138351. };
  138352. static float _vq_quantthresh__44un1__p7_0[] = {
  138353. -253.5, -84.5, 84.5, 253.5,
  138354. };
  138355. static long _vq_quantmap__44un1__p7_0[] = {
  138356. 3, 1, 0, 2, 4,
  138357. };
  138358. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138359. _vq_quantthresh__44un1__p7_0,
  138360. _vq_quantmap__44un1__p7_0,
  138361. 5,
  138362. 5
  138363. };
  138364. static static_codebook _44un1__p7_0 = {
  138365. 4, 625,
  138366. _vq_lengthlist__44un1__p7_0,
  138367. 1, -518709248, 1626677248, 3, 0,
  138368. _vq_quantlist__44un1__p7_0,
  138369. NULL,
  138370. &_vq_auxt__44un1__p7_0,
  138371. NULL,
  138372. 0
  138373. };
  138374. static long _vq_quantlist__44un1__p7_1[] = {
  138375. 6,
  138376. 5,
  138377. 7,
  138378. 4,
  138379. 8,
  138380. 3,
  138381. 9,
  138382. 2,
  138383. 10,
  138384. 1,
  138385. 11,
  138386. 0,
  138387. 12,
  138388. };
  138389. static long _vq_lengthlist__44un1__p7_1[] = {
  138390. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138391. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138392. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138393. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138394. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138395. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138396. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138397. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138398. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138399. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138400. 12,13,13,12,13,13,14,14,14,
  138401. };
  138402. static float _vq_quantthresh__44un1__p7_1[] = {
  138403. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138404. 32.5, 45.5, 58.5, 71.5,
  138405. };
  138406. static long _vq_quantmap__44un1__p7_1[] = {
  138407. 11, 9, 7, 5, 3, 1, 0, 2,
  138408. 4, 6, 8, 10, 12,
  138409. };
  138410. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138411. _vq_quantthresh__44un1__p7_1,
  138412. _vq_quantmap__44un1__p7_1,
  138413. 13,
  138414. 13
  138415. };
  138416. static static_codebook _44un1__p7_1 = {
  138417. 2, 169,
  138418. _vq_lengthlist__44un1__p7_1,
  138419. 1, -523010048, 1618608128, 4, 0,
  138420. _vq_quantlist__44un1__p7_1,
  138421. NULL,
  138422. &_vq_auxt__44un1__p7_1,
  138423. NULL,
  138424. 0
  138425. };
  138426. static long _vq_quantlist__44un1__p7_2[] = {
  138427. 6,
  138428. 5,
  138429. 7,
  138430. 4,
  138431. 8,
  138432. 3,
  138433. 9,
  138434. 2,
  138435. 10,
  138436. 1,
  138437. 11,
  138438. 0,
  138439. 12,
  138440. };
  138441. static long _vq_lengthlist__44un1__p7_2[] = {
  138442. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138443. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138444. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138445. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138446. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138447. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138448. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138449. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138450. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138451. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138452. 9, 9, 9,10,10,10,10,10,10,
  138453. };
  138454. static float _vq_quantthresh__44un1__p7_2[] = {
  138455. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138456. 2.5, 3.5, 4.5, 5.5,
  138457. };
  138458. static long _vq_quantmap__44un1__p7_2[] = {
  138459. 11, 9, 7, 5, 3, 1, 0, 2,
  138460. 4, 6, 8, 10, 12,
  138461. };
  138462. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138463. _vq_quantthresh__44un1__p7_2,
  138464. _vq_quantmap__44un1__p7_2,
  138465. 13,
  138466. 13
  138467. };
  138468. static static_codebook _44un1__p7_2 = {
  138469. 2, 169,
  138470. _vq_lengthlist__44un1__p7_2,
  138471. 1, -531103744, 1611661312, 4, 0,
  138472. _vq_quantlist__44un1__p7_2,
  138473. NULL,
  138474. &_vq_auxt__44un1__p7_2,
  138475. NULL,
  138476. 0
  138477. };
  138478. static long _huff_lengthlist__44un1__short[] = {
  138479. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138480. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138481. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138482. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138483. };
  138484. static static_codebook _huff_book__44un1__short = {
  138485. 2, 64,
  138486. _huff_lengthlist__44un1__short,
  138487. 0, 0, 0, 0, 0,
  138488. NULL,
  138489. NULL,
  138490. NULL,
  138491. NULL,
  138492. 0
  138493. };
  138494. /*** End of inlined file: res_books_uncoupled.h ***/
  138495. static vorbis_info_residue0 _residue_44_low_un={
  138496. 0,-1, -1, 8,-1,
  138497. {0},
  138498. {-1},
  138499. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138500. { -1, 25, -1, 45, -1, -1, -1}
  138501. };
  138502. static vorbis_info_residue0 _residue_44_mid_un={
  138503. 0,-1, -1, 10,-1,
  138504. {0},
  138505. {-1},
  138506. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138507. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138508. };
  138509. static vorbis_info_residue0 _residue_44_hi_un={
  138510. 0,-1, -1, 10,-1,
  138511. {0},
  138512. {-1},
  138513. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138514. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138515. };
  138516. static vorbis_info_mapping0 _map_nominal_u[2]={
  138517. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138518. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138519. };
  138520. static static_bookblock _resbook_44u_n1={
  138521. {
  138522. {0},
  138523. {0,0,&_44un1__p1_0},
  138524. {0,0,&_44un1__p2_0},
  138525. {0,0,&_44un1__p3_0},
  138526. {0,0,&_44un1__p4_0},
  138527. {0,0,&_44un1__p5_0},
  138528. {&_44un1__p6_0,&_44un1__p6_1},
  138529. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138530. }
  138531. };
  138532. static static_bookblock _resbook_44u_0={
  138533. {
  138534. {0},
  138535. {0,0,&_44u0__p1_0},
  138536. {0,0,&_44u0__p2_0},
  138537. {0,0,&_44u0__p3_0},
  138538. {0,0,&_44u0__p4_0},
  138539. {0,0,&_44u0__p5_0},
  138540. {&_44u0__p6_0,&_44u0__p6_1},
  138541. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138542. }
  138543. };
  138544. static static_bookblock _resbook_44u_1={
  138545. {
  138546. {0},
  138547. {0,0,&_44u1__p1_0},
  138548. {0,0,&_44u1__p2_0},
  138549. {0,0,&_44u1__p3_0},
  138550. {0,0,&_44u1__p4_0},
  138551. {0,0,&_44u1__p5_0},
  138552. {&_44u1__p6_0,&_44u1__p6_1},
  138553. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138554. }
  138555. };
  138556. static static_bookblock _resbook_44u_2={
  138557. {
  138558. {0},
  138559. {0,0,&_44u2__p1_0},
  138560. {0,0,&_44u2__p2_0},
  138561. {0,0,&_44u2__p3_0},
  138562. {0,0,&_44u2__p4_0},
  138563. {0,0,&_44u2__p5_0},
  138564. {&_44u2__p6_0,&_44u2__p6_1},
  138565. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138566. }
  138567. };
  138568. static static_bookblock _resbook_44u_3={
  138569. {
  138570. {0},
  138571. {0,0,&_44u3__p1_0},
  138572. {0,0,&_44u3__p2_0},
  138573. {0,0,&_44u3__p3_0},
  138574. {0,0,&_44u3__p4_0},
  138575. {0,0,&_44u3__p5_0},
  138576. {&_44u3__p6_0,&_44u3__p6_1},
  138577. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138578. }
  138579. };
  138580. static static_bookblock _resbook_44u_4={
  138581. {
  138582. {0},
  138583. {0,0,&_44u4__p1_0},
  138584. {0,0,&_44u4__p2_0},
  138585. {0,0,&_44u4__p3_0},
  138586. {0,0,&_44u4__p4_0},
  138587. {0,0,&_44u4__p5_0},
  138588. {&_44u4__p6_0,&_44u4__p6_1},
  138589. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138590. }
  138591. };
  138592. static static_bookblock _resbook_44u_5={
  138593. {
  138594. {0},
  138595. {0,0,&_44u5__p1_0},
  138596. {0,0,&_44u5__p2_0},
  138597. {0,0,&_44u5__p3_0},
  138598. {0,0,&_44u5__p4_0},
  138599. {0,0,&_44u5__p5_0},
  138600. {0,0,&_44u5__p6_0},
  138601. {&_44u5__p7_0,&_44u5__p7_1},
  138602. {&_44u5__p8_0,&_44u5__p8_1},
  138603. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138604. }
  138605. };
  138606. static static_bookblock _resbook_44u_6={
  138607. {
  138608. {0},
  138609. {0,0,&_44u6__p1_0},
  138610. {0,0,&_44u6__p2_0},
  138611. {0,0,&_44u6__p3_0},
  138612. {0,0,&_44u6__p4_0},
  138613. {0,0,&_44u6__p5_0},
  138614. {0,0,&_44u6__p6_0},
  138615. {&_44u6__p7_0,&_44u6__p7_1},
  138616. {&_44u6__p8_0,&_44u6__p8_1},
  138617. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138618. }
  138619. };
  138620. static static_bookblock _resbook_44u_7={
  138621. {
  138622. {0},
  138623. {0,0,&_44u7__p1_0},
  138624. {0,0,&_44u7__p2_0},
  138625. {0,0,&_44u7__p3_0},
  138626. {0,0,&_44u7__p4_0},
  138627. {0,0,&_44u7__p5_0},
  138628. {0,0,&_44u7__p6_0},
  138629. {&_44u7__p7_0,&_44u7__p7_1},
  138630. {&_44u7__p8_0,&_44u7__p8_1},
  138631. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138632. }
  138633. };
  138634. static static_bookblock _resbook_44u_8={
  138635. {
  138636. {0},
  138637. {0,0,&_44u8_p1_0},
  138638. {0,0,&_44u8_p2_0},
  138639. {0,0,&_44u8_p3_0},
  138640. {0,0,&_44u8_p4_0},
  138641. {&_44u8_p5_0,&_44u8_p5_1},
  138642. {&_44u8_p6_0,&_44u8_p6_1},
  138643. {&_44u8_p7_0,&_44u8_p7_1},
  138644. {&_44u8_p8_0,&_44u8_p8_1},
  138645. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138646. }
  138647. };
  138648. static static_bookblock _resbook_44u_9={
  138649. {
  138650. {0},
  138651. {0,0,&_44u9_p1_0},
  138652. {0,0,&_44u9_p2_0},
  138653. {0,0,&_44u9_p3_0},
  138654. {0,0,&_44u9_p4_0},
  138655. {&_44u9_p5_0,&_44u9_p5_1},
  138656. {&_44u9_p6_0,&_44u9_p6_1},
  138657. {&_44u9_p7_0,&_44u9_p7_1},
  138658. {&_44u9_p8_0,&_44u9_p8_1},
  138659. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138660. }
  138661. };
  138662. static vorbis_residue_template _res_44u_n1[]={
  138663. {1,0, &_residue_44_low_un,
  138664. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138665. &_resbook_44u_n1,&_resbook_44u_n1},
  138666. {1,0, &_residue_44_low_un,
  138667. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138668. &_resbook_44u_n1,&_resbook_44u_n1}
  138669. };
  138670. static vorbis_residue_template _res_44u_0[]={
  138671. {1,0, &_residue_44_low_un,
  138672. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138673. &_resbook_44u_0,&_resbook_44u_0},
  138674. {1,0, &_residue_44_low_un,
  138675. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138676. &_resbook_44u_0,&_resbook_44u_0}
  138677. };
  138678. static vorbis_residue_template _res_44u_1[]={
  138679. {1,0, &_residue_44_low_un,
  138680. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138681. &_resbook_44u_1,&_resbook_44u_1},
  138682. {1,0, &_residue_44_low_un,
  138683. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138684. &_resbook_44u_1,&_resbook_44u_1}
  138685. };
  138686. static vorbis_residue_template _res_44u_2[]={
  138687. {1,0, &_residue_44_low_un,
  138688. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138689. &_resbook_44u_2,&_resbook_44u_2},
  138690. {1,0, &_residue_44_low_un,
  138691. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138692. &_resbook_44u_2,&_resbook_44u_2}
  138693. };
  138694. static vorbis_residue_template _res_44u_3[]={
  138695. {1,0, &_residue_44_low_un,
  138696. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138697. &_resbook_44u_3,&_resbook_44u_3},
  138698. {1,0, &_residue_44_low_un,
  138699. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138700. &_resbook_44u_3,&_resbook_44u_3}
  138701. };
  138702. static vorbis_residue_template _res_44u_4[]={
  138703. {1,0, &_residue_44_low_un,
  138704. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138705. &_resbook_44u_4,&_resbook_44u_4},
  138706. {1,0, &_residue_44_low_un,
  138707. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138708. &_resbook_44u_4,&_resbook_44u_4}
  138709. };
  138710. static vorbis_residue_template _res_44u_5[]={
  138711. {1,0, &_residue_44_mid_un,
  138712. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138713. &_resbook_44u_5,&_resbook_44u_5},
  138714. {1,0, &_residue_44_mid_un,
  138715. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138716. &_resbook_44u_5,&_resbook_44u_5}
  138717. };
  138718. static vorbis_residue_template _res_44u_6[]={
  138719. {1,0, &_residue_44_mid_un,
  138720. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138721. &_resbook_44u_6,&_resbook_44u_6},
  138722. {1,0, &_residue_44_mid_un,
  138723. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138724. &_resbook_44u_6,&_resbook_44u_6}
  138725. };
  138726. static vorbis_residue_template _res_44u_7[]={
  138727. {1,0, &_residue_44_mid_un,
  138728. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138729. &_resbook_44u_7,&_resbook_44u_7},
  138730. {1,0, &_residue_44_mid_un,
  138731. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138732. &_resbook_44u_7,&_resbook_44u_7}
  138733. };
  138734. static vorbis_residue_template _res_44u_8[]={
  138735. {1,0, &_residue_44_hi_un,
  138736. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138737. &_resbook_44u_8,&_resbook_44u_8},
  138738. {1,0, &_residue_44_hi_un,
  138739. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138740. &_resbook_44u_8,&_resbook_44u_8}
  138741. };
  138742. static vorbis_residue_template _res_44u_9[]={
  138743. {1,0, &_residue_44_hi_un,
  138744. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138745. &_resbook_44u_9,&_resbook_44u_9},
  138746. {1,0, &_residue_44_hi_un,
  138747. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138748. &_resbook_44u_9,&_resbook_44u_9}
  138749. };
  138750. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138751. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138752. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138753. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138754. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138755. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138756. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138757. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138758. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138759. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138760. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138761. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138762. };
  138763. /*** End of inlined file: residue_44u.h ***/
  138764. static double rate_mapping_44_un[12]={
  138765. 32000.,48000.,60000.,70000.,80000.,86000.,
  138766. 96000.,110000.,120000.,140000.,160000.,240001.
  138767. };
  138768. ve_setup_data_template ve_setup_44_uncoupled={
  138769. 11,
  138770. rate_mapping_44_un,
  138771. quality_mapping_44,
  138772. -1,
  138773. 40000,
  138774. 50000,
  138775. blocksize_short_44,
  138776. blocksize_long_44,
  138777. _psy_tone_masteratt_44,
  138778. _psy_tone_0dB,
  138779. _psy_tone_suppress,
  138780. _vp_tonemask_adj_otherblock,
  138781. _vp_tonemask_adj_longblock,
  138782. _vp_tonemask_adj_otherblock,
  138783. _psy_noiseguards_44,
  138784. _psy_noisebias_impulse,
  138785. _psy_noisebias_padding,
  138786. _psy_noisebias_trans,
  138787. _psy_noisebias_long,
  138788. _psy_noise_suppress,
  138789. _psy_compand_44,
  138790. _psy_compand_short_mapping,
  138791. _psy_compand_long_mapping,
  138792. {_noise_start_short_44,_noise_start_long_44},
  138793. {_noise_part_short_44,_noise_part_long_44},
  138794. _noise_thresh_44,
  138795. _psy_ath_floater,
  138796. _psy_ath_abs,
  138797. _psy_lowpass_44,
  138798. _psy_global_44,
  138799. _global_mapping_44,
  138800. NULL,
  138801. _floor_books,
  138802. _floor,
  138803. _floor_short_mapping_44,
  138804. _floor_long_mapping_44,
  138805. _mapres_template_44_uncoupled
  138806. };
  138807. /*** End of inlined file: setup_44u.h ***/
  138808. /*** Start of inlined file: setup_32.h ***/
  138809. static double rate_mapping_32[12]={
  138810. 18000.,28000.,35000.,45000.,56000.,60000.,
  138811. 75000.,90000.,100000.,115000.,150000.,190000.,
  138812. };
  138813. static double rate_mapping_32_un[12]={
  138814. 30000.,42000.,52000.,64000.,72000.,78000.,
  138815. 86000.,92000.,110000.,120000.,140000.,190000.,
  138816. };
  138817. static double _psy_lowpass_32[12]={
  138818. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138819. };
  138820. ve_setup_data_template ve_setup_32_stereo={
  138821. 11,
  138822. rate_mapping_32,
  138823. quality_mapping_44,
  138824. 2,
  138825. 26000,
  138826. 40000,
  138827. blocksize_short_44,
  138828. blocksize_long_44,
  138829. _psy_tone_masteratt_44,
  138830. _psy_tone_0dB,
  138831. _psy_tone_suppress,
  138832. _vp_tonemask_adj_otherblock,
  138833. _vp_tonemask_adj_longblock,
  138834. _vp_tonemask_adj_otherblock,
  138835. _psy_noiseguards_44,
  138836. _psy_noisebias_impulse,
  138837. _psy_noisebias_padding,
  138838. _psy_noisebias_trans,
  138839. _psy_noisebias_long,
  138840. _psy_noise_suppress,
  138841. _psy_compand_44,
  138842. _psy_compand_short_mapping,
  138843. _psy_compand_long_mapping,
  138844. {_noise_start_short_44,_noise_start_long_44},
  138845. {_noise_part_short_44,_noise_part_long_44},
  138846. _noise_thresh_44,
  138847. _psy_ath_floater,
  138848. _psy_ath_abs,
  138849. _psy_lowpass_32,
  138850. _psy_global_44,
  138851. _global_mapping_44,
  138852. _psy_stereo_modes_44,
  138853. _floor_books,
  138854. _floor,
  138855. _floor_short_mapping_44,
  138856. _floor_long_mapping_44,
  138857. _mapres_template_44_stereo
  138858. };
  138859. ve_setup_data_template ve_setup_32_uncoupled={
  138860. 11,
  138861. rate_mapping_32_un,
  138862. quality_mapping_44,
  138863. -1,
  138864. 26000,
  138865. 40000,
  138866. blocksize_short_44,
  138867. blocksize_long_44,
  138868. _psy_tone_masteratt_44,
  138869. _psy_tone_0dB,
  138870. _psy_tone_suppress,
  138871. _vp_tonemask_adj_otherblock,
  138872. _vp_tonemask_adj_longblock,
  138873. _vp_tonemask_adj_otherblock,
  138874. _psy_noiseguards_44,
  138875. _psy_noisebias_impulse,
  138876. _psy_noisebias_padding,
  138877. _psy_noisebias_trans,
  138878. _psy_noisebias_long,
  138879. _psy_noise_suppress,
  138880. _psy_compand_44,
  138881. _psy_compand_short_mapping,
  138882. _psy_compand_long_mapping,
  138883. {_noise_start_short_44,_noise_start_long_44},
  138884. {_noise_part_short_44,_noise_part_long_44},
  138885. _noise_thresh_44,
  138886. _psy_ath_floater,
  138887. _psy_ath_abs,
  138888. _psy_lowpass_32,
  138889. _psy_global_44,
  138890. _global_mapping_44,
  138891. NULL,
  138892. _floor_books,
  138893. _floor,
  138894. _floor_short_mapping_44,
  138895. _floor_long_mapping_44,
  138896. _mapres_template_44_uncoupled
  138897. };
  138898. /*** End of inlined file: setup_32.h ***/
  138899. /*** Start of inlined file: setup_8.h ***/
  138900. /*** Start of inlined file: psych_8.h ***/
  138901. static att3 _psy_tone_masteratt_8[3]={
  138902. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138903. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138904. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138905. };
  138906. static vp_adjblock _vp_tonemask_adj_8[3]={
  138907. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138908. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138909. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138910. };
  138911. static noise3 _psy_noisebias_8[3]={
  138912. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138913. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138914. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138915. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138916. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  138917. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138918. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  138919. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  138920. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  138921. };
  138922. static adj_stereo _psy_stereo_modes_8[3]={
  138923. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138924. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138925. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138926. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138927. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138928. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138929. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138930. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138931. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138932. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138933. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138934. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138935. };
  138936. static noiseguard _psy_noiseguards_8[2]={
  138937. {10,10,-1},
  138938. {10,10,-1},
  138939. };
  138940. static compandblock _psy_compand_8[2]={
  138941. {{
  138942. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  138943. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  138944. 12,12,13,13,14,14,15, 15, /* 23dB */
  138945. 16,16,17,17,17,18,18, 19, /* 31dB */
  138946. 19,19,20,21,22,23,24, 25, /* 39dB */
  138947. }},
  138948. {{
  138949. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  138950. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  138951. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  138952. 9,10,11,12,13,14,15, 16, /* 31dB */
  138953. 17,18,19,20,21,22,23, 24, /* 39dB */
  138954. }},
  138955. };
  138956. static double _psy_lowpass_8[3]={3.,4.,4.};
  138957. static int _noise_start_8[2]={
  138958. 64,64,
  138959. };
  138960. static int _noise_part_8[2]={
  138961. 8,8,
  138962. };
  138963. static int _psy_ath_floater_8[3]={
  138964. -100,-100,-105,
  138965. };
  138966. static int _psy_ath_abs_8[3]={
  138967. -130,-130,-140,
  138968. };
  138969. /*** End of inlined file: psych_8.h ***/
  138970. /*** Start of inlined file: residue_8.h ***/
  138971. static static_bookblock _resbook_8s_0={
  138972. {
  138973. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  138974. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  138975. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  138976. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  138977. }
  138978. };
  138979. static static_bookblock _resbook_8s_1={
  138980. {
  138981. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  138982. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  138983. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  138984. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  138985. }
  138986. };
  138987. static vorbis_residue_template _res_8s_0[]={
  138988. {2,0, &_residue_44_mid,
  138989. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  138990. &_resbook_8s_0,&_resbook_8s_0},
  138991. };
  138992. static vorbis_residue_template _res_8s_1[]={
  138993. {2,0, &_residue_44_mid,
  138994. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  138995. &_resbook_8s_1,&_resbook_8s_1},
  138996. };
  138997. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  138998. { _map_nominal, _res_8s_0 }, /* 0 */
  138999. { _map_nominal, _res_8s_1 }, /* 1 */
  139000. };
  139001. static static_bookblock _resbook_8u_0={
  139002. {
  139003. {0},
  139004. {0,0,&_8u0__p1_0},
  139005. {0,0,&_8u0__p2_0},
  139006. {0,0,&_8u0__p3_0},
  139007. {0,0,&_8u0__p4_0},
  139008. {0,0,&_8u0__p5_0},
  139009. {&_8u0__p6_0,&_8u0__p6_1},
  139010. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139011. }
  139012. };
  139013. static static_bookblock _resbook_8u_1={
  139014. {
  139015. {0},
  139016. {0,0,&_8u1__p1_0},
  139017. {0,0,&_8u1__p2_0},
  139018. {0,0,&_8u1__p3_0},
  139019. {0,0,&_8u1__p4_0},
  139020. {0,0,&_8u1__p5_0},
  139021. {0,0,&_8u1__p6_0},
  139022. {&_8u1__p7_0,&_8u1__p7_1},
  139023. {&_8u1__p8_0,&_8u1__p8_1},
  139024. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139025. }
  139026. };
  139027. static vorbis_residue_template _res_8u_0[]={
  139028. {1,0, &_residue_44_low_un,
  139029. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139030. &_resbook_8u_0,&_resbook_8u_0},
  139031. };
  139032. static vorbis_residue_template _res_8u_1[]={
  139033. {1,0, &_residue_44_mid_un,
  139034. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139035. &_resbook_8u_1,&_resbook_8u_1},
  139036. };
  139037. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139038. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139039. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139040. };
  139041. /*** End of inlined file: residue_8.h ***/
  139042. static int blocksize_8[2]={
  139043. 512,512
  139044. };
  139045. static int _floor_mapping_8[2]={
  139046. 6,6,
  139047. };
  139048. static double rate_mapping_8[3]={
  139049. 6000.,9000.,32000.,
  139050. };
  139051. static double rate_mapping_8_uncoupled[3]={
  139052. 8000.,14000.,42000.,
  139053. };
  139054. static double quality_mapping_8[3]={
  139055. -.1,.0,1.
  139056. };
  139057. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139058. static double _global_mapping_8[3]={ 1., 2., 3. };
  139059. ve_setup_data_template ve_setup_8_stereo={
  139060. 2,
  139061. rate_mapping_8,
  139062. quality_mapping_8,
  139063. 2,
  139064. 8000,
  139065. 9000,
  139066. blocksize_8,
  139067. blocksize_8,
  139068. _psy_tone_masteratt_8,
  139069. _psy_tone_0dB,
  139070. _psy_tone_suppress,
  139071. _vp_tonemask_adj_8,
  139072. NULL,
  139073. _vp_tonemask_adj_8,
  139074. _psy_noiseguards_8,
  139075. _psy_noisebias_8,
  139076. _psy_noisebias_8,
  139077. NULL,
  139078. NULL,
  139079. _psy_noise_suppress,
  139080. _psy_compand_8,
  139081. _psy_compand_8_mapping,
  139082. NULL,
  139083. {_noise_start_8,_noise_start_8},
  139084. {_noise_part_8,_noise_part_8},
  139085. _noise_thresh_5only,
  139086. _psy_ath_floater_8,
  139087. _psy_ath_abs_8,
  139088. _psy_lowpass_8,
  139089. _psy_global_44,
  139090. _global_mapping_8,
  139091. _psy_stereo_modes_8,
  139092. _floor_books,
  139093. _floor,
  139094. _floor_mapping_8,
  139095. NULL,
  139096. _mapres_template_8_stereo
  139097. };
  139098. ve_setup_data_template ve_setup_8_uncoupled={
  139099. 2,
  139100. rate_mapping_8_uncoupled,
  139101. quality_mapping_8,
  139102. -1,
  139103. 8000,
  139104. 9000,
  139105. blocksize_8,
  139106. blocksize_8,
  139107. _psy_tone_masteratt_8,
  139108. _psy_tone_0dB,
  139109. _psy_tone_suppress,
  139110. _vp_tonemask_adj_8,
  139111. NULL,
  139112. _vp_tonemask_adj_8,
  139113. _psy_noiseguards_8,
  139114. _psy_noisebias_8,
  139115. _psy_noisebias_8,
  139116. NULL,
  139117. NULL,
  139118. _psy_noise_suppress,
  139119. _psy_compand_8,
  139120. _psy_compand_8_mapping,
  139121. NULL,
  139122. {_noise_start_8,_noise_start_8},
  139123. {_noise_part_8,_noise_part_8},
  139124. _noise_thresh_5only,
  139125. _psy_ath_floater_8,
  139126. _psy_ath_abs_8,
  139127. _psy_lowpass_8,
  139128. _psy_global_44,
  139129. _global_mapping_8,
  139130. _psy_stereo_modes_8,
  139131. _floor_books,
  139132. _floor,
  139133. _floor_mapping_8,
  139134. NULL,
  139135. _mapres_template_8_uncoupled
  139136. };
  139137. /*** End of inlined file: setup_8.h ***/
  139138. /*** Start of inlined file: setup_11.h ***/
  139139. /*** Start of inlined file: psych_11.h ***/
  139140. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139141. static att3 _psy_tone_masteratt_11[3]={
  139142. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139143. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139144. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139145. };
  139146. static vp_adjblock _vp_tonemask_adj_11[3]={
  139147. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139148. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139149. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139150. };
  139151. static noise3 _psy_noisebias_11[3]={
  139152. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139153. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139154. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139155. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139156. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139157. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139158. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139159. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139160. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139161. };
  139162. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139163. /*** End of inlined file: psych_11.h ***/
  139164. static int blocksize_11[2]={
  139165. 512,512
  139166. };
  139167. static int _floor_mapping_11[2]={
  139168. 6,6,
  139169. };
  139170. static double rate_mapping_11[3]={
  139171. 8000.,13000.,44000.,
  139172. };
  139173. static double rate_mapping_11_uncoupled[3]={
  139174. 12000.,20000.,50000.,
  139175. };
  139176. static double quality_mapping_11[3]={
  139177. -.1,.0,1.
  139178. };
  139179. ve_setup_data_template ve_setup_11_stereo={
  139180. 2,
  139181. rate_mapping_11,
  139182. quality_mapping_11,
  139183. 2,
  139184. 9000,
  139185. 15000,
  139186. blocksize_11,
  139187. blocksize_11,
  139188. _psy_tone_masteratt_11,
  139189. _psy_tone_0dB,
  139190. _psy_tone_suppress,
  139191. _vp_tonemask_adj_11,
  139192. NULL,
  139193. _vp_tonemask_adj_11,
  139194. _psy_noiseguards_8,
  139195. _psy_noisebias_11,
  139196. _psy_noisebias_11,
  139197. NULL,
  139198. NULL,
  139199. _psy_noise_suppress,
  139200. _psy_compand_8,
  139201. _psy_compand_8_mapping,
  139202. NULL,
  139203. {_noise_start_8,_noise_start_8},
  139204. {_noise_part_8,_noise_part_8},
  139205. _noise_thresh_11,
  139206. _psy_ath_floater_8,
  139207. _psy_ath_abs_8,
  139208. _psy_lowpass_11,
  139209. _psy_global_44,
  139210. _global_mapping_8,
  139211. _psy_stereo_modes_8,
  139212. _floor_books,
  139213. _floor,
  139214. _floor_mapping_11,
  139215. NULL,
  139216. _mapres_template_8_stereo
  139217. };
  139218. ve_setup_data_template ve_setup_11_uncoupled={
  139219. 2,
  139220. rate_mapping_11_uncoupled,
  139221. quality_mapping_11,
  139222. -1,
  139223. 9000,
  139224. 15000,
  139225. blocksize_11,
  139226. blocksize_11,
  139227. _psy_tone_masteratt_11,
  139228. _psy_tone_0dB,
  139229. _psy_tone_suppress,
  139230. _vp_tonemask_adj_11,
  139231. NULL,
  139232. _vp_tonemask_adj_11,
  139233. _psy_noiseguards_8,
  139234. _psy_noisebias_11,
  139235. _psy_noisebias_11,
  139236. NULL,
  139237. NULL,
  139238. _psy_noise_suppress,
  139239. _psy_compand_8,
  139240. _psy_compand_8_mapping,
  139241. NULL,
  139242. {_noise_start_8,_noise_start_8},
  139243. {_noise_part_8,_noise_part_8},
  139244. _noise_thresh_11,
  139245. _psy_ath_floater_8,
  139246. _psy_ath_abs_8,
  139247. _psy_lowpass_11,
  139248. _psy_global_44,
  139249. _global_mapping_8,
  139250. _psy_stereo_modes_8,
  139251. _floor_books,
  139252. _floor,
  139253. _floor_mapping_11,
  139254. NULL,
  139255. _mapres_template_8_uncoupled
  139256. };
  139257. /*** End of inlined file: setup_11.h ***/
  139258. /*** Start of inlined file: setup_16.h ***/
  139259. /*** Start of inlined file: psych_16.h ***/
  139260. static adj_stereo _psy_stereo_modes_16[4]={
  139261. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139262. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139263. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139264. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139265. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139266. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139267. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139268. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139269. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139270. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139271. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139272. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139273. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139274. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139275. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139276. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139277. };
  139278. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139279. static att3 _psy_tone_masteratt_16[4]={
  139280. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139281. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139282. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139283. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139284. };
  139285. static vp_adjblock _vp_tonemask_adj_16[4]={
  139286. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139287. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139288. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139289. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139290. };
  139291. static noise3 _psy_noisebias_16_short[4]={
  139292. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139293. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139294. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139295. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139296. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139297. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139298. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139299. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139300. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139301. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139302. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139303. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139304. };
  139305. static noise3 _psy_noisebias_16_impulse[4]={
  139306. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139307. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139308. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139309. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139310. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139311. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139312. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139313. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139314. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139315. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139316. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139317. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139318. };
  139319. static noise3 _psy_noisebias_16[4]={
  139320. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139321. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139322. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139323. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139324. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139325. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139326. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139327. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139328. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139329. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139330. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139331. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139332. };
  139333. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139334. static int _noise_start_16[3]={ 256,256,9999 };
  139335. static int _noise_part_16[4]={ 8,8,8,8 };
  139336. static int _psy_ath_floater_16[4]={
  139337. -100,-100,-100,-105,
  139338. };
  139339. static int _psy_ath_abs_16[4]={
  139340. -130,-130,-130,-140,
  139341. };
  139342. /*** End of inlined file: psych_16.h ***/
  139343. /*** Start of inlined file: residue_16.h ***/
  139344. static static_bookblock _resbook_16s_0={
  139345. {
  139346. {0},
  139347. {0,0,&_16c0_s_p1_0},
  139348. {0,0,&_16c0_s_p2_0},
  139349. {0,0,&_16c0_s_p3_0},
  139350. {0,0,&_16c0_s_p4_0},
  139351. {0,0,&_16c0_s_p5_0},
  139352. {0,0,&_16c0_s_p6_0},
  139353. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139354. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139355. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139356. }
  139357. };
  139358. static static_bookblock _resbook_16s_1={
  139359. {
  139360. {0},
  139361. {0,0,&_16c1_s_p1_0},
  139362. {0,0,&_16c1_s_p2_0},
  139363. {0,0,&_16c1_s_p3_0},
  139364. {0,0,&_16c1_s_p4_0},
  139365. {0,0,&_16c1_s_p5_0},
  139366. {0,0,&_16c1_s_p6_0},
  139367. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139368. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139369. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139370. }
  139371. };
  139372. static static_bookblock _resbook_16s_2={
  139373. {
  139374. {0},
  139375. {0,0,&_16c2_s_p1_0},
  139376. {0,0,&_16c2_s_p2_0},
  139377. {0,0,&_16c2_s_p3_0},
  139378. {0,0,&_16c2_s_p4_0},
  139379. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139380. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139381. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139382. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139383. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139384. }
  139385. };
  139386. static vorbis_residue_template _res_16s_0[]={
  139387. {2,0, &_residue_44_mid,
  139388. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139389. &_resbook_16s_0,&_resbook_16s_0},
  139390. };
  139391. static vorbis_residue_template _res_16s_1[]={
  139392. {2,0, &_residue_44_mid,
  139393. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139394. &_resbook_16s_1,&_resbook_16s_1},
  139395. {2,0, &_residue_44_mid,
  139396. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139397. &_resbook_16s_1,&_resbook_16s_1}
  139398. };
  139399. static vorbis_residue_template _res_16s_2[]={
  139400. {2,0, &_residue_44_high,
  139401. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139402. &_resbook_16s_2,&_resbook_16s_2},
  139403. {2,0, &_residue_44_high,
  139404. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139405. &_resbook_16s_2,&_resbook_16s_2}
  139406. };
  139407. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139408. { _map_nominal, _res_16s_0 }, /* 0 */
  139409. { _map_nominal, _res_16s_1 }, /* 1 */
  139410. { _map_nominal, _res_16s_2 }, /* 2 */
  139411. };
  139412. static static_bookblock _resbook_16u_0={
  139413. {
  139414. {0},
  139415. {0,0,&_16u0__p1_0},
  139416. {0,0,&_16u0__p2_0},
  139417. {0,0,&_16u0__p3_0},
  139418. {0,0,&_16u0__p4_0},
  139419. {0,0,&_16u0__p5_0},
  139420. {&_16u0__p6_0,&_16u0__p6_1},
  139421. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139422. }
  139423. };
  139424. static static_bookblock _resbook_16u_1={
  139425. {
  139426. {0},
  139427. {0,0,&_16u1__p1_0},
  139428. {0,0,&_16u1__p2_0},
  139429. {0,0,&_16u1__p3_0},
  139430. {0,0,&_16u1__p4_0},
  139431. {0,0,&_16u1__p5_0},
  139432. {0,0,&_16u1__p6_0},
  139433. {&_16u1__p7_0,&_16u1__p7_1},
  139434. {&_16u1__p8_0,&_16u1__p8_1},
  139435. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139436. }
  139437. };
  139438. static static_bookblock _resbook_16u_2={
  139439. {
  139440. {0},
  139441. {0,0,&_16u2_p1_0},
  139442. {0,0,&_16u2_p2_0},
  139443. {0,0,&_16u2_p3_0},
  139444. {0,0,&_16u2_p4_0},
  139445. {&_16u2_p5_0,&_16u2_p5_1},
  139446. {&_16u2_p6_0,&_16u2_p6_1},
  139447. {&_16u2_p7_0,&_16u2_p7_1},
  139448. {&_16u2_p8_0,&_16u2_p8_1},
  139449. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139450. }
  139451. };
  139452. static vorbis_residue_template _res_16u_0[]={
  139453. {1,0, &_residue_44_low_un,
  139454. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139455. &_resbook_16u_0,&_resbook_16u_0},
  139456. };
  139457. static vorbis_residue_template _res_16u_1[]={
  139458. {1,0, &_residue_44_mid_un,
  139459. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139460. &_resbook_16u_1,&_resbook_16u_1},
  139461. {1,0, &_residue_44_mid_un,
  139462. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139463. &_resbook_16u_1,&_resbook_16u_1}
  139464. };
  139465. static vorbis_residue_template _res_16u_2[]={
  139466. {1,0, &_residue_44_hi_un,
  139467. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139468. &_resbook_16u_2,&_resbook_16u_2},
  139469. {1,0, &_residue_44_hi_un,
  139470. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139471. &_resbook_16u_2,&_resbook_16u_2}
  139472. };
  139473. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139474. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139475. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139476. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139477. };
  139478. /*** End of inlined file: residue_16.h ***/
  139479. static int blocksize_16_short[3]={
  139480. 1024,512,512
  139481. };
  139482. static int blocksize_16_long[3]={
  139483. 1024,1024,1024
  139484. };
  139485. static int _floor_mapping_16_short[3]={
  139486. 9,3,3
  139487. };
  139488. static int _floor_mapping_16[3]={
  139489. 9,9,9
  139490. };
  139491. static double rate_mapping_16[4]={
  139492. 12000.,20000.,44000.,86000.
  139493. };
  139494. static double rate_mapping_16_uncoupled[4]={
  139495. 16000.,28000.,64000.,100000.
  139496. };
  139497. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139498. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139499. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139500. ve_setup_data_template ve_setup_16_stereo={
  139501. 3,
  139502. rate_mapping_16,
  139503. quality_mapping_16,
  139504. 2,
  139505. 15000,
  139506. 19000,
  139507. blocksize_16_short,
  139508. blocksize_16_long,
  139509. _psy_tone_masteratt_16,
  139510. _psy_tone_0dB,
  139511. _psy_tone_suppress,
  139512. _vp_tonemask_adj_16,
  139513. _vp_tonemask_adj_16,
  139514. _vp_tonemask_adj_16,
  139515. _psy_noiseguards_8,
  139516. _psy_noisebias_16_impulse,
  139517. _psy_noisebias_16_short,
  139518. _psy_noisebias_16_short,
  139519. _psy_noisebias_16,
  139520. _psy_noise_suppress,
  139521. _psy_compand_8,
  139522. _psy_compand_16_mapping,
  139523. _psy_compand_16_mapping,
  139524. {_noise_start_16,_noise_start_16},
  139525. { _noise_part_16, _noise_part_16},
  139526. _noise_thresh_16,
  139527. _psy_ath_floater_16,
  139528. _psy_ath_abs_16,
  139529. _psy_lowpass_16,
  139530. _psy_global_44,
  139531. _global_mapping_16,
  139532. _psy_stereo_modes_16,
  139533. _floor_books,
  139534. _floor,
  139535. _floor_mapping_16_short,
  139536. _floor_mapping_16,
  139537. _mapres_template_16_stereo
  139538. };
  139539. ve_setup_data_template ve_setup_16_uncoupled={
  139540. 3,
  139541. rate_mapping_16_uncoupled,
  139542. quality_mapping_16,
  139543. -1,
  139544. 15000,
  139545. 19000,
  139546. blocksize_16_short,
  139547. blocksize_16_long,
  139548. _psy_tone_masteratt_16,
  139549. _psy_tone_0dB,
  139550. _psy_tone_suppress,
  139551. _vp_tonemask_adj_16,
  139552. _vp_tonemask_adj_16,
  139553. _vp_tonemask_adj_16,
  139554. _psy_noiseguards_8,
  139555. _psy_noisebias_16_impulse,
  139556. _psy_noisebias_16_short,
  139557. _psy_noisebias_16_short,
  139558. _psy_noisebias_16,
  139559. _psy_noise_suppress,
  139560. _psy_compand_8,
  139561. _psy_compand_16_mapping,
  139562. _psy_compand_16_mapping,
  139563. {_noise_start_16,_noise_start_16},
  139564. { _noise_part_16, _noise_part_16},
  139565. _noise_thresh_16,
  139566. _psy_ath_floater_16,
  139567. _psy_ath_abs_16,
  139568. _psy_lowpass_16,
  139569. _psy_global_44,
  139570. _global_mapping_16,
  139571. _psy_stereo_modes_16,
  139572. _floor_books,
  139573. _floor,
  139574. _floor_mapping_16_short,
  139575. _floor_mapping_16,
  139576. _mapres_template_16_uncoupled
  139577. };
  139578. /*** End of inlined file: setup_16.h ***/
  139579. /*** Start of inlined file: setup_22.h ***/
  139580. static double rate_mapping_22[4]={
  139581. 15000.,20000.,44000.,86000.
  139582. };
  139583. static double rate_mapping_22_uncoupled[4]={
  139584. 16000.,28000.,50000.,90000.
  139585. };
  139586. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139587. ve_setup_data_template ve_setup_22_stereo={
  139588. 3,
  139589. rate_mapping_22,
  139590. quality_mapping_16,
  139591. 2,
  139592. 19000,
  139593. 26000,
  139594. blocksize_16_short,
  139595. blocksize_16_long,
  139596. _psy_tone_masteratt_16,
  139597. _psy_tone_0dB,
  139598. _psy_tone_suppress,
  139599. _vp_tonemask_adj_16,
  139600. _vp_tonemask_adj_16,
  139601. _vp_tonemask_adj_16,
  139602. _psy_noiseguards_8,
  139603. _psy_noisebias_16_impulse,
  139604. _psy_noisebias_16_short,
  139605. _psy_noisebias_16_short,
  139606. _psy_noisebias_16,
  139607. _psy_noise_suppress,
  139608. _psy_compand_8,
  139609. _psy_compand_8_mapping,
  139610. _psy_compand_8_mapping,
  139611. {_noise_start_16,_noise_start_16},
  139612. { _noise_part_16, _noise_part_16},
  139613. _noise_thresh_16,
  139614. _psy_ath_floater_16,
  139615. _psy_ath_abs_16,
  139616. _psy_lowpass_22,
  139617. _psy_global_44,
  139618. _global_mapping_16,
  139619. _psy_stereo_modes_16,
  139620. _floor_books,
  139621. _floor,
  139622. _floor_mapping_16_short,
  139623. _floor_mapping_16,
  139624. _mapres_template_16_stereo
  139625. };
  139626. ve_setup_data_template ve_setup_22_uncoupled={
  139627. 3,
  139628. rate_mapping_22_uncoupled,
  139629. quality_mapping_16,
  139630. -1,
  139631. 19000,
  139632. 26000,
  139633. blocksize_16_short,
  139634. blocksize_16_long,
  139635. _psy_tone_masteratt_16,
  139636. _psy_tone_0dB,
  139637. _psy_tone_suppress,
  139638. _vp_tonemask_adj_16,
  139639. _vp_tonemask_adj_16,
  139640. _vp_tonemask_adj_16,
  139641. _psy_noiseguards_8,
  139642. _psy_noisebias_16_impulse,
  139643. _psy_noisebias_16_short,
  139644. _psy_noisebias_16_short,
  139645. _psy_noisebias_16,
  139646. _psy_noise_suppress,
  139647. _psy_compand_8,
  139648. _psy_compand_8_mapping,
  139649. _psy_compand_8_mapping,
  139650. {_noise_start_16,_noise_start_16},
  139651. { _noise_part_16, _noise_part_16},
  139652. _noise_thresh_16,
  139653. _psy_ath_floater_16,
  139654. _psy_ath_abs_16,
  139655. _psy_lowpass_22,
  139656. _psy_global_44,
  139657. _global_mapping_16,
  139658. _psy_stereo_modes_16,
  139659. _floor_books,
  139660. _floor,
  139661. _floor_mapping_16_short,
  139662. _floor_mapping_16,
  139663. _mapres_template_16_uncoupled
  139664. };
  139665. /*** End of inlined file: setup_22.h ***/
  139666. /*** Start of inlined file: setup_X.h ***/
  139667. static double rate_mapping_X[12]={
  139668. -1.,-1.,-1.,-1.,-1.,-1.,
  139669. -1.,-1.,-1.,-1.,-1.,-1.
  139670. };
  139671. ve_setup_data_template ve_setup_X_stereo={
  139672. 11,
  139673. rate_mapping_X,
  139674. quality_mapping_44,
  139675. 2,
  139676. 50000,
  139677. 200000,
  139678. blocksize_short_44,
  139679. blocksize_long_44,
  139680. _psy_tone_masteratt_44,
  139681. _psy_tone_0dB,
  139682. _psy_tone_suppress,
  139683. _vp_tonemask_adj_otherblock,
  139684. _vp_tonemask_adj_longblock,
  139685. _vp_tonemask_adj_otherblock,
  139686. _psy_noiseguards_44,
  139687. _psy_noisebias_impulse,
  139688. _psy_noisebias_padding,
  139689. _psy_noisebias_trans,
  139690. _psy_noisebias_long,
  139691. _psy_noise_suppress,
  139692. _psy_compand_44,
  139693. _psy_compand_short_mapping,
  139694. _psy_compand_long_mapping,
  139695. {_noise_start_short_44,_noise_start_long_44},
  139696. {_noise_part_short_44,_noise_part_long_44},
  139697. _noise_thresh_44,
  139698. _psy_ath_floater,
  139699. _psy_ath_abs,
  139700. _psy_lowpass_44,
  139701. _psy_global_44,
  139702. _global_mapping_44,
  139703. _psy_stereo_modes_44,
  139704. _floor_books,
  139705. _floor,
  139706. _floor_short_mapping_44,
  139707. _floor_long_mapping_44,
  139708. _mapres_template_44_stereo
  139709. };
  139710. ve_setup_data_template ve_setup_X_uncoupled={
  139711. 11,
  139712. rate_mapping_X,
  139713. quality_mapping_44,
  139714. -1,
  139715. 50000,
  139716. 200000,
  139717. blocksize_short_44,
  139718. blocksize_long_44,
  139719. _psy_tone_masteratt_44,
  139720. _psy_tone_0dB,
  139721. _psy_tone_suppress,
  139722. _vp_tonemask_adj_otherblock,
  139723. _vp_tonemask_adj_longblock,
  139724. _vp_tonemask_adj_otherblock,
  139725. _psy_noiseguards_44,
  139726. _psy_noisebias_impulse,
  139727. _psy_noisebias_padding,
  139728. _psy_noisebias_trans,
  139729. _psy_noisebias_long,
  139730. _psy_noise_suppress,
  139731. _psy_compand_44,
  139732. _psy_compand_short_mapping,
  139733. _psy_compand_long_mapping,
  139734. {_noise_start_short_44,_noise_start_long_44},
  139735. {_noise_part_short_44,_noise_part_long_44},
  139736. _noise_thresh_44,
  139737. _psy_ath_floater,
  139738. _psy_ath_abs,
  139739. _psy_lowpass_44,
  139740. _psy_global_44,
  139741. _global_mapping_44,
  139742. NULL,
  139743. _floor_books,
  139744. _floor,
  139745. _floor_short_mapping_44,
  139746. _floor_long_mapping_44,
  139747. _mapres_template_44_uncoupled
  139748. };
  139749. ve_setup_data_template ve_setup_XX_stereo={
  139750. 2,
  139751. rate_mapping_X,
  139752. quality_mapping_8,
  139753. 2,
  139754. 0,
  139755. 8000,
  139756. blocksize_8,
  139757. blocksize_8,
  139758. _psy_tone_masteratt_8,
  139759. _psy_tone_0dB,
  139760. _psy_tone_suppress,
  139761. _vp_tonemask_adj_8,
  139762. NULL,
  139763. _vp_tonemask_adj_8,
  139764. _psy_noiseguards_8,
  139765. _psy_noisebias_8,
  139766. _psy_noisebias_8,
  139767. NULL,
  139768. NULL,
  139769. _psy_noise_suppress,
  139770. _psy_compand_8,
  139771. _psy_compand_8_mapping,
  139772. NULL,
  139773. {_noise_start_8,_noise_start_8},
  139774. {_noise_part_8,_noise_part_8},
  139775. _noise_thresh_5only,
  139776. _psy_ath_floater_8,
  139777. _psy_ath_abs_8,
  139778. _psy_lowpass_8,
  139779. _psy_global_44,
  139780. _global_mapping_8,
  139781. _psy_stereo_modes_8,
  139782. _floor_books,
  139783. _floor,
  139784. _floor_mapping_8,
  139785. NULL,
  139786. _mapres_template_8_stereo
  139787. };
  139788. ve_setup_data_template ve_setup_XX_uncoupled={
  139789. 2,
  139790. rate_mapping_X,
  139791. quality_mapping_8,
  139792. -1,
  139793. 0,
  139794. 8000,
  139795. blocksize_8,
  139796. blocksize_8,
  139797. _psy_tone_masteratt_8,
  139798. _psy_tone_0dB,
  139799. _psy_tone_suppress,
  139800. _vp_tonemask_adj_8,
  139801. NULL,
  139802. _vp_tonemask_adj_8,
  139803. _psy_noiseguards_8,
  139804. _psy_noisebias_8,
  139805. _psy_noisebias_8,
  139806. NULL,
  139807. NULL,
  139808. _psy_noise_suppress,
  139809. _psy_compand_8,
  139810. _psy_compand_8_mapping,
  139811. NULL,
  139812. {_noise_start_8,_noise_start_8},
  139813. {_noise_part_8,_noise_part_8},
  139814. _noise_thresh_5only,
  139815. _psy_ath_floater_8,
  139816. _psy_ath_abs_8,
  139817. _psy_lowpass_8,
  139818. _psy_global_44,
  139819. _global_mapping_8,
  139820. _psy_stereo_modes_8,
  139821. _floor_books,
  139822. _floor,
  139823. _floor_mapping_8,
  139824. NULL,
  139825. _mapres_template_8_uncoupled
  139826. };
  139827. /*** End of inlined file: setup_X.h ***/
  139828. static ve_setup_data_template *setup_list[]={
  139829. &ve_setup_44_stereo,
  139830. &ve_setup_44_uncoupled,
  139831. &ve_setup_32_stereo,
  139832. &ve_setup_32_uncoupled,
  139833. &ve_setup_22_stereo,
  139834. &ve_setup_22_uncoupled,
  139835. &ve_setup_16_stereo,
  139836. &ve_setup_16_uncoupled,
  139837. &ve_setup_11_stereo,
  139838. &ve_setup_11_uncoupled,
  139839. &ve_setup_8_stereo,
  139840. &ve_setup_8_uncoupled,
  139841. &ve_setup_X_stereo,
  139842. &ve_setup_X_uncoupled,
  139843. &ve_setup_XX_stereo,
  139844. &ve_setup_XX_uncoupled,
  139845. 0
  139846. };
  139847. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139848. if(vi && vi->codec_setup){
  139849. vi->version=0;
  139850. vi->channels=ch;
  139851. vi->rate=rate;
  139852. return(0);
  139853. }
  139854. return(OV_EINVAL);
  139855. }
  139856. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139857. static_codebook ***books,
  139858. vorbis_info_floor1 *in,
  139859. int *x){
  139860. int i,k,is=s;
  139861. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139862. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139863. memcpy(f,in+x[is],sizeof(*f));
  139864. f->n=ci->blocksizes[block]>>1;
  139865. {
  139866. int partitions=f->partitions;
  139867. int maxclass=-1;
  139868. int maxbook=-1;
  139869. for(i=0;i<partitions;i++)
  139870. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139871. for(i=0;i<=maxclass;i++){
  139872. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139873. f->class_book[i]+=ci->books;
  139874. for(k=0;k<(1<<f->class_subs[i]);k++){
  139875. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139876. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139877. }
  139878. }
  139879. for(i=0;i<=maxbook;i++)
  139880. ci->book_param[ci->books++]=books[x[is]][i];
  139881. }
  139882. ci->floor_type[ci->floors]=1;
  139883. ci->floor_param[ci->floors]=f;
  139884. ci->floors++;
  139885. return;
  139886. }
  139887. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139888. vorbis_info_psy_global *in,
  139889. double *x){
  139890. int i,is=s;
  139891. double ds=s-is;
  139892. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139893. vorbis_info_psy_global *g=&ci->psy_g_param;
  139894. memcpy(g,in+(int)x[is],sizeof(*g));
  139895. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139896. is=(int)ds;
  139897. ds-=is;
  139898. if(ds==0 && is>0){
  139899. is--;
  139900. ds=1.;
  139901. }
  139902. for(i=0;i<4;i++){
  139903. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139904. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139905. }
  139906. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139907. return;
  139908. }
  139909. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139910. highlevel_encode_setup *hi,
  139911. adj_stereo *p){
  139912. float s=hi->stereo_point_setting;
  139913. int i,is=s;
  139914. double ds=s-is;
  139915. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139916. vorbis_info_psy_global *g=&ci->psy_g_param;
  139917. if(p){
  139918. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  139919. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  139920. if(hi->managed){
  139921. for(i=0;i<PACKETBLOBS;i++){
  139922. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  139923. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139924. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139925. g->coupling_pkHz[i]=kHz;
  139926. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  139927. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139928. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139929. }
  139930. }else{
  139931. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  139932. for(i=0;i<PACKETBLOBS;i++){
  139933. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139934. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139935. g->coupling_pkHz[i]=kHz;
  139936. }
  139937. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  139938. for(i=0;i<PACKETBLOBS;i++){
  139939. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139940. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139941. }
  139942. }
  139943. }else{
  139944. for(i=0;i<PACKETBLOBS;i++){
  139945. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  139946. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  139947. }
  139948. }
  139949. return;
  139950. }
  139951. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  139952. int *nn_start,
  139953. int *nn_partition,
  139954. double *nn_thresh,
  139955. int block){
  139956. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139957. vorbis_info_psy *p=ci->psy_param[block];
  139958. highlevel_encode_setup *hi=&ci->hi;
  139959. int is=s;
  139960. if(block>=ci->psys)
  139961. ci->psys=block+1;
  139962. if(!p){
  139963. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  139964. ci->psy_param[block]=p;
  139965. }
  139966. memcpy(p,&_psy_info_template,sizeof(*p));
  139967. p->blockflag=block>>1;
  139968. if(hi->noise_normalize_p){
  139969. p->normal_channel_p=1;
  139970. p->normal_point_p=1;
  139971. p->normal_start=nn_start[is];
  139972. p->normal_partition=nn_partition[is];
  139973. p->normal_thresh=nn_thresh[is];
  139974. }
  139975. return;
  139976. }
  139977. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  139978. att3 *att,
  139979. int *max,
  139980. vp_adjblock *in){
  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 *p=ci->psy_param[block];
  139985. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  139986. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  139987. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  139988. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  139989. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  139990. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  139991. for(i=0;i<P_BANDS;i++)
  139992. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  139993. return;
  139994. }
  139995. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  139996. compandblock *in, double *x){
  139997. int i,is=s;
  139998. double ds=s-is;
  139999. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140000. vorbis_info_psy *p=ci->psy_param[block];
  140001. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140002. is=(int)ds;
  140003. ds-=is;
  140004. if(ds==0 && is>0){
  140005. is--;
  140006. ds=1.;
  140007. }
  140008. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140009. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140010. return;
  140011. }
  140012. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140013. int *suppress){
  140014. int is=s;
  140015. double ds=s-is;
  140016. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140017. vorbis_info_psy *p=ci->psy_param[block];
  140018. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140019. return;
  140020. }
  140021. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140022. int *suppress,
  140023. noise3 *in,
  140024. noiseguard *guard,
  140025. double userbias){
  140026. int i,is=s,j;
  140027. double ds=s-is;
  140028. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140029. vorbis_info_psy *p=ci->psy_param[block];
  140030. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140031. p->noisewindowlomin=guard[block].lo;
  140032. p->noisewindowhimin=guard[block].hi;
  140033. p->noisewindowfixed=guard[block].fixed;
  140034. for(j=0;j<P_NOISECURVES;j++)
  140035. for(i=0;i<P_BANDS;i++)
  140036. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140037. for(j=0;j<P_NOISECURVES;j++){
  140038. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140039. for(i=0;i<P_BANDS;i++){
  140040. p->noiseoff[j][i]+=userbias;
  140041. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140042. }
  140043. }
  140044. return;
  140045. }
  140046. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140047. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140048. vorbis_info_psy *p=ci->psy_param[block];
  140049. p->ath_adjatt=ci->hi.ath_floating_dB;
  140050. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140051. return;
  140052. }
  140053. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140054. int i;
  140055. for(i=0;i<ci->books;i++)
  140056. if(ci->book_param[i]==book)return(i);
  140057. return(ci->books++);
  140058. }
  140059. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140060. int *shortb,int *longb){
  140061. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140062. int is=s;
  140063. int blockshort=shortb[is];
  140064. int blocklong=longb[is];
  140065. ci->blocksizes[0]=blockshort;
  140066. ci->blocksizes[1]=blocklong;
  140067. }
  140068. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140069. int number, int block,
  140070. vorbis_residue_template *res){
  140071. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140072. int i,n;
  140073. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140074. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140075. memcpy(r,res->res,sizeof(*r));
  140076. if(ci->residues<=number)ci->residues=number+1;
  140077. switch(ci->blocksizes[block]){
  140078. case 64:case 128:case 256:
  140079. r->grouping=16;
  140080. break;
  140081. default:
  140082. r->grouping=32;
  140083. break;
  140084. }
  140085. ci->residue_type[number]=res->res_type;
  140086. n=r->end=ci->blocksizes[block]>>1;
  140087. if(res->res_type==2)
  140088. n=r->end*=vi->channels;
  140089. {
  140090. int booklist=0,k;
  140091. if(ci->hi.managed){
  140092. for(i=0;i<r->partitions;i++)
  140093. for(k=0;k<3;k++)
  140094. if(res->books_base_managed->books[i][k])
  140095. r->secondstages[i]|=(1<<k);
  140096. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140097. ci->book_param[r->groupbook]=res->book_aux_managed;
  140098. for(i=0;i<r->partitions;i++){
  140099. for(k=0;k<3;k++){
  140100. if(res->books_base_managed->books[i][k]){
  140101. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140102. r->booklist[booklist++]=bookid;
  140103. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140104. }
  140105. }
  140106. }
  140107. }else{
  140108. for(i=0;i<r->partitions;i++)
  140109. for(k=0;k<3;k++)
  140110. if(res->books_base->books[i][k])
  140111. r->secondstages[i]|=(1<<k);
  140112. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140113. ci->book_param[r->groupbook]=res->book_aux;
  140114. for(i=0;i<r->partitions;i++){
  140115. for(k=0;k<3;k++){
  140116. if(res->books_base->books[i][k]){
  140117. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140118. r->booklist[booklist++]=bookid;
  140119. ci->book_param[bookid]=res->books_base->books[i][k];
  140120. }
  140121. }
  140122. }
  140123. }
  140124. }
  140125. {
  140126. double freq=ci->hi.lowpass_kHz*1000.;
  140127. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140128. double nyq=vi->rate/2.;
  140129. long blocksize=ci->blocksizes[block]>>1;
  140130. if(freq>nyq)freq=nyq;
  140131. f->n=freq/nyq*blocksize;
  140132. if(res->limit_type){
  140133. if(ci->hi.managed)
  140134. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140135. else
  140136. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140137. if(freq>nyq)freq=nyq;
  140138. }
  140139. if(ci->residue_type[block]==2)
  140140. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140141. r->grouping;
  140142. else
  140143. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140144. r->grouping;
  140145. }
  140146. }
  140147. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140148. vorbis_mapping_template *maps){
  140149. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140150. int i,j,is=s,modes=2;
  140151. vorbis_info_mapping0 *map=maps[is].map;
  140152. vorbis_info_mode *mode=_mode_template;
  140153. vorbis_residue_template *res=maps[is].res;
  140154. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140155. for(i=0;i<modes;i++){
  140156. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140157. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140158. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140159. if(i>=ci->modes)ci->modes=i+1;
  140160. ci->map_type[i]=0;
  140161. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140162. if(i>=ci->maps)ci->maps=i+1;
  140163. for(j=0;j<map[i].submaps;j++)
  140164. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140165. ,res+map[i].residuesubmap[j]);
  140166. }
  140167. }
  140168. static double setting_to_approx_bitrate(vorbis_info *vi){
  140169. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140170. highlevel_encode_setup *hi=&ci->hi;
  140171. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140172. int is=hi->base_setting;
  140173. double ds=hi->base_setting-is;
  140174. int ch=vi->channels;
  140175. double *r=setup->rate_mapping;
  140176. if(r==NULL)
  140177. return(-1);
  140178. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140179. }
  140180. static void get_setup_template(vorbis_info *vi,
  140181. long ch,long srate,
  140182. double req,int q_or_bitrate){
  140183. int i=0,j;
  140184. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140185. highlevel_encode_setup *hi=&ci->hi;
  140186. if(q_or_bitrate)req/=ch;
  140187. while(setup_list[i]){
  140188. if(setup_list[i]->coupling_restriction==-1 ||
  140189. setup_list[i]->coupling_restriction==ch){
  140190. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140191. srate<=setup_list[i]->samplerate_max_restriction){
  140192. int mappings=setup_list[i]->mappings;
  140193. double *map=(q_or_bitrate?
  140194. setup_list[i]->rate_mapping:
  140195. setup_list[i]->quality_mapping);
  140196. if(req<map[0]){++i;continue;}
  140197. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140198. for(j=0;j<mappings;j++)
  140199. if(req>=map[j] && req<map[j+1])break;
  140200. hi->setup=setup_list[i];
  140201. if(j==mappings)
  140202. hi->base_setting=j-.001;
  140203. else{
  140204. float low=map[j];
  140205. float high=map[j+1];
  140206. float del=(req-low)/(high-low);
  140207. hi->base_setting=j+del;
  140208. }
  140209. return;
  140210. }
  140211. }
  140212. i++;
  140213. }
  140214. hi->setup=NULL;
  140215. }
  140216. int vorbis_encode_setup_init(vorbis_info *vi){
  140217. int i0=0,singleblock=0;
  140218. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140219. ve_setup_data_template *setup=NULL;
  140220. highlevel_encode_setup *hi=&ci->hi;
  140221. if(ci==NULL)return(OV_EINVAL);
  140222. if(!hi->impulse_block_p)i0=1;
  140223. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140224. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140225. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140226. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140227. setup=(ve_setup_data_template *)hi->setup;
  140228. if(setup==NULL)return(OV_EINVAL);
  140229. hi->set_in_stone=1;
  140230. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140231. setup->blocksize_short,
  140232. setup->blocksize_long);
  140233. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140234. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140235. setup->floor_books,
  140236. setup->floor_params,
  140237. setup->floor_short_mapping);
  140238. if(!singleblock)
  140239. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140240. setup->floor_books,
  140241. setup->floor_params,
  140242. setup->floor_long_mapping);
  140243. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140244. setup->global_params,
  140245. setup->global_mapping);
  140246. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140247. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140248. setup->psy_noise_normal_start[0],
  140249. setup->psy_noise_normal_partition[0],
  140250. setup->psy_noise_normal_thresh,
  140251. 0);
  140252. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140253. setup->psy_noise_normal_start[0],
  140254. setup->psy_noise_normal_partition[0],
  140255. setup->psy_noise_normal_thresh,
  140256. 1);
  140257. if(!singleblock){
  140258. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140259. setup->psy_noise_normal_start[1],
  140260. setup->psy_noise_normal_partition[1],
  140261. setup->psy_noise_normal_thresh,
  140262. 2);
  140263. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140264. setup->psy_noise_normal_start[1],
  140265. setup->psy_noise_normal_partition[1],
  140266. setup->psy_noise_normal_thresh,
  140267. 3);
  140268. }
  140269. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140270. setup->psy_tone_masteratt,
  140271. setup->psy_tone_0dB,
  140272. setup->psy_tone_adj_impulse);
  140273. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140274. setup->psy_tone_masteratt,
  140275. setup->psy_tone_0dB,
  140276. setup->psy_tone_adj_other);
  140277. if(!singleblock){
  140278. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140279. setup->psy_tone_masteratt,
  140280. setup->psy_tone_0dB,
  140281. setup->psy_tone_adj_other);
  140282. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140283. setup->psy_tone_masteratt,
  140284. setup->psy_tone_0dB,
  140285. setup->psy_tone_adj_long);
  140286. }
  140287. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140288. setup->psy_noise_compand,
  140289. setup->psy_noise_compand_short_mapping);
  140290. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140291. setup->psy_noise_compand,
  140292. setup->psy_noise_compand_short_mapping);
  140293. if(!singleblock){
  140294. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140295. setup->psy_noise_compand,
  140296. setup->psy_noise_compand_long_mapping);
  140297. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140298. setup->psy_noise_compand,
  140299. setup->psy_noise_compand_long_mapping);
  140300. }
  140301. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140302. setup->psy_tone_dBsuppress);
  140303. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140304. setup->psy_tone_dBsuppress);
  140305. if(!singleblock){
  140306. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140307. setup->psy_tone_dBsuppress);
  140308. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140309. setup->psy_tone_dBsuppress);
  140310. }
  140311. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140312. setup->psy_noise_dBsuppress,
  140313. setup->psy_noise_bias_impulse,
  140314. setup->psy_noiseguards,
  140315. (i0==0?hi->impulse_noisetune:0.));
  140316. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140317. setup->psy_noise_dBsuppress,
  140318. setup->psy_noise_bias_padding,
  140319. setup->psy_noiseguards,0.);
  140320. if(!singleblock){
  140321. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140322. setup->psy_noise_dBsuppress,
  140323. setup->psy_noise_bias_trans,
  140324. setup->psy_noiseguards,0.);
  140325. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140326. setup->psy_noise_dBsuppress,
  140327. setup->psy_noise_bias_long,
  140328. setup->psy_noiseguards,0.);
  140329. }
  140330. vorbis_encode_ath_setup(vi,0);
  140331. vorbis_encode_ath_setup(vi,1);
  140332. if(!singleblock){
  140333. vorbis_encode_ath_setup(vi,2);
  140334. vorbis_encode_ath_setup(vi,3);
  140335. }
  140336. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140337. if(hi->bitrate_av>0)
  140338. vi->bitrate_nominal=hi->bitrate_av;
  140339. else{
  140340. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140341. }
  140342. vi->bitrate_lower=hi->bitrate_min;
  140343. vi->bitrate_upper=hi->bitrate_max;
  140344. if(hi->bitrate_av)
  140345. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140346. else
  140347. vi->bitrate_window=0.;
  140348. if(hi->managed){
  140349. ci->bi.avg_rate=hi->bitrate_av;
  140350. ci->bi.min_rate=hi->bitrate_min;
  140351. ci->bi.max_rate=hi->bitrate_max;
  140352. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140353. ci->bi.reservoir_bias=
  140354. hi->bitrate_reservoir_bias;
  140355. ci->bi.slew_damp=hi->bitrate_av_damp;
  140356. }
  140357. return(0);
  140358. }
  140359. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140360. long channels,
  140361. long rate){
  140362. int ret=0,i,is;
  140363. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140364. highlevel_encode_setup *hi=&ci->hi;
  140365. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140366. double ds;
  140367. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140368. if(ret)return(ret);
  140369. is=hi->base_setting;
  140370. ds=hi->base_setting-is;
  140371. hi->short_setting=hi->base_setting;
  140372. hi->long_setting=hi->base_setting;
  140373. hi->managed=0;
  140374. hi->impulse_block_p=1;
  140375. hi->noise_normalize_p=1;
  140376. hi->stereo_point_setting=hi->base_setting;
  140377. hi->lowpass_kHz=
  140378. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140379. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140380. setup->psy_ath_float[is+1]*ds;
  140381. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140382. setup->psy_ath_abs[is+1]*ds;
  140383. hi->amplitude_track_dBpersec=-6.;
  140384. hi->trigger_setting=hi->base_setting;
  140385. for(i=0;i<4;i++){
  140386. hi->block[i].tone_mask_setting=hi->base_setting;
  140387. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140388. hi->block[i].noise_bias_setting=hi->base_setting;
  140389. hi->block[i].noise_compand_setting=hi->base_setting;
  140390. }
  140391. return(ret);
  140392. }
  140393. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140394. long channels,
  140395. long rate,
  140396. float quality){
  140397. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140398. highlevel_encode_setup *hi=&ci->hi;
  140399. quality+=.0000001;
  140400. if(quality>=1.)quality=.9999;
  140401. get_setup_template(vi,channels,rate,quality,0);
  140402. if(!hi->setup)return OV_EIMPL;
  140403. return vorbis_encode_setup_setting(vi,channels,rate);
  140404. }
  140405. int vorbis_encode_init_vbr(vorbis_info *vi,
  140406. long channels,
  140407. long rate,
  140408. float base_quality /* 0. to 1. */
  140409. ){
  140410. int ret=0;
  140411. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140412. if(ret){
  140413. vorbis_info_clear(vi);
  140414. return ret;
  140415. }
  140416. ret=vorbis_encode_setup_init(vi);
  140417. if(ret)
  140418. vorbis_info_clear(vi);
  140419. return(ret);
  140420. }
  140421. int vorbis_encode_setup_managed(vorbis_info *vi,
  140422. long channels,
  140423. long rate,
  140424. long max_bitrate,
  140425. long nominal_bitrate,
  140426. long min_bitrate){
  140427. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140428. highlevel_encode_setup *hi=&ci->hi;
  140429. double tnominal=nominal_bitrate;
  140430. int ret=0;
  140431. if(nominal_bitrate<=0.){
  140432. if(max_bitrate>0.){
  140433. if(min_bitrate>0.)
  140434. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140435. else
  140436. nominal_bitrate=max_bitrate*.875;
  140437. }else{
  140438. if(min_bitrate>0.){
  140439. nominal_bitrate=min_bitrate;
  140440. }else{
  140441. return(OV_EINVAL);
  140442. }
  140443. }
  140444. }
  140445. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140446. if(!hi->setup)return OV_EIMPL;
  140447. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140448. if(ret){
  140449. vorbis_info_clear(vi);
  140450. return ret;
  140451. }
  140452. hi->managed=1;
  140453. hi->bitrate_min=min_bitrate;
  140454. hi->bitrate_max=max_bitrate;
  140455. hi->bitrate_av=tnominal;
  140456. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140457. hi->bitrate_reservoir=nominal_bitrate*2;
  140458. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140459. return(ret);
  140460. }
  140461. int vorbis_encode_init(vorbis_info *vi,
  140462. long channels,
  140463. long rate,
  140464. long max_bitrate,
  140465. long nominal_bitrate,
  140466. long min_bitrate){
  140467. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140468. max_bitrate,
  140469. nominal_bitrate,
  140470. min_bitrate);
  140471. if(ret){
  140472. vorbis_info_clear(vi);
  140473. return(ret);
  140474. }
  140475. ret=vorbis_encode_setup_init(vi);
  140476. if(ret)
  140477. vorbis_info_clear(vi);
  140478. return(ret);
  140479. }
  140480. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140481. if(vi){
  140482. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140483. highlevel_encode_setup *hi=&ci->hi;
  140484. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140485. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140486. switch(number){
  140487. case OV_ECTL_RATEMANAGE_GET:
  140488. {
  140489. struct ovectl_ratemanage_arg *ai=
  140490. (struct ovectl_ratemanage_arg *)arg;
  140491. ai->management_active=hi->managed;
  140492. ai->bitrate_hard_window=ai->bitrate_av_window=
  140493. (double)hi->bitrate_reservoir/vi->rate;
  140494. ai->bitrate_av_window_center=1.;
  140495. ai->bitrate_hard_min=hi->bitrate_min;
  140496. ai->bitrate_hard_max=hi->bitrate_max;
  140497. ai->bitrate_av_lo=hi->bitrate_av;
  140498. ai->bitrate_av_hi=hi->bitrate_av;
  140499. }
  140500. return(0);
  140501. case OV_ECTL_RATEMANAGE_SET:
  140502. {
  140503. struct ovectl_ratemanage_arg *ai=
  140504. (struct ovectl_ratemanage_arg *)arg;
  140505. if(ai==NULL){
  140506. hi->managed=0;
  140507. }else{
  140508. hi->managed=ai->management_active;
  140509. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140510. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140511. }
  140512. }
  140513. return 0;
  140514. case OV_ECTL_RATEMANAGE_AVG:
  140515. {
  140516. struct ovectl_ratemanage_arg *ai=
  140517. (struct ovectl_ratemanage_arg *)arg;
  140518. if(ai==NULL){
  140519. hi->bitrate_av=0;
  140520. }else{
  140521. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140522. }
  140523. }
  140524. return(0);
  140525. case OV_ECTL_RATEMANAGE_HARD:
  140526. {
  140527. struct ovectl_ratemanage_arg *ai=
  140528. (struct ovectl_ratemanage_arg *)arg;
  140529. if(ai==NULL){
  140530. hi->bitrate_min=0;
  140531. hi->bitrate_max=0;
  140532. }else{
  140533. hi->bitrate_min=ai->bitrate_hard_min;
  140534. hi->bitrate_max=ai->bitrate_hard_max;
  140535. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140536. (hi->bitrate_max+hi->bitrate_min)*.5;
  140537. }
  140538. if(hi->bitrate_reservoir<128.)
  140539. hi->bitrate_reservoir=128.;
  140540. }
  140541. return(0);
  140542. case OV_ECTL_RATEMANAGE2_GET:
  140543. {
  140544. struct ovectl_ratemanage2_arg *ai=
  140545. (struct ovectl_ratemanage2_arg *)arg;
  140546. if(ai==NULL)return OV_EINVAL;
  140547. ai->management_active=hi->managed;
  140548. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140549. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140550. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140551. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140552. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140553. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140554. }
  140555. return (0);
  140556. case OV_ECTL_RATEMANAGE2_SET:
  140557. {
  140558. struct ovectl_ratemanage2_arg *ai=
  140559. (struct ovectl_ratemanage2_arg *)arg;
  140560. if(ai==NULL){
  140561. hi->managed=0;
  140562. }else{
  140563. if(ai->bitrate_limit_min_kbps>0 &&
  140564. ai->bitrate_average_kbps>0 &&
  140565. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140566. return OV_EINVAL;
  140567. if(ai->bitrate_limit_max_kbps>0 &&
  140568. ai->bitrate_average_kbps>0 &&
  140569. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140570. return OV_EINVAL;
  140571. if(ai->bitrate_limit_min_kbps>0 &&
  140572. ai->bitrate_limit_max_kbps>0 &&
  140573. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140574. return OV_EINVAL;
  140575. if(ai->bitrate_average_damping <= 0.)
  140576. return OV_EINVAL;
  140577. if(ai->bitrate_limit_reservoir_bits < 0)
  140578. return OV_EINVAL;
  140579. if(ai->bitrate_limit_reservoir_bias < 0.)
  140580. return OV_EINVAL;
  140581. if(ai->bitrate_limit_reservoir_bias > 1.)
  140582. return OV_EINVAL;
  140583. hi->managed=ai->management_active;
  140584. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140585. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140586. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140587. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140588. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140589. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140590. }
  140591. }
  140592. return 0;
  140593. case OV_ECTL_LOWPASS_GET:
  140594. {
  140595. double *farg=(double *)arg;
  140596. *farg=hi->lowpass_kHz;
  140597. }
  140598. return(0);
  140599. case OV_ECTL_LOWPASS_SET:
  140600. {
  140601. double *farg=(double *)arg;
  140602. hi->lowpass_kHz=*farg;
  140603. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140604. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140605. }
  140606. return(0);
  140607. case OV_ECTL_IBLOCK_GET:
  140608. {
  140609. double *farg=(double *)arg;
  140610. *farg=hi->impulse_noisetune;
  140611. }
  140612. return(0);
  140613. case OV_ECTL_IBLOCK_SET:
  140614. {
  140615. double *farg=(double *)arg;
  140616. hi->impulse_noisetune=*farg;
  140617. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140618. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140619. }
  140620. return(0);
  140621. }
  140622. return(OV_EIMPL);
  140623. }
  140624. return(OV_EINVAL);
  140625. }
  140626. #endif
  140627. /*** End of inlined file: vorbisenc.c ***/
  140628. /*** Start of inlined file: vorbisfile.c ***/
  140629. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140630. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140631. // tasks..
  140632. #if JUCE_MSVC
  140633. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140634. #endif
  140635. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140636. #if JUCE_USE_OGGVORBIS
  140637. #include <stdlib.h>
  140638. #include <stdio.h>
  140639. #include <errno.h>
  140640. #include <string.h>
  140641. #include <math.h>
  140642. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140643. over 8k gets what they deserve */
  140644. static long _get_data(OggVorbis_File *vf){
  140645. errno=0;
  140646. if(vf->datasource){
  140647. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140648. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140649. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140650. if(bytes==0 && errno)return(-1);
  140651. return(bytes);
  140652. }else
  140653. return(0);
  140654. }
  140655. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140656. if(vf->datasource){
  140657. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140658. vf->offset=offset;
  140659. ogg_sync_reset(&vf->oy);
  140660. }else{
  140661. return;
  140662. }
  140663. }
  140664. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140665. ogg_int64_t boundary){
  140666. if(boundary>0)boundary+=vf->offset;
  140667. while(1){
  140668. long more;
  140669. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140670. more=ogg_sync_pageseek(&vf->oy,og);
  140671. if(more<0){
  140672. vf->offset-=more;
  140673. }else{
  140674. if(more==0){
  140675. if(!boundary)return(OV_FALSE);
  140676. {
  140677. long ret=_get_data(vf);
  140678. if(ret==0)return(OV_EOF);
  140679. if(ret<0)return(OV_EREAD);
  140680. }
  140681. }else{
  140682. ogg_int64_t ret=vf->offset;
  140683. vf->offset+=more;
  140684. return(ret);
  140685. }
  140686. }
  140687. }
  140688. }
  140689. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140690. ogg_int64_t begin=vf->offset;
  140691. ogg_int64_t end=begin;
  140692. ogg_int64_t ret;
  140693. ogg_int64_t offset=-1;
  140694. while(offset==-1){
  140695. begin-=CHUNKSIZE;
  140696. if(begin<0)
  140697. begin=0;
  140698. _seek_helper(vf,begin);
  140699. while(vf->offset<end){
  140700. ret=_get_next_page(vf,og,end-vf->offset);
  140701. if(ret==OV_EREAD)return(OV_EREAD);
  140702. if(ret<0){
  140703. break;
  140704. }else{
  140705. offset=ret;
  140706. }
  140707. }
  140708. }
  140709. _seek_helper(vf,offset);
  140710. ret=_get_next_page(vf,og,CHUNKSIZE);
  140711. if(ret<0)
  140712. return(OV_EFAULT);
  140713. return(offset);
  140714. }
  140715. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140716. ogg_int64_t begin,
  140717. ogg_int64_t searched,
  140718. ogg_int64_t end,
  140719. long currentno,
  140720. long m){
  140721. ogg_int64_t endsearched=end;
  140722. ogg_int64_t next=end;
  140723. ogg_page og;
  140724. ogg_int64_t ret;
  140725. while(searched<endsearched){
  140726. ogg_int64_t bisect;
  140727. if(endsearched-searched<CHUNKSIZE){
  140728. bisect=searched;
  140729. }else{
  140730. bisect=(searched+endsearched)/2;
  140731. }
  140732. _seek_helper(vf,bisect);
  140733. ret=_get_next_page(vf,&og,-1);
  140734. if(ret==OV_EREAD)return(OV_EREAD);
  140735. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140736. endsearched=bisect;
  140737. if(ret>=0)next=ret;
  140738. }else{
  140739. searched=ret+og.header_len+og.body_len;
  140740. }
  140741. }
  140742. _seek_helper(vf,next);
  140743. ret=_get_next_page(vf,&og,-1);
  140744. if(ret==OV_EREAD)return(OV_EREAD);
  140745. if(searched>=end || ret<0){
  140746. vf->links=m+1;
  140747. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140748. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140749. vf->offsets[m+1]=searched;
  140750. }else{
  140751. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140752. end,ogg_page_serialno(&og),m+1);
  140753. if(ret==OV_EREAD)return(OV_EREAD);
  140754. }
  140755. vf->offsets[m]=begin;
  140756. vf->serialnos[m]=currentno;
  140757. return(0);
  140758. }
  140759. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140760. long *serialno,ogg_page *og_ptr){
  140761. ogg_page og;
  140762. ogg_packet op;
  140763. int i,ret;
  140764. if(!og_ptr){
  140765. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140766. if(llret==OV_EREAD)return(OV_EREAD);
  140767. if(llret<0)return OV_ENOTVORBIS;
  140768. og_ptr=&og;
  140769. }
  140770. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140771. if(serialno)*serialno=vf->os.serialno;
  140772. vf->ready_state=STREAMSET;
  140773. vorbis_info_init(vi);
  140774. vorbis_comment_init(vc);
  140775. i=0;
  140776. while(i<3){
  140777. ogg_stream_pagein(&vf->os,og_ptr);
  140778. while(i<3){
  140779. int result=ogg_stream_packetout(&vf->os,&op);
  140780. if(result==0)break;
  140781. if(result==-1){
  140782. ret=OV_EBADHEADER;
  140783. goto bail_header;
  140784. }
  140785. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140786. goto bail_header;
  140787. }
  140788. i++;
  140789. }
  140790. if(i<3)
  140791. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140792. ret=OV_EBADHEADER;
  140793. goto bail_header;
  140794. }
  140795. }
  140796. return 0;
  140797. bail_header:
  140798. vorbis_info_clear(vi);
  140799. vorbis_comment_clear(vc);
  140800. vf->ready_state=OPENED;
  140801. return ret;
  140802. }
  140803. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140804. ogg_page og;
  140805. int i;
  140806. ogg_int64_t ret;
  140807. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140808. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140809. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140810. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140811. for(i=0;i<vf->links;i++){
  140812. if(i==0){
  140813. vf->dataoffsets[i]=dataoffset;
  140814. _seek_helper(vf,dataoffset);
  140815. }else{
  140816. _seek_helper(vf,vf->offsets[i]);
  140817. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140818. vf->dataoffsets[i]=-1;
  140819. }else{
  140820. vf->dataoffsets[i]=vf->offset;
  140821. }
  140822. }
  140823. if(vf->dataoffsets[i]!=-1){
  140824. ogg_int64_t accumulated=0;
  140825. long lastblock=-1;
  140826. int result;
  140827. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140828. while(1){
  140829. ogg_packet op;
  140830. ret=_get_next_page(vf,&og,-1);
  140831. if(ret<0)
  140832. break;
  140833. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140834. break;
  140835. ogg_stream_pagein(&vf->os,&og);
  140836. while((result=ogg_stream_packetout(&vf->os,&op))){
  140837. if(result>0){ /* ignore holes */
  140838. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140839. if(lastblock!=-1)
  140840. accumulated+=(lastblock+thisblock)>>2;
  140841. lastblock=thisblock;
  140842. }
  140843. }
  140844. if(ogg_page_granulepos(&og)!=-1){
  140845. accumulated= ogg_page_granulepos(&og)-accumulated;
  140846. break;
  140847. }
  140848. }
  140849. if(accumulated<0)accumulated=0;
  140850. vf->pcmlengths[i*2]=accumulated;
  140851. }
  140852. {
  140853. ogg_int64_t end=vf->offsets[i+1];
  140854. _seek_helper(vf,end);
  140855. while(1){
  140856. ret=_get_prev_page(vf,&og);
  140857. if(ret<0){
  140858. vorbis_info_clear(vf->vi+i);
  140859. vorbis_comment_clear(vf->vc+i);
  140860. break;
  140861. }
  140862. if(ogg_page_granulepos(&og)!=-1){
  140863. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140864. break;
  140865. }
  140866. vf->offset=ret;
  140867. }
  140868. }
  140869. }
  140870. }
  140871. static int _make_decode_ready(OggVorbis_File *vf){
  140872. if(vf->ready_state>STREAMSET)return 0;
  140873. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140874. if(vf->seekable){
  140875. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140876. return OV_EBADLINK;
  140877. }else{
  140878. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140879. return OV_EBADLINK;
  140880. }
  140881. vorbis_block_init(&vf->vd,&vf->vb);
  140882. vf->ready_state=INITSET;
  140883. vf->bittrack=0.f;
  140884. vf->samptrack=0.f;
  140885. return 0;
  140886. }
  140887. static int _open_seekable2(OggVorbis_File *vf){
  140888. long serialno=vf->current_serialno;
  140889. ogg_int64_t dataoffset=vf->offset, end;
  140890. ogg_page og;
  140891. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140892. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140893. end=_get_prev_page(vf,&og);
  140894. if(end<0)return(end);
  140895. if(ogg_page_serialno(&og)!=serialno){
  140896. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140897. }else{
  140898. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140899. }
  140900. _prefetch_all_headers(vf,dataoffset);
  140901. return(ov_raw_seek(vf,0));
  140902. }
  140903. static void _decode_clear(OggVorbis_File *vf){
  140904. vorbis_dsp_clear(&vf->vd);
  140905. vorbis_block_clear(&vf->vb);
  140906. vf->ready_state=OPENED;
  140907. }
  140908. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140909. ogg_packet *op_in,
  140910. int readp,
  140911. int spanp){
  140912. ogg_page og;
  140913. while(1){
  140914. if(vf->ready_state==INITSET){
  140915. while(1) {
  140916. ogg_packet op;
  140917. ogg_packet *op_ptr=(op_in?op_in:&op);
  140918. int result=ogg_stream_packetout(&vf->os,op_ptr);
  140919. ogg_int64_t granulepos;
  140920. op_in=NULL;
  140921. if(result==-1)return(OV_HOLE); /* hole in the data. */
  140922. if(result>0){
  140923. granulepos=op_ptr->granulepos;
  140924. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  140925. header handling. The
  140926. header packets aren't
  140927. audio, so if/when we
  140928. submit them,
  140929. vorbis_synthesis will
  140930. reject them */
  140931. {
  140932. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140933. if(oldsamples)return(OV_EFAULT);
  140934. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  140935. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  140936. vf->bittrack+=op_ptr->bytes*8;
  140937. }
  140938. if(granulepos!=-1 && !op_ptr->e_o_s){
  140939. int link=(vf->seekable?vf->current_link:0);
  140940. int i,samples;
  140941. if(vf->seekable && link>0)
  140942. granulepos-=vf->pcmlengths[link*2];
  140943. if(granulepos<0)granulepos=0; /* actually, this
  140944. shouldn't be possible
  140945. here unless the stream
  140946. is very broken */
  140947. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140948. granulepos-=samples;
  140949. for(i=0;i<link;i++)
  140950. granulepos+=vf->pcmlengths[i*2+1];
  140951. vf->pcm_offset=granulepos;
  140952. }
  140953. return(1);
  140954. }
  140955. }
  140956. else
  140957. break;
  140958. }
  140959. }
  140960. if(vf->ready_state>=OPENED){
  140961. ogg_int64_t ret;
  140962. if(!readp)return(0);
  140963. if((ret=_get_next_page(vf,&og,-1))<0){
  140964. return(OV_EOF); /* eof.
  140965. leave unitialized */
  140966. }
  140967. vf->bittrack+=og.header_len*8;
  140968. if(vf->ready_state==INITSET){
  140969. if(vf->current_serialno!=ogg_page_serialno(&og)){
  140970. if(!spanp)
  140971. return(OV_EOF);
  140972. _decode_clear(vf);
  140973. if(!vf->seekable){
  140974. vorbis_info_clear(vf->vi);
  140975. vorbis_comment_clear(vf->vc);
  140976. }
  140977. }
  140978. }
  140979. }
  140980. if(vf->ready_state!=INITSET){
  140981. int link;
  140982. if(vf->ready_state<STREAMSET){
  140983. if(vf->seekable){
  140984. vf->current_serialno=ogg_page_serialno(&og);
  140985. for(link=0;link<vf->links;link++)
  140986. if(vf->serialnos[link]==vf->current_serialno)break;
  140987. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  140988. stream. error out,
  140989. leave machine
  140990. uninitialized */
  140991. vf->current_link=link;
  140992. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  140993. vf->ready_state=STREAMSET;
  140994. }else{
  140995. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  140996. if(ret)return(ret);
  140997. vf->current_link++;
  140998. link=0;
  140999. }
  141000. }
  141001. {
  141002. int ret=_make_decode_ready(vf);
  141003. if(ret<0)return ret;
  141004. }
  141005. }
  141006. ogg_stream_pagein(&vf->os,&og);
  141007. }
  141008. }
  141009. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141010. if(f==NULL)return(-1);
  141011. return fseek(f,off,whence);
  141012. }
  141013. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141014. long ibytes, ov_callbacks callbacks){
  141015. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141016. int ret;
  141017. memset(vf,0,sizeof(*vf));
  141018. vf->datasource=f;
  141019. vf->callbacks = callbacks;
  141020. ogg_sync_init(&vf->oy);
  141021. if(initial){
  141022. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141023. memcpy(buffer,initial,ibytes);
  141024. ogg_sync_wrote(&vf->oy,ibytes);
  141025. }
  141026. if(offsettest!=-1)vf->seekable=1;
  141027. vf->links=1;
  141028. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141029. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141030. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141031. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141032. vf->datasource=NULL;
  141033. ov_clear(vf);
  141034. }else
  141035. vf->ready_state=PARTOPEN;
  141036. return(ret);
  141037. }
  141038. static int _ov_open2(OggVorbis_File *vf){
  141039. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141040. vf->ready_state=OPENED;
  141041. if(vf->seekable){
  141042. int ret=_open_seekable2(vf);
  141043. if(ret){
  141044. vf->datasource=NULL;
  141045. ov_clear(vf);
  141046. }
  141047. return(ret);
  141048. }else
  141049. vf->ready_state=STREAMSET;
  141050. return 0;
  141051. }
  141052. int ov_clear(OggVorbis_File *vf){
  141053. if(vf){
  141054. vorbis_block_clear(&vf->vb);
  141055. vorbis_dsp_clear(&vf->vd);
  141056. ogg_stream_clear(&vf->os);
  141057. if(vf->vi && vf->links){
  141058. int i;
  141059. for(i=0;i<vf->links;i++){
  141060. vorbis_info_clear(vf->vi+i);
  141061. vorbis_comment_clear(vf->vc+i);
  141062. }
  141063. _ogg_free(vf->vi);
  141064. _ogg_free(vf->vc);
  141065. }
  141066. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141067. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141068. if(vf->serialnos)_ogg_free(vf->serialnos);
  141069. if(vf->offsets)_ogg_free(vf->offsets);
  141070. ogg_sync_clear(&vf->oy);
  141071. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141072. memset(vf,0,sizeof(*vf));
  141073. }
  141074. #ifdef DEBUG_LEAKS
  141075. _VDBG_dump();
  141076. #endif
  141077. return(0);
  141078. }
  141079. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141080. ov_callbacks callbacks){
  141081. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141082. if(ret)return ret;
  141083. return _ov_open2(vf);
  141084. }
  141085. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141086. ov_callbacks callbacks = {
  141087. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141088. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141089. (int (*)(void *)) fclose,
  141090. (long (*)(void *)) ftell
  141091. };
  141092. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141093. }
  141094. int ov_halfrate(OggVorbis_File *vf,int flag){
  141095. int i;
  141096. if(vf->vi==NULL)return OV_EINVAL;
  141097. if(!vf->seekable)return OV_EINVAL;
  141098. if(vf->ready_state>=STREAMSET)
  141099. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141100. will be able to swap this on the fly, but
  141101. for now dumping the decode machine is needed
  141102. to reinit the MDCT lookups. 1.1 libvorbis
  141103. is planned to be able to switch on the fly */
  141104. for(i=0;i<vf->links;i++){
  141105. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141106. ov_halfrate(vf,0);
  141107. return OV_EINVAL;
  141108. }
  141109. }
  141110. return 0;
  141111. }
  141112. int ov_halfrate_p(OggVorbis_File *vf){
  141113. if(vf->vi==NULL)return OV_EINVAL;
  141114. return vorbis_synthesis_halfrate_p(vf->vi);
  141115. }
  141116. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141117. ov_callbacks callbacks)
  141118. {
  141119. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141120. }
  141121. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141122. ov_callbacks callbacks = {
  141123. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141124. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141125. (int (*)(void *)) fclose,
  141126. (long (*)(void *)) ftell
  141127. };
  141128. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141129. }
  141130. int ov_test_open(OggVorbis_File *vf){
  141131. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141132. return _ov_open2(vf);
  141133. }
  141134. long ov_streams(OggVorbis_File *vf){
  141135. return vf->links;
  141136. }
  141137. long ov_seekable(OggVorbis_File *vf){
  141138. return vf->seekable;
  141139. }
  141140. long ov_bitrate(OggVorbis_File *vf,int i){
  141141. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141142. if(i>=vf->links)return(OV_EINVAL);
  141143. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141144. if(i<0){
  141145. ogg_int64_t bits=0;
  141146. int i;
  141147. float br;
  141148. for(i=0;i<vf->links;i++)
  141149. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141150. br = bits/ov_time_total(vf,-1);
  141151. return(rint(br));
  141152. }else{
  141153. if(vf->seekable){
  141154. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141155. }else{
  141156. if(vf->vi[i].bitrate_nominal>0){
  141157. return vf->vi[i].bitrate_nominal;
  141158. }else{
  141159. if(vf->vi[i].bitrate_upper>0){
  141160. if(vf->vi[i].bitrate_lower>0){
  141161. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141162. }else{
  141163. return vf->vi[i].bitrate_upper;
  141164. }
  141165. }
  141166. return(OV_FALSE);
  141167. }
  141168. }
  141169. }
  141170. }
  141171. long ov_bitrate_instant(OggVorbis_File *vf){
  141172. int link=(vf->seekable?vf->current_link:0);
  141173. long ret;
  141174. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141175. if(vf->samptrack==0)return(OV_FALSE);
  141176. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141177. vf->bittrack=0.f;
  141178. vf->samptrack=0.f;
  141179. return(ret);
  141180. }
  141181. long ov_serialnumber(OggVorbis_File *vf,int i){
  141182. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141183. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141184. if(i<0){
  141185. return(vf->current_serialno);
  141186. }else{
  141187. return(vf->serialnos[i]);
  141188. }
  141189. }
  141190. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141191. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141192. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141193. if(i<0){
  141194. ogg_int64_t acc=0;
  141195. int i;
  141196. for(i=0;i<vf->links;i++)
  141197. acc+=ov_raw_total(vf,i);
  141198. return(acc);
  141199. }else{
  141200. return(vf->offsets[i+1]-vf->offsets[i]);
  141201. }
  141202. }
  141203. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141204. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141205. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141206. if(i<0){
  141207. ogg_int64_t acc=0;
  141208. int i;
  141209. for(i=0;i<vf->links;i++)
  141210. acc+=ov_pcm_total(vf,i);
  141211. return(acc);
  141212. }else{
  141213. return(vf->pcmlengths[i*2+1]);
  141214. }
  141215. }
  141216. double ov_time_total(OggVorbis_File *vf,int i){
  141217. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141218. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141219. if(i<0){
  141220. double acc=0;
  141221. int i;
  141222. for(i=0;i<vf->links;i++)
  141223. acc+=ov_time_total(vf,i);
  141224. return(acc);
  141225. }else{
  141226. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141227. }
  141228. }
  141229. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141230. ogg_stream_state work_os;
  141231. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141232. if(!vf->seekable)
  141233. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141234. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141235. vf->pcm_offset=-1;
  141236. ogg_stream_reset_serialno(&vf->os,
  141237. vf->current_serialno); /* must set serialno */
  141238. vorbis_synthesis_restart(&vf->vd);
  141239. _seek_helper(vf,pos);
  141240. {
  141241. ogg_page og;
  141242. ogg_packet op;
  141243. int lastblock=0;
  141244. int accblock=0;
  141245. int thisblock;
  141246. int eosflag;
  141247. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141248. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141249. return from not necessarily
  141250. starting from the beginning */
  141251. while(1){
  141252. if(vf->ready_state>=STREAMSET){
  141253. int result=ogg_stream_packetout(&work_os,&op);
  141254. if(result>0){
  141255. if(vf->vi[vf->current_link].codec_setup){
  141256. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141257. if(thisblock<0){
  141258. ogg_stream_packetout(&vf->os,NULL);
  141259. thisblock=0;
  141260. }else{
  141261. if(eosflag)
  141262. ogg_stream_packetout(&vf->os,NULL);
  141263. else
  141264. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141265. }
  141266. if(op.granulepos!=-1){
  141267. int i,link=vf->current_link;
  141268. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141269. if(granulepos<0)granulepos=0;
  141270. for(i=0;i<link;i++)
  141271. granulepos+=vf->pcmlengths[i*2+1];
  141272. vf->pcm_offset=granulepos-accblock;
  141273. break;
  141274. }
  141275. lastblock=thisblock;
  141276. continue;
  141277. }else
  141278. ogg_stream_packetout(&vf->os,NULL);
  141279. }
  141280. }
  141281. if(!lastblock){
  141282. if(_get_next_page(vf,&og,-1)<0){
  141283. vf->pcm_offset=ov_pcm_total(vf,-1);
  141284. break;
  141285. }
  141286. }else{
  141287. vf->pcm_offset=-1;
  141288. break;
  141289. }
  141290. if(vf->ready_state>=STREAMSET)
  141291. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141292. _decode_clear(vf); /* clear out stream state */
  141293. ogg_stream_clear(&work_os);
  141294. }
  141295. if(vf->ready_state<STREAMSET){
  141296. int link;
  141297. vf->current_serialno=ogg_page_serialno(&og);
  141298. for(link=0;link<vf->links;link++)
  141299. if(vf->serialnos[link]==vf->current_serialno)break;
  141300. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141301. error out, leave
  141302. machine uninitialized */
  141303. vf->current_link=link;
  141304. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141305. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141306. vf->ready_state=STREAMSET;
  141307. }
  141308. ogg_stream_pagein(&vf->os,&og);
  141309. ogg_stream_pagein(&work_os,&og);
  141310. eosflag=ogg_page_eos(&og);
  141311. }
  141312. }
  141313. ogg_stream_clear(&work_os);
  141314. vf->bittrack=0.f;
  141315. vf->samptrack=0.f;
  141316. return(0);
  141317. seek_error:
  141318. vf->pcm_offset=-1;
  141319. ogg_stream_clear(&work_os);
  141320. _decode_clear(vf);
  141321. return OV_EBADLINK;
  141322. }
  141323. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141324. int link=-1;
  141325. ogg_int64_t result=0;
  141326. ogg_int64_t total=ov_pcm_total(vf,-1);
  141327. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141328. if(!vf->seekable)return(OV_ENOSEEK);
  141329. if(pos<0 || pos>total)return(OV_EINVAL);
  141330. for(link=vf->links-1;link>=0;link--){
  141331. total-=vf->pcmlengths[link*2+1];
  141332. if(pos>=total)break;
  141333. }
  141334. {
  141335. ogg_int64_t end=vf->offsets[link+1];
  141336. ogg_int64_t begin=vf->offsets[link];
  141337. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141338. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141339. ogg_int64_t target=pos-total+begintime;
  141340. ogg_int64_t best=begin;
  141341. ogg_page og;
  141342. while(begin<end){
  141343. ogg_int64_t bisect;
  141344. if(end-begin<CHUNKSIZE){
  141345. bisect=begin;
  141346. }else{
  141347. bisect=begin +
  141348. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141349. if(bisect<=begin)
  141350. bisect=begin+1;
  141351. }
  141352. _seek_helper(vf,bisect);
  141353. while(begin<end){
  141354. result=_get_next_page(vf,&og,end-vf->offset);
  141355. if(result==OV_EREAD) goto seek_error;
  141356. if(result<0){
  141357. if(bisect<=begin+1)
  141358. end=begin; /* found it */
  141359. else{
  141360. if(bisect==0) goto seek_error;
  141361. bisect-=CHUNKSIZE;
  141362. if(bisect<=begin)bisect=begin+1;
  141363. _seek_helper(vf,bisect);
  141364. }
  141365. }else{
  141366. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141367. if(granulepos==-1)continue;
  141368. if(granulepos<target){
  141369. best=result; /* raw offset of packet with granulepos */
  141370. begin=vf->offset; /* raw offset of next page */
  141371. begintime=granulepos;
  141372. if(target-begintime>44100)break;
  141373. bisect=begin; /* *not* begin + 1 */
  141374. }else{
  141375. if(bisect<=begin+1)
  141376. end=begin; /* found it */
  141377. else{
  141378. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141379. end=result;
  141380. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141381. if(bisect<=begin)bisect=begin+1;
  141382. _seek_helper(vf,bisect);
  141383. }else{
  141384. end=result;
  141385. endtime=granulepos;
  141386. break;
  141387. }
  141388. }
  141389. }
  141390. }
  141391. }
  141392. }
  141393. {
  141394. ogg_page og;
  141395. ogg_packet op;
  141396. _seek_helper(vf,best);
  141397. vf->pcm_offset=-1;
  141398. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141399. if(link!=vf->current_link){
  141400. _decode_clear(vf);
  141401. vf->current_link=link;
  141402. vf->current_serialno=ogg_page_serialno(&og);
  141403. vf->ready_state=STREAMSET;
  141404. }else{
  141405. vorbis_synthesis_restart(&vf->vd);
  141406. }
  141407. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141408. ogg_stream_pagein(&vf->os,&og);
  141409. while(1){
  141410. result=ogg_stream_packetpeek(&vf->os,&op);
  141411. if(result==0){
  141412. _seek_helper(vf,best);
  141413. while(1){
  141414. result=_get_prev_page(vf,&og);
  141415. if(result<0) goto seek_error;
  141416. if(ogg_page_granulepos(&og)>-1 ||
  141417. !ogg_page_continued(&og)){
  141418. return ov_raw_seek(vf,result);
  141419. }
  141420. vf->offset=result;
  141421. }
  141422. }
  141423. if(result<0){
  141424. result = OV_EBADPACKET;
  141425. goto seek_error;
  141426. }
  141427. if(op.granulepos!=-1){
  141428. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141429. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141430. vf->pcm_offset+=total;
  141431. break;
  141432. }else
  141433. result=ogg_stream_packetout(&vf->os,NULL);
  141434. }
  141435. }
  141436. }
  141437. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141438. result=OV_EFAULT;
  141439. goto seek_error;
  141440. }
  141441. vf->bittrack=0.f;
  141442. vf->samptrack=0.f;
  141443. return(0);
  141444. seek_error:
  141445. vf->pcm_offset=-1;
  141446. _decode_clear(vf);
  141447. return (int)result;
  141448. }
  141449. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141450. int thisblock,lastblock=0;
  141451. int ret=ov_pcm_seek_page(vf,pos);
  141452. if(ret<0)return(ret);
  141453. if((ret=_make_decode_ready(vf)))return ret;
  141454. while(1){
  141455. ogg_packet op;
  141456. ogg_page og;
  141457. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141458. if(ret>0){
  141459. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141460. if(thisblock<0){
  141461. ogg_stream_packetout(&vf->os,NULL);
  141462. continue; /* non audio packet */
  141463. }
  141464. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141465. if(vf->pcm_offset+((thisblock+
  141466. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141467. ogg_stream_packetout(&vf->os,NULL);
  141468. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141469. only tracking, no
  141470. pcm_decode */
  141471. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141472. if(op.granulepos>-1){
  141473. int i;
  141474. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141475. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141476. for(i=0;i<vf->current_link;i++)
  141477. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141478. }
  141479. lastblock=thisblock;
  141480. }else{
  141481. if(ret<0 && ret!=OV_HOLE)break;
  141482. if(_get_next_page(vf,&og,-1)<0)break;
  141483. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141484. if(vf->ready_state<STREAMSET){
  141485. int link;
  141486. vf->current_serialno=ogg_page_serialno(&og);
  141487. for(link=0;link<vf->links;link++)
  141488. if(vf->serialnos[link]==vf->current_serialno)break;
  141489. if(link==vf->links)return(OV_EBADLINK);
  141490. vf->current_link=link;
  141491. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141492. vf->ready_state=STREAMSET;
  141493. ret=_make_decode_ready(vf);
  141494. if(ret)return ret;
  141495. lastblock=0;
  141496. }
  141497. ogg_stream_pagein(&vf->os,&og);
  141498. }
  141499. }
  141500. vf->bittrack=0.f;
  141501. vf->samptrack=0.f;
  141502. while(vf->pcm_offset<pos){
  141503. ogg_int64_t target=pos-vf->pcm_offset;
  141504. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141505. if(samples>target)samples=target;
  141506. vorbis_synthesis_read(&vf->vd,samples);
  141507. vf->pcm_offset+=samples;
  141508. if(samples<target)
  141509. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141510. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141511. }
  141512. return 0;
  141513. }
  141514. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141515. int link=-1;
  141516. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141517. double time_total=ov_time_total(vf,-1);
  141518. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141519. if(!vf->seekable)return(OV_ENOSEEK);
  141520. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141521. for(link=vf->links-1;link>=0;link--){
  141522. pcm_total-=vf->pcmlengths[link*2+1];
  141523. time_total-=ov_time_total(vf,link);
  141524. if(seconds>=time_total)break;
  141525. }
  141526. {
  141527. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141528. return(ov_pcm_seek(vf,target));
  141529. }
  141530. }
  141531. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141532. int link=-1;
  141533. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141534. double time_total=ov_time_total(vf,-1);
  141535. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141536. if(!vf->seekable)return(OV_ENOSEEK);
  141537. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141538. for(link=vf->links-1;link>=0;link--){
  141539. pcm_total-=vf->pcmlengths[link*2+1];
  141540. time_total-=ov_time_total(vf,link);
  141541. if(seconds>=time_total)break;
  141542. }
  141543. {
  141544. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141545. return(ov_pcm_seek_page(vf,target));
  141546. }
  141547. }
  141548. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141549. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141550. return(vf->offset);
  141551. }
  141552. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141553. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141554. return(vf->pcm_offset);
  141555. }
  141556. double ov_time_tell(OggVorbis_File *vf){
  141557. int link=0;
  141558. ogg_int64_t pcm_total=0;
  141559. double time_total=0.f;
  141560. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141561. if(vf->seekable){
  141562. pcm_total=ov_pcm_total(vf,-1);
  141563. time_total=ov_time_total(vf,-1);
  141564. for(link=vf->links-1;link>=0;link--){
  141565. pcm_total-=vf->pcmlengths[link*2+1];
  141566. time_total-=ov_time_total(vf,link);
  141567. if(vf->pcm_offset>=pcm_total)break;
  141568. }
  141569. }
  141570. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141571. }
  141572. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141573. if(vf->seekable){
  141574. if(link<0)
  141575. if(vf->ready_state>=STREAMSET)
  141576. return vf->vi+vf->current_link;
  141577. else
  141578. return vf->vi;
  141579. else
  141580. if(link>=vf->links)
  141581. return NULL;
  141582. else
  141583. return vf->vi+link;
  141584. }else{
  141585. return vf->vi;
  141586. }
  141587. }
  141588. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141589. if(vf->seekable){
  141590. if(link<0)
  141591. if(vf->ready_state>=STREAMSET)
  141592. return vf->vc+vf->current_link;
  141593. else
  141594. return vf->vc;
  141595. else
  141596. if(link>=vf->links)
  141597. return NULL;
  141598. else
  141599. return vf->vc+link;
  141600. }else{
  141601. return vf->vc;
  141602. }
  141603. }
  141604. static int host_is_big_endian() {
  141605. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141606. unsigned char *bytewise = (unsigned char *)&pattern;
  141607. if (bytewise[0] == 0xfe) return 1;
  141608. return 0;
  141609. }
  141610. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141611. int bigendianp,int word,int sgned,int *bitstream){
  141612. int i,j;
  141613. int host_endian = host_is_big_endian();
  141614. float **pcm;
  141615. long samples;
  141616. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141617. while(1){
  141618. if(vf->ready_state==INITSET){
  141619. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141620. if(samples)break;
  141621. }
  141622. {
  141623. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141624. if(ret==OV_EOF)
  141625. return(0);
  141626. if(ret<=0)
  141627. return(ret);
  141628. }
  141629. }
  141630. if(samples>0){
  141631. long channels=ov_info(vf,-1)->channels;
  141632. long bytespersample=word * channels;
  141633. vorbis_fpu_control fpu;
  141634. (void) fpu; // (to avoid a warning about it being unused)
  141635. if(samples>length/bytespersample)samples=length/bytespersample;
  141636. if(samples <= 0)
  141637. return OV_EINVAL;
  141638. {
  141639. int val;
  141640. if(word==1){
  141641. int off=(sgned?0:128);
  141642. vorbis_fpu_setround(&fpu);
  141643. for(j=0;j<samples;j++)
  141644. for(i=0;i<channels;i++){
  141645. val=vorbis_ftoi(pcm[i][j]*128.f);
  141646. if(val>127)val=127;
  141647. else if(val<-128)val=-128;
  141648. *buffer++=val+off;
  141649. }
  141650. vorbis_fpu_restore(fpu);
  141651. }else{
  141652. int off=(sgned?0:32768);
  141653. if(host_endian==bigendianp){
  141654. if(sgned){
  141655. vorbis_fpu_setround(&fpu);
  141656. for(i=0;i<channels;i++) { /* It's faster in this order */
  141657. float *src=pcm[i];
  141658. short *dest=((short *)buffer)+i;
  141659. for(j=0;j<samples;j++) {
  141660. val=vorbis_ftoi(src[j]*32768.f);
  141661. if(val>32767)val=32767;
  141662. else if(val<-32768)val=-32768;
  141663. *dest=val;
  141664. dest+=channels;
  141665. }
  141666. }
  141667. vorbis_fpu_restore(fpu);
  141668. }else{
  141669. vorbis_fpu_setround(&fpu);
  141670. for(i=0;i<channels;i++) {
  141671. float *src=pcm[i];
  141672. short *dest=((short *)buffer)+i;
  141673. for(j=0;j<samples;j++) {
  141674. val=vorbis_ftoi(src[j]*32768.f);
  141675. if(val>32767)val=32767;
  141676. else if(val<-32768)val=-32768;
  141677. *dest=val+off;
  141678. dest+=channels;
  141679. }
  141680. }
  141681. vorbis_fpu_restore(fpu);
  141682. }
  141683. }else if(bigendianp){
  141684. vorbis_fpu_setround(&fpu);
  141685. for(j=0;j<samples;j++)
  141686. for(i=0;i<channels;i++){
  141687. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141688. if(val>32767)val=32767;
  141689. else if(val<-32768)val=-32768;
  141690. val+=off;
  141691. *buffer++=(val>>8);
  141692. *buffer++=(val&0xff);
  141693. }
  141694. vorbis_fpu_restore(fpu);
  141695. }else{
  141696. int val;
  141697. vorbis_fpu_setround(&fpu);
  141698. for(j=0;j<samples;j++)
  141699. for(i=0;i<channels;i++){
  141700. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141701. if(val>32767)val=32767;
  141702. else if(val<-32768)val=-32768;
  141703. val+=off;
  141704. *buffer++=(val&0xff);
  141705. *buffer++=(val>>8);
  141706. }
  141707. vorbis_fpu_restore(fpu);
  141708. }
  141709. }
  141710. }
  141711. vorbis_synthesis_read(&vf->vd,samples);
  141712. vf->pcm_offset+=samples;
  141713. if(bitstream)*bitstream=vf->current_link;
  141714. return(samples*bytespersample);
  141715. }else{
  141716. return(samples);
  141717. }
  141718. }
  141719. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141720. int *bitstream){
  141721. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141722. while(1){
  141723. if(vf->ready_state==INITSET){
  141724. float **pcm;
  141725. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141726. if(samples){
  141727. if(pcm_channels)*pcm_channels=pcm;
  141728. if(samples>length)samples=length;
  141729. vorbis_synthesis_read(&vf->vd,samples);
  141730. vf->pcm_offset+=samples;
  141731. if(bitstream)*bitstream=vf->current_link;
  141732. return samples;
  141733. }
  141734. }
  141735. {
  141736. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141737. if(ret==OV_EOF)return(0);
  141738. if(ret<=0)return(ret);
  141739. }
  141740. }
  141741. }
  141742. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141743. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141744. ogg_int64_t off);
  141745. static void _ov_splice(float **pcm,float **lappcm,
  141746. int n1, int n2,
  141747. int ch1, int ch2,
  141748. float *w1, float *w2){
  141749. int i,j;
  141750. float *w=w1;
  141751. int n=n1;
  141752. if(n1>n2){
  141753. n=n2;
  141754. w=w2;
  141755. }
  141756. for(j=0;j<ch1 && j<ch2;j++){
  141757. float *s=lappcm[j];
  141758. float *d=pcm[j];
  141759. for(i=0;i<n;i++){
  141760. float wd=w[i]*w[i];
  141761. float ws=1.-wd;
  141762. d[i]=d[i]*wd + s[i]*ws;
  141763. }
  141764. }
  141765. for(;j<ch2;j++){
  141766. float *d=pcm[j];
  141767. for(i=0;i<n;i++){
  141768. float wd=w[i]*w[i];
  141769. d[i]=d[i]*wd;
  141770. }
  141771. }
  141772. }
  141773. static int _ov_initset(OggVorbis_File *vf){
  141774. while(1){
  141775. if(vf->ready_state==INITSET)break;
  141776. {
  141777. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141778. if(ret<0 && ret!=OV_HOLE)return(ret);
  141779. }
  141780. }
  141781. return 0;
  141782. }
  141783. static int _ov_initprime(OggVorbis_File *vf){
  141784. vorbis_dsp_state *vd=&vf->vd;
  141785. while(1){
  141786. if(vf->ready_state==INITSET)
  141787. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141788. {
  141789. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141790. if(ret<0 && ret!=OV_HOLE)return(ret);
  141791. }
  141792. }
  141793. return 0;
  141794. }
  141795. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141796. float **lappcm,int lapsize){
  141797. int lapcount=0,i;
  141798. float **pcm;
  141799. while(lapcount<lapsize){
  141800. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141801. if(samples){
  141802. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141803. for(i=0;i<vi->channels;i++)
  141804. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141805. lapcount+=samples;
  141806. vorbis_synthesis_read(vd,samples);
  141807. }else{
  141808. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141809. if(ret==OV_EOF)break;
  141810. }
  141811. }
  141812. if(lapcount<lapsize){
  141813. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141814. if(samples==0){
  141815. for(i=0;i<vi->channels;i++)
  141816. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141817. lapcount=lapsize;
  141818. }else{
  141819. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141820. for(i=0;i<vi->channels;i++)
  141821. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141822. lapcount+=samples;
  141823. }
  141824. }
  141825. }
  141826. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141827. vorbis_info *vi1,*vi2;
  141828. float **lappcm;
  141829. float **pcm;
  141830. float *w1,*w2;
  141831. int n1,n2,i,ret,hs1,hs2;
  141832. if(vf1==vf2)return(0); /* degenerate case */
  141833. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141834. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141835. ret=_ov_initset(vf1);
  141836. if(ret)return(ret);
  141837. ret=_ov_initprime(vf2);
  141838. if(ret)return(ret);
  141839. vi1=ov_info(vf1,-1);
  141840. vi2=ov_info(vf2,-1);
  141841. hs1=ov_halfrate_p(vf1);
  141842. hs2=ov_halfrate_p(vf2);
  141843. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141844. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141845. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141846. w1=vorbis_window(&vf1->vd,0);
  141847. w2=vorbis_window(&vf2->vd,0);
  141848. for(i=0;i<vi1->channels;i++)
  141849. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141850. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141851. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141852. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141853. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141854. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141855. return(0);
  141856. }
  141857. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141858. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141859. vorbis_info *vi;
  141860. float **lappcm;
  141861. float **pcm;
  141862. float *w1,*w2;
  141863. int n1,n2,ch1,ch2,hs;
  141864. int i,ret;
  141865. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141866. ret=_ov_initset(vf);
  141867. if(ret)return(ret);
  141868. vi=ov_info(vf,-1);
  141869. hs=ov_halfrate_p(vf);
  141870. ch1=vi->channels;
  141871. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141872. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141873. persistent; even if the decode state
  141874. from this link gets dumped, this
  141875. window array continues to exist */
  141876. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141877. for(i=0;i<ch1;i++)
  141878. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141879. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141880. ret=localseek(vf,pos);
  141881. if(ret)return ret;
  141882. ret=_ov_initprime(vf);
  141883. if(ret)return(ret);
  141884. vi=ov_info(vf,-1);
  141885. ch2=vi->channels;
  141886. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141887. w2=vorbis_window(&vf->vd,0);
  141888. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141889. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141890. return(0);
  141891. }
  141892. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141893. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141894. }
  141895. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141896. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141897. }
  141898. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141899. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141900. }
  141901. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141902. int (*localseek)(OggVorbis_File *,double)){
  141903. vorbis_info *vi;
  141904. float **lappcm;
  141905. float **pcm;
  141906. float *w1,*w2;
  141907. int n1,n2,ch1,ch2,hs;
  141908. int i,ret;
  141909. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141910. ret=_ov_initset(vf);
  141911. if(ret)return(ret);
  141912. vi=ov_info(vf,-1);
  141913. hs=ov_halfrate_p(vf);
  141914. ch1=vi->channels;
  141915. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141916. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141917. persistent; even if the decode state
  141918. from this link gets dumped, this
  141919. window array continues to exist */
  141920. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141921. for(i=0;i<ch1;i++)
  141922. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141923. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141924. ret=localseek(vf,pos);
  141925. if(ret)return ret;
  141926. ret=_ov_initprime(vf);
  141927. if(ret)return(ret);
  141928. vi=ov_info(vf,-1);
  141929. ch2=vi->channels;
  141930. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141931. w2=vorbis_window(&vf->vd,0);
  141932. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141933. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141934. return(0);
  141935. }
  141936. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  141937. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  141938. }
  141939. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  141940. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  141941. }
  141942. #endif
  141943. /*** End of inlined file: vorbisfile.c ***/
  141944. /*** Start of inlined file: window.c ***/
  141945. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141946. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141947. // tasks..
  141948. #if JUCE_MSVC
  141949. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141950. #endif
  141951. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141952. #if JUCE_USE_OGGVORBIS
  141953. #include <stdlib.h>
  141954. #include <math.h>
  141955. static float vwin64[32] = {
  141956. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  141957. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  141958. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  141959. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  141960. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  141961. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  141962. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  141963. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  141964. };
  141965. static float vwin128[64] = {
  141966. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  141967. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  141968. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  141969. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  141970. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  141971. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  141972. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  141973. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  141974. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  141975. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  141976. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  141977. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  141978. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  141979. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  141980. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  141981. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  141982. };
  141983. static float vwin256[128] = {
  141984. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  141985. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  141986. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  141987. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  141988. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  141989. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  141990. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  141991. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  141992. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  141993. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  141994. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  141995. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  141996. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  141997. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  141998. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  141999. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142000. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142001. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142002. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142003. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142004. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142005. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142006. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142007. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142008. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142009. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142010. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142011. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142012. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142013. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142014. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142015. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142016. };
  142017. static float vwin512[256] = {
  142018. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142019. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142020. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142021. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142022. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142023. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142024. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142025. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142026. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142027. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142028. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142029. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142030. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142031. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142032. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142033. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142034. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142035. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142036. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142037. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142038. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142039. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142040. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142041. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142042. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142043. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142044. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142045. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142046. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142047. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142048. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142049. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142050. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142051. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142052. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142053. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142054. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142055. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142056. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142057. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142058. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142059. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142060. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142061. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142062. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142063. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142064. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142065. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142066. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142067. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142068. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142069. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142070. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142071. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142072. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142073. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142074. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142075. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142076. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142077. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142078. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142079. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142080. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142081. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142082. };
  142083. static float vwin1024[512] = {
  142084. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142085. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142086. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142087. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142088. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142089. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142090. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142091. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142092. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142093. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142094. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142095. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142096. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142097. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142098. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142099. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142100. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142101. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142102. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142103. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142104. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142105. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142106. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142107. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142108. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142109. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142110. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142111. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142112. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142113. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142114. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142115. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142116. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142117. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142118. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142119. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142120. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142121. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142122. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142123. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142124. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142125. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142126. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142127. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142128. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142129. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142130. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142131. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142132. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142133. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142134. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142135. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142136. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142137. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142138. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142139. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142140. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142141. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142142. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142143. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142144. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142145. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142146. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142147. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142148. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142149. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142150. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142151. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142152. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142153. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142154. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142155. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142156. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142157. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142158. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142159. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142160. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142161. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142162. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142163. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142164. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142165. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142166. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142167. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142168. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142169. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142170. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142171. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142172. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142173. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142174. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142175. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142176. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142177. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142178. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142179. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142180. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142181. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142182. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142183. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142184. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142185. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142186. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142187. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142188. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142189. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142190. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142191. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142192. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142193. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142194. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142195. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142196. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142197. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142198. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142199. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142200. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142201. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142202. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142203. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142204. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142205. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142206. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142207. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142208. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142209. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142210. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142211. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142212. };
  142213. static float vwin2048[1024] = {
  142214. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142215. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142216. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142217. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142218. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142219. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142220. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142221. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142222. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142223. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142224. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142225. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142226. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142227. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142228. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142229. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142230. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142231. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142232. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142233. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142234. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142235. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142236. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142237. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142238. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142239. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142240. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142241. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142242. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142243. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142244. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142245. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142246. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142247. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142248. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142249. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142250. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142251. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142252. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142253. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142254. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142255. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142256. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142257. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142258. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142259. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142260. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142261. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142262. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142263. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142264. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142265. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142266. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142267. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142268. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142269. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142270. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142271. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142272. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142273. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142274. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142275. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142276. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142277. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142278. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142279. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142280. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142281. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142282. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142283. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142284. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142285. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142286. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142287. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142288. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142289. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142290. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142291. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142292. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142293. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142294. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142295. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142296. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142297. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142298. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142299. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142300. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142301. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142302. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142303. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142304. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142305. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142306. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142307. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142308. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142309. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142310. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142311. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142312. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142313. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142314. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142315. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142316. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142317. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142318. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142319. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142320. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142321. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142322. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142323. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142324. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142325. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142326. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142327. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142328. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142329. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142330. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142331. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142332. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142333. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142334. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142335. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142336. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142337. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142338. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142339. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142340. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142341. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142342. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142343. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142344. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142345. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142346. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142347. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142348. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142349. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142350. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142351. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142352. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142353. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142354. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142355. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142356. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142357. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142358. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142359. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142360. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142361. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142362. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142363. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142364. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142365. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142366. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142367. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142368. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142369. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142370. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142371. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142372. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142373. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142374. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142375. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142376. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142377. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142378. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142379. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142380. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142381. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142382. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142383. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142384. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142385. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142386. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142387. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142388. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142389. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142390. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142391. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142392. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142393. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142394. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142395. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142396. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142397. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142398. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142399. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142400. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142401. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142402. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142403. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142404. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142405. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142406. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142407. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142408. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142409. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142410. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142411. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142412. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142413. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142414. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142415. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142416. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142417. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142418. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142419. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142420. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142421. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142422. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142423. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142424. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142425. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142426. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142427. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142428. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142429. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142430. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142431. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142432. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142433. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142434. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142435. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142436. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142437. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142438. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142439. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142440. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142441. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142442. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142443. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142444. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142445. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142446. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142447. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142448. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142449. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142450. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142451. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142452. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142453. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142454. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142455. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142456. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142457. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142458. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142459. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142460. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142461. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142462. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142463. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142464. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142465. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142466. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142467. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142468. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142469. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142470. };
  142471. static float vwin4096[2048] = {
  142472. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142473. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142474. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142475. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142476. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142477. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142478. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142479. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142480. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142481. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142482. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142483. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142484. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142485. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142486. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142487. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142488. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142489. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142490. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142491. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142492. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142493. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142494. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142495. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142496. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142497. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142498. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142499. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142500. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142501. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142502. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142503. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142504. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142505. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142506. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142507. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142508. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142509. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142510. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142511. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142512. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142513. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142514. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142515. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142516. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142517. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142518. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142519. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142520. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142521. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142522. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142523. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142524. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142525. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142526. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142527. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142528. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142529. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142530. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142531. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142532. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142533. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142534. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142535. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142536. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142537. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142538. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142539. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142540. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142541. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142542. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142543. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142544. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142545. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142546. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142547. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142548. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142549. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142550. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142551. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142552. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142553. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142554. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142555. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142556. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142557. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142558. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142559. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142560. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142561. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142562. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142563. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142564. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142565. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142566. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142567. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142568. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142569. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142570. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142571. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142572. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142573. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142574. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142575. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142576. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142577. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142578. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142579. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142580. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142581. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142582. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142583. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142584. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142585. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142586. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142587. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142588. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142589. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142590. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142591. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142592. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142593. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142594. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142595. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142596. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142597. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142598. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142599. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142600. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142601. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142602. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142603. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142604. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142605. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142606. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142607. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142608. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142609. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142610. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142611. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142612. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142613. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142614. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142615. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142616. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142617. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142618. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142619. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142620. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142621. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142622. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142623. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142624. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142625. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142626. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142627. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142628. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142629. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142630. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142631. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142632. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142633. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142634. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142635. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142636. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142637. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142638. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142639. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142640. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142641. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142642. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142643. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142644. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142645. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142646. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142647. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142648. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142649. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142650. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142651. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142652. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142653. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142654. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142655. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142656. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142657. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142658. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142659. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142660. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142661. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142662. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142663. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142664. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142665. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142666. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142667. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142668. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142669. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142670. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142671. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142672. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142673. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142674. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142675. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142676. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142677. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142678. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142679. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142680. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142681. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142682. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142683. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142684. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142685. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142686. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142687. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142688. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142689. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142690. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142691. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142692. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142693. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142694. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142695. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142696. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142697. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142698. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142699. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142700. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142701. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142702. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142703. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142704. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142705. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142706. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142707. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142708. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142709. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142710. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142711. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142712. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142713. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142714. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142715. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142716. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142717. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142718. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142719. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142720. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142721. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142722. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142723. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142724. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142725. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142726. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142727. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142728. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142729. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142730. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142731. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142732. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142733. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142734. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142735. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142736. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142737. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142738. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142739. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142740. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142741. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142742. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142743. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142744. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142745. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142746. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142747. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142748. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142749. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142750. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142751. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142752. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142753. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142754. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142755. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142756. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142757. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142758. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142759. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142760. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142761. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142762. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142763. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142764. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142765. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142766. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142767. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142768. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142769. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142770. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142771. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142772. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142773. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142774. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142775. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142776. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142777. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142778. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142779. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142780. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142781. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142782. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142783. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142784. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142785. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142786. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142787. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142788. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142789. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142790. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142791. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142792. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142793. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142794. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142795. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142796. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142797. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142798. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142799. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142800. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142801. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142802. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142803. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142804. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142805. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142806. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142807. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142808. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142809. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142810. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142811. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142812. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142813. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142814. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142815. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142816. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142817. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142818. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142819. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142820. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142821. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142822. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142823. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142824. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142825. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142826. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142827. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142828. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142829. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142830. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142831. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142832. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142833. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142834. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142835. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142836. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142837. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142838. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142839. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142840. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142841. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142842. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142843. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142844. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142845. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142846. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142847. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142848. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142849. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142850. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142851. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142852. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142853. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142854. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142855. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142856. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142857. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142858. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142859. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142860. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142861. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142862. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142863. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142864. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142865. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142866. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142867. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142868. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142869. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142870. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142871. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142872. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142873. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142874. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142875. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142876. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142877. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142878. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142879. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142880. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142881. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142882. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142883. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142884. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142885. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142886. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142887. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142888. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142889. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142890. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142891. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142892. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142893. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142894. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142895. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142896. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142897. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142898. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142899. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142900. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142901. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142902. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142903. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142904. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142905. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142906. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142907. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142908. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142909. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142910. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142911. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142912. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142913. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142914. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142915. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142916. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  142917. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  142918. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  142919. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  142920. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  142921. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  142922. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  142923. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  142924. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  142925. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  142926. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  142927. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  142928. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  142929. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  142930. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  142931. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  142932. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  142933. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  142934. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  142935. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  142936. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  142937. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  142938. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  142939. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  142940. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  142941. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  142942. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  142943. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  142944. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  142945. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  142946. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  142947. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  142948. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  142949. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  142950. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  142951. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  142952. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  142953. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  142954. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  142955. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  142956. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  142957. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  142958. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  142959. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  142960. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  142961. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  142962. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  142963. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  142964. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  142965. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  142966. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  142967. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  142968. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  142969. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  142970. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  142971. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  142972. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  142973. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  142974. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  142975. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  142976. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  142977. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  142978. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  142979. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  142980. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  142981. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  142982. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  142983. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  142984. };
  142985. static float vwin8192[4096] = {
  142986. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  142987. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  142988. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  142989. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  142990. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  142991. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  142992. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  142993. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  142994. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  142995. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  142996. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  142997. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  142998. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  142999. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143000. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143001. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143002. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143003. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143004. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143005. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143006. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143007. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143008. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143009. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143010. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143011. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143012. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143013. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143014. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143015. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143016. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143017. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143018. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143019. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143020. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143021. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143022. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143023. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143024. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143025. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143026. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143027. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143028. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143029. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143030. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143031. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143032. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143033. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143034. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143035. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143036. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143037. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143038. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143039. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143040. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143041. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143042. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143043. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143044. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143045. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143046. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143047. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143048. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143049. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143050. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143051. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143052. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143053. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143054. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143055. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143056. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143057. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143058. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143059. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143060. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143061. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143062. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143063. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143064. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143065. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143066. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143067. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143068. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143069. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143070. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143071. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143072. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143073. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143074. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143075. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143076. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143077. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143078. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143079. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143080. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143081. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143082. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143083. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143084. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143085. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143086. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143087. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143088. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143089. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143090. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143091. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143092. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143093. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143094. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143095. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143096. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143097. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143098. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143099. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143100. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143101. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143102. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143103. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143104. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143105. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143106. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143107. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143108. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143109. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143110. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143111. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143112. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143113. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143114. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143115. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143116. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143117. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143118. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143119. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143120. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143121. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143122. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143123. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143124. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143125. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143126. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143127. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143128. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143129. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143130. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143131. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143132. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143133. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143134. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143135. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143136. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143137. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143138. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143139. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143140. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143141. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143142. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143143. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143144. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143145. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143146. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143147. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143148. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143149. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143150. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143151. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143152. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143153. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143154. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143155. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143156. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143157. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143158. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143159. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143160. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143161. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143162. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143163. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143164. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143165. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143166. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143167. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143168. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143169. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143170. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143171. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143172. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143173. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143174. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143175. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143176. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143177. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143178. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143179. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143180. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143181. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143182. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143183. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143184. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143185. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143186. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143187. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143188. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143189. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143190. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143191. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143192. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143193. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143194. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143195. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143196. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143197. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143198. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143199. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143200. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143201. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143202. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143203. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143204. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143205. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143206. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143207. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143208. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143209. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143210. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143211. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143212. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143213. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143214. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143215. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143216. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143217. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143218. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143219. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143220. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143221. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143222. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143223. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143224. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143225. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143226. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143227. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143228. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143229. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143230. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143231. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143232. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143233. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143234. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143235. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143236. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143237. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143238. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143239. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143240. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143241. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143242. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143243. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143244. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143245. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143246. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143247. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143248. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143249. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143250. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143251. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143252. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143253. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143254. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143255. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143256. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143257. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143258. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143259. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143260. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143261. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143262. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143263. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143264. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143265. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143266. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143267. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143268. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143269. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143270. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143271. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143272. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143273. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143274. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143275. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143276. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143277. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143278. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143279. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143280. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143281. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143282. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143283. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143284. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143285. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143286. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143287. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143288. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143289. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143290. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143291. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143292. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143293. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143294. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143295. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143296. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143297. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143298. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143299. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143300. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143301. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143302. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143303. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143304. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143305. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143306. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143307. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143308. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143309. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143310. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143311. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143312. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143313. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143314. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143315. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143316. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143317. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143318. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143319. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143320. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143321. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143322. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143323. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143324. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143325. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143326. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143327. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143328. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143329. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143330. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143331. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143332. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143333. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143334. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143335. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143336. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143337. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143338. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143339. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143340. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143341. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143342. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143343. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143344. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143345. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143346. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143347. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143348. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143349. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143350. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143351. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143352. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143353. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143354. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143355. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143356. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143357. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143358. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143359. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143360. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143361. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143362. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143363. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143364. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143365. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143366. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143367. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143368. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143369. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143370. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143371. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143372. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143373. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143374. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143375. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143376. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143377. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143378. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143379. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143380. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143381. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143382. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143383. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143384. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143385. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143386. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143387. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143388. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143389. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143390. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143391. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143392. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143393. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143394. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143395. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143396. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143397. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143398. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143399. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143400. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143401. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143402. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143403. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143404. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143405. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143406. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143407. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143408. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143409. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143410. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143411. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143412. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143413. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143414. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143415. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143416. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143417. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143418. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143419. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143420. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143421. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143422. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143423. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143424. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143425. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143426. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143427. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143428. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143429. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143430. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143431. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143432. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143433. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143434. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143435. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143436. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143437. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143438. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143439. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143440. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143441. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143442. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143443. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143444. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143445. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143446. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143447. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143448. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143449. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143450. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143451. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143452. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143453. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143454. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143455. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143456. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143457. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143458. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143459. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143460. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143461. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143462. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143463. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143464. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143465. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143466. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143467. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143468. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143469. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143470. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143471. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143472. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143473. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143474. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143475. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143476. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143477. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143478. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143479. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143480. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143481. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143482. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143483. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143484. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143485. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143486. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143487. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143488. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143489. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143490. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143491. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143492. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143493. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143494. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143495. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143496. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143497. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143498. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143499. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143500. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143501. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143502. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143503. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143504. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143505. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143506. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143507. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143508. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143509. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143510. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143511. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143512. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143513. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143514. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143515. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143516. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143517. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143518. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143519. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143520. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143521. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143522. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143523. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143524. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143525. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143526. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143527. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143528. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143529. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143530. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143531. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143532. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143533. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143534. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143535. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143536. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143537. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143538. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143539. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143540. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143541. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143542. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143543. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143544. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143545. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143546. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143547. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143548. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143549. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143550. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143551. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143552. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143553. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143554. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143555. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143556. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143557. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143558. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143559. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143560. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143561. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143562. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143563. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143564. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143565. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143566. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143567. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143568. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143569. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143570. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143571. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143572. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143573. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143574. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143575. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143576. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143577. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143578. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143579. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143580. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143581. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143582. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143583. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143584. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143585. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143586. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143587. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143588. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143589. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143590. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143591. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143592. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143593. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143594. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143595. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143596. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143597. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143598. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143599. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143600. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143601. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143602. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143603. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143604. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143605. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143606. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143607. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143608. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143609. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143610. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143611. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143612. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143613. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143614. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143615. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143616. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143617. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143618. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143619. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143620. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143621. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143622. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143623. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143624. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143625. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143626. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143627. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143628. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143629. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143630. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143631. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143632. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143633. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143634. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143635. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143636. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143637. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143638. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143639. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143640. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143641. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143642. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143643. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143644. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143645. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143646. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143647. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143648. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143649. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143650. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143651. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143652. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143653. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143654. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143655. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143656. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143657. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143658. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143659. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143660. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143661. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143662. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143663. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143664. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143665. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143666. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143667. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143668. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143669. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143670. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143671. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143672. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143673. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143674. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143675. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143676. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143677. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143678. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143679. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143680. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143681. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143682. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143683. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143684. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143685. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143686. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143687. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143688. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143689. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143690. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143691. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143692. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143693. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143694. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143695. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143696. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143697. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143698. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143699. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143700. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143701. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143702. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143703. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143704. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143705. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143706. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143707. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143708. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143709. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143710. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143711. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143712. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143713. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143714. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143715. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143716. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143717. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143718. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143719. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143720. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143721. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143722. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143723. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143724. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143725. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143726. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143727. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143728. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143729. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143730. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143731. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143732. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143733. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143734. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143735. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143736. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143737. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143738. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143739. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143740. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143741. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143742. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143743. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143744. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143745. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143746. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143747. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143748. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143749. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143750. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143751. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143752. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143753. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143754. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143755. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143756. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143757. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143758. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143759. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143760. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143761. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143762. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143763. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143764. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143765. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143766. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143767. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143768. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143769. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143770. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143771. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143772. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143773. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143774. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143775. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143776. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143777. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143778. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143779. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143780. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143781. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143782. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143783. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143784. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143785. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143786. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143787. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143788. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143789. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143790. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143791. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143792. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143793. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143794. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143795. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143796. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143797. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143798. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143799. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143800. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143801. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143802. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143803. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143804. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143805. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143806. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143807. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143808. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143809. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143810. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143811. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143812. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143813. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143814. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143815. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143816. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143817. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143818. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143819. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143820. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143821. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143822. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143823. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143824. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143825. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143826. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143827. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143828. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143829. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143830. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143831. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143832. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143833. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143834. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143835. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143836. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143837. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143838. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143839. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143840. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143841. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143842. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143843. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143844. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143845. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143846. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143847. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143848. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143849. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143850. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143851. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143852. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143853. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143854. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143855. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143856. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143857. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143858. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143859. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143860. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143861. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143862. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143863. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143864. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143865. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143866. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143867. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143868. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143869. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143870. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143871. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143872. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143873. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143874. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143875. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143876. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143877. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143878. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143879. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143880. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143881. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143882. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143883. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143884. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143885. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143886. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143887. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143888. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143889. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143890. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143891. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143892. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143893. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143894. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143895. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143896. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143897. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143898. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143899. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143900. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143901. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143902. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143903. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143904. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143905. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143906. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143907. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143908. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143909. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143910. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143911. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143912. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143913. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143914. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143915. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143916. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  143917. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  143918. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  143919. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  143920. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  143921. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  143922. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  143923. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  143924. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  143925. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  143926. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  143927. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  143928. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  143929. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  143930. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  143931. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  143932. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  143933. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  143934. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  143935. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  143936. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  143937. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  143938. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  143939. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  143940. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  143941. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  143942. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  143943. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  143944. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  143945. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  143946. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  143947. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  143948. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  143949. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  143950. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  143951. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  143952. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  143953. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  143954. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  143955. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  143956. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  143957. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  143958. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  143959. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  143960. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  143961. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  143962. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  143963. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  143964. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  143965. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  143966. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  143967. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  143968. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  143969. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  143970. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  143971. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  143972. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  143973. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  143974. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  143975. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  143976. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  143977. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  143978. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  143979. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  143980. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  143981. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  143982. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  143983. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  143984. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  143985. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  143986. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  143987. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  143988. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  143989. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  143990. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  143991. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  143992. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  143993. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  143994. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  143995. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  143996. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  143997. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  143998. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  143999. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144000. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144001. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144002. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144003. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144004. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144005. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144006. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144007. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144008. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144009. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144010. };
  144011. static float *vwin[8] = {
  144012. vwin64,
  144013. vwin128,
  144014. vwin256,
  144015. vwin512,
  144016. vwin1024,
  144017. vwin2048,
  144018. vwin4096,
  144019. vwin8192,
  144020. };
  144021. float *_vorbis_window_get(int n){
  144022. return vwin[n];
  144023. }
  144024. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144025. int lW,int W,int nW){
  144026. lW=(W?lW:0);
  144027. nW=(W?nW:0);
  144028. {
  144029. float *windowLW=vwin[winno[lW]];
  144030. float *windowNW=vwin[winno[nW]];
  144031. long n=blocksizes[W];
  144032. long ln=blocksizes[lW];
  144033. long rn=blocksizes[nW];
  144034. long leftbegin=n/4-ln/4;
  144035. long leftend=leftbegin+ln/2;
  144036. long rightbegin=n/2+n/4-rn/4;
  144037. long rightend=rightbegin+rn/2;
  144038. int i,p;
  144039. for(i=0;i<leftbegin;i++)
  144040. d[i]=0.f;
  144041. for(p=0;i<leftend;i++,p++)
  144042. d[i]*=windowLW[p];
  144043. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144044. d[i]*=windowNW[p];
  144045. for(;i<n;i++)
  144046. d[i]=0.f;
  144047. }
  144048. }
  144049. #endif
  144050. /*** End of inlined file: window.c ***/
  144051. #else
  144052. #include <vorbis/vorbisenc.h>
  144053. #include <vorbis/codec.h>
  144054. #include <vorbis/vorbisfile.h>
  144055. #endif
  144056. }
  144057. #undef max
  144058. #undef min
  144059. BEGIN_JUCE_NAMESPACE
  144060. static const char* const oggFormatName = "Ogg-Vorbis file";
  144061. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144062. class OggReader : public AudioFormatReader
  144063. {
  144064. OggVorbisNamespace::OggVorbis_File ovFile;
  144065. OggVorbisNamespace::ov_callbacks callbacks;
  144066. AudioSampleBuffer reservoir;
  144067. int reservoirStart, samplesInReservoir;
  144068. public:
  144069. OggReader (InputStream* const inp)
  144070. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144071. reservoir (2, 4096),
  144072. reservoirStart (0),
  144073. samplesInReservoir (0)
  144074. {
  144075. using namespace OggVorbisNamespace;
  144076. sampleRate = 0;
  144077. usesFloatingPointData = true;
  144078. callbacks.read_func = &oggReadCallback;
  144079. callbacks.seek_func = &oggSeekCallback;
  144080. callbacks.close_func = &oggCloseCallback;
  144081. callbacks.tell_func = &oggTellCallback;
  144082. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144083. if (err == 0)
  144084. {
  144085. vorbis_info* info = ov_info (&ovFile, -1);
  144086. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144087. numChannels = info->channels;
  144088. bitsPerSample = 16;
  144089. sampleRate = info->rate;
  144090. reservoir.setSize (numChannels,
  144091. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144092. }
  144093. }
  144094. ~OggReader()
  144095. {
  144096. OggVorbisNamespace::ov_clear (&ovFile);
  144097. }
  144098. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144099. int64 startSampleInFile, int numSamples)
  144100. {
  144101. while (numSamples > 0)
  144102. {
  144103. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144104. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144105. {
  144106. // got a few samples overlapping, so use them before seeking..
  144107. const int numToUse = jmin (numSamples, numAvailable);
  144108. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144109. if (destSamples[i] != 0)
  144110. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144111. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144112. sizeof (float) * numToUse);
  144113. startSampleInFile += numToUse;
  144114. numSamples -= numToUse;
  144115. startOffsetInDestBuffer += numToUse;
  144116. if (numSamples == 0)
  144117. break;
  144118. }
  144119. if (startSampleInFile < reservoirStart
  144120. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144121. {
  144122. // buffer miss, so refill the reservoir
  144123. int bitStream = 0;
  144124. reservoirStart = jmax (0, (int) startSampleInFile);
  144125. samplesInReservoir = reservoir.getNumSamples();
  144126. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144127. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144128. int offset = 0;
  144129. int numToRead = samplesInReservoir;
  144130. while (numToRead > 0)
  144131. {
  144132. float** dataIn = 0;
  144133. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144134. if (samps <= 0)
  144135. break;
  144136. jassert (samps <= numToRead);
  144137. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144138. {
  144139. memcpy (reservoir.getSampleData (i, offset),
  144140. dataIn[i],
  144141. sizeof (float) * samps);
  144142. }
  144143. numToRead -= samps;
  144144. offset += samps;
  144145. }
  144146. if (numToRead > 0)
  144147. reservoir.clear (offset, numToRead);
  144148. }
  144149. }
  144150. if (numSamples > 0)
  144151. {
  144152. for (int i = numDestChannels; --i >= 0;)
  144153. if (destSamples[i] != 0)
  144154. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144155. sizeof (int) * numSamples);
  144156. }
  144157. return true;
  144158. }
  144159. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144160. {
  144161. return (size_t) (static_cast <InputStream*> (datasource)->read (ptr, (int) (size * nmemb)) / size);
  144162. }
  144163. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144164. {
  144165. InputStream* const in = static_cast <InputStream*> (datasource);
  144166. if (whence == SEEK_CUR)
  144167. offset += in->getPosition();
  144168. else if (whence == SEEK_END)
  144169. offset += in->getTotalLength();
  144170. in->setPosition (offset);
  144171. return 0;
  144172. }
  144173. static int oggCloseCallback (void*)
  144174. {
  144175. return 0;
  144176. }
  144177. static long oggTellCallback (void* datasource)
  144178. {
  144179. return (long) static_cast <InputStream*> (datasource)->getPosition();
  144180. }
  144181. juce_UseDebuggingNewOperator
  144182. };
  144183. class OggWriter : public AudioFormatWriter
  144184. {
  144185. OggVorbisNamespace::ogg_stream_state os;
  144186. OggVorbisNamespace::ogg_page og;
  144187. OggVorbisNamespace::ogg_packet op;
  144188. OggVorbisNamespace::vorbis_info vi;
  144189. OggVorbisNamespace::vorbis_comment vc;
  144190. OggVorbisNamespace::vorbis_dsp_state vd;
  144191. OggVorbisNamespace::vorbis_block vb;
  144192. public:
  144193. bool ok;
  144194. OggWriter (OutputStream* const out,
  144195. const double sampleRate,
  144196. const int numChannels,
  144197. const int bitsPerSample,
  144198. const int qualityIndex)
  144199. : AudioFormatWriter (out, TRANS (oggFormatName),
  144200. sampleRate,
  144201. numChannels,
  144202. bitsPerSample)
  144203. {
  144204. using namespace OggVorbisNamespace;
  144205. ok = false;
  144206. vorbis_info_init (&vi);
  144207. if (vorbis_encode_init_vbr (&vi,
  144208. numChannels,
  144209. (int) sampleRate,
  144210. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144211. {
  144212. vorbis_comment_init (&vc);
  144213. if (JUCEApplication::getInstance() != 0)
  144214. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144215. vorbis_analysis_init (&vd, &vi);
  144216. vorbis_block_init (&vd, &vb);
  144217. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144218. ogg_packet header;
  144219. ogg_packet header_comm;
  144220. ogg_packet header_code;
  144221. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144222. ogg_stream_packetin (&os, &header);
  144223. ogg_stream_packetin (&os, &header_comm);
  144224. ogg_stream_packetin (&os, &header_code);
  144225. for (;;)
  144226. {
  144227. if (ogg_stream_flush (&os, &og) == 0)
  144228. break;
  144229. output->write (og.header, og.header_len);
  144230. output->write (og.body, og.body_len);
  144231. }
  144232. ok = true;
  144233. }
  144234. }
  144235. ~OggWriter()
  144236. {
  144237. using namespace OggVorbisNamespace;
  144238. if (ok)
  144239. {
  144240. // write a zero-length packet to show ogg that we're finished..
  144241. write (0, 0);
  144242. ogg_stream_clear (&os);
  144243. vorbis_block_clear (&vb);
  144244. vorbis_dsp_clear (&vd);
  144245. vorbis_comment_clear (&vc);
  144246. vorbis_info_clear (&vi);
  144247. output->flush();
  144248. }
  144249. else
  144250. {
  144251. vorbis_info_clear (&vi);
  144252. output = 0; // to stop the base class deleting this, as it needs to be returned
  144253. // to the caller of createWriter()
  144254. }
  144255. }
  144256. bool write (const int** samplesToWrite, int numSamples)
  144257. {
  144258. using namespace OggVorbisNamespace;
  144259. if (! ok)
  144260. return false;
  144261. if (numSamples > 0)
  144262. {
  144263. const double gain = 1.0 / 0x80000000u;
  144264. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144265. for (int i = numChannels; --i >= 0;)
  144266. {
  144267. float* const dst = vorbisBuffer[i];
  144268. const int* const src = samplesToWrite [i];
  144269. if (src != 0 && dst != 0)
  144270. {
  144271. for (int j = 0; j < numSamples; ++j)
  144272. dst[j] = (float) (src[j] * gain);
  144273. }
  144274. }
  144275. }
  144276. vorbis_analysis_wrote (&vd, numSamples);
  144277. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144278. {
  144279. vorbis_analysis (&vb, 0);
  144280. vorbis_bitrate_addblock (&vb);
  144281. while (vorbis_bitrate_flushpacket (&vd, &op))
  144282. {
  144283. ogg_stream_packetin (&os, &op);
  144284. for (;;)
  144285. {
  144286. if (ogg_stream_pageout (&os, &og) == 0)
  144287. break;
  144288. output->write (og.header, og.header_len);
  144289. output->write (og.body, og.body_len);
  144290. if (ogg_page_eos (&og))
  144291. break;
  144292. }
  144293. }
  144294. }
  144295. return true;
  144296. }
  144297. juce_UseDebuggingNewOperator
  144298. };
  144299. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144300. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144301. {
  144302. }
  144303. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144304. {
  144305. }
  144306. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144307. {
  144308. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144309. return Array <int> (rates);
  144310. }
  144311. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144312. {
  144313. Array <int> depths;
  144314. depths.add (32);
  144315. return depths;
  144316. }
  144317. bool OggVorbisAudioFormat::canDoStereo()
  144318. {
  144319. return true;
  144320. }
  144321. bool OggVorbisAudioFormat::canDoMono()
  144322. {
  144323. return true;
  144324. }
  144325. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144326. const bool deleteStreamIfOpeningFails)
  144327. {
  144328. ScopedPointer <OggReader> r (new OggReader (in));
  144329. if (r->sampleRate != 0)
  144330. return r.release();
  144331. if (! deleteStreamIfOpeningFails)
  144332. r->input = 0;
  144333. return 0;
  144334. }
  144335. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144336. double sampleRate,
  144337. unsigned int numChannels,
  144338. int bitsPerSample,
  144339. const StringPairArray& /*metadataValues*/,
  144340. int qualityOptionIndex)
  144341. {
  144342. ScopedPointer <OggWriter> w (new OggWriter (out,
  144343. sampleRate,
  144344. numChannels,
  144345. bitsPerSample,
  144346. qualityOptionIndex));
  144347. return w->ok ? w.release() : 0;
  144348. }
  144349. bool OggVorbisAudioFormat::isCompressed()
  144350. {
  144351. return true;
  144352. }
  144353. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144354. {
  144355. StringArray s;
  144356. s.add ("Low Quality");
  144357. s.add ("Medium Quality");
  144358. s.add ("High Quality");
  144359. return s;
  144360. }
  144361. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144362. {
  144363. FileInputStream* const in = source.createInputStream();
  144364. if (in != 0)
  144365. {
  144366. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144367. if (r != 0)
  144368. {
  144369. const int64 numSamps = r->lengthInSamples;
  144370. r = 0;
  144371. const int64 fileNumSamps = source.getSize() / 4;
  144372. const double ratio = numSamps / (double) fileNumSamps;
  144373. if (ratio > 12.0)
  144374. return 0;
  144375. else if (ratio > 6.0)
  144376. return 1;
  144377. else
  144378. return 2;
  144379. }
  144380. }
  144381. return 1;
  144382. }
  144383. END_JUCE_NAMESPACE
  144384. #endif
  144385. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144386. #endif
  144387. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144388. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144389. #if JUCE_MSVC
  144390. #pragma warning (push)
  144391. #endif
  144392. namespace jpeglibNamespace
  144393. {
  144394. #if JUCE_INCLUDE_JPEGLIB_CODE
  144395. #if JUCE_MINGW
  144396. typedef unsigned char boolean;
  144397. #endif
  144398. extern "C"
  144399. {
  144400. #define JPEG_INTERNALS
  144401. #undef FAR
  144402. /*** Start of inlined file: jpeglib.h ***/
  144403. #ifndef JPEGLIB_H
  144404. #define JPEGLIB_H
  144405. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144406. /*** Start of inlined file: jconfig.h ***/
  144407. // disable all the warnings under MSVC
  144408. #ifdef _MSC_VER
  144409. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144410. #endif
  144411. #ifdef __BORLANDC__
  144412. #pragma warn -8057
  144413. #pragma warn -8019
  144414. #pragma warn -8004
  144415. #pragma warn -8008
  144416. #endif
  144417. #define HAVE_PROTOTYPES
  144418. #define HAVE_UNSIGNED_CHAR
  144419. #define HAVE_UNSIGNED_SHORT
  144420. #undef CHAR_IS_UNSIGNED
  144421. #define HAVE_STDDEF_H
  144422. #define HAVE_STDLIB_H
  144423. #undef NEED_BSD_STRINGS
  144424. #undef NEED_SYS_TYPES_H
  144425. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144426. #undef NEED_SHORT_EXTERNAL_NAMES
  144427. #undef INCOMPLETE_TYPES_BROKEN
  144428. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144429. typedef unsigned char boolean;
  144430. #endif
  144431. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144432. #ifdef JPEG_INTERNALS
  144433. #undef RIGHT_SHIFT_IS_UNSIGNED
  144434. #endif /* JPEG_INTERNALS */
  144435. #ifdef JPEG_CJPEG_DJPEG
  144436. #define BMP_SUPPORTED /* BMP image file format */
  144437. #define GIF_SUPPORTED /* GIF image file format */
  144438. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144439. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144440. #define TARGA_SUPPORTED /* Targa image file format */
  144441. #define TWO_FILE_COMMANDLINE /* optional */
  144442. #define USE_SETMODE /* Microsoft has setmode() */
  144443. #undef NEED_SIGNAL_CATCHER
  144444. #undef DONT_USE_B_MODE
  144445. #undef PROGRESS_REPORT /* optional */
  144446. #endif /* JPEG_CJPEG_DJPEG */
  144447. /*** End of inlined file: jconfig.h ***/
  144448. /* widely used configuration options */
  144449. #endif
  144450. /*** Start of inlined file: jmorecfg.h ***/
  144451. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144452. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144453. #if BITS_IN_JSAMPLE == 8
  144454. #ifdef HAVE_UNSIGNED_CHAR
  144455. typedef unsigned char JSAMPLE;
  144456. #define GETJSAMPLE(value) ((int) (value))
  144457. #else /* not HAVE_UNSIGNED_CHAR */
  144458. typedef char JSAMPLE;
  144459. #ifdef CHAR_IS_UNSIGNED
  144460. #define GETJSAMPLE(value) ((int) (value))
  144461. #else
  144462. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144463. #endif /* CHAR_IS_UNSIGNED */
  144464. #endif /* HAVE_UNSIGNED_CHAR */
  144465. #define MAXJSAMPLE 255
  144466. #define CENTERJSAMPLE 128
  144467. #endif /* BITS_IN_JSAMPLE == 8 */
  144468. #if BITS_IN_JSAMPLE == 12
  144469. typedef short JSAMPLE;
  144470. #define GETJSAMPLE(value) ((int) (value))
  144471. #define MAXJSAMPLE 4095
  144472. #define CENTERJSAMPLE 2048
  144473. #endif /* BITS_IN_JSAMPLE == 12 */
  144474. typedef short JCOEF;
  144475. #ifdef HAVE_UNSIGNED_CHAR
  144476. typedef unsigned char JOCTET;
  144477. #define GETJOCTET(value) (value)
  144478. #else /* not HAVE_UNSIGNED_CHAR */
  144479. typedef char JOCTET;
  144480. #ifdef CHAR_IS_UNSIGNED
  144481. #define GETJOCTET(value) (value)
  144482. #else
  144483. #define GETJOCTET(value) ((value) & 0xFF)
  144484. #endif /* CHAR_IS_UNSIGNED */
  144485. #endif /* HAVE_UNSIGNED_CHAR */
  144486. #ifdef HAVE_UNSIGNED_CHAR
  144487. typedef unsigned char UINT8;
  144488. #else /* not HAVE_UNSIGNED_CHAR */
  144489. #ifdef CHAR_IS_UNSIGNED
  144490. typedef char UINT8;
  144491. #else /* not CHAR_IS_UNSIGNED */
  144492. typedef short UINT8;
  144493. #endif /* CHAR_IS_UNSIGNED */
  144494. #endif /* HAVE_UNSIGNED_CHAR */
  144495. #ifdef HAVE_UNSIGNED_SHORT
  144496. typedef unsigned short UINT16;
  144497. #else /* not HAVE_UNSIGNED_SHORT */
  144498. typedef unsigned int UINT16;
  144499. #endif /* HAVE_UNSIGNED_SHORT */
  144500. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144501. typedef short INT16;
  144502. #endif
  144503. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144504. typedef long INT32;
  144505. #endif
  144506. typedef unsigned int JDIMENSION;
  144507. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144508. #define METHODDEF(type) static type
  144509. #define LOCAL(type) static type
  144510. #define GLOBAL(type) type
  144511. #define EXTERN(type) extern type
  144512. #ifdef HAVE_PROTOTYPES
  144513. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144514. #else
  144515. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144516. #endif
  144517. #ifdef NEED_FAR_POINTERS
  144518. #define FAR far
  144519. #else
  144520. #define FAR
  144521. #endif
  144522. #ifndef HAVE_BOOLEAN
  144523. typedef int boolean;
  144524. #endif
  144525. #ifndef FALSE /* in case these macros already exist */
  144526. #define FALSE 0 /* values of boolean */
  144527. #endif
  144528. #ifndef TRUE
  144529. #define TRUE 1
  144530. #endif
  144531. #ifdef JPEG_INTERNALS
  144532. #define JPEG_INTERNAL_OPTIONS
  144533. #endif
  144534. #ifdef JPEG_INTERNAL_OPTIONS
  144535. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144536. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144537. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144538. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144539. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144540. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144541. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144542. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144543. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144544. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144545. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144546. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144547. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144548. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144549. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144550. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144551. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144552. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144553. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144554. #define RGB_GREEN 1 /* Offset of Green */
  144555. #define RGB_BLUE 2 /* Offset of Blue */
  144556. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144557. #ifndef INLINE
  144558. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144559. #define INLINE __inline__
  144560. #endif
  144561. #ifndef INLINE
  144562. #define INLINE /* default is to define it as empty */
  144563. #endif
  144564. #endif
  144565. #ifndef MULTIPLIER
  144566. #define MULTIPLIER int /* type for fastest integer multiply */
  144567. #endif
  144568. #ifndef FAST_FLOAT
  144569. #ifdef HAVE_PROTOTYPES
  144570. #define FAST_FLOAT float
  144571. #else
  144572. #define FAST_FLOAT double
  144573. #endif
  144574. #endif
  144575. #endif /* JPEG_INTERNAL_OPTIONS */
  144576. /*** End of inlined file: jmorecfg.h ***/
  144577. /* seldom changed options */
  144578. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144579. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144580. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144581. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144582. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144583. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144584. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144585. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144586. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144587. #ifndef D_MAX_BLOCKS_IN_MCU
  144588. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144589. #endif
  144590. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144591. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144592. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144593. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144594. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144595. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144596. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144597. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144598. typedef struct {
  144599. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144600. boolean sent_table; /* TRUE when table has been output */
  144601. } JQUANT_TBL;
  144602. typedef struct {
  144603. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144604. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144605. boolean sent_table; /* TRUE when table has been output */
  144606. } JHUFF_TBL;
  144607. typedef struct {
  144608. int component_id; /* identifier for this component (0..255) */
  144609. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144610. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144611. int v_samp_factor; /* vertical sampling factor (1..4) */
  144612. int quant_tbl_no; /* quantization table selector (0..3) */
  144613. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144614. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144615. JDIMENSION width_in_blocks;
  144616. JDIMENSION height_in_blocks;
  144617. int DCT_scaled_size;
  144618. JDIMENSION downsampled_width; /* actual width in samples */
  144619. JDIMENSION downsampled_height; /* actual height in samples */
  144620. boolean component_needed; /* do we need the value of this component? */
  144621. int MCU_width; /* number of blocks per MCU, horizontally */
  144622. int MCU_height; /* number of blocks per MCU, vertically */
  144623. int MCU_blocks; /* MCU_width * MCU_height */
  144624. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144625. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144626. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144627. JQUANT_TBL * quant_table;
  144628. void * dct_table;
  144629. } jpeg_component_info;
  144630. typedef struct {
  144631. int comps_in_scan; /* number of components encoded in this scan */
  144632. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144633. int Ss, Se; /* progressive JPEG spectral selection parms */
  144634. int Ah, Al; /* progressive JPEG successive approx. parms */
  144635. } jpeg_scan_info;
  144636. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144637. struct jpeg_marker_struct {
  144638. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144639. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144640. unsigned int original_length; /* # bytes of data in the file */
  144641. unsigned int data_length; /* # bytes of data saved at data[] */
  144642. JOCTET FAR * data; /* the data contained in the marker */
  144643. };
  144644. typedef enum {
  144645. JCS_UNKNOWN, /* error/unspecified */
  144646. JCS_GRAYSCALE, /* monochrome */
  144647. JCS_RGB, /* red/green/blue */
  144648. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144649. JCS_CMYK, /* C/M/Y/K */
  144650. JCS_YCCK /* Y/Cb/Cr/K */
  144651. } J_COLOR_SPACE;
  144652. typedef enum {
  144653. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144654. JDCT_IFAST, /* faster, less accurate integer method */
  144655. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144656. } J_DCT_METHOD;
  144657. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144658. #define JDCT_DEFAULT JDCT_ISLOW
  144659. #endif
  144660. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144661. #define JDCT_FASTEST JDCT_IFAST
  144662. #endif
  144663. typedef enum {
  144664. JDITHER_NONE, /* no dithering */
  144665. JDITHER_ORDERED, /* simple ordered dither */
  144666. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144667. } J_DITHER_MODE;
  144668. #define jpeg_common_fields \
  144669. struct jpeg_error_mgr * err; /* Error handler module */\
  144670. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144671. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144672. void * client_data; /* Available for use by application */\
  144673. boolean is_decompressor; /* So common code can tell which is which */\
  144674. int global_state /* For checking call sequence validity */
  144675. struct jpeg_common_struct {
  144676. jpeg_common_fields; /* Fields common to both master struct types */
  144677. };
  144678. typedef struct jpeg_common_struct * j_common_ptr;
  144679. typedef struct jpeg_compress_struct * j_compress_ptr;
  144680. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144681. struct jpeg_compress_struct {
  144682. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144683. struct jpeg_destination_mgr * dest;
  144684. JDIMENSION image_width; /* input image width */
  144685. JDIMENSION image_height; /* input image height */
  144686. int input_components; /* # of color components in input image */
  144687. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144688. double input_gamma; /* image gamma of input image */
  144689. int data_precision; /* bits of precision in image data */
  144690. int num_components; /* # of color components in JPEG image */
  144691. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144692. jpeg_component_info * comp_info;
  144693. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144694. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144695. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144696. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144697. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144698. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144699. int num_scans; /* # of entries in scan_info array */
  144700. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144701. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144702. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144703. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144704. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144705. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144706. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144707. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144708. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144709. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144710. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144711. UINT8 JFIF_minor_version;
  144712. UINT8 density_unit; /* JFIF code for pixel size units */
  144713. UINT16 X_density; /* Horizontal pixel density */
  144714. UINT16 Y_density; /* Vertical pixel density */
  144715. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144716. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144717. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144718. int max_h_samp_factor; /* largest h_samp_factor */
  144719. int max_v_samp_factor; /* largest v_samp_factor */
  144720. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144721. int comps_in_scan; /* # of JPEG components in this scan */
  144722. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144723. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144724. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144725. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144726. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144727. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144728. struct jpeg_comp_master * master;
  144729. struct jpeg_c_main_controller * main;
  144730. struct jpeg_c_prep_controller * prep;
  144731. struct jpeg_c_coef_controller * coef;
  144732. struct jpeg_marker_writer * marker;
  144733. struct jpeg_color_converter * cconvert;
  144734. struct jpeg_downsampler * downsample;
  144735. struct jpeg_forward_dct * fdct;
  144736. struct jpeg_entropy_encoder * entropy;
  144737. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144738. int script_space_size;
  144739. };
  144740. struct jpeg_decompress_struct {
  144741. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144742. struct jpeg_source_mgr * src;
  144743. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144744. JDIMENSION image_height; /* nominal image height */
  144745. int num_components; /* # of color components in JPEG image */
  144746. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144747. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144748. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144749. double output_gamma; /* image gamma wanted in output */
  144750. boolean buffered_image; /* TRUE=multiple output passes */
  144751. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144752. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144753. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144754. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144755. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144756. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144757. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144758. int desired_number_of_colors; /* max # colors to use in created colormap */
  144759. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144760. boolean enable_external_quant;/* enable future use of external colormap */
  144761. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144762. JDIMENSION output_width; /* scaled image width */
  144763. JDIMENSION output_height; /* scaled image height */
  144764. int out_color_components; /* # of color components in out_color_space */
  144765. int output_components; /* # of color components returned */
  144766. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144767. int actual_number_of_colors; /* number of entries in use */
  144768. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144769. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144770. int input_scan_number; /* Number of SOS markers seen so far */
  144771. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144772. int output_scan_number; /* Nominal scan number being displayed */
  144773. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144774. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144775. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144776. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144777. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144778. int data_precision; /* bits of precision in image data */
  144779. jpeg_component_info * comp_info;
  144780. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144781. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144782. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144783. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144784. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144785. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144786. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144787. UINT8 JFIF_major_version; /* JFIF version number */
  144788. UINT8 JFIF_minor_version;
  144789. UINT8 density_unit; /* JFIF code for pixel size units */
  144790. UINT16 X_density; /* Horizontal pixel density */
  144791. UINT16 Y_density; /* Vertical pixel density */
  144792. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144793. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144794. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144795. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144796. int max_h_samp_factor; /* largest h_samp_factor */
  144797. int max_v_samp_factor; /* largest v_samp_factor */
  144798. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144799. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144800. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144801. int comps_in_scan; /* # of JPEG components in this scan */
  144802. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144803. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144804. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144805. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144806. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144807. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144808. int unread_marker;
  144809. struct jpeg_decomp_master * master;
  144810. struct jpeg_d_main_controller * main;
  144811. struct jpeg_d_coef_controller * coef;
  144812. struct jpeg_d_post_controller * post;
  144813. struct jpeg_input_controller * inputctl;
  144814. struct jpeg_marker_reader * marker;
  144815. struct jpeg_entropy_decoder * entropy;
  144816. struct jpeg_inverse_dct * idct;
  144817. struct jpeg_upsampler * upsample;
  144818. struct jpeg_color_deconverter * cconvert;
  144819. struct jpeg_color_quantizer * cquantize;
  144820. };
  144821. struct jpeg_error_mgr {
  144822. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144823. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144824. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144825. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144826. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144827. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144828. int msg_code;
  144829. #define JMSG_STR_PARM_MAX 80
  144830. union {
  144831. int i[8];
  144832. char s[JMSG_STR_PARM_MAX];
  144833. } msg_parm;
  144834. int trace_level; /* max msg_level that will be displayed */
  144835. long num_warnings; /* number of corrupt-data warnings */
  144836. const char * const * jpeg_message_table; /* Library errors */
  144837. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144838. const char * const * addon_message_table; /* Non-library errors */
  144839. int first_addon_message; /* code for first string in addon table */
  144840. int last_addon_message; /* code for last string in addon table */
  144841. };
  144842. struct jpeg_progress_mgr {
  144843. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144844. long pass_counter; /* work units completed in this pass */
  144845. long pass_limit; /* total number of work units in this pass */
  144846. int completed_passes; /* passes completed so far */
  144847. int total_passes; /* total number of passes expected */
  144848. };
  144849. struct jpeg_destination_mgr {
  144850. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144851. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144852. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144853. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144854. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144855. };
  144856. struct jpeg_source_mgr {
  144857. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144858. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144859. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144860. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144861. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144862. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144863. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144864. };
  144865. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144866. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144867. #define JPOOL_NUMPOOLS 2
  144868. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144869. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144870. struct jpeg_memory_mgr {
  144871. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144872. size_t sizeofobject));
  144873. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144874. size_t sizeofobject));
  144875. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144876. JDIMENSION samplesperrow,
  144877. JDIMENSION numrows));
  144878. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144879. JDIMENSION blocksperrow,
  144880. JDIMENSION numrows));
  144881. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144882. int pool_id,
  144883. boolean pre_zero,
  144884. JDIMENSION samplesperrow,
  144885. JDIMENSION numrows,
  144886. JDIMENSION maxaccess));
  144887. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144888. int pool_id,
  144889. boolean pre_zero,
  144890. JDIMENSION blocksperrow,
  144891. JDIMENSION numrows,
  144892. JDIMENSION maxaccess));
  144893. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144894. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144895. jvirt_sarray_ptr ptr,
  144896. JDIMENSION start_row,
  144897. JDIMENSION num_rows,
  144898. boolean writable));
  144899. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144900. jvirt_barray_ptr ptr,
  144901. JDIMENSION start_row,
  144902. JDIMENSION num_rows,
  144903. boolean writable));
  144904. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144905. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144906. long max_memory_to_use;
  144907. long max_alloc_chunk;
  144908. };
  144909. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144910. #ifdef HAVE_PROTOTYPES
  144911. #define JPP(arglist) arglist
  144912. #else
  144913. #define JPP(arglist) ()
  144914. #endif
  144915. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144916. #define jpeg_std_error jStdError
  144917. #define jpeg_CreateCompress jCreaCompress
  144918. #define jpeg_CreateDecompress jCreaDecompress
  144919. #define jpeg_destroy_compress jDestCompress
  144920. #define jpeg_destroy_decompress jDestDecompress
  144921. #define jpeg_stdio_dest jStdDest
  144922. #define jpeg_stdio_src jStdSrc
  144923. #define jpeg_set_defaults jSetDefaults
  144924. #define jpeg_set_colorspace jSetColorspace
  144925. #define jpeg_default_colorspace jDefColorspace
  144926. #define jpeg_set_quality jSetQuality
  144927. #define jpeg_set_linear_quality jSetLQuality
  144928. #define jpeg_add_quant_table jAddQuantTable
  144929. #define jpeg_quality_scaling jQualityScaling
  144930. #define jpeg_simple_progression jSimProgress
  144931. #define jpeg_suppress_tables jSuppressTables
  144932. #define jpeg_alloc_quant_table jAlcQTable
  144933. #define jpeg_alloc_huff_table jAlcHTable
  144934. #define jpeg_start_compress jStrtCompress
  144935. #define jpeg_write_scanlines jWrtScanlines
  144936. #define jpeg_finish_compress jFinCompress
  144937. #define jpeg_write_raw_data jWrtRawData
  144938. #define jpeg_write_marker jWrtMarker
  144939. #define jpeg_write_m_header jWrtMHeader
  144940. #define jpeg_write_m_byte jWrtMByte
  144941. #define jpeg_write_tables jWrtTables
  144942. #define jpeg_read_header jReadHeader
  144943. #define jpeg_start_decompress jStrtDecompress
  144944. #define jpeg_read_scanlines jReadScanlines
  144945. #define jpeg_finish_decompress jFinDecompress
  144946. #define jpeg_read_raw_data jReadRawData
  144947. #define jpeg_has_multiple_scans jHasMultScn
  144948. #define jpeg_start_output jStrtOutput
  144949. #define jpeg_finish_output jFinOutput
  144950. #define jpeg_input_complete jInComplete
  144951. #define jpeg_new_colormap jNewCMap
  144952. #define jpeg_consume_input jConsumeInput
  144953. #define jpeg_calc_output_dimensions jCalcDimensions
  144954. #define jpeg_save_markers jSaveMarkers
  144955. #define jpeg_set_marker_processor jSetMarker
  144956. #define jpeg_read_coefficients jReadCoefs
  144957. #define jpeg_write_coefficients jWrtCoefs
  144958. #define jpeg_copy_critical_parameters jCopyCrit
  144959. #define jpeg_abort_compress jAbrtCompress
  144960. #define jpeg_abort_decompress jAbrtDecompress
  144961. #define jpeg_abort jAbort
  144962. #define jpeg_destroy jDestroy
  144963. #define jpeg_resync_to_restart jResyncRestart
  144964. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  144965. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  144966. JPP((struct jpeg_error_mgr * err));
  144967. #define jpeg_create_compress(cinfo) \
  144968. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  144969. (size_t) sizeof(struct jpeg_compress_struct))
  144970. #define jpeg_create_decompress(cinfo) \
  144971. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  144972. (size_t) sizeof(struct jpeg_decompress_struct))
  144973. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  144974. int version, size_t structsize));
  144975. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  144976. int version, size_t structsize));
  144977. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  144978. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  144979. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  144980. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  144981. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  144982. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  144983. J_COLOR_SPACE colorspace));
  144984. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  144985. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  144986. boolean force_baseline));
  144987. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  144988. int scale_factor,
  144989. boolean force_baseline));
  144990. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  144991. const unsigned int *basic_table,
  144992. int scale_factor,
  144993. boolean force_baseline));
  144994. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  144995. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  144996. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  144997. boolean suppress));
  144998. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  144999. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145000. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145001. boolean write_all_tables));
  145002. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145003. JSAMPARRAY scanlines,
  145004. JDIMENSION num_lines));
  145005. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145006. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145007. JSAMPIMAGE data,
  145008. JDIMENSION num_lines));
  145009. EXTERN(void) jpeg_write_marker
  145010. JPP((j_compress_ptr cinfo, int marker,
  145011. const JOCTET * dataptr, unsigned int datalen));
  145012. EXTERN(void) jpeg_write_m_header
  145013. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145014. EXTERN(void) jpeg_write_m_byte
  145015. JPP((j_compress_ptr cinfo, int val));
  145016. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145017. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145018. boolean require_image));
  145019. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145020. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145021. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145022. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145023. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145024. JSAMPARRAY scanlines,
  145025. JDIMENSION max_lines));
  145026. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145027. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145028. JSAMPIMAGE data,
  145029. JDIMENSION max_lines));
  145030. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145031. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145032. int scan_number));
  145033. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145034. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145035. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145036. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145037. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145038. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145039. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145040. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145041. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145042. EXTERN(void) jpeg_save_markers
  145043. JPP((j_decompress_ptr cinfo, int marker_code,
  145044. unsigned int length_limit));
  145045. EXTERN(void) jpeg_set_marker_processor
  145046. JPP((j_decompress_ptr cinfo, int marker_code,
  145047. jpeg_marker_parser_method routine));
  145048. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145049. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145050. jvirt_barray_ptr * coef_arrays));
  145051. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145052. j_compress_ptr dstinfo));
  145053. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145054. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145055. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145056. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145057. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145058. int desired));
  145059. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145060. #define JPEG_EOI 0xD9 /* EOI marker code */
  145061. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145062. #define JPEG_COM 0xFE /* COM marker code */
  145063. #ifdef INCOMPLETE_TYPES_BROKEN
  145064. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145065. struct jvirt_sarray_control { long dummy; };
  145066. struct jvirt_barray_control { long dummy; };
  145067. struct jpeg_comp_master { long dummy; };
  145068. struct jpeg_c_main_controller { long dummy; };
  145069. struct jpeg_c_prep_controller { long dummy; };
  145070. struct jpeg_c_coef_controller { long dummy; };
  145071. struct jpeg_marker_writer { long dummy; };
  145072. struct jpeg_color_converter { long dummy; };
  145073. struct jpeg_downsampler { long dummy; };
  145074. struct jpeg_forward_dct { long dummy; };
  145075. struct jpeg_entropy_encoder { long dummy; };
  145076. struct jpeg_decomp_master { long dummy; };
  145077. struct jpeg_d_main_controller { long dummy; };
  145078. struct jpeg_d_coef_controller { long dummy; };
  145079. struct jpeg_d_post_controller { long dummy; };
  145080. struct jpeg_input_controller { long dummy; };
  145081. struct jpeg_marker_reader { long dummy; };
  145082. struct jpeg_entropy_decoder { long dummy; };
  145083. struct jpeg_inverse_dct { long dummy; };
  145084. struct jpeg_upsampler { long dummy; };
  145085. struct jpeg_color_deconverter { long dummy; };
  145086. struct jpeg_color_quantizer { long dummy; };
  145087. #endif /* JPEG_INTERNALS */
  145088. #endif /* INCOMPLETE_TYPES_BROKEN */
  145089. #ifdef JPEG_INTERNALS
  145090. /*** Start of inlined file: jpegint.h ***/
  145091. typedef enum { /* Operating modes for buffer controllers */
  145092. JBUF_PASS_THRU, /* Plain stripwise operation */
  145093. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145094. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145095. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145096. } J_BUF_MODE;
  145097. #define CSTATE_START 100 /* after create_compress */
  145098. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145099. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145100. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145101. #define DSTATE_START 200 /* after create_decompress */
  145102. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145103. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145104. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145105. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145106. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145107. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145108. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145109. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145110. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145111. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145112. struct jpeg_comp_master {
  145113. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145114. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145115. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145116. boolean call_pass_startup; /* True if pass_startup must be called */
  145117. boolean is_last_pass; /* True during last pass */
  145118. };
  145119. struct jpeg_c_main_controller {
  145120. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145121. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145122. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145123. JDIMENSION in_rows_avail));
  145124. };
  145125. struct jpeg_c_prep_controller {
  145126. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145127. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145128. JSAMPARRAY input_buf,
  145129. JDIMENSION *in_row_ctr,
  145130. JDIMENSION in_rows_avail,
  145131. JSAMPIMAGE output_buf,
  145132. JDIMENSION *out_row_group_ctr,
  145133. JDIMENSION out_row_groups_avail));
  145134. };
  145135. struct jpeg_c_coef_controller {
  145136. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145137. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145138. JSAMPIMAGE input_buf));
  145139. };
  145140. struct jpeg_color_converter {
  145141. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145142. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145143. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145144. JDIMENSION output_row, int num_rows));
  145145. };
  145146. struct jpeg_downsampler {
  145147. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145148. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145149. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145150. JSAMPIMAGE output_buf,
  145151. JDIMENSION out_row_group_index));
  145152. boolean need_context_rows; /* TRUE if need rows above & below */
  145153. };
  145154. struct jpeg_forward_dct {
  145155. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145156. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145157. jpeg_component_info * compptr,
  145158. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145159. JDIMENSION start_row, JDIMENSION start_col,
  145160. JDIMENSION num_blocks));
  145161. };
  145162. struct jpeg_entropy_encoder {
  145163. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145164. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145165. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145166. };
  145167. struct jpeg_marker_writer {
  145168. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145169. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145170. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145171. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145172. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145173. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145174. unsigned int datalen));
  145175. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145176. };
  145177. struct jpeg_decomp_master {
  145178. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145179. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145180. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145181. };
  145182. struct jpeg_input_controller {
  145183. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145184. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145185. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145186. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145187. boolean has_multiple_scans; /* True if file has multiple scans */
  145188. boolean eoi_reached; /* True when EOI has been consumed */
  145189. };
  145190. struct jpeg_d_main_controller {
  145191. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145192. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145193. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145194. JDIMENSION out_rows_avail));
  145195. };
  145196. struct jpeg_d_coef_controller {
  145197. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145198. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145199. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145200. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145201. JSAMPIMAGE output_buf));
  145202. jvirt_barray_ptr *coef_arrays;
  145203. };
  145204. struct jpeg_d_post_controller {
  145205. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145206. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145207. JSAMPIMAGE input_buf,
  145208. JDIMENSION *in_row_group_ctr,
  145209. JDIMENSION in_row_groups_avail,
  145210. JSAMPARRAY output_buf,
  145211. JDIMENSION *out_row_ctr,
  145212. JDIMENSION out_rows_avail));
  145213. };
  145214. struct jpeg_marker_reader {
  145215. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145216. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145217. jpeg_marker_parser_method read_restart_marker;
  145218. boolean saw_SOI; /* found SOI? */
  145219. boolean saw_SOF; /* found SOF? */
  145220. int next_restart_num; /* next restart number expected (0-7) */
  145221. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145222. };
  145223. struct jpeg_entropy_decoder {
  145224. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145225. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145226. JBLOCKROW *MCU_data));
  145227. boolean insufficient_data; /* set TRUE after emitting warning */
  145228. };
  145229. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145230. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145231. JCOEFPTR coef_block,
  145232. JSAMPARRAY output_buf, JDIMENSION output_col));
  145233. struct jpeg_inverse_dct {
  145234. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145235. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145236. };
  145237. struct jpeg_upsampler {
  145238. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145239. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145240. JSAMPIMAGE input_buf,
  145241. JDIMENSION *in_row_group_ctr,
  145242. JDIMENSION in_row_groups_avail,
  145243. JSAMPARRAY output_buf,
  145244. JDIMENSION *out_row_ctr,
  145245. JDIMENSION out_rows_avail));
  145246. boolean need_context_rows; /* TRUE if need rows above & below */
  145247. };
  145248. struct jpeg_color_deconverter {
  145249. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145250. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145251. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145252. JSAMPARRAY output_buf, int num_rows));
  145253. };
  145254. struct jpeg_color_quantizer {
  145255. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145256. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145257. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145258. int num_rows));
  145259. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145260. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145261. };
  145262. #undef MAX
  145263. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145264. #undef MIN
  145265. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145266. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145267. #define SHIFT_TEMPS INT32 shift_temp;
  145268. #define RIGHT_SHIFT(x,shft) \
  145269. ((shift_temp = (x)) < 0 ? \
  145270. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145271. (shift_temp >> (shft)))
  145272. #else
  145273. #define SHIFT_TEMPS
  145274. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145275. #endif
  145276. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145277. #define jinit_compress_master jICompress
  145278. #define jinit_c_master_control jICMaster
  145279. #define jinit_c_main_controller jICMainC
  145280. #define jinit_c_prep_controller jICPrepC
  145281. #define jinit_c_coef_controller jICCoefC
  145282. #define jinit_color_converter jICColor
  145283. #define jinit_downsampler jIDownsampler
  145284. #define jinit_forward_dct jIFDCT
  145285. #define jinit_huff_encoder jIHEncoder
  145286. #define jinit_phuff_encoder jIPHEncoder
  145287. #define jinit_marker_writer jIMWriter
  145288. #define jinit_master_decompress jIDMaster
  145289. #define jinit_d_main_controller jIDMainC
  145290. #define jinit_d_coef_controller jIDCoefC
  145291. #define jinit_d_post_controller jIDPostC
  145292. #define jinit_input_controller jIInCtlr
  145293. #define jinit_marker_reader jIMReader
  145294. #define jinit_huff_decoder jIHDecoder
  145295. #define jinit_phuff_decoder jIPHDecoder
  145296. #define jinit_inverse_dct jIIDCT
  145297. #define jinit_upsampler jIUpsampler
  145298. #define jinit_color_deconverter jIDColor
  145299. #define jinit_1pass_quantizer jI1Quant
  145300. #define jinit_2pass_quantizer jI2Quant
  145301. #define jinit_merged_upsampler jIMUpsampler
  145302. #define jinit_memory_mgr jIMemMgr
  145303. #define jdiv_round_up jDivRound
  145304. #define jround_up jRound
  145305. #define jcopy_sample_rows jCopySamples
  145306. #define jcopy_block_row jCopyBlocks
  145307. #define jzero_far jZeroFar
  145308. #define jpeg_zigzag_order jZIGTable
  145309. #define jpeg_natural_order jZAGTable
  145310. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145311. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145312. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145313. boolean transcode_only));
  145314. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145315. boolean need_full_buffer));
  145316. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145317. boolean need_full_buffer));
  145318. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145319. boolean need_full_buffer));
  145320. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145321. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145322. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145323. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145324. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145325. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145326. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145327. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145328. boolean need_full_buffer));
  145329. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145330. boolean need_full_buffer));
  145331. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145332. boolean need_full_buffer));
  145333. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145334. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145335. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145336. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145337. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145338. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145339. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145340. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145341. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145342. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145343. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145344. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145345. EXTERN(long) jround_up JPP((long a, long b));
  145346. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145347. JSAMPARRAY output_array, int dest_row,
  145348. int num_rows, JDIMENSION num_cols));
  145349. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145350. JDIMENSION num_blocks));
  145351. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145352. #if 0 /* This table is not actually needed in v6a */
  145353. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145354. #endif
  145355. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145356. #ifdef INCOMPLETE_TYPES_BROKEN
  145357. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145358. struct jvirt_sarray_control { long dummy; };
  145359. struct jvirt_barray_control { long dummy; };
  145360. #endif
  145361. #endif /* INCOMPLETE_TYPES_BROKEN */
  145362. /*** End of inlined file: jpegint.h ***/
  145363. /* fetch private declarations */
  145364. /*** Start of inlined file: jerror.h ***/
  145365. #ifndef JMESSAGE
  145366. #ifndef JERROR_H
  145367. #define JMAKE_ENUM_LIST
  145368. #else
  145369. #define JMESSAGE(code,string)
  145370. #endif /* JERROR_H */
  145371. #endif /* JMESSAGE */
  145372. #ifdef JMAKE_ENUM_LIST
  145373. typedef enum {
  145374. #define JMESSAGE(code,string) code ,
  145375. #endif /* JMAKE_ENUM_LIST */
  145376. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145377. JMESSAGE(JERR_ARITH_NOTIMPL,
  145378. "Sorry, there are legal restrictions on arithmetic coding")
  145379. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145380. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145381. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145382. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145383. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145384. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145385. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145386. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145387. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145388. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145389. JMESSAGE(JERR_BAD_LIB_VERSION,
  145390. "Wrong JPEG library version: library is %d, caller expects %d")
  145391. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145392. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145393. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145394. JMESSAGE(JERR_BAD_PROGRESSION,
  145395. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145396. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145397. "Invalid progressive parameters at scan script entry %d")
  145398. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145399. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145400. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145401. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145402. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145403. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145404. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145405. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145406. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145407. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145408. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145409. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145410. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145411. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145412. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145413. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145414. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145415. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145416. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145417. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145418. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145419. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145420. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145421. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145422. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145423. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145424. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145425. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145426. "Cannot transcode due to multiple use of quantization table %d")
  145427. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145428. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145429. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145430. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145431. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145432. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145433. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145434. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145435. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145436. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145437. JMESSAGE(JERR_QUANT_COMPONENTS,
  145438. "Cannot quantize more than %d color components")
  145439. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145440. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145441. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145442. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145443. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145444. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145445. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145446. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145447. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145448. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145449. JMESSAGE(JERR_TFILE_WRITE,
  145450. "Write failed on temporary file --- out of disk space?")
  145451. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145452. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145453. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145454. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145455. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145456. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145457. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145458. JMESSAGE(JMSG_VERSION, JVERSION)
  145459. JMESSAGE(JTRC_16BIT_TABLES,
  145460. "Caution: quantization tables are too coarse for baseline JPEG")
  145461. JMESSAGE(JTRC_ADOBE,
  145462. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145463. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145464. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145465. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145466. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145467. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145468. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145469. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145470. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145471. JMESSAGE(JTRC_EOI, "End Of Image")
  145472. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145473. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145474. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145475. "Warning: thumbnail image size does not match data length %u")
  145476. JMESSAGE(JTRC_JFIF_EXTENSION,
  145477. "JFIF extension marker: type 0x%02x, length %u")
  145478. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145479. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145480. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145481. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145482. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145483. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145484. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145485. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145486. JMESSAGE(JTRC_RST, "RST%d")
  145487. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145488. "Smoothing not supported with nonstandard sampling ratios")
  145489. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145490. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145491. JMESSAGE(JTRC_SOI, "Start of Image")
  145492. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145493. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145494. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145495. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145496. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145497. JMESSAGE(JTRC_THUMB_JPEG,
  145498. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145499. JMESSAGE(JTRC_THUMB_PALETTE,
  145500. "JFIF extension marker: palette thumbnail image, length %u")
  145501. JMESSAGE(JTRC_THUMB_RGB,
  145502. "JFIF extension marker: RGB thumbnail image, length %u")
  145503. JMESSAGE(JTRC_UNKNOWN_IDS,
  145504. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145505. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145506. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145507. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145508. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145509. "Inconsistent progression sequence for component %d coefficient %d")
  145510. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145511. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145512. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145513. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145514. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145515. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145516. JMESSAGE(JWRN_MUST_RESYNC,
  145517. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145518. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145519. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145520. #ifdef JMAKE_ENUM_LIST
  145521. JMSG_LASTMSGCODE
  145522. } J_MESSAGE_CODE;
  145523. #undef JMAKE_ENUM_LIST
  145524. #endif /* JMAKE_ENUM_LIST */
  145525. #undef JMESSAGE
  145526. #ifndef JERROR_H
  145527. #define JERROR_H
  145528. #define ERREXIT(cinfo,code) \
  145529. ((cinfo)->err->msg_code = (code), \
  145530. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145531. #define ERREXIT1(cinfo,code,p1) \
  145532. ((cinfo)->err->msg_code = (code), \
  145533. (cinfo)->err->msg_parm.i[0] = (p1), \
  145534. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145535. #define ERREXIT2(cinfo,code,p1,p2) \
  145536. ((cinfo)->err->msg_code = (code), \
  145537. (cinfo)->err->msg_parm.i[0] = (p1), \
  145538. (cinfo)->err->msg_parm.i[1] = (p2), \
  145539. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145540. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145541. ((cinfo)->err->msg_code = (code), \
  145542. (cinfo)->err->msg_parm.i[0] = (p1), \
  145543. (cinfo)->err->msg_parm.i[1] = (p2), \
  145544. (cinfo)->err->msg_parm.i[2] = (p3), \
  145545. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145546. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145547. ((cinfo)->err->msg_code = (code), \
  145548. (cinfo)->err->msg_parm.i[0] = (p1), \
  145549. (cinfo)->err->msg_parm.i[1] = (p2), \
  145550. (cinfo)->err->msg_parm.i[2] = (p3), \
  145551. (cinfo)->err->msg_parm.i[3] = (p4), \
  145552. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145553. #define ERREXITS(cinfo,code,str) \
  145554. ((cinfo)->err->msg_code = (code), \
  145555. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145556. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145557. #define MAKESTMT(stuff) do { stuff } while (0)
  145558. #define WARNMS(cinfo,code) \
  145559. ((cinfo)->err->msg_code = (code), \
  145560. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145561. #define WARNMS1(cinfo,code,p1) \
  145562. ((cinfo)->err->msg_code = (code), \
  145563. (cinfo)->err->msg_parm.i[0] = (p1), \
  145564. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145565. #define WARNMS2(cinfo,code,p1,p2) \
  145566. ((cinfo)->err->msg_code = (code), \
  145567. (cinfo)->err->msg_parm.i[0] = (p1), \
  145568. (cinfo)->err->msg_parm.i[1] = (p2), \
  145569. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145570. #define TRACEMS(cinfo,lvl,code) \
  145571. ((cinfo)->err->msg_code = (code), \
  145572. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145573. #define TRACEMS1(cinfo,lvl,code,p1) \
  145574. ((cinfo)->err->msg_code = (code), \
  145575. (cinfo)->err->msg_parm.i[0] = (p1), \
  145576. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145577. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145578. ((cinfo)->err->msg_code = (code), \
  145579. (cinfo)->err->msg_parm.i[0] = (p1), \
  145580. (cinfo)->err->msg_parm.i[1] = (p2), \
  145581. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145582. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145583. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145584. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145585. (cinfo)->err->msg_code = (code); \
  145586. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145587. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145588. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145589. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145590. (cinfo)->err->msg_code = (code); \
  145591. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145592. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145593. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145594. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145595. _mp[4] = (p5); \
  145596. (cinfo)->err->msg_code = (code); \
  145597. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145598. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145599. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145600. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145601. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145602. (cinfo)->err->msg_code = (code); \
  145603. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145604. #define TRACEMSS(cinfo,lvl,code,str) \
  145605. ((cinfo)->err->msg_code = (code), \
  145606. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145607. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145608. #endif /* JERROR_H */
  145609. /*** End of inlined file: jerror.h ***/
  145610. /* fetch error codes too */
  145611. #endif
  145612. #endif /* JPEGLIB_H */
  145613. /*** End of inlined file: jpeglib.h ***/
  145614. /*** Start of inlined file: jcapimin.c ***/
  145615. #define JPEG_INTERNALS
  145616. /*** Start of inlined file: jinclude.h ***/
  145617. #ifndef __jinclude_h__
  145618. #define __jinclude_h__
  145619. /*** Start of inlined file: jconfig.h ***/
  145620. // disable all the warnings under MSVC
  145621. #ifdef _MSC_VER
  145622. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145623. #endif
  145624. #ifdef __BORLANDC__
  145625. #pragma warn -8057
  145626. #pragma warn -8019
  145627. #pragma warn -8004
  145628. #pragma warn -8008
  145629. #endif
  145630. #define HAVE_PROTOTYPES
  145631. #define HAVE_UNSIGNED_CHAR
  145632. #define HAVE_UNSIGNED_SHORT
  145633. #undef CHAR_IS_UNSIGNED
  145634. #define HAVE_STDDEF_H
  145635. #define HAVE_STDLIB_H
  145636. #undef NEED_BSD_STRINGS
  145637. #undef NEED_SYS_TYPES_H
  145638. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145639. #undef NEED_SHORT_EXTERNAL_NAMES
  145640. #undef INCOMPLETE_TYPES_BROKEN
  145641. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145642. typedef unsigned char boolean;
  145643. #endif
  145644. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145645. #ifdef JPEG_INTERNALS
  145646. #undef RIGHT_SHIFT_IS_UNSIGNED
  145647. #endif /* JPEG_INTERNALS */
  145648. #ifdef JPEG_CJPEG_DJPEG
  145649. #define BMP_SUPPORTED /* BMP image file format */
  145650. #define GIF_SUPPORTED /* GIF image file format */
  145651. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145652. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145653. #define TARGA_SUPPORTED /* Targa image file format */
  145654. #define TWO_FILE_COMMANDLINE /* optional */
  145655. #define USE_SETMODE /* Microsoft has setmode() */
  145656. #undef NEED_SIGNAL_CATCHER
  145657. #undef DONT_USE_B_MODE
  145658. #undef PROGRESS_REPORT /* optional */
  145659. #endif /* JPEG_CJPEG_DJPEG */
  145660. /*** End of inlined file: jconfig.h ***/
  145661. /* auto configuration options */
  145662. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145663. #ifdef HAVE_STDDEF_H
  145664. #include <stddef.h>
  145665. #endif
  145666. #ifdef HAVE_STDLIB_H
  145667. #include <stdlib.h>
  145668. #endif
  145669. #ifdef NEED_SYS_TYPES_H
  145670. #include <sys/types.h>
  145671. #endif
  145672. #include <stdio.h>
  145673. #ifdef NEED_BSD_STRINGS
  145674. #include <strings.h>
  145675. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145676. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145677. #else /* not BSD, assume ANSI/SysV string lib */
  145678. #include <string.h>
  145679. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145680. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145681. #endif
  145682. #define SIZEOF(object) ((size_t) sizeof(object))
  145683. #define JFREAD(file,buf,sizeofbuf) \
  145684. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145685. #define JFWRITE(file,buf,sizeofbuf) \
  145686. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145687. typedef enum { /* JPEG marker codes */
  145688. M_SOF0 = 0xc0,
  145689. M_SOF1 = 0xc1,
  145690. M_SOF2 = 0xc2,
  145691. M_SOF3 = 0xc3,
  145692. M_SOF5 = 0xc5,
  145693. M_SOF6 = 0xc6,
  145694. M_SOF7 = 0xc7,
  145695. M_JPG = 0xc8,
  145696. M_SOF9 = 0xc9,
  145697. M_SOF10 = 0xca,
  145698. M_SOF11 = 0xcb,
  145699. M_SOF13 = 0xcd,
  145700. M_SOF14 = 0xce,
  145701. M_SOF15 = 0xcf,
  145702. M_DHT = 0xc4,
  145703. M_DAC = 0xcc,
  145704. M_RST0 = 0xd0,
  145705. M_RST1 = 0xd1,
  145706. M_RST2 = 0xd2,
  145707. M_RST3 = 0xd3,
  145708. M_RST4 = 0xd4,
  145709. M_RST5 = 0xd5,
  145710. M_RST6 = 0xd6,
  145711. M_RST7 = 0xd7,
  145712. M_SOI = 0xd8,
  145713. M_EOI = 0xd9,
  145714. M_SOS = 0xda,
  145715. M_DQT = 0xdb,
  145716. M_DNL = 0xdc,
  145717. M_DRI = 0xdd,
  145718. M_DHP = 0xde,
  145719. M_EXP = 0xdf,
  145720. M_APP0 = 0xe0,
  145721. M_APP1 = 0xe1,
  145722. M_APP2 = 0xe2,
  145723. M_APP3 = 0xe3,
  145724. M_APP4 = 0xe4,
  145725. M_APP5 = 0xe5,
  145726. M_APP6 = 0xe6,
  145727. M_APP7 = 0xe7,
  145728. M_APP8 = 0xe8,
  145729. M_APP9 = 0xe9,
  145730. M_APP10 = 0xea,
  145731. M_APP11 = 0xeb,
  145732. M_APP12 = 0xec,
  145733. M_APP13 = 0xed,
  145734. M_APP14 = 0xee,
  145735. M_APP15 = 0xef,
  145736. M_JPG0 = 0xf0,
  145737. M_JPG13 = 0xfd,
  145738. M_COM = 0xfe,
  145739. M_TEM = 0x01,
  145740. M_ERROR = 0x100
  145741. } JPEG_MARKER;
  145742. #ifdef AVOID_TABLES
  145743. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145744. #else
  145745. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145746. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145747. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145748. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145749. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145750. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145751. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145752. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145753. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145754. #endif /* AVOID_TABLES */
  145755. #endif
  145756. /*** End of inlined file: jinclude.h ***/
  145757. GLOBAL(void)
  145758. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145759. {
  145760. int i;
  145761. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145762. if (version != JPEG_LIB_VERSION)
  145763. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145764. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145765. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145766. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145767. {
  145768. struct jpeg_error_mgr * err = cinfo->err;
  145769. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145770. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145771. cinfo->err = err;
  145772. cinfo->client_data = client_data;
  145773. }
  145774. cinfo->is_decompressor = FALSE;
  145775. jinit_memory_mgr((j_common_ptr) cinfo);
  145776. cinfo->progress = NULL;
  145777. cinfo->dest = NULL;
  145778. cinfo->comp_info = NULL;
  145779. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145780. cinfo->quant_tbl_ptrs[i] = NULL;
  145781. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145782. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145783. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145784. }
  145785. cinfo->script_space = NULL;
  145786. cinfo->input_gamma = 1.0; /* in case application forgets */
  145787. cinfo->global_state = CSTATE_START;
  145788. }
  145789. GLOBAL(void)
  145790. jpeg_destroy_compress (j_compress_ptr cinfo)
  145791. {
  145792. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145793. }
  145794. GLOBAL(void)
  145795. jpeg_abort_compress (j_compress_ptr cinfo)
  145796. {
  145797. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145798. }
  145799. GLOBAL(void)
  145800. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145801. {
  145802. int i;
  145803. JQUANT_TBL * qtbl;
  145804. JHUFF_TBL * htbl;
  145805. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145806. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145807. qtbl->sent_table = suppress;
  145808. }
  145809. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145810. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145811. htbl->sent_table = suppress;
  145812. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145813. htbl->sent_table = suppress;
  145814. }
  145815. }
  145816. GLOBAL(void)
  145817. jpeg_finish_compress (j_compress_ptr cinfo)
  145818. {
  145819. JDIMENSION iMCU_row;
  145820. if (cinfo->global_state == CSTATE_SCANNING ||
  145821. cinfo->global_state == CSTATE_RAW_OK) {
  145822. if (cinfo->next_scanline < cinfo->image_height)
  145823. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145824. (*cinfo->master->finish_pass) (cinfo);
  145825. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145826. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145827. while (! cinfo->master->is_last_pass) {
  145828. (*cinfo->master->prepare_for_pass) (cinfo);
  145829. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145830. if (cinfo->progress != NULL) {
  145831. cinfo->progress->pass_counter = (long) iMCU_row;
  145832. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145833. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145834. }
  145835. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145836. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145837. }
  145838. (*cinfo->master->finish_pass) (cinfo);
  145839. }
  145840. (*cinfo->marker->write_file_trailer) (cinfo);
  145841. (*cinfo->dest->term_destination) (cinfo);
  145842. jpeg_abort((j_common_ptr) cinfo);
  145843. }
  145844. GLOBAL(void)
  145845. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145846. const JOCTET *dataptr, unsigned int datalen)
  145847. {
  145848. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145849. if (cinfo->next_scanline != 0 ||
  145850. (cinfo->global_state != CSTATE_SCANNING &&
  145851. cinfo->global_state != CSTATE_RAW_OK &&
  145852. cinfo->global_state != CSTATE_WRCOEFS))
  145853. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145854. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145855. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145856. while (datalen--) {
  145857. (*write_marker_byte) (cinfo, *dataptr);
  145858. dataptr++;
  145859. }
  145860. }
  145861. GLOBAL(void)
  145862. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145863. {
  145864. if (cinfo->next_scanline != 0 ||
  145865. (cinfo->global_state != CSTATE_SCANNING &&
  145866. cinfo->global_state != CSTATE_RAW_OK &&
  145867. cinfo->global_state != CSTATE_WRCOEFS))
  145868. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145869. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145870. }
  145871. GLOBAL(void)
  145872. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145873. {
  145874. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145875. }
  145876. GLOBAL(void)
  145877. jpeg_write_tables (j_compress_ptr cinfo)
  145878. {
  145879. if (cinfo->global_state != CSTATE_START)
  145880. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145881. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145882. (*cinfo->dest->init_destination) (cinfo);
  145883. jinit_marker_writer(cinfo);
  145884. (*cinfo->marker->write_tables_only) (cinfo);
  145885. (*cinfo->dest->term_destination) (cinfo);
  145886. }
  145887. /*** End of inlined file: jcapimin.c ***/
  145888. /*** Start of inlined file: jcapistd.c ***/
  145889. #define JPEG_INTERNALS
  145890. GLOBAL(void)
  145891. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145892. {
  145893. if (cinfo->global_state != CSTATE_START)
  145894. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145895. if (write_all_tables)
  145896. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145897. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145898. (*cinfo->dest->init_destination) (cinfo);
  145899. jinit_compress_master(cinfo);
  145900. (*cinfo->master->prepare_for_pass) (cinfo);
  145901. cinfo->next_scanline = 0;
  145902. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145903. }
  145904. GLOBAL(JDIMENSION)
  145905. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145906. JDIMENSION num_lines)
  145907. {
  145908. JDIMENSION row_ctr, rows_left;
  145909. if (cinfo->global_state != CSTATE_SCANNING)
  145910. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145911. if (cinfo->next_scanline >= cinfo->image_height)
  145912. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145913. if (cinfo->progress != NULL) {
  145914. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145915. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145916. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145917. }
  145918. if (cinfo->master->call_pass_startup)
  145919. (*cinfo->master->pass_startup) (cinfo);
  145920. rows_left = cinfo->image_height - cinfo->next_scanline;
  145921. if (num_lines > rows_left)
  145922. num_lines = rows_left;
  145923. row_ctr = 0;
  145924. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  145925. cinfo->next_scanline += row_ctr;
  145926. return row_ctr;
  145927. }
  145928. GLOBAL(JDIMENSION)
  145929. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  145930. JDIMENSION num_lines)
  145931. {
  145932. JDIMENSION lines_per_iMCU_row;
  145933. if (cinfo->global_state != CSTATE_RAW_OK)
  145934. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145935. if (cinfo->next_scanline >= cinfo->image_height) {
  145936. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145937. return 0;
  145938. }
  145939. if (cinfo->progress != NULL) {
  145940. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145941. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145942. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145943. }
  145944. if (cinfo->master->call_pass_startup)
  145945. (*cinfo->master->pass_startup) (cinfo);
  145946. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  145947. if (num_lines < lines_per_iMCU_row)
  145948. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  145949. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  145950. return 0;
  145951. }
  145952. cinfo->next_scanline += lines_per_iMCU_row;
  145953. return lines_per_iMCU_row;
  145954. }
  145955. /*** End of inlined file: jcapistd.c ***/
  145956. /*** Start of inlined file: jccoefct.c ***/
  145957. #define JPEG_INTERNALS
  145958. #ifdef ENTROPY_OPT_SUPPORTED
  145959. #define FULL_COEF_BUFFER_SUPPORTED
  145960. #else
  145961. #ifdef C_MULTISCAN_FILES_SUPPORTED
  145962. #define FULL_COEF_BUFFER_SUPPORTED
  145963. #endif
  145964. #endif
  145965. typedef struct {
  145966. struct jpeg_c_coef_controller pub; /* public fields */
  145967. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  145968. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  145969. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  145970. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  145971. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  145972. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  145973. } my_coef_controller;
  145974. typedef my_coef_controller * my_coef_ptr;
  145975. METHODDEF(boolean) compress_data
  145976. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145977. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145978. METHODDEF(boolean) compress_first_pass
  145979. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145980. METHODDEF(boolean) compress_output
  145981. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145982. #endif
  145983. LOCAL(void)
  145984. start_iMCU_row (j_compress_ptr cinfo)
  145985. {
  145986. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145987. if (cinfo->comps_in_scan > 1) {
  145988. coef->MCU_rows_per_iMCU_row = 1;
  145989. } else {
  145990. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  145991. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  145992. else
  145993. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  145994. }
  145995. coef->mcu_ctr = 0;
  145996. coef->MCU_vert_offset = 0;
  145997. }
  145998. METHODDEF(void)
  145999. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146000. {
  146001. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146002. coef->iMCU_row_num = 0;
  146003. start_iMCU_row(cinfo);
  146004. switch (pass_mode) {
  146005. case JBUF_PASS_THRU:
  146006. if (coef->whole_image[0] != NULL)
  146007. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146008. coef->pub.compress_data = compress_data;
  146009. break;
  146010. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146011. case JBUF_SAVE_AND_PASS:
  146012. if (coef->whole_image[0] == NULL)
  146013. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146014. coef->pub.compress_data = compress_first_pass;
  146015. break;
  146016. case JBUF_CRANK_DEST:
  146017. if (coef->whole_image[0] == NULL)
  146018. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146019. coef->pub.compress_data = compress_output;
  146020. break;
  146021. #endif
  146022. default:
  146023. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146024. break;
  146025. }
  146026. }
  146027. METHODDEF(boolean)
  146028. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146029. {
  146030. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146031. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146032. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146033. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146034. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146035. JDIMENSION ypos, xpos;
  146036. jpeg_component_info *compptr;
  146037. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146038. yoffset++) {
  146039. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146040. MCU_col_num++) {
  146041. blkn = 0;
  146042. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146043. compptr = cinfo->cur_comp_info[ci];
  146044. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146045. : compptr->last_col_width;
  146046. xpos = MCU_col_num * compptr->MCU_sample_width;
  146047. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146048. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146049. if (coef->iMCU_row_num < last_iMCU_row ||
  146050. yoffset+yindex < compptr->last_row_height) {
  146051. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146052. input_buf[compptr->component_index],
  146053. coef->MCU_buffer[blkn],
  146054. ypos, xpos, (JDIMENSION) blockcnt);
  146055. if (blockcnt < compptr->MCU_width) {
  146056. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146057. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146058. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146059. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146060. }
  146061. }
  146062. } else {
  146063. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146064. compptr->MCU_width * SIZEOF(JBLOCK));
  146065. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146066. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146067. }
  146068. }
  146069. blkn += compptr->MCU_width;
  146070. ypos += DCTSIZE;
  146071. }
  146072. }
  146073. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146074. coef->MCU_vert_offset = yoffset;
  146075. coef->mcu_ctr = MCU_col_num;
  146076. return FALSE;
  146077. }
  146078. }
  146079. coef->mcu_ctr = 0;
  146080. }
  146081. coef->iMCU_row_num++;
  146082. start_iMCU_row(cinfo);
  146083. return TRUE;
  146084. }
  146085. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146086. METHODDEF(boolean)
  146087. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146088. {
  146089. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146090. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146091. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146092. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146093. JCOEF lastDC;
  146094. jpeg_component_info *compptr;
  146095. JBLOCKARRAY buffer;
  146096. JBLOCKROW thisblockrow, lastblockrow;
  146097. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146098. ci++, compptr++) {
  146099. buffer = (*cinfo->mem->access_virt_barray)
  146100. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146101. coef->iMCU_row_num * compptr->v_samp_factor,
  146102. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146103. if (coef->iMCU_row_num < last_iMCU_row)
  146104. block_rows = compptr->v_samp_factor;
  146105. else {
  146106. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146107. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146108. }
  146109. blocks_across = compptr->width_in_blocks;
  146110. h_samp_factor = compptr->h_samp_factor;
  146111. ndummy = (int) (blocks_across % h_samp_factor);
  146112. if (ndummy > 0)
  146113. ndummy = h_samp_factor - ndummy;
  146114. for (block_row = 0; block_row < block_rows; block_row++) {
  146115. thisblockrow = buffer[block_row];
  146116. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146117. input_buf[ci], thisblockrow,
  146118. (JDIMENSION) (block_row * DCTSIZE),
  146119. (JDIMENSION) 0, blocks_across);
  146120. if (ndummy > 0) {
  146121. thisblockrow += blocks_across; /* => first dummy block */
  146122. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146123. lastDC = thisblockrow[-1][0];
  146124. for (bi = 0; bi < ndummy; bi++) {
  146125. thisblockrow[bi][0] = lastDC;
  146126. }
  146127. }
  146128. }
  146129. if (coef->iMCU_row_num == last_iMCU_row) {
  146130. blocks_across += ndummy; /* include lower right corner */
  146131. MCUs_across = blocks_across / h_samp_factor;
  146132. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146133. block_row++) {
  146134. thisblockrow = buffer[block_row];
  146135. lastblockrow = buffer[block_row-1];
  146136. jzero_far((void FAR *) thisblockrow,
  146137. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146138. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146139. lastDC = lastblockrow[h_samp_factor-1][0];
  146140. for (bi = 0; bi < h_samp_factor; bi++) {
  146141. thisblockrow[bi][0] = lastDC;
  146142. }
  146143. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146144. lastblockrow += h_samp_factor;
  146145. }
  146146. }
  146147. }
  146148. }
  146149. return compress_output(cinfo, input_buf);
  146150. }
  146151. METHODDEF(boolean)
  146152. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146153. {
  146154. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146155. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146156. int blkn, ci, xindex, yindex, yoffset;
  146157. JDIMENSION start_col;
  146158. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146159. JBLOCKROW buffer_ptr;
  146160. jpeg_component_info *compptr;
  146161. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146162. compptr = cinfo->cur_comp_info[ci];
  146163. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146164. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146165. coef->iMCU_row_num * compptr->v_samp_factor,
  146166. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146167. }
  146168. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146169. yoffset++) {
  146170. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146171. MCU_col_num++) {
  146172. blkn = 0; /* index of current DCT block within MCU */
  146173. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146174. compptr = cinfo->cur_comp_info[ci];
  146175. start_col = MCU_col_num * compptr->MCU_width;
  146176. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146177. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146178. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146179. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146180. }
  146181. }
  146182. }
  146183. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146184. coef->MCU_vert_offset = yoffset;
  146185. coef->mcu_ctr = MCU_col_num;
  146186. return FALSE;
  146187. }
  146188. }
  146189. coef->mcu_ctr = 0;
  146190. }
  146191. coef->iMCU_row_num++;
  146192. start_iMCU_row(cinfo);
  146193. return TRUE;
  146194. }
  146195. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146196. GLOBAL(void)
  146197. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146198. {
  146199. my_coef_ptr coef;
  146200. coef = (my_coef_ptr)
  146201. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146202. SIZEOF(my_coef_controller));
  146203. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146204. coef->pub.start_pass = start_pass_coef;
  146205. if (need_full_buffer) {
  146206. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146207. int ci;
  146208. jpeg_component_info *compptr;
  146209. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146210. ci++, compptr++) {
  146211. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146212. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146213. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146214. (long) compptr->h_samp_factor),
  146215. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146216. (long) compptr->v_samp_factor),
  146217. (JDIMENSION) compptr->v_samp_factor);
  146218. }
  146219. #else
  146220. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146221. #endif
  146222. } else {
  146223. JBLOCKROW buffer;
  146224. int i;
  146225. buffer = (JBLOCKROW)
  146226. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146227. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146228. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146229. coef->MCU_buffer[i] = buffer + i;
  146230. }
  146231. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146232. }
  146233. }
  146234. /*** End of inlined file: jccoefct.c ***/
  146235. /*** Start of inlined file: jccolor.c ***/
  146236. #define JPEG_INTERNALS
  146237. typedef struct {
  146238. struct jpeg_color_converter pub; /* public fields */
  146239. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146240. } my_color_converter;
  146241. typedef my_color_converter * my_cconvert_ptr;
  146242. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146243. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146244. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146245. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146246. #define R_Y_OFF 0 /* offset to R => Y section */
  146247. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146248. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146249. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146250. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146251. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146252. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146253. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146254. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146255. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146256. METHODDEF(void)
  146257. rgb_ycc_start (j_compress_ptr cinfo)
  146258. {
  146259. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146260. INT32 * rgb_ycc_tab;
  146261. INT32 i;
  146262. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146263. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146264. (TABLE_SIZE * SIZEOF(INT32)));
  146265. for (i = 0; i <= MAXJSAMPLE; i++) {
  146266. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146267. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146268. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146269. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146270. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146271. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146272. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146273. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146274. }
  146275. }
  146276. METHODDEF(void)
  146277. rgb_ycc_convert (j_compress_ptr cinfo,
  146278. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146279. JDIMENSION output_row, int num_rows)
  146280. {
  146281. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146282. register int r, g, b;
  146283. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146284. register JSAMPROW inptr;
  146285. register JSAMPROW outptr0, outptr1, outptr2;
  146286. register JDIMENSION col;
  146287. JDIMENSION num_cols = cinfo->image_width;
  146288. while (--num_rows >= 0) {
  146289. inptr = *input_buf++;
  146290. outptr0 = output_buf[0][output_row];
  146291. outptr1 = output_buf[1][output_row];
  146292. outptr2 = output_buf[2][output_row];
  146293. output_row++;
  146294. for (col = 0; col < num_cols; col++) {
  146295. r = GETJSAMPLE(inptr[RGB_RED]);
  146296. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146297. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146298. inptr += RGB_PIXELSIZE;
  146299. outptr0[col] = (JSAMPLE)
  146300. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146301. >> SCALEBITS);
  146302. outptr1[col] = (JSAMPLE)
  146303. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146304. >> SCALEBITS);
  146305. outptr2[col] = (JSAMPLE)
  146306. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146307. >> SCALEBITS);
  146308. }
  146309. }
  146310. }
  146311. METHODDEF(void)
  146312. rgb_gray_convert (j_compress_ptr cinfo,
  146313. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146314. JDIMENSION output_row, int num_rows)
  146315. {
  146316. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146317. register int r, g, b;
  146318. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146319. register JSAMPROW inptr;
  146320. register JSAMPROW outptr;
  146321. register JDIMENSION col;
  146322. JDIMENSION num_cols = cinfo->image_width;
  146323. while (--num_rows >= 0) {
  146324. inptr = *input_buf++;
  146325. outptr = output_buf[0][output_row];
  146326. output_row++;
  146327. for (col = 0; col < num_cols; col++) {
  146328. r = GETJSAMPLE(inptr[RGB_RED]);
  146329. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146330. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146331. inptr += RGB_PIXELSIZE;
  146332. outptr[col] = (JSAMPLE)
  146333. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146334. >> SCALEBITS);
  146335. }
  146336. }
  146337. }
  146338. METHODDEF(void)
  146339. cmyk_ycck_convert (j_compress_ptr cinfo,
  146340. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146341. JDIMENSION output_row, int num_rows)
  146342. {
  146343. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146344. register int r, g, b;
  146345. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146346. register JSAMPROW inptr;
  146347. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146348. register JDIMENSION col;
  146349. JDIMENSION num_cols = cinfo->image_width;
  146350. while (--num_rows >= 0) {
  146351. inptr = *input_buf++;
  146352. outptr0 = output_buf[0][output_row];
  146353. outptr1 = output_buf[1][output_row];
  146354. outptr2 = output_buf[2][output_row];
  146355. outptr3 = output_buf[3][output_row];
  146356. output_row++;
  146357. for (col = 0; col < num_cols; col++) {
  146358. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146359. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146360. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146361. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146362. inptr += 4;
  146363. outptr0[col] = (JSAMPLE)
  146364. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146365. >> SCALEBITS);
  146366. outptr1[col] = (JSAMPLE)
  146367. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146368. >> SCALEBITS);
  146369. outptr2[col] = (JSAMPLE)
  146370. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146371. >> SCALEBITS);
  146372. }
  146373. }
  146374. }
  146375. METHODDEF(void)
  146376. grayscale_convert (j_compress_ptr cinfo,
  146377. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146378. JDIMENSION output_row, int num_rows)
  146379. {
  146380. register JSAMPROW inptr;
  146381. register JSAMPROW outptr;
  146382. register JDIMENSION col;
  146383. JDIMENSION num_cols = cinfo->image_width;
  146384. int instride = cinfo->input_components;
  146385. while (--num_rows >= 0) {
  146386. inptr = *input_buf++;
  146387. outptr = output_buf[0][output_row];
  146388. output_row++;
  146389. for (col = 0; col < num_cols; col++) {
  146390. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146391. inptr += instride;
  146392. }
  146393. }
  146394. }
  146395. METHODDEF(void)
  146396. null_convert (j_compress_ptr cinfo,
  146397. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146398. JDIMENSION output_row, int num_rows)
  146399. {
  146400. register JSAMPROW inptr;
  146401. register JSAMPROW outptr;
  146402. register JDIMENSION col;
  146403. register int ci;
  146404. int nc = cinfo->num_components;
  146405. JDIMENSION num_cols = cinfo->image_width;
  146406. while (--num_rows >= 0) {
  146407. for (ci = 0; ci < nc; ci++) {
  146408. inptr = *input_buf;
  146409. outptr = output_buf[ci][output_row];
  146410. for (col = 0; col < num_cols; col++) {
  146411. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146412. inptr += nc;
  146413. }
  146414. }
  146415. input_buf++;
  146416. output_row++;
  146417. }
  146418. }
  146419. METHODDEF(void)
  146420. null_method (j_compress_ptr cinfo)
  146421. {
  146422. }
  146423. GLOBAL(void)
  146424. jinit_color_converter (j_compress_ptr cinfo)
  146425. {
  146426. my_cconvert_ptr cconvert;
  146427. cconvert = (my_cconvert_ptr)
  146428. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146429. SIZEOF(my_color_converter));
  146430. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146431. cconvert->pub.start_pass = null_method;
  146432. switch (cinfo->in_color_space) {
  146433. case JCS_GRAYSCALE:
  146434. if (cinfo->input_components != 1)
  146435. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146436. break;
  146437. case JCS_RGB:
  146438. #if RGB_PIXELSIZE != 3
  146439. if (cinfo->input_components != RGB_PIXELSIZE)
  146440. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146441. break;
  146442. #endif /* else share code with YCbCr */
  146443. case JCS_YCbCr:
  146444. if (cinfo->input_components != 3)
  146445. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146446. break;
  146447. case JCS_CMYK:
  146448. case JCS_YCCK:
  146449. if (cinfo->input_components != 4)
  146450. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146451. break;
  146452. default: /* JCS_UNKNOWN can be anything */
  146453. if (cinfo->input_components < 1)
  146454. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146455. break;
  146456. }
  146457. switch (cinfo->jpeg_color_space) {
  146458. case JCS_GRAYSCALE:
  146459. if (cinfo->num_components != 1)
  146460. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146461. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146462. cconvert->pub.color_convert = grayscale_convert;
  146463. else if (cinfo->in_color_space == JCS_RGB) {
  146464. cconvert->pub.start_pass = rgb_ycc_start;
  146465. cconvert->pub.color_convert = rgb_gray_convert;
  146466. } else if (cinfo->in_color_space == JCS_YCbCr)
  146467. cconvert->pub.color_convert = grayscale_convert;
  146468. else
  146469. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146470. break;
  146471. case JCS_RGB:
  146472. if (cinfo->num_components != 3)
  146473. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146474. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146475. cconvert->pub.color_convert = null_convert;
  146476. else
  146477. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146478. break;
  146479. case JCS_YCbCr:
  146480. if (cinfo->num_components != 3)
  146481. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146482. if (cinfo->in_color_space == JCS_RGB) {
  146483. cconvert->pub.start_pass = rgb_ycc_start;
  146484. cconvert->pub.color_convert = rgb_ycc_convert;
  146485. } else if (cinfo->in_color_space == JCS_YCbCr)
  146486. cconvert->pub.color_convert = null_convert;
  146487. else
  146488. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146489. break;
  146490. case JCS_CMYK:
  146491. if (cinfo->num_components != 4)
  146492. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146493. if (cinfo->in_color_space == JCS_CMYK)
  146494. cconvert->pub.color_convert = null_convert;
  146495. else
  146496. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146497. break;
  146498. case JCS_YCCK:
  146499. if (cinfo->num_components != 4)
  146500. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146501. if (cinfo->in_color_space == JCS_CMYK) {
  146502. cconvert->pub.start_pass = rgb_ycc_start;
  146503. cconvert->pub.color_convert = cmyk_ycck_convert;
  146504. } else if (cinfo->in_color_space == JCS_YCCK)
  146505. cconvert->pub.color_convert = null_convert;
  146506. else
  146507. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146508. break;
  146509. default: /* allow null conversion of JCS_UNKNOWN */
  146510. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146511. cinfo->num_components != cinfo->input_components)
  146512. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146513. cconvert->pub.color_convert = null_convert;
  146514. break;
  146515. }
  146516. }
  146517. /*** End of inlined file: jccolor.c ***/
  146518. #undef FIX
  146519. /*** Start of inlined file: jcdctmgr.c ***/
  146520. #define JPEG_INTERNALS
  146521. /*** Start of inlined file: jdct.h ***/
  146522. #ifndef __jdct_h__
  146523. #define __jdct_h__
  146524. #if BITS_IN_JSAMPLE == 8
  146525. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146526. #else
  146527. typedef INT32 DCTELEM; /* must have 32 bits */
  146528. #endif
  146529. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146530. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146531. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146532. #if BITS_IN_JSAMPLE == 8
  146533. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146534. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146535. #else
  146536. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146537. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146538. #endif
  146539. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146540. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146541. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146542. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146543. #define jpeg_fdct_islow jFDislow
  146544. #define jpeg_fdct_ifast jFDifast
  146545. #define jpeg_fdct_float jFDfloat
  146546. #define jpeg_idct_islow jRDislow
  146547. #define jpeg_idct_ifast jRDifast
  146548. #define jpeg_idct_float jRDfloat
  146549. #define jpeg_idct_4x4 jRD4x4
  146550. #define jpeg_idct_2x2 jRD2x2
  146551. #define jpeg_idct_1x1 jRD1x1
  146552. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146553. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146554. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146555. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146556. EXTERN(void) jpeg_idct_islow
  146557. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146558. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146559. EXTERN(void) jpeg_idct_ifast
  146560. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146561. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146562. EXTERN(void) jpeg_idct_float
  146563. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146564. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146565. EXTERN(void) jpeg_idct_4x4
  146566. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146567. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146568. EXTERN(void) jpeg_idct_2x2
  146569. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146570. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146571. EXTERN(void) jpeg_idct_1x1
  146572. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146573. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146574. #define ONE ((INT32) 1)
  146575. #define CONST_SCALE (ONE << CONST_BITS)
  146576. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146577. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146578. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146579. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146580. #endif
  146581. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146582. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146583. #endif
  146584. #ifndef MULTIPLY16C16 /* default definition */
  146585. #define MULTIPLY16C16(var,const) ((var) * (const))
  146586. #endif
  146587. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146588. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146589. #endif
  146590. #ifndef MULTIPLY16V16 /* default definition */
  146591. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146592. #endif
  146593. #endif
  146594. /*** End of inlined file: jdct.h ***/
  146595. /* Private declarations for DCT subsystem */
  146596. typedef struct {
  146597. struct jpeg_forward_dct pub; /* public fields */
  146598. forward_DCT_method_ptr do_dct;
  146599. DCTELEM * divisors[NUM_QUANT_TBLS];
  146600. #ifdef DCT_FLOAT_SUPPORTED
  146601. float_DCT_method_ptr do_float_dct;
  146602. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146603. #endif
  146604. } my_fdct_controller;
  146605. typedef my_fdct_controller * my_fdct_ptr;
  146606. METHODDEF(void)
  146607. start_pass_fdctmgr (j_compress_ptr cinfo)
  146608. {
  146609. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146610. int ci, qtblno, i;
  146611. jpeg_component_info *compptr;
  146612. JQUANT_TBL * qtbl;
  146613. DCTELEM * dtbl;
  146614. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146615. ci++, compptr++) {
  146616. qtblno = compptr->quant_tbl_no;
  146617. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146618. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146619. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146620. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146621. switch (cinfo->dct_method) {
  146622. #ifdef DCT_ISLOW_SUPPORTED
  146623. case JDCT_ISLOW:
  146624. if (fdct->divisors[qtblno] == NULL) {
  146625. fdct->divisors[qtblno] = (DCTELEM *)
  146626. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146627. DCTSIZE2 * SIZEOF(DCTELEM));
  146628. }
  146629. dtbl = fdct->divisors[qtblno];
  146630. for (i = 0; i < DCTSIZE2; i++) {
  146631. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146632. }
  146633. break;
  146634. #endif
  146635. #ifdef DCT_IFAST_SUPPORTED
  146636. case JDCT_IFAST:
  146637. {
  146638. #define CONST_BITS 14
  146639. static const INT16 aanscales[DCTSIZE2] = {
  146640. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146641. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146642. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146643. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146644. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146645. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146646. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146647. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146648. };
  146649. SHIFT_TEMPS
  146650. if (fdct->divisors[qtblno] == NULL) {
  146651. fdct->divisors[qtblno] = (DCTELEM *)
  146652. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146653. DCTSIZE2 * SIZEOF(DCTELEM));
  146654. }
  146655. dtbl = fdct->divisors[qtblno];
  146656. for (i = 0; i < DCTSIZE2; i++) {
  146657. dtbl[i] = (DCTELEM)
  146658. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146659. (INT32) aanscales[i]),
  146660. CONST_BITS-3);
  146661. }
  146662. }
  146663. break;
  146664. #endif
  146665. #ifdef DCT_FLOAT_SUPPORTED
  146666. case JDCT_FLOAT:
  146667. {
  146668. FAST_FLOAT * fdtbl;
  146669. int row, col;
  146670. static const double aanscalefactor[DCTSIZE] = {
  146671. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146672. 1.0, 0.785694958, 0.541196100, 0.275899379
  146673. };
  146674. if (fdct->float_divisors[qtblno] == NULL) {
  146675. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146676. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146677. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146678. }
  146679. fdtbl = fdct->float_divisors[qtblno];
  146680. i = 0;
  146681. for (row = 0; row < DCTSIZE; row++) {
  146682. for (col = 0; col < DCTSIZE; col++) {
  146683. fdtbl[i] = (FAST_FLOAT)
  146684. (1.0 / (((double) qtbl->quantval[i] *
  146685. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146686. i++;
  146687. }
  146688. }
  146689. }
  146690. break;
  146691. #endif
  146692. default:
  146693. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146694. break;
  146695. }
  146696. }
  146697. }
  146698. METHODDEF(void)
  146699. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146700. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146701. JDIMENSION start_row, JDIMENSION start_col,
  146702. JDIMENSION num_blocks)
  146703. {
  146704. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146705. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146706. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146707. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146708. JDIMENSION bi;
  146709. sample_data += start_row; /* fold in the vertical offset once */
  146710. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146711. { register DCTELEM *workspaceptr;
  146712. register JSAMPROW elemptr;
  146713. register int elemr;
  146714. workspaceptr = workspace;
  146715. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146716. elemptr = sample_data[elemr] + start_col;
  146717. #if DCTSIZE == 8 /* unroll the inner loop */
  146718. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146719. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146720. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146721. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146722. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146723. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146724. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146725. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146726. #else
  146727. { register int elemc;
  146728. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146729. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146730. }
  146731. }
  146732. #endif
  146733. }
  146734. }
  146735. (*do_dct) (workspace);
  146736. { register DCTELEM temp, qval;
  146737. register int i;
  146738. register JCOEFPTR output_ptr = coef_blocks[bi];
  146739. for (i = 0; i < DCTSIZE2; i++) {
  146740. qval = divisors[i];
  146741. temp = workspace[i];
  146742. #ifdef FAST_DIVIDE
  146743. #define DIVIDE_BY(a,b) a /= b
  146744. #else
  146745. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146746. #endif
  146747. if (temp < 0) {
  146748. temp = -temp;
  146749. temp += qval>>1; /* for rounding */
  146750. DIVIDE_BY(temp, qval);
  146751. temp = -temp;
  146752. } else {
  146753. temp += qval>>1; /* for rounding */
  146754. DIVIDE_BY(temp, qval);
  146755. }
  146756. output_ptr[i] = (JCOEF) temp;
  146757. }
  146758. }
  146759. }
  146760. }
  146761. #ifdef DCT_FLOAT_SUPPORTED
  146762. METHODDEF(void)
  146763. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146764. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146765. JDIMENSION start_row, JDIMENSION start_col,
  146766. JDIMENSION num_blocks)
  146767. {
  146768. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146769. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146770. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146771. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146772. JDIMENSION bi;
  146773. sample_data += start_row; /* fold in the vertical offset once */
  146774. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146775. { register FAST_FLOAT *workspaceptr;
  146776. register JSAMPROW elemptr;
  146777. register int elemr;
  146778. workspaceptr = workspace;
  146779. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146780. elemptr = sample_data[elemr] + start_col;
  146781. #if DCTSIZE == 8 /* unroll the inner loop */
  146782. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146783. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146784. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146785. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146786. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146787. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146788. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146789. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146790. #else
  146791. { register int elemc;
  146792. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146793. *workspaceptr++ = (FAST_FLOAT)
  146794. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146795. }
  146796. }
  146797. #endif
  146798. }
  146799. }
  146800. (*do_dct) (workspace);
  146801. { register FAST_FLOAT temp;
  146802. register int i;
  146803. register JCOEFPTR output_ptr = coef_blocks[bi];
  146804. for (i = 0; i < DCTSIZE2; i++) {
  146805. temp = workspace[i] * divisors[i];
  146806. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146807. }
  146808. }
  146809. }
  146810. }
  146811. #endif /* DCT_FLOAT_SUPPORTED */
  146812. GLOBAL(void)
  146813. jinit_forward_dct (j_compress_ptr cinfo)
  146814. {
  146815. my_fdct_ptr fdct;
  146816. int i;
  146817. fdct = (my_fdct_ptr)
  146818. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146819. SIZEOF(my_fdct_controller));
  146820. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146821. fdct->pub.start_pass = start_pass_fdctmgr;
  146822. switch (cinfo->dct_method) {
  146823. #ifdef DCT_ISLOW_SUPPORTED
  146824. case JDCT_ISLOW:
  146825. fdct->pub.forward_DCT = forward_DCT;
  146826. fdct->do_dct = jpeg_fdct_islow;
  146827. break;
  146828. #endif
  146829. #ifdef DCT_IFAST_SUPPORTED
  146830. case JDCT_IFAST:
  146831. fdct->pub.forward_DCT = forward_DCT;
  146832. fdct->do_dct = jpeg_fdct_ifast;
  146833. break;
  146834. #endif
  146835. #ifdef DCT_FLOAT_SUPPORTED
  146836. case JDCT_FLOAT:
  146837. fdct->pub.forward_DCT = forward_DCT_float;
  146838. fdct->do_float_dct = jpeg_fdct_float;
  146839. break;
  146840. #endif
  146841. default:
  146842. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146843. break;
  146844. }
  146845. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146846. fdct->divisors[i] = NULL;
  146847. #ifdef DCT_FLOAT_SUPPORTED
  146848. fdct->float_divisors[i] = NULL;
  146849. #endif
  146850. }
  146851. }
  146852. /*** End of inlined file: jcdctmgr.c ***/
  146853. #undef CONST_BITS
  146854. /*** Start of inlined file: jchuff.c ***/
  146855. #define JPEG_INTERNALS
  146856. /*** Start of inlined file: jchuff.h ***/
  146857. #ifndef _jchuff_h_
  146858. #define _jchuff_h_
  146859. #if BITS_IN_JSAMPLE == 8
  146860. #define MAX_COEF_BITS 10
  146861. #else
  146862. #define MAX_COEF_BITS 14
  146863. #endif
  146864. typedef struct {
  146865. unsigned int ehufco[256]; /* code for each symbol */
  146866. char ehufsi[256]; /* length of code for each symbol */
  146867. } c_derived_tbl;
  146868. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146869. #define jpeg_make_c_derived_tbl jMkCDerived
  146870. #define jpeg_gen_optimal_table jGenOptTbl
  146871. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146872. EXTERN(void) jpeg_make_c_derived_tbl
  146873. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146874. c_derived_tbl ** pdtbl));
  146875. EXTERN(void) jpeg_gen_optimal_table
  146876. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146877. #endif
  146878. /*** End of inlined file: jchuff.h ***/
  146879. /* Declarations shared with jcphuff.c */
  146880. typedef struct {
  146881. INT32 put_buffer; /* current bit-accumulation buffer */
  146882. int put_bits; /* # of bits now in it */
  146883. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146884. } savable_state;
  146885. #ifndef NO_STRUCT_ASSIGN
  146886. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146887. #else
  146888. #if MAX_COMPS_IN_SCAN == 4
  146889. #define ASSIGN_STATE(dest,src) \
  146890. ((dest).put_buffer = (src).put_buffer, \
  146891. (dest).put_bits = (src).put_bits, \
  146892. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146893. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146894. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146895. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146896. #endif
  146897. #endif
  146898. typedef struct {
  146899. struct jpeg_entropy_encoder pub; /* public fields */
  146900. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146901. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146902. int next_restart_num; /* next restart number to write (0-7) */
  146903. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146904. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146905. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146906. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146907. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146908. #endif
  146909. } huff_entropy_encoder;
  146910. typedef huff_entropy_encoder * huff_entropy_ptr;
  146911. typedef struct {
  146912. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146913. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146914. savable_state cur; /* Current bit buffer & DC state */
  146915. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146916. } working_state;
  146917. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  146918. JBLOCKROW *MCU_data));
  146919. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  146920. #ifdef ENTROPY_OPT_SUPPORTED
  146921. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  146922. JBLOCKROW *MCU_data));
  146923. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  146924. #endif
  146925. METHODDEF(void)
  146926. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  146927. {
  146928. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  146929. int ci, dctbl, actbl;
  146930. jpeg_component_info * compptr;
  146931. if (gather_statistics) {
  146932. #ifdef ENTROPY_OPT_SUPPORTED
  146933. entropy->pub.encode_mcu = encode_mcu_gather;
  146934. entropy->pub.finish_pass = finish_pass_gather;
  146935. #else
  146936. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146937. #endif
  146938. } else {
  146939. entropy->pub.encode_mcu = encode_mcu_huff;
  146940. entropy->pub.finish_pass = finish_pass_huff;
  146941. }
  146942. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146943. compptr = cinfo->cur_comp_info[ci];
  146944. dctbl = compptr->dc_tbl_no;
  146945. actbl = compptr->ac_tbl_no;
  146946. if (gather_statistics) {
  146947. #ifdef ENTROPY_OPT_SUPPORTED
  146948. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  146949. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  146950. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  146951. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  146952. if (entropy->dc_count_ptrs[dctbl] == NULL)
  146953. entropy->dc_count_ptrs[dctbl] = (long *)
  146954. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146955. 257 * SIZEOF(long));
  146956. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  146957. if (entropy->ac_count_ptrs[actbl] == NULL)
  146958. entropy->ac_count_ptrs[actbl] = (long *)
  146959. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146960. 257 * SIZEOF(long));
  146961. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  146962. #endif
  146963. } else {
  146964. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  146965. & entropy->dc_derived_tbls[dctbl]);
  146966. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  146967. & entropy->ac_derived_tbls[actbl]);
  146968. }
  146969. entropy->saved.last_dc_val[ci] = 0;
  146970. }
  146971. entropy->saved.put_buffer = 0;
  146972. entropy->saved.put_bits = 0;
  146973. entropy->restarts_to_go = cinfo->restart_interval;
  146974. entropy->next_restart_num = 0;
  146975. }
  146976. GLOBAL(void)
  146977. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  146978. c_derived_tbl ** pdtbl)
  146979. {
  146980. JHUFF_TBL *htbl;
  146981. c_derived_tbl *dtbl;
  146982. int p, i, l, lastp, si, maxsymbol;
  146983. char huffsize[257];
  146984. unsigned int huffcode[257];
  146985. unsigned int code;
  146986. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  146987. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146988. htbl =
  146989. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  146990. if (htbl == NULL)
  146991. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146992. if (*pdtbl == NULL)
  146993. *pdtbl = (c_derived_tbl *)
  146994. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146995. SIZEOF(c_derived_tbl));
  146996. dtbl = *pdtbl;
  146997. p = 0;
  146998. for (l = 1; l <= 16; l++) {
  146999. i = (int) htbl->bits[l];
  147000. if (i < 0 || p + i > 256) /* protect against table overrun */
  147001. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147002. while (i--)
  147003. huffsize[p++] = (char) l;
  147004. }
  147005. huffsize[p] = 0;
  147006. lastp = p;
  147007. code = 0;
  147008. si = huffsize[0];
  147009. p = 0;
  147010. while (huffsize[p]) {
  147011. while (((int) huffsize[p]) == si) {
  147012. huffcode[p++] = code;
  147013. code++;
  147014. }
  147015. if (((INT32) code) >= (((INT32) 1) << si))
  147016. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147017. code <<= 1;
  147018. si++;
  147019. }
  147020. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147021. maxsymbol = isDC ? 15 : 255;
  147022. for (p = 0; p < lastp; p++) {
  147023. i = htbl->huffval[p];
  147024. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147025. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147026. dtbl->ehufco[i] = huffcode[p];
  147027. dtbl->ehufsi[i] = huffsize[p];
  147028. }
  147029. }
  147030. #define emit_byte(state,val,action) \
  147031. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147032. if (--(state)->free_in_buffer == 0) \
  147033. if (! dump_buffer(state)) \
  147034. { action; } }
  147035. LOCAL(boolean)
  147036. dump_buffer (working_state * state)
  147037. {
  147038. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147039. if (! (*dest->empty_output_buffer) (state->cinfo))
  147040. return FALSE;
  147041. state->next_output_byte = dest->next_output_byte;
  147042. state->free_in_buffer = dest->free_in_buffer;
  147043. return TRUE;
  147044. }
  147045. INLINE
  147046. LOCAL(boolean)
  147047. emit_bits (working_state * state, unsigned int code, int size)
  147048. {
  147049. register INT32 put_buffer = (INT32) code;
  147050. register int put_bits = state->cur.put_bits;
  147051. if (size == 0)
  147052. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147053. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147054. put_bits += size; /* new number of bits in buffer */
  147055. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147056. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147057. while (put_bits >= 8) {
  147058. int c = (int) ((put_buffer >> 16) & 0xFF);
  147059. emit_byte(state, c, return FALSE);
  147060. if (c == 0xFF) { /* need to stuff a zero byte? */
  147061. emit_byte(state, 0, return FALSE);
  147062. }
  147063. put_buffer <<= 8;
  147064. put_bits -= 8;
  147065. }
  147066. state->cur.put_buffer = put_buffer; /* update state variables */
  147067. state->cur.put_bits = put_bits;
  147068. return TRUE;
  147069. }
  147070. LOCAL(boolean)
  147071. flush_bits (working_state * state)
  147072. {
  147073. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147074. return FALSE;
  147075. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147076. state->cur.put_bits = 0;
  147077. return TRUE;
  147078. }
  147079. LOCAL(boolean)
  147080. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147081. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147082. {
  147083. register int temp, temp2;
  147084. register int nbits;
  147085. register int k, r, i;
  147086. temp = temp2 = block[0] - last_dc_val;
  147087. if (temp < 0) {
  147088. temp = -temp; /* temp is abs value of input */
  147089. temp2--;
  147090. }
  147091. nbits = 0;
  147092. while (temp) {
  147093. nbits++;
  147094. temp >>= 1;
  147095. }
  147096. if (nbits > MAX_COEF_BITS+1)
  147097. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147098. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147099. return FALSE;
  147100. if (nbits) /* emit_bits rejects calls with size 0 */
  147101. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147102. return FALSE;
  147103. r = 0; /* r = run length of zeros */
  147104. for (k = 1; k < DCTSIZE2; k++) {
  147105. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147106. r++;
  147107. } else {
  147108. while (r > 15) {
  147109. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147110. return FALSE;
  147111. r -= 16;
  147112. }
  147113. temp2 = temp;
  147114. if (temp < 0) {
  147115. temp = -temp; /* temp is abs value of input */
  147116. temp2--;
  147117. }
  147118. nbits = 1; /* there must be at least one 1 bit */
  147119. while ((temp >>= 1))
  147120. nbits++;
  147121. if (nbits > MAX_COEF_BITS)
  147122. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147123. i = (r << 4) + nbits;
  147124. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147125. return FALSE;
  147126. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147127. return FALSE;
  147128. r = 0;
  147129. }
  147130. }
  147131. if (r > 0)
  147132. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147133. return FALSE;
  147134. return TRUE;
  147135. }
  147136. LOCAL(boolean)
  147137. emit_restart (working_state * state, int restart_num)
  147138. {
  147139. int ci;
  147140. if (! flush_bits(state))
  147141. return FALSE;
  147142. emit_byte(state, 0xFF, return FALSE);
  147143. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147144. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147145. state->cur.last_dc_val[ci] = 0;
  147146. return TRUE;
  147147. }
  147148. METHODDEF(boolean)
  147149. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147150. {
  147151. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147152. working_state state;
  147153. int blkn, ci;
  147154. jpeg_component_info * compptr;
  147155. state.next_output_byte = cinfo->dest->next_output_byte;
  147156. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147157. ASSIGN_STATE(state.cur, entropy->saved);
  147158. state.cinfo = cinfo;
  147159. if (cinfo->restart_interval) {
  147160. if (entropy->restarts_to_go == 0)
  147161. if (! emit_restart(&state, entropy->next_restart_num))
  147162. return FALSE;
  147163. }
  147164. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147165. ci = cinfo->MCU_membership[blkn];
  147166. compptr = cinfo->cur_comp_info[ci];
  147167. if (! encode_one_block(&state,
  147168. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147169. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147170. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147171. return FALSE;
  147172. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147173. }
  147174. cinfo->dest->next_output_byte = state.next_output_byte;
  147175. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147176. ASSIGN_STATE(entropy->saved, state.cur);
  147177. if (cinfo->restart_interval) {
  147178. if (entropy->restarts_to_go == 0) {
  147179. entropy->restarts_to_go = cinfo->restart_interval;
  147180. entropy->next_restart_num++;
  147181. entropy->next_restart_num &= 7;
  147182. }
  147183. entropy->restarts_to_go--;
  147184. }
  147185. return TRUE;
  147186. }
  147187. METHODDEF(void)
  147188. finish_pass_huff (j_compress_ptr cinfo)
  147189. {
  147190. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147191. working_state state;
  147192. state.next_output_byte = cinfo->dest->next_output_byte;
  147193. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147194. ASSIGN_STATE(state.cur, entropy->saved);
  147195. state.cinfo = cinfo;
  147196. if (! flush_bits(&state))
  147197. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147198. cinfo->dest->next_output_byte = state.next_output_byte;
  147199. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147200. ASSIGN_STATE(entropy->saved, state.cur);
  147201. }
  147202. #ifdef ENTROPY_OPT_SUPPORTED
  147203. LOCAL(void)
  147204. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147205. long dc_counts[], long ac_counts[])
  147206. {
  147207. register int temp;
  147208. register int nbits;
  147209. register int k, r;
  147210. temp = block[0] - last_dc_val;
  147211. if (temp < 0)
  147212. temp = -temp;
  147213. nbits = 0;
  147214. while (temp) {
  147215. nbits++;
  147216. temp >>= 1;
  147217. }
  147218. if (nbits > MAX_COEF_BITS+1)
  147219. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147220. dc_counts[nbits]++;
  147221. r = 0; /* r = run length of zeros */
  147222. for (k = 1; k < DCTSIZE2; k++) {
  147223. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147224. r++;
  147225. } else {
  147226. while (r > 15) {
  147227. ac_counts[0xF0]++;
  147228. r -= 16;
  147229. }
  147230. if (temp < 0)
  147231. temp = -temp;
  147232. nbits = 1; /* there must be at least one 1 bit */
  147233. while ((temp >>= 1))
  147234. nbits++;
  147235. if (nbits > MAX_COEF_BITS)
  147236. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147237. ac_counts[(r << 4) + nbits]++;
  147238. r = 0;
  147239. }
  147240. }
  147241. if (r > 0)
  147242. ac_counts[0]++;
  147243. }
  147244. METHODDEF(boolean)
  147245. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147246. {
  147247. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147248. int blkn, ci;
  147249. jpeg_component_info * compptr;
  147250. if (cinfo->restart_interval) {
  147251. if (entropy->restarts_to_go == 0) {
  147252. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147253. entropy->saved.last_dc_val[ci] = 0;
  147254. entropy->restarts_to_go = cinfo->restart_interval;
  147255. }
  147256. entropy->restarts_to_go--;
  147257. }
  147258. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147259. ci = cinfo->MCU_membership[blkn];
  147260. compptr = cinfo->cur_comp_info[ci];
  147261. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147262. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147263. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147264. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147265. }
  147266. return TRUE;
  147267. }
  147268. GLOBAL(void)
  147269. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147270. {
  147271. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147272. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147273. int codesize[257]; /* codesize[k] = code length of symbol k */
  147274. int others[257]; /* next symbol in current branch of tree */
  147275. int c1, c2;
  147276. int p, i, j;
  147277. long v;
  147278. MEMZERO(bits, SIZEOF(bits));
  147279. MEMZERO(codesize, SIZEOF(codesize));
  147280. for (i = 0; i < 257; i++)
  147281. others[i] = -1; /* init links to empty */
  147282. freq[256] = 1; /* make sure 256 has a nonzero count */
  147283. for (;;) {
  147284. c1 = -1;
  147285. v = 1000000000L;
  147286. for (i = 0; i <= 256; i++) {
  147287. if (freq[i] && freq[i] <= v) {
  147288. v = freq[i];
  147289. c1 = i;
  147290. }
  147291. }
  147292. c2 = -1;
  147293. v = 1000000000L;
  147294. for (i = 0; i <= 256; i++) {
  147295. if (freq[i] && freq[i] <= v && i != c1) {
  147296. v = freq[i];
  147297. c2 = i;
  147298. }
  147299. }
  147300. if (c2 < 0)
  147301. break;
  147302. freq[c1] += freq[c2];
  147303. freq[c2] = 0;
  147304. codesize[c1]++;
  147305. while (others[c1] >= 0) {
  147306. c1 = others[c1];
  147307. codesize[c1]++;
  147308. }
  147309. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147310. codesize[c2]++;
  147311. while (others[c2] >= 0) {
  147312. c2 = others[c2];
  147313. codesize[c2]++;
  147314. }
  147315. }
  147316. for (i = 0; i <= 256; i++) {
  147317. if (codesize[i]) {
  147318. if (codesize[i] > MAX_CLEN)
  147319. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147320. bits[codesize[i]]++;
  147321. }
  147322. }
  147323. for (i = MAX_CLEN; i > 16; i--) {
  147324. while (bits[i] > 0) {
  147325. j = i - 2; /* find length of new prefix to be used */
  147326. while (bits[j] == 0)
  147327. j--;
  147328. bits[i] -= 2; /* remove two symbols */
  147329. bits[i-1]++; /* one goes in this length */
  147330. bits[j+1] += 2; /* two new symbols in this length */
  147331. bits[j]--; /* symbol of this length is now a prefix */
  147332. }
  147333. }
  147334. while (bits[i] == 0) /* find largest codelength still in use */
  147335. i--;
  147336. bits[i]--;
  147337. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147338. p = 0;
  147339. for (i = 1; i <= MAX_CLEN; i++) {
  147340. for (j = 0; j <= 255; j++) {
  147341. if (codesize[j] == i) {
  147342. htbl->huffval[p] = (UINT8) j;
  147343. p++;
  147344. }
  147345. }
  147346. }
  147347. htbl->sent_table = FALSE;
  147348. }
  147349. METHODDEF(void)
  147350. finish_pass_gather (j_compress_ptr cinfo)
  147351. {
  147352. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147353. int ci, dctbl, actbl;
  147354. jpeg_component_info * compptr;
  147355. JHUFF_TBL **htblptr;
  147356. boolean did_dc[NUM_HUFF_TBLS];
  147357. boolean did_ac[NUM_HUFF_TBLS];
  147358. MEMZERO(did_dc, SIZEOF(did_dc));
  147359. MEMZERO(did_ac, SIZEOF(did_ac));
  147360. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147361. compptr = cinfo->cur_comp_info[ci];
  147362. dctbl = compptr->dc_tbl_no;
  147363. actbl = compptr->ac_tbl_no;
  147364. if (! did_dc[dctbl]) {
  147365. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147366. if (*htblptr == NULL)
  147367. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147368. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147369. did_dc[dctbl] = TRUE;
  147370. }
  147371. if (! did_ac[actbl]) {
  147372. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147373. if (*htblptr == NULL)
  147374. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147375. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147376. did_ac[actbl] = TRUE;
  147377. }
  147378. }
  147379. }
  147380. #endif /* ENTROPY_OPT_SUPPORTED */
  147381. GLOBAL(void)
  147382. jinit_huff_encoder (j_compress_ptr cinfo)
  147383. {
  147384. huff_entropy_ptr entropy;
  147385. int i;
  147386. entropy = (huff_entropy_ptr)
  147387. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147388. SIZEOF(huff_entropy_encoder));
  147389. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147390. entropy->pub.start_pass = start_pass_huff;
  147391. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147392. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147393. #ifdef ENTROPY_OPT_SUPPORTED
  147394. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147395. #endif
  147396. }
  147397. }
  147398. /*** End of inlined file: jchuff.c ***/
  147399. #undef emit_byte
  147400. /*** Start of inlined file: jcinit.c ***/
  147401. #define JPEG_INTERNALS
  147402. GLOBAL(void)
  147403. jinit_compress_master (j_compress_ptr cinfo)
  147404. {
  147405. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147406. if (! cinfo->raw_data_in) {
  147407. jinit_color_converter(cinfo);
  147408. jinit_downsampler(cinfo);
  147409. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147410. }
  147411. jinit_forward_dct(cinfo);
  147412. if (cinfo->arith_code) {
  147413. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147414. } else {
  147415. if (cinfo->progressive_mode) {
  147416. #ifdef C_PROGRESSIVE_SUPPORTED
  147417. jinit_phuff_encoder(cinfo);
  147418. #else
  147419. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147420. #endif
  147421. } else
  147422. jinit_huff_encoder(cinfo);
  147423. }
  147424. jinit_c_coef_controller(cinfo,
  147425. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147426. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147427. jinit_marker_writer(cinfo);
  147428. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147429. (*cinfo->marker->write_file_header) (cinfo);
  147430. }
  147431. /*** End of inlined file: jcinit.c ***/
  147432. /*** Start of inlined file: jcmainct.c ***/
  147433. #define JPEG_INTERNALS
  147434. #undef FULL_MAIN_BUFFER_SUPPORTED
  147435. typedef struct {
  147436. struct jpeg_c_main_controller pub; /* public fields */
  147437. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147438. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147439. boolean suspended; /* remember if we suspended output */
  147440. J_BUF_MODE pass_mode; /* current operating mode */
  147441. JSAMPARRAY buffer[MAX_COMPONENTS];
  147442. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147443. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147444. #endif
  147445. } my_main_controller;
  147446. typedef my_main_controller * my_main_ptr;
  147447. METHODDEF(void) process_data_simple_main
  147448. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147449. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147450. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147451. METHODDEF(void) process_data_buffer_main
  147452. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147453. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147454. #endif
  147455. METHODDEF(void)
  147456. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147457. {
  147458. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147459. if (cinfo->raw_data_in)
  147460. return;
  147461. main_->cur_iMCU_row = 0; /* initialize counters */
  147462. main_->rowgroup_ctr = 0;
  147463. main_->suspended = FALSE;
  147464. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147465. switch (pass_mode) {
  147466. case JBUF_PASS_THRU:
  147467. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147468. if (main_->whole_image[0] != NULL)
  147469. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147470. #endif
  147471. main_->pub.process_data = process_data_simple_main;
  147472. break;
  147473. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147474. case JBUF_SAVE_SOURCE:
  147475. case JBUF_CRANK_DEST:
  147476. case JBUF_SAVE_AND_PASS:
  147477. if (main_->whole_image[0] == NULL)
  147478. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147479. main_->pub.process_data = process_data_buffer_main;
  147480. break;
  147481. #endif
  147482. default:
  147483. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147484. break;
  147485. }
  147486. }
  147487. METHODDEF(void)
  147488. process_data_simple_main (j_compress_ptr cinfo,
  147489. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147490. JDIMENSION in_rows_avail)
  147491. {
  147492. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147493. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147494. if (main_->rowgroup_ctr < DCTSIZE)
  147495. (*cinfo->prep->pre_process_data) (cinfo,
  147496. input_buf, in_row_ctr, in_rows_avail,
  147497. main_->buffer, &main_->rowgroup_ctr,
  147498. (JDIMENSION) DCTSIZE);
  147499. if (main_->rowgroup_ctr != DCTSIZE)
  147500. return;
  147501. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147502. if (! main_->suspended) {
  147503. (*in_row_ctr)--;
  147504. main_->suspended = TRUE;
  147505. }
  147506. return;
  147507. }
  147508. if (main_->suspended) {
  147509. (*in_row_ctr)++;
  147510. main_->suspended = FALSE;
  147511. }
  147512. main_->rowgroup_ctr = 0;
  147513. main_->cur_iMCU_row++;
  147514. }
  147515. }
  147516. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147517. METHODDEF(void)
  147518. process_data_buffer_main (j_compress_ptr cinfo,
  147519. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147520. JDIMENSION in_rows_avail)
  147521. {
  147522. my_main_ptr main = (my_main_ptr) cinfo->main;
  147523. int ci;
  147524. jpeg_component_info *compptr;
  147525. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147526. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147527. if (main->rowgroup_ctr == 0) {
  147528. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147529. ci++, compptr++) {
  147530. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147531. ((j_common_ptr) cinfo, main->whole_image[ci],
  147532. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147533. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147534. }
  147535. if (! writing) {
  147536. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147537. main->rowgroup_ctr = DCTSIZE;
  147538. }
  147539. }
  147540. if (writing) {
  147541. (*cinfo->prep->pre_process_data) (cinfo,
  147542. input_buf, in_row_ctr, in_rows_avail,
  147543. main->buffer, &main->rowgroup_ctr,
  147544. (JDIMENSION) DCTSIZE);
  147545. if (main->rowgroup_ctr < DCTSIZE)
  147546. return;
  147547. }
  147548. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147549. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147550. if (! main->suspended) {
  147551. (*in_row_ctr)--;
  147552. main->suspended = TRUE;
  147553. }
  147554. return;
  147555. }
  147556. if (main->suspended) {
  147557. (*in_row_ctr)++;
  147558. main->suspended = FALSE;
  147559. }
  147560. }
  147561. main->rowgroup_ctr = 0;
  147562. main->cur_iMCU_row++;
  147563. }
  147564. }
  147565. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147566. GLOBAL(void)
  147567. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147568. {
  147569. my_main_ptr main_;
  147570. int ci;
  147571. jpeg_component_info *compptr;
  147572. main_ = (my_main_ptr)
  147573. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147574. SIZEOF(my_main_controller));
  147575. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147576. main_->pub.start_pass = start_pass_main;
  147577. if (cinfo->raw_data_in)
  147578. return;
  147579. if (need_full_buffer) {
  147580. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147581. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147582. ci++, compptr++) {
  147583. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147584. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147585. compptr->width_in_blocks * DCTSIZE,
  147586. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147587. (long) compptr->v_samp_factor) * DCTSIZE,
  147588. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147589. }
  147590. #else
  147591. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147592. #endif
  147593. } else {
  147594. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147595. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147596. #endif
  147597. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147598. ci++, compptr++) {
  147599. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147600. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147601. compptr->width_in_blocks * DCTSIZE,
  147602. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147603. }
  147604. }
  147605. }
  147606. /*** End of inlined file: jcmainct.c ***/
  147607. /*** Start of inlined file: jcmarker.c ***/
  147608. #define JPEG_INTERNALS
  147609. typedef struct {
  147610. struct jpeg_marker_writer pub; /* public fields */
  147611. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147612. } my_marker_writer;
  147613. typedef my_marker_writer * my_marker_ptr;
  147614. LOCAL(void)
  147615. emit_byte (j_compress_ptr cinfo, int val)
  147616. {
  147617. struct jpeg_destination_mgr * dest = cinfo->dest;
  147618. *(dest->next_output_byte)++ = (JOCTET) val;
  147619. if (--dest->free_in_buffer == 0) {
  147620. if (! (*dest->empty_output_buffer) (cinfo))
  147621. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147622. }
  147623. }
  147624. LOCAL(void)
  147625. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147626. {
  147627. emit_byte(cinfo, 0xFF);
  147628. emit_byte(cinfo, (int) mark);
  147629. }
  147630. LOCAL(void)
  147631. emit_2bytes (j_compress_ptr cinfo, int value)
  147632. {
  147633. emit_byte(cinfo, (value >> 8) & 0xFF);
  147634. emit_byte(cinfo, value & 0xFF);
  147635. }
  147636. LOCAL(int)
  147637. emit_dqt (j_compress_ptr cinfo, int index)
  147638. {
  147639. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147640. int prec;
  147641. int i;
  147642. if (qtbl == NULL)
  147643. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147644. prec = 0;
  147645. for (i = 0; i < DCTSIZE2; i++) {
  147646. if (qtbl->quantval[i] > 255)
  147647. prec = 1;
  147648. }
  147649. if (! qtbl->sent_table) {
  147650. emit_marker(cinfo, M_DQT);
  147651. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147652. emit_byte(cinfo, index + (prec<<4));
  147653. for (i = 0; i < DCTSIZE2; i++) {
  147654. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147655. if (prec)
  147656. emit_byte(cinfo, (int) (qval >> 8));
  147657. emit_byte(cinfo, (int) (qval & 0xFF));
  147658. }
  147659. qtbl->sent_table = TRUE;
  147660. }
  147661. return prec;
  147662. }
  147663. LOCAL(void)
  147664. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147665. {
  147666. JHUFF_TBL * htbl;
  147667. int length, i;
  147668. if (is_ac) {
  147669. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147670. index += 0x10; /* output index has AC bit set */
  147671. } else {
  147672. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147673. }
  147674. if (htbl == NULL)
  147675. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147676. if (! htbl->sent_table) {
  147677. emit_marker(cinfo, M_DHT);
  147678. length = 0;
  147679. for (i = 1; i <= 16; i++)
  147680. length += htbl->bits[i];
  147681. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147682. emit_byte(cinfo, index);
  147683. for (i = 1; i <= 16; i++)
  147684. emit_byte(cinfo, htbl->bits[i]);
  147685. for (i = 0; i < length; i++)
  147686. emit_byte(cinfo, htbl->huffval[i]);
  147687. htbl->sent_table = TRUE;
  147688. }
  147689. }
  147690. LOCAL(void)
  147691. emit_dac (j_compress_ptr cinfo)
  147692. {
  147693. #ifdef C_ARITH_CODING_SUPPORTED
  147694. char dc_in_use[NUM_ARITH_TBLS];
  147695. char ac_in_use[NUM_ARITH_TBLS];
  147696. int length, i;
  147697. jpeg_component_info *compptr;
  147698. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147699. dc_in_use[i] = ac_in_use[i] = 0;
  147700. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147701. compptr = cinfo->cur_comp_info[i];
  147702. dc_in_use[compptr->dc_tbl_no] = 1;
  147703. ac_in_use[compptr->ac_tbl_no] = 1;
  147704. }
  147705. length = 0;
  147706. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147707. length += dc_in_use[i] + ac_in_use[i];
  147708. emit_marker(cinfo, M_DAC);
  147709. emit_2bytes(cinfo, length*2 + 2);
  147710. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147711. if (dc_in_use[i]) {
  147712. emit_byte(cinfo, i);
  147713. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147714. }
  147715. if (ac_in_use[i]) {
  147716. emit_byte(cinfo, i + 0x10);
  147717. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147718. }
  147719. }
  147720. #endif /* C_ARITH_CODING_SUPPORTED */
  147721. }
  147722. LOCAL(void)
  147723. emit_dri (j_compress_ptr cinfo)
  147724. {
  147725. emit_marker(cinfo, M_DRI);
  147726. emit_2bytes(cinfo, 4); /* fixed length */
  147727. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147728. }
  147729. LOCAL(void)
  147730. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147731. {
  147732. int ci;
  147733. jpeg_component_info *compptr;
  147734. emit_marker(cinfo, code);
  147735. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147736. if ((long) cinfo->image_height > 65535L ||
  147737. (long) cinfo->image_width > 65535L)
  147738. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147739. emit_byte(cinfo, cinfo->data_precision);
  147740. emit_2bytes(cinfo, (int) cinfo->image_height);
  147741. emit_2bytes(cinfo, (int) cinfo->image_width);
  147742. emit_byte(cinfo, cinfo->num_components);
  147743. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147744. ci++, compptr++) {
  147745. emit_byte(cinfo, compptr->component_id);
  147746. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147747. emit_byte(cinfo, compptr->quant_tbl_no);
  147748. }
  147749. }
  147750. LOCAL(void)
  147751. emit_sos (j_compress_ptr cinfo)
  147752. {
  147753. int i, td, ta;
  147754. jpeg_component_info *compptr;
  147755. emit_marker(cinfo, M_SOS);
  147756. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147757. emit_byte(cinfo, cinfo->comps_in_scan);
  147758. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147759. compptr = cinfo->cur_comp_info[i];
  147760. emit_byte(cinfo, compptr->component_id);
  147761. td = compptr->dc_tbl_no;
  147762. ta = compptr->ac_tbl_no;
  147763. if (cinfo->progressive_mode) {
  147764. if (cinfo->Ss == 0) {
  147765. ta = 0; /* DC scan */
  147766. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147767. td = 0; /* no DC table either */
  147768. } else {
  147769. td = 0; /* AC scan */
  147770. }
  147771. }
  147772. emit_byte(cinfo, (td << 4) + ta);
  147773. }
  147774. emit_byte(cinfo, cinfo->Ss);
  147775. emit_byte(cinfo, cinfo->Se);
  147776. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147777. }
  147778. LOCAL(void)
  147779. emit_jfif_app0 (j_compress_ptr cinfo)
  147780. {
  147781. emit_marker(cinfo, M_APP0);
  147782. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147783. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147784. emit_byte(cinfo, 0x46);
  147785. emit_byte(cinfo, 0x49);
  147786. emit_byte(cinfo, 0x46);
  147787. emit_byte(cinfo, 0);
  147788. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147789. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147790. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147791. emit_2bytes(cinfo, (int) cinfo->X_density);
  147792. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147793. emit_byte(cinfo, 0); /* No thumbnail image */
  147794. emit_byte(cinfo, 0);
  147795. }
  147796. LOCAL(void)
  147797. emit_adobe_app14 (j_compress_ptr cinfo)
  147798. {
  147799. emit_marker(cinfo, M_APP14);
  147800. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147801. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147802. emit_byte(cinfo, 0x64);
  147803. emit_byte(cinfo, 0x6F);
  147804. emit_byte(cinfo, 0x62);
  147805. emit_byte(cinfo, 0x65);
  147806. emit_2bytes(cinfo, 100); /* Version */
  147807. emit_2bytes(cinfo, 0); /* Flags0 */
  147808. emit_2bytes(cinfo, 0); /* Flags1 */
  147809. switch (cinfo->jpeg_color_space) {
  147810. case JCS_YCbCr:
  147811. emit_byte(cinfo, 1); /* Color transform = 1 */
  147812. break;
  147813. case JCS_YCCK:
  147814. emit_byte(cinfo, 2); /* Color transform = 2 */
  147815. break;
  147816. default:
  147817. emit_byte(cinfo, 0); /* Color transform = 0 */
  147818. break;
  147819. }
  147820. }
  147821. METHODDEF(void)
  147822. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147823. {
  147824. if (datalen > (unsigned int) 65533) /* safety check */
  147825. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147826. emit_marker(cinfo, (JPEG_MARKER) marker);
  147827. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147828. }
  147829. METHODDEF(void)
  147830. write_marker_byte (j_compress_ptr cinfo, int val)
  147831. {
  147832. emit_byte(cinfo, val);
  147833. }
  147834. METHODDEF(void)
  147835. write_file_header (j_compress_ptr cinfo)
  147836. {
  147837. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147838. emit_marker(cinfo, M_SOI); /* first the SOI */
  147839. marker->last_restart_interval = 0;
  147840. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147841. emit_jfif_app0(cinfo);
  147842. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147843. emit_adobe_app14(cinfo);
  147844. }
  147845. METHODDEF(void)
  147846. write_frame_header (j_compress_ptr cinfo)
  147847. {
  147848. int ci, prec;
  147849. boolean is_baseline;
  147850. jpeg_component_info *compptr;
  147851. prec = 0;
  147852. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147853. ci++, compptr++) {
  147854. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147855. }
  147856. if (cinfo->arith_code || cinfo->progressive_mode ||
  147857. cinfo->data_precision != 8) {
  147858. is_baseline = FALSE;
  147859. } else {
  147860. is_baseline = TRUE;
  147861. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147862. ci++, compptr++) {
  147863. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147864. is_baseline = FALSE;
  147865. }
  147866. if (prec && is_baseline) {
  147867. is_baseline = FALSE;
  147868. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147869. }
  147870. }
  147871. if (cinfo->arith_code) {
  147872. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147873. } else {
  147874. if (cinfo->progressive_mode)
  147875. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147876. else if (is_baseline)
  147877. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147878. else
  147879. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147880. }
  147881. }
  147882. METHODDEF(void)
  147883. write_scan_header (j_compress_ptr cinfo)
  147884. {
  147885. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147886. int i;
  147887. jpeg_component_info *compptr;
  147888. if (cinfo->arith_code) {
  147889. emit_dac(cinfo);
  147890. } else {
  147891. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147892. compptr = cinfo->cur_comp_info[i];
  147893. if (cinfo->progressive_mode) {
  147894. if (cinfo->Ss == 0) {
  147895. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147896. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147897. } else {
  147898. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147899. }
  147900. } else {
  147901. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147902. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147903. }
  147904. }
  147905. }
  147906. if (cinfo->restart_interval != marker->last_restart_interval) {
  147907. emit_dri(cinfo);
  147908. marker->last_restart_interval = cinfo->restart_interval;
  147909. }
  147910. emit_sos(cinfo);
  147911. }
  147912. METHODDEF(void)
  147913. write_file_trailer (j_compress_ptr cinfo)
  147914. {
  147915. emit_marker(cinfo, M_EOI);
  147916. }
  147917. METHODDEF(void)
  147918. write_tables_only (j_compress_ptr cinfo)
  147919. {
  147920. int i;
  147921. emit_marker(cinfo, M_SOI);
  147922. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147923. if (cinfo->quant_tbl_ptrs[i] != NULL)
  147924. (void) emit_dqt(cinfo, i);
  147925. }
  147926. if (! cinfo->arith_code) {
  147927. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147928. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  147929. emit_dht(cinfo, i, FALSE);
  147930. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  147931. emit_dht(cinfo, i, TRUE);
  147932. }
  147933. }
  147934. emit_marker(cinfo, M_EOI);
  147935. }
  147936. GLOBAL(void)
  147937. jinit_marker_writer (j_compress_ptr cinfo)
  147938. {
  147939. my_marker_ptr marker;
  147940. marker = (my_marker_ptr)
  147941. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147942. SIZEOF(my_marker_writer));
  147943. cinfo->marker = (struct jpeg_marker_writer *) marker;
  147944. marker->pub.write_file_header = write_file_header;
  147945. marker->pub.write_frame_header = write_frame_header;
  147946. marker->pub.write_scan_header = write_scan_header;
  147947. marker->pub.write_file_trailer = write_file_trailer;
  147948. marker->pub.write_tables_only = write_tables_only;
  147949. marker->pub.write_marker_header = write_marker_header;
  147950. marker->pub.write_marker_byte = write_marker_byte;
  147951. marker->last_restart_interval = 0;
  147952. }
  147953. /*** End of inlined file: jcmarker.c ***/
  147954. /*** Start of inlined file: jcmaster.c ***/
  147955. #define JPEG_INTERNALS
  147956. typedef enum {
  147957. main_pass, /* input data, also do first output step */
  147958. huff_opt_pass, /* Huffman code optimization pass */
  147959. output_pass /* data output pass */
  147960. } c_pass_type;
  147961. typedef struct {
  147962. struct jpeg_comp_master pub; /* public fields */
  147963. c_pass_type pass_type; /* the type of the current pass */
  147964. int pass_number; /* # of passes completed */
  147965. int total_passes; /* total # of passes needed */
  147966. int scan_number; /* current index in scan_info[] */
  147967. } my_comp_master;
  147968. typedef my_comp_master * my_master_ptr;
  147969. LOCAL(void)
  147970. initial_setup (j_compress_ptr cinfo)
  147971. {
  147972. int ci;
  147973. jpeg_component_info *compptr;
  147974. long samplesperrow;
  147975. JDIMENSION jd_samplesperrow;
  147976. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  147977. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  147978. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  147979. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  147980. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  147981. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  147982. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  147983. jd_samplesperrow = (JDIMENSION) samplesperrow;
  147984. if ((long) jd_samplesperrow != samplesperrow)
  147985. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  147986. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  147987. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  147988. if (cinfo->num_components > MAX_COMPONENTS)
  147989. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  147990. MAX_COMPONENTS);
  147991. cinfo->max_h_samp_factor = 1;
  147992. cinfo->max_v_samp_factor = 1;
  147993. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147994. ci++, compptr++) {
  147995. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  147996. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  147997. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  147998. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  147999. compptr->h_samp_factor);
  148000. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148001. compptr->v_samp_factor);
  148002. }
  148003. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148004. ci++, compptr++) {
  148005. compptr->component_index = ci;
  148006. compptr->DCT_scaled_size = DCTSIZE;
  148007. compptr->width_in_blocks = (JDIMENSION)
  148008. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148009. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148010. compptr->height_in_blocks = (JDIMENSION)
  148011. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148012. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148013. compptr->downsampled_width = (JDIMENSION)
  148014. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148015. (long) cinfo->max_h_samp_factor);
  148016. compptr->downsampled_height = (JDIMENSION)
  148017. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148018. (long) cinfo->max_v_samp_factor);
  148019. compptr->component_needed = TRUE;
  148020. }
  148021. cinfo->total_iMCU_rows = (JDIMENSION)
  148022. jdiv_round_up((long) cinfo->image_height,
  148023. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148024. }
  148025. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148026. LOCAL(void)
  148027. validate_script (j_compress_ptr cinfo)
  148028. {
  148029. const jpeg_scan_info * scanptr;
  148030. int scanno, ncomps, ci, coefi, thisi;
  148031. int Ss, Se, Ah, Al;
  148032. boolean component_sent[MAX_COMPONENTS];
  148033. #ifdef C_PROGRESSIVE_SUPPORTED
  148034. int * last_bitpos_ptr;
  148035. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148036. #endif
  148037. if (cinfo->num_scans <= 0)
  148038. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148039. scanptr = cinfo->scan_info;
  148040. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148041. #ifdef C_PROGRESSIVE_SUPPORTED
  148042. cinfo->progressive_mode = TRUE;
  148043. last_bitpos_ptr = & last_bitpos[0][0];
  148044. for (ci = 0; ci < cinfo->num_components; ci++)
  148045. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148046. *last_bitpos_ptr++ = -1;
  148047. #else
  148048. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148049. #endif
  148050. } else {
  148051. cinfo->progressive_mode = FALSE;
  148052. for (ci = 0; ci < cinfo->num_components; ci++)
  148053. component_sent[ci] = FALSE;
  148054. }
  148055. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148056. ncomps = scanptr->comps_in_scan;
  148057. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148058. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148059. for (ci = 0; ci < ncomps; ci++) {
  148060. thisi = scanptr->component_index[ci];
  148061. if (thisi < 0 || thisi >= cinfo->num_components)
  148062. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148063. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148064. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148065. }
  148066. Ss = scanptr->Ss;
  148067. Se = scanptr->Se;
  148068. Ah = scanptr->Ah;
  148069. Al = scanptr->Al;
  148070. if (cinfo->progressive_mode) {
  148071. #ifdef C_PROGRESSIVE_SUPPORTED
  148072. #if BITS_IN_JSAMPLE == 8
  148073. #define MAX_AH_AL 10
  148074. #else
  148075. #define MAX_AH_AL 13
  148076. #endif
  148077. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148078. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148079. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148080. if (Ss == 0) {
  148081. if (Se != 0) /* DC and AC together not OK */
  148082. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148083. } else {
  148084. if (ncomps != 1) /* AC scans must be for only one component */
  148085. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148086. }
  148087. for (ci = 0; ci < ncomps; ci++) {
  148088. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148089. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148090. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148091. for (coefi = Ss; coefi <= Se; coefi++) {
  148092. if (last_bitpos_ptr[coefi] < 0) {
  148093. if (Ah != 0)
  148094. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148095. } else {
  148096. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148097. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148098. }
  148099. last_bitpos_ptr[coefi] = Al;
  148100. }
  148101. }
  148102. #endif
  148103. } else {
  148104. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148105. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148106. for (ci = 0; ci < ncomps; ci++) {
  148107. thisi = scanptr->component_index[ci];
  148108. if (component_sent[thisi])
  148109. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148110. component_sent[thisi] = TRUE;
  148111. }
  148112. }
  148113. }
  148114. if (cinfo->progressive_mode) {
  148115. #ifdef C_PROGRESSIVE_SUPPORTED
  148116. for (ci = 0; ci < cinfo->num_components; ci++) {
  148117. if (last_bitpos[ci][0] < 0)
  148118. ERREXIT(cinfo, JERR_MISSING_DATA);
  148119. }
  148120. #endif
  148121. } else {
  148122. for (ci = 0; ci < cinfo->num_components; ci++) {
  148123. if (! component_sent[ci])
  148124. ERREXIT(cinfo, JERR_MISSING_DATA);
  148125. }
  148126. }
  148127. }
  148128. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148129. LOCAL(void)
  148130. select_scan_parameters (j_compress_ptr cinfo)
  148131. {
  148132. int ci;
  148133. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148134. if (cinfo->scan_info != NULL) {
  148135. my_master_ptr master = (my_master_ptr) cinfo->master;
  148136. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148137. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148138. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148139. cinfo->cur_comp_info[ci] =
  148140. &cinfo->comp_info[scanptr->component_index[ci]];
  148141. }
  148142. cinfo->Ss = scanptr->Ss;
  148143. cinfo->Se = scanptr->Se;
  148144. cinfo->Ah = scanptr->Ah;
  148145. cinfo->Al = scanptr->Al;
  148146. }
  148147. else
  148148. #endif
  148149. {
  148150. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148151. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148152. MAX_COMPS_IN_SCAN);
  148153. cinfo->comps_in_scan = cinfo->num_components;
  148154. for (ci = 0; ci < cinfo->num_components; ci++) {
  148155. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148156. }
  148157. cinfo->Ss = 0;
  148158. cinfo->Se = DCTSIZE2-1;
  148159. cinfo->Ah = 0;
  148160. cinfo->Al = 0;
  148161. }
  148162. }
  148163. LOCAL(void)
  148164. per_scan_setup (j_compress_ptr cinfo)
  148165. {
  148166. int ci, mcublks, tmp;
  148167. jpeg_component_info *compptr;
  148168. if (cinfo->comps_in_scan == 1) {
  148169. compptr = cinfo->cur_comp_info[0];
  148170. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148171. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148172. compptr->MCU_width = 1;
  148173. compptr->MCU_height = 1;
  148174. compptr->MCU_blocks = 1;
  148175. compptr->MCU_sample_width = DCTSIZE;
  148176. compptr->last_col_width = 1;
  148177. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148178. if (tmp == 0) tmp = compptr->v_samp_factor;
  148179. compptr->last_row_height = tmp;
  148180. cinfo->blocks_in_MCU = 1;
  148181. cinfo->MCU_membership[0] = 0;
  148182. } else {
  148183. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148184. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148185. MAX_COMPS_IN_SCAN);
  148186. cinfo->MCUs_per_row = (JDIMENSION)
  148187. jdiv_round_up((long) cinfo->image_width,
  148188. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148189. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148190. jdiv_round_up((long) cinfo->image_height,
  148191. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148192. cinfo->blocks_in_MCU = 0;
  148193. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148194. compptr = cinfo->cur_comp_info[ci];
  148195. compptr->MCU_width = compptr->h_samp_factor;
  148196. compptr->MCU_height = compptr->v_samp_factor;
  148197. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148198. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148199. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148200. if (tmp == 0) tmp = compptr->MCU_width;
  148201. compptr->last_col_width = tmp;
  148202. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148203. if (tmp == 0) tmp = compptr->MCU_height;
  148204. compptr->last_row_height = tmp;
  148205. mcublks = compptr->MCU_blocks;
  148206. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148207. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148208. while (mcublks-- > 0) {
  148209. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148210. }
  148211. }
  148212. }
  148213. if (cinfo->restart_in_rows > 0) {
  148214. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148215. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148216. }
  148217. }
  148218. METHODDEF(void)
  148219. prepare_for_pass (j_compress_ptr cinfo)
  148220. {
  148221. my_master_ptr master = (my_master_ptr) cinfo->master;
  148222. switch (master->pass_type) {
  148223. case main_pass:
  148224. select_scan_parameters(cinfo);
  148225. per_scan_setup(cinfo);
  148226. if (! cinfo->raw_data_in) {
  148227. (*cinfo->cconvert->start_pass) (cinfo);
  148228. (*cinfo->downsample->start_pass) (cinfo);
  148229. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148230. }
  148231. (*cinfo->fdct->start_pass) (cinfo);
  148232. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148233. (*cinfo->coef->start_pass) (cinfo,
  148234. (master->total_passes > 1 ?
  148235. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148236. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148237. if (cinfo->optimize_coding) {
  148238. master->pub.call_pass_startup = FALSE;
  148239. } else {
  148240. master->pub.call_pass_startup = TRUE;
  148241. }
  148242. break;
  148243. #ifdef ENTROPY_OPT_SUPPORTED
  148244. case huff_opt_pass:
  148245. select_scan_parameters(cinfo);
  148246. per_scan_setup(cinfo);
  148247. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148248. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148249. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148250. master->pub.call_pass_startup = FALSE;
  148251. break;
  148252. }
  148253. master->pass_type = output_pass;
  148254. master->pass_number++;
  148255. #endif
  148256. case output_pass:
  148257. if (! cinfo->optimize_coding) {
  148258. select_scan_parameters(cinfo);
  148259. per_scan_setup(cinfo);
  148260. }
  148261. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148262. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148263. if (master->scan_number == 0)
  148264. (*cinfo->marker->write_frame_header) (cinfo);
  148265. (*cinfo->marker->write_scan_header) (cinfo);
  148266. master->pub.call_pass_startup = FALSE;
  148267. break;
  148268. default:
  148269. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148270. }
  148271. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148272. if (cinfo->progress != NULL) {
  148273. cinfo->progress->completed_passes = master->pass_number;
  148274. cinfo->progress->total_passes = master->total_passes;
  148275. }
  148276. }
  148277. METHODDEF(void)
  148278. pass_startup (j_compress_ptr cinfo)
  148279. {
  148280. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148281. (*cinfo->marker->write_frame_header) (cinfo);
  148282. (*cinfo->marker->write_scan_header) (cinfo);
  148283. }
  148284. METHODDEF(void)
  148285. finish_pass_master (j_compress_ptr cinfo)
  148286. {
  148287. my_master_ptr master = (my_master_ptr) cinfo->master;
  148288. (*cinfo->entropy->finish_pass) (cinfo);
  148289. switch (master->pass_type) {
  148290. case main_pass:
  148291. master->pass_type = output_pass;
  148292. if (! cinfo->optimize_coding)
  148293. master->scan_number++;
  148294. break;
  148295. case huff_opt_pass:
  148296. master->pass_type = output_pass;
  148297. break;
  148298. case output_pass:
  148299. if (cinfo->optimize_coding)
  148300. master->pass_type = huff_opt_pass;
  148301. master->scan_number++;
  148302. break;
  148303. }
  148304. master->pass_number++;
  148305. }
  148306. GLOBAL(void)
  148307. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148308. {
  148309. my_master_ptr master;
  148310. master = (my_master_ptr)
  148311. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148312. SIZEOF(my_comp_master));
  148313. cinfo->master = (struct jpeg_comp_master *) master;
  148314. master->pub.prepare_for_pass = prepare_for_pass;
  148315. master->pub.pass_startup = pass_startup;
  148316. master->pub.finish_pass = finish_pass_master;
  148317. master->pub.is_last_pass = FALSE;
  148318. initial_setup(cinfo);
  148319. if (cinfo->scan_info != NULL) {
  148320. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148321. validate_script(cinfo);
  148322. #else
  148323. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148324. #endif
  148325. } else {
  148326. cinfo->progressive_mode = FALSE;
  148327. cinfo->num_scans = 1;
  148328. }
  148329. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148330. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148331. if (transcode_only) {
  148332. if (cinfo->optimize_coding)
  148333. master->pass_type = huff_opt_pass;
  148334. else
  148335. master->pass_type = output_pass;
  148336. } else {
  148337. master->pass_type = main_pass;
  148338. }
  148339. master->scan_number = 0;
  148340. master->pass_number = 0;
  148341. if (cinfo->optimize_coding)
  148342. master->total_passes = cinfo->num_scans * 2;
  148343. else
  148344. master->total_passes = cinfo->num_scans;
  148345. }
  148346. /*** End of inlined file: jcmaster.c ***/
  148347. /*** Start of inlined file: jcomapi.c ***/
  148348. #define JPEG_INTERNALS
  148349. GLOBAL(void)
  148350. jpeg_abort (j_common_ptr cinfo)
  148351. {
  148352. int pool;
  148353. if (cinfo->mem == NULL)
  148354. return;
  148355. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148356. (*cinfo->mem->free_pool) (cinfo, pool);
  148357. }
  148358. if (cinfo->is_decompressor) {
  148359. cinfo->global_state = DSTATE_START;
  148360. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148361. } else {
  148362. cinfo->global_state = CSTATE_START;
  148363. }
  148364. }
  148365. GLOBAL(void)
  148366. jpeg_destroy (j_common_ptr cinfo)
  148367. {
  148368. if (cinfo->mem != NULL)
  148369. (*cinfo->mem->self_destruct) (cinfo);
  148370. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148371. cinfo->global_state = 0; /* mark it destroyed */
  148372. }
  148373. GLOBAL(JQUANT_TBL *)
  148374. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148375. {
  148376. JQUANT_TBL *tbl;
  148377. tbl = (JQUANT_TBL *)
  148378. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148379. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148380. return tbl;
  148381. }
  148382. GLOBAL(JHUFF_TBL *)
  148383. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148384. {
  148385. JHUFF_TBL *tbl;
  148386. tbl = (JHUFF_TBL *)
  148387. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148388. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148389. return tbl;
  148390. }
  148391. /*** End of inlined file: jcomapi.c ***/
  148392. /*** Start of inlined file: jcparam.c ***/
  148393. #define JPEG_INTERNALS
  148394. GLOBAL(void)
  148395. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148396. const unsigned int *basic_table,
  148397. int scale_factor, boolean force_baseline)
  148398. {
  148399. JQUANT_TBL ** qtblptr;
  148400. int i;
  148401. long temp;
  148402. if (cinfo->global_state != CSTATE_START)
  148403. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148404. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148405. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148406. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148407. if (*qtblptr == NULL)
  148408. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148409. for (i = 0; i < DCTSIZE2; i++) {
  148410. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148411. if (temp <= 0L) temp = 1L;
  148412. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148413. if (force_baseline && temp > 255L)
  148414. temp = 255L; /* limit to baseline range if requested */
  148415. (*qtblptr)->quantval[i] = (UINT16) temp;
  148416. }
  148417. (*qtblptr)->sent_table = FALSE;
  148418. }
  148419. GLOBAL(void)
  148420. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148421. boolean force_baseline)
  148422. {
  148423. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148424. 16, 11, 10, 16, 24, 40, 51, 61,
  148425. 12, 12, 14, 19, 26, 58, 60, 55,
  148426. 14, 13, 16, 24, 40, 57, 69, 56,
  148427. 14, 17, 22, 29, 51, 87, 80, 62,
  148428. 18, 22, 37, 56, 68, 109, 103, 77,
  148429. 24, 35, 55, 64, 81, 104, 113, 92,
  148430. 49, 64, 78, 87, 103, 121, 120, 101,
  148431. 72, 92, 95, 98, 112, 100, 103, 99
  148432. };
  148433. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148434. 17, 18, 24, 47, 99, 99, 99, 99,
  148435. 18, 21, 26, 66, 99, 99, 99, 99,
  148436. 24, 26, 56, 99, 99, 99, 99, 99,
  148437. 47, 66, 99, 99, 99, 99, 99, 99,
  148438. 99, 99, 99, 99, 99, 99, 99, 99,
  148439. 99, 99, 99, 99, 99, 99, 99, 99,
  148440. 99, 99, 99, 99, 99, 99, 99, 99,
  148441. 99, 99, 99, 99, 99, 99, 99, 99
  148442. };
  148443. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148444. scale_factor, force_baseline);
  148445. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148446. scale_factor, force_baseline);
  148447. }
  148448. GLOBAL(int)
  148449. jpeg_quality_scaling (int quality)
  148450. {
  148451. if (quality <= 0) quality = 1;
  148452. if (quality > 100) quality = 100;
  148453. if (quality < 50)
  148454. quality = 5000 / quality;
  148455. else
  148456. quality = 200 - quality*2;
  148457. return quality;
  148458. }
  148459. GLOBAL(void)
  148460. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148461. {
  148462. quality = jpeg_quality_scaling(quality);
  148463. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148464. }
  148465. LOCAL(void)
  148466. add_huff_table (j_compress_ptr cinfo,
  148467. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148468. {
  148469. int nsymbols, len;
  148470. if (*htblptr == NULL)
  148471. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148472. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148473. nsymbols = 0;
  148474. for (len = 1; len <= 16; len++)
  148475. nsymbols += bits[len];
  148476. if (nsymbols < 1 || nsymbols > 256)
  148477. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148478. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148479. (*htblptr)->sent_table = FALSE;
  148480. }
  148481. LOCAL(void)
  148482. std_huff_tables (j_compress_ptr cinfo)
  148483. {
  148484. static const UINT8 bits_dc_luminance[17] =
  148485. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148486. static const UINT8 val_dc_luminance[] =
  148487. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148488. static const UINT8 bits_dc_chrominance[17] =
  148489. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148490. static const UINT8 val_dc_chrominance[] =
  148491. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148492. static const UINT8 bits_ac_luminance[17] =
  148493. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148494. static const UINT8 val_ac_luminance[] =
  148495. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148496. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148497. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148498. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148499. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148500. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148501. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148502. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148503. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148504. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148505. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148506. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148507. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148508. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148509. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148510. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148511. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148512. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148513. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148514. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148515. 0xf9, 0xfa };
  148516. static const UINT8 bits_ac_chrominance[17] =
  148517. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148518. static const UINT8 val_ac_chrominance[] =
  148519. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148520. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148521. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148522. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148523. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148524. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148525. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148526. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148527. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148528. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148529. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148530. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148531. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148532. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148533. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148534. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148535. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148536. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148537. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148538. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148539. 0xf9, 0xfa };
  148540. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148541. bits_dc_luminance, val_dc_luminance);
  148542. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148543. bits_ac_luminance, val_ac_luminance);
  148544. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148545. bits_dc_chrominance, val_dc_chrominance);
  148546. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148547. bits_ac_chrominance, val_ac_chrominance);
  148548. }
  148549. GLOBAL(void)
  148550. jpeg_set_defaults (j_compress_ptr cinfo)
  148551. {
  148552. int i;
  148553. if (cinfo->global_state != CSTATE_START)
  148554. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148555. if (cinfo->comp_info == NULL)
  148556. cinfo->comp_info = (jpeg_component_info *)
  148557. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148558. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148559. cinfo->data_precision = BITS_IN_JSAMPLE;
  148560. jpeg_set_quality(cinfo, 75, TRUE);
  148561. std_huff_tables(cinfo);
  148562. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148563. cinfo->arith_dc_L[i] = 0;
  148564. cinfo->arith_dc_U[i] = 1;
  148565. cinfo->arith_ac_K[i] = 5;
  148566. }
  148567. cinfo->scan_info = NULL;
  148568. cinfo->num_scans = 0;
  148569. cinfo->raw_data_in = FALSE;
  148570. cinfo->arith_code = FALSE;
  148571. cinfo->optimize_coding = FALSE;
  148572. if (cinfo->data_precision > 8)
  148573. cinfo->optimize_coding = TRUE;
  148574. cinfo->CCIR601_sampling = FALSE;
  148575. cinfo->smoothing_factor = 0;
  148576. cinfo->dct_method = JDCT_DEFAULT;
  148577. cinfo->restart_interval = 0;
  148578. cinfo->restart_in_rows = 0;
  148579. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148580. cinfo->JFIF_minor_version = 1;
  148581. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148582. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148583. cinfo->Y_density = 1;
  148584. jpeg_default_colorspace(cinfo);
  148585. }
  148586. GLOBAL(void)
  148587. jpeg_default_colorspace (j_compress_ptr cinfo)
  148588. {
  148589. switch (cinfo->in_color_space) {
  148590. case JCS_GRAYSCALE:
  148591. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148592. break;
  148593. case JCS_RGB:
  148594. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148595. break;
  148596. case JCS_YCbCr:
  148597. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148598. break;
  148599. case JCS_CMYK:
  148600. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148601. break;
  148602. case JCS_YCCK:
  148603. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148604. break;
  148605. case JCS_UNKNOWN:
  148606. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148607. break;
  148608. default:
  148609. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148610. }
  148611. }
  148612. GLOBAL(void)
  148613. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148614. {
  148615. jpeg_component_info * compptr;
  148616. int ci;
  148617. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148618. (compptr = &cinfo->comp_info[index], \
  148619. compptr->component_id = (id), \
  148620. compptr->h_samp_factor = (hsamp), \
  148621. compptr->v_samp_factor = (vsamp), \
  148622. compptr->quant_tbl_no = (quant), \
  148623. compptr->dc_tbl_no = (dctbl), \
  148624. compptr->ac_tbl_no = (actbl) )
  148625. if (cinfo->global_state != CSTATE_START)
  148626. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148627. cinfo->jpeg_color_space = colorspace;
  148628. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148629. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148630. switch (colorspace) {
  148631. case JCS_GRAYSCALE:
  148632. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148633. cinfo->num_components = 1;
  148634. SET_COMP(0, 1, 1,1, 0, 0,0);
  148635. break;
  148636. case JCS_RGB:
  148637. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148638. cinfo->num_components = 3;
  148639. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148640. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148641. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148642. break;
  148643. case JCS_YCbCr:
  148644. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148645. cinfo->num_components = 3;
  148646. SET_COMP(0, 1, 2,2, 0, 0,0);
  148647. SET_COMP(1, 2, 1,1, 1, 1,1);
  148648. SET_COMP(2, 3, 1,1, 1, 1,1);
  148649. break;
  148650. case JCS_CMYK:
  148651. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148652. cinfo->num_components = 4;
  148653. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148654. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148655. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148656. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148657. break;
  148658. case JCS_YCCK:
  148659. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148660. cinfo->num_components = 4;
  148661. SET_COMP(0, 1, 2,2, 0, 0,0);
  148662. SET_COMP(1, 2, 1,1, 1, 1,1);
  148663. SET_COMP(2, 3, 1,1, 1, 1,1);
  148664. SET_COMP(3, 4, 2,2, 0, 0,0);
  148665. break;
  148666. case JCS_UNKNOWN:
  148667. cinfo->num_components = cinfo->input_components;
  148668. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148669. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148670. MAX_COMPONENTS);
  148671. for (ci = 0; ci < cinfo->num_components; ci++) {
  148672. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148673. }
  148674. break;
  148675. default:
  148676. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148677. }
  148678. }
  148679. #ifdef C_PROGRESSIVE_SUPPORTED
  148680. LOCAL(jpeg_scan_info *)
  148681. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148682. int Ss, int Se, int Ah, int Al)
  148683. {
  148684. scanptr->comps_in_scan = 1;
  148685. scanptr->component_index[0] = ci;
  148686. scanptr->Ss = Ss;
  148687. scanptr->Se = Se;
  148688. scanptr->Ah = Ah;
  148689. scanptr->Al = Al;
  148690. scanptr++;
  148691. return scanptr;
  148692. }
  148693. LOCAL(jpeg_scan_info *)
  148694. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148695. int Ss, int Se, int Ah, int Al)
  148696. {
  148697. int ci;
  148698. for (ci = 0; ci < ncomps; ci++) {
  148699. scanptr->comps_in_scan = 1;
  148700. scanptr->component_index[0] = ci;
  148701. scanptr->Ss = Ss;
  148702. scanptr->Se = Se;
  148703. scanptr->Ah = Ah;
  148704. scanptr->Al = Al;
  148705. scanptr++;
  148706. }
  148707. return scanptr;
  148708. }
  148709. LOCAL(jpeg_scan_info *)
  148710. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148711. {
  148712. int ci;
  148713. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148714. scanptr->comps_in_scan = ncomps;
  148715. for (ci = 0; ci < ncomps; ci++)
  148716. scanptr->component_index[ci] = ci;
  148717. scanptr->Ss = scanptr->Se = 0;
  148718. scanptr->Ah = Ah;
  148719. scanptr->Al = Al;
  148720. scanptr++;
  148721. } else {
  148722. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148723. }
  148724. return scanptr;
  148725. }
  148726. GLOBAL(void)
  148727. jpeg_simple_progression (j_compress_ptr cinfo)
  148728. {
  148729. int ncomps = cinfo->num_components;
  148730. int nscans;
  148731. jpeg_scan_info * scanptr;
  148732. if (cinfo->global_state != CSTATE_START)
  148733. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148734. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148735. nscans = 10;
  148736. } else {
  148737. if (ncomps > MAX_COMPS_IN_SCAN)
  148738. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148739. else
  148740. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148741. }
  148742. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148743. cinfo->script_space_size = MAX(nscans, 10);
  148744. cinfo->script_space = (jpeg_scan_info *)
  148745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148746. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148747. }
  148748. scanptr = cinfo->script_space;
  148749. cinfo->scan_info = scanptr;
  148750. cinfo->num_scans = nscans;
  148751. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148752. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148753. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148754. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148755. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148756. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148757. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148758. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148759. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148760. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148761. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148762. } else {
  148763. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148764. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148765. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148766. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148767. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148768. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148769. }
  148770. }
  148771. #endif /* C_PROGRESSIVE_SUPPORTED */
  148772. /*** End of inlined file: jcparam.c ***/
  148773. /*** Start of inlined file: jcphuff.c ***/
  148774. #define JPEG_INTERNALS
  148775. #ifdef C_PROGRESSIVE_SUPPORTED
  148776. typedef struct {
  148777. struct jpeg_entropy_encoder pub; /* public fields */
  148778. boolean gather_statistics;
  148779. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148780. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148781. INT32 put_buffer; /* current bit-accumulation buffer */
  148782. int put_bits; /* # of bits now in it */
  148783. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148784. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148785. int ac_tbl_no; /* the table number of the single component */
  148786. unsigned int EOBRUN; /* run length of EOBs */
  148787. unsigned int BE; /* # of buffered correction bits before MCU */
  148788. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148789. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148790. int next_restart_num; /* next restart number to write (0-7) */
  148791. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148792. long * count_ptrs[NUM_HUFF_TBLS];
  148793. } phuff_entropy_encoder;
  148794. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148795. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148796. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148797. #define ISHIFT_TEMPS int ishift_temp;
  148798. #define IRIGHT_SHIFT(x,shft) \
  148799. ((ishift_temp = (x)) < 0 ? \
  148800. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148801. (ishift_temp >> (shft)))
  148802. #else
  148803. #define ISHIFT_TEMPS
  148804. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148805. #endif
  148806. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148807. JBLOCKROW *MCU_data));
  148808. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148809. JBLOCKROW *MCU_data));
  148810. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148811. JBLOCKROW *MCU_data));
  148812. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148813. JBLOCKROW *MCU_data));
  148814. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148815. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148816. METHODDEF(void)
  148817. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148818. {
  148819. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148820. boolean is_DC_band;
  148821. int ci, tbl;
  148822. jpeg_component_info * compptr;
  148823. entropy->cinfo = cinfo;
  148824. entropy->gather_statistics = gather_statistics;
  148825. is_DC_band = (cinfo->Ss == 0);
  148826. if (cinfo->Ah == 0) {
  148827. if (is_DC_band)
  148828. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148829. else
  148830. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148831. } else {
  148832. if (is_DC_band)
  148833. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148834. else {
  148835. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148836. if (entropy->bit_buffer == NULL)
  148837. entropy->bit_buffer = (char *)
  148838. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148839. MAX_CORR_BITS * SIZEOF(char));
  148840. }
  148841. }
  148842. if (gather_statistics)
  148843. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148844. else
  148845. entropy->pub.finish_pass = finish_pass_phuff;
  148846. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148847. compptr = cinfo->cur_comp_info[ci];
  148848. entropy->last_dc_val[ci] = 0;
  148849. if (is_DC_band) {
  148850. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148851. continue;
  148852. tbl = compptr->dc_tbl_no;
  148853. } else {
  148854. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148855. }
  148856. if (gather_statistics) {
  148857. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148858. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148859. if (entropy->count_ptrs[tbl] == NULL)
  148860. entropy->count_ptrs[tbl] = (long *)
  148861. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148862. 257 * SIZEOF(long));
  148863. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148864. } else {
  148865. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148866. & entropy->derived_tbls[tbl]);
  148867. }
  148868. }
  148869. entropy->EOBRUN = 0;
  148870. entropy->BE = 0;
  148871. entropy->put_buffer = 0;
  148872. entropy->put_bits = 0;
  148873. entropy->restarts_to_go = cinfo->restart_interval;
  148874. entropy->next_restart_num = 0;
  148875. }
  148876. #define emit_byte(entropy,val) \
  148877. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148878. if (--(entropy)->free_in_buffer == 0) \
  148879. dump_buffer_p(entropy); }
  148880. LOCAL(void)
  148881. dump_buffer_p (phuff_entropy_ptr entropy)
  148882. {
  148883. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148884. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148885. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148886. entropy->next_output_byte = dest->next_output_byte;
  148887. entropy->free_in_buffer = dest->free_in_buffer;
  148888. }
  148889. INLINE
  148890. LOCAL(void)
  148891. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148892. {
  148893. register INT32 put_buffer = (INT32) code;
  148894. register int put_bits = entropy->put_bits;
  148895. if (size == 0)
  148896. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148897. if (entropy->gather_statistics)
  148898. return; /* do nothing if we're only getting stats */
  148899. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148900. put_bits += size; /* new number of bits in buffer */
  148901. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148902. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148903. while (put_bits >= 8) {
  148904. int c = (int) ((put_buffer >> 16) & 0xFF);
  148905. emit_byte(entropy, c);
  148906. if (c == 0xFF) { /* need to stuff a zero byte? */
  148907. emit_byte(entropy, 0);
  148908. }
  148909. put_buffer <<= 8;
  148910. put_bits -= 8;
  148911. }
  148912. entropy->put_buffer = put_buffer; /* update variables */
  148913. entropy->put_bits = put_bits;
  148914. }
  148915. LOCAL(void)
  148916. flush_bits_p (phuff_entropy_ptr entropy)
  148917. {
  148918. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  148919. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  148920. entropy->put_bits = 0;
  148921. }
  148922. INLINE
  148923. LOCAL(void)
  148924. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  148925. {
  148926. if (entropy->gather_statistics)
  148927. entropy->count_ptrs[tbl_no][symbol]++;
  148928. else {
  148929. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  148930. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  148931. }
  148932. }
  148933. LOCAL(void)
  148934. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  148935. unsigned int nbits)
  148936. {
  148937. if (entropy->gather_statistics)
  148938. return; /* no real work */
  148939. while (nbits > 0) {
  148940. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  148941. bufstart++;
  148942. nbits--;
  148943. }
  148944. }
  148945. LOCAL(void)
  148946. emit_eobrun (phuff_entropy_ptr entropy)
  148947. {
  148948. register int temp, nbits;
  148949. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  148950. temp = entropy->EOBRUN;
  148951. nbits = 0;
  148952. while ((temp >>= 1))
  148953. nbits++;
  148954. if (nbits > 14)
  148955. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148956. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  148957. if (nbits)
  148958. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  148959. entropy->EOBRUN = 0;
  148960. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  148961. entropy->BE = 0;
  148962. }
  148963. }
  148964. LOCAL(void)
  148965. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  148966. {
  148967. int ci;
  148968. emit_eobrun(entropy);
  148969. if (! entropy->gather_statistics) {
  148970. flush_bits_p(entropy);
  148971. emit_byte(entropy, 0xFF);
  148972. emit_byte(entropy, JPEG_RST0 + restart_num);
  148973. }
  148974. if (entropy->cinfo->Ss == 0) {
  148975. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  148976. entropy->last_dc_val[ci] = 0;
  148977. } else {
  148978. entropy->EOBRUN = 0;
  148979. entropy->BE = 0;
  148980. }
  148981. }
  148982. METHODDEF(boolean)
  148983. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148984. {
  148985. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148986. register int temp, temp2;
  148987. register int nbits;
  148988. int blkn, ci;
  148989. int Al = cinfo->Al;
  148990. JBLOCKROW block;
  148991. jpeg_component_info * compptr;
  148992. ISHIFT_TEMPS
  148993. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148994. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148995. if (cinfo->restart_interval)
  148996. if (entropy->restarts_to_go == 0)
  148997. emit_restart_p(entropy, entropy->next_restart_num);
  148998. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148999. block = MCU_data[blkn];
  149000. ci = cinfo->MCU_membership[blkn];
  149001. compptr = cinfo->cur_comp_info[ci];
  149002. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149003. temp = temp2 - entropy->last_dc_val[ci];
  149004. entropy->last_dc_val[ci] = temp2;
  149005. temp2 = temp;
  149006. if (temp < 0) {
  149007. temp = -temp; /* temp is abs value of input */
  149008. temp2--;
  149009. }
  149010. nbits = 0;
  149011. while (temp) {
  149012. nbits++;
  149013. temp >>= 1;
  149014. }
  149015. if (nbits > MAX_COEF_BITS+1)
  149016. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149017. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149018. if (nbits) /* emit_bits rejects calls with size 0 */
  149019. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149020. }
  149021. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149022. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149023. if (cinfo->restart_interval) {
  149024. if (entropy->restarts_to_go == 0) {
  149025. entropy->restarts_to_go = cinfo->restart_interval;
  149026. entropy->next_restart_num++;
  149027. entropy->next_restart_num &= 7;
  149028. }
  149029. entropy->restarts_to_go--;
  149030. }
  149031. return TRUE;
  149032. }
  149033. METHODDEF(boolean)
  149034. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149035. {
  149036. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149037. register int temp, temp2;
  149038. register int nbits;
  149039. register int r, k;
  149040. int Se = cinfo->Se;
  149041. int Al = cinfo->Al;
  149042. JBLOCKROW block;
  149043. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149044. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149045. if (cinfo->restart_interval)
  149046. if (entropy->restarts_to_go == 0)
  149047. emit_restart_p(entropy, entropy->next_restart_num);
  149048. block = MCU_data[0];
  149049. r = 0; /* r = run length of zeros */
  149050. for (k = cinfo->Ss; k <= Se; k++) {
  149051. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149052. r++;
  149053. continue;
  149054. }
  149055. if (temp < 0) {
  149056. temp = -temp; /* temp is abs value of input */
  149057. temp >>= Al; /* apply the point transform */
  149058. temp2 = ~temp;
  149059. } else {
  149060. temp >>= Al; /* apply the point transform */
  149061. temp2 = temp;
  149062. }
  149063. if (temp == 0) {
  149064. r++;
  149065. continue;
  149066. }
  149067. if (entropy->EOBRUN > 0)
  149068. emit_eobrun(entropy);
  149069. while (r > 15) {
  149070. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149071. r -= 16;
  149072. }
  149073. nbits = 1; /* there must be at least one 1 bit */
  149074. while ((temp >>= 1))
  149075. nbits++;
  149076. if (nbits > MAX_COEF_BITS)
  149077. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149078. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149079. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149080. r = 0; /* reset zero run length */
  149081. }
  149082. if (r > 0) { /* If there are trailing zeroes, */
  149083. entropy->EOBRUN++; /* count an EOB */
  149084. if (entropy->EOBRUN == 0x7FFF)
  149085. emit_eobrun(entropy); /* force it out to avoid overflow */
  149086. }
  149087. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149088. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149089. if (cinfo->restart_interval) {
  149090. if (entropy->restarts_to_go == 0) {
  149091. entropy->restarts_to_go = cinfo->restart_interval;
  149092. entropy->next_restart_num++;
  149093. entropy->next_restart_num &= 7;
  149094. }
  149095. entropy->restarts_to_go--;
  149096. }
  149097. return TRUE;
  149098. }
  149099. METHODDEF(boolean)
  149100. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149101. {
  149102. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149103. register int temp;
  149104. int blkn;
  149105. int Al = cinfo->Al;
  149106. JBLOCKROW block;
  149107. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149108. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149109. if (cinfo->restart_interval)
  149110. if (entropy->restarts_to_go == 0)
  149111. emit_restart_p(entropy, entropy->next_restart_num);
  149112. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149113. block = MCU_data[blkn];
  149114. temp = (*block)[0];
  149115. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149116. }
  149117. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149118. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149119. if (cinfo->restart_interval) {
  149120. if (entropy->restarts_to_go == 0) {
  149121. entropy->restarts_to_go = cinfo->restart_interval;
  149122. entropy->next_restart_num++;
  149123. entropy->next_restart_num &= 7;
  149124. }
  149125. entropy->restarts_to_go--;
  149126. }
  149127. return TRUE;
  149128. }
  149129. METHODDEF(boolean)
  149130. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149131. {
  149132. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149133. register int temp;
  149134. register int r, k;
  149135. int EOB;
  149136. char *BR_buffer;
  149137. unsigned int BR;
  149138. int Se = cinfo->Se;
  149139. int Al = cinfo->Al;
  149140. JBLOCKROW block;
  149141. int absvalues[DCTSIZE2];
  149142. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149143. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149144. if (cinfo->restart_interval)
  149145. if (entropy->restarts_to_go == 0)
  149146. emit_restart_p(entropy, entropy->next_restart_num);
  149147. block = MCU_data[0];
  149148. EOB = 0;
  149149. for (k = cinfo->Ss; k <= Se; k++) {
  149150. temp = (*block)[jpeg_natural_order[k]];
  149151. if (temp < 0)
  149152. temp = -temp; /* temp is abs value of input */
  149153. temp >>= Al; /* apply the point transform */
  149154. absvalues[k] = temp; /* save abs value for main pass */
  149155. if (temp == 1)
  149156. EOB = k; /* EOB = index of last newly-nonzero coef */
  149157. }
  149158. r = 0; /* r = run length of zeros */
  149159. BR = 0; /* BR = count of buffered bits added now */
  149160. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149161. for (k = cinfo->Ss; k <= Se; k++) {
  149162. if ((temp = absvalues[k]) == 0) {
  149163. r++;
  149164. continue;
  149165. }
  149166. while (r > 15 && k <= EOB) {
  149167. emit_eobrun(entropy);
  149168. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149169. r -= 16;
  149170. emit_buffered_bits(entropy, BR_buffer, BR);
  149171. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149172. BR = 0;
  149173. }
  149174. if (temp > 1) {
  149175. BR_buffer[BR++] = (char) (temp & 1);
  149176. continue;
  149177. }
  149178. emit_eobrun(entropy);
  149179. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149180. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149181. emit_bits_p(entropy, (unsigned int) temp, 1);
  149182. emit_buffered_bits(entropy, BR_buffer, BR);
  149183. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149184. BR = 0;
  149185. r = 0; /* reset zero run length */
  149186. }
  149187. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149188. entropy->EOBRUN++; /* count an EOB */
  149189. entropy->BE += BR; /* concat my correction bits to older ones */
  149190. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149191. emit_eobrun(entropy);
  149192. }
  149193. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149194. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149195. if (cinfo->restart_interval) {
  149196. if (entropy->restarts_to_go == 0) {
  149197. entropy->restarts_to_go = cinfo->restart_interval;
  149198. entropy->next_restart_num++;
  149199. entropy->next_restart_num &= 7;
  149200. }
  149201. entropy->restarts_to_go--;
  149202. }
  149203. return TRUE;
  149204. }
  149205. METHODDEF(void)
  149206. finish_pass_phuff (j_compress_ptr cinfo)
  149207. {
  149208. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149209. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149210. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149211. emit_eobrun(entropy);
  149212. flush_bits_p(entropy);
  149213. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149214. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149215. }
  149216. METHODDEF(void)
  149217. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149218. {
  149219. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149220. boolean is_DC_band;
  149221. int ci, tbl;
  149222. jpeg_component_info * compptr;
  149223. JHUFF_TBL **htblptr;
  149224. boolean did[NUM_HUFF_TBLS];
  149225. emit_eobrun(entropy);
  149226. is_DC_band = (cinfo->Ss == 0);
  149227. MEMZERO(did, SIZEOF(did));
  149228. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149229. compptr = cinfo->cur_comp_info[ci];
  149230. if (is_DC_band) {
  149231. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149232. continue;
  149233. tbl = compptr->dc_tbl_no;
  149234. } else {
  149235. tbl = compptr->ac_tbl_no;
  149236. }
  149237. if (! did[tbl]) {
  149238. if (is_DC_band)
  149239. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149240. else
  149241. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149242. if (*htblptr == NULL)
  149243. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149244. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149245. did[tbl] = TRUE;
  149246. }
  149247. }
  149248. }
  149249. GLOBAL(void)
  149250. jinit_phuff_encoder (j_compress_ptr cinfo)
  149251. {
  149252. phuff_entropy_ptr entropy;
  149253. int i;
  149254. entropy = (phuff_entropy_ptr)
  149255. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149256. SIZEOF(phuff_entropy_encoder));
  149257. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149258. entropy->pub.start_pass = start_pass_phuff;
  149259. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149260. entropy->derived_tbls[i] = NULL;
  149261. entropy->count_ptrs[i] = NULL;
  149262. }
  149263. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149264. }
  149265. #endif /* C_PROGRESSIVE_SUPPORTED */
  149266. /*** End of inlined file: jcphuff.c ***/
  149267. /*** Start of inlined file: jcprepct.c ***/
  149268. #define JPEG_INTERNALS
  149269. #ifdef INPUT_SMOOTHING_SUPPORTED
  149270. #define CONTEXT_ROWS_SUPPORTED
  149271. #endif
  149272. typedef struct {
  149273. struct jpeg_c_prep_controller pub; /* public fields */
  149274. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149275. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149276. int next_buf_row; /* index of next row to store in color_buf */
  149277. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149278. int this_row_group; /* starting row index of group to process */
  149279. int next_buf_stop; /* downsample when we reach this index */
  149280. #endif
  149281. } my_prep_controller;
  149282. typedef my_prep_controller * my_prep_ptr;
  149283. METHODDEF(void)
  149284. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149285. {
  149286. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149287. if (pass_mode != JBUF_PASS_THRU)
  149288. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149289. prep->rows_to_go = cinfo->image_height;
  149290. prep->next_buf_row = 0;
  149291. #ifdef CONTEXT_ROWS_SUPPORTED
  149292. prep->this_row_group = 0;
  149293. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149294. #endif
  149295. }
  149296. LOCAL(void)
  149297. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149298. int input_rows, int output_rows)
  149299. {
  149300. register int row;
  149301. for (row = input_rows; row < output_rows; row++) {
  149302. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149303. 1, num_cols);
  149304. }
  149305. }
  149306. METHODDEF(void)
  149307. pre_process_data (j_compress_ptr cinfo,
  149308. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149309. JDIMENSION in_rows_avail,
  149310. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149311. JDIMENSION out_row_groups_avail)
  149312. {
  149313. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149314. int numrows, ci;
  149315. JDIMENSION inrows;
  149316. jpeg_component_info * compptr;
  149317. while (*in_row_ctr < in_rows_avail &&
  149318. *out_row_group_ctr < out_row_groups_avail) {
  149319. inrows = in_rows_avail - *in_row_ctr;
  149320. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149321. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149322. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149323. prep->color_buf,
  149324. (JDIMENSION) prep->next_buf_row,
  149325. numrows);
  149326. *in_row_ctr += numrows;
  149327. prep->next_buf_row += numrows;
  149328. prep->rows_to_go -= numrows;
  149329. if (prep->rows_to_go == 0 &&
  149330. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149331. for (ci = 0; ci < cinfo->num_components; ci++) {
  149332. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149333. prep->next_buf_row, cinfo->max_v_samp_factor);
  149334. }
  149335. prep->next_buf_row = cinfo->max_v_samp_factor;
  149336. }
  149337. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149338. (*cinfo->downsample->downsample) (cinfo,
  149339. prep->color_buf, (JDIMENSION) 0,
  149340. output_buf, *out_row_group_ctr);
  149341. prep->next_buf_row = 0;
  149342. (*out_row_group_ctr)++;
  149343. }
  149344. if (prep->rows_to_go == 0 &&
  149345. *out_row_group_ctr < out_row_groups_avail) {
  149346. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149347. ci++, compptr++) {
  149348. expand_bottom_edge(output_buf[ci],
  149349. compptr->width_in_blocks * DCTSIZE,
  149350. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149351. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149352. }
  149353. *out_row_group_ctr = out_row_groups_avail;
  149354. break; /* can exit outer loop without test */
  149355. }
  149356. }
  149357. }
  149358. #ifdef CONTEXT_ROWS_SUPPORTED
  149359. METHODDEF(void)
  149360. pre_process_context (j_compress_ptr cinfo,
  149361. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149362. JDIMENSION in_rows_avail,
  149363. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149364. JDIMENSION out_row_groups_avail)
  149365. {
  149366. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149367. int numrows, ci;
  149368. int buf_height = cinfo->max_v_samp_factor * 3;
  149369. JDIMENSION inrows;
  149370. while (*out_row_group_ctr < out_row_groups_avail) {
  149371. if (*in_row_ctr < in_rows_avail) {
  149372. inrows = in_rows_avail - *in_row_ctr;
  149373. numrows = prep->next_buf_stop - prep->next_buf_row;
  149374. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149375. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149376. prep->color_buf,
  149377. (JDIMENSION) prep->next_buf_row,
  149378. numrows);
  149379. if (prep->rows_to_go == cinfo->image_height) {
  149380. for (ci = 0; ci < cinfo->num_components; ci++) {
  149381. int row;
  149382. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149383. jcopy_sample_rows(prep->color_buf[ci], 0,
  149384. prep->color_buf[ci], -row,
  149385. 1, cinfo->image_width);
  149386. }
  149387. }
  149388. }
  149389. *in_row_ctr += numrows;
  149390. prep->next_buf_row += numrows;
  149391. prep->rows_to_go -= numrows;
  149392. } else {
  149393. if (prep->rows_to_go != 0)
  149394. break;
  149395. if (prep->next_buf_row < prep->next_buf_stop) {
  149396. for (ci = 0; ci < cinfo->num_components; ci++) {
  149397. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149398. prep->next_buf_row, prep->next_buf_stop);
  149399. }
  149400. prep->next_buf_row = prep->next_buf_stop;
  149401. }
  149402. }
  149403. if (prep->next_buf_row == prep->next_buf_stop) {
  149404. (*cinfo->downsample->downsample) (cinfo,
  149405. prep->color_buf,
  149406. (JDIMENSION) prep->this_row_group,
  149407. output_buf, *out_row_group_ctr);
  149408. (*out_row_group_ctr)++;
  149409. prep->this_row_group += cinfo->max_v_samp_factor;
  149410. if (prep->this_row_group >= buf_height)
  149411. prep->this_row_group = 0;
  149412. if (prep->next_buf_row >= buf_height)
  149413. prep->next_buf_row = 0;
  149414. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149415. }
  149416. }
  149417. }
  149418. LOCAL(void)
  149419. create_context_buffer (j_compress_ptr cinfo)
  149420. {
  149421. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149422. int rgroup_height = cinfo->max_v_samp_factor;
  149423. int ci, i;
  149424. jpeg_component_info * compptr;
  149425. JSAMPARRAY true_buffer, fake_buffer;
  149426. fake_buffer = (JSAMPARRAY)
  149427. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149428. (cinfo->num_components * 5 * rgroup_height) *
  149429. SIZEOF(JSAMPROW));
  149430. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149431. ci++, compptr++) {
  149432. true_buffer = (*cinfo->mem->alloc_sarray)
  149433. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149434. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149435. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149436. (JDIMENSION) (3 * rgroup_height));
  149437. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149438. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149439. for (i = 0; i < rgroup_height; i++) {
  149440. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149441. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149442. }
  149443. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149444. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149445. }
  149446. }
  149447. #endif /* CONTEXT_ROWS_SUPPORTED */
  149448. GLOBAL(void)
  149449. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149450. {
  149451. my_prep_ptr prep;
  149452. int ci;
  149453. jpeg_component_info * compptr;
  149454. if (need_full_buffer) /* safety check */
  149455. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149456. prep = (my_prep_ptr)
  149457. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149458. SIZEOF(my_prep_controller));
  149459. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149460. prep->pub.start_pass = start_pass_prep;
  149461. if (cinfo->downsample->need_context_rows) {
  149462. #ifdef CONTEXT_ROWS_SUPPORTED
  149463. prep->pub.pre_process_data = pre_process_context;
  149464. create_context_buffer(cinfo);
  149465. #else
  149466. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149467. #endif
  149468. } else {
  149469. prep->pub.pre_process_data = pre_process_data;
  149470. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149471. ci++, compptr++) {
  149472. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149473. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149474. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149475. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149476. (JDIMENSION) cinfo->max_v_samp_factor);
  149477. }
  149478. }
  149479. }
  149480. /*** End of inlined file: jcprepct.c ***/
  149481. /*** Start of inlined file: jcsample.c ***/
  149482. #define JPEG_INTERNALS
  149483. typedef JMETHOD(void, downsample1_ptr,
  149484. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149485. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149486. typedef struct {
  149487. struct jpeg_downsampler pub; /* public fields */
  149488. downsample1_ptr methods[MAX_COMPONENTS];
  149489. } my_downsampler;
  149490. typedef my_downsampler * my_downsample_ptr;
  149491. METHODDEF(void)
  149492. start_pass_downsample (j_compress_ptr cinfo)
  149493. {
  149494. }
  149495. LOCAL(void)
  149496. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149497. JDIMENSION input_cols, JDIMENSION output_cols)
  149498. {
  149499. register JSAMPROW ptr;
  149500. register JSAMPLE pixval;
  149501. register int count;
  149502. int row;
  149503. int numcols = (int) (output_cols - input_cols);
  149504. if (numcols > 0) {
  149505. for (row = 0; row < num_rows; row++) {
  149506. ptr = image_data[row] + input_cols;
  149507. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149508. for (count = numcols; count > 0; count--)
  149509. *ptr++ = pixval;
  149510. }
  149511. }
  149512. }
  149513. METHODDEF(void)
  149514. sep_downsample (j_compress_ptr cinfo,
  149515. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149516. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149517. {
  149518. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149519. int ci;
  149520. jpeg_component_info * compptr;
  149521. JSAMPARRAY in_ptr, out_ptr;
  149522. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149523. ci++, compptr++) {
  149524. in_ptr = input_buf[ci] + in_row_index;
  149525. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149526. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149527. }
  149528. }
  149529. METHODDEF(void)
  149530. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149531. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149532. {
  149533. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149534. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149535. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149536. JSAMPROW inptr, outptr;
  149537. INT32 outvalue;
  149538. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149539. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149540. numpix = h_expand * v_expand;
  149541. numpix2 = numpix/2;
  149542. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149543. cinfo->image_width, output_cols * h_expand);
  149544. inrow = 0;
  149545. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149546. outptr = output_data[outrow];
  149547. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149548. outcol++, outcol_h += h_expand) {
  149549. outvalue = 0;
  149550. for (v = 0; v < v_expand; v++) {
  149551. inptr = input_data[inrow+v] + outcol_h;
  149552. for (h = 0; h < h_expand; h++) {
  149553. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149554. }
  149555. }
  149556. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149557. }
  149558. inrow += v_expand;
  149559. }
  149560. }
  149561. METHODDEF(void)
  149562. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149563. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149564. {
  149565. jcopy_sample_rows(input_data, 0, output_data, 0,
  149566. cinfo->max_v_samp_factor, cinfo->image_width);
  149567. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149568. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149569. }
  149570. METHODDEF(void)
  149571. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149572. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149573. {
  149574. int outrow;
  149575. JDIMENSION outcol;
  149576. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149577. register JSAMPROW inptr, outptr;
  149578. register int bias;
  149579. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149580. cinfo->image_width, output_cols * 2);
  149581. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149582. outptr = output_data[outrow];
  149583. inptr = input_data[outrow];
  149584. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149585. for (outcol = 0; outcol < output_cols; outcol++) {
  149586. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149587. + bias) >> 1);
  149588. bias ^= 1; /* 0=>1, 1=>0 */
  149589. inptr += 2;
  149590. }
  149591. }
  149592. }
  149593. METHODDEF(void)
  149594. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149595. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149596. {
  149597. int inrow, outrow;
  149598. JDIMENSION outcol;
  149599. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149600. register JSAMPROW inptr0, inptr1, outptr;
  149601. register int bias;
  149602. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149603. cinfo->image_width, output_cols * 2);
  149604. inrow = 0;
  149605. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149606. outptr = output_data[outrow];
  149607. inptr0 = input_data[inrow];
  149608. inptr1 = input_data[inrow+1];
  149609. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149610. for (outcol = 0; outcol < output_cols; outcol++) {
  149611. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149612. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149613. + bias) >> 2);
  149614. bias ^= 3; /* 1=>2, 2=>1 */
  149615. inptr0 += 2; inptr1 += 2;
  149616. }
  149617. inrow += 2;
  149618. }
  149619. }
  149620. #ifdef INPUT_SMOOTHING_SUPPORTED
  149621. METHODDEF(void)
  149622. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149623. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149624. {
  149625. int inrow, outrow;
  149626. JDIMENSION colctr;
  149627. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149628. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149629. INT32 membersum, neighsum, memberscale, neighscale;
  149630. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149631. cinfo->image_width, output_cols * 2);
  149632. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149633. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149634. inrow = 0;
  149635. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149636. outptr = output_data[outrow];
  149637. inptr0 = input_data[inrow];
  149638. inptr1 = input_data[inrow+1];
  149639. above_ptr = input_data[inrow-1];
  149640. below_ptr = input_data[inrow+2];
  149641. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149642. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149643. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149644. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149645. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149646. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149647. neighsum += neighsum;
  149648. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149649. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149650. membersum = membersum * memberscale + neighsum * neighscale;
  149651. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149652. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149653. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149654. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149655. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149656. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149657. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149658. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149659. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149660. neighsum += neighsum;
  149661. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149662. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149663. membersum = membersum * memberscale + neighsum * neighscale;
  149664. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149665. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149666. }
  149667. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149668. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149669. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149670. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149671. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149672. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149673. neighsum += neighsum;
  149674. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149675. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149676. membersum = membersum * memberscale + neighsum * neighscale;
  149677. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149678. inrow += 2;
  149679. }
  149680. }
  149681. METHODDEF(void)
  149682. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149683. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149684. {
  149685. int outrow;
  149686. JDIMENSION colctr;
  149687. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149688. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149689. INT32 membersum, neighsum, memberscale, neighscale;
  149690. int colsum, lastcolsum, nextcolsum;
  149691. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149692. cinfo->image_width, output_cols);
  149693. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149694. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149695. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149696. outptr = output_data[outrow];
  149697. inptr = input_data[outrow];
  149698. above_ptr = input_data[outrow-1];
  149699. below_ptr = input_data[outrow+1];
  149700. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149701. GETJSAMPLE(*inptr);
  149702. membersum = GETJSAMPLE(*inptr++);
  149703. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149704. GETJSAMPLE(*inptr);
  149705. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149706. membersum = membersum * memberscale + neighsum * neighscale;
  149707. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149708. lastcolsum = colsum; colsum = nextcolsum;
  149709. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149710. membersum = GETJSAMPLE(*inptr++);
  149711. above_ptr++; below_ptr++;
  149712. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149713. GETJSAMPLE(*inptr);
  149714. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149715. membersum = membersum * memberscale + neighsum * neighscale;
  149716. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149717. lastcolsum = colsum; colsum = nextcolsum;
  149718. }
  149719. membersum = GETJSAMPLE(*inptr);
  149720. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149721. membersum = membersum * memberscale + neighsum * neighscale;
  149722. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149723. }
  149724. }
  149725. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149726. GLOBAL(void)
  149727. jinit_downsampler (j_compress_ptr cinfo)
  149728. {
  149729. my_downsample_ptr downsample;
  149730. int ci;
  149731. jpeg_component_info * compptr;
  149732. boolean smoothok = TRUE;
  149733. downsample = (my_downsample_ptr)
  149734. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149735. SIZEOF(my_downsampler));
  149736. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149737. downsample->pub.start_pass = start_pass_downsample;
  149738. downsample->pub.downsample = sep_downsample;
  149739. downsample->pub.need_context_rows = FALSE;
  149740. if (cinfo->CCIR601_sampling)
  149741. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149742. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149743. ci++, compptr++) {
  149744. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149745. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149746. #ifdef INPUT_SMOOTHING_SUPPORTED
  149747. if (cinfo->smoothing_factor) {
  149748. downsample->methods[ci] = fullsize_smooth_downsample;
  149749. downsample->pub.need_context_rows = TRUE;
  149750. } else
  149751. #endif
  149752. downsample->methods[ci] = fullsize_downsample;
  149753. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149754. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149755. smoothok = FALSE;
  149756. downsample->methods[ci] = h2v1_downsample;
  149757. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149758. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149759. #ifdef INPUT_SMOOTHING_SUPPORTED
  149760. if (cinfo->smoothing_factor) {
  149761. downsample->methods[ci] = h2v2_smooth_downsample;
  149762. downsample->pub.need_context_rows = TRUE;
  149763. } else
  149764. #endif
  149765. downsample->methods[ci] = h2v2_downsample;
  149766. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149767. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149768. smoothok = FALSE;
  149769. downsample->methods[ci] = int_downsample;
  149770. } else
  149771. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149772. }
  149773. #ifdef INPUT_SMOOTHING_SUPPORTED
  149774. if (cinfo->smoothing_factor && !smoothok)
  149775. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149776. #endif
  149777. }
  149778. /*** End of inlined file: jcsample.c ***/
  149779. /*** Start of inlined file: jctrans.c ***/
  149780. #define JPEG_INTERNALS
  149781. LOCAL(void) transencode_master_selection
  149782. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149783. LOCAL(void) transencode_coef_controller
  149784. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149785. GLOBAL(void)
  149786. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149787. {
  149788. if (cinfo->global_state != CSTATE_START)
  149789. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149790. jpeg_suppress_tables(cinfo, FALSE);
  149791. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149792. (*cinfo->dest->init_destination) (cinfo);
  149793. transencode_master_selection(cinfo, coef_arrays);
  149794. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149795. cinfo->global_state = CSTATE_WRCOEFS;
  149796. }
  149797. GLOBAL(void)
  149798. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149799. j_compress_ptr dstinfo)
  149800. {
  149801. JQUANT_TBL ** qtblptr;
  149802. jpeg_component_info *incomp, *outcomp;
  149803. JQUANT_TBL *c_quant, *slot_quant;
  149804. int tblno, ci, coefi;
  149805. if (dstinfo->global_state != CSTATE_START)
  149806. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149807. dstinfo->image_width = srcinfo->image_width;
  149808. dstinfo->image_height = srcinfo->image_height;
  149809. dstinfo->input_components = srcinfo->num_components;
  149810. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149811. jpeg_set_defaults(dstinfo);
  149812. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149813. dstinfo->data_precision = srcinfo->data_precision;
  149814. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149815. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149816. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149817. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149818. if (*qtblptr == NULL)
  149819. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149820. MEMCOPY((*qtblptr)->quantval,
  149821. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149822. SIZEOF((*qtblptr)->quantval));
  149823. (*qtblptr)->sent_table = FALSE;
  149824. }
  149825. }
  149826. dstinfo->num_components = srcinfo->num_components;
  149827. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149828. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149829. MAX_COMPONENTS);
  149830. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149831. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149832. outcomp->component_id = incomp->component_id;
  149833. outcomp->h_samp_factor = incomp->h_samp_factor;
  149834. outcomp->v_samp_factor = incomp->v_samp_factor;
  149835. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149836. tblno = outcomp->quant_tbl_no;
  149837. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149838. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149839. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149840. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149841. c_quant = incomp->quant_table;
  149842. if (c_quant != NULL) {
  149843. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149844. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149845. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149846. }
  149847. }
  149848. }
  149849. if (srcinfo->saw_JFIF_marker) {
  149850. if (srcinfo->JFIF_major_version == 1) {
  149851. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149852. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149853. }
  149854. dstinfo->density_unit = srcinfo->density_unit;
  149855. dstinfo->X_density = srcinfo->X_density;
  149856. dstinfo->Y_density = srcinfo->Y_density;
  149857. }
  149858. }
  149859. LOCAL(void)
  149860. transencode_master_selection (j_compress_ptr cinfo,
  149861. jvirt_barray_ptr * coef_arrays)
  149862. {
  149863. cinfo->input_components = 1;
  149864. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149865. if (cinfo->arith_code) {
  149866. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149867. } else {
  149868. if (cinfo->progressive_mode) {
  149869. #ifdef C_PROGRESSIVE_SUPPORTED
  149870. jinit_phuff_encoder(cinfo);
  149871. #else
  149872. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149873. #endif
  149874. } else
  149875. jinit_huff_encoder(cinfo);
  149876. }
  149877. transencode_coef_controller(cinfo, coef_arrays);
  149878. jinit_marker_writer(cinfo);
  149879. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149880. (*cinfo->marker->write_file_header) (cinfo);
  149881. }
  149882. typedef struct {
  149883. struct jpeg_c_coef_controller pub; /* public fields */
  149884. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149885. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149886. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149887. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149888. jvirt_barray_ptr * whole_image;
  149889. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149890. } my_coef_controller2;
  149891. typedef my_coef_controller2 * my_coef_ptr2;
  149892. LOCAL(void)
  149893. start_iMCU_row2 (j_compress_ptr cinfo)
  149894. {
  149895. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149896. if (cinfo->comps_in_scan > 1) {
  149897. coef->MCU_rows_per_iMCU_row = 1;
  149898. } else {
  149899. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149900. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149901. else
  149902. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149903. }
  149904. coef->mcu_ctr = 0;
  149905. coef->MCU_vert_offset = 0;
  149906. }
  149907. METHODDEF(void)
  149908. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149909. {
  149910. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149911. if (pass_mode != JBUF_CRANK_DEST)
  149912. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149913. coef->iMCU_row_num = 0;
  149914. start_iMCU_row2(cinfo);
  149915. }
  149916. METHODDEF(boolean)
  149917. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  149918. {
  149919. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149920. JDIMENSION MCU_col_num; /* index of current MCU within row */
  149921. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  149922. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  149923. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  149924. JDIMENSION start_col;
  149925. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  149926. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  149927. JBLOCKROW buffer_ptr;
  149928. jpeg_component_info *compptr;
  149929. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149930. compptr = cinfo->cur_comp_info[ci];
  149931. buffer[ci] = (*cinfo->mem->access_virt_barray)
  149932. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  149933. coef->iMCU_row_num * compptr->v_samp_factor,
  149934. (JDIMENSION) compptr->v_samp_factor, FALSE);
  149935. }
  149936. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  149937. yoffset++) {
  149938. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  149939. MCU_col_num++) {
  149940. blkn = 0; /* index of current DCT block within MCU */
  149941. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149942. compptr = cinfo->cur_comp_info[ci];
  149943. start_col = MCU_col_num * compptr->MCU_width;
  149944. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  149945. : compptr->last_col_width;
  149946. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  149947. if (coef->iMCU_row_num < last_iMCU_row ||
  149948. yindex+yoffset < compptr->last_row_height) {
  149949. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  149950. for (xindex = 0; xindex < blockcnt; xindex++)
  149951. MCU_buffer[blkn++] = buffer_ptr++;
  149952. } else {
  149953. xindex = 0;
  149954. }
  149955. for (; xindex < compptr->MCU_width; xindex++) {
  149956. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  149957. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  149958. blkn++;
  149959. }
  149960. }
  149961. }
  149962. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  149963. coef->MCU_vert_offset = yoffset;
  149964. coef->mcu_ctr = MCU_col_num;
  149965. return FALSE;
  149966. }
  149967. }
  149968. coef->mcu_ctr = 0;
  149969. }
  149970. coef->iMCU_row_num++;
  149971. start_iMCU_row2(cinfo);
  149972. return TRUE;
  149973. }
  149974. LOCAL(void)
  149975. transencode_coef_controller (j_compress_ptr cinfo,
  149976. jvirt_barray_ptr * coef_arrays)
  149977. {
  149978. my_coef_ptr2 coef;
  149979. JBLOCKROW buffer;
  149980. int i;
  149981. coef = (my_coef_ptr2)
  149982. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149983. SIZEOF(my_coef_controller2));
  149984. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  149985. coef->pub.start_pass = start_pass_coef2;
  149986. coef->pub.compress_data = compress_output2;
  149987. coef->whole_image = coef_arrays;
  149988. buffer = (JBLOCKROW)
  149989. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149990. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149991. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149992. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  149993. coef->dummy_buffer[i] = buffer + i;
  149994. }
  149995. }
  149996. /*** End of inlined file: jctrans.c ***/
  149997. /*** Start of inlined file: jdapistd.c ***/
  149998. #define JPEG_INTERNALS
  149999. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150000. GLOBAL(boolean)
  150001. jpeg_start_decompress (j_decompress_ptr cinfo)
  150002. {
  150003. if (cinfo->global_state == DSTATE_READY) {
  150004. jinit_master_decompress(cinfo);
  150005. if (cinfo->buffered_image) {
  150006. cinfo->global_state = DSTATE_BUFIMAGE;
  150007. return TRUE;
  150008. }
  150009. cinfo->global_state = DSTATE_PRELOAD;
  150010. }
  150011. if (cinfo->global_state == DSTATE_PRELOAD) {
  150012. if (cinfo->inputctl->has_multiple_scans) {
  150013. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150014. for (;;) {
  150015. int retcode;
  150016. if (cinfo->progress != NULL)
  150017. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150018. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150019. if (retcode == JPEG_SUSPENDED)
  150020. return FALSE;
  150021. if (retcode == JPEG_REACHED_EOI)
  150022. break;
  150023. if (cinfo->progress != NULL &&
  150024. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150025. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150026. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150027. }
  150028. }
  150029. }
  150030. #else
  150031. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150032. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150033. }
  150034. cinfo->output_scan_number = cinfo->input_scan_number;
  150035. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150036. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150037. return output_pass_setup(cinfo);
  150038. }
  150039. LOCAL(boolean)
  150040. output_pass_setup (j_decompress_ptr cinfo)
  150041. {
  150042. if (cinfo->global_state != DSTATE_PRESCAN) {
  150043. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150044. cinfo->output_scanline = 0;
  150045. cinfo->global_state = DSTATE_PRESCAN;
  150046. }
  150047. while (cinfo->master->is_dummy_pass) {
  150048. #ifdef QUANT_2PASS_SUPPORTED
  150049. while (cinfo->output_scanline < cinfo->output_height) {
  150050. JDIMENSION last_scanline;
  150051. if (cinfo->progress != NULL) {
  150052. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150053. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150054. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150055. }
  150056. last_scanline = cinfo->output_scanline;
  150057. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150058. &cinfo->output_scanline, (JDIMENSION) 0);
  150059. if (cinfo->output_scanline == last_scanline)
  150060. return FALSE; /* No progress made, must suspend */
  150061. }
  150062. (*cinfo->master->finish_output_pass) (cinfo);
  150063. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150064. cinfo->output_scanline = 0;
  150065. #else
  150066. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150067. #endif /* QUANT_2PASS_SUPPORTED */
  150068. }
  150069. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150070. return TRUE;
  150071. }
  150072. GLOBAL(JDIMENSION)
  150073. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150074. JDIMENSION max_lines)
  150075. {
  150076. JDIMENSION row_ctr;
  150077. if (cinfo->global_state != DSTATE_SCANNING)
  150078. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150079. if (cinfo->output_scanline >= cinfo->output_height) {
  150080. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150081. return 0;
  150082. }
  150083. if (cinfo->progress != NULL) {
  150084. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150085. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150086. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150087. }
  150088. row_ctr = 0;
  150089. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150090. cinfo->output_scanline += row_ctr;
  150091. return row_ctr;
  150092. }
  150093. GLOBAL(JDIMENSION)
  150094. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150095. JDIMENSION max_lines)
  150096. {
  150097. JDIMENSION lines_per_iMCU_row;
  150098. if (cinfo->global_state != DSTATE_RAW_OK)
  150099. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150100. if (cinfo->output_scanline >= cinfo->output_height) {
  150101. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150102. return 0;
  150103. }
  150104. if (cinfo->progress != NULL) {
  150105. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150106. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150107. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150108. }
  150109. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150110. if (max_lines < lines_per_iMCU_row)
  150111. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150112. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150113. return 0; /* suspension forced, can do nothing more */
  150114. cinfo->output_scanline += lines_per_iMCU_row;
  150115. return lines_per_iMCU_row;
  150116. }
  150117. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150118. GLOBAL(boolean)
  150119. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150120. {
  150121. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150122. cinfo->global_state != DSTATE_PRESCAN)
  150123. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150124. if (scan_number <= 0)
  150125. scan_number = 1;
  150126. if (cinfo->inputctl->eoi_reached &&
  150127. scan_number > cinfo->input_scan_number)
  150128. scan_number = cinfo->input_scan_number;
  150129. cinfo->output_scan_number = scan_number;
  150130. return output_pass_setup(cinfo);
  150131. }
  150132. GLOBAL(boolean)
  150133. jpeg_finish_output (j_decompress_ptr cinfo)
  150134. {
  150135. if ((cinfo->global_state == DSTATE_SCANNING ||
  150136. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150137. (*cinfo->master->finish_output_pass) (cinfo);
  150138. cinfo->global_state = DSTATE_BUFPOST;
  150139. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150140. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150141. }
  150142. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150143. ! cinfo->inputctl->eoi_reached) {
  150144. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150145. return FALSE; /* Suspend, come back later */
  150146. }
  150147. cinfo->global_state = DSTATE_BUFIMAGE;
  150148. return TRUE;
  150149. }
  150150. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150151. /*** End of inlined file: jdapistd.c ***/
  150152. /*** Start of inlined file: jdapimin.c ***/
  150153. #define JPEG_INTERNALS
  150154. GLOBAL(void)
  150155. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150156. {
  150157. int i;
  150158. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150159. if (version != JPEG_LIB_VERSION)
  150160. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150161. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150162. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150163. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150164. {
  150165. struct jpeg_error_mgr * err = cinfo->err;
  150166. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150167. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150168. cinfo->err = err;
  150169. cinfo->client_data = client_data;
  150170. }
  150171. cinfo->is_decompressor = TRUE;
  150172. jinit_memory_mgr((j_common_ptr) cinfo);
  150173. cinfo->progress = NULL;
  150174. cinfo->src = NULL;
  150175. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150176. cinfo->quant_tbl_ptrs[i] = NULL;
  150177. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150178. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150179. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150180. }
  150181. cinfo->marker_list = NULL;
  150182. jinit_marker_reader(cinfo);
  150183. jinit_input_controller(cinfo);
  150184. cinfo->global_state = DSTATE_START;
  150185. }
  150186. GLOBAL(void)
  150187. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150188. {
  150189. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150190. }
  150191. GLOBAL(void)
  150192. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150193. {
  150194. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150195. }
  150196. LOCAL(void)
  150197. default_decompress_parms (j_decompress_ptr cinfo)
  150198. {
  150199. switch (cinfo->num_components) {
  150200. case 1:
  150201. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150202. cinfo->out_color_space = JCS_GRAYSCALE;
  150203. break;
  150204. case 3:
  150205. if (cinfo->saw_JFIF_marker) {
  150206. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150207. } else if (cinfo->saw_Adobe_marker) {
  150208. switch (cinfo->Adobe_transform) {
  150209. case 0:
  150210. cinfo->jpeg_color_space = JCS_RGB;
  150211. break;
  150212. case 1:
  150213. cinfo->jpeg_color_space = JCS_YCbCr;
  150214. break;
  150215. default:
  150216. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150217. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150218. break;
  150219. }
  150220. } else {
  150221. int cid0 = cinfo->comp_info[0].component_id;
  150222. int cid1 = cinfo->comp_info[1].component_id;
  150223. int cid2 = cinfo->comp_info[2].component_id;
  150224. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150225. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150226. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150227. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150228. else {
  150229. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150230. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150231. }
  150232. }
  150233. cinfo->out_color_space = JCS_RGB;
  150234. break;
  150235. case 4:
  150236. if (cinfo->saw_Adobe_marker) {
  150237. switch (cinfo->Adobe_transform) {
  150238. case 0:
  150239. cinfo->jpeg_color_space = JCS_CMYK;
  150240. break;
  150241. case 2:
  150242. cinfo->jpeg_color_space = JCS_YCCK;
  150243. break;
  150244. default:
  150245. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150246. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150247. break;
  150248. }
  150249. } else {
  150250. cinfo->jpeg_color_space = JCS_CMYK;
  150251. }
  150252. cinfo->out_color_space = JCS_CMYK;
  150253. break;
  150254. default:
  150255. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150256. cinfo->out_color_space = JCS_UNKNOWN;
  150257. break;
  150258. }
  150259. cinfo->scale_num = 1; /* 1:1 scaling */
  150260. cinfo->scale_denom = 1;
  150261. cinfo->output_gamma = 1.0;
  150262. cinfo->buffered_image = FALSE;
  150263. cinfo->raw_data_out = FALSE;
  150264. cinfo->dct_method = JDCT_DEFAULT;
  150265. cinfo->do_fancy_upsampling = TRUE;
  150266. cinfo->do_block_smoothing = TRUE;
  150267. cinfo->quantize_colors = FALSE;
  150268. cinfo->dither_mode = JDITHER_FS;
  150269. #ifdef QUANT_2PASS_SUPPORTED
  150270. cinfo->two_pass_quantize = TRUE;
  150271. #else
  150272. cinfo->two_pass_quantize = FALSE;
  150273. #endif
  150274. cinfo->desired_number_of_colors = 256;
  150275. cinfo->colormap = NULL;
  150276. cinfo->enable_1pass_quant = FALSE;
  150277. cinfo->enable_external_quant = FALSE;
  150278. cinfo->enable_2pass_quant = FALSE;
  150279. }
  150280. GLOBAL(int)
  150281. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150282. {
  150283. int retcode;
  150284. if (cinfo->global_state != DSTATE_START &&
  150285. cinfo->global_state != DSTATE_INHEADER)
  150286. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150287. retcode = jpeg_consume_input(cinfo);
  150288. switch (retcode) {
  150289. case JPEG_REACHED_SOS:
  150290. retcode = JPEG_HEADER_OK;
  150291. break;
  150292. case JPEG_REACHED_EOI:
  150293. if (require_image) /* Complain if application wanted an image */
  150294. ERREXIT(cinfo, JERR_NO_IMAGE);
  150295. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150296. retcode = JPEG_HEADER_TABLES_ONLY;
  150297. break;
  150298. case JPEG_SUSPENDED:
  150299. break;
  150300. }
  150301. return retcode;
  150302. }
  150303. GLOBAL(int)
  150304. jpeg_consume_input (j_decompress_ptr cinfo)
  150305. {
  150306. int retcode = JPEG_SUSPENDED;
  150307. switch (cinfo->global_state) {
  150308. case DSTATE_START:
  150309. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150310. (*cinfo->src->init_source) (cinfo);
  150311. cinfo->global_state = DSTATE_INHEADER;
  150312. case DSTATE_INHEADER:
  150313. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150314. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150315. default_decompress_parms(cinfo);
  150316. cinfo->global_state = DSTATE_READY;
  150317. }
  150318. break;
  150319. case DSTATE_READY:
  150320. retcode = JPEG_REACHED_SOS;
  150321. break;
  150322. case DSTATE_PRELOAD:
  150323. case DSTATE_PRESCAN:
  150324. case DSTATE_SCANNING:
  150325. case DSTATE_RAW_OK:
  150326. case DSTATE_BUFIMAGE:
  150327. case DSTATE_BUFPOST:
  150328. case DSTATE_STOPPING:
  150329. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150330. break;
  150331. default:
  150332. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150333. }
  150334. return retcode;
  150335. }
  150336. GLOBAL(boolean)
  150337. jpeg_input_complete (j_decompress_ptr cinfo)
  150338. {
  150339. if (cinfo->global_state < DSTATE_START ||
  150340. cinfo->global_state > DSTATE_STOPPING)
  150341. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150342. return cinfo->inputctl->eoi_reached;
  150343. }
  150344. GLOBAL(boolean)
  150345. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150346. {
  150347. if (cinfo->global_state < DSTATE_READY ||
  150348. cinfo->global_state > DSTATE_STOPPING)
  150349. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150350. return cinfo->inputctl->has_multiple_scans;
  150351. }
  150352. GLOBAL(boolean)
  150353. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150354. {
  150355. if ((cinfo->global_state == DSTATE_SCANNING ||
  150356. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150357. if (cinfo->output_scanline < cinfo->output_height)
  150358. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150359. (*cinfo->master->finish_output_pass) (cinfo);
  150360. cinfo->global_state = DSTATE_STOPPING;
  150361. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150362. cinfo->global_state = DSTATE_STOPPING;
  150363. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150364. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150365. }
  150366. while (! cinfo->inputctl->eoi_reached) {
  150367. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150368. return FALSE; /* Suspend, come back later */
  150369. }
  150370. (*cinfo->src->term_source) (cinfo);
  150371. jpeg_abort((j_common_ptr) cinfo);
  150372. return TRUE;
  150373. }
  150374. /*** End of inlined file: jdapimin.c ***/
  150375. /*** Start of inlined file: jdatasrc.c ***/
  150376. /*** Start of inlined file: jerror.h ***/
  150377. #ifndef JMESSAGE
  150378. #ifndef JERROR_H
  150379. #define JMAKE_ENUM_LIST
  150380. #else
  150381. #define JMESSAGE(code,string)
  150382. #endif /* JERROR_H */
  150383. #endif /* JMESSAGE */
  150384. #ifdef JMAKE_ENUM_LIST
  150385. typedef enum {
  150386. #define JMESSAGE(code,string) code ,
  150387. #endif /* JMAKE_ENUM_LIST */
  150388. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150389. JMESSAGE(JERR_ARITH_NOTIMPL,
  150390. "Sorry, there are legal restrictions on arithmetic coding")
  150391. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150392. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150393. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150394. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150395. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150396. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150397. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150398. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150399. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150400. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150401. JMESSAGE(JERR_BAD_LIB_VERSION,
  150402. "Wrong JPEG library version: library is %d, caller expects %d")
  150403. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150404. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150405. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150406. JMESSAGE(JERR_BAD_PROGRESSION,
  150407. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150408. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150409. "Invalid progressive parameters at scan script entry %d")
  150410. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150411. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150412. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150413. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150414. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150415. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150416. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150417. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150418. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150419. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150420. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150421. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150422. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150423. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150424. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150425. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150426. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150427. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150428. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150429. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150430. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150431. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150432. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150433. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150434. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150435. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150436. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150437. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150438. "Cannot transcode due to multiple use of quantization table %d")
  150439. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150440. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150441. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150442. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150443. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150444. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150445. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150446. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150447. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150448. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150449. JMESSAGE(JERR_QUANT_COMPONENTS,
  150450. "Cannot quantize more than %d color components")
  150451. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150452. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150453. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150454. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150455. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150456. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150457. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150458. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150459. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150460. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150461. JMESSAGE(JERR_TFILE_WRITE,
  150462. "Write failed on temporary file --- out of disk space?")
  150463. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150464. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150465. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150466. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150467. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150468. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150469. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150470. JMESSAGE(JMSG_VERSION, JVERSION)
  150471. JMESSAGE(JTRC_16BIT_TABLES,
  150472. "Caution: quantization tables are too coarse for baseline JPEG")
  150473. JMESSAGE(JTRC_ADOBE,
  150474. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150475. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150476. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150477. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150478. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150479. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150480. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150481. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150482. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150483. JMESSAGE(JTRC_EOI, "End Of Image")
  150484. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150485. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150486. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150487. "Warning: thumbnail image size does not match data length %u")
  150488. JMESSAGE(JTRC_JFIF_EXTENSION,
  150489. "JFIF extension marker: type 0x%02x, length %u")
  150490. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150491. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150492. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150493. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150494. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150495. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150496. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150497. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150498. JMESSAGE(JTRC_RST, "RST%d")
  150499. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150500. "Smoothing not supported with nonstandard sampling ratios")
  150501. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150502. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150503. JMESSAGE(JTRC_SOI, "Start of Image")
  150504. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150505. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150506. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150507. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150508. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150509. JMESSAGE(JTRC_THUMB_JPEG,
  150510. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150511. JMESSAGE(JTRC_THUMB_PALETTE,
  150512. "JFIF extension marker: palette thumbnail image, length %u")
  150513. JMESSAGE(JTRC_THUMB_RGB,
  150514. "JFIF extension marker: RGB thumbnail image, length %u")
  150515. JMESSAGE(JTRC_UNKNOWN_IDS,
  150516. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150517. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150518. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150519. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150520. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150521. "Inconsistent progression sequence for component %d coefficient %d")
  150522. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150523. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150524. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150525. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150526. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150527. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150528. JMESSAGE(JWRN_MUST_RESYNC,
  150529. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150530. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150531. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150532. #ifdef JMAKE_ENUM_LIST
  150533. JMSG_LASTMSGCODE
  150534. } J_MESSAGE_CODE;
  150535. #undef JMAKE_ENUM_LIST
  150536. #endif /* JMAKE_ENUM_LIST */
  150537. #undef JMESSAGE
  150538. #ifndef JERROR_H
  150539. #define JERROR_H
  150540. #define ERREXIT(cinfo,code) \
  150541. ((cinfo)->err->msg_code = (code), \
  150542. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150543. #define ERREXIT1(cinfo,code,p1) \
  150544. ((cinfo)->err->msg_code = (code), \
  150545. (cinfo)->err->msg_parm.i[0] = (p1), \
  150546. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150547. #define ERREXIT2(cinfo,code,p1,p2) \
  150548. ((cinfo)->err->msg_code = (code), \
  150549. (cinfo)->err->msg_parm.i[0] = (p1), \
  150550. (cinfo)->err->msg_parm.i[1] = (p2), \
  150551. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150552. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150553. ((cinfo)->err->msg_code = (code), \
  150554. (cinfo)->err->msg_parm.i[0] = (p1), \
  150555. (cinfo)->err->msg_parm.i[1] = (p2), \
  150556. (cinfo)->err->msg_parm.i[2] = (p3), \
  150557. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150558. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150559. ((cinfo)->err->msg_code = (code), \
  150560. (cinfo)->err->msg_parm.i[0] = (p1), \
  150561. (cinfo)->err->msg_parm.i[1] = (p2), \
  150562. (cinfo)->err->msg_parm.i[2] = (p3), \
  150563. (cinfo)->err->msg_parm.i[3] = (p4), \
  150564. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150565. #define ERREXITS(cinfo,code,str) \
  150566. ((cinfo)->err->msg_code = (code), \
  150567. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150568. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150569. #define MAKESTMT(stuff) do { stuff } while (0)
  150570. #define WARNMS(cinfo,code) \
  150571. ((cinfo)->err->msg_code = (code), \
  150572. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150573. #define WARNMS1(cinfo,code,p1) \
  150574. ((cinfo)->err->msg_code = (code), \
  150575. (cinfo)->err->msg_parm.i[0] = (p1), \
  150576. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150577. #define WARNMS2(cinfo,code,p1,p2) \
  150578. ((cinfo)->err->msg_code = (code), \
  150579. (cinfo)->err->msg_parm.i[0] = (p1), \
  150580. (cinfo)->err->msg_parm.i[1] = (p2), \
  150581. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150582. #define TRACEMS(cinfo,lvl,code) \
  150583. ((cinfo)->err->msg_code = (code), \
  150584. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150585. #define TRACEMS1(cinfo,lvl,code,p1) \
  150586. ((cinfo)->err->msg_code = (code), \
  150587. (cinfo)->err->msg_parm.i[0] = (p1), \
  150588. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150589. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150590. ((cinfo)->err->msg_code = (code), \
  150591. (cinfo)->err->msg_parm.i[0] = (p1), \
  150592. (cinfo)->err->msg_parm.i[1] = (p2), \
  150593. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150594. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150595. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150596. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150597. (cinfo)->err->msg_code = (code); \
  150598. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150599. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150600. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150601. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150602. (cinfo)->err->msg_code = (code); \
  150603. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150604. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150605. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150606. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150607. _mp[4] = (p5); \
  150608. (cinfo)->err->msg_code = (code); \
  150609. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150610. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150611. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150612. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150613. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150614. (cinfo)->err->msg_code = (code); \
  150615. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150616. #define TRACEMSS(cinfo,lvl,code,str) \
  150617. ((cinfo)->err->msg_code = (code), \
  150618. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150619. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150620. #endif /* JERROR_H */
  150621. /*** End of inlined file: jerror.h ***/
  150622. typedef struct {
  150623. struct jpeg_source_mgr pub; /* public fields */
  150624. FILE * infile; /* source stream */
  150625. JOCTET * buffer; /* start of buffer */
  150626. boolean start_of_file; /* have we gotten any data yet? */
  150627. } my_source_mgr;
  150628. typedef my_source_mgr * my_src_ptr;
  150629. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150630. METHODDEF(void)
  150631. init_source (j_decompress_ptr cinfo)
  150632. {
  150633. my_src_ptr src = (my_src_ptr) cinfo->src;
  150634. src->start_of_file = TRUE;
  150635. }
  150636. METHODDEF(boolean)
  150637. fill_input_buffer (j_decompress_ptr cinfo)
  150638. {
  150639. my_src_ptr src = (my_src_ptr) cinfo->src;
  150640. size_t nbytes;
  150641. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150642. if (nbytes <= 0) {
  150643. if (src->start_of_file) /* Treat empty input file as fatal error */
  150644. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150645. WARNMS(cinfo, JWRN_JPEG_EOF);
  150646. src->buffer[0] = (JOCTET) 0xFF;
  150647. src->buffer[1] = (JOCTET) JPEG_EOI;
  150648. nbytes = 2;
  150649. }
  150650. src->pub.next_input_byte = src->buffer;
  150651. src->pub.bytes_in_buffer = nbytes;
  150652. src->start_of_file = FALSE;
  150653. return TRUE;
  150654. }
  150655. METHODDEF(void)
  150656. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150657. {
  150658. my_src_ptr src = (my_src_ptr) cinfo->src;
  150659. if (num_bytes > 0) {
  150660. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150661. num_bytes -= (long) src->pub.bytes_in_buffer;
  150662. (void) fill_input_buffer(cinfo);
  150663. }
  150664. src->pub.next_input_byte += (size_t) num_bytes;
  150665. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150666. }
  150667. }
  150668. METHODDEF(void)
  150669. term_source (j_decompress_ptr cinfo)
  150670. {
  150671. }
  150672. GLOBAL(void)
  150673. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150674. {
  150675. my_src_ptr src;
  150676. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150677. cinfo->src = (struct jpeg_source_mgr *)
  150678. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150679. SIZEOF(my_source_mgr));
  150680. src = (my_src_ptr) cinfo->src;
  150681. src->buffer = (JOCTET *)
  150682. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150683. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150684. }
  150685. src = (my_src_ptr) cinfo->src;
  150686. src->pub.init_source = init_source;
  150687. src->pub.fill_input_buffer = fill_input_buffer;
  150688. src->pub.skip_input_data = skip_input_data;
  150689. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150690. src->pub.term_source = term_source;
  150691. src->infile = infile;
  150692. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150693. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150694. }
  150695. /*** End of inlined file: jdatasrc.c ***/
  150696. /*** Start of inlined file: jdcoefct.c ***/
  150697. #define JPEG_INTERNALS
  150698. #ifndef D_PROGRESSIVE_SUPPORTED
  150699. #undef BLOCK_SMOOTHING_SUPPORTED
  150700. #endif
  150701. typedef struct {
  150702. struct jpeg_d_coef_controller pub; /* public fields */
  150703. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150704. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150705. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150706. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150707. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150708. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150709. #endif
  150710. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150711. int * coef_bits_latch;
  150712. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150713. #endif
  150714. } my_coef_controller3;
  150715. typedef my_coef_controller3 * my_coef_ptr3;
  150716. METHODDEF(int) decompress_onepass
  150717. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150718. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150719. METHODDEF(int) decompress_data
  150720. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150721. #endif
  150722. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150723. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150724. METHODDEF(int) decompress_smooth_data
  150725. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150726. #endif
  150727. LOCAL(void)
  150728. start_iMCU_row3 (j_decompress_ptr cinfo)
  150729. {
  150730. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150731. if (cinfo->comps_in_scan > 1) {
  150732. coef->MCU_rows_per_iMCU_row = 1;
  150733. } else {
  150734. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150735. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150736. else
  150737. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150738. }
  150739. coef->MCU_ctr = 0;
  150740. coef->MCU_vert_offset = 0;
  150741. }
  150742. METHODDEF(void)
  150743. start_input_pass (j_decompress_ptr cinfo)
  150744. {
  150745. cinfo->input_iMCU_row = 0;
  150746. start_iMCU_row3(cinfo);
  150747. }
  150748. METHODDEF(void)
  150749. start_output_pass (j_decompress_ptr cinfo)
  150750. {
  150751. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150752. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150753. if (coef->pub.coef_arrays != NULL) {
  150754. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150755. coef->pub.decompress_data = decompress_smooth_data;
  150756. else
  150757. coef->pub.decompress_data = decompress_data;
  150758. }
  150759. #endif
  150760. cinfo->output_iMCU_row = 0;
  150761. }
  150762. METHODDEF(int)
  150763. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150764. {
  150765. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150766. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150767. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150768. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150769. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150770. JSAMPARRAY output_ptr;
  150771. JDIMENSION start_col, output_col;
  150772. jpeg_component_info *compptr;
  150773. inverse_DCT_method_ptr inverse_DCT;
  150774. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150775. yoffset++) {
  150776. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150777. MCU_col_num++) {
  150778. jzero_far((void FAR *) coef->MCU_buffer[0],
  150779. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150780. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150781. coef->MCU_vert_offset = yoffset;
  150782. coef->MCU_ctr = MCU_col_num;
  150783. return JPEG_SUSPENDED;
  150784. }
  150785. blkn = 0; /* index of current DCT block within MCU */
  150786. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150787. compptr = cinfo->cur_comp_info[ci];
  150788. if (! compptr->component_needed) {
  150789. blkn += compptr->MCU_blocks;
  150790. continue;
  150791. }
  150792. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150793. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150794. : compptr->last_col_width;
  150795. output_ptr = output_buf[compptr->component_index] +
  150796. yoffset * compptr->DCT_scaled_size;
  150797. start_col = MCU_col_num * compptr->MCU_sample_width;
  150798. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150799. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150800. yoffset+yindex < compptr->last_row_height) {
  150801. output_col = start_col;
  150802. for (xindex = 0; xindex < useful_width; xindex++) {
  150803. (*inverse_DCT) (cinfo, compptr,
  150804. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150805. output_ptr, output_col);
  150806. output_col += compptr->DCT_scaled_size;
  150807. }
  150808. }
  150809. blkn += compptr->MCU_width;
  150810. output_ptr += compptr->DCT_scaled_size;
  150811. }
  150812. }
  150813. }
  150814. coef->MCU_ctr = 0;
  150815. }
  150816. cinfo->output_iMCU_row++;
  150817. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150818. start_iMCU_row3(cinfo);
  150819. return JPEG_ROW_COMPLETED;
  150820. }
  150821. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150822. return JPEG_SCAN_COMPLETED;
  150823. }
  150824. METHODDEF(int)
  150825. dummy_consume_data (j_decompress_ptr cinfo)
  150826. {
  150827. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150828. }
  150829. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150830. METHODDEF(int)
  150831. consume_data (j_decompress_ptr cinfo)
  150832. {
  150833. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150834. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150835. int blkn, ci, xindex, yindex, yoffset;
  150836. JDIMENSION start_col;
  150837. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150838. JBLOCKROW buffer_ptr;
  150839. jpeg_component_info *compptr;
  150840. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150841. compptr = cinfo->cur_comp_info[ci];
  150842. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150843. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150844. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150845. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150846. }
  150847. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150848. yoffset++) {
  150849. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150850. MCU_col_num++) {
  150851. blkn = 0; /* index of current DCT block within MCU */
  150852. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150853. compptr = cinfo->cur_comp_info[ci];
  150854. start_col = MCU_col_num * compptr->MCU_width;
  150855. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150856. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150857. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150858. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150859. }
  150860. }
  150861. }
  150862. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150863. coef->MCU_vert_offset = yoffset;
  150864. coef->MCU_ctr = MCU_col_num;
  150865. return JPEG_SUSPENDED;
  150866. }
  150867. }
  150868. coef->MCU_ctr = 0;
  150869. }
  150870. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150871. start_iMCU_row3(cinfo);
  150872. return JPEG_ROW_COMPLETED;
  150873. }
  150874. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150875. return JPEG_SCAN_COMPLETED;
  150876. }
  150877. METHODDEF(int)
  150878. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150879. {
  150880. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150881. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150882. JDIMENSION block_num;
  150883. int ci, block_row, block_rows;
  150884. JBLOCKARRAY buffer;
  150885. JBLOCKROW buffer_ptr;
  150886. JSAMPARRAY output_ptr;
  150887. JDIMENSION output_col;
  150888. jpeg_component_info *compptr;
  150889. inverse_DCT_method_ptr inverse_DCT;
  150890. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150891. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150892. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150893. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150894. return JPEG_SUSPENDED;
  150895. }
  150896. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150897. ci++, compptr++) {
  150898. if (! compptr->component_needed)
  150899. continue;
  150900. buffer = (*cinfo->mem->access_virt_barray)
  150901. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150902. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150903. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150904. if (cinfo->output_iMCU_row < last_iMCU_row)
  150905. block_rows = compptr->v_samp_factor;
  150906. else {
  150907. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150908. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150909. }
  150910. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150911. output_ptr = output_buf[ci];
  150912. for (block_row = 0; block_row < block_rows; block_row++) {
  150913. buffer_ptr = buffer[block_row];
  150914. output_col = 0;
  150915. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150916. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  150917. output_ptr, output_col);
  150918. buffer_ptr++;
  150919. output_col += compptr->DCT_scaled_size;
  150920. }
  150921. output_ptr += compptr->DCT_scaled_size;
  150922. }
  150923. }
  150924. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  150925. return JPEG_ROW_COMPLETED;
  150926. return JPEG_SCAN_COMPLETED;
  150927. }
  150928. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150929. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150930. #define Q01_POS 1
  150931. #define Q10_POS 8
  150932. #define Q20_POS 16
  150933. #define Q11_POS 9
  150934. #define Q02_POS 2
  150935. LOCAL(boolean)
  150936. smoothing_ok (j_decompress_ptr cinfo)
  150937. {
  150938. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150939. boolean smoothing_useful = FALSE;
  150940. int ci, coefi;
  150941. jpeg_component_info *compptr;
  150942. JQUANT_TBL * qtable;
  150943. int * coef_bits;
  150944. int * coef_bits_latch;
  150945. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  150946. return FALSE;
  150947. if (coef->coef_bits_latch == NULL)
  150948. coef->coef_bits_latch = (int *)
  150949. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150950. cinfo->num_components *
  150951. (SAVED_COEFS * SIZEOF(int)));
  150952. coef_bits_latch = coef->coef_bits_latch;
  150953. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150954. ci++, compptr++) {
  150955. if ((qtable = compptr->quant_table) == NULL)
  150956. return FALSE;
  150957. if (qtable->quantval[0] == 0 ||
  150958. qtable->quantval[Q01_POS] == 0 ||
  150959. qtable->quantval[Q10_POS] == 0 ||
  150960. qtable->quantval[Q20_POS] == 0 ||
  150961. qtable->quantval[Q11_POS] == 0 ||
  150962. qtable->quantval[Q02_POS] == 0)
  150963. return FALSE;
  150964. coef_bits = cinfo->coef_bits[ci];
  150965. if (coef_bits[0] < 0)
  150966. return FALSE;
  150967. for (coefi = 1; coefi <= 5; coefi++) {
  150968. coef_bits_latch[coefi] = coef_bits[coefi];
  150969. if (coef_bits[coefi] != 0)
  150970. smoothing_useful = TRUE;
  150971. }
  150972. coef_bits_latch += SAVED_COEFS;
  150973. }
  150974. return smoothing_useful;
  150975. }
  150976. METHODDEF(int)
  150977. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150978. {
  150979. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150980. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150981. JDIMENSION block_num, last_block_column;
  150982. int ci, block_row, block_rows, access_rows;
  150983. JBLOCKARRAY buffer;
  150984. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  150985. JSAMPARRAY output_ptr;
  150986. JDIMENSION output_col;
  150987. jpeg_component_info *compptr;
  150988. inverse_DCT_method_ptr inverse_DCT;
  150989. boolean first_row, last_row;
  150990. JBLOCK workspace;
  150991. int *coef_bits;
  150992. JQUANT_TBL *quanttbl;
  150993. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  150994. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  150995. int Al, pred;
  150996. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150997. ! cinfo->inputctl->eoi_reached) {
  150998. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  150999. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151000. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151001. break;
  151002. }
  151003. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151004. return JPEG_SUSPENDED;
  151005. }
  151006. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151007. ci++, compptr++) {
  151008. if (! compptr->component_needed)
  151009. continue;
  151010. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151011. block_rows = compptr->v_samp_factor;
  151012. access_rows = block_rows * 2; /* this and next iMCU row */
  151013. last_row = FALSE;
  151014. } else {
  151015. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151016. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151017. access_rows = block_rows; /* this iMCU row only */
  151018. last_row = TRUE;
  151019. }
  151020. if (cinfo->output_iMCU_row > 0) {
  151021. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151022. buffer = (*cinfo->mem->access_virt_barray)
  151023. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151024. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151025. (JDIMENSION) access_rows, FALSE);
  151026. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151027. first_row = FALSE;
  151028. } else {
  151029. buffer = (*cinfo->mem->access_virt_barray)
  151030. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151031. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151032. first_row = TRUE;
  151033. }
  151034. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151035. quanttbl = compptr->quant_table;
  151036. Q00 = quanttbl->quantval[0];
  151037. Q01 = quanttbl->quantval[Q01_POS];
  151038. Q10 = quanttbl->quantval[Q10_POS];
  151039. Q20 = quanttbl->quantval[Q20_POS];
  151040. Q11 = quanttbl->quantval[Q11_POS];
  151041. Q02 = quanttbl->quantval[Q02_POS];
  151042. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151043. output_ptr = output_buf[ci];
  151044. for (block_row = 0; block_row < block_rows; block_row++) {
  151045. buffer_ptr = buffer[block_row];
  151046. if (first_row && block_row == 0)
  151047. prev_block_row = buffer_ptr;
  151048. else
  151049. prev_block_row = buffer[block_row-1];
  151050. if (last_row && block_row == block_rows-1)
  151051. next_block_row = buffer_ptr;
  151052. else
  151053. next_block_row = buffer[block_row+1];
  151054. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151055. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151056. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151057. output_col = 0;
  151058. last_block_column = compptr->width_in_blocks - 1;
  151059. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151060. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151061. if (block_num < last_block_column) {
  151062. DC3 = (int) prev_block_row[1][0];
  151063. DC6 = (int) buffer_ptr[1][0];
  151064. DC9 = (int) next_block_row[1][0];
  151065. }
  151066. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151067. num = 36 * Q00 * (DC4 - DC6);
  151068. if (num >= 0) {
  151069. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151070. if (Al > 0 && pred >= (1<<Al))
  151071. pred = (1<<Al)-1;
  151072. } else {
  151073. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151074. if (Al > 0 && pred >= (1<<Al))
  151075. pred = (1<<Al)-1;
  151076. pred = -pred;
  151077. }
  151078. workspace[1] = (JCOEF) pred;
  151079. }
  151080. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151081. num = 36 * Q00 * (DC2 - DC8);
  151082. if (num >= 0) {
  151083. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151084. if (Al > 0 && pred >= (1<<Al))
  151085. pred = (1<<Al)-1;
  151086. } else {
  151087. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151088. if (Al > 0 && pred >= (1<<Al))
  151089. pred = (1<<Al)-1;
  151090. pred = -pred;
  151091. }
  151092. workspace[8] = (JCOEF) pred;
  151093. }
  151094. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151095. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151096. if (num >= 0) {
  151097. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151098. if (Al > 0 && pred >= (1<<Al))
  151099. pred = (1<<Al)-1;
  151100. } else {
  151101. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151102. if (Al > 0 && pred >= (1<<Al))
  151103. pred = (1<<Al)-1;
  151104. pred = -pred;
  151105. }
  151106. workspace[16] = (JCOEF) pred;
  151107. }
  151108. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151109. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151110. if (num >= 0) {
  151111. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151112. if (Al > 0 && pred >= (1<<Al))
  151113. pred = (1<<Al)-1;
  151114. } else {
  151115. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151116. if (Al > 0 && pred >= (1<<Al))
  151117. pred = (1<<Al)-1;
  151118. pred = -pred;
  151119. }
  151120. workspace[9] = (JCOEF) pred;
  151121. }
  151122. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151123. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151124. if (num >= 0) {
  151125. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151126. if (Al > 0 && pred >= (1<<Al))
  151127. pred = (1<<Al)-1;
  151128. } else {
  151129. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151130. if (Al > 0 && pred >= (1<<Al))
  151131. pred = (1<<Al)-1;
  151132. pred = -pred;
  151133. }
  151134. workspace[2] = (JCOEF) pred;
  151135. }
  151136. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151137. output_ptr, output_col);
  151138. DC1 = DC2; DC2 = DC3;
  151139. DC4 = DC5; DC5 = DC6;
  151140. DC7 = DC8; DC8 = DC9;
  151141. buffer_ptr++, prev_block_row++, next_block_row++;
  151142. output_col += compptr->DCT_scaled_size;
  151143. }
  151144. output_ptr += compptr->DCT_scaled_size;
  151145. }
  151146. }
  151147. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151148. return JPEG_ROW_COMPLETED;
  151149. return JPEG_SCAN_COMPLETED;
  151150. }
  151151. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151152. GLOBAL(void)
  151153. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151154. {
  151155. my_coef_ptr3 coef;
  151156. coef = (my_coef_ptr3)
  151157. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151158. SIZEOF(my_coef_controller3));
  151159. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151160. coef->pub.start_input_pass = start_input_pass;
  151161. coef->pub.start_output_pass = start_output_pass;
  151162. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151163. coef->coef_bits_latch = NULL;
  151164. #endif
  151165. if (need_full_buffer) {
  151166. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151167. int ci, access_rows;
  151168. jpeg_component_info *compptr;
  151169. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151170. ci++, compptr++) {
  151171. access_rows = compptr->v_samp_factor;
  151172. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151173. if (cinfo->progressive_mode)
  151174. access_rows *= 3;
  151175. #endif
  151176. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151177. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151178. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151179. (long) compptr->h_samp_factor),
  151180. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151181. (long) compptr->v_samp_factor),
  151182. (JDIMENSION) access_rows);
  151183. }
  151184. coef->pub.consume_data = consume_data;
  151185. coef->pub.decompress_data = decompress_data;
  151186. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151187. #else
  151188. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151189. #endif
  151190. } else {
  151191. JBLOCKROW buffer;
  151192. int i;
  151193. buffer = (JBLOCKROW)
  151194. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151195. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151196. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151197. coef->MCU_buffer[i] = buffer + i;
  151198. }
  151199. coef->pub.consume_data = dummy_consume_data;
  151200. coef->pub.decompress_data = decompress_onepass;
  151201. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151202. }
  151203. }
  151204. /*** End of inlined file: jdcoefct.c ***/
  151205. #undef FIX
  151206. /*** Start of inlined file: jdcolor.c ***/
  151207. #define JPEG_INTERNALS
  151208. typedef struct {
  151209. struct jpeg_color_deconverter pub; /* public fields */
  151210. int * Cr_r_tab; /* => table for Cr to R conversion */
  151211. int * Cb_b_tab; /* => table for Cb to B conversion */
  151212. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151213. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151214. } my_color_deconverter2;
  151215. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151216. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151217. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151218. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151219. LOCAL(void)
  151220. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151221. {
  151222. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151223. int i;
  151224. INT32 x;
  151225. SHIFT_TEMPS
  151226. cconvert->Cr_r_tab = (int *)
  151227. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151228. (MAXJSAMPLE+1) * SIZEOF(int));
  151229. cconvert->Cb_b_tab = (int *)
  151230. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151231. (MAXJSAMPLE+1) * SIZEOF(int));
  151232. cconvert->Cr_g_tab = (INT32 *)
  151233. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151234. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151235. cconvert->Cb_g_tab = (INT32 *)
  151236. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151237. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151238. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151239. cconvert->Cr_r_tab[i] = (int)
  151240. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151241. cconvert->Cb_b_tab[i] = (int)
  151242. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151243. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151244. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151245. }
  151246. }
  151247. METHODDEF(void)
  151248. ycc_rgb_convert (j_decompress_ptr cinfo,
  151249. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151250. JSAMPARRAY output_buf, int num_rows)
  151251. {
  151252. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151253. register int y, cb, cr;
  151254. register JSAMPROW outptr;
  151255. register JSAMPROW inptr0, inptr1, inptr2;
  151256. register JDIMENSION col;
  151257. JDIMENSION num_cols = cinfo->output_width;
  151258. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151259. register int * Crrtab = cconvert->Cr_r_tab;
  151260. register int * Cbbtab = cconvert->Cb_b_tab;
  151261. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151262. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151263. SHIFT_TEMPS
  151264. while (--num_rows >= 0) {
  151265. inptr0 = input_buf[0][input_row];
  151266. inptr1 = input_buf[1][input_row];
  151267. inptr2 = input_buf[2][input_row];
  151268. input_row++;
  151269. outptr = *output_buf++;
  151270. for (col = 0; col < num_cols; col++) {
  151271. y = GETJSAMPLE(inptr0[col]);
  151272. cb = GETJSAMPLE(inptr1[col]);
  151273. cr = GETJSAMPLE(inptr2[col]);
  151274. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151275. outptr[RGB_GREEN] = range_limit[y +
  151276. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151277. SCALEBITS))];
  151278. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151279. outptr += RGB_PIXELSIZE;
  151280. }
  151281. }
  151282. }
  151283. METHODDEF(void)
  151284. null_convert2 (j_decompress_ptr cinfo,
  151285. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151286. JSAMPARRAY output_buf, int num_rows)
  151287. {
  151288. register JSAMPROW inptr, outptr;
  151289. register JDIMENSION count;
  151290. register int num_components = cinfo->num_components;
  151291. JDIMENSION num_cols = cinfo->output_width;
  151292. int ci;
  151293. while (--num_rows >= 0) {
  151294. for (ci = 0; ci < num_components; ci++) {
  151295. inptr = input_buf[ci][input_row];
  151296. outptr = output_buf[0] + ci;
  151297. for (count = num_cols; count > 0; count--) {
  151298. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151299. outptr += num_components;
  151300. }
  151301. }
  151302. input_row++;
  151303. output_buf++;
  151304. }
  151305. }
  151306. METHODDEF(void)
  151307. grayscale_convert2 (j_decompress_ptr cinfo,
  151308. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151309. JSAMPARRAY output_buf, int num_rows)
  151310. {
  151311. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151312. num_rows, cinfo->output_width);
  151313. }
  151314. METHODDEF(void)
  151315. gray_rgb_convert (j_decompress_ptr cinfo,
  151316. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151317. JSAMPARRAY output_buf, int num_rows)
  151318. {
  151319. register JSAMPROW inptr, outptr;
  151320. register JDIMENSION col;
  151321. JDIMENSION num_cols = cinfo->output_width;
  151322. while (--num_rows >= 0) {
  151323. inptr = input_buf[0][input_row++];
  151324. outptr = *output_buf++;
  151325. for (col = 0; col < num_cols; col++) {
  151326. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151327. outptr += RGB_PIXELSIZE;
  151328. }
  151329. }
  151330. }
  151331. METHODDEF(void)
  151332. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151333. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151334. JSAMPARRAY output_buf, int num_rows)
  151335. {
  151336. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151337. register int y, cb, cr;
  151338. register JSAMPROW outptr;
  151339. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151340. register JDIMENSION col;
  151341. JDIMENSION num_cols = cinfo->output_width;
  151342. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151343. register int * Crrtab = cconvert->Cr_r_tab;
  151344. register int * Cbbtab = cconvert->Cb_b_tab;
  151345. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151346. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151347. SHIFT_TEMPS
  151348. while (--num_rows >= 0) {
  151349. inptr0 = input_buf[0][input_row];
  151350. inptr1 = input_buf[1][input_row];
  151351. inptr2 = input_buf[2][input_row];
  151352. inptr3 = input_buf[3][input_row];
  151353. input_row++;
  151354. outptr = *output_buf++;
  151355. for (col = 0; col < num_cols; col++) {
  151356. y = GETJSAMPLE(inptr0[col]);
  151357. cb = GETJSAMPLE(inptr1[col]);
  151358. cr = GETJSAMPLE(inptr2[col]);
  151359. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151360. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151361. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151362. SCALEBITS)))];
  151363. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151364. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151365. outptr += 4;
  151366. }
  151367. }
  151368. }
  151369. METHODDEF(void)
  151370. start_pass_dcolor (j_decompress_ptr cinfo)
  151371. {
  151372. }
  151373. GLOBAL(void)
  151374. jinit_color_deconverter (j_decompress_ptr cinfo)
  151375. {
  151376. my_cconvert_ptr2 cconvert;
  151377. int ci;
  151378. cconvert = (my_cconvert_ptr2)
  151379. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151380. SIZEOF(my_color_deconverter2));
  151381. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151382. cconvert->pub.start_pass = start_pass_dcolor;
  151383. switch (cinfo->jpeg_color_space) {
  151384. case JCS_GRAYSCALE:
  151385. if (cinfo->num_components != 1)
  151386. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151387. break;
  151388. case JCS_RGB:
  151389. case JCS_YCbCr:
  151390. if (cinfo->num_components != 3)
  151391. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151392. break;
  151393. case JCS_CMYK:
  151394. case JCS_YCCK:
  151395. if (cinfo->num_components != 4)
  151396. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151397. break;
  151398. default: /* JCS_UNKNOWN can be anything */
  151399. if (cinfo->num_components < 1)
  151400. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151401. break;
  151402. }
  151403. switch (cinfo->out_color_space) {
  151404. case JCS_GRAYSCALE:
  151405. cinfo->out_color_components = 1;
  151406. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151407. cinfo->jpeg_color_space == JCS_YCbCr) {
  151408. cconvert->pub.color_convert = grayscale_convert2;
  151409. for (ci = 1; ci < cinfo->num_components; ci++)
  151410. cinfo->comp_info[ci].component_needed = FALSE;
  151411. } else
  151412. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151413. break;
  151414. case JCS_RGB:
  151415. cinfo->out_color_components = RGB_PIXELSIZE;
  151416. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151417. cconvert->pub.color_convert = ycc_rgb_convert;
  151418. build_ycc_rgb_table(cinfo);
  151419. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151420. cconvert->pub.color_convert = gray_rgb_convert;
  151421. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151422. cconvert->pub.color_convert = null_convert2;
  151423. } else
  151424. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151425. break;
  151426. case JCS_CMYK:
  151427. cinfo->out_color_components = 4;
  151428. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151429. cconvert->pub.color_convert = ycck_cmyk_convert;
  151430. build_ycc_rgb_table(cinfo);
  151431. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151432. cconvert->pub.color_convert = null_convert2;
  151433. } else
  151434. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151435. break;
  151436. default:
  151437. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151438. cinfo->out_color_components = cinfo->num_components;
  151439. cconvert->pub.color_convert = null_convert2;
  151440. } else /* unsupported non-null conversion */
  151441. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151442. break;
  151443. }
  151444. if (cinfo->quantize_colors)
  151445. cinfo->output_components = 1; /* single colormapped output component */
  151446. else
  151447. cinfo->output_components = cinfo->out_color_components;
  151448. }
  151449. /*** End of inlined file: jdcolor.c ***/
  151450. #undef FIX
  151451. /*** Start of inlined file: jddctmgr.c ***/
  151452. #define JPEG_INTERNALS
  151453. typedef struct {
  151454. struct jpeg_inverse_dct pub; /* public fields */
  151455. int cur_method[MAX_COMPONENTS];
  151456. } my_idct_controller;
  151457. typedef my_idct_controller * my_idct_ptr;
  151458. typedef union {
  151459. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151460. #ifdef DCT_IFAST_SUPPORTED
  151461. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151462. #endif
  151463. #ifdef DCT_FLOAT_SUPPORTED
  151464. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151465. #endif
  151466. } multiplier_table;
  151467. #ifdef DCT_ISLOW_SUPPORTED
  151468. #define PROVIDE_ISLOW_TABLES
  151469. #else
  151470. #ifdef IDCT_SCALING_SUPPORTED
  151471. #define PROVIDE_ISLOW_TABLES
  151472. #endif
  151473. #endif
  151474. METHODDEF(void)
  151475. start_pass (j_decompress_ptr cinfo)
  151476. {
  151477. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151478. int ci, i;
  151479. jpeg_component_info *compptr;
  151480. int method = 0;
  151481. inverse_DCT_method_ptr method_ptr = NULL;
  151482. JQUANT_TBL * qtbl;
  151483. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151484. ci++, compptr++) {
  151485. switch (compptr->DCT_scaled_size) {
  151486. #ifdef IDCT_SCALING_SUPPORTED
  151487. case 1:
  151488. method_ptr = jpeg_idct_1x1;
  151489. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151490. break;
  151491. case 2:
  151492. method_ptr = jpeg_idct_2x2;
  151493. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151494. break;
  151495. case 4:
  151496. method_ptr = jpeg_idct_4x4;
  151497. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151498. break;
  151499. #endif
  151500. case DCTSIZE:
  151501. switch (cinfo->dct_method) {
  151502. #ifdef DCT_ISLOW_SUPPORTED
  151503. case JDCT_ISLOW:
  151504. method_ptr = jpeg_idct_islow;
  151505. method = JDCT_ISLOW;
  151506. break;
  151507. #endif
  151508. #ifdef DCT_IFAST_SUPPORTED
  151509. case JDCT_IFAST:
  151510. method_ptr = jpeg_idct_ifast;
  151511. method = JDCT_IFAST;
  151512. break;
  151513. #endif
  151514. #ifdef DCT_FLOAT_SUPPORTED
  151515. case JDCT_FLOAT:
  151516. method_ptr = jpeg_idct_float;
  151517. method = JDCT_FLOAT;
  151518. break;
  151519. #endif
  151520. default:
  151521. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151522. break;
  151523. }
  151524. break;
  151525. default:
  151526. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151527. break;
  151528. }
  151529. idct->pub.inverse_DCT[ci] = method_ptr;
  151530. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151531. continue;
  151532. qtbl = compptr->quant_table;
  151533. if (qtbl == NULL) /* happens if no data yet for component */
  151534. continue;
  151535. idct->cur_method[ci] = method;
  151536. switch (method) {
  151537. #ifdef PROVIDE_ISLOW_TABLES
  151538. case JDCT_ISLOW:
  151539. {
  151540. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151541. for (i = 0; i < DCTSIZE2; i++) {
  151542. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151543. }
  151544. }
  151545. break;
  151546. #endif
  151547. #ifdef DCT_IFAST_SUPPORTED
  151548. case JDCT_IFAST:
  151549. {
  151550. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151551. #define CONST_BITS 14
  151552. static const INT16 aanscales[DCTSIZE2] = {
  151553. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151554. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151555. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151556. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151557. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151558. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151559. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151560. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151561. };
  151562. SHIFT_TEMPS
  151563. for (i = 0; i < DCTSIZE2; i++) {
  151564. ifmtbl[i] = (IFAST_MULT_TYPE)
  151565. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151566. (INT32) aanscales[i]),
  151567. CONST_BITS-IFAST_SCALE_BITS);
  151568. }
  151569. }
  151570. break;
  151571. #endif
  151572. #ifdef DCT_FLOAT_SUPPORTED
  151573. case JDCT_FLOAT:
  151574. {
  151575. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151576. int row, col;
  151577. static const double aanscalefactor[DCTSIZE] = {
  151578. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151579. 1.0, 0.785694958, 0.541196100, 0.275899379
  151580. };
  151581. i = 0;
  151582. for (row = 0; row < DCTSIZE; row++) {
  151583. for (col = 0; col < DCTSIZE; col++) {
  151584. fmtbl[i] = (FLOAT_MULT_TYPE)
  151585. ((double) qtbl->quantval[i] *
  151586. aanscalefactor[row] * aanscalefactor[col]);
  151587. i++;
  151588. }
  151589. }
  151590. }
  151591. break;
  151592. #endif
  151593. default:
  151594. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151595. break;
  151596. }
  151597. }
  151598. }
  151599. GLOBAL(void)
  151600. jinit_inverse_dct (j_decompress_ptr cinfo)
  151601. {
  151602. my_idct_ptr idct;
  151603. int ci;
  151604. jpeg_component_info *compptr;
  151605. idct = (my_idct_ptr)
  151606. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151607. SIZEOF(my_idct_controller));
  151608. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151609. idct->pub.start_pass = start_pass;
  151610. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151611. ci++, compptr++) {
  151612. compptr->dct_table =
  151613. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151614. SIZEOF(multiplier_table));
  151615. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151616. idct->cur_method[ci] = -1;
  151617. }
  151618. }
  151619. /*** End of inlined file: jddctmgr.c ***/
  151620. #undef CONST_BITS
  151621. #undef ASSIGN_STATE
  151622. /*** Start of inlined file: jdhuff.c ***/
  151623. #define JPEG_INTERNALS
  151624. /*** Start of inlined file: jdhuff.h ***/
  151625. #ifndef __jdhuff_h__
  151626. #define __jdhuff_h__
  151627. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151628. #define jpeg_make_d_derived_tbl jMkDDerived
  151629. #define jpeg_fill_bit_buffer jFilBitBuf
  151630. #define jpeg_huff_decode jHufDecode
  151631. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151632. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151633. typedef struct {
  151634. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151635. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151636. JHUFF_TBL *pub;
  151637. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151638. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151639. } d_derived_tbl;
  151640. EXTERN(void) jpeg_make_d_derived_tbl
  151641. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151642. d_derived_tbl ** pdtbl));
  151643. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151644. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151645. typedef struct { /* Bitreading state saved across MCUs */
  151646. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151647. int bits_left; /* # of unused bits in it */
  151648. } bitread_perm_state;
  151649. typedef struct { /* Bitreading working state within an MCU */
  151650. const JOCTET * next_input_byte; /* => next byte to read from source */
  151651. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151652. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151653. int bits_left; /* # of unused bits in it */
  151654. j_decompress_ptr cinfo; /* back link to decompress master record */
  151655. } bitread_working_state;
  151656. #define BITREAD_STATE_VARS \
  151657. register bit_buf_type get_buffer; \
  151658. register int bits_left; \
  151659. bitread_working_state br_state
  151660. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151661. br_state.cinfo = cinfop; \
  151662. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151663. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151664. get_buffer = permstate.get_buffer; \
  151665. bits_left = permstate.bits_left;
  151666. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151667. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151668. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151669. permstate.get_buffer = get_buffer; \
  151670. permstate.bits_left = bits_left
  151671. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151672. { if (bits_left < (nbits)) { \
  151673. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151674. { action; } \
  151675. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151676. #define GET_BITS(nbits) \
  151677. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151678. #define PEEK_BITS(nbits) \
  151679. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151680. #define DROP_BITS(nbits) \
  151681. (bits_left -= (nbits))
  151682. EXTERN(boolean) jpeg_fill_bit_buffer
  151683. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151684. register int bits_left, int nbits));
  151685. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151686. { register int nb, look; \
  151687. if (bits_left < HUFF_LOOKAHEAD) { \
  151688. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151689. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151690. if (bits_left < HUFF_LOOKAHEAD) { \
  151691. nb = 1; goto slowlabel; \
  151692. } \
  151693. } \
  151694. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151695. if ((nb = htbl->look_nbits[look]) != 0) { \
  151696. DROP_BITS(nb); \
  151697. result = htbl->look_sym[look]; \
  151698. } else { \
  151699. nb = HUFF_LOOKAHEAD+1; \
  151700. slowlabel: \
  151701. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151702. { failaction; } \
  151703. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151704. } \
  151705. }
  151706. EXTERN(int) jpeg_huff_decode
  151707. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151708. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151709. #endif
  151710. /*** End of inlined file: jdhuff.h ***/
  151711. /* Declarations shared with jdphuff.c */
  151712. typedef struct {
  151713. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151714. } savable_state2;
  151715. #ifndef NO_STRUCT_ASSIGN
  151716. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151717. #else
  151718. #if MAX_COMPS_IN_SCAN == 4
  151719. #define ASSIGN_STATE(dest,src) \
  151720. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151721. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151722. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151723. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151724. #endif
  151725. #endif
  151726. typedef struct {
  151727. struct jpeg_entropy_decoder pub; /* public fields */
  151728. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151729. savable_state2 saved; /* Other state at start of MCU */
  151730. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151731. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151732. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151733. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151734. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151735. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151736. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151737. } huff_entropy_decoder2;
  151738. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151739. METHODDEF(void)
  151740. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151741. {
  151742. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151743. int ci, blkn, dctbl, actbl;
  151744. jpeg_component_info * compptr;
  151745. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151746. cinfo->Ah != 0 || cinfo->Al != 0)
  151747. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151748. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151749. compptr = cinfo->cur_comp_info[ci];
  151750. dctbl = compptr->dc_tbl_no;
  151751. actbl = compptr->ac_tbl_no;
  151752. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151753. & entropy->dc_derived_tbls[dctbl]);
  151754. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151755. & entropy->ac_derived_tbls[actbl]);
  151756. entropy->saved.last_dc_val[ci] = 0;
  151757. }
  151758. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151759. ci = cinfo->MCU_membership[blkn];
  151760. compptr = cinfo->cur_comp_info[ci];
  151761. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151762. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151763. if (compptr->component_needed) {
  151764. entropy->dc_needed[blkn] = TRUE;
  151765. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151766. } else {
  151767. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151768. }
  151769. }
  151770. entropy->bitstate.bits_left = 0;
  151771. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151772. entropy->pub.insufficient_data = FALSE;
  151773. entropy->restarts_to_go = cinfo->restart_interval;
  151774. }
  151775. GLOBAL(void)
  151776. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151777. d_derived_tbl ** pdtbl)
  151778. {
  151779. JHUFF_TBL *htbl;
  151780. d_derived_tbl *dtbl;
  151781. int p, i, l, si, numsymbols;
  151782. int lookbits, ctr;
  151783. char huffsize[257];
  151784. unsigned int huffcode[257];
  151785. unsigned int code;
  151786. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151787. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151788. htbl =
  151789. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151790. if (htbl == NULL)
  151791. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151792. if (*pdtbl == NULL)
  151793. *pdtbl = (d_derived_tbl *)
  151794. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151795. SIZEOF(d_derived_tbl));
  151796. dtbl = *pdtbl;
  151797. dtbl->pub = htbl; /* fill in back link */
  151798. p = 0;
  151799. for (l = 1; l <= 16; l++) {
  151800. i = (int) htbl->bits[l];
  151801. if (i < 0 || p + i > 256) /* protect against table overrun */
  151802. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151803. while (i--)
  151804. huffsize[p++] = (char) l;
  151805. }
  151806. huffsize[p] = 0;
  151807. numsymbols = p;
  151808. code = 0;
  151809. si = huffsize[0];
  151810. p = 0;
  151811. while (huffsize[p]) {
  151812. while (((int) huffsize[p]) == si) {
  151813. huffcode[p++] = code;
  151814. code++;
  151815. }
  151816. if (((INT32) code) >= (((INT32) 1) << si))
  151817. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151818. code <<= 1;
  151819. si++;
  151820. }
  151821. p = 0;
  151822. for (l = 1; l <= 16; l++) {
  151823. if (htbl->bits[l]) {
  151824. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151825. p += htbl->bits[l];
  151826. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151827. } else {
  151828. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151829. }
  151830. }
  151831. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151832. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151833. p = 0;
  151834. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151835. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151836. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151837. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151838. dtbl->look_nbits[lookbits] = l;
  151839. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151840. lookbits++;
  151841. }
  151842. }
  151843. }
  151844. if (isDC) {
  151845. for (i = 0; i < numsymbols; i++) {
  151846. int sym = htbl->huffval[i];
  151847. if (sym < 0 || sym > 15)
  151848. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151849. }
  151850. }
  151851. }
  151852. #ifdef SLOW_SHIFT_32
  151853. #define MIN_GET_BITS 15 /* minimum allowable value */
  151854. #else
  151855. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151856. #endif
  151857. GLOBAL(boolean)
  151858. jpeg_fill_bit_buffer (bitread_working_state * state,
  151859. register bit_buf_type get_buffer, register int bits_left,
  151860. int nbits)
  151861. {
  151862. register const JOCTET * next_input_byte = state->next_input_byte;
  151863. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151864. j_decompress_ptr cinfo = state->cinfo;
  151865. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151866. while (bits_left < MIN_GET_BITS) {
  151867. register int c;
  151868. if (bytes_in_buffer == 0) {
  151869. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151870. return FALSE;
  151871. next_input_byte = cinfo->src->next_input_byte;
  151872. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151873. }
  151874. bytes_in_buffer--;
  151875. c = GETJOCTET(*next_input_byte++);
  151876. if (c == 0xFF) {
  151877. do {
  151878. if (bytes_in_buffer == 0) {
  151879. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151880. return FALSE;
  151881. next_input_byte = cinfo->src->next_input_byte;
  151882. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151883. }
  151884. bytes_in_buffer--;
  151885. c = GETJOCTET(*next_input_byte++);
  151886. } while (c == 0xFF);
  151887. if (c == 0) {
  151888. c = 0xFF;
  151889. } else {
  151890. cinfo->unread_marker = c;
  151891. goto no_more_bytes;
  151892. }
  151893. }
  151894. get_buffer = (get_buffer << 8) | c;
  151895. bits_left += 8;
  151896. } /* end while */
  151897. } else {
  151898. no_more_bytes:
  151899. if (nbits > bits_left) {
  151900. if (! cinfo->entropy->insufficient_data) {
  151901. WARNMS(cinfo, JWRN_HIT_MARKER);
  151902. cinfo->entropy->insufficient_data = TRUE;
  151903. }
  151904. get_buffer <<= MIN_GET_BITS - bits_left;
  151905. bits_left = MIN_GET_BITS;
  151906. }
  151907. }
  151908. state->next_input_byte = next_input_byte;
  151909. state->bytes_in_buffer = bytes_in_buffer;
  151910. state->get_buffer = get_buffer;
  151911. state->bits_left = bits_left;
  151912. return TRUE;
  151913. }
  151914. GLOBAL(int)
  151915. jpeg_huff_decode (bitread_working_state * state,
  151916. register bit_buf_type get_buffer, register int bits_left,
  151917. d_derived_tbl * htbl, int min_bits)
  151918. {
  151919. register int l = min_bits;
  151920. register INT32 code;
  151921. CHECK_BIT_BUFFER(*state, l, return -1);
  151922. code = GET_BITS(l);
  151923. while (code > htbl->maxcode[l]) {
  151924. code <<= 1;
  151925. CHECK_BIT_BUFFER(*state, 1, return -1);
  151926. code |= GET_BITS(1);
  151927. l++;
  151928. }
  151929. state->get_buffer = get_buffer;
  151930. state->bits_left = bits_left;
  151931. if (l > 16) {
  151932. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  151933. return 0; /* fake a zero as the safest result */
  151934. }
  151935. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  151936. }
  151937. LOCAL(boolean)
  151938. process_restart (j_decompress_ptr cinfo)
  151939. {
  151940. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151941. int ci;
  151942. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  151943. entropy->bitstate.bits_left = 0;
  151944. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  151945. return FALSE;
  151946. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  151947. entropy->saved.last_dc_val[ci] = 0;
  151948. entropy->restarts_to_go = cinfo->restart_interval;
  151949. if (cinfo->unread_marker == 0)
  151950. entropy->pub.insufficient_data = FALSE;
  151951. return TRUE;
  151952. }
  151953. METHODDEF(boolean)
  151954. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  151955. {
  151956. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151957. int blkn;
  151958. BITREAD_STATE_VARS;
  151959. savable_state2 state;
  151960. if (cinfo->restart_interval) {
  151961. if (entropy->restarts_to_go == 0)
  151962. if (! process_restart(cinfo))
  151963. return FALSE;
  151964. }
  151965. if (! entropy->pub.insufficient_data) {
  151966. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  151967. ASSIGN_STATE(state, entropy->saved);
  151968. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151969. JBLOCKROW block = MCU_data[blkn];
  151970. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  151971. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  151972. register int s, k, r;
  151973. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  151974. if (s) {
  151975. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151976. r = GET_BITS(s);
  151977. s = HUFF_EXTEND(r, s);
  151978. }
  151979. if (entropy->dc_needed[blkn]) {
  151980. int ci = cinfo->MCU_membership[blkn];
  151981. s += state.last_dc_val[ci];
  151982. state.last_dc_val[ci] = s;
  151983. (*block)[0] = (JCOEF) s;
  151984. }
  151985. if (entropy->ac_needed[blkn]) {
  151986. for (k = 1; k < DCTSIZE2; k++) {
  151987. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  151988. r = s >> 4;
  151989. s &= 15;
  151990. if (s) {
  151991. k += r;
  151992. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151993. r = GET_BITS(s);
  151994. s = HUFF_EXTEND(r, s);
  151995. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  151996. } else {
  151997. if (r != 15)
  151998. break;
  151999. k += 15;
  152000. }
  152001. }
  152002. } else {
  152003. for (k = 1; k < DCTSIZE2; k++) {
  152004. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152005. r = s >> 4;
  152006. s &= 15;
  152007. if (s) {
  152008. k += r;
  152009. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152010. DROP_BITS(s);
  152011. } else {
  152012. if (r != 15)
  152013. break;
  152014. k += 15;
  152015. }
  152016. }
  152017. }
  152018. }
  152019. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152020. ASSIGN_STATE(entropy->saved, state);
  152021. }
  152022. entropy->restarts_to_go--;
  152023. return TRUE;
  152024. }
  152025. GLOBAL(void)
  152026. jinit_huff_decoder (j_decompress_ptr cinfo)
  152027. {
  152028. huff_entropy_ptr2 entropy;
  152029. int i;
  152030. entropy = (huff_entropy_ptr2)
  152031. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152032. SIZEOF(huff_entropy_decoder2));
  152033. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152034. entropy->pub.start_pass = start_pass_huff_decoder;
  152035. entropy->pub.decode_mcu = decode_mcu;
  152036. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152037. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152038. }
  152039. }
  152040. /*** End of inlined file: jdhuff.c ***/
  152041. /*** Start of inlined file: jdinput.c ***/
  152042. #define JPEG_INTERNALS
  152043. typedef struct {
  152044. struct jpeg_input_controller pub; /* public fields */
  152045. boolean inheaders; /* TRUE until first SOS is reached */
  152046. } my_input_controller;
  152047. typedef my_input_controller * my_inputctl_ptr;
  152048. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152049. LOCAL(void)
  152050. initial_setup2 (j_decompress_ptr cinfo)
  152051. {
  152052. int ci;
  152053. jpeg_component_info *compptr;
  152054. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152055. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152056. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152057. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152058. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152059. if (cinfo->num_components > MAX_COMPONENTS)
  152060. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152061. MAX_COMPONENTS);
  152062. cinfo->max_h_samp_factor = 1;
  152063. cinfo->max_v_samp_factor = 1;
  152064. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152065. ci++, compptr++) {
  152066. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152067. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152068. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152069. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152070. compptr->h_samp_factor);
  152071. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152072. compptr->v_samp_factor);
  152073. }
  152074. cinfo->min_DCT_scaled_size = DCTSIZE;
  152075. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152076. ci++, compptr++) {
  152077. compptr->DCT_scaled_size = DCTSIZE;
  152078. compptr->width_in_blocks = (JDIMENSION)
  152079. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152080. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152081. compptr->height_in_blocks = (JDIMENSION)
  152082. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152083. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152084. compptr->downsampled_width = (JDIMENSION)
  152085. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152086. (long) cinfo->max_h_samp_factor);
  152087. compptr->downsampled_height = (JDIMENSION)
  152088. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152089. (long) cinfo->max_v_samp_factor);
  152090. compptr->component_needed = TRUE;
  152091. compptr->quant_table = NULL;
  152092. }
  152093. cinfo->total_iMCU_rows = (JDIMENSION)
  152094. jdiv_round_up((long) cinfo->image_height,
  152095. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152096. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152097. cinfo->inputctl->has_multiple_scans = TRUE;
  152098. else
  152099. cinfo->inputctl->has_multiple_scans = FALSE;
  152100. }
  152101. LOCAL(void)
  152102. per_scan_setup2 (j_decompress_ptr cinfo)
  152103. {
  152104. int ci, mcublks, tmp;
  152105. jpeg_component_info *compptr;
  152106. if (cinfo->comps_in_scan == 1) {
  152107. compptr = cinfo->cur_comp_info[0];
  152108. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152109. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152110. compptr->MCU_width = 1;
  152111. compptr->MCU_height = 1;
  152112. compptr->MCU_blocks = 1;
  152113. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152114. compptr->last_col_width = 1;
  152115. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152116. if (tmp == 0) tmp = compptr->v_samp_factor;
  152117. compptr->last_row_height = tmp;
  152118. cinfo->blocks_in_MCU = 1;
  152119. cinfo->MCU_membership[0] = 0;
  152120. } else {
  152121. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152122. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152123. MAX_COMPS_IN_SCAN);
  152124. cinfo->MCUs_per_row = (JDIMENSION)
  152125. jdiv_round_up((long) cinfo->image_width,
  152126. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152127. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152128. jdiv_round_up((long) cinfo->image_height,
  152129. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152130. cinfo->blocks_in_MCU = 0;
  152131. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152132. compptr = cinfo->cur_comp_info[ci];
  152133. compptr->MCU_width = compptr->h_samp_factor;
  152134. compptr->MCU_height = compptr->v_samp_factor;
  152135. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152136. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152137. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152138. if (tmp == 0) tmp = compptr->MCU_width;
  152139. compptr->last_col_width = tmp;
  152140. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152141. if (tmp == 0) tmp = compptr->MCU_height;
  152142. compptr->last_row_height = tmp;
  152143. mcublks = compptr->MCU_blocks;
  152144. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152145. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152146. while (mcublks-- > 0) {
  152147. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152148. }
  152149. }
  152150. }
  152151. }
  152152. LOCAL(void)
  152153. latch_quant_tables (j_decompress_ptr cinfo)
  152154. {
  152155. int ci, qtblno;
  152156. jpeg_component_info *compptr;
  152157. JQUANT_TBL * qtbl;
  152158. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152159. compptr = cinfo->cur_comp_info[ci];
  152160. if (compptr->quant_table != NULL)
  152161. continue;
  152162. qtblno = compptr->quant_tbl_no;
  152163. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152164. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152165. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152166. qtbl = (JQUANT_TBL *)
  152167. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152168. SIZEOF(JQUANT_TBL));
  152169. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152170. compptr->quant_table = qtbl;
  152171. }
  152172. }
  152173. METHODDEF(void)
  152174. start_input_pass2 (j_decompress_ptr cinfo)
  152175. {
  152176. per_scan_setup2(cinfo);
  152177. latch_quant_tables(cinfo);
  152178. (*cinfo->entropy->start_pass) (cinfo);
  152179. (*cinfo->coef->start_input_pass) (cinfo);
  152180. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152181. }
  152182. METHODDEF(void)
  152183. finish_input_pass (j_decompress_ptr cinfo)
  152184. {
  152185. cinfo->inputctl->consume_input = consume_markers;
  152186. }
  152187. METHODDEF(int)
  152188. consume_markers (j_decompress_ptr cinfo)
  152189. {
  152190. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152191. int val;
  152192. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152193. return JPEG_REACHED_EOI;
  152194. val = (*cinfo->marker->read_markers) (cinfo);
  152195. switch (val) {
  152196. case JPEG_REACHED_SOS: /* Found SOS */
  152197. if (inputctl->inheaders) { /* 1st SOS */
  152198. initial_setup2(cinfo);
  152199. inputctl->inheaders = FALSE;
  152200. } else { /* 2nd or later SOS marker */
  152201. if (! inputctl->pub.has_multiple_scans)
  152202. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152203. start_input_pass2(cinfo);
  152204. }
  152205. break;
  152206. case JPEG_REACHED_EOI: /* Found EOI */
  152207. inputctl->pub.eoi_reached = TRUE;
  152208. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152209. if (cinfo->marker->saw_SOF)
  152210. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152211. } else {
  152212. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152213. cinfo->output_scan_number = cinfo->input_scan_number;
  152214. }
  152215. break;
  152216. case JPEG_SUSPENDED:
  152217. break;
  152218. }
  152219. return val;
  152220. }
  152221. METHODDEF(void)
  152222. reset_input_controller (j_decompress_ptr cinfo)
  152223. {
  152224. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152225. inputctl->pub.consume_input = consume_markers;
  152226. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152227. inputctl->pub.eoi_reached = FALSE;
  152228. inputctl->inheaders = TRUE;
  152229. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152230. (*cinfo->marker->reset_marker_reader) (cinfo);
  152231. cinfo->coef_bits = NULL;
  152232. }
  152233. GLOBAL(void)
  152234. jinit_input_controller (j_decompress_ptr cinfo)
  152235. {
  152236. my_inputctl_ptr inputctl;
  152237. inputctl = (my_inputctl_ptr)
  152238. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152239. SIZEOF(my_input_controller));
  152240. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152241. inputctl->pub.consume_input = consume_markers;
  152242. inputctl->pub.reset_input_controller = reset_input_controller;
  152243. inputctl->pub.start_input_pass = start_input_pass2;
  152244. inputctl->pub.finish_input_pass = finish_input_pass;
  152245. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152246. inputctl->pub.eoi_reached = FALSE;
  152247. inputctl->inheaders = TRUE;
  152248. }
  152249. /*** End of inlined file: jdinput.c ***/
  152250. /*** Start of inlined file: jdmainct.c ***/
  152251. #define JPEG_INTERNALS
  152252. typedef struct {
  152253. struct jpeg_d_main_controller pub; /* public fields */
  152254. JSAMPARRAY buffer[MAX_COMPONENTS];
  152255. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152256. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152257. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152258. int whichptr; /* indicates which pointer set is now in use */
  152259. int context_state; /* process_data state machine status */
  152260. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152261. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152262. } my_main_controller4;
  152263. typedef my_main_controller4 * my_main_ptr4;
  152264. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152265. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152266. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152267. METHODDEF(void) process_data_simple_main2
  152268. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152269. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152270. METHODDEF(void) process_data_context_main
  152271. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152272. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152273. #ifdef QUANT_2PASS_SUPPORTED
  152274. METHODDEF(void) process_data_crank_post
  152275. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152276. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152277. #endif
  152278. LOCAL(void)
  152279. alloc_funny_pointers (j_decompress_ptr cinfo)
  152280. {
  152281. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152282. int ci, rgroup;
  152283. int M = cinfo->min_DCT_scaled_size;
  152284. jpeg_component_info *compptr;
  152285. JSAMPARRAY xbuf;
  152286. main_->xbuffer[0] = (JSAMPIMAGE)
  152287. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152288. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152289. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152290. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152291. ci++, compptr++) {
  152292. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152293. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152294. xbuf = (JSAMPARRAY)
  152295. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152296. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152297. xbuf += rgroup; /* want one row group at negative offsets */
  152298. main_->xbuffer[0][ci] = xbuf;
  152299. xbuf += rgroup * (M + 4);
  152300. main_->xbuffer[1][ci] = xbuf;
  152301. }
  152302. }
  152303. LOCAL(void)
  152304. make_funny_pointers (j_decompress_ptr cinfo)
  152305. {
  152306. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152307. int ci, i, rgroup;
  152308. int M = cinfo->min_DCT_scaled_size;
  152309. jpeg_component_info *compptr;
  152310. JSAMPARRAY buf, xbuf0, xbuf1;
  152311. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152312. ci++, compptr++) {
  152313. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152314. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152315. xbuf0 = main_->xbuffer[0][ci];
  152316. xbuf1 = main_->xbuffer[1][ci];
  152317. buf = main_->buffer[ci];
  152318. for (i = 0; i < rgroup * (M + 2); i++) {
  152319. xbuf0[i] = xbuf1[i] = buf[i];
  152320. }
  152321. for (i = 0; i < rgroup * 2; i++) {
  152322. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152323. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152324. }
  152325. for (i = 0; i < rgroup; i++) {
  152326. xbuf0[i - rgroup] = xbuf0[0];
  152327. }
  152328. }
  152329. }
  152330. LOCAL(void)
  152331. set_wraparound_pointers (j_decompress_ptr cinfo)
  152332. {
  152333. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152334. int ci, i, rgroup;
  152335. int M = cinfo->min_DCT_scaled_size;
  152336. jpeg_component_info *compptr;
  152337. JSAMPARRAY xbuf0, xbuf1;
  152338. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152339. ci++, compptr++) {
  152340. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152341. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152342. xbuf0 = main_->xbuffer[0][ci];
  152343. xbuf1 = main_->xbuffer[1][ci];
  152344. for (i = 0; i < rgroup; i++) {
  152345. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152346. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152347. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152348. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152349. }
  152350. }
  152351. }
  152352. LOCAL(void)
  152353. set_bottom_pointers (j_decompress_ptr cinfo)
  152354. {
  152355. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152356. int ci, i, rgroup, iMCUheight, rows_left;
  152357. jpeg_component_info *compptr;
  152358. JSAMPARRAY xbuf;
  152359. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152360. ci++, compptr++) {
  152361. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152362. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152363. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152364. if (rows_left == 0) rows_left = iMCUheight;
  152365. if (ci == 0) {
  152366. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152367. }
  152368. xbuf = main_->xbuffer[main_->whichptr][ci];
  152369. for (i = 0; i < rgroup * 2; i++) {
  152370. xbuf[rows_left + i] = xbuf[rows_left-1];
  152371. }
  152372. }
  152373. }
  152374. METHODDEF(void)
  152375. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152376. {
  152377. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152378. switch (pass_mode) {
  152379. case JBUF_PASS_THRU:
  152380. if (cinfo->upsample->need_context_rows) {
  152381. main_->pub.process_data = process_data_context_main;
  152382. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152383. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152384. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152385. main_->iMCU_row_ctr = 0;
  152386. } else {
  152387. main_->pub.process_data = process_data_simple_main2;
  152388. }
  152389. main_->buffer_full = FALSE; /* Mark buffer empty */
  152390. main_->rowgroup_ctr = 0;
  152391. break;
  152392. #ifdef QUANT_2PASS_SUPPORTED
  152393. case JBUF_CRANK_DEST:
  152394. main_->pub.process_data = process_data_crank_post;
  152395. break;
  152396. #endif
  152397. default:
  152398. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152399. break;
  152400. }
  152401. }
  152402. METHODDEF(void)
  152403. process_data_simple_main2 (j_decompress_ptr cinfo,
  152404. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152405. JDIMENSION out_rows_avail)
  152406. {
  152407. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152408. JDIMENSION rowgroups_avail;
  152409. if (! main_->buffer_full) {
  152410. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152411. return; /* suspension forced, can do nothing more */
  152412. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152413. }
  152414. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152415. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152416. &main_->rowgroup_ctr, rowgroups_avail,
  152417. output_buf, out_row_ctr, out_rows_avail);
  152418. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152419. main_->buffer_full = FALSE;
  152420. main_->rowgroup_ctr = 0;
  152421. }
  152422. }
  152423. METHODDEF(void)
  152424. process_data_context_main (j_decompress_ptr cinfo,
  152425. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152426. JDIMENSION out_rows_avail)
  152427. {
  152428. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152429. if (! main_->buffer_full) {
  152430. if (! (*cinfo->coef->decompress_data) (cinfo,
  152431. main_->xbuffer[main_->whichptr]))
  152432. return; /* suspension forced, can do nothing more */
  152433. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152434. main_->iMCU_row_ctr++; /* count rows received */
  152435. }
  152436. switch (main_->context_state) {
  152437. case CTX_POSTPONED_ROW:
  152438. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152439. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152440. output_buf, out_row_ctr, out_rows_avail);
  152441. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152442. return; /* Need to suspend */
  152443. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152444. if (*out_row_ctr >= out_rows_avail)
  152445. return; /* Postprocessor exactly filled output buf */
  152446. case CTX_PREPARE_FOR_IMCU:
  152447. main_->rowgroup_ctr = 0;
  152448. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152449. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152450. set_bottom_pointers(cinfo);
  152451. main_->context_state = CTX_PROCESS_IMCU;
  152452. case CTX_PROCESS_IMCU:
  152453. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152454. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152455. output_buf, out_row_ctr, out_rows_avail);
  152456. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152457. return; /* Need to suspend */
  152458. if (main_->iMCU_row_ctr == 1)
  152459. set_wraparound_pointers(cinfo);
  152460. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152461. main_->buffer_full = FALSE;
  152462. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152463. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152464. main_->context_state = CTX_POSTPONED_ROW;
  152465. }
  152466. }
  152467. #ifdef QUANT_2PASS_SUPPORTED
  152468. METHODDEF(void)
  152469. process_data_crank_post (j_decompress_ptr cinfo,
  152470. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152471. JDIMENSION out_rows_avail)
  152472. {
  152473. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152474. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152475. output_buf, out_row_ctr, out_rows_avail);
  152476. }
  152477. #endif /* QUANT_2PASS_SUPPORTED */
  152478. GLOBAL(void)
  152479. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152480. {
  152481. my_main_ptr4 main_;
  152482. int ci, rgroup, ngroups;
  152483. jpeg_component_info *compptr;
  152484. main_ = (my_main_ptr4)
  152485. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152486. SIZEOF(my_main_controller4));
  152487. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152488. main_->pub.start_pass = start_pass_main2;
  152489. if (need_full_buffer) /* shouldn't happen */
  152490. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152491. if (cinfo->upsample->need_context_rows) {
  152492. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152493. ERREXIT(cinfo, JERR_NOTIMPL);
  152494. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152495. ngroups = cinfo->min_DCT_scaled_size + 2;
  152496. } else {
  152497. ngroups = cinfo->min_DCT_scaled_size;
  152498. }
  152499. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152500. ci++, compptr++) {
  152501. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152502. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152503. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152504. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152505. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152506. (JDIMENSION) (rgroup * ngroups));
  152507. }
  152508. }
  152509. /*** End of inlined file: jdmainct.c ***/
  152510. /*** Start of inlined file: jdmarker.c ***/
  152511. #define JPEG_INTERNALS
  152512. typedef struct {
  152513. struct jpeg_marker_reader pub; /* public fields */
  152514. jpeg_marker_parser_method process_COM;
  152515. jpeg_marker_parser_method process_APPn[16];
  152516. unsigned int length_limit_COM;
  152517. unsigned int length_limit_APPn[16];
  152518. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152519. unsigned int bytes_read; /* data bytes read so far in marker */
  152520. } my_marker_reader;
  152521. typedef my_marker_reader * my_marker_ptr2;
  152522. #define INPUT_VARS(cinfo) \
  152523. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152524. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152525. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152526. #define INPUT_SYNC(cinfo) \
  152527. ( datasrc->next_input_byte = next_input_byte, \
  152528. datasrc->bytes_in_buffer = bytes_in_buffer )
  152529. #define INPUT_RELOAD(cinfo) \
  152530. ( next_input_byte = datasrc->next_input_byte, \
  152531. bytes_in_buffer = datasrc->bytes_in_buffer )
  152532. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152533. if (bytes_in_buffer == 0) { \
  152534. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152535. { action; } \
  152536. INPUT_RELOAD(cinfo); \
  152537. }
  152538. #define INPUT_BYTE(cinfo,V,action) \
  152539. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152540. bytes_in_buffer--; \
  152541. V = GETJOCTET(*next_input_byte++); )
  152542. #define INPUT_2BYTES(cinfo,V,action) \
  152543. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152544. bytes_in_buffer--; \
  152545. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152546. MAKE_BYTE_AVAIL(cinfo,action); \
  152547. bytes_in_buffer--; \
  152548. V += GETJOCTET(*next_input_byte++); )
  152549. LOCAL(boolean)
  152550. get_soi (j_decompress_ptr cinfo)
  152551. {
  152552. int i;
  152553. TRACEMS(cinfo, 1, JTRC_SOI);
  152554. if (cinfo->marker->saw_SOI)
  152555. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152556. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152557. cinfo->arith_dc_L[i] = 0;
  152558. cinfo->arith_dc_U[i] = 1;
  152559. cinfo->arith_ac_K[i] = 5;
  152560. }
  152561. cinfo->restart_interval = 0;
  152562. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152563. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152564. cinfo->saw_JFIF_marker = FALSE;
  152565. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152566. cinfo->JFIF_minor_version = 1;
  152567. cinfo->density_unit = 0;
  152568. cinfo->X_density = 1;
  152569. cinfo->Y_density = 1;
  152570. cinfo->saw_Adobe_marker = FALSE;
  152571. cinfo->Adobe_transform = 0;
  152572. cinfo->marker->saw_SOI = TRUE;
  152573. return TRUE;
  152574. }
  152575. LOCAL(boolean)
  152576. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152577. {
  152578. INT32 length;
  152579. int c, ci;
  152580. jpeg_component_info * compptr;
  152581. INPUT_VARS(cinfo);
  152582. cinfo->progressive_mode = is_prog;
  152583. cinfo->arith_code = is_arith;
  152584. INPUT_2BYTES(cinfo, length, return FALSE);
  152585. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152586. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152587. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152588. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152589. length -= 8;
  152590. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152591. (int) cinfo->image_width, (int) cinfo->image_height,
  152592. cinfo->num_components);
  152593. if (cinfo->marker->saw_SOF)
  152594. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152595. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152596. || cinfo->num_components <= 0)
  152597. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152598. if (length != (cinfo->num_components * 3))
  152599. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152600. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152601. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152602. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152603. cinfo->num_components * SIZEOF(jpeg_component_info));
  152604. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152605. ci++, compptr++) {
  152606. compptr->component_index = ci;
  152607. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152608. INPUT_BYTE(cinfo, c, return FALSE);
  152609. compptr->h_samp_factor = (c >> 4) & 15;
  152610. compptr->v_samp_factor = (c ) & 15;
  152611. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152612. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152613. compptr->component_id, compptr->h_samp_factor,
  152614. compptr->v_samp_factor, compptr->quant_tbl_no);
  152615. }
  152616. cinfo->marker->saw_SOF = TRUE;
  152617. INPUT_SYNC(cinfo);
  152618. return TRUE;
  152619. }
  152620. LOCAL(boolean)
  152621. get_sos (j_decompress_ptr cinfo)
  152622. {
  152623. INT32 length;
  152624. int i, ci, n, c, cc;
  152625. jpeg_component_info * compptr;
  152626. INPUT_VARS(cinfo);
  152627. if (! cinfo->marker->saw_SOF)
  152628. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152629. INPUT_2BYTES(cinfo, length, return FALSE);
  152630. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152631. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152632. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152633. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152634. cinfo->comps_in_scan = n;
  152635. for (i = 0; i < n; i++) {
  152636. INPUT_BYTE(cinfo, cc, return FALSE);
  152637. INPUT_BYTE(cinfo, c, return FALSE);
  152638. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152639. ci++, compptr++) {
  152640. if (cc == compptr->component_id)
  152641. goto id_found;
  152642. }
  152643. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152644. id_found:
  152645. cinfo->cur_comp_info[i] = compptr;
  152646. compptr->dc_tbl_no = (c >> 4) & 15;
  152647. compptr->ac_tbl_no = (c ) & 15;
  152648. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152649. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152650. }
  152651. INPUT_BYTE(cinfo, c, return FALSE);
  152652. cinfo->Ss = c;
  152653. INPUT_BYTE(cinfo, c, return FALSE);
  152654. cinfo->Se = c;
  152655. INPUT_BYTE(cinfo, c, return FALSE);
  152656. cinfo->Ah = (c >> 4) & 15;
  152657. cinfo->Al = (c ) & 15;
  152658. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152659. cinfo->Ah, cinfo->Al);
  152660. cinfo->marker->next_restart_num = 0;
  152661. cinfo->input_scan_number++;
  152662. INPUT_SYNC(cinfo);
  152663. return TRUE;
  152664. }
  152665. #ifdef D_ARITH_CODING_SUPPORTED
  152666. LOCAL(boolean)
  152667. get_dac (j_decompress_ptr cinfo)
  152668. {
  152669. INT32 length;
  152670. int index, val;
  152671. INPUT_VARS(cinfo);
  152672. INPUT_2BYTES(cinfo, length, return FALSE);
  152673. length -= 2;
  152674. while (length > 0) {
  152675. INPUT_BYTE(cinfo, index, return FALSE);
  152676. INPUT_BYTE(cinfo, val, return FALSE);
  152677. length -= 2;
  152678. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152679. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152680. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152681. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152682. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152683. } else { /* define DC table */
  152684. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152685. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152686. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152687. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152688. }
  152689. }
  152690. if (length != 0)
  152691. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152692. INPUT_SYNC(cinfo);
  152693. return TRUE;
  152694. }
  152695. #else /* ! D_ARITH_CODING_SUPPORTED */
  152696. #define get_dac(cinfo) skip_variable(cinfo)
  152697. #endif /* D_ARITH_CODING_SUPPORTED */
  152698. LOCAL(boolean)
  152699. get_dht (j_decompress_ptr cinfo)
  152700. {
  152701. INT32 length;
  152702. UINT8 bits[17];
  152703. UINT8 huffval[256];
  152704. int i, index, count;
  152705. JHUFF_TBL **htblptr;
  152706. INPUT_VARS(cinfo);
  152707. INPUT_2BYTES(cinfo, length, return FALSE);
  152708. length -= 2;
  152709. while (length > 16) {
  152710. INPUT_BYTE(cinfo, index, return FALSE);
  152711. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152712. bits[0] = 0;
  152713. count = 0;
  152714. for (i = 1; i <= 16; i++) {
  152715. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152716. count += bits[i];
  152717. }
  152718. length -= 1 + 16;
  152719. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152720. bits[1], bits[2], bits[3], bits[4],
  152721. bits[5], bits[6], bits[7], bits[8]);
  152722. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152723. bits[9], bits[10], bits[11], bits[12],
  152724. bits[13], bits[14], bits[15], bits[16]);
  152725. if (count > 256 || ((INT32) count) > length)
  152726. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152727. for (i = 0; i < count; i++)
  152728. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152729. length -= count;
  152730. if (index & 0x10) { /* AC table definition */
  152731. index -= 0x10;
  152732. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152733. } else { /* DC table definition */
  152734. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152735. }
  152736. if (index < 0 || index >= NUM_HUFF_TBLS)
  152737. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152738. if (*htblptr == NULL)
  152739. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152740. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152741. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152742. }
  152743. if (length != 0)
  152744. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152745. INPUT_SYNC(cinfo);
  152746. return TRUE;
  152747. }
  152748. LOCAL(boolean)
  152749. get_dqt (j_decompress_ptr cinfo)
  152750. {
  152751. INT32 length;
  152752. int n, i, prec;
  152753. unsigned int tmp;
  152754. JQUANT_TBL *quant_ptr;
  152755. INPUT_VARS(cinfo);
  152756. INPUT_2BYTES(cinfo, length, return FALSE);
  152757. length -= 2;
  152758. while (length > 0) {
  152759. INPUT_BYTE(cinfo, n, return FALSE);
  152760. prec = n >> 4;
  152761. n &= 0x0F;
  152762. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152763. if (n >= NUM_QUANT_TBLS)
  152764. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152765. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152766. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152767. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152768. for (i = 0; i < DCTSIZE2; i++) {
  152769. if (prec)
  152770. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152771. else
  152772. INPUT_BYTE(cinfo, tmp, return FALSE);
  152773. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152774. }
  152775. if (cinfo->err->trace_level >= 2) {
  152776. for (i = 0; i < DCTSIZE2; i += 8) {
  152777. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152778. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152779. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152780. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152781. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152782. }
  152783. }
  152784. length -= DCTSIZE2+1;
  152785. if (prec) length -= DCTSIZE2;
  152786. }
  152787. if (length != 0)
  152788. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152789. INPUT_SYNC(cinfo);
  152790. return TRUE;
  152791. }
  152792. LOCAL(boolean)
  152793. get_dri (j_decompress_ptr cinfo)
  152794. {
  152795. INT32 length;
  152796. unsigned int tmp;
  152797. INPUT_VARS(cinfo);
  152798. INPUT_2BYTES(cinfo, length, return FALSE);
  152799. if (length != 4)
  152800. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152801. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152802. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152803. cinfo->restart_interval = tmp;
  152804. INPUT_SYNC(cinfo);
  152805. return TRUE;
  152806. }
  152807. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152808. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152809. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152810. LOCAL(void)
  152811. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152812. unsigned int datalen, INT32 remaining)
  152813. {
  152814. INT32 totallen = (INT32) datalen + remaining;
  152815. if (datalen >= APP0_DATA_LEN &&
  152816. GETJOCTET(data[0]) == 0x4A &&
  152817. GETJOCTET(data[1]) == 0x46 &&
  152818. GETJOCTET(data[2]) == 0x49 &&
  152819. GETJOCTET(data[3]) == 0x46 &&
  152820. GETJOCTET(data[4]) == 0) {
  152821. cinfo->saw_JFIF_marker = TRUE;
  152822. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152823. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152824. cinfo->density_unit = GETJOCTET(data[7]);
  152825. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152826. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152827. if (cinfo->JFIF_major_version != 1)
  152828. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152829. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152830. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152831. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152832. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152833. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152834. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152835. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152836. totallen -= APP0_DATA_LEN;
  152837. if (totallen !=
  152838. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152839. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152840. } else if (datalen >= 6 &&
  152841. GETJOCTET(data[0]) == 0x4A &&
  152842. GETJOCTET(data[1]) == 0x46 &&
  152843. GETJOCTET(data[2]) == 0x58 &&
  152844. GETJOCTET(data[3]) == 0x58 &&
  152845. GETJOCTET(data[4]) == 0) {
  152846. switch (GETJOCTET(data[5])) {
  152847. case 0x10:
  152848. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152849. break;
  152850. case 0x11:
  152851. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152852. break;
  152853. case 0x13:
  152854. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152855. break;
  152856. default:
  152857. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152858. GETJOCTET(data[5]), (int) totallen);
  152859. break;
  152860. }
  152861. } else {
  152862. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152863. }
  152864. }
  152865. LOCAL(void)
  152866. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152867. unsigned int datalen, INT32 remaining)
  152868. {
  152869. unsigned int version, flags0, flags1, transform;
  152870. if (datalen >= APP14_DATA_LEN &&
  152871. GETJOCTET(data[0]) == 0x41 &&
  152872. GETJOCTET(data[1]) == 0x64 &&
  152873. GETJOCTET(data[2]) == 0x6F &&
  152874. GETJOCTET(data[3]) == 0x62 &&
  152875. GETJOCTET(data[4]) == 0x65) {
  152876. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152877. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152878. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152879. transform = GETJOCTET(data[11]);
  152880. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152881. cinfo->saw_Adobe_marker = TRUE;
  152882. cinfo->Adobe_transform = (UINT8) transform;
  152883. } else {
  152884. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152885. }
  152886. }
  152887. METHODDEF(boolean)
  152888. get_interesting_appn (j_decompress_ptr cinfo)
  152889. {
  152890. INT32 length;
  152891. JOCTET b[APPN_DATA_LEN];
  152892. unsigned int i, numtoread;
  152893. INPUT_VARS(cinfo);
  152894. INPUT_2BYTES(cinfo, length, return FALSE);
  152895. length -= 2;
  152896. if (length >= APPN_DATA_LEN)
  152897. numtoread = APPN_DATA_LEN;
  152898. else if (length > 0)
  152899. numtoread = (unsigned int) length;
  152900. else
  152901. numtoread = 0;
  152902. for (i = 0; i < numtoread; i++)
  152903. INPUT_BYTE(cinfo, b[i], return FALSE);
  152904. length -= numtoread;
  152905. switch (cinfo->unread_marker) {
  152906. case M_APP0:
  152907. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152908. break;
  152909. case M_APP14:
  152910. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152911. break;
  152912. default:
  152913. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152914. break;
  152915. }
  152916. INPUT_SYNC(cinfo);
  152917. if (length > 0)
  152918. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152919. return TRUE;
  152920. }
  152921. #ifdef SAVE_MARKERS_SUPPORTED
  152922. METHODDEF(boolean)
  152923. save_marker (j_decompress_ptr cinfo)
  152924. {
  152925. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  152926. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  152927. unsigned int bytes_read, data_length;
  152928. JOCTET FAR * data;
  152929. INT32 length = 0;
  152930. INPUT_VARS(cinfo);
  152931. if (cur_marker == NULL) {
  152932. INPUT_2BYTES(cinfo, length, return FALSE);
  152933. length -= 2;
  152934. if (length >= 0) { /* watch out for bogus length word */
  152935. unsigned int limit;
  152936. if (cinfo->unread_marker == (int) M_COM)
  152937. limit = marker->length_limit_COM;
  152938. else
  152939. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  152940. if ((unsigned int) length < limit)
  152941. limit = (unsigned int) length;
  152942. cur_marker = (jpeg_saved_marker_ptr)
  152943. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152944. SIZEOF(struct jpeg_marker_struct) + limit);
  152945. cur_marker->next = NULL;
  152946. cur_marker->marker = (UINT8) cinfo->unread_marker;
  152947. cur_marker->original_length = (unsigned int) length;
  152948. cur_marker->data_length = limit;
  152949. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  152950. marker->cur_marker = cur_marker;
  152951. marker->bytes_read = 0;
  152952. bytes_read = 0;
  152953. data_length = limit;
  152954. } else {
  152955. bytes_read = data_length = 0;
  152956. data = NULL;
  152957. }
  152958. } else {
  152959. bytes_read = marker->bytes_read;
  152960. data_length = cur_marker->data_length;
  152961. data = cur_marker->data + bytes_read;
  152962. }
  152963. while (bytes_read < data_length) {
  152964. INPUT_SYNC(cinfo); /* move the restart point to here */
  152965. marker->bytes_read = bytes_read;
  152966. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  152967. while (bytes_read < data_length && bytes_in_buffer > 0) {
  152968. *data++ = *next_input_byte++;
  152969. bytes_in_buffer--;
  152970. bytes_read++;
  152971. }
  152972. }
  152973. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  152974. if (cinfo->marker_list == NULL) {
  152975. cinfo->marker_list = cur_marker;
  152976. } else {
  152977. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  152978. while (prev->next != NULL)
  152979. prev = prev->next;
  152980. prev->next = cur_marker;
  152981. }
  152982. data = cur_marker->data;
  152983. length = cur_marker->original_length - data_length;
  152984. }
  152985. marker->cur_marker = NULL;
  152986. switch (cinfo->unread_marker) {
  152987. case M_APP0:
  152988. examine_app0(cinfo, data, data_length, length);
  152989. break;
  152990. case M_APP14:
  152991. examine_app14(cinfo, data, data_length, length);
  152992. break;
  152993. default:
  152994. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  152995. (int) (data_length + length));
  152996. break;
  152997. }
  152998. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152999. if (length > 0)
  153000. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153001. return TRUE;
  153002. }
  153003. #endif /* SAVE_MARKERS_SUPPORTED */
  153004. METHODDEF(boolean)
  153005. skip_variable (j_decompress_ptr cinfo)
  153006. {
  153007. INT32 length;
  153008. INPUT_VARS(cinfo);
  153009. INPUT_2BYTES(cinfo, length, return FALSE);
  153010. length -= 2;
  153011. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153012. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153013. if (length > 0)
  153014. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153015. return TRUE;
  153016. }
  153017. LOCAL(boolean)
  153018. next_marker (j_decompress_ptr cinfo)
  153019. {
  153020. int c;
  153021. INPUT_VARS(cinfo);
  153022. for (;;) {
  153023. INPUT_BYTE(cinfo, c, return FALSE);
  153024. while (c != 0xFF) {
  153025. cinfo->marker->discarded_bytes++;
  153026. INPUT_SYNC(cinfo);
  153027. INPUT_BYTE(cinfo, c, return FALSE);
  153028. }
  153029. do {
  153030. INPUT_BYTE(cinfo, c, return FALSE);
  153031. } while (c == 0xFF);
  153032. if (c != 0)
  153033. break; /* found a valid marker, exit loop */
  153034. cinfo->marker->discarded_bytes += 2;
  153035. INPUT_SYNC(cinfo);
  153036. }
  153037. if (cinfo->marker->discarded_bytes != 0) {
  153038. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153039. cinfo->marker->discarded_bytes = 0;
  153040. }
  153041. cinfo->unread_marker = c;
  153042. INPUT_SYNC(cinfo);
  153043. return TRUE;
  153044. }
  153045. LOCAL(boolean)
  153046. first_marker (j_decompress_ptr cinfo)
  153047. {
  153048. int c, c2;
  153049. INPUT_VARS(cinfo);
  153050. INPUT_BYTE(cinfo, c, return FALSE);
  153051. INPUT_BYTE(cinfo, c2, return FALSE);
  153052. if (c != 0xFF || c2 != (int) M_SOI)
  153053. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153054. cinfo->unread_marker = c2;
  153055. INPUT_SYNC(cinfo);
  153056. return TRUE;
  153057. }
  153058. METHODDEF(int)
  153059. read_markers (j_decompress_ptr cinfo)
  153060. {
  153061. for (;;) {
  153062. if (cinfo->unread_marker == 0) {
  153063. if (! cinfo->marker->saw_SOI) {
  153064. if (! first_marker(cinfo))
  153065. return JPEG_SUSPENDED;
  153066. } else {
  153067. if (! next_marker(cinfo))
  153068. return JPEG_SUSPENDED;
  153069. }
  153070. }
  153071. switch (cinfo->unread_marker) {
  153072. case M_SOI:
  153073. if (! get_soi(cinfo))
  153074. return JPEG_SUSPENDED;
  153075. break;
  153076. case M_SOF0: /* Baseline */
  153077. case M_SOF1: /* Extended sequential, Huffman */
  153078. if (! get_sof(cinfo, FALSE, FALSE))
  153079. return JPEG_SUSPENDED;
  153080. break;
  153081. case M_SOF2: /* Progressive, Huffman */
  153082. if (! get_sof(cinfo, TRUE, FALSE))
  153083. return JPEG_SUSPENDED;
  153084. break;
  153085. case M_SOF9: /* Extended sequential, arithmetic */
  153086. if (! get_sof(cinfo, FALSE, TRUE))
  153087. return JPEG_SUSPENDED;
  153088. break;
  153089. case M_SOF10: /* Progressive, arithmetic */
  153090. if (! get_sof(cinfo, TRUE, TRUE))
  153091. return JPEG_SUSPENDED;
  153092. break;
  153093. case M_SOF3: /* Lossless, Huffman */
  153094. case M_SOF5: /* Differential sequential, Huffman */
  153095. case M_SOF6: /* Differential progressive, Huffman */
  153096. case M_SOF7: /* Differential lossless, Huffman */
  153097. case M_JPG: /* Reserved for JPEG extensions */
  153098. case M_SOF11: /* Lossless, arithmetic */
  153099. case M_SOF13: /* Differential sequential, arithmetic */
  153100. case M_SOF14: /* Differential progressive, arithmetic */
  153101. case M_SOF15: /* Differential lossless, arithmetic */
  153102. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153103. break;
  153104. case M_SOS:
  153105. if (! get_sos(cinfo))
  153106. return JPEG_SUSPENDED;
  153107. cinfo->unread_marker = 0; /* processed the marker */
  153108. return JPEG_REACHED_SOS;
  153109. case M_EOI:
  153110. TRACEMS(cinfo, 1, JTRC_EOI);
  153111. cinfo->unread_marker = 0; /* processed the marker */
  153112. return JPEG_REACHED_EOI;
  153113. case M_DAC:
  153114. if (! get_dac(cinfo))
  153115. return JPEG_SUSPENDED;
  153116. break;
  153117. case M_DHT:
  153118. if (! get_dht(cinfo))
  153119. return JPEG_SUSPENDED;
  153120. break;
  153121. case M_DQT:
  153122. if (! get_dqt(cinfo))
  153123. return JPEG_SUSPENDED;
  153124. break;
  153125. case M_DRI:
  153126. if (! get_dri(cinfo))
  153127. return JPEG_SUSPENDED;
  153128. break;
  153129. case M_APP0:
  153130. case M_APP1:
  153131. case M_APP2:
  153132. case M_APP3:
  153133. case M_APP4:
  153134. case M_APP5:
  153135. case M_APP6:
  153136. case M_APP7:
  153137. case M_APP8:
  153138. case M_APP9:
  153139. case M_APP10:
  153140. case M_APP11:
  153141. case M_APP12:
  153142. case M_APP13:
  153143. case M_APP14:
  153144. case M_APP15:
  153145. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153146. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153147. return JPEG_SUSPENDED;
  153148. break;
  153149. case M_COM:
  153150. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153151. return JPEG_SUSPENDED;
  153152. break;
  153153. case M_RST0: /* these are all parameterless */
  153154. case M_RST1:
  153155. case M_RST2:
  153156. case M_RST3:
  153157. case M_RST4:
  153158. case M_RST5:
  153159. case M_RST6:
  153160. case M_RST7:
  153161. case M_TEM:
  153162. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153163. break;
  153164. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153165. if (! skip_variable(cinfo))
  153166. return JPEG_SUSPENDED;
  153167. break;
  153168. default: /* must be DHP, EXP, JPGn, or RESn */
  153169. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153170. break;
  153171. }
  153172. cinfo->unread_marker = 0;
  153173. } /* end loop */
  153174. }
  153175. METHODDEF(boolean)
  153176. read_restart_marker (j_decompress_ptr cinfo)
  153177. {
  153178. if (cinfo->unread_marker == 0) {
  153179. if (! next_marker(cinfo))
  153180. return FALSE;
  153181. }
  153182. if (cinfo->unread_marker ==
  153183. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153184. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153185. cinfo->unread_marker = 0;
  153186. } else {
  153187. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153188. cinfo->marker->next_restart_num))
  153189. return FALSE;
  153190. }
  153191. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153192. return TRUE;
  153193. }
  153194. GLOBAL(boolean)
  153195. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153196. {
  153197. int marker = cinfo->unread_marker;
  153198. int action = 1;
  153199. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153200. for (;;) {
  153201. if (marker < (int) M_SOF0)
  153202. action = 2; /* invalid marker */
  153203. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153204. action = 3; /* valid non-restart marker */
  153205. else {
  153206. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153207. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153208. action = 3; /* one of the next two expected restarts */
  153209. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153210. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153211. action = 2; /* a prior restart, so advance */
  153212. else
  153213. action = 1; /* desired restart or too far away */
  153214. }
  153215. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153216. switch (action) {
  153217. case 1:
  153218. cinfo->unread_marker = 0;
  153219. return TRUE;
  153220. case 2:
  153221. if (! next_marker(cinfo))
  153222. return FALSE;
  153223. marker = cinfo->unread_marker;
  153224. break;
  153225. case 3:
  153226. return TRUE;
  153227. }
  153228. } /* end loop */
  153229. }
  153230. METHODDEF(void)
  153231. reset_marker_reader (j_decompress_ptr cinfo)
  153232. {
  153233. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153234. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153235. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153236. cinfo->unread_marker = 0; /* no pending marker */
  153237. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153238. marker->pub.saw_SOF = FALSE;
  153239. marker->pub.discarded_bytes = 0;
  153240. marker->cur_marker = NULL;
  153241. }
  153242. GLOBAL(void)
  153243. jinit_marker_reader (j_decompress_ptr cinfo)
  153244. {
  153245. my_marker_ptr2 marker;
  153246. int i;
  153247. marker = (my_marker_ptr2)
  153248. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153249. SIZEOF(my_marker_reader));
  153250. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153251. marker->pub.reset_marker_reader = reset_marker_reader;
  153252. marker->pub.read_markers = read_markers;
  153253. marker->pub.read_restart_marker = read_restart_marker;
  153254. marker->process_COM = skip_variable;
  153255. marker->length_limit_COM = 0;
  153256. for (i = 0; i < 16; i++) {
  153257. marker->process_APPn[i] = skip_variable;
  153258. marker->length_limit_APPn[i] = 0;
  153259. }
  153260. marker->process_APPn[0] = get_interesting_appn;
  153261. marker->process_APPn[14] = get_interesting_appn;
  153262. reset_marker_reader(cinfo);
  153263. }
  153264. #ifdef SAVE_MARKERS_SUPPORTED
  153265. GLOBAL(void)
  153266. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153267. unsigned int length_limit)
  153268. {
  153269. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153270. long maxlength;
  153271. jpeg_marker_parser_method processor;
  153272. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153273. if (((long) length_limit) > maxlength)
  153274. length_limit = (unsigned int) maxlength;
  153275. if (length_limit) {
  153276. processor = save_marker;
  153277. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153278. length_limit = APP0_DATA_LEN;
  153279. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153280. length_limit = APP14_DATA_LEN;
  153281. } else {
  153282. processor = skip_variable;
  153283. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153284. processor = get_interesting_appn;
  153285. }
  153286. if (marker_code == (int) M_COM) {
  153287. marker->process_COM = processor;
  153288. marker->length_limit_COM = length_limit;
  153289. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153290. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153291. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153292. } else
  153293. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153294. }
  153295. #endif /* SAVE_MARKERS_SUPPORTED */
  153296. GLOBAL(void)
  153297. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153298. jpeg_marker_parser_method routine)
  153299. {
  153300. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153301. if (marker_code == (int) M_COM)
  153302. marker->process_COM = routine;
  153303. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153304. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153305. else
  153306. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153307. }
  153308. /*** End of inlined file: jdmarker.c ***/
  153309. /*** Start of inlined file: jdmaster.c ***/
  153310. #define JPEG_INTERNALS
  153311. typedef struct {
  153312. struct jpeg_decomp_master pub; /* public fields */
  153313. int pass_number; /* # of passes completed */
  153314. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153315. struct jpeg_color_quantizer * quantizer_1pass;
  153316. struct jpeg_color_quantizer * quantizer_2pass;
  153317. } my_decomp_master;
  153318. typedef my_decomp_master * my_master_ptr6;
  153319. LOCAL(boolean)
  153320. use_merged_upsample (j_decompress_ptr cinfo)
  153321. {
  153322. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153323. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153324. return FALSE;
  153325. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153326. cinfo->out_color_space != JCS_RGB ||
  153327. cinfo->out_color_components != RGB_PIXELSIZE)
  153328. return FALSE;
  153329. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153330. cinfo->comp_info[1].h_samp_factor != 1 ||
  153331. cinfo->comp_info[2].h_samp_factor != 1 ||
  153332. cinfo->comp_info[0].v_samp_factor > 2 ||
  153333. cinfo->comp_info[1].v_samp_factor != 1 ||
  153334. cinfo->comp_info[2].v_samp_factor != 1)
  153335. return FALSE;
  153336. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153337. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153338. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153339. return FALSE;
  153340. return TRUE; /* by golly, it'll work... */
  153341. #else
  153342. return FALSE;
  153343. #endif
  153344. }
  153345. GLOBAL(void)
  153346. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153347. {
  153348. #ifdef IDCT_SCALING_SUPPORTED
  153349. int ci;
  153350. jpeg_component_info *compptr;
  153351. #endif
  153352. if (cinfo->global_state != DSTATE_READY)
  153353. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153354. #ifdef IDCT_SCALING_SUPPORTED
  153355. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153356. cinfo->output_width = (JDIMENSION)
  153357. jdiv_round_up((long) cinfo->image_width, 8L);
  153358. cinfo->output_height = (JDIMENSION)
  153359. jdiv_round_up((long) cinfo->image_height, 8L);
  153360. cinfo->min_DCT_scaled_size = 1;
  153361. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153362. cinfo->output_width = (JDIMENSION)
  153363. jdiv_round_up((long) cinfo->image_width, 4L);
  153364. cinfo->output_height = (JDIMENSION)
  153365. jdiv_round_up((long) cinfo->image_height, 4L);
  153366. cinfo->min_DCT_scaled_size = 2;
  153367. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153368. cinfo->output_width = (JDIMENSION)
  153369. jdiv_round_up((long) cinfo->image_width, 2L);
  153370. cinfo->output_height = (JDIMENSION)
  153371. jdiv_round_up((long) cinfo->image_height, 2L);
  153372. cinfo->min_DCT_scaled_size = 4;
  153373. } else {
  153374. cinfo->output_width = cinfo->image_width;
  153375. cinfo->output_height = cinfo->image_height;
  153376. cinfo->min_DCT_scaled_size = DCTSIZE;
  153377. }
  153378. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153379. ci++, compptr++) {
  153380. int ssize = cinfo->min_DCT_scaled_size;
  153381. while (ssize < DCTSIZE &&
  153382. (compptr->h_samp_factor * ssize * 2 <=
  153383. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153384. (compptr->v_samp_factor * ssize * 2 <=
  153385. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153386. ssize = ssize * 2;
  153387. }
  153388. compptr->DCT_scaled_size = ssize;
  153389. }
  153390. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153391. ci++, compptr++) {
  153392. compptr->downsampled_width = (JDIMENSION)
  153393. jdiv_round_up((long) cinfo->image_width *
  153394. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153395. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153396. compptr->downsampled_height = (JDIMENSION)
  153397. jdiv_round_up((long) cinfo->image_height *
  153398. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153399. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153400. }
  153401. #else /* !IDCT_SCALING_SUPPORTED */
  153402. cinfo->output_width = cinfo->image_width;
  153403. cinfo->output_height = cinfo->image_height;
  153404. #endif /* IDCT_SCALING_SUPPORTED */
  153405. switch (cinfo->out_color_space) {
  153406. case JCS_GRAYSCALE:
  153407. cinfo->out_color_components = 1;
  153408. break;
  153409. case JCS_RGB:
  153410. #if RGB_PIXELSIZE != 3
  153411. cinfo->out_color_components = RGB_PIXELSIZE;
  153412. break;
  153413. #endif /* else share code with YCbCr */
  153414. case JCS_YCbCr:
  153415. cinfo->out_color_components = 3;
  153416. break;
  153417. case JCS_CMYK:
  153418. case JCS_YCCK:
  153419. cinfo->out_color_components = 4;
  153420. break;
  153421. default: /* else must be same colorspace as in file */
  153422. cinfo->out_color_components = cinfo->num_components;
  153423. break;
  153424. }
  153425. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153426. cinfo->out_color_components);
  153427. if (use_merged_upsample(cinfo))
  153428. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153429. else
  153430. cinfo->rec_outbuf_height = 1;
  153431. }
  153432. LOCAL(void)
  153433. prepare_range_limit_table (j_decompress_ptr cinfo)
  153434. {
  153435. JSAMPLE * table;
  153436. int i;
  153437. table = (JSAMPLE *)
  153438. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153439. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153440. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153441. cinfo->sample_range_limit = table;
  153442. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153443. for (i = 0; i <= MAXJSAMPLE; i++)
  153444. table[i] = (JSAMPLE) i;
  153445. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153446. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153447. table[i] = MAXJSAMPLE;
  153448. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153449. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153450. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153451. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153452. }
  153453. LOCAL(void)
  153454. master_selection (j_decompress_ptr cinfo)
  153455. {
  153456. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153457. boolean use_c_buffer;
  153458. long samplesperrow;
  153459. JDIMENSION jd_samplesperrow;
  153460. jpeg_calc_output_dimensions(cinfo);
  153461. prepare_range_limit_table(cinfo);
  153462. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153463. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153464. if ((long) jd_samplesperrow != samplesperrow)
  153465. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153466. master->pass_number = 0;
  153467. master->using_merged_upsample = use_merged_upsample(cinfo);
  153468. master->quantizer_1pass = NULL;
  153469. master->quantizer_2pass = NULL;
  153470. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153471. cinfo->enable_1pass_quant = FALSE;
  153472. cinfo->enable_external_quant = FALSE;
  153473. cinfo->enable_2pass_quant = FALSE;
  153474. }
  153475. if (cinfo->quantize_colors) {
  153476. if (cinfo->raw_data_out)
  153477. ERREXIT(cinfo, JERR_NOTIMPL);
  153478. if (cinfo->out_color_components != 3) {
  153479. cinfo->enable_1pass_quant = TRUE;
  153480. cinfo->enable_external_quant = FALSE;
  153481. cinfo->enable_2pass_quant = FALSE;
  153482. cinfo->colormap = NULL;
  153483. } else if (cinfo->colormap != NULL) {
  153484. cinfo->enable_external_quant = TRUE;
  153485. } else if (cinfo->two_pass_quantize) {
  153486. cinfo->enable_2pass_quant = TRUE;
  153487. } else {
  153488. cinfo->enable_1pass_quant = TRUE;
  153489. }
  153490. if (cinfo->enable_1pass_quant) {
  153491. #ifdef QUANT_1PASS_SUPPORTED
  153492. jinit_1pass_quantizer(cinfo);
  153493. master->quantizer_1pass = cinfo->cquantize;
  153494. #else
  153495. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153496. #endif
  153497. }
  153498. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153499. #ifdef QUANT_2PASS_SUPPORTED
  153500. jinit_2pass_quantizer(cinfo);
  153501. master->quantizer_2pass = cinfo->cquantize;
  153502. #else
  153503. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153504. #endif
  153505. }
  153506. }
  153507. if (! cinfo->raw_data_out) {
  153508. if (master->using_merged_upsample) {
  153509. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153510. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153511. #else
  153512. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153513. #endif
  153514. } else {
  153515. jinit_color_deconverter(cinfo);
  153516. jinit_upsampler(cinfo);
  153517. }
  153518. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153519. }
  153520. jinit_inverse_dct(cinfo);
  153521. if (cinfo->arith_code) {
  153522. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153523. } else {
  153524. if (cinfo->progressive_mode) {
  153525. #ifdef D_PROGRESSIVE_SUPPORTED
  153526. jinit_phuff_decoder(cinfo);
  153527. #else
  153528. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153529. #endif
  153530. } else
  153531. jinit_huff_decoder(cinfo);
  153532. }
  153533. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153534. jinit_d_coef_controller(cinfo, use_c_buffer);
  153535. if (! cinfo->raw_data_out)
  153536. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153537. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153538. (*cinfo->inputctl->start_input_pass) (cinfo);
  153539. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153540. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153541. cinfo->inputctl->has_multiple_scans) {
  153542. int nscans;
  153543. if (cinfo->progressive_mode) {
  153544. nscans = 2 + 3 * cinfo->num_components;
  153545. } else {
  153546. nscans = cinfo->num_components;
  153547. }
  153548. cinfo->progress->pass_counter = 0L;
  153549. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153550. cinfo->progress->completed_passes = 0;
  153551. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153552. master->pass_number++;
  153553. }
  153554. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153555. }
  153556. METHODDEF(void)
  153557. prepare_for_output_pass (j_decompress_ptr cinfo)
  153558. {
  153559. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153560. if (master->pub.is_dummy_pass) {
  153561. #ifdef QUANT_2PASS_SUPPORTED
  153562. master->pub.is_dummy_pass = FALSE;
  153563. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153564. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153565. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153566. #else
  153567. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153568. #endif /* QUANT_2PASS_SUPPORTED */
  153569. } else {
  153570. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153571. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153572. cinfo->cquantize = master->quantizer_2pass;
  153573. master->pub.is_dummy_pass = TRUE;
  153574. } else if (cinfo->enable_1pass_quant) {
  153575. cinfo->cquantize = master->quantizer_1pass;
  153576. } else {
  153577. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153578. }
  153579. }
  153580. (*cinfo->idct->start_pass) (cinfo);
  153581. (*cinfo->coef->start_output_pass) (cinfo);
  153582. if (! cinfo->raw_data_out) {
  153583. if (! master->using_merged_upsample)
  153584. (*cinfo->cconvert->start_pass) (cinfo);
  153585. (*cinfo->upsample->start_pass) (cinfo);
  153586. if (cinfo->quantize_colors)
  153587. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153588. (*cinfo->post->start_pass) (cinfo,
  153589. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153590. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153591. }
  153592. }
  153593. if (cinfo->progress != NULL) {
  153594. cinfo->progress->completed_passes = master->pass_number;
  153595. cinfo->progress->total_passes = master->pass_number +
  153596. (master->pub.is_dummy_pass ? 2 : 1);
  153597. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153598. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153599. }
  153600. }
  153601. }
  153602. METHODDEF(void)
  153603. finish_output_pass (j_decompress_ptr cinfo)
  153604. {
  153605. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153606. if (cinfo->quantize_colors)
  153607. (*cinfo->cquantize->finish_pass) (cinfo);
  153608. master->pass_number++;
  153609. }
  153610. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153611. GLOBAL(void)
  153612. jpeg_new_colormap (j_decompress_ptr cinfo)
  153613. {
  153614. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153615. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153616. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153617. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153618. cinfo->colormap != NULL) {
  153619. cinfo->cquantize = master->quantizer_2pass;
  153620. (*cinfo->cquantize->new_color_map) (cinfo);
  153621. master->pub.is_dummy_pass = FALSE; /* just in case */
  153622. } else
  153623. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153624. }
  153625. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153626. GLOBAL(void)
  153627. jinit_master_decompress (j_decompress_ptr cinfo)
  153628. {
  153629. my_master_ptr6 master;
  153630. master = (my_master_ptr6)
  153631. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153632. SIZEOF(my_decomp_master));
  153633. cinfo->master = (struct jpeg_decomp_master *) master;
  153634. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153635. master->pub.finish_output_pass = finish_output_pass;
  153636. master->pub.is_dummy_pass = FALSE;
  153637. master_selection(cinfo);
  153638. }
  153639. /*** End of inlined file: jdmaster.c ***/
  153640. #undef FIX
  153641. /*** Start of inlined file: jdmerge.c ***/
  153642. #define JPEG_INTERNALS
  153643. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153644. typedef struct {
  153645. struct jpeg_upsampler pub; /* public fields */
  153646. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153647. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153648. JSAMPARRAY output_buf));
  153649. int * Cr_r_tab; /* => table for Cr to R conversion */
  153650. int * Cb_b_tab; /* => table for Cb to B conversion */
  153651. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153652. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153653. JSAMPROW spare_row;
  153654. boolean spare_full; /* T if spare buffer is occupied */
  153655. JDIMENSION out_row_width; /* samples per output row */
  153656. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153657. } my_upsampler;
  153658. typedef my_upsampler * my_upsample_ptr;
  153659. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153660. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153661. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153662. LOCAL(void)
  153663. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153664. {
  153665. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153666. int i;
  153667. INT32 x;
  153668. SHIFT_TEMPS
  153669. upsample->Cr_r_tab = (int *)
  153670. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153671. (MAXJSAMPLE+1) * SIZEOF(int));
  153672. upsample->Cb_b_tab = (int *)
  153673. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153674. (MAXJSAMPLE+1) * SIZEOF(int));
  153675. upsample->Cr_g_tab = (INT32 *)
  153676. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153677. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153678. upsample->Cb_g_tab = (INT32 *)
  153679. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153680. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153681. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153682. upsample->Cr_r_tab[i] = (int)
  153683. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153684. upsample->Cb_b_tab[i] = (int)
  153685. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153686. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153687. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153688. }
  153689. }
  153690. METHODDEF(void)
  153691. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153692. {
  153693. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153694. upsample->spare_full = FALSE;
  153695. upsample->rows_to_go = cinfo->output_height;
  153696. }
  153697. METHODDEF(void)
  153698. merged_2v_upsample (j_decompress_ptr cinfo,
  153699. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153700. JDIMENSION in_row_groups_avail,
  153701. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153702. JDIMENSION out_rows_avail)
  153703. {
  153704. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153705. JSAMPROW work_ptrs[2];
  153706. JDIMENSION num_rows; /* number of rows returned to caller */
  153707. if (upsample->spare_full) {
  153708. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153709. 1, upsample->out_row_width);
  153710. num_rows = 1;
  153711. upsample->spare_full = FALSE;
  153712. } else {
  153713. num_rows = 2;
  153714. if (num_rows > upsample->rows_to_go)
  153715. num_rows = upsample->rows_to_go;
  153716. out_rows_avail -= *out_row_ctr;
  153717. if (num_rows > out_rows_avail)
  153718. num_rows = out_rows_avail;
  153719. work_ptrs[0] = output_buf[*out_row_ctr];
  153720. if (num_rows > 1) {
  153721. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153722. } else {
  153723. work_ptrs[1] = upsample->spare_row;
  153724. upsample->spare_full = TRUE;
  153725. }
  153726. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153727. }
  153728. *out_row_ctr += num_rows;
  153729. upsample->rows_to_go -= num_rows;
  153730. if (! upsample->spare_full)
  153731. (*in_row_group_ctr)++;
  153732. }
  153733. METHODDEF(void)
  153734. merged_1v_upsample (j_decompress_ptr cinfo,
  153735. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153736. JDIMENSION in_row_groups_avail,
  153737. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153738. JDIMENSION out_rows_avail)
  153739. {
  153740. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153741. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153742. output_buf + *out_row_ctr);
  153743. (*out_row_ctr)++;
  153744. (*in_row_group_ctr)++;
  153745. }
  153746. METHODDEF(void)
  153747. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153748. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153749. JSAMPARRAY output_buf)
  153750. {
  153751. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153752. register int y, cred, cgreen, cblue;
  153753. int cb, cr;
  153754. register JSAMPROW outptr;
  153755. JSAMPROW inptr0, inptr1, inptr2;
  153756. JDIMENSION col;
  153757. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153758. int * Crrtab = upsample->Cr_r_tab;
  153759. int * Cbbtab = upsample->Cb_b_tab;
  153760. INT32 * Crgtab = upsample->Cr_g_tab;
  153761. INT32 * Cbgtab = upsample->Cb_g_tab;
  153762. SHIFT_TEMPS
  153763. inptr0 = input_buf[0][in_row_group_ctr];
  153764. inptr1 = input_buf[1][in_row_group_ctr];
  153765. inptr2 = input_buf[2][in_row_group_ctr];
  153766. outptr = output_buf[0];
  153767. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153768. cb = GETJSAMPLE(*inptr1++);
  153769. cr = GETJSAMPLE(*inptr2++);
  153770. cred = Crrtab[cr];
  153771. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153772. cblue = Cbbtab[cb];
  153773. y = GETJSAMPLE(*inptr0++);
  153774. outptr[RGB_RED] = range_limit[y + cred];
  153775. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153776. outptr[RGB_BLUE] = range_limit[y + cblue];
  153777. outptr += RGB_PIXELSIZE;
  153778. y = GETJSAMPLE(*inptr0++);
  153779. outptr[RGB_RED] = range_limit[y + cred];
  153780. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153781. outptr[RGB_BLUE] = range_limit[y + cblue];
  153782. outptr += RGB_PIXELSIZE;
  153783. }
  153784. if (cinfo->output_width & 1) {
  153785. cb = GETJSAMPLE(*inptr1);
  153786. cr = GETJSAMPLE(*inptr2);
  153787. cred = Crrtab[cr];
  153788. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153789. cblue = Cbbtab[cb];
  153790. y = GETJSAMPLE(*inptr0);
  153791. outptr[RGB_RED] = range_limit[y + cred];
  153792. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153793. outptr[RGB_BLUE] = range_limit[y + cblue];
  153794. }
  153795. }
  153796. METHODDEF(void)
  153797. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153798. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153799. JSAMPARRAY output_buf)
  153800. {
  153801. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153802. register int y, cred, cgreen, cblue;
  153803. int cb, cr;
  153804. register JSAMPROW outptr0, outptr1;
  153805. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153806. JDIMENSION col;
  153807. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153808. int * Crrtab = upsample->Cr_r_tab;
  153809. int * Cbbtab = upsample->Cb_b_tab;
  153810. INT32 * Crgtab = upsample->Cr_g_tab;
  153811. INT32 * Cbgtab = upsample->Cb_g_tab;
  153812. SHIFT_TEMPS
  153813. inptr00 = input_buf[0][in_row_group_ctr*2];
  153814. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153815. inptr1 = input_buf[1][in_row_group_ctr];
  153816. inptr2 = input_buf[2][in_row_group_ctr];
  153817. outptr0 = output_buf[0];
  153818. outptr1 = output_buf[1];
  153819. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153820. cb = GETJSAMPLE(*inptr1++);
  153821. cr = GETJSAMPLE(*inptr2++);
  153822. cred = Crrtab[cr];
  153823. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153824. cblue = Cbbtab[cb];
  153825. y = GETJSAMPLE(*inptr00++);
  153826. outptr0[RGB_RED] = range_limit[y + cred];
  153827. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153828. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153829. outptr0 += RGB_PIXELSIZE;
  153830. y = GETJSAMPLE(*inptr00++);
  153831. outptr0[RGB_RED] = range_limit[y + cred];
  153832. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153833. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153834. outptr0 += RGB_PIXELSIZE;
  153835. y = GETJSAMPLE(*inptr01++);
  153836. outptr1[RGB_RED] = range_limit[y + cred];
  153837. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153838. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153839. outptr1 += RGB_PIXELSIZE;
  153840. y = GETJSAMPLE(*inptr01++);
  153841. outptr1[RGB_RED] = range_limit[y + cred];
  153842. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153843. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153844. outptr1 += RGB_PIXELSIZE;
  153845. }
  153846. if (cinfo->output_width & 1) {
  153847. cb = GETJSAMPLE(*inptr1);
  153848. cr = GETJSAMPLE(*inptr2);
  153849. cred = Crrtab[cr];
  153850. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153851. cblue = Cbbtab[cb];
  153852. y = GETJSAMPLE(*inptr00);
  153853. outptr0[RGB_RED] = range_limit[y + cred];
  153854. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153855. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153856. y = GETJSAMPLE(*inptr01);
  153857. outptr1[RGB_RED] = range_limit[y + cred];
  153858. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153859. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153860. }
  153861. }
  153862. GLOBAL(void)
  153863. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153864. {
  153865. my_upsample_ptr upsample;
  153866. upsample = (my_upsample_ptr)
  153867. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153868. SIZEOF(my_upsampler));
  153869. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153870. upsample->pub.start_pass = start_pass_merged_upsample;
  153871. upsample->pub.need_context_rows = FALSE;
  153872. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153873. if (cinfo->max_v_samp_factor == 2) {
  153874. upsample->pub.upsample = merged_2v_upsample;
  153875. upsample->upmethod = h2v2_merged_upsample;
  153876. upsample->spare_row = (JSAMPROW)
  153877. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153878. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153879. } else {
  153880. upsample->pub.upsample = merged_1v_upsample;
  153881. upsample->upmethod = h2v1_merged_upsample;
  153882. upsample->spare_row = NULL;
  153883. }
  153884. build_ycc_rgb_table2(cinfo);
  153885. }
  153886. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153887. /*** End of inlined file: jdmerge.c ***/
  153888. #undef ASSIGN_STATE
  153889. /*** Start of inlined file: jdphuff.c ***/
  153890. #define JPEG_INTERNALS
  153891. #ifdef D_PROGRESSIVE_SUPPORTED
  153892. typedef struct {
  153893. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153894. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153895. } savable_state3;
  153896. #ifndef NO_STRUCT_ASSIGN
  153897. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153898. #else
  153899. #if MAX_COMPS_IN_SCAN == 4
  153900. #define ASSIGN_STATE(dest,src) \
  153901. ((dest).EOBRUN = (src).EOBRUN, \
  153902. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153903. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153904. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153905. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153906. #endif
  153907. #endif
  153908. typedef struct {
  153909. struct jpeg_entropy_decoder pub; /* public fields */
  153910. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153911. savable_state3 saved; /* Other state at start of MCU */
  153912. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153913. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153914. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153915. } phuff_entropy_decoder;
  153916. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  153917. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  153918. JBLOCKROW *MCU_data));
  153919. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  153920. JBLOCKROW *MCU_data));
  153921. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  153922. JBLOCKROW *MCU_data));
  153923. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  153924. JBLOCKROW *MCU_data));
  153925. METHODDEF(void)
  153926. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  153927. {
  153928. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153929. boolean is_DC_band, bad;
  153930. int ci, coefi, tbl;
  153931. int *coef_bit_ptr;
  153932. jpeg_component_info * compptr;
  153933. is_DC_band = (cinfo->Ss == 0);
  153934. bad = FALSE;
  153935. if (is_DC_band) {
  153936. if (cinfo->Se != 0)
  153937. bad = TRUE;
  153938. } else {
  153939. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  153940. bad = TRUE;
  153941. if (cinfo->comps_in_scan != 1)
  153942. bad = TRUE;
  153943. }
  153944. if (cinfo->Ah != 0) {
  153945. if (cinfo->Al != cinfo->Ah-1)
  153946. bad = TRUE;
  153947. }
  153948. if (cinfo->Al > 13) /* need not check for < 0 */
  153949. bad = TRUE;
  153950. if (bad)
  153951. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  153952. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  153953. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153954. int cindex = cinfo->cur_comp_info[ci]->component_index;
  153955. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  153956. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  153957. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  153958. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  153959. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  153960. if (cinfo->Ah != expected)
  153961. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  153962. coef_bit_ptr[coefi] = cinfo->Al;
  153963. }
  153964. }
  153965. if (cinfo->Ah == 0) {
  153966. if (is_DC_band)
  153967. entropy->pub.decode_mcu = decode_mcu_DC_first;
  153968. else
  153969. entropy->pub.decode_mcu = decode_mcu_AC_first;
  153970. } else {
  153971. if (is_DC_band)
  153972. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  153973. else
  153974. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  153975. }
  153976. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153977. compptr = cinfo->cur_comp_info[ci];
  153978. if (is_DC_band) {
  153979. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  153980. tbl = compptr->dc_tbl_no;
  153981. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  153982. & entropy->derived_tbls[tbl]);
  153983. }
  153984. } else {
  153985. tbl = compptr->ac_tbl_no;
  153986. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  153987. & entropy->derived_tbls[tbl]);
  153988. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  153989. }
  153990. entropy->saved.last_dc_val[ci] = 0;
  153991. }
  153992. entropy->bitstate.bits_left = 0;
  153993. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  153994. entropy->pub.insufficient_data = FALSE;
  153995. entropy->saved.EOBRUN = 0;
  153996. entropy->restarts_to_go = cinfo->restart_interval;
  153997. }
  153998. LOCAL(boolean)
  153999. process_restartp (j_decompress_ptr cinfo)
  154000. {
  154001. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154002. int ci;
  154003. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154004. entropy->bitstate.bits_left = 0;
  154005. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154006. return FALSE;
  154007. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154008. entropy->saved.last_dc_val[ci] = 0;
  154009. entropy->saved.EOBRUN = 0;
  154010. entropy->restarts_to_go = cinfo->restart_interval;
  154011. if (cinfo->unread_marker == 0)
  154012. entropy->pub.insufficient_data = FALSE;
  154013. return TRUE;
  154014. }
  154015. METHODDEF(boolean)
  154016. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154017. {
  154018. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154019. int Al = cinfo->Al;
  154020. register int s, r;
  154021. int blkn, ci;
  154022. JBLOCKROW block;
  154023. BITREAD_STATE_VARS;
  154024. savable_state3 state;
  154025. d_derived_tbl * tbl;
  154026. jpeg_component_info * compptr;
  154027. if (cinfo->restart_interval) {
  154028. if (entropy->restarts_to_go == 0)
  154029. if (! process_restartp(cinfo))
  154030. return FALSE;
  154031. }
  154032. if (! entropy->pub.insufficient_data) {
  154033. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154034. ASSIGN_STATE(state, entropy->saved);
  154035. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154036. block = MCU_data[blkn];
  154037. ci = cinfo->MCU_membership[blkn];
  154038. compptr = cinfo->cur_comp_info[ci];
  154039. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154040. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154041. if (s) {
  154042. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154043. r = GET_BITS(s);
  154044. s = HUFF_EXTEND(r, s);
  154045. }
  154046. s += state.last_dc_val[ci];
  154047. state.last_dc_val[ci] = s;
  154048. (*block)[0] = (JCOEF) (s << Al);
  154049. }
  154050. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154051. ASSIGN_STATE(entropy->saved, state);
  154052. }
  154053. entropy->restarts_to_go--;
  154054. return TRUE;
  154055. }
  154056. METHODDEF(boolean)
  154057. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154058. {
  154059. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154060. int Se = cinfo->Se;
  154061. int Al = cinfo->Al;
  154062. register int s, k, r;
  154063. unsigned int EOBRUN;
  154064. JBLOCKROW block;
  154065. BITREAD_STATE_VARS;
  154066. d_derived_tbl * tbl;
  154067. if (cinfo->restart_interval) {
  154068. if (entropy->restarts_to_go == 0)
  154069. if (! process_restartp(cinfo))
  154070. return FALSE;
  154071. }
  154072. if (! entropy->pub.insufficient_data) {
  154073. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154074. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154075. EOBRUN--; /* ...process it now (we do nothing) */
  154076. else {
  154077. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154078. block = MCU_data[0];
  154079. tbl = entropy->ac_derived_tbl;
  154080. for (k = cinfo->Ss; k <= Se; k++) {
  154081. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154082. r = s >> 4;
  154083. s &= 15;
  154084. if (s) {
  154085. k += r;
  154086. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154087. r = GET_BITS(s);
  154088. s = HUFF_EXTEND(r, s);
  154089. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154090. } else {
  154091. if (r == 15) { /* ZRL */
  154092. k += 15; /* skip 15 zeroes in band */
  154093. } else { /* EOBr, run length is 2^r + appended bits */
  154094. EOBRUN = 1 << r;
  154095. if (r) { /* EOBr, r > 0 */
  154096. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154097. r = GET_BITS(r);
  154098. EOBRUN += r;
  154099. }
  154100. EOBRUN--; /* this band is processed at this moment */
  154101. break; /* force end-of-band */
  154102. }
  154103. }
  154104. }
  154105. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154106. }
  154107. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154108. }
  154109. entropy->restarts_to_go--;
  154110. return TRUE;
  154111. }
  154112. METHODDEF(boolean)
  154113. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154114. {
  154115. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154116. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154117. int blkn;
  154118. JBLOCKROW block;
  154119. BITREAD_STATE_VARS;
  154120. if (cinfo->restart_interval) {
  154121. if (entropy->restarts_to_go == 0)
  154122. if (! process_restartp(cinfo))
  154123. return FALSE;
  154124. }
  154125. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154126. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154127. block = MCU_data[blkn];
  154128. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154129. if (GET_BITS(1))
  154130. (*block)[0] |= p1;
  154131. }
  154132. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154133. entropy->restarts_to_go--;
  154134. return TRUE;
  154135. }
  154136. METHODDEF(boolean)
  154137. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154138. {
  154139. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154140. int Se = cinfo->Se;
  154141. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154142. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154143. register int s, k, r;
  154144. unsigned int EOBRUN;
  154145. JBLOCKROW block;
  154146. JCOEFPTR thiscoef;
  154147. BITREAD_STATE_VARS;
  154148. d_derived_tbl * tbl;
  154149. int num_newnz;
  154150. int newnz_pos[DCTSIZE2];
  154151. if (cinfo->restart_interval) {
  154152. if (entropy->restarts_to_go == 0)
  154153. if (! process_restartp(cinfo))
  154154. return FALSE;
  154155. }
  154156. if (! entropy->pub.insufficient_data) {
  154157. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154158. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154159. block = MCU_data[0];
  154160. tbl = entropy->ac_derived_tbl;
  154161. num_newnz = 0;
  154162. k = cinfo->Ss;
  154163. if (EOBRUN == 0) {
  154164. for (; k <= Se; k++) {
  154165. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154166. r = s >> 4;
  154167. s &= 15;
  154168. if (s) {
  154169. if (s != 1) /* size of new coef should always be 1 */
  154170. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154171. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154172. if (GET_BITS(1))
  154173. s = p1; /* newly nonzero coef is positive */
  154174. else
  154175. s = m1; /* newly nonzero coef is negative */
  154176. } else {
  154177. if (r != 15) {
  154178. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154179. if (r) {
  154180. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154181. r = GET_BITS(r);
  154182. EOBRUN += r;
  154183. }
  154184. break; /* rest of block is handled by EOB logic */
  154185. }
  154186. }
  154187. do {
  154188. thiscoef = *block + jpeg_natural_order[k];
  154189. if (*thiscoef != 0) {
  154190. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154191. if (GET_BITS(1)) {
  154192. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154193. if (*thiscoef >= 0)
  154194. *thiscoef += p1;
  154195. else
  154196. *thiscoef += m1;
  154197. }
  154198. }
  154199. } else {
  154200. if (--r < 0)
  154201. break; /* reached target zero coefficient */
  154202. }
  154203. k++;
  154204. } while (k <= Se);
  154205. if (s) {
  154206. int pos = jpeg_natural_order[k];
  154207. (*block)[pos] = (JCOEF) s;
  154208. newnz_pos[num_newnz++] = pos;
  154209. }
  154210. }
  154211. }
  154212. if (EOBRUN > 0) {
  154213. for (; k <= Se; k++) {
  154214. thiscoef = *block + jpeg_natural_order[k];
  154215. if (*thiscoef != 0) {
  154216. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154217. if (GET_BITS(1)) {
  154218. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154219. if (*thiscoef >= 0)
  154220. *thiscoef += p1;
  154221. else
  154222. *thiscoef += m1;
  154223. }
  154224. }
  154225. }
  154226. }
  154227. EOBRUN--;
  154228. }
  154229. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154230. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154231. }
  154232. entropy->restarts_to_go--;
  154233. return TRUE;
  154234. undoit:
  154235. while (num_newnz > 0)
  154236. (*block)[newnz_pos[--num_newnz]] = 0;
  154237. return FALSE;
  154238. }
  154239. GLOBAL(void)
  154240. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154241. {
  154242. phuff_entropy_ptr2 entropy;
  154243. int *coef_bit_ptr;
  154244. int ci, i;
  154245. entropy = (phuff_entropy_ptr2)
  154246. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154247. SIZEOF(phuff_entropy_decoder));
  154248. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154249. entropy->pub.start_pass = start_pass_phuff_decoder;
  154250. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154251. entropy->derived_tbls[i] = NULL;
  154252. }
  154253. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154254. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154255. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154256. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154257. for (ci = 0; ci < cinfo->num_components; ci++)
  154258. for (i = 0; i < DCTSIZE2; i++)
  154259. *coef_bit_ptr++ = -1;
  154260. }
  154261. #endif /* D_PROGRESSIVE_SUPPORTED */
  154262. /*** End of inlined file: jdphuff.c ***/
  154263. /*** Start of inlined file: jdpostct.c ***/
  154264. #define JPEG_INTERNALS
  154265. typedef struct {
  154266. struct jpeg_d_post_controller pub; /* public fields */
  154267. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154268. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154269. JDIMENSION strip_height; /* buffer size in rows */
  154270. JDIMENSION starting_row; /* row # of first row in current strip */
  154271. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154272. } my_post_controller;
  154273. typedef my_post_controller * my_post_ptr;
  154274. METHODDEF(void) post_process_1pass
  154275. JPP((j_decompress_ptr cinfo,
  154276. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154277. JDIMENSION in_row_groups_avail,
  154278. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154279. JDIMENSION out_rows_avail));
  154280. #ifdef QUANT_2PASS_SUPPORTED
  154281. METHODDEF(void) post_process_prepass
  154282. JPP((j_decompress_ptr cinfo,
  154283. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154284. JDIMENSION in_row_groups_avail,
  154285. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154286. JDIMENSION out_rows_avail));
  154287. METHODDEF(void) post_process_2pass
  154288. JPP((j_decompress_ptr cinfo,
  154289. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154290. JDIMENSION in_row_groups_avail,
  154291. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154292. JDIMENSION out_rows_avail));
  154293. #endif
  154294. METHODDEF(void)
  154295. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154296. {
  154297. my_post_ptr post = (my_post_ptr) cinfo->post;
  154298. switch (pass_mode) {
  154299. case JBUF_PASS_THRU:
  154300. if (cinfo->quantize_colors) {
  154301. post->pub.post_process_data = post_process_1pass;
  154302. if (post->buffer == NULL) {
  154303. post->buffer = (*cinfo->mem->access_virt_sarray)
  154304. ((j_common_ptr) cinfo, post->whole_image,
  154305. (JDIMENSION) 0, post->strip_height, TRUE);
  154306. }
  154307. } else {
  154308. post->pub.post_process_data = cinfo->upsample->upsample;
  154309. }
  154310. break;
  154311. #ifdef QUANT_2PASS_SUPPORTED
  154312. case JBUF_SAVE_AND_PASS:
  154313. if (post->whole_image == NULL)
  154314. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154315. post->pub.post_process_data = post_process_prepass;
  154316. break;
  154317. case JBUF_CRANK_DEST:
  154318. if (post->whole_image == NULL)
  154319. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154320. post->pub.post_process_data = post_process_2pass;
  154321. break;
  154322. #endif /* QUANT_2PASS_SUPPORTED */
  154323. default:
  154324. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154325. break;
  154326. }
  154327. post->starting_row = post->next_row = 0;
  154328. }
  154329. METHODDEF(void)
  154330. post_process_1pass (j_decompress_ptr cinfo,
  154331. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154332. JDIMENSION in_row_groups_avail,
  154333. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154334. JDIMENSION out_rows_avail)
  154335. {
  154336. my_post_ptr post = (my_post_ptr) cinfo->post;
  154337. JDIMENSION num_rows, max_rows;
  154338. max_rows = out_rows_avail - *out_row_ctr;
  154339. if (max_rows > post->strip_height)
  154340. max_rows = post->strip_height;
  154341. num_rows = 0;
  154342. (*cinfo->upsample->upsample) (cinfo,
  154343. input_buf, in_row_group_ctr, in_row_groups_avail,
  154344. post->buffer, &num_rows, max_rows);
  154345. (*cinfo->cquantize->color_quantize) (cinfo,
  154346. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154347. *out_row_ctr += num_rows;
  154348. }
  154349. #ifdef QUANT_2PASS_SUPPORTED
  154350. METHODDEF(void)
  154351. post_process_prepass (j_decompress_ptr cinfo,
  154352. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154353. JDIMENSION in_row_groups_avail,
  154354. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154355. JDIMENSION out_rows_avail)
  154356. {
  154357. my_post_ptr post = (my_post_ptr) cinfo->post;
  154358. JDIMENSION old_next_row, num_rows;
  154359. if (post->next_row == 0) {
  154360. post->buffer = (*cinfo->mem->access_virt_sarray)
  154361. ((j_common_ptr) cinfo, post->whole_image,
  154362. post->starting_row, post->strip_height, TRUE);
  154363. }
  154364. old_next_row = post->next_row;
  154365. (*cinfo->upsample->upsample) (cinfo,
  154366. input_buf, in_row_group_ctr, in_row_groups_avail,
  154367. post->buffer, &post->next_row, post->strip_height);
  154368. if (post->next_row > old_next_row) {
  154369. num_rows = post->next_row - old_next_row;
  154370. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154371. (JSAMPARRAY) NULL, (int) num_rows);
  154372. *out_row_ctr += num_rows;
  154373. }
  154374. if (post->next_row >= post->strip_height) {
  154375. post->starting_row += post->strip_height;
  154376. post->next_row = 0;
  154377. }
  154378. }
  154379. METHODDEF(void)
  154380. post_process_2pass (j_decompress_ptr cinfo,
  154381. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154382. JDIMENSION in_row_groups_avail,
  154383. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154384. JDIMENSION out_rows_avail)
  154385. {
  154386. my_post_ptr post = (my_post_ptr) cinfo->post;
  154387. JDIMENSION num_rows, max_rows;
  154388. if (post->next_row == 0) {
  154389. post->buffer = (*cinfo->mem->access_virt_sarray)
  154390. ((j_common_ptr) cinfo, post->whole_image,
  154391. post->starting_row, post->strip_height, FALSE);
  154392. }
  154393. num_rows = post->strip_height - post->next_row; /* available in strip */
  154394. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154395. if (num_rows > max_rows)
  154396. num_rows = max_rows;
  154397. max_rows = cinfo->output_height - post->starting_row;
  154398. if (num_rows > max_rows)
  154399. num_rows = max_rows;
  154400. (*cinfo->cquantize->color_quantize) (cinfo,
  154401. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154402. (int) num_rows);
  154403. *out_row_ctr += num_rows;
  154404. post->next_row += num_rows;
  154405. if (post->next_row >= post->strip_height) {
  154406. post->starting_row += post->strip_height;
  154407. post->next_row = 0;
  154408. }
  154409. }
  154410. #endif /* QUANT_2PASS_SUPPORTED */
  154411. GLOBAL(void)
  154412. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154413. {
  154414. my_post_ptr post;
  154415. post = (my_post_ptr)
  154416. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154417. SIZEOF(my_post_controller));
  154418. cinfo->post = (struct jpeg_d_post_controller *) post;
  154419. post->pub.start_pass = start_pass_dpost;
  154420. post->whole_image = NULL; /* flag for no virtual arrays */
  154421. post->buffer = NULL; /* flag for no strip buffer */
  154422. if (cinfo->quantize_colors) {
  154423. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154424. if (need_full_buffer) {
  154425. #ifdef QUANT_2PASS_SUPPORTED
  154426. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154427. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154428. cinfo->output_width * cinfo->out_color_components,
  154429. (JDIMENSION) jround_up((long) cinfo->output_height,
  154430. (long) post->strip_height),
  154431. post->strip_height);
  154432. #else
  154433. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154434. #endif /* QUANT_2PASS_SUPPORTED */
  154435. } else {
  154436. post->buffer = (*cinfo->mem->alloc_sarray)
  154437. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154438. cinfo->output_width * cinfo->out_color_components,
  154439. post->strip_height);
  154440. }
  154441. }
  154442. }
  154443. /*** End of inlined file: jdpostct.c ***/
  154444. #undef FIX
  154445. /*** Start of inlined file: jdsample.c ***/
  154446. #define JPEG_INTERNALS
  154447. typedef JMETHOD(void, upsample1_ptr,
  154448. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154449. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154450. typedef struct {
  154451. struct jpeg_upsampler pub; /* public fields */
  154452. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154453. upsample1_ptr methods[MAX_COMPONENTS];
  154454. int next_row_out; /* counts rows emitted from color_buf */
  154455. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154456. int rowgroup_height[MAX_COMPONENTS];
  154457. UINT8 h_expand[MAX_COMPONENTS];
  154458. UINT8 v_expand[MAX_COMPONENTS];
  154459. } my_upsampler2;
  154460. typedef my_upsampler2 * my_upsample_ptr2;
  154461. METHODDEF(void)
  154462. start_pass_upsample (j_decompress_ptr cinfo)
  154463. {
  154464. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154465. upsample->next_row_out = cinfo->max_v_samp_factor;
  154466. upsample->rows_to_go = cinfo->output_height;
  154467. }
  154468. METHODDEF(void)
  154469. sep_upsample (j_decompress_ptr cinfo,
  154470. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154471. JDIMENSION in_row_groups_avail,
  154472. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154473. JDIMENSION out_rows_avail)
  154474. {
  154475. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154476. int ci;
  154477. jpeg_component_info * compptr;
  154478. JDIMENSION num_rows;
  154479. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154480. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154481. ci++, compptr++) {
  154482. (*upsample->methods[ci]) (cinfo, compptr,
  154483. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154484. upsample->color_buf + ci);
  154485. }
  154486. upsample->next_row_out = 0;
  154487. }
  154488. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154489. if (num_rows > upsample->rows_to_go)
  154490. num_rows = upsample->rows_to_go;
  154491. out_rows_avail -= *out_row_ctr;
  154492. if (num_rows > out_rows_avail)
  154493. num_rows = out_rows_avail;
  154494. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154495. (JDIMENSION) upsample->next_row_out,
  154496. output_buf + *out_row_ctr,
  154497. (int) num_rows);
  154498. *out_row_ctr += num_rows;
  154499. upsample->rows_to_go -= num_rows;
  154500. upsample->next_row_out += num_rows;
  154501. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154502. (*in_row_group_ctr)++;
  154503. }
  154504. METHODDEF(void)
  154505. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154506. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154507. {
  154508. *output_data_ptr = input_data;
  154509. }
  154510. METHODDEF(void)
  154511. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154512. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154513. {
  154514. *output_data_ptr = NULL; /* safety check */
  154515. }
  154516. METHODDEF(void)
  154517. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154518. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154519. {
  154520. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154521. JSAMPARRAY output_data = *output_data_ptr;
  154522. register JSAMPROW inptr, outptr;
  154523. register JSAMPLE invalue;
  154524. register int h;
  154525. JSAMPROW outend;
  154526. int h_expand, v_expand;
  154527. int inrow, outrow;
  154528. h_expand = upsample->h_expand[compptr->component_index];
  154529. v_expand = upsample->v_expand[compptr->component_index];
  154530. inrow = outrow = 0;
  154531. while (outrow < cinfo->max_v_samp_factor) {
  154532. inptr = input_data[inrow];
  154533. outptr = output_data[outrow];
  154534. outend = outptr + cinfo->output_width;
  154535. while (outptr < outend) {
  154536. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154537. for (h = h_expand; h > 0; h--) {
  154538. *outptr++ = invalue;
  154539. }
  154540. }
  154541. if (v_expand > 1) {
  154542. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154543. v_expand-1, cinfo->output_width);
  154544. }
  154545. inrow++;
  154546. outrow += v_expand;
  154547. }
  154548. }
  154549. METHODDEF(void)
  154550. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154551. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154552. {
  154553. JSAMPARRAY output_data = *output_data_ptr;
  154554. register JSAMPROW inptr, outptr;
  154555. register JSAMPLE invalue;
  154556. JSAMPROW outend;
  154557. int inrow;
  154558. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154559. inptr = input_data[inrow];
  154560. outptr = output_data[inrow];
  154561. outend = outptr + cinfo->output_width;
  154562. while (outptr < outend) {
  154563. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154564. *outptr++ = invalue;
  154565. *outptr++ = invalue;
  154566. }
  154567. }
  154568. }
  154569. METHODDEF(void)
  154570. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154571. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154572. {
  154573. JSAMPARRAY output_data = *output_data_ptr;
  154574. register JSAMPROW inptr, outptr;
  154575. register JSAMPLE invalue;
  154576. JSAMPROW outend;
  154577. int inrow, outrow;
  154578. inrow = outrow = 0;
  154579. while (outrow < cinfo->max_v_samp_factor) {
  154580. inptr = input_data[inrow];
  154581. outptr = output_data[outrow];
  154582. outend = outptr + cinfo->output_width;
  154583. while (outptr < outend) {
  154584. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154585. *outptr++ = invalue;
  154586. *outptr++ = invalue;
  154587. }
  154588. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154589. 1, cinfo->output_width);
  154590. inrow++;
  154591. outrow += 2;
  154592. }
  154593. }
  154594. METHODDEF(void)
  154595. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154596. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154597. {
  154598. JSAMPARRAY output_data = *output_data_ptr;
  154599. register JSAMPROW inptr, outptr;
  154600. register int invalue;
  154601. register JDIMENSION colctr;
  154602. int inrow;
  154603. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154604. inptr = input_data[inrow];
  154605. outptr = output_data[inrow];
  154606. invalue = GETJSAMPLE(*inptr++);
  154607. *outptr++ = (JSAMPLE) invalue;
  154608. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154609. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154610. invalue = GETJSAMPLE(*inptr++) * 3;
  154611. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154612. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154613. }
  154614. invalue = GETJSAMPLE(*inptr);
  154615. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154616. *outptr++ = (JSAMPLE) invalue;
  154617. }
  154618. }
  154619. METHODDEF(void)
  154620. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154621. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154622. {
  154623. JSAMPARRAY output_data = *output_data_ptr;
  154624. register JSAMPROW inptr0, inptr1, outptr;
  154625. #if BITS_IN_JSAMPLE == 8
  154626. register int thiscolsum, lastcolsum, nextcolsum;
  154627. #else
  154628. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154629. #endif
  154630. register JDIMENSION colctr;
  154631. int inrow, outrow, v;
  154632. inrow = outrow = 0;
  154633. while (outrow < cinfo->max_v_samp_factor) {
  154634. for (v = 0; v < 2; v++) {
  154635. inptr0 = input_data[inrow];
  154636. if (v == 0) /* next nearest is row above */
  154637. inptr1 = input_data[inrow-1];
  154638. else /* next nearest is row below */
  154639. inptr1 = input_data[inrow+1];
  154640. outptr = output_data[outrow++];
  154641. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154642. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154643. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154644. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154645. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154646. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154647. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154648. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154649. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154650. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154651. }
  154652. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154653. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154654. }
  154655. inrow++;
  154656. }
  154657. }
  154658. GLOBAL(void)
  154659. jinit_upsampler (j_decompress_ptr cinfo)
  154660. {
  154661. my_upsample_ptr2 upsample;
  154662. int ci;
  154663. jpeg_component_info * compptr;
  154664. boolean need_buffer, do_fancy;
  154665. int h_in_group, v_in_group, h_out_group, v_out_group;
  154666. upsample = (my_upsample_ptr2)
  154667. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154668. SIZEOF(my_upsampler2));
  154669. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154670. upsample->pub.start_pass = start_pass_upsample;
  154671. upsample->pub.upsample = sep_upsample;
  154672. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154673. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154674. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154675. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154676. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154677. ci++, compptr++) {
  154678. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154679. cinfo->min_DCT_scaled_size;
  154680. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154681. cinfo->min_DCT_scaled_size;
  154682. h_out_group = cinfo->max_h_samp_factor;
  154683. v_out_group = cinfo->max_v_samp_factor;
  154684. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154685. need_buffer = TRUE;
  154686. if (! compptr->component_needed) {
  154687. upsample->methods[ci] = noop_upsample;
  154688. need_buffer = FALSE;
  154689. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154690. upsample->methods[ci] = fullsize_upsample;
  154691. need_buffer = FALSE;
  154692. } else if (h_in_group * 2 == h_out_group &&
  154693. v_in_group == v_out_group) {
  154694. if (do_fancy && compptr->downsampled_width > 2)
  154695. upsample->methods[ci] = h2v1_fancy_upsample;
  154696. else
  154697. upsample->methods[ci] = h2v1_upsample;
  154698. } else if (h_in_group * 2 == h_out_group &&
  154699. v_in_group * 2 == v_out_group) {
  154700. if (do_fancy && compptr->downsampled_width > 2) {
  154701. upsample->methods[ci] = h2v2_fancy_upsample;
  154702. upsample->pub.need_context_rows = TRUE;
  154703. } else
  154704. upsample->methods[ci] = h2v2_upsample;
  154705. } else if ((h_out_group % h_in_group) == 0 &&
  154706. (v_out_group % v_in_group) == 0) {
  154707. upsample->methods[ci] = int_upsample;
  154708. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154709. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154710. } else
  154711. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154712. if (need_buffer) {
  154713. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154714. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154715. (JDIMENSION) jround_up((long) cinfo->output_width,
  154716. (long) cinfo->max_h_samp_factor),
  154717. (JDIMENSION) cinfo->max_v_samp_factor);
  154718. }
  154719. }
  154720. }
  154721. /*** End of inlined file: jdsample.c ***/
  154722. /*** Start of inlined file: jdtrans.c ***/
  154723. #define JPEG_INTERNALS
  154724. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154725. GLOBAL(jvirt_barray_ptr *)
  154726. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154727. {
  154728. if (cinfo->global_state == DSTATE_READY) {
  154729. transdecode_master_selection(cinfo);
  154730. cinfo->global_state = DSTATE_RDCOEFS;
  154731. }
  154732. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154733. for (;;) {
  154734. int retcode;
  154735. if (cinfo->progress != NULL)
  154736. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154737. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154738. if (retcode == JPEG_SUSPENDED)
  154739. return NULL;
  154740. if (retcode == JPEG_REACHED_EOI)
  154741. break;
  154742. if (cinfo->progress != NULL &&
  154743. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154744. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154745. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154746. }
  154747. }
  154748. }
  154749. cinfo->global_state = DSTATE_STOPPING;
  154750. }
  154751. if ((cinfo->global_state == DSTATE_STOPPING ||
  154752. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154753. return cinfo->coef->coef_arrays;
  154754. }
  154755. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154756. return NULL; /* keep compiler happy */
  154757. }
  154758. LOCAL(void)
  154759. transdecode_master_selection (j_decompress_ptr cinfo)
  154760. {
  154761. cinfo->buffered_image = TRUE;
  154762. if (cinfo->arith_code) {
  154763. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154764. } else {
  154765. if (cinfo->progressive_mode) {
  154766. #ifdef D_PROGRESSIVE_SUPPORTED
  154767. jinit_phuff_decoder(cinfo);
  154768. #else
  154769. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154770. #endif
  154771. } else
  154772. jinit_huff_decoder(cinfo);
  154773. }
  154774. jinit_d_coef_controller(cinfo, TRUE);
  154775. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154776. (*cinfo->inputctl->start_input_pass) (cinfo);
  154777. if (cinfo->progress != NULL) {
  154778. int nscans;
  154779. if (cinfo->progressive_mode) {
  154780. nscans = 2 + 3 * cinfo->num_components;
  154781. } else if (cinfo->inputctl->has_multiple_scans) {
  154782. nscans = cinfo->num_components;
  154783. } else {
  154784. nscans = 1;
  154785. }
  154786. cinfo->progress->pass_counter = 0L;
  154787. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154788. cinfo->progress->completed_passes = 0;
  154789. cinfo->progress->total_passes = 1;
  154790. }
  154791. }
  154792. /*** End of inlined file: jdtrans.c ***/
  154793. /*** Start of inlined file: jfdctflt.c ***/
  154794. #define JPEG_INTERNALS
  154795. #ifdef DCT_FLOAT_SUPPORTED
  154796. #if DCTSIZE != 8
  154797. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154798. #endif
  154799. GLOBAL(void)
  154800. jpeg_fdct_float (FAST_FLOAT * data)
  154801. {
  154802. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154803. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154804. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154805. FAST_FLOAT *dataptr;
  154806. int ctr;
  154807. dataptr = data;
  154808. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154809. tmp0 = dataptr[0] + dataptr[7];
  154810. tmp7 = dataptr[0] - dataptr[7];
  154811. tmp1 = dataptr[1] + dataptr[6];
  154812. tmp6 = dataptr[1] - dataptr[6];
  154813. tmp2 = dataptr[2] + dataptr[5];
  154814. tmp5 = dataptr[2] - dataptr[5];
  154815. tmp3 = dataptr[3] + dataptr[4];
  154816. tmp4 = dataptr[3] - dataptr[4];
  154817. tmp10 = tmp0 + tmp3; /* phase 2 */
  154818. tmp13 = tmp0 - tmp3;
  154819. tmp11 = tmp1 + tmp2;
  154820. tmp12 = tmp1 - tmp2;
  154821. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154822. dataptr[4] = tmp10 - tmp11;
  154823. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154824. dataptr[2] = tmp13 + z1; /* phase 5 */
  154825. dataptr[6] = tmp13 - z1;
  154826. tmp10 = tmp4 + tmp5; /* phase 2 */
  154827. tmp11 = tmp5 + tmp6;
  154828. tmp12 = tmp6 + tmp7;
  154829. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154830. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154831. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154832. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154833. z11 = tmp7 + z3; /* phase 5 */
  154834. z13 = tmp7 - z3;
  154835. dataptr[5] = z13 + z2; /* phase 6 */
  154836. dataptr[3] = z13 - z2;
  154837. dataptr[1] = z11 + z4;
  154838. dataptr[7] = z11 - z4;
  154839. dataptr += DCTSIZE; /* advance pointer to next row */
  154840. }
  154841. dataptr = data;
  154842. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154843. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154844. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154845. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154846. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154847. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154848. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154849. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154850. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154851. tmp10 = tmp0 + tmp3; /* phase 2 */
  154852. tmp13 = tmp0 - tmp3;
  154853. tmp11 = tmp1 + tmp2;
  154854. tmp12 = tmp1 - tmp2;
  154855. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154856. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154857. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154858. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154859. dataptr[DCTSIZE*6] = tmp13 - z1;
  154860. tmp10 = tmp4 + tmp5; /* phase 2 */
  154861. tmp11 = tmp5 + tmp6;
  154862. tmp12 = tmp6 + tmp7;
  154863. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154864. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154865. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154866. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154867. z11 = tmp7 + z3; /* phase 5 */
  154868. z13 = tmp7 - z3;
  154869. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154870. dataptr[DCTSIZE*3] = z13 - z2;
  154871. dataptr[DCTSIZE*1] = z11 + z4;
  154872. dataptr[DCTSIZE*7] = z11 - z4;
  154873. dataptr++; /* advance pointer to next column */
  154874. }
  154875. }
  154876. #endif /* DCT_FLOAT_SUPPORTED */
  154877. /*** End of inlined file: jfdctflt.c ***/
  154878. /*** Start of inlined file: jfdctint.c ***/
  154879. #define JPEG_INTERNALS
  154880. #ifdef DCT_ISLOW_SUPPORTED
  154881. #if DCTSIZE != 8
  154882. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154883. #endif
  154884. #if BITS_IN_JSAMPLE == 8
  154885. #define CONST_BITS 13
  154886. #define PASS1_BITS 2
  154887. #else
  154888. #define CONST_BITS 13
  154889. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154890. #endif
  154891. #if CONST_BITS == 13
  154892. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154893. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154894. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154895. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154896. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154897. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154898. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154899. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154900. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154901. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154902. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154903. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154904. #else
  154905. #define FIX_0_298631336 FIX(0.298631336)
  154906. #define FIX_0_390180644 FIX(0.390180644)
  154907. #define FIX_0_541196100 FIX(0.541196100)
  154908. #define FIX_0_765366865 FIX(0.765366865)
  154909. #define FIX_0_899976223 FIX(0.899976223)
  154910. #define FIX_1_175875602 FIX(1.175875602)
  154911. #define FIX_1_501321110 FIX(1.501321110)
  154912. #define FIX_1_847759065 FIX(1.847759065)
  154913. #define FIX_1_961570560 FIX(1.961570560)
  154914. #define FIX_2_053119869 FIX(2.053119869)
  154915. #define FIX_2_562915447 FIX(2.562915447)
  154916. #define FIX_3_072711026 FIX(3.072711026)
  154917. #endif
  154918. #if BITS_IN_JSAMPLE == 8
  154919. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  154920. #else
  154921. #define MULTIPLY(var,const) ((var) * (const))
  154922. #endif
  154923. GLOBAL(void)
  154924. jpeg_fdct_islow (DCTELEM * data)
  154925. {
  154926. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154927. INT32 tmp10, tmp11, tmp12, tmp13;
  154928. INT32 z1, z2, z3, z4, z5;
  154929. DCTELEM *dataptr;
  154930. int ctr;
  154931. SHIFT_TEMPS
  154932. dataptr = data;
  154933. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154934. tmp0 = dataptr[0] + dataptr[7];
  154935. tmp7 = dataptr[0] - dataptr[7];
  154936. tmp1 = dataptr[1] + dataptr[6];
  154937. tmp6 = dataptr[1] - dataptr[6];
  154938. tmp2 = dataptr[2] + dataptr[5];
  154939. tmp5 = dataptr[2] - dataptr[5];
  154940. tmp3 = dataptr[3] + dataptr[4];
  154941. tmp4 = dataptr[3] - dataptr[4];
  154942. tmp10 = tmp0 + tmp3;
  154943. tmp13 = tmp0 - tmp3;
  154944. tmp11 = tmp1 + tmp2;
  154945. tmp12 = tmp1 - tmp2;
  154946. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  154947. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  154948. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154949. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154950. CONST_BITS-PASS1_BITS);
  154951. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154952. CONST_BITS-PASS1_BITS);
  154953. z1 = tmp4 + tmp7;
  154954. z2 = tmp5 + tmp6;
  154955. z3 = tmp4 + tmp6;
  154956. z4 = tmp5 + tmp7;
  154957. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154958. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154959. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154960. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154961. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154962. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154963. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154964. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154965. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154966. z3 += z5;
  154967. z4 += z5;
  154968. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  154969. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  154970. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  154971. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  154972. dataptr += DCTSIZE; /* advance pointer to next row */
  154973. }
  154974. dataptr = data;
  154975. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154976. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154977. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154978. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154979. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154980. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154981. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154982. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154983. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154984. tmp10 = tmp0 + tmp3;
  154985. tmp13 = tmp0 - tmp3;
  154986. tmp11 = tmp1 + tmp2;
  154987. tmp12 = tmp1 - tmp2;
  154988. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  154989. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  154990. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154991. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154992. CONST_BITS+PASS1_BITS);
  154993. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154994. CONST_BITS+PASS1_BITS);
  154995. z1 = tmp4 + tmp7;
  154996. z2 = tmp5 + tmp6;
  154997. z3 = tmp4 + tmp6;
  154998. z4 = tmp5 + tmp7;
  154999. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155000. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155001. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155002. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155003. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155004. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155005. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155006. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155007. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155008. z3 += z5;
  155009. z4 += z5;
  155010. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155011. CONST_BITS+PASS1_BITS);
  155012. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155013. CONST_BITS+PASS1_BITS);
  155014. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155015. CONST_BITS+PASS1_BITS);
  155016. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155017. CONST_BITS+PASS1_BITS);
  155018. dataptr++; /* advance pointer to next column */
  155019. }
  155020. }
  155021. #endif /* DCT_ISLOW_SUPPORTED */
  155022. /*** End of inlined file: jfdctint.c ***/
  155023. #undef CONST_BITS
  155024. #undef MULTIPLY
  155025. #undef FIX_0_541196100
  155026. /*** Start of inlined file: jfdctfst.c ***/
  155027. #define JPEG_INTERNALS
  155028. #ifdef DCT_IFAST_SUPPORTED
  155029. #if DCTSIZE != 8
  155030. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155031. #endif
  155032. #define CONST_BITS 8
  155033. #if CONST_BITS == 8
  155034. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155035. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155036. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155037. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155038. #else
  155039. #define FIX_0_382683433 FIX(0.382683433)
  155040. #define FIX_0_541196100 FIX(0.541196100)
  155041. #define FIX_0_707106781 FIX(0.707106781)
  155042. #define FIX_1_306562965 FIX(1.306562965)
  155043. #endif
  155044. #ifndef USE_ACCURATE_ROUNDING
  155045. #undef DESCALE
  155046. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155047. #endif
  155048. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155049. GLOBAL(void)
  155050. jpeg_fdct_ifast (DCTELEM * data)
  155051. {
  155052. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155053. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155054. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155055. DCTELEM *dataptr;
  155056. int ctr;
  155057. SHIFT_TEMPS
  155058. dataptr = data;
  155059. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155060. tmp0 = dataptr[0] + dataptr[7];
  155061. tmp7 = dataptr[0] - dataptr[7];
  155062. tmp1 = dataptr[1] + dataptr[6];
  155063. tmp6 = dataptr[1] - dataptr[6];
  155064. tmp2 = dataptr[2] + dataptr[5];
  155065. tmp5 = dataptr[2] - dataptr[5];
  155066. tmp3 = dataptr[3] + dataptr[4];
  155067. tmp4 = dataptr[3] - dataptr[4];
  155068. tmp10 = tmp0 + tmp3; /* phase 2 */
  155069. tmp13 = tmp0 - tmp3;
  155070. tmp11 = tmp1 + tmp2;
  155071. tmp12 = tmp1 - tmp2;
  155072. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155073. dataptr[4] = tmp10 - tmp11;
  155074. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155075. dataptr[2] = tmp13 + z1; /* phase 5 */
  155076. dataptr[6] = tmp13 - z1;
  155077. tmp10 = tmp4 + tmp5; /* phase 2 */
  155078. tmp11 = tmp5 + tmp6;
  155079. tmp12 = tmp6 + tmp7;
  155080. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155081. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155082. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155083. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155084. z11 = tmp7 + z3; /* phase 5 */
  155085. z13 = tmp7 - z3;
  155086. dataptr[5] = z13 + z2; /* phase 6 */
  155087. dataptr[3] = z13 - z2;
  155088. dataptr[1] = z11 + z4;
  155089. dataptr[7] = z11 - z4;
  155090. dataptr += DCTSIZE; /* advance pointer to next row */
  155091. }
  155092. dataptr = data;
  155093. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155094. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155095. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155096. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155097. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155098. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155099. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155100. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155101. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155102. tmp10 = tmp0 + tmp3; /* phase 2 */
  155103. tmp13 = tmp0 - tmp3;
  155104. tmp11 = tmp1 + tmp2;
  155105. tmp12 = tmp1 - tmp2;
  155106. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155107. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155108. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155109. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155110. dataptr[DCTSIZE*6] = tmp13 - z1;
  155111. tmp10 = tmp4 + tmp5; /* phase 2 */
  155112. tmp11 = tmp5 + tmp6;
  155113. tmp12 = tmp6 + tmp7;
  155114. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155115. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155116. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155117. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155118. z11 = tmp7 + z3; /* phase 5 */
  155119. z13 = tmp7 - z3;
  155120. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155121. dataptr[DCTSIZE*3] = z13 - z2;
  155122. dataptr[DCTSIZE*1] = z11 + z4;
  155123. dataptr[DCTSIZE*7] = z11 - z4;
  155124. dataptr++; /* advance pointer to next column */
  155125. }
  155126. }
  155127. #endif /* DCT_IFAST_SUPPORTED */
  155128. /*** End of inlined file: jfdctfst.c ***/
  155129. #undef FIX_0_541196100
  155130. /*** Start of inlined file: jidctflt.c ***/
  155131. #define JPEG_INTERNALS
  155132. #ifdef DCT_FLOAT_SUPPORTED
  155133. #if DCTSIZE != 8
  155134. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155135. #endif
  155136. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155137. GLOBAL(void)
  155138. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155139. JCOEFPTR coef_block,
  155140. JSAMPARRAY output_buf, JDIMENSION output_col)
  155141. {
  155142. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155143. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155144. FAST_FLOAT z5, z10, z11, z12, z13;
  155145. JCOEFPTR inptr;
  155146. FLOAT_MULT_TYPE * quantptr;
  155147. FAST_FLOAT * wsptr;
  155148. JSAMPROW outptr;
  155149. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155150. int ctr;
  155151. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155152. SHIFT_TEMPS
  155153. inptr = coef_block;
  155154. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155155. wsptr = workspace;
  155156. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155157. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155158. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155159. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155160. inptr[DCTSIZE*7] == 0) {
  155161. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155162. wsptr[DCTSIZE*0] = dcval;
  155163. wsptr[DCTSIZE*1] = dcval;
  155164. wsptr[DCTSIZE*2] = dcval;
  155165. wsptr[DCTSIZE*3] = dcval;
  155166. wsptr[DCTSIZE*4] = dcval;
  155167. wsptr[DCTSIZE*5] = dcval;
  155168. wsptr[DCTSIZE*6] = dcval;
  155169. wsptr[DCTSIZE*7] = dcval;
  155170. inptr++; /* advance pointers to next column */
  155171. quantptr++;
  155172. wsptr++;
  155173. continue;
  155174. }
  155175. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155176. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155177. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155178. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155179. tmp10 = tmp0 + tmp2; /* phase 3 */
  155180. tmp11 = tmp0 - tmp2;
  155181. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155182. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155183. tmp0 = tmp10 + tmp13; /* phase 2 */
  155184. tmp3 = tmp10 - tmp13;
  155185. tmp1 = tmp11 + tmp12;
  155186. tmp2 = tmp11 - tmp12;
  155187. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155188. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155189. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155190. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155191. z13 = tmp6 + tmp5; /* phase 6 */
  155192. z10 = tmp6 - tmp5;
  155193. z11 = tmp4 + tmp7;
  155194. z12 = tmp4 - tmp7;
  155195. tmp7 = z11 + z13; /* phase 5 */
  155196. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155197. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155198. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155199. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155200. tmp6 = tmp12 - tmp7; /* phase 2 */
  155201. tmp5 = tmp11 - tmp6;
  155202. tmp4 = tmp10 + tmp5;
  155203. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155204. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155205. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155206. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155207. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155208. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155209. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155210. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155211. inptr++; /* advance pointers to next column */
  155212. quantptr++;
  155213. wsptr++;
  155214. }
  155215. wsptr = workspace;
  155216. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155217. outptr = output_buf[ctr] + output_col;
  155218. tmp10 = wsptr[0] + wsptr[4];
  155219. tmp11 = wsptr[0] - wsptr[4];
  155220. tmp13 = wsptr[2] + wsptr[6];
  155221. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155222. tmp0 = tmp10 + tmp13;
  155223. tmp3 = tmp10 - tmp13;
  155224. tmp1 = tmp11 + tmp12;
  155225. tmp2 = tmp11 - tmp12;
  155226. z13 = wsptr[5] + wsptr[3];
  155227. z10 = wsptr[5] - wsptr[3];
  155228. z11 = wsptr[1] + wsptr[7];
  155229. z12 = wsptr[1] - wsptr[7];
  155230. tmp7 = z11 + z13;
  155231. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155232. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155233. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155234. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155235. tmp6 = tmp12 - tmp7;
  155236. tmp5 = tmp11 - tmp6;
  155237. tmp4 = tmp10 + tmp5;
  155238. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155239. & RANGE_MASK];
  155240. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155241. & RANGE_MASK];
  155242. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155243. & RANGE_MASK];
  155244. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155245. & RANGE_MASK];
  155246. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155247. & RANGE_MASK];
  155248. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155249. & RANGE_MASK];
  155250. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155251. & RANGE_MASK];
  155252. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155253. & RANGE_MASK];
  155254. wsptr += DCTSIZE; /* advance pointer to next row */
  155255. }
  155256. }
  155257. #endif /* DCT_FLOAT_SUPPORTED */
  155258. /*** End of inlined file: jidctflt.c ***/
  155259. #undef CONST_BITS
  155260. #undef FIX_1_847759065
  155261. #undef MULTIPLY
  155262. #undef DEQUANTIZE
  155263. #undef DESCALE
  155264. /*** Start of inlined file: jidctfst.c ***/
  155265. #define JPEG_INTERNALS
  155266. #ifdef DCT_IFAST_SUPPORTED
  155267. #if DCTSIZE != 8
  155268. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155269. #endif
  155270. #if BITS_IN_JSAMPLE == 8
  155271. #define CONST_BITS 8
  155272. #define PASS1_BITS 2
  155273. #else
  155274. #define CONST_BITS 8
  155275. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155276. #endif
  155277. #if CONST_BITS == 8
  155278. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155279. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155280. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155281. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155282. #else
  155283. #define FIX_1_082392200 FIX(1.082392200)
  155284. #define FIX_1_414213562 FIX(1.414213562)
  155285. #define FIX_1_847759065 FIX(1.847759065)
  155286. #define FIX_2_613125930 FIX(2.613125930)
  155287. #endif
  155288. #ifndef USE_ACCURATE_ROUNDING
  155289. #undef DESCALE
  155290. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155291. #endif
  155292. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155293. #if BITS_IN_JSAMPLE == 8
  155294. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155295. #else
  155296. #define DEQUANTIZE(coef,quantval) \
  155297. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155298. #endif
  155299. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155300. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155301. #if BITS_IN_JSAMPLE == 8
  155302. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155303. #else
  155304. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155305. #endif
  155306. #define IRIGHT_SHIFT(x,shft) \
  155307. ((ishift_temp = (x)) < 0 ? \
  155308. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155309. (ishift_temp >> (shft)))
  155310. #else
  155311. #define ISHIFT_TEMPS
  155312. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155313. #endif
  155314. #ifdef USE_ACCURATE_ROUNDING
  155315. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155316. #else
  155317. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155318. #endif
  155319. GLOBAL(void)
  155320. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155321. JCOEFPTR coef_block,
  155322. JSAMPARRAY output_buf, JDIMENSION output_col)
  155323. {
  155324. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155325. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155326. DCTELEM z5, z10, z11, z12, z13;
  155327. JCOEFPTR inptr;
  155328. IFAST_MULT_TYPE * quantptr;
  155329. int * wsptr;
  155330. JSAMPROW outptr;
  155331. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155332. int ctr;
  155333. int workspace[DCTSIZE2]; /* buffers data between passes */
  155334. SHIFT_TEMPS /* for DESCALE */
  155335. ISHIFT_TEMPS /* for IDESCALE */
  155336. inptr = coef_block;
  155337. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155338. wsptr = workspace;
  155339. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155340. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155341. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155342. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155343. inptr[DCTSIZE*7] == 0) {
  155344. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155345. wsptr[DCTSIZE*0] = dcval;
  155346. wsptr[DCTSIZE*1] = dcval;
  155347. wsptr[DCTSIZE*2] = dcval;
  155348. wsptr[DCTSIZE*3] = dcval;
  155349. wsptr[DCTSIZE*4] = dcval;
  155350. wsptr[DCTSIZE*5] = dcval;
  155351. wsptr[DCTSIZE*6] = dcval;
  155352. wsptr[DCTSIZE*7] = dcval;
  155353. inptr++; /* advance pointers to next column */
  155354. quantptr++;
  155355. wsptr++;
  155356. continue;
  155357. }
  155358. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155359. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155360. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155361. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155362. tmp10 = tmp0 + tmp2; /* phase 3 */
  155363. tmp11 = tmp0 - tmp2;
  155364. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155365. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155366. tmp0 = tmp10 + tmp13; /* phase 2 */
  155367. tmp3 = tmp10 - tmp13;
  155368. tmp1 = tmp11 + tmp12;
  155369. tmp2 = tmp11 - tmp12;
  155370. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155371. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155372. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155373. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155374. z13 = tmp6 + tmp5; /* phase 6 */
  155375. z10 = tmp6 - tmp5;
  155376. z11 = tmp4 + tmp7;
  155377. z12 = tmp4 - tmp7;
  155378. tmp7 = z11 + z13; /* phase 5 */
  155379. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155380. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155381. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155382. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155383. tmp6 = tmp12 - tmp7; /* phase 2 */
  155384. tmp5 = tmp11 - tmp6;
  155385. tmp4 = tmp10 + tmp5;
  155386. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155387. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155388. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155389. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155390. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155391. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155392. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155393. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155394. inptr++; /* advance pointers to next column */
  155395. quantptr++;
  155396. wsptr++;
  155397. }
  155398. wsptr = workspace;
  155399. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155400. outptr = output_buf[ctr] + output_col;
  155401. #ifndef NO_ZERO_ROW_TEST
  155402. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155403. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155404. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155405. & RANGE_MASK];
  155406. outptr[0] = dcval;
  155407. outptr[1] = dcval;
  155408. outptr[2] = dcval;
  155409. outptr[3] = dcval;
  155410. outptr[4] = dcval;
  155411. outptr[5] = dcval;
  155412. outptr[6] = dcval;
  155413. outptr[7] = dcval;
  155414. wsptr += DCTSIZE; /* advance pointer to next row */
  155415. continue;
  155416. }
  155417. #endif
  155418. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155419. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155420. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155421. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155422. - tmp13;
  155423. tmp0 = tmp10 + tmp13;
  155424. tmp3 = tmp10 - tmp13;
  155425. tmp1 = tmp11 + tmp12;
  155426. tmp2 = tmp11 - tmp12;
  155427. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155428. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155429. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155430. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155431. tmp7 = z11 + z13; /* phase 5 */
  155432. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155433. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155434. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155435. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155436. tmp6 = tmp12 - tmp7; /* phase 2 */
  155437. tmp5 = tmp11 - tmp6;
  155438. tmp4 = tmp10 + tmp5;
  155439. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155440. & RANGE_MASK];
  155441. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155442. & RANGE_MASK];
  155443. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155444. & RANGE_MASK];
  155445. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155446. & RANGE_MASK];
  155447. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155448. & RANGE_MASK];
  155449. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155450. & RANGE_MASK];
  155451. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155452. & RANGE_MASK];
  155453. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155454. & RANGE_MASK];
  155455. wsptr += DCTSIZE; /* advance pointer to next row */
  155456. }
  155457. }
  155458. #endif /* DCT_IFAST_SUPPORTED */
  155459. /*** End of inlined file: jidctfst.c ***/
  155460. #undef CONST_BITS
  155461. #undef FIX_1_847759065
  155462. #undef MULTIPLY
  155463. #undef DEQUANTIZE
  155464. /*** Start of inlined file: jidctint.c ***/
  155465. #define JPEG_INTERNALS
  155466. #ifdef DCT_ISLOW_SUPPORTED
  155467. #if DCTSIZE != 8
  155468. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155469. #endif
  155470. #if BITS_IN_JSAMPLE == 8
  155471. #define CONST_BITS 13
  155472. #define PASS1_BITS 2
  155473. #else
  155474. #define CONST_BITS 13
  155475. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155476. #endif
  155477. #if CONST_BITS == 13
  155478. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155479. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155480. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155481. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155482. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155483. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155484. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155485. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155486. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155487. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155488. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155489. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155490. #else
  155491. #define FIX_0_298631336 FIX(0.298631336)
  155492. #define FIX_0_390180644 FIX(0.390180644)
  155493. #define FIX_0_541196100 FIX(0.541196100)
  155494. #define FIX_0_765366865 FIX(0.765366865)
  155495. #define FIX_0_899976223 FIX(0.899976223)
  155496. #define FIX_1_175875602 FIX(1.175875602)
  155497. #define FIX_1_501321110 FIX(1.501321110)
  155498. #define FIX_1_847759065 FIX(1.847759065)
  155499. #define FIX_1_961570560 FIX(1.961570560)
  155500. #define FIX_2_053119869 FIX(2.053119869)
  155501. #define FIX_2_562915447 FIX(2.562915447)
  155502. #define FIX_3_072711026 FIX(3.072711026)
  155503. #endif
  155504. #if BITS_IN_JSAMPLE == 8
  155505. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155506. #else
  155507. #define MULTIPLY(var,const) ((var) * (const))
  155508. #endif
  155509. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155510. GLOBAL(void)
  155511. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155512. JCOEFPTR coef_block,
  155513. JSAMPARRAY output_buf, JDIMENSION output_col)
  155514. {
  155515. INT32 tmp0, tmp1, tmp2, tmp3;
  155516. INT32 tmp10, tmp11, tmp12, tmp13;
  155517. INT32 z1, z2, z3, z4, z5;
  155518. JCOEFPTR inptr;
  155519. ISLOW_MULT_TYPE * quantptr;
  155520. int * wsptr;
  155521. JSAMPROW outptr;
  155522. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155523. int ctr;
  155524. int workspace[DCTSIZE2]; /* buffers data between passes */
  155525. SHIFT_TEMPS
  155526. inptr = coef_block;
  155527. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155528. wsptr = workspace;
  155529. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155530. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155531. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155532. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155533. inptr[DCTSIZE*7] == 0) {
  155534. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155535. wsptr[DCTSIZE*0] = dcval;
  155536. wsptr[DCTSIZE*1] = dcval;
  155537. wsptr[DCTSIZE*2] = dcval;
  155538. wsptr[DCTSIZE*3] = dcval;
  155539. wsptr[DCTSIZE*4] = dcval;
  155540. wsptr[DCTSIZE*5] = dcval;
  155541. wsptr[DCTSIZE*6] = dcval;
  155542. wsptr[DCTSIZE*7] = dcval;
  155543. inptr++; /* advance pointers to next column */
  155544. quantptr++;
  155545. wsptr++;
  155546. continue;
  155547. }
  155548. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155549. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155550. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155551. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155552. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155553. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155554. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155555. tmp0 = (z2 + z3) << CONST_BITS;
  155556. tmp1 = (z2 - z3) << CONST_BITS;
  155557. tmp10 = tmp0 + tmp3;
  155558. tmp13 = tmp0 - tmp3;
  155559. tmp11 = tmp1 + tmp2;
  155560. tmp12 = tmp1 - tmp2;
  155561. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155562. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155563. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155564. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155565. z1 = tmp0 + tmp3;
  155566. z2 = tmp1 + tmp2;
  155567. z3 = tmp0 + tmp2;
  155568. z4 = tmp1 + tmp3;
  155569. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155570. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155571. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155572. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155573. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155574. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155575. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155576. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155577. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155578. z3 += z5;
  155579. z4 += z5;
  155580. tmp0 += z1 + z3;
  155581. tmp1 += z2 + z4;
  155582. tmp2 += z2 + z3;
  155583. tmp3 += z1 + z4;
  155584. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155585. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155586. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155587. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155588. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155589. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155590. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155591. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155592. inptr++; /* advance pointers to next column */
  155593. quantptr++;
  155594. wsptr++;
  155595. }
  155596. wsptr = workspace;
  155597. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155598. outptr = output_buf[ctr] + output_col;
  155599. #ifndef NO_ZERO_ROW_TEST
  155600. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155601. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155602. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155603. & RANGE_MASK];
  155604. outptr[0] = dcval;
  155605. outptr[1] = dcval;
  155606. outptr[2] = dcval;
  155607. outptr[3] = dcval;
  155608. outptr[4] = dcval;
  155609. outptr[5] = dcval;
  155610. outptr[6] = dcval;
  155611. outptr[7] = dcval;
  155612. wsptr += DCTSIZE; /* advance pointer to next row */
  155613. continue;
  155614. }
  155615. #endif
  155616. z2 = (INT32) wsptr[2];
  155617. z3 = (INT32) wsptr[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. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155622. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155623. tmp10 = tmp0 + tmp3;
  155624. tmp13 = tmp0 - tmp3;
  155625. tmp11 = tmp1 + tmp2;
  155626. tmp12 = tmp1 - tmp2;
  155627. tmp0 = (INT32) wsptr[7];
  155628. tmp1 = (INT32) wsptr[5];
  155629. tmp2 = (INT32) wsptr[3];
  155630. tmp3 = (INT32) wsptr[1];
  155631. z1 = tmp0 + tmp3;
  155632. z2 = tmp1 + tmp2;
  155633. z3 = tmp0 + tmp2;
  155634. z4 = tmp1 + tmp3;
  155635. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155636. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155637. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155638. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155639. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155640. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155641. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155642. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155643. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155644. z3 += z5;
  155645. z4 += z5;
  155646. tmp0 += z1 + z3;
  155647. tmp1 += z2 + z4;
  155648. tmp2 += z2 + z3;
  155649. tmp3 += z1 + z4;
  155650. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155651. CONST_BITS+PASS1_BITS+3)
  155652. & RANGE_MASK];
  155653. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155654. CONST_BITS+PASS1_BITS+3)
  155655. & RANGE_MASK];
  155656. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155657. CONST_BITS+PASS1_BITS+3)
  155658. & RANGE_MASK];
  155659. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155660. CONST_BITS+PASS1_BITS+3)
  155661. & RANGE_MASK];
  155662. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155663. CONST_BITS+PASS1_BITS+3)
  155664. & RANGE_MASK];
  155665. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155666. CONST_BITS+PASS1_BITS+3)
  155667. & RANGE_MASK];
  155668. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155669. CONST_BITS+PASS1_BITS+3)
  155670. & RANGE_MASK];
  155671. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155672. CONST_BITS+PASS1_BITS+3)
  155673. & RANGE_MASK];
  155674. wsptr += DCTSIZE; /* advance pointer to next row */
  155675. }
  155676. }
  155677. #endif /* DCT_ISLOW_SUPPORTED */
  155678. /*** End of inlined file: jidctint.c ***/
  155679. /*** Start of inlined file: jidctred.c ***/
  155680. #define JPEG_INTERNALS
  155681. #ifdef IDCT_SCALING_SUPPORTED
  155682. #if DCTSIZE != 8
  155683. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155684. #endif
  155685. #if BITS_IN_JSAMPLE == 8
  155686. #define CONST_BITS 13
  155687. #define PASS1_BITS 2
  155688. #else
  155689. #define CONST_BITS 13
  155690. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155691. #endif
  155692. #if CONST_BITS == 13
  155693. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155694. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155695. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155696. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155697. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155698. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155699. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155700. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155701. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155702. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155703. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155704. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155705. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155706. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155707. #else
  155708. #define FIX_0_211164243 FIX(0.211164243)
  155709. #define FIX_0_509795579 FIX(0.509795579)
  155710. #define FIX_0_601344887 FIX(0.601344887)
  155711. #define FIX_0_720959822 FIX(0.720959822)
  155712. #define FIX_0_765366865 FIX(0.765366865)
  155713. #define FIX_0_850430095 FIX(0.850430095)
  155714. #define FIX_0_899976223 FIX(0.899976223)
  155715. #define FIX_1_061594337 FIX(1.061594337)
  155716. #define FIX_1_272758580 FIX(1.272758580)
  155717. #define FIX_1_451774981 FIX(1.451774981)
  155718. #define FIX_1_847759065 FIX(1.847759065)
  155719. #define FIX_2_172734803 FIX(2.172734803)
  155720. #define FIX_2_562915447 FIX(2.562915447)
  155721. #define FIX_3_624509785 FIX(3.624509785)
  155722. #endif
  155723. #if BITS_IN_JSAMPLE == 8
  155724. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155725. #else
  155726. #define MULTIPLY(var,const) ((var) * (const))
  155727. #endif
  155728. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155729. GLOBAL(void)
  155730. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155731. JCOEFPTR coef_block,
  155732. JSAMPARRAY output_buf, JDIMENSION output_col)
  155733. {
  155734. INT32 tmp0, tmp2, tmp10, tmp12;
  155735. INT32 z1, z2, z3, z4;
  155736. JCOEFPTR inptr;
  155737. ISLOW_MULT_TYPE * quantptr;
  155738. int * wsptr;
  155739. JSAMPROW outptr;
  155740. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155741. int ctr;
  155742. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155743. SHIFT_TEMPS
  155744. inptr = coef_block;
  155745. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155746. wsptr = workspace;
  155747. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155748. if (ctr == DCTSIZE-4)
  155749. continue;
  155750. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155751. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155752. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155753. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155754. wsptr[DCTSIZE*0] = dcval;
  155755. wsptr[DCTSIZE*1] = dcval;
  155756. wsptr[DCTSIZE*2] = dcval;
  155757. wsptr[DCTSIZE*3] = dcval;
  155758. continue;
  155759. }
  155760. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155761. tmp0 <<= (CONST_BITS+1);
  155762. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155763. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155764. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155765. tmp10 = tmp0 + tmp2;
  155766. tmp12 = tmp0 - tmp2;
  155767. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155768. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155769. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155770. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155771. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155772. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155773. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155774. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155775. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155776. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155777. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155778. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155779. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155780. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155781. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155782. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155783. }
  155784. wsptr = workspace;
  155785. for (ctr = 0; ctr < 4; ctr++) {
  155786. outptr = output_buf[ctr] + output_col;
  155787. #ifndef NO_ZERO_ROW_TEST
  155788. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155789. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155790. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155791. & RANGE_MASK];
  155792. outptr[0] = dcval;
  155793. outptr[1] = dcval;
  155794. outptr[2] = dcval;
  155795. outptr[3] = dcval;
  155796. wsptr += DCTSIZE; /* advance pointer to next row */
  155797. continue;
  155798. }
  155799. #endif
  155800. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155801. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155802. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155803. tmp10 = tmp0 + tmp2;
  155804. tmp12 = tmp0 - tmp2;
  155805. z1 = (INT32) wsptr[7];
  155806. z2 = (INT32) wsptr[5];
  155807. z3 = (INT32) wsptr[3];
  155808. z4 = (INT32) wsptr[1];
  155809. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155810. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155811. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155812. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155813. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155814. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155815. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155816. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155817. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155818. CONST_BITS+PASS1_BITS+3+1)
  155819. & RANGE_MASK];
  155820. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155821. CONST_BITS+PASS1_BITS+3+1)
  155822. & RANGE_MASK];
  155823. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155824. CONST_BITS+PASS1_BITS+3+1)
  155825. & RANGE_MASK];
  155826. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155827. CONST_BITS+PASS1_BITS+3+1)
  155828. & RANGE_MASK];
  155829. wsptr += DCTSIZE; /* advance pointer to next row */
  155830. }
  155831. }
  155832. GLOBAL(void)
  155833. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155834. JCOEFPTR coef_block,
  155835. JSAMPARRAY output_buf, JDIMENSION output_col)
  155836. {
  155837. INT32 tmp0, tmp10, z1;
  155838. JCOEFPTR inptr;
  155839. ISLOW_MULT_TYPE * quantptr;
  155840. int * wsptr;
  155841. JSAMPROW outptr;
  155842. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155843. int ctr;
  155844. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155845. SHIFT_TEMPS
  155846. inptr = coef_block;
  155847. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155848. wsptr = workspace;
  155849. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155850. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155851. continue;
  155852. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155853. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155854. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155855. wsptr[DCTSIZE*0] = dcval;
  155856. wsptr[DCTSIZE*1] = dcval;
  155857. continue;
  155858. }
  155859. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155860. tmp10 = z1 << (CONST_BITS+2);
  155861. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155862. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155863. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155864. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155865. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155866. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155867. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155868. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155869. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155870. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155871. }
  155872. wsptr = workspace;
  155873. for (ctr = 0; ctr < 2; ctr++) {
  155874. outptr = output_buf[ctr] + output_col;
  155875. #ifndef NO_ZERO_ROW_TEST
  155876. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155877. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155878. & RANGE_MASK];
  155879. outptr[0] = dcval;
  155880. outptr[1] = dcval;
  155881. wsptr += DCTSIZE; /* advance pointer to next row */
  155882. continue;
  155883. }
  155884. #endif
  155885. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155886. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155887. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155888. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155889. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155890. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155891. CONST_BITS+PASS1_BITS+3+2)
  155892. & RANGE_MASK];
  155893. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155894. CONST_BITS+PASS1_BITS+3+2)
  155895. & RANGE_MASK];
  155896. wsptr += DCTSIZE; /* advance pointer to next row */
  155897. }
  155898. }
  155899. GLOBAL(void)
  155900. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155901. JCOEFPTR coef_block,
  155902. JSAMPARRAY output_buf, JDIMENSION output_col)
  155903. {
  155904. int dcval;
  155905. ISLOW_MULT_TYPE * quantptr;
  155906. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155907. SHIFT_TEMPS
  155908. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155909. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155910. dcval = (int) DESCALE((INT32) dcval, 3);
  155911. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155912. }
  155913. #endif /* IDCT_SCALING_SUPPORTED */
  155914. /*** End of inlined file: jidctred.c ***/
  155915. /*** Start of inlined file: jmemmgr.c ***/
  155916. #define JPEG_INTERNALS
  155917. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  155918. /*** Start of inlined file: jmemsys.h ***/
  155919. #ifndef __jmemsys_h__
  155920. #define __jmemsys_h__
  155921. #ifdef NEED_SHORT_EXTERNAL_NAMES
  155922. #define jpeg_get_small jGetSmall
  155923. #define jpeg_free_small jFreeSmall
  155924. #define jpeg_get_large jGetLarge
  155925. #define jpeg_free_large jFreeLarge
  155926. #define jpeg_mem_available jMemAvail
  155927. #define jpeg_open_backing_store jOpenBackStore
  155928. #define jpeg_mem_init jMemInit
  155929. #define jpeg_mem_term jMemTerm
  155930. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  155931. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  155932. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  155933. size_t sizeofobject));
  155934. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  155935. size_t sizeofobject));
  155936. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  155937. size_t sizeofobject));
  155938. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  155939. #define MAX_ALLOC_CHUNK 1000000000L
  155940. #endif
  155941. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  155942. long min_bytes_needed,
  155943. long max_bytes_needed,
  155944. long already_allocated));
  155945. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  155946. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  155947. typedef unsigned short XMSH; /* type of extended-memory handles */
  155948. typedef unsigned short EMSH; /* type of expanded-memory handles */
  155949. typedef union {
  155950. short file_handle; /* DOS file handle if it's a temp file */
  155951. XMSH xms_handle; /* handle if it's a chunk of XMS */
  155952. EMSH ems_handle; /* handle if it's a chunk of EMS */
  155953. } handle_union;
  155954. #endif /* USE_MSDOS_MEMMGR */
  155955. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  155956. #include <Files.h>
  155957. #endif /* USE_MAC_MEMMGR */
  155958. //typedef struct backing_store_struct * backing_store_ptr;
  155959. typedef struct backing_store_struct {
  155960. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  155961. struct backing_store_struct *info,
  155962. void FAR * buffer_address,
  155963. long file_offset, long byte_count));
  155964. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  155965. struct backing_store_struct *info,
  155966. void FAR * buffer_address,
  155967. long file_offset, long byte_count));
  155968. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  155969. struct backing_store_struct *info));
  155970. #ifdef USE_MSDOS_MEMMGR
  155971. handle_union handle; /* reference to backing-store storage object */
  155972. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155973. #else
  155974. #ifdef USE_MAC_MEMMGR
  155975. short temp_file; /* file reference number to temp file */
  155976. FSSpec tempSpec; /* the FSSpec for the temp file */
  155977. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155978. #else
  155979. FILE * temp_file; /* stdio reference to temp file */
  155980. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  155981. #endif
  155982. #endif
  155983. } backing_store_info;
  155984. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  155985. struct backing_store_struct *info,
  155986. long total_bytes_needed));
  155987. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  155988. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  155989. #endif
  155990. /*** End of inlined file: jmemsys.h ***/
  155991. /* import the system-dependent declarations */
  155992. #ifndef NO_GETENV
  155993. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  155994. extern char * getenv JPP((const char * name));
  155995. #endif
  155996. #endif
  155997. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  155998. #define ALIGN_TYPE double
  155999. #endif
  156000. typedef union small_pool_struct * small_pool_ptr;
  156001. typedef union small_pool_struct {
  156002. struct {
  156003. small_pool_ptr next; /* next in list of pools */
  156004. size_t bytes_used; /* how many bytes already used within pool */
  156005. size_t bytes_left; /* bytes still available in this pool */
  156006. } hdr;
  156007. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156008. } small_pool_hdr;
  156009. typedef union large_pool_struct FAR * large_pool_ptr;
  156010. typedef union large_pool_struct {
  156011. struct {
  156012. large_pool_ptr next; /* next in list of pools */
  156013. size_t bytes_used; /* how many bytes already used within pool */
  156014. size_t bytes_left; /* bytes still available in this pool */
  156015. } hdr;
  156016. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156017. } large_pool_hdr;
  156018. typedef struct {
  156019. struct jpeg_memory_mgr pub; /* public fields */
  156020. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156021. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156022. jvirt_sarray_ptr virt_sarray_list;
  156023. jvirt_barray_ptr virt_barray_list;
  156024. long total_space_allocated;
  156025. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156026. } my_memory_mgr;
  156027. typedef my_memory_mgr * my_mem_ptr;
  156028. struct jvirt_sarray_control {
  156029. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156030. JDIMENSION rows_in_array; /* total virtual array height */
  156031. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156032. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156033. JDIMENSION rows_in_mem; /* height of memory buffer */
  156034. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156035. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156036. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156037. boolean pre_zero; /* pre-zero mode requested? */
  156038. boolean dirty; /* do current buffer contents need written? */
  156039. boolean b_s_open; /* is backing-store data valid? */
  156040. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156041. backing_store_info b_s_info; /* System-dependent control info */
  156042. };
  156043. struct jvirt_barray_control {
  156044. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156045. JDIMENSION rows_in_array; /* total virtual array height */
  156046. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156047. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156048. JDIMENSION rows_in_mem; /* height of memory buffer */
  156049. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156050. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156051. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156052. boolean pre_zero; /* pre-zero mode requested? */
  156053. boolean dirty; /* do current buffer contents need written? */
  156054. boolean b_s_open; /* is backing-store data valid? */
  156055. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156056. backing_store_info b_s_info; /* System-dependent control info */
  156057. };
  156058. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156059. LOCAL(void)
  156060. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156061. {
  156062. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156063. small_pool_ptr shdr_ptr;
  156064. large_pool_ptr lhdr_ptr;
  156065. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156066. pool_id, mem->total_space_allocated);
  156067. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156068. lhdr_ptr = lhdr_ptr->hdr.next) {
  156069. fprintf(stderr, " Large chunk used %ld\n",
  156070. (long) lhdr_ptr->hdr.bytes_used);
  156071. }
  156072. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156073. shdr_ptr = shdr_ptr->hdr.next) {
  156074. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156075. (long) shdr_ptr->hdr.bytes_used,
  156076. (long) shdr_ptr->hdr.bytes_left);
  156077. }
  156078. }
  156079. #endif /* MEM_STATS */
  156080. LOCAL(void)
  156081. out_of_memory (j_common_ptr cinfo, int which)
  156082. {
  156083. #ifdef MEM_STATS
  156084. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156085. #endif
  156086. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156087. }
  156088. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156089. {
  156090. 1600, /* first PERMANENT pool */
  156091. 16000 /* first IMAGE pool */
  156092. };
  156093. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156094. {
  156095. 0, /* additional PERMANENT pools */
  156096. 5000 /* additional IMAGE pools */
  156097. };
  156098. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156099. METHODDEF(void *)
  156100. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156101. {
  156102. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156103. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156104. char * data_ptr;
  156105. size_t odd_bytes, min_request, slop;
  156106. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156107. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156108. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156109. if (odd_bytes > 0)
  156110. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156111. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156112. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156113. prev_hdr_ptr = NULL;
  156114. hdr_ptr = mem->small_list[pool_id];
  156115. while (hdr_ptr != NULL) {
  156116. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156117. break; /* found pool with enough space */
  156118. prev_hdr_ptr = hdr_ptr;
  156119. hdr_ptr = hdr_ptr->hdr.next;
  156120. }
  156121. if (hdr_ptr == NULL) {
  156122. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156123. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156124. slop = first_pool_slop[pool_id];
  156125. else
  156126. slop = extra_pool_slop[pool_id];
  156127. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156128. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156129. for (;;) {
  156130. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156131. if (hdr_ptr != NULL)
  156132. break;
  156133. slop /= 2;
  156134. if (slop < MIN_SLOP) /* give up when it gets real small */
  156135. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156136. }
  156137. mem->total_space_allocated += min_request + slop;
  156138. hdr_ptr->hdr.next = NULL;
  156139. hdr_ptr->hdr.bytes_used = 0;
  156140. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156141. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156142. mem->small_list[pool_id] = hdr_ptr;
  156143. else
  156144. prev_hdr_ptr->hdr.next = hdr_ptr;
  156145. }
  156146. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156147. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156148. hdr_ptr->hdr.bytes_used += sizeofobject;
  156149. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156150. return (void *) data_ptr;
  156151. }
  156152. METHODDEF(void FAR *)
  156153. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156154. {
  156155. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156156. large_pool_ptr hdr_ptr;
  156157. size_t odd_bytes;
  156158. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156159. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156160. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156161. if (odd_bytes > 0)
  156162. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156163. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156164. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156165. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156166. SIZEOF(large_pool_hdr));
  156167. if (hdr_ptr == NULL)
  156168. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156169. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156170. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156171. hdr_ptr->hdr.bytes_used = sizeofobject;
  156172. hdr_ptr->hdr.bytes_left = 0;
  156173. mem->large_list[pool_id] = hdr_ptr;
  156174. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156175. }
  156176. METHODDEF(JSAMPARRAY)
  156177. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156178. JDIMENSION samplesperrow, JDIMENSION numrows)
  156179. {
  156180. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156181. JSAMPARRAY result;
  156182. JSAMPROW workspace;
  156183. JDIMENSION rowsperchunk, currow, i;
  156184. long ltemp;
  156185. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156186. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156187. if (ltemp <= 0)
  156188. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156189. if (ltemp < (long) numrows)
  156190. rowsperchunk = (JDIMENSION) ltemp;
  156191. else
  156192. rowsperchunk = numrows;
  156193. mem->last_rowsperchunk = rowsperchunk;
  156194. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156195. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156196. currow = 0;
  156197. while (currow < numrows) {
  156198. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156199. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156200. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156201. * SIZEOF(JSAMPLE)));
  156202. for (i = rowsperchunk; i > 0; i--) {
  156203. result[currow++] = workspace;
  156204. workspace += samplesperrow;
  156205. }
  156206. }
  156207. return result;
  156208. }
  156209. METHODDEF(JBLOCKARRAY)
  156210. alloc_barray (j_common_ptr cinfo, int pool_id,
  156211. JDIMENSION blocksperrow, JDIMENSION numrows)
  156212. {
  156213. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156214. JBLOCKARRAY result;
  156215. JBLOCKROW workspace;
  156216. JDIMENSION rowsperchunk, currow, i;
  156217. long ltemp;
  156218. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156219. ((long) blocksperrow * SIZEOF(JBLOCK));
  156220. if (ltemp <= 0)
  156221. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156222. if (ltemp < (long) numrows)
  156223. rowsperchunk = (JDIMENSION) ltemp;
  156224. else
  156225. rowsperchunk = numrows;
  156226. mem->last_rowsperchunk = rowsperchunk;
  156227. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156228. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156229. currow = 0;
  156230. while (currow < numrows) {
  156231. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156232. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156233. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156234. * SIZEOF(JBLOCK)));
  156235. for (i = rowsperchunk; i > 0; i--) {
  156236. result[currow++] = workspace;
  156237. workspace += blocksperrow;
  156238. }
  156239. }
  156240. return result;
  156241. }
  156242. METHODDEF(jvirt_sarray_ptr)
  156243. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156244. JDIMENSION samplesperrow, JDIMENSION numrows,
  156245. JDIMENSION maxaccess)
  156246. {
  156247. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156248. jvirt_sarray_ptr result;
  156249. if (pool_id != JPOOL_IMAGE)
  156250. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156251. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156252. SIZEOF(struct jvirt_sarray_control));
  156253. result->mem_buffer = NULL; /* marks array not yet realized */
  156254. result->rows_in_array = numrows;
  156255. result->samplesperrow = samplesperrow;
  156256. result->maxaccess = maxaccess;
  156257. result->pre_zero = pre_zero;
  156258. result->b_s_open = FALSE; /* no associated backing-store object */
  156259. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156260. mem->virt_sarray_list = result;
  156261. return result;
  156262. }
  156263. METHODDEF(jvirt_barray_ptr)
  156264. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156265. JDIMENSION blocksperrow, JDIMENSION numrows,
  156266. JDIMENSION maxaccess)
  156267. {
  156268. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156269. jvirt_barray_ptr result;
  156270. if (pool_id != JPOOL_IMAGE)
  156271. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156272. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156273. SIZEOF(struct jvirt_barray_control));
  156274. result->mem_buffer = NULL; /* marks array not yet realized */
  156275. result->rows_in_array = numrows;
  156276. result->blocksperrow = blocksperrow;
  156277. result->maxaccess = maxaccess;
  156278. result->pre_zero = pre_zero;
  156279. result->b_s_open = FALSE; /* no associated backing-store object */
  156280. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156281. mem->virt_barray_list = result;
  156282. return result;
  156283. }
  156284. METHODDEF(void)
  156285. realize_virt_arrays (j_common_ptr cinfo)
  156286. {
  156287. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156288. long space_per_minheight, maximum_space, avail_mem;
  156289. long minheights, max_minheights;
  156290. jvirt_sarray_ptr sptr;
  156291. jvirt_barray_ptr bptr;
  156292. space_per_minheight = 0;
  156293. maximum_space = 0;
  156294. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156295. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156296. space_per_minheight += (long) sptr->maxaccess *
  156297. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156298. maximum_space += (long) sptr->rows_in_array *
  156299. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156300. }
  156301. }
  156302. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156303. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156304. space_per_minheight += (long) bptr->maxaccess *
  156305. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156306. maximum_space += (long) bptr->rows_in_array *
  156307. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156308. }
  156309. }
  156310. if (space_per_minheight <= 0)
  156311. return; /* no unrealized arrays, no work */
  156312. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156313. mem->total_space_allocated);
  156314. if (avail_mem >= maximum_space)
  156315. max_minheights = 1000000000L;
  156316. else {
  156317. max_minheights = avail_mem / space_per_minheight;
  156318. if (max_minheights <= 0)
  156319. max_minheights = 1;
  156320. }
  156321. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156322. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156323. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156324. if (minheights <= max_minheights) {
  156325. sptr->rows_in_mem = sptr->rows_in_array;
  156326. } else {
  156327. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156328. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156329. (long) sptr->rows_in_array *
  156330. (long) sptr->samplesperrow *
  156331. (long) SIZEOF(JSAMPLE));
  156332. sptr->b_s_open = TRUE;
  156333. }
  156334. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156335. sptr->samplesperrow, sptr->rows_in_mem);
  156336. sptr->rowsperchunk = mem->last_rowsperchunk;
  156337. sptr->cur_start_row = 0;
  156338. sptr->first_undef_row = 0;
  156339. sptr->dirty = FALSE;
  156340. }
  156341. }
  156342. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156343. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156344. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156345. if (minheights <= max_minheights) {
  156346. bptr->rows_in_mem = bptr->rows_in_array;
  156347. } else {
  156348. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156349. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156350. (long) bptr->rows_in_array *
  156351. (long) bptr->blocksperrow *
  156352. (long) SIZEOF(JBLOCK));
  156353. bptr->b_s_open = TRUE;
  156354. }
  156355. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156356. bptr->blocksperrow, bptr->rows_in_mem);
  156357. bptr->rowsperchunk = mem->last_rowsperchunk;
  156358. bptr->cur_start_row = 0;
  156359. bptr->first_undef_row = 0;
  156360. bptr->dirty = FALSE;
  156361. }
  156362. }
  156363. }
  156364. LOCAL(void)
  156365. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156366. {
  156367. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156368. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156369. file_offset = ptr->cur_start_row * bytesperrow;
  156370. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156371. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156372. thisrow = (long) ptr->cur_start_row + i;
  156373. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156374. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156375. if (rows <= 0) /* this chunk might be past end of file! */
  156376. break;
  156377. byte_count = rows * bytesperrow;
  156378. if (writing)
  156379. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156380. (void FAR *) ptr->mem_buffer[i],
  156381. file_offset, byte_count);
  156382. else
  156383. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156384. (void FAR *) ptr->mem_buffer[i],
  156385. file_offset, byte_count);
  156386. file_offset += byte_count;
  156387. }
  156388. }
  156389. LOCAL(void)
  156390. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156391. {
  156392. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156393. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156394. file_offset = ptr->cur_start_row * bytesperrow;
  156395. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156396. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156397. thisrow = (long) ptr->cur_start_row + i;
  156398. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156399. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156400. if (rows <= 0) /* this chunk might be past end of file! */
  156401. break;
  156402. byte_count = rows * bytesperrow;
  156403. if (writing)
  156404. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156405. (void FAR *) ptr->mem_buffer[i],
  156406. file_offset, byte_count);
  156407. else
  156408. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156409. (void FAR *) ptr->mem_buffer[i],
  156410. file_offset, byte_count);
  156411. file_offset += byte_count;
  156412. }
  156413. }
  156414. METHODDEF(JSAMPARRAY)
  156415. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156416. JDIMENSION start_row, JDIMENSION num_rows,
  156417. boolean writable)
  156418. {
  156419. JDIMENSION end_row = start_row + num_rows;
  156420. JDIMENSION undef_row;
  156421. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156422. ptr->mem_buffer == NULL)
  156423. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156424. if (start_row < ptr->cur_start_row ||
  156425. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156426. if (! ptr->b_s_open)
  156427. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156428. if (ptr->dirty) {
  156429. do_sarray_io(cinfo, ptr, TRUE);
  156430. ptr->dirty = FALSE;
  156431. }
  156432. if (start_row > ptr->cur_start_row) {
  156433. ptr->cur_start_row = start_row;
  156434. } else {
  156435. long ltemp;
  156436. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156437. if (ltemp < 0)
  156438. ltemp = 0; /* don't fall off front end of file */
  156439. ptr->cur_start_row = (JDIMENSION) ltemp;
  156440. }
  156441. do_sarray_io(cinfo, ptr, FALSE);
  156442. }
  156443. if (ptr->first_undef_row < end_row) {
  156444. if (ptr->first_undef_row < start_row) {
  156445. if (writable) /* writer skipped over a section of array */
  156446. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156447. undef_row = start_row; /* but reader is allowed to read ahead */
  156448. } else {
  156449. undef_row = ptr->first_undef_row;
  156450. }
  156451. if (writable)
  156452. ptr->first_undef_row = end_row;
  156453. if (ptr->pre_zero) {
  156454. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156455. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156456. end_row -= ptr->cur_start_row;
  156457. while (undef_row < end_row) {
  156458. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156459. undef_row++;
  156460. }
  156461. } else {
  156462. if (! writable) /* reader looking at undefined data */
  156463. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156464. }
  156465. }
  156466. if (writable)
  156467. ptr->dirty = TRUE;
  156468. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156469. }
  156470. METHODDEF(JBLOCKARRAY)
  156471. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156472. JDIMENSION start_row, JDIMENSION num_rows,
  156473. boolean writable)
  156474. {
  156475. JDIMENSION end_row = start_row + num_rows;
  156476. JDIMENSION undef_row;
  156477. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156478. ptr->mem_buffer == NULL)
  156479. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156480. if (start_row < ptr->cur_start_row ||
  156481. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156482. if (! ptr->b_s_open)
  156483. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156484. if (ptr->dirty) {
  156485. do_barray_io(cinfo, ptr, TRUE);
  156486. ptr->dirty = FALSE;
  156487. }
  156488. if (start_row > ptr->cur_start_row) {
  156489. ptr->cur_start_row = start_row;
  156490. } else {
  156491. long ltemp;
  156492. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156493. if (ltemp < 0)
  156494. ltemp = 0; /* don't fall off front end of file */
  156495. ptr->cur_start_row = (JDIMENSION) ltemp;
  156496. }
  156497. do_barray_io(cinfo, ptr, FALSE);
  156498. }
  156499. if (ptr->first_undef_row < end_row) {
  156500. if (ptr->first_undef_row < start_row) {
  156501. if (writable) /* writer skipped over a section of array */
  156502. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156503. undef_row = start_row; /* but reader is allowed to read ahead */
  156504. } else {
  156505. undef_row = ptr->first_undef_row;
  156506. }
  156507. if (writable)
  156508. ptr->first_undef_row = end_row;
  156509. if (ptr->pre_zero) {
  156510. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156511. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156512. end_row -= ptr->cur_start_row;
  156513. while (undef_row < end_row) {
  156514. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156515. undef_row++;
  156516. }
  156517. } else {
  156518. if (! writable) /* reader looking at undefined data */
  156519. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156520. }
  156521. }
  156522. if (writable)
  156523. ptr->dirty = TRUE;
  156524. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156525. }
  156526. METHODDEF(void)
  156527. free_pool (j_common_ptr cinfo, int pool_id)
  156528. {
  156529. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156530. small_pool_ptr shdr_ptr;
  156531. large_pool_ptr lhdr_ptr;
  156532. size_t space_freed;
  156533. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156534. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156535. #ifdef MEM_STATS
  156536. if (cinfo->err->trace_level > 1)
  156537. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156538. #endif
  156539. if (pool_id == JPOOL_IMAGE) {
  156540. jvirt_sarray_ptr sptr;
  156541. jvirt_barray_ptr bptr;
  156542. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156543. if (sptr->b_s_open) { /* there may be no backing store */
  156544. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156545. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156546. }
  156547. }
  156548. mem->virt_sarray_list = NULL;
  156549. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156550. if (bptr->b_s_open) { /* there may be no backing store */
  156551. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156552. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156553. }
  156554. }
  156555. mem->virt_barray_list = NULL;
  156556. }
  156557. lhdr_ptr = mem->large_list[pool_id];
  156558. mem->large_list[pool_id] = NULL;
  156559. while (lhdr_ptr != NULL) {
  156560. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156561. space_freed = lhdr_ptr->hdr.bytes_used +
  156562. lhdr_ptr->hdr.bytes_left +
  156563. SIZEOF(large_pool_hdr);
  156564. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156565. mem->total_space_allocated -= space_freed;
  156566. lhdr_ptr = next_lhdr_ptr;
  156567. }
  156568. shdr_ptr = mem->small_list[pool_id];
  156569. mem->small_list[pool_id] = NULL;
  156570. while (shdr_ptr != NULL) {
  156571. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156572. space_freed = shdr_ptr->hdr.bytes_used +
  156573. shdr_ptr->hdr.bytes_left +
  156574. SIZEOF(small_pool_hdr);
  156575. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156576. mem->total_space_allocated -= space_freed;
  156577. shdr_ptr = next_shdr_ptr;
  156578. }
  156579. }
  156580. METHODDEF(void)
  156581. self_destruct (j_common_ptr cinfo)
  156582. {
  156583. int pool;
  156584. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156585. free_pool(cinfo, pool);
  156586. }
  156587. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156588. cinfo->mem = NULL; /* ensures I will be called only once */
  156589. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156590. }
  156591. GLOBAL(void)
  156592. jinit_memory_mgr (j_common_ptr cinfo)
  156593. {
  156594. my_mem_ptr mem;
  156595. long max_to_use;
  156596. int pool;
  156597. size_t test_mac;
  156598. cinfo->mem = NULL; /* for safety if init fails */
  156599. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156600. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156601. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156602. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156603. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156604. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156605. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156606. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156607. if (mem == NULL) {
  156608. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156609. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156610. }
  156611. mem->pub.alloc_small = alloc_small;
  156612. mem->pub.alloc_large = alloc_large;
  156613. mem->pub.alloc_sarray = alloc_sarray;
  156614. mem->pub.alloc_barray = alloc_barray;
  156615. mem->pub.request_virt_sarray = request_virt_sarray;
  156616. mem->pub.request_virt_barray = request_virt_barray;
  156617. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156618. mem->pub.access_virt_sarray = access_virt_sarray;
  156619. mem->pub.access_virt_barray = access_virt_barray;
  156620. mem->pub.free_pool = free_pool;
  156621. mem->pub.self_destruct = self_destruct;
  156622. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156623. mem->pub.max_memory_to_use = max_to_use;
  156624. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156625. mem->small_list[pool] = NULL;
  156626. mem->large_list[pool] = NULL;
  156627. }
  156628. mem->virt_sarray_list = NULL;
  156629. mem->virt_barray_list = NULL;
  156630. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156631. cinfo->mem = & mem->pub;
  156632. #ifndef NO_GETENV
  156633. { char * memenv;
  156634. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156635. char ch = 'x';
  156636. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156637. if (ch == 'm' || ch == 'M')
  156638. max_to_use *= 1000L;
  156639. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156640. }
  156641. }
  156642. }
  156643. #endif
  156644. }
  156645. /*** End of inlined file: jmemmgr.c ***/
  156646. /*** Start of inlined file: jmemnobs.c ***/
  156647. #define JPEG_INTERNALS
  156648. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156649. extern void * malloc JPP((size_t size));
  156650. extern void free JPP((void *ptr));
  156651. #endif
  156652. GLOBAL(void *)
  156653. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156654. {
  156655. return (void *) malloc(sizeofobject);
  156656. }
  156657. GLOBAL(void)
  156658. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156659. {
  156660. free(object);
  156661. }
  156662. GLOBAL(void FAR *)
  156663. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156664. {
  156665. return (void FAR *) malloc(sizeofobject);
  156666. }
  156667. GLOBAL(void)
  156668. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156669. {
  156670. free(object);
  156671. }
  156672. GLOBAL(long)
  156673. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156674. long max_bytes_needed, long already_allocated)
  156675. {
  156676. return max_bytes_needed;
  156677. }
  156678. GLOBAL(void)
  156679. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156680. long total_bytes_needed)
  156681. {
  156682. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156683. }
  156684. GLOBAL(long)
  156685. jpeg_mem_init (j_common_ptr cinfo)
  156686. {
  156687. return 0; /* just set max_memory_to_use to 0 */
  156688. }
  156689. GLOBAL(void)
  156690. jpeg_mem_term (j_common_ptr cinfo)
  156691. {
  156692. }
  156693. /*** End of inlined file: jmemnobs.c ***/
  156694. /*** Start of inlined file: jquant1.c ***/
  156695. #define JPEG_INTERNALS
  156696. #ifdef QUANT_1PASS_SUPPORTED
  156697. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156698. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156699. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156700. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156701. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156702. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156703. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156704. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156705. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156706. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156707. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156708. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156709. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156710. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156711. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156712. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156713. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156714. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156715. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156716. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156717. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156718. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156719. };
  156720. #if BITS_IN_JSAMPLE == 8
  156721. typedef INT16 FSERROR; /* 16 bits should be enough */
  156722. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156723. #else
  156724. typedef INT32 FSERROR; /* may need more than 16 bits */
  156725. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156726. #endif
  156727. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156728. #define MAX_Q_COMPS 4 /* max components I can handle */
  156729. typedef struct {
  156730. struct jpeg_color_quantizer pub; /* public fields */
  156731. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156732. int sv_actual; /* number of entries in use */
  156733. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156734. boolean is_padded; /* is the colorindex padded for odither? */
  156735. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156736. int row_index; /* cur row's vertical index in dither matrix */
  156737. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156738. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156739. boolean on_odd_row; /* flag to remember which row we are on */
  156740. } my_cquantizer;
  156741. typedef my_cquantizer * my_cquantize_ptr;
  156742. LOCAL(int)
  156743. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156744. {
  156745. int nc = cinfo->out_color_components; /* number of color components */
  156746. int max_colors = cinfo->desired_number_of_colors;
  156747. int total_colors, iroot, i, j;
  156748. boolean changed;
  156749. long temp;
  156750. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156751. iroot = 1;
  156752. do {
  156753. iroot++;
  156754. temp = iroot; /* set temp = iroot ** nc */
  156755. for (i = 1; i < nc; i++)
  156756. temp *= iroot;
  156757. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156758. iroot--; /* now iroot = floor(root) */
  156759. if (iroot < 2)
  156760. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156761. total_colors = 1;
  156762. for (i = 0; i < nc; i++) {
  156763. Ncolors[i] = iroot;
  156764. total_colors *= iroot;
  156765. }
  156766. do {
  156767. changed = FALSE;
  156768. for (i = 0; i < nc; i++) {
  156769. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156770. temp = total_colors / Ncolors[j];
  156771. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156772. if (temp > (long) max_colors)
  156773. break; /* won't fit, done with this pass */
  156774. Ncolors[j]++; /* OK, apply the increment */
  156775. total_colors = (int) temp;
  156776. changed = TRUE;
  156777. }
  156778. } while (changed);
  156779. return total_colors;
  156780. }
  156781. LOCAL(int)
  156782. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156783. {
  156784. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156785. }
  156786. LOCAL(int)
  156787. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156788. {
  156789. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156790. }
  156791. LOCAL(void)
  156792. create_colormap (j_decompress_ptr cinfo)
  156793. {
  156794. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156795. JSAMPARRAY colormap; /* Created colormap */
  156796. int total_colors; /* Number of distinct output colors */
  156797. int i,j,k, nci, blksize, blkdist, ptr, val;
  156798. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156799. if (cinfo->out_color_components == 3)
  156800. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156801. total_colors, cquantize->Ncolors[0],
  156802. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156803. else
  156804. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156805. colormap = (*cinfo->mem->alloc_sarray)
  156806. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156807. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156808. blkdist = total_colors;
  156809. for (i = 0; i < cinfo->out_color_components; i++) {
  156810. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156811. blksize = blkdist / nci;
  156812. for (j = 0; j < nci; j++) {
  156813. val = output_value(cinfo, i, j, nci-1);
  156814. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156815. for (k = 0; k < blksize; k++)
  156816. colormap[i][ptr+k] = (JSAMPLE) val;
  156817. }
  156818. }
  156819. blkdist = blksize; /* blksize of this color is blkdist of next */
  156820. }
  156821. cquantize->sv_colormap = colormap;
  156822. cquantize->sv_actual = total_colors;
  156823. }
  156824. LOCAL(void)
  156825. create_colorindex (j_decompress_ptr cinfo)
  156826. {
  156827. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156828. JSAMPROW indexptr;
  156829. int i,j,k, nci, blksize, val, pad;
  156830. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156831. pad = MAXJSAMPLE*2;
  156832. cquantize->is_padded = TRUE;
  156833. } else {
  156834. pad = 0;
  156835. cquantize->is_padded = FALSE;
  156836. }
  156837. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156838. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156839. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156840. (JDIMENSION) cinfo->out_color_components);
  156841. blksize = cquantize->sv_actual;
  156842. for (i = 0; i < cinfo->out_color_components; i++) {
  156843. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156844. blksize = blksize / nci;
  156845. if (pad)
  156846. cquantize->colorindex[i] += MAXJSAMPLE;
  156847. indexptr = cquantize->colorindex[i];
  156848. val = 0;
  156849. k = largest_input_value(cinfo, i, 0, nci-1);
  156850. for (j = 0; j <= MAXJSAMPLE; j++) {
  156851. while (j > k) /* advance val if past boundary */
  156852. k = largest_input_value(cinfo, i, ++val, nci-1);
  156853. indexptr[j] = (JSAMPLE) (val * blksize);
  156854. }
  156855. if (pad)
  156856. for (j = 1; j <= MAXJSAMPLE; j++) {
  156857. indexptr[-j] = indexptr[0];
  156858. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156859. }
  156860. }
  156861. }
  156862. LOCAL(ODITHER_MATRIX_PTR)
  156863. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156864. {
  156865. ODITHER_MATRIX_PTR odither;
  156866. int j,k;
  156867. INT32 num,den;
  156868. odither = (ODITHER_MATRIX_PTR)
  156869. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156870. SIZEOF(ODITHER_MATRIX));
  156871. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156872. for (j = 0; j < ODITHER_SIZE; j++) {
  156873. for (k = 0; k < ODITHER_SIZE; k++) {
  156874. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156875. * MAXJSAMPLE;
  156876. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156877. }
  156878. }
  156879. return odither;
  156880. }
  156881. LOCAL(void)
  156882. create_odither_tables (j_decompress_ptr cinfo)
  156883. {
  156884. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156885. ODITHER_MATRIX_PTR odither;
  156886. int i, j, nci;
  156887. for (i = 0; i < cinfo->out_color_components; i++) {
  156888. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156889. odither = NULL; /* search for matching prior component */
  156890. for (j = 0; j < i; j++) {
  156891. if (nci == cquantize->Ncolors[j]) {
  156892. odither = cquantize->odither[j];
  156893. break;
  156894. }
  156895. }
  156896. if (odither == NULL) /* need a new table? */
  156897. odither = make_odither_array(cinfo, nci);
  156898. cquantize->odither[i] = odither;
  156899. }
  156900. }
  156901. METHODDEF(void)
  156902. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156903. JSAMPARRAY output_buf, int num_rows)
  156904. {
  156905. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156906. JSAMPARRAY colorindex = cquantize->colorindex;
  156907. register int pixcode, ci;
  156908. register JSAMPROW ptrin, ptrout;
  156909. int row;
  156910. JDIMENSION col;
  156911. JDIMENSION width = cinfo->output_width;
  156912. register int nc = cinfo->out_color_components;
  156913. for (row = 0; row < num_rows; row++) {
  156914. ptrin = input_buf[row];
  156915. ptrout = output_buf[row];
  156916. for (col = width; col > 0; col--) {
  156917. pixcode = 0;
  156918. for (ci = 0; ci < nc; ci++) {
  156919. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  156920. }
  156921. *ptrout++ = (JSAMPLE) pixcode;
  156922. }
  156923. }
  156924. }
  156925. METHODDEF(void)
  156926. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156927. JSAMPARRAY output_buf, int num_rows)
  156928. {
  156929. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156930. register int pixcode;
  156931. register JSAMPROW ptrin, ptrout;
  156932. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156933. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156934. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156935. int row;
  156936. JDIMENSION col;
  156937. JDIMENSION width = cinfo->output_width;
  156938. for (row = 0; row < num_rows; row++) {
  156939. ptrin = input_buf[row];
  156940. ptrout = output_buf[row];
  156941. for (col = width; col > 0; col--) {
  156942. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  156943. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  156944. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  156945. *ptrout++ = (JSAMPLE) pixcode;
  156946. }
  156947. }
  156948. }
  156949. METHODDEF(void)
  156950. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156951. JSAMPARRAY output_buf, int num_rows)
  156952. {
  156953. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156954. register JSAMPROW input_ptr;
  156955. register JSAMPROW output_ptr;
  156956. JSAMPROW colorindex_ci;
  156957. int * dither; /* points to active row of dither matrix */
  156958. int row_index, col_index; /* current indexes into dither matrix */
  156959. int nc = cinfo->out_color_components;
  156960. int ci;
  156961. int row;
  156962. JDIMENSION col;
  156963. JDIMENSION width = cinfo->output_width;
  156964. for (row = 0; row < num_rows; row++) {
  156965. jzero_far((void FAR *) output_buf[row],
  156966. (size_t) (width * SIZEOF(JSAMPLE)));
  156967. row_index = cquantize->row_index;
  156968. for (ci = 0; ci < nc; ci++) {
  156969. input_ptr = input_buf[row] + ci;
  156970. output_ptr = output_buf[row];
  156971. colorindex_ci = cquantize->colorindex[ci];
  156972. dither = cquantize->odither[ci][row_index];
  156973. col_index = 0;
  156974. for (col = width; col > 0; col--) {
  156975. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  156976. input_ptr += nc;
  156977. output_ptr++;
  156978. col_index = (col_index + 1) & ODITHER_MASK;
  156979. }
  156980. }
  156981. row_index = (row_index + 1) & ODITHER_MASK;
  156982. cquantize->row_index = row_index;
  156983. }
  156984. }
  156985. METHODDEF(void)
  156986. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156987. JSAMPARRAY output_buf, int num_rows)
  156988. {
  156989. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156990. register int pixcode;
  156991. register JSAMPROW input_ptr;
  156992. register JSAMPROW output_ptr;
  156993. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156994. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156995. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156996. int * dither0; /* points to active row of dither matrix */
  156997. int * dither1;
  156998. int * dither2;
  156999. int row_index, col_index; /* current indexes into dither matrix */
  157000. int row;
  157001. JDIMENSION col;
  157002. JDIMENSION width = cinfo->output_width;
  157003. for (row = 0; row < num_rows; row++) {
  157004. row_index = cquantize->row_index;
  157005. input_ptr = input_buf[row];
  157006. output_ptr = output_buf[row];
  157007. dither0 = cquantize->odither[0][row_index];
  157008. dither1 = cquantize->odither[1][row_index];
  157009. dither2 = cquantize->odither[2][row_index];
  157010. col_index = 0;
  157011. for (col = width; col > 0; col--) {
  157012. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157013. dither0[col_index]]);
  157014. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157015. dither1[col_index]]);
  157016. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157017. dither2[col_index]]);
  157018. *output_ptr++ = (JSAMPLE) pixcode;
  157019. col_index = (col_index + 1) & ODITHER_MASK;
  157020. }
  157021. row_index = (row_index + 1) & ODITHER_MASK;
  157022. cquantize->row_index = row_index;
  157023. }
  157024. }
  157025. METHODDEF(void)
  157026. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157027. JSAMPARRAY output_buf, int num_rows)
  157028. {
  157029. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157030. register LOCFSERROR cur; /* current error or pixel value */
  157031. LOCFSERROR belowerr; /* error for pixel below cur */
  157032. LOCFSERROR bpreverr; /* error for below/prev col */
  157033. LOCFSERROR bnexterr; /* error for below/next col */
  157034. LOCFSERROR delta;
  157035. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157036. register JSAMPROW input_ptr;
  157037. register JSAMPROW output_ptr;
  157038. JSAMPROW colorindex_ci;
  157039. JSAMPROW colormap_ci;
  157040. int pixcode;
  157041. int nc = cinfo->out_color_components;
  157042. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157043. int dirnc; /* dir * nc */
  157044. int ci;
  157045. int row;
  157046. JDIMENSION col;
  157047. JDIMENSION width = cinfo->output_width;
  157048. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157049. SHIFT_TEMPS
  157050. for (row = 0; row < num_rows; row++) {
  157051. jzero_far((void FAR *) output_buf[row],
  157052. (size_t) (width * SIZEOF(JSAMPLE)));
  157053. for (ci = 0; ci < nc; ci++) {
  157054. input_ptr = input_buf[row] + ci;
  157055. output_ptr = output_buf[row];
  157056. if (cquantize->on_odd_row) {
  157057. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157058. output_ptr += width-1;
  157059. dir = -1;
  157060. dirnc = -nc;
  157061. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157062. } else {
  157063. dir = 1;
  157064. dirnc = nc;
  157065. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157066. }
  157067. colorindex_ci = cquantize->colorindex[ci];
  157068. colormap_ci = cquantize->sv_colormap[ci];
  157069. cur = 0;
  157070. belowerr = bpreverr = 0;
  157071. for (col = width; col > 0; col--) {
  157072. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157073. cur += GETJSAMPLE(*input_ptr);
  157074. cur = GETJSAMPLE(range_limit[cur]);
  157075. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157076. *output_ptr += (JSAMPLE) pixcode;
  157077. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157078. bnexterr = cur;
  157079. delta = cur * 2;
  157080. cur += delta; /* form error * 3 */
  157081. errorptr[0] = (FSERROR) (bpreverr + cur);
  157082. cur += delta; /* form error * 5 */
  157083. bpreverr = belowerr + cur;
  157084. belowerr = bnexterr;
  157085. cur += delta; /* form error * 7 */
  157086. input_ptr += dirnc; /* advance input ptr to next column */
  157087. output_ptr += dir; /* advance output ptr to next column */
  157088. errorptr += dir; /* advance errorptr to current column */
  157089. }
  157090. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157091. }
  157092. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157093. }
  157094. }
  157095. LOCAL(void)
  157096. alloc_fs_workspace (j_decompress_ptr cinfo)
  157097. {
  157098. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157099. size_t arraysize;
  157100. int i;
  157101. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157102. for (i = 0; i < cinfo->out_color_components; i++) {
  157103. cquantize->fserrors[i] = (FSERRPTR)
  157104. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157105. }
  157106. }
  157107. METHODDEF(void)
  157108. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157109. {
  157110. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157111. size_t arraysize;
  157112. int i;
  157113. cinfo->colormap = cquantize->sv_colormap;
  157114. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157115. switch (cinfo->dither_mode) {
  157116. case JDITHER_NONE:
  157117. if (cinfo->out_color_components == 3)
  157118. cquantize->pub.color_quantize = color_quantize3;
  157119. else
  157120. cquantize->pub.color_quantize = color_quantize;
  157121. break;
  157122. case JDITHER_ORDERED:
  157123. if (cinfo->out_color_components == 3)
  157124. cquantize->pub.color_quantize = quantize3_ord_dither;
  157125. else
  157126. cquantize->pub.color_quantize = quantize_ord_dither;
  157127. cquantize->row_index = 0; /* initialize state for ordered dither */
  157128. if (! cquantize->is_padded)
  157129. create_colorindex(cinfo);
  157130. if (cquantize->odither[0] == NULL)
  157131. create_odither_tables(cinfo);
  157132. break;
  157133. case JDITHER_FS:
  157134. cquantize->pub.color_quantize = quantize_fs_dither;
  157135. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157136. if (cquantize->fserrors[0] == NULL)
  157137. alloc_fs_workspace(cinfo);
  157138. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157139. for (i = 0; i < cinfo->out_color_components; i++)
  157140. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157141. break;
  157142. default:
  157143. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157144. break;
  157145. }
  157146. }
  157147. METHODDEF(void)
  157148. finish_pass_1_quant (j_decompress_ptr cinfo)
  157149. {
  157150. }
  157151. METHODDEF(void)
  157152. new_color_map_1_quant (j_decompress_ptr cinfo)
  157153. {
  157154. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157155. }
  157156. GLOBAL(void)
  157157. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157158. {
  157159. my_cquantize_ptr cquantize;
  157160. cquantize = (my_cquantize_ptr)
  157161. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157162. SIZEOF(my_cquantizer));
  157163. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157164. cquantize->pub.start_pass = start_pass_1_quant;
  157165. cquantize->pub.finish_pass = finish_pass_1_quant;
  157166. cquantize->pub.new_color_map = new_color_map_1_quant;
  157167. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157168. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157169. if (cinfo->out_color_components > MAX_Q_COMPS)
  157170. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157171. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157172. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157173. create_colormap(cinfo);
  157174. create_colorindex(cinfo);
  157175. if (cinfo->dither_mode == JDITHER_FS)
  157176. alloc_fs_workspace(cinfo);
  157177. }
  157178. #endif /* QUANT_1PASS_SUPPORTED */
  157179. /*** End of inlined file: jquant1.c ***/
  157180. /*** Start of inlined file: jquant2.c ***/
  157181. #define JPEG_INTERNALS
  157182. #ifdef QUANT_2PASS_SUPPORTED
  157183. #define R_SCALE 2 /* scale R distances by this much */
  157184. #define G_SCALE 3 /* scale G distances by this much */
  157185. #define B_SCALE 1 /* and B by this much */
  157186. #if RGB_RED == 0
  157187. #define C0_SCALE R_SCALE
  157188. #endif
  157189. #if RGB_BLUE == 0
  157190. #define C0_SCALE B_SCALE
  157191. #endif
  157192. #if RGB_GREEN == 1
  157193. #define C1_SCALE G_SCALE
  157194. #endif
  157195. #if RGB_RED == 2
  157196. #define C2_SCALE R_SCALE
  157197. #endif
  157198. #if RGB_BLUE == 2
  157199. #define C2_SCALE B_SCALE
  157200. #endif
  157201. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157202. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157203. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157204. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157205. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157206. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157207. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157208. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157209. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157210. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157211. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157212. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157213. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157214. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157215. typedef hist2d * hist3d; /* type for top-level pointer */
  157216. #if BITS_IN_JSAMPLE == 8
  157217. typedef INT16 FSERROR; /* 16 bits should be enough */
  157218. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157219. #else
  157220. typedef INT32 FSERROR; /* may need more than 16 bits */
  157221. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157222. #endif
  157223. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157224. typedef struct {
  157225. struct jpeg_color_quantizer pub; /* public fields */
  157226. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157227. int desired; /* desired # of colors = size of colormap */
  157228. hist3d histogram; /* pointer to the histogram */
  157229. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157230. FSERRPTR fserrors; /* accumulated errors */
  157231. boolean on_odd_row; /* flag to remember which row we are on */
  157232. int * error_limiter; /* table for clamping the applied error */
  157233. } my_cquantizer2;
  157234. typedef my_cquantizer2 * my_cquantize_ptr2;
  157235. METHODDEF(void)
  157236. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157237. JSAMPARRAY output_buf, int num_rows)
  157238. {
  157239. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157240. register JSAMPROW ptr;
  157241. register histptr histp;
  157242. register hist3d histogram = cquantize->histogram;
  157243. int row;
  157244. JDIMENSION col;
  157245. JDIMENSION width = cinfo->output_width;
  157246. for (row = 0; row < num_rows; row++) {
  157247. ptr = input_buf[row];
  157248. for (col = width; col > 0; col--) {
  157249. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157250. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157251. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157252. if (++(*histp) <= 0)
  157253. (*histp)--;
  157254. ptr += 3;
  157255. }
  157256. }
  157257. }
  157258. typedef struct {
  157259. int c0min, c0max;
  157260. int c1min, c1max;
  157261. int c2min, c2max;
  157262. INT32 volume;
  157263. long colorcount;
  157264. } box;
  157265. typedef box * boxptr;
  157266. LOCAL(boxptr)
  157267. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157268. {
  157269. register boxptr boxp;
  157270. register int i;
  157271. register long maxc = 0;
  157272. boxptr which = NULL;
  157273. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157274. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157275. which = boxp;
  157276. maxc = boxp->colorcount;
  157277. }
  157278. }
  157279. return which;
  157280. }
  157281. LOCAL(boxptr)
  157282. find_biggest_volume (boxptr boxlist, int numboxes)
  157283. {
  157284. register boxptr boxp;
  157285. register int i;
  157286. register INT32 maxv = 0;
  157287. boxptr which = NULL;
  157288. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157289. if (boxp->volume > maxv) {
  157290. which = boxp;
  157291. maxv = boxp->volume;
  157292. }
  157293. }
  157294. return which;
  157295. }
  157296. LOCAL(void)
  157297. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157298. {
  157299. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157300. hist3d histogram = cquantize->histogram;
  157301. histptr histp;
  157302. int c0,c1,c2;
  157303. int c0min,c0max,c1min,c1max,c2min,c2max;
  157304. INT32 dist0,dist1,dist2;
  157305. long ccount;
  157306. c0min = boxp->c0min; c0max = boxp->c0max;
  157307. c1min = boxp->c1min; c1max = boxp->c1max;
  157308. c2min = boxp->c2min; c2max = boxp->c2max;
  157309. if (c0max > c0min)
  157310. for (c0 = c0min; c0 <= c0max; c0++)
  157311. for (c1 = c1min; c1 <= c1max; c1++) {
  157312. histp = & histogram[c0][c1][c2min];
  157313. for (c2 = c2min; c2 <= c2max; c2++)
  157314. if (*histp++ != 0) {
  157315. boxp->c0min = c0min = c0;
  157316. goto have_c0min;
  157317. }
  157318. }
  157319. have_c0min:
  157320. if (c0max > c0min)
  157321. for (c0 = c0max; c0 >= c0min; c0--)
  157322. for (c1 = c1min; c1 <= c1max; c1++) {
  157323. histp = & histogram[c0][c1][c2min];
  157324. for (c2 = c2min; c2 <= c2max; c2++)
  157325. if (*histp++ != 0) {
  157326. boxp->c0max = c0max = c0;
  157327. goto have_c0max;
  157328. }
  157329. }
  157330. have_c0max:
  157331. if (c1max > c1min)
  157332. for (c1 = c1min; c1 <= c1max; c1++)
  157333. for (c0 = c0min; c0 <= c0max; c0++) {
  157334. histp = & histogram[c0][c1][c2min];
  157335. for (c2 = c2min; c2 <= c2max; c2++)
  157336. if (*histp++ != 0) {
  157337. boxp->c1min = c1min = c1;
  157338. goto have_c1min;
  157339. }
  157340. }
  157341. have_c1min:
  157342. if (c1max > c1min)
  157343. for (c1 = c1max; c1 >= c1min; c1--)
  157344. for (c0 = c0min; c0 <= c0max; c0++) {
  157345. histp = & histogram[c0][c1][c2min];
  157346. for (c2 = c2min; c2 <= c2max; c2++)
  157347. if (*histp++ != 0) {
  157348. boxp->c1max = c1max = c1;
  157349. goto have_c1max;
  157350. }
  157351. }
  157352. have_c1max:
  157353. if (c2max > c2min)
  157354. for (c2 = c2min; c2 <= c2max; c2++)
  157355. for (c0 = c0min; c0 <= c0max; c0++) {
  157356. histp = & histogram[c0][c1min][c2];
  157357. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157358. if (*histp != 0) {
  157359. boxp->c2min = c2min = c2;
  157360. goto have_c2min;
  157361. }
  157362. }
  157363. have_c2min:
  157364. if (c2max > c2min)
  157365. for (c2 = c2max; c2 >= c2min; c2--)
  157366. for (c0 = c0min; c0 <= c0max; c0++) {
  157367. histp = & histogram[c0][c1min][c2];
  157368. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157369. if (*histp != 0) {
  157370. boxp->c2max = c2max = c2;
  157371. goto have_c2max;
  157372. }
  157373. }
  157374. have_c2max:
  157375. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157376. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157377. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157378. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157379. ccount = 0;
  157380. for (c0 = c0min; c0 <= c0max; c0++)
  157381. for (c1 = c1min; c1 <= c1max; c1++) {
  157382. histp = & histogram[c0][c1][c2min];
  157383. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157384. if (*histp != 0) {
  157385. ccount++;
  157386. }
  157387. }
  157388. boxp->colorcount = ccount;
  157389. }
  157390. LOCAL(int)
  157391. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157392. int desired_colors)
  157393. {
  157394. int n,lb;
  157395. int c0,c1,c2,cmax;
  157396. register boxptr b1,b2;
  157397. while (numboxes < desired_colors) {
  157398. if (numboxes*2 <= desired_colors) {
  157399. b1 = find_biggest_color_pop(boxlist, numboxes);
  157400. } else {
  157401. b1 = find_biggest_volume(boxlist, numboxes);
  157402. }
  157403. if (b1 == NULL) /* no splittable boxes left! */
  157404. break;
  157405. b2 = &boxlist[numboxes]; /* where new box will go */
  157406. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157407. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157408. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157409. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157410. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157411. #if RGB_RED == 0
  157412. cmax = c1; n = 1;
  157413. if (c0 > cmax) { cmax = c0; n = 0; }
  157414. if (c2 > cmax) { n = 2; }
  157415. #else
  157416. cmax = c1; n = 1;
  157417. if (c2 > cmax) { cmax = c2; n = 2; }
  157418. if (c0 > cmax) { n = 0; }
  157419. #endif
  157420. switch (n) {
  157421. case 0:
  157422. lb = (b1->c0max + b1->c0min) / 2;
  157423. b1->c0max = lb;
  157424. b2->c0min = lb+1;
  157425. break;
  157426. case 1:
  157427. lb = (b1->c1max + b1->c1min) / 2;
  157428. b1->c1max = lb;
  157429. b2->c1min = lb+1;
  157430. break;
  157431. case 2:
  157432. lb = (b1->c2max + b1->c2min) / 2;
  157433. b1->c2max = lb;
  157434. b2->c2min = lb+1;
  157435. break;
  157436. }
  157437. update_box(cinfo, b1);
  157438. update_box(cinfo, b2);
  157439. numboxes++;
  157440. }
  157441. return numboxes;
  157442. }
  157443. LOCAL(void)
  157444. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157445. {
  157446. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157447. hist3d histogram = cquantize->histogram;
  157448. histptr histp;
  157449. int c0,c1,c2;
  157450. int c0min,c0max,c1min,c1max,c2min,c2max;
  157451. long count;
  157452. long total = 0;
  157453. long c0total = 0;
  157454. long c1total = 0;
  157455. long c2total = 0;
  157456. c0min = boxp->c0min; c0max = boxp->c0max;
  157457. c1min = boxp->c1min; c1max = boxp->c1max;
  157458. c2min = boxp->c2min; c2max = boxp->c2max;
  157459. for (c0 = c0min; c0 <= c0max; c0++)
  157460. for (c1 = c1min; c1 <= c1max; c1++) {
  157461. histp = & histogram[c0][c1][c2min];
  157462. for (c2 = c2min; c2 <= c2max; c2++) {
  157463. if ((count = *histp++) != 0) {
  157464. total += count;
  157465. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157466. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157467. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157468. }
  157469. }
  157470. }
  157471. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157472. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157473. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157474. }
  157475. LOCAL(void)
  157476. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157477. {
  157478. boxptr boxlist;
  157479. int numboxes;
  157480. int i;
  157481. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157482. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157483. numboxes = 1;
  157484. boxlist[0].c0min = 0;
  157485. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157486. boxlist[0].c1min = 0;
  157487. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157488. boxlist[0].c2min = 0;
  157489. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157490. update_box(cinfo, & boxlist[0]);
  157491. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157492. for (i = 0; i < numboxes; i++)
  157493. compute_color(cinfo, & boxlist[i], i);
  157494. cinfo->actual_number_of_colors = numboxes;
  157495. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157496. }
  157497. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157498. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157499. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157500. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157501. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157502. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157503. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157504. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157505. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157506. LOCAL(int)
  157507. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157508. JSAMPLE colorlist[])
  157509. {
  157510. int numcolors = cinfo->actual_number_of_colors;
  157511. int maxc0, maxc1, maxc2;
  157512. int centerc0, centerc1, centerc2;
  157513. int i, x, ncolors;
  157514. INT32 minmaxdist, min_dist, max_dist, tdist;
  157515. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157516. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157517. centerc0 = (minc0 + maxc0) >> 1;
  157518. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157519. centerc1 = (minc1 + maxc1) >> 1;
  157520. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157521. centerc2 = (minc2 + maxc2) >> 1;
  157522. minmaxdist = 0x7FFFFFFFL;
  157523. for (i = 0; i < numcolors; i++) {
  157524. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157525. if (x < minc0) {
  157526. tdist = (x - minc0) * C0_SCALE;
  157527. min_dist = tdist*tdist;
  157528. tdist = (x - maxc0) * C0_SCALE;
  157529. max_dist = tdist*tdist;
  157530. } else if (x > maxc0) {
  157531. tdist = (x - maxc0) * C0_SCALE;
  157532. min_dist = tdist*tdist;
  157533. tdist = (x - minc0) * C0_SCALE;
  157534. max_dist = tdist*tdist;
  157535. } else {
  157536. min_dist = 0;
  157537. if (x <= centerc0) {
  157538. tdist = (x - maxc0) * C0_SCALE;
  157539. max_dist = tdist*tdist;
  157540. } else {
  157541. tdist = (x - minc0) * C0_SCALE;
  157542. max_dist = tdist*tdist;
  157543. }
  157544. }
  157545. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157546. if (x < minc1) {
  157547. tdist = (x - minc1) * C1_SCALE;
  157548. min_dist += tdist*tdist;
  157549. tdist = (x - maxc1) * C1_SCALE;
  157550. max_dist += tdist*tdist;
  157551. } else if (x > maxc1) {
  157552. tdist = (x - maxc1) * C1_SCALE;
  157553. min_dist += tdist*tdist;
  157554. tdist = (x - minc1) * C1_SCALE;
  157555. max_dist += tdist*tdist;
  157556. } else {
  157557. if (x <= centerc1) {
  157558. tdist = (x - maxc1) * C1_SCALE;
  157559. max_dist += tdist*tdist;
  157560. } else {
  157561. tdist = (x - minc1) * C1_SCALE;
  157562. max_dist += tdist*tdist;
  157563. }
  157564. }
  157565. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157566. if (x < minc2) {
  157567. tdist = (x - minc2) * C2_SCALE;
  157568. min_dist += tdist*tdist;
  157569. tdist = (x - maxc2) * C2_SCALE;
  157570. max_dist += tdist*tdist;
  157571. } else if (x > maxc2) {
  157572. tdist = (x - maxc2) * C2_SCALE;
  157573. min_dist += tdist*tdist;
  157574. tdist = (x - minc2) * C2_SCALE;
  157575. max_dist += tdist*tdist;
  157576. } else {
  157577. if (x <= centerc2) {
  157578. tdist = (x - maxc2) * C2_SCALE;
  157579. max_dist += tdist*tdist;
  157580. } else {
  157581. tdist = (x - minc2) * C2_SCALE;
  157582. max_dist += tdist*tdist;
  157583. }
  157584. }
  157585. mindist[i] = min_dist; /* save away the results */
  157586. if (max_dist < minmaxdist)
  157587. minmaxdist = max_dist;
  157588. }
  157589. ncolors = 0;
  157590. for (i = 0; i < numcolors; i++) {
  157591. if (mindist[i] <= minmaxdist)
  157592. colorlist[ncolors++] = (JSAMPLE) i;
  157593. }
  157594. return ncolors;
  157595. }
  157596. LOCAL(void)
  157597. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157598. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157599. {
  157600. int ic0, ic1, ic2;
  157601. int i, icolor;
  157602. register INT32 * bptr; /* pointer into bestdist[] array */
  157603. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157604. INT32 dist0, dist1; /* initial distance values */
  157605. register INT32 dist2; /* current distance in inner loop */
  157606. INT32 xx0, xx1; /* distance increments */
  157607. register INT32 xx2;
  157608. INT32 inc0, inc1, inc2; /* initial values for increments */
  157609. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157610. bptr = bestdist;
  157611. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157612. *bptr++ = 0x7FFFFFFFL;
  157613. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157614. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157615. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157616. for (i = 0; i < numcolors; i++) {
  157617. icolor = GETJSAMPLE(colorlist[i]);
  157618. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157619. dist0 = inc0*inc0;
  157620. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157621. dist0 += inc1*inc1;
  157622. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157623. dist0 += inc2*inc2;
  157624. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157625. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157626. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157627. bptr = bestdist;
  157628. cptr = bestcolor;
  157629. xx0 = inc0;
  157630. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157631. dist1 = dist0;
  157632. xx1 = inc1;
  157633. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157634. dist2 = dist1;
  157635. xx2 = inc2;
  157636. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157637. if (dist2 < *bptr) {
  157638. *bptr = dist2;
  157639. *cptr = (JSAMPLE) icolor;
  157640. }
  157641. dist2 += xx2;
  157642. xx2 += 2 * STEP_C2 * STEP_C2;
  157643. bptr++;
  157644. cptr++;
  157645. }
  157646. dist1 += xx1;
  157647. xx1 += 2 * STEP_C1 * STEP_C1;
  157648. }
  157649. dist0 += xx0;
  157650. xx0 += 2 * STEP_C0 * STEP_C0;
  157651. }
  157652. }
  157653. }
  157654. LOCAL(void)
  157655. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157656. {
  157657. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157658. hist3d histogram = cquantize->histogram;
  157659. int minc0, minc1, minc2; /* lower left corner of update box */
  157660. int ic0, ic1, ic2;
  157661. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157662. register histptr cachep; /* pointer into main cache array */
  157663. JSAMPLE colorlist[MAXNUMCOLORS];
  157664. int numcolors; /* number of candidate colors */
  157665. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157666. c0 >>= BOX_C0_LOG;
  157667. c1 >>= BOX_C1_LOG;
  157668. c2 >>= BOX_C2_LOG;
  157669. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157670. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157671. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157672. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157673. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157674. bestcolor);
  157675. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157676. c1 <<= BOX_C1_LOG;
  157677. c2 <<= BOX_C2_LOG;
  157678. cptr = bestcolor;
  157679. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157680. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157681. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157682. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157683. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157684. }
  157685. }
  157686. }
  157687. }
  157688. METHODDEF(void)
  157689. pass2_no_dither (j_decompress_ptr cinfo,
  157690. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157691. {
  157692. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157693. hist3d histogram = cquantize->histogram;
  157694. register JSAMPROW inptr, outptr;
  157695. register histptr cachep;
  157696. register int c0, c1, c2;
  157697. int row;
  157698. JDIMENSION col;
  157699. JDIMENSION width = cinfo->output_width;
  157700. for (row = 0; row < num_rows; row++) {
  157701. inptr = input_buf[row];
  157702. outptr = output_buf[row];
  157703. for (col = width; col > 0; col--) {
  157704. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157705. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157706. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157707. cachep = & histogram[c0][c1][c2];
  157708. if (*cachep == 0)
  157709. fill_inverse_cmap(cinfo, c0,c1,c2);
  157710. *outptr++ = (JSAMPLE) (*cachep - 1);
  157711. }
  157712. }
  157713. }
  157714. METHODDEF(void)
  157715. pass2_fs_dither (j_decompress_ptr cinfo,
  157716. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157717. {
  157718. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157719. hist3d histogram = cquantize->histogram;
  157720. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157721. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157722. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157723. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157724. JSAMPROW inptr; /* => current input pixel */
  157725. JSAMPROW outptr; /* => current output pixel */
  157726. histptr cachep;
  157727. int dir; /* +1 or -1 depending on direction */
  157728. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157729. int row;
  157730. JDIMENSION col;
  157731. JDIMENSION width = cinfo->output_width;
  157732. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157733. int *error_limit = cquantize->error_limiter;
  157734. JSAMPROW colormap0 = cinfo->colormap[0];
  157735. JSAMPROW colormap1 = cinfo->colormap[1];
  157736. JSAMPROW colormap2 = cinfo->colormap[2];
  157737. SHIFT_TEMPS
  157738. for (row = 0; row < num_rows; row++) {
  157739. inptr = input_buf[row];
  157740. outptr = output_buf[row];
  157741. if (cquantize->on_odd_row) {
  157742. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157743. outptr += width-1;
  157744. dir = -1;
  157745. dir3 = -3;
  157746. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157747. cquantize->on_odd_row = FALSE; /* flip for next time */
  157748. } else {
  157749. dir = 1;
  157750. dir3 = 3;
  157751. errorptr = cquantize->fserrors; /* => entry before first real column */
  157752. cquantize->on_odd_row = TRUE; /* flip for next time */
  157753. }
  157754. cur0 = cur1 = cur2 = 0;
  157755. belowerr0 = belowerr1 = belowerr2 = 0;
  157756. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157757. for (col = width; col > 0; col--) {
  157758. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157759. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157760. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157761. cur0 = error_limit[cur0];
  157762. cur1 = error_limit[cur1];
  157763. cur2 = error_limit[cur2];
  157764. cur0 += GETJSAMPLE(inptr[0]);
  157765. cur1 += GETJSAMPLE(inptr[1]);
  157766. cur2 += GETJSAMPLE(inptr[2]);
  157767. cur0 = GETJSAMPLE(range_limit[cur0]);
  157768. cur1 = GETJSAMPLE(range_limit[cur1]);
  157769. cur2 = GETJSAMPLE(range_limit[cur2]);
  157770. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157771. if (*cachep == 0)
  157772. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157773. { register int pixcode = *cachep - 1;
  157774. *outptr = (JSAMPLE) pixcode;
  157775. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157776. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157777. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157778. }
  157779. { register LOCFSERROR bnexterr, delta;
  157780. bnexterr = cur0; /* Process component 0 */
  157781. delta = cur0 * 2;
  157782. cur0 += delta; /* form error * 3 */
  157783. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157784. cur0 += delta; /* form error * 5 */
  157785. bpreverr0 = belowerr0 + cur0;
  157786. belowerr0 = bnexterr;
  157787. cur0 += delta; /* form error * 7 */
  157788. bnexterr = cur1; /* Process component 1 */
  157789. delta = cur1 * 2;
  157790. cur1 += delta; /* form error * 3 */
  157791. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157792. cur1 += delta; /* form error * 5 */
  157793. bpreverr1 = belowerr1 + cur1;
  157794. belowerr1 = bnexterr;
  157795. cur1 += delta; /* form error * 7 */
  157796. bnexterr = cur2; /* Process component 2 */
  157797. delta = cur2 * 2;
  157798. cur2 += delta; /* form error * 3 */
  157799. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157800. cur2 += delta; /* form error * 5 */
  157801. bpreverr2 = belowerr2 + cur2;
  157802. belowerr2 = bnexterr;
  157803. cur2 += delta; /* form error * 7 */
  157804. }
  157805. inptr += dir3; /* Advance pixel pointers to next column */
  157806. outptr += dir;
  157807. errorptr += dir3; /* advance errorptr to current column */
  157808. }
  157809. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157810. errorptr[1] = (FSERROR) bpreverr1;
  157811. errorptr[2] = (FSERROR) bpreverr2;
  157812. }
  157813. }
  157814. LOCAL(void)
  157815. init_error_limit (j_decompress_ptr cinfo)
  157816. {
  157817. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157818. int * table;
  157819. int in, out;
  157820. table = (int *) (*cinfo->mem->alloc_small)
  157821. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157822. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157823. cquantize->error_limiter = table;
  157824. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157825. out = 0;
  157826. for (in = 0; in < STEPSIZE; in++, out++) {
  157827. table[in] = out; table[-in] = -out;
  157828. }
  157829. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157830. table[in] = out; table[-in] = -out;
  157831. }
  157832. for (; in <= MAXJSAMPLE; in++) {
  157833. table[in] = out; table[-in] = -out;
  157834. }
  157835. #undef STEPSIZE
  157836. }
  157837. METHODDEF(void)
  157838. finish_pass1 (j_decompress_ptr cinfo)
  157839. {
  157840. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157841. cinfo->colormap = cquantize->sv_colormap;
  157842. select_colors(cinfo, cquantize->desired);
  157843. cquantize->needs_zeroed = TRUE;
  157844. }
  157845. METHODDEF(void)
  157846. finish_pass2 (j_decompress_ptr cinfo)
  157847. {
  157848. }
  157849. METHODDEF(void)
  157850. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157851. {
  157852. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157853. hist3d histogram = cquantize->histogram;
  157854. int i;
  157855. if (cinfo->dither_mode != JDITHER_NONE)
  157856. cinfo->dither_mode = JDITHER_FS;
  157857. if (is_pre_scan) {
  157858. cquantize->pub.color_quantize = prescan_quantize;
  157859. cquantize->pub.finish_pass = finish_pass1;
  157860. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157861. } else {
  157862. if (cinfo->dither_mode == JDITHER_FS)
  157863. cquantize->pub.color_quantize = pass2_fs_dither;
  157864. else
  157865. cquantize->pub.color_quantize = pass2_no_dither;
  157866. cquantize->pub.finish_pass = finish_pass2;
  157867. i = cinfo->actual_number_of_colors;
  157868. if (i < 1)
  157869. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157870. if (i > MAXNUMCOLORS)
  157871. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157872. if (cinfo->dither_mode == JDITHER_FS) {
  157873. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157874. (3 * SIZEOF(FSERROR)));
  157875. if (cquantize->fserrors == NULL)
  157876. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157877. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157878. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157879. if (cquantize->error_limiter == NULL)
  157880. init_error_limit(cinfo);
  157881. cquantize->on_odd_row = FALSE;
  157882. }
  157883. }
  157884. if (cquantize->needs_zeroed) {
  157885. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157886. jzero_far((void FAR *) histogram[i],
  157887. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157888. }
  157889. cquantize->needs_zeroed = FALSE;
  157890. }
  157891. }
  157892. METHODDEF(void)
  157893. new_color_map_2_quant (j_decompress_ptr cinfo)
  157894. {
  157895. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157896. cquantize->needs_zeroed = TRUE;
  157897. }
  157898. GLOBAL(void)
  157899. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157900. {
  157901. my_cquantize_ptr2 cquantize;
  157902. int i;
  157903. cquantize = (my_cquantize_ptr2)
  157904. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157905. SIZEOF(my_cquantizer2));
  157906. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157907. cquantize->pub.start_pass = start_pass_2_quant;
  157908. cquantize->pub.new_color_map = new_color_map_2_quant;
  157909. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157910. cquantize->error_limiter = NULL;
  157911. if (cinfo->out_color_components != 3)
  157912. ERREXIT(cinfo, JERR_NOTIMPL);
  157913. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157914. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157915. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157916. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  157917. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157918. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157919. }
  157920. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  157921. if (cinfo->enable_2pass_quant) {
  157922. int desired = cinfo->desired_number_of_colors;
  157923. if (desired < 8)
  157924. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  157925. if (desired > MAXNUMCOLORS)
  157926. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157927. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  157928. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  157929. cquantize->desired = desired;
  157930. } else
  157931. cquantize->sv_colormap = NULL;
  157932. if (cinfo->dither_mode != JDITHER_NONE)
  157933. cinfo->dither_mode = JDITHER_FS;
  157934. if (cinfo->dither_mode == JDITHER_FS) {
  157935. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157936. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157937. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  157938. init_error_limit(cinfo);
  157939. }
  157940. }
  157941. #endif /* QUANT_2PASS_SUPPORTED */
  157942. /*** End of inlined file: jquant2.c ***/
  157943. /*** Start of inlined file: jutils.c ***/
  157944. #define JPEG_INTERNALS
  157945. #if 0 /* This table is not actually needed in v6a */
  157946. const int jpeg_zigzag_order[DCTSIZE2] = {
  157947. 0, 1, 5, 6, 14, 15, 27, 28,
  157948. 2, 4, 7, 13, 16, 26, 29, 42,
  157949. 3, 8, 12, 17, 25, 30, 41, 43,
  157950. 9, 11, 18, 24, 31, 40, 44, 53,
  157951. 10, 19, 23, 32, 39, 45, 52, 54,
  157952. 20, 22, 33, 38, 46, 51, 55, 60,
  157953. 21, 34, 37, 47, 50, 56, 59, 61,
  157954. 35, 36, 48, 49, 57, 58, 62, 63
  157955. };
  157956. #endif
  157957. const int jpeg_natural_order[DCTSIZE2+16] = {
  157958. 0, 1, 8, 16, 9, 2, 3, 10,
  157959. 17, 24, 32, 25, 18, 11, 4, 5,
  157960. 12, 19, 26, 33, 40, 48, 41, 34,
  157961. 27, 20, 13, 6, 7, 14, 21, 28,
  157962. 35, 42, 49, 56, 57, 50, 43, 36,
  157963. 29, 22, 15, 23, 30, 37, 44, 51,
  157964. 58, 59, 52, 45, 38, 31, 39, 46,
  157965. 53, 60, 61, 54, 47, 55, 62, 63,
  157966. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  157967. 63, 63, 63, 63, 63, 63, 63, 63
  157968. };
  157969. GLOBAL(long)
  157970. jdiv_round_up (long a, long b)
  157971. {
  157972. return (a + b - 1L) / b;
  157973. }
  157974. GLOBAL(long)
  157975. jround_up (long a, long b)
  157976. {
  157977. a += b - 1L;
  157978. return a - (a % b);
  157979. }
  157980. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  157981. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  157982. #define FMEMZERO(target,size) MEMZERO(target,size)
  157983. #else /* 80x86 case, define if we can */
  157984. #ifdef USE_FMEM
  157985. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  157986. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  157987. #endif
  157988. #endif
  157989. GLOBAL(void)
  157990. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  157991. JSAMPARRAY output_array, int dest_row,
  157992. int num_rows, JDIMENSION num_cols)
  157993. {
  157994. register JSAMPROW inptr, outptr;
  157995. #ifdef FMEMCOPY
  157996. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  157997. #else
  157998. register JDIMENSION count;
  157999. #endif
  158000. register int row;
  158001. input_array += source_row;
  158002. output_array += dest_row;
  158003. for (row = num_rows; row > 0; row--) {
  158004. inptr = *input_array++;
  158005. outptr = *output_array++;
  158006. #ifdef FMEMCOPY
  158007. FMEMCOPY(outptr, inptr, count);
  158008. #else
  158009. for (count = num_cols; count > 0; count--)
  158010. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158011. #endif
  158012. }
  158013. }
  158014. GLOBAL(void)
  158015. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158016. JDIMENSION num_blocks)
  158017. {
  158018. #ifdef FMEMCOPY
  158019. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158020. #else
  158021. register JCOEFPTR inptr, outptr;
  158022. register long count;
  158023. inptr = (JCOEFPTR) input_row;
  158024. outptr = (JCOEFPTR) output_row;
  158025. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158026. *outptr++ = *inptr++;
  158027. }
  158028. #endif
  158029. }
  158030. GLOBAL(void)
  158031. jzero_far (void FAR * target, size_t bytestozero)
  158032. {
  158033. #ifdef FMEMZERO
  158034. FMEMZERO(target, bytestozero);
  158035. #else
  158036. register char FAR * ptr = (char FAR *) target;
  158037. register size_t count;
  158038. for (count = bytestozero; count > 0; count--) {
  158039. *ptr++ = 0;
  158040. }
  158041. #endif
  158042. }
  158043. /*** End of inlined file: jutils.c ***/
  158044. /*** Start of inlined file: transupp.c ***/
  158045. #define JPEG_INTERNALS
  158046. /*** Start of inlined file: transupp.h ***/
  158047. #ifndef TRANSFORMS_SUPPORTED
  158048. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158049. #endif
  158050. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158051. #define jtransform_request_workspace jTrRequest
  158052. #define jtransform_adjust_parameters jTrAdjust
  158053. #define jtransform_execute_transformation jTrExec
  158054. #define jcopy_markers_setup jCMrkSetup
  158055. #define jcopy_markers_execute jCMrkExec
  158056. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158057. typedef enum {
  158058. JXFORM_NONE, /* no transformation */
  158059. JXFORM_FLIP_H, /* horizontal flip */
  158060. JXFORM_FLIP_V, /* vertical flip */
  158061. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158062. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158063. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158064. JXFORM_ROT_180, /* 180-degree rotation */
  158065. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158066. } JXFORM_CODE;
  158067. typedef struct {
  158068. JXFORM_CODE transform; /* image transform operator */
  158069. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158070. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158071. int num_components; /* # of components in workspace */
  158072. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158073. } jpeg_transform_info;
  158074. #if TRANSFORMS_SUPPORTED
  158075. EXTERN(void) jtransform_request_workspace
  158076. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158077. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158078. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158079. jvirt_barray_ptr *src_coef_arrays,
  158080. jpeg_transform_info *info));
  158081. EXTERN(void) jtransform_execute_transformation
  158082. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158083. jvirt_barray_ptr *src_coef_arrays,
  158084. jpeg_transform_info *info));
  158085. #endif /* TRANSFORMS_SUPPORTED */
  158086. typedef enum {
  158087. JCOPYOPT_NONE, /* copy no optional markers */
  158088. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158089. JCOPYOPT_ALL /* copy all optional markers */
  158090. } JCOPY_OPTION;
  158091. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158092. EXTERN(void) jcopy_markers_setup
  158093. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158094. EXTERN(void) jcopy_markers_execute
  158095. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158096. JCOPY_OPTION option));
  158097. /*** End of inlined file: transupp.h ***/
  158098. /* My own external interface */
  158099. #if TRANSFORMS_SUPPORTED
  158100. LOCAL(void)
  158101. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158102. jvirt_barray_ptr *src_coef_arrays)
  158103. {
  158104. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158105. int ci, k, offset_y;
  158106. JBLOCKARRAY buffer;
  158107. JCOEFPTR ptr1, ptr2;
  158108. JCOEF temp1, temp2;
  158109. jpeg_component_info *compptr;
  158110. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158111. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158112. compptr = dstinfo->comp_info + ci;
  158113. comp_width = MCU_cols * compptr->h_samp_factor;
  158114. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158115. blk_y += compptr->v_samp_factor) {
  158116. buffer = (*srcinfo->mem->access_virt_barray)
  158117. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158118. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158119. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158120. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158121. ptr1 = buffer[offset_y][blk_x];
  158122. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158123. for (k = 0; k < DCTSIZE2; k += 2) {
  158124. temp1 = *ptr1; /* swap even column */
  158125. temp2 = *ptr2;
  158126. *ptr1++ = temp2;
  158127. *ptr2++ = temp1;
  158128. temp1 = *ptr1; /* swap odd column with sign change */
  158129. temp2 = *ptr2;
  158130. *ptr1++ = -temp2;
  158131. *ptr2++ = -temp1;
  158132. }
  158133. }
  158134. }
  158135. }
  158136. }
  158137. }
  158138. LOCAL(void)
  158139. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158140. jvirt_barray_ptr *src_coef_arrays,
  158141. jvirt_barray_ptr *dst_coef_arrays)
  158142. {
  158143. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158144. int ci, i, j, offset_y;
  158145. JBLOCKARRAY src_buffer, dst_buffer;
  158146. JBLOCKROW src_row_ptr, dst_row_ptr;
  158147. JCOEFPTR src_ptr, dst_ptr;
  158148. jpeg_component_info *compptr;
  158149. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158150. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158151. compptr = dstinfo->comp_info + ci;
  158152. comp_height = MCU_rows * compptr->v_samp_factor;
  158153. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158154. dst_blk_y += compptr->v_samp_factor) {
  158155. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158156. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158157. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158158. if (dst_blk_y < comp_height) {
  158159. src_buffer = (*srcinfo->mem->access_virt_barray)
  158160. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158161. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158162. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158163. } else {
  158164. src_buffer = (*srcinfo->mem->access_virt_barray)
  158165. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158166. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158167. }
  158168. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158169. if (dst_blk_y < comp_height) {
  158170. dst_row_ptr = dst_buffer[offset_y];
  158171. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158172. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158173. dst_blk_x++) {
  158174. dst_ptr = dst_row_ptr[dst_blk_x];
  158175. src_ptr = src_row_ptr[dst_blk_x];
  158176. for (i = 0; i < DCTSIZE; i += 2) {
  158177. for (j = 0; j < DCTSIZE; j++)
  158178. *dst_ptr++ = *src_ptr++;
  158179. for (j = 0; j < DCTSIZE; j++)
  158180. *dst_ptr++ = - *src_ptr++;
  158181. }
  158182. }
  158183. } else {
  158184. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158185. compptr->width_in_blocks);
  158186. }
  158187. }
  158188. }
  158189. }
  158190. }
  158191. LOCAL(void)
  158192. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158193. jvirt_barray_ptr *src_coef_arrays,
  158194. jvirt_barray_ptr *dst_coef_arrays)
  158195. {
  158196. JDIMENSION dst_blk_x, dst_blk_y;
  158197. int ci, i, j, offset_x, offset_y;
  158198. JBLOCKARRAY src_buffer, dst_buffer;
  158199. JCOEFPTR src_ptr, dst_ptr;
  158200. jpeg_component_info *compptr;
  158201. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158202. compptr = dstinfo->comp_info + ci;
  158203. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158204. dst_blk_y += compptr->v_samp_factor) {
  158205. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158206. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158207. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158208. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158209. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158210. dst_blk_x += compptr->h_samp_factor) {
  158211. src_buffer = (*srcinfo->mem->access_virt_barray)
  158212. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158213. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158214. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158215. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158216. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158217. for (i = 0; i < DCTSIZE; i++)
  158218. for (j = 0; j < DCTSIZE; j++)
  158219. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158220. }
  158221. }
  158222. }
  158223. }
  158224. }
  158225. }
  158226. LOCAL(void)
  158227. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158228. jvirt_barray_ptr *src_coef_arrays,
  158229. jvirt_barray_ptr *dst_coef_arrays)
  158230. {
  158231. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158232. int ci, i, j, offset_x, offset_y;
  158233. JBLOCKARRAY src_buffer, dst_buffer;
  158234. JCOEFPTR src_ptr, dst_ptr;
  158235. jpeg_component_info *compptr;
  158236. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158237. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158238. compptr = dstinfo->comp_info + ci;
  158239. comp_width = MCU_cols * compptr->h_samp_factor;
  158240. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158241. dst_blk_y += compptr->v_samp_factor) {
  158242. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158243. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158244. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158245. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158246. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158247. dst_blk_x += compptr->h_samp_factor) {
  158248. src_buffer = (*srcinfo->mem->access_virt_barray)
  158249. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158250. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158251. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158252. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158253. if (dst_blk_x < comp_width) {
  158254. dst_ptr = dst_buffer[offset_y]
  158255. [comp_width - dst_blk_x - offset_x - 1];
  158256. for (i = 0; i < DCTSIZE; i++) {
  158257. for (j = 0; j < DCTSIZE; j++)
  158258. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158259. i++;
  158260. for (j = 0; j < DCTSIZE; j++)
  158261. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158262. }
  158263. } else {
  158264. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158265. for (i = 0; i < DCTSIZE; i++)
  158266. for (j = 0; j < DCTSIZE; j++)
  158267. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158268. }
  158269. }
  158270. }
  158271. }
  158272. }
  158273. }
  158274. }
  158275. LOCAL(void)
  158276. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158277. jvirt_barray_ptr *src_coef_arrays,
  158278. jvirt_barray_ptr *dst_coef_arrays)
  158279. {
  158280. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158281. int ci, i, j, offset_x, offset_y;
  158282. JBLOCKARRAY src_buffer, dst_buffer;
  158283. JCOEFPTR src_ptr, dst_ptr;
  158284. jpeg_component_info *compptr;
  158285. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158286. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158287. compptr = dstinfo->comp_info + ci;
  158288. comp_height = MCU_rows * compptr->v_samp_factor;
  158289. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158290. dst_blk_y += compptr->v_samp_factor) {
  158291. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158292. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158293. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158294. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158295. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158296. dst_blk_x += compptr->h_samp_factor) {
  158297. src_buffer = (*srcinfo->mem->access_virt_barray)
  158298. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158299. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158300. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158301. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158302. if (dst_blk_y < comp_height) {
  158303. src_ptr = src_buffer[offset_x]
  158304. [comp_height - dst_blk_y - offset_y - 1];
  158305. for (i = 0; i < DCTSIZE; i++) {
  158306. for (j = 0; j < DCTSIZE; j++) {
  158307. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158308. j++;
  158309. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158310. }
  158311. }
  158312. } else {
  158313. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158314. for (i = 0; i < DCTSIZE; i++)
  158315. for (j = 0; j < DCTSIZE; j++)
  158316. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158317. }
  158318. }
  158319. }
  158320. }
  158321. }
  158322. }
  158323. }
  158324. LOCAL(void)
  158325. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158326. jvirt_barray_ptr *src_coef_arrays,
  158327. jvirt_barray_ptr *dst_coef_arrays)
  158328. {
  158329. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158330. int ci, i, j, offset_y;
  158331. JBLOCKARRAY src_buffer, dst_buffer;
  158332. JBLOCKROW src_row_ptr, dst_row_ptr;
  158333. JCOEFPTR src_ptr, dst_ptr;
  158334. jpeg_component_info *compptr;
  158335. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158336. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158337. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158338. compptr = dstinfo->comp_info + ci;
  158339. comp_width = MCU_cols * compptr->h_samp_factor;
  158340. comp_height = MCU_rows * compptr->v_samp_factor;
  158341. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158342. dst_blk_y += compptr->v_samp_factor) {
  158343. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158344. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158345. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158346. if (dst_blk_y < comp_height) {
  158347. src_buffer = (*srcinfo->mem->access_virt_barray)
  158348. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158349. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158350. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158351. } else {
  158352. src_buffer = (*srcinfo->mem->access_virt_barray)
  158353. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158354. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158355. }
  158356. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158357. if (dst_blk_y < comp_height) {
  158358. dst_row_ptr = dst_buffer[offset_y];
  158359. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158360. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158361. dst_ptr = dst_row_ptr[dst_blk_x];
  158362. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158363. for (i = 0; i < DCTSIZE; i += 2) {
  158364. for (j = 0; j < DCTSIZE; j += 2) {
  158365. *dst_ptr++ = *src_ptr++;
  158366. *dst_ptr++ = - *src_ptr++;
  158367. }
  158368. for (j = 0; j < DCTSIZE; j += 2) {
  158369. *dst_ptr++ = - *src_ptr++;
  158370. *dst_ptr++ = *src_ptr++;
  158371. }
  158372. }
  158373. }
  158374. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158375. dst_ptr = dst_row_ptr[dst_blk_x];
  158376. src_ptr = src_row_ptr[dst_blk_x];
  158377. for (i = 0; i < DCTSIZE; i += 2) {
  158378. for (j = 0; j < DCTSIZE; j++)
  158379. *dst_ptr++ = *src_ptr++;
  158380. for (j = 0; j < DCTSIZE; j++)
  158381. *dst_ptr++ = - *src_ptr++;
  158382. }
  158383. }
  158384. } else {
  158385. dst_row_ptr = dst_buffer[offset_y];
  158386. src_row_ptr = src_buffer[offset_y];
  158387. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158388. dst_ptr = dst_row_ptr[dst_blk_x];
  158389. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158390. for (i = 0; i < DCTSIZE2; i += 2) {
  158391. *dst_ptr++ = *src_ptr++;
  158392. *dst_ptr++ = - *src_ptr++;
  158393. }
  158394. }
  158395. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158396. dst_ptr = dst_row_ptr[dst_blk_x];
  158397. src_ptr = src_row_ptr[dst_blk_x];
  158398. for (i = 0; i < DCTSIZE2; i++)
  158399. *dst_ptr++ = *src_ptr++;
  158400. }
  158401. }
  158402. }
  158403. }
  158404. }
  158405. }
  158406. LOCAL(void)
  158407. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158408. jvirt_barray_ptr *src_coef_arrays,
  158409. jvirt_barray_ptr *dst_coef_arrays)
  158410. {
  158411. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158412. int ci, i, j, offset_x, offset_y;
  158413. JBLOCKARRAY src_buffer, dst_buffer;
  158414. JCOEFPTR src_ptr, dst_ptr;
  158415. jpeg_component_info *compptr;
  158416. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158417. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158418. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158419. compptr = dstinfo->comp_info + ci;
  158420. comp_width = MCU_cols * compptr->h_samp_factor;
  158421. comp_height = MCU_rows * compptr->v_samp_factor;
  158422. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158423. dst_blk_y += compptr->v_samp_factor) {
  158424. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158425. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158426. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158427. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158428. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158429. dst_blk_x += compptr->h_samp_factor) {
  158430. src_buffer = (*srcinfo->mem->access_virt_barray)
  158431. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158432. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158433. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158434. if (dst_blk_y < comp_height) {
  158435. src_ptr = src_buffer[offset_x]
  158436. [comp_height - dst_blk_y - offset_y - 1];
  158437. if (dst_blk_x < comp_width) {
  158438. dst_ptr = dst_buffer[offset_y]
  158439. [comp_width - dst_blk_x - offset_x - 1];
  158440. for (i = 0; i < DCTSIZE; i++) {
  158441. for (j = 0; j < DCTSIZE; j++) {
  158442. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158443. j++;
  158444. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158445. }
  158446. i++;
  158447. for (j = 0; j < DCTSIZE; j++) {
  158448. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158449. j++;
  158450. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158451. }
  158452. }
  158453. } else {
  158454. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158455. for (i = 0; i < DCTSIZE; i++) {
  158456. for (j = 0; j < DCTSIZE; j++) {
  158457. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158458. j++;
  158459. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158460. }
  158461. }
  158462. }
  158463. } else {
  158464. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158465. if (dst_blk_x < comp_width) {
  158466. dst_ptr = dst_buffer[offset_y]
  158467. [comp_width - dst_blk_x - offset_x - 1];
  158468. for (i = 0; i < DCTSIZE; i++) {
  158469. for (j = 0; j < DCTSIZE; j++)
  158470. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158471. i++;
  158472. for (j = 0; j < DCTSIZE; j++)
  158473. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158474. }
  158475. } else {
  158476. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158477. for (i = 0; i < DCTSIZE; i++)
  158478. for (j = 0; j < DCTSIZE; j++)
  158479. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158480. }
  158481. }
  158482. }
  158483. }
  158484. }
  158485. }
  158486. }
  158487. }
  158488. GLOBAL(void)
  158489. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158490. jpeg_transform_info *info)
  158491. {
  158492. jvirt_barray_ptr *coef_arrays = NULL;
  158493. jpeg_component_info *compptr;
  158494. int ci;
  158495. if (info->force_grayscale &&
  158496. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158497. srcinfo->num_components == 3) {
  158498. info->num_components = 1;
  158499. } else {
  158500. info->num_components = srcinfo->num_components;
  158501. }
  158502. switch (info->transform) {
  158503. case JXFORM_NONE:
  158504. case JXFORM_FLIP_H:
  158505. break;
  158506. case JXFORM_FLIP_V:
  158507. case JXFORM_ROT_180:
  158508. coef_arrays = (jvirt_barray_ptr *)
  158509. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158510. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158511. for (ci = 0; ci < info->num_components; ci++) {
  158512. compptr = srcinfo->comp_info + ci;
  158513. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158514. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158515. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158516. (long) compptr->h_samp_factor),
  158517. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158518. (long) compptr->v_samp_factor),
  158519. (JDIMENSION) compptr->v_samp_factor);
  158520. }
  158521. break;
  158522. case JXFORM_TRANSPOSE:
  158523. case JXFORM_TRANSVERSE:
  158524. case JXFORM_ROT_90:
  158525. case JXFORM_ROT_270:
  158526. coef_arrays = (jvirt_barray_ptr *)
  158527. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158528. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158529. for (ci = 0; ci < info->num_components; ci++) {
  158530. compptr = srcinfo->comp_info + ci;
  158531. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158532. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158533. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158534. (long) compptr->v_samp_factor),
  158535. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158536. (long) compptr->h_samp_factor),
  158537. (JDIMENSION) compptr->h_samp_factor);
  158538. }
  158539. break;
  158540. }
  158541. info->workspace_coef_arrays = coef_arrays;
  158542. }
  158543. LOCAL(void)
  158544. transpose_critical_parameters (j_compress_ptr dstinfo)
  158545. {
  158546. int tblno, i, j, ci, itemp;
  158547. jpeg_component_info *compptr;
  158548. JQUANT_TBL *qtblptr;
  158549. JDIMENSION dtemp;
  158550. UINT16 qtemp;
  158551. dtemp = dstinfo->image_width;
  158552. dstinfo->image_width = dstinfo->image_height;
  158553. dstinfo->image_height = dtemp;
  158554. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158555. compptr = dstinfo->comp_info + ci;
  158556. itemp = compptr->h_samp_factor;
  158557. compptr->h_samp_factor = compptr->v_samp_factor;
  158558. compptr->v_samp_factor = itemp;
  158559. }
  158560. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158561. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158562. if (qtblptr != NULL) {
  158563. for (i = 0; i < DCTSIZE; i++) {
  158564. for (j = 0; j < i; j++) {
  158565. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158566. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158567. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158568. }
  158569. }
  158570. }
  158571. }
  158572. }
  158573. LOCAL(void)
  158574. trim_right_edge (j_compress_ptr dstinfo)
  158575. {
  158576. int ci, max_h_samp_factor;
  158577. JDIMENSION MCU_cols;
  158578. max_h_samp_factor = 1;
  158579. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158580. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158581. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158582. }
  158583. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158584. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158585. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158586. }
  158587. LOCAL(void)
  158588. trim_bottom_edge (j_compress_ptr dstinfo)
  158589. {
  158590. int ci, max_v_samp_factor;
  158591. JDIMENSION MCU_rows;
  158592. max_v_samp_factor = 1;
  158593. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158594. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158595. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158596. }
  158597. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158598. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158599. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158600. }
  158601. GLOBAL(jvirt_barray_ptr *)
  158602. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158603. j_compress_ptr dstinfo,
  158604. jvirt_barray_ptr *src_coef_arrays,
  158605. jpeg_transform_info *info)
  158606. {
  158607. if (info->force_grayscale) {
  158608. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158609. dstinfo->num_components == 3) ||
  158610. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158611. dstinfo->num_components == 1)) {
  158612. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158613. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158614. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158615. } else {
  158616. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158617. }
  158618. }
  158619. switch (info->transform) {
  158620. case JXFORM_NONE:
  158621. break;
  158622. case JXFORM_FLIP_H:
  158623. if (info->trim)
  158624. trim_right_edge(dstinfo);
  158625. break;
  158626. case JXFORM_FLIP_V:
  158627. if (info->trim)
  158628. trim_bottom_edge(dstinfo);
  158629. break;
  158630. case JXFORM_TRANSPOSE:
  158631. transpose_critical_parameters(dstinfo);
  158632. break;
  158633. case JXFORM_TRANSVERSE:
  158634. transpose_critical_parameters(dstinfo);
  158635. if (info->trim) {
  158636. trim_right_edge(dstinfo);
  158637. trim_bottom_edge(dstinfo);
  158638. }
  158639. break;
  158640. case JXFORM_ROT_90:
  158641. transpose_critical_parameters(dstinfo);
  158642. if (info->trim)
  158643. trim_right_edge(dstinfo);
  158644. break;
  158645. case JXFORM_ROT_180:
  158646. if (info->trim) {
  158647. trim_right_edge(dstinfo);
  158648. trim_bottom_edge(dstinfo);
  158649. }
  158650. break;
  158651. case JXFORM_ROT_270:
  158652. transpose_critical_parameters(dstinfo);
  158653. if (info->trim)
  158654. trim_bottom_edge(dstinfo);
  158655. break;
  158656. }
  158657. if (info->workspace_coef_arrays != NULL)
  158658. return info->workspace_coef_arrays;
  158659. return src_coef_arrays;
  158660. }
  158661. GLOBAL(void)
  158662. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158663. j_compress_ptr dstinfo,
  158664. jvirt_barray_ptr *src_coef_arrays,
  158665. jpeg_transform_info *info)
  158666. {
  158667. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158668. switch (info->transform) {
  158669. case JXFORM_NONE:
  158670. break;
  158671. case JXFORM_FLIP_H:
  158672. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158673. break;
  158674. case JXFORM_FLIP_V:
  158675. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158676. break;
  158677. case JXFORM_TRANSPOSE:
  158678. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158679. break;
  158680. case JXFORM_TRANSVERSE:
  158681. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158682. break;
  158683. case JXFORM_ROT_90:
  158684. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158685. break;
  158686. case JXFORM_ROT_180:
  158687. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158688. break;
  158689. case JXFORM_ROT_270:
  158690. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158691. break;
  158692. }
  158693. }
  158694. #endif /* TRANSFORMS_SUPPORTED */
  158695. GLOBAL(void)
  158696. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158697. {
  158698. #ifdef SAVE_MARKERS_SUPPORTED
  158699. int m;
  158700. if (option != JCOPYOPT_NONE) {
  158701. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158702. }
  158703. if (option == JCOPYOPT_ALL) {
  158704. for (m = 0; m < 16; m++)
  158705. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158706. }
  158707. #endif /* SAVE_MARKERS_SUPPORTED */
  158708. }
  158709. GLOBAL(void)
  158710. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158711. JCOPY_OPTION option)
  158712. {
  158713. jpeg_saved_marker_ptr marker;
  158714. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158715. if (dstinfo->write_JFIF_header &&
  158716. marker->marker == JPEG_APP0 &&
  158717. marker->data_length >= 5 &&
  158718. GETJOCTET(marker->data[0]) == 0x4A &&
  158719. GETJOCTET(marker->data[1]) == 0x46 &&
  158720. GETJOCTET(marker->data[2]) == 0x49 &&
  158721. GETJOCTET(marker->data[3]) == 0x46 &&
  158722. GETJOCTET(marker->data[4]) == 0)
  158723. continue; /* reject duplicate JFIF */
  158724. if (dstinfo->write_Adobe_marker &&
  158725. marker->marker == JPEG_APP0+14 &&
  158726. marker->data_length >= 5 &&
  158727. GETJOCTET(marker->data[0]) == 0x41 &&
  158728. GETJOCTET(marker->data[1]) == 0x64 &&
  158729. GETJOCTET(marker->data[2]) == 0x6F &&
  158730. GETJOCTET(marker->data[3]) == 0x62 &&
  158731. GETJOCTET(marker->data[4]) == 0x65)
  158732. continue; /* reject duplicate Adobe */
  158733. #ifdef NEED_FAR_POINTERS
  158734. {
  158735. unsigned int i;
  158736. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158737. for (i = 0; i < marker->data_length; i++)
  158738. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158739. }
  158740. #else
  158741. jpeg_write_marker(dstinfo, marker->marker,
  158742. marker->data, marker->data_length);
  158743. #endif
  158744. }
  158745. }
  158746. /*** End of inlined file: transupp.c ***/
  158747. }
  158748. #else
  158749. #define JPEG_INTERNALS
  158750. #undef FAR
  158751. #include <jpeglib.h>
  158752. #endif
  158753. }
  158754. #undef max
  158755. #undef min
  158756. #if JUCE_MSVC
  158757. #pragma warning (pop)
  158758. #endif
  158759. BEGIN_JUCE_NAMESPACE
  158760. namespace JPEGHelpers
  158761. {
  158762. using namespace jpeglibNamespace;
  158763. #if ! JUCE_MSVC
  158764. using jpeglibNamespace::boolean;
  158765. #endif
  158766. struct JPEGDecodingFailure {};
  158767. static void fatalErrorHandler (j_common_ptr)
  158768. {
  158769. throw JPEGDecodingFailure();
  158770. }
  158771. static void silentErrorCallback1 (j_common_ptr) {}
  158772. static void silentErrorCallback2 (j_common_ptr, int) {}
  158773. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158774. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158775. {
  158776. zerostruct (err);
  158777. err.error_exit = fatalErrorHandler;
  158778. err.emit_message = silentErrorCallback2;
  158779. err.output_message = silentErrorCallback1;
  158780. err.format_message = silentErrorCallback3;
  158781. err.reset_error_mgr = silentErrorCallback1;
  158782. }
  158783. static void dummyCallback1 (j_decompress_ptr)
  158784. {
  158785. }
  158786. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158787. {
  158788. decompStruct->src->next_input_byte += num;
  158789. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158790. decompStruct->src->bytes_in_buffer -= num;
  158791. }
  158792. static boolean jpegFill (j_decompress_ptr)
  158793. {
  158794. return 0;
  158795. }
  158796. static const int jpegBufferSize = 512;
  158797. struct JuceJpegDest : public jpeg_destination_mgr
  158798. {
  158799. OutputStream* output;
  158800. char* buffer;
  158801. };
  158802. static void jpegWriteInit (j_compress_ptr)
  158803. {
  158804. }
  158805. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158806. {
  158807. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158808. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158809. dest->output->write (dest->buffer, (int) numToWrite);
  158810. }
  158811. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158812. {
  158813. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158814. const int numToWrite = jpegBufferSize;
  158815. dest->next_output_byte = reinterpret_cast <JOCTET*> (dest->buffer);
  158816. dest->free_in_buffer = jpegBufferSize;
  158817. return dest->output->write (dest->buffer, numToWrite);
  158818. }
  158819. }
  158820. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158821. {
  158822. using namespace jpeglibNamespace;
  158823. using namespace JPEGHelpers;
  158824. MemoryBlock mb;
  158825. in.readIntoMemoryBlock (mb);
  158826. Image* image = 0;
  158827. if (mb.getSize() > 16)
  158828. {
  158829. struct jpeg_decompress_struct jpegDecompStruct;
  158830. struct jpeg_error_mgr jerr;
  158831. setupSilentErrorHandler (jerr);
  158832. jpegDecompStruct.err = &jerr;
  158833. jpeg_create_decompress (&jpegDecompStruct);
  158834. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158835. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158836. jpegDecompStruct.src->init_source = dummyCallback1;
  158837. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158838. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158839. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158840. jpegDecompStruct.src->term_source = dummyCallback1;
  158841. jpegDecompStruct.src->next_input_byte = static_cast <const unsigned char*> (mb.getData());
  158842. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158843. try
  158844. {
  158845. jpeg_read_header (&jpegDecompStruct, TRUE);
  158846. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158847. const int width = jpegDecompStruct.output_width;
  158848. const int height = jpegDecompStruct.output_height;
  158849. jpegDecompStruct.out_color_space = JCS_RGB;
  158850. JSAMPARRAY buffer
  158851. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158852. JPOOL_IMAGE,
  158853. width * 3, 1);
  158854. if (jpeg_start_decompress (&jpegDecompStruct))
  158855. {
  158856. image = Image::createNativeImage (Image::RGB, width, height, false);
  158857. const bool hasAlphaChan = image->hasAlphaChannel();
  158858. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158859. for (int y = 0; y < height; ++y)
  158860. {
  158861. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158862. const uint8* src = *buffer;
  158863. uint8* dest = destData.getLinePointer (y);
  158864. if (hasAlphaChan)
  158865. {
  158866. for (int i = width; --i >= 0;)
  158867. {
  158868. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158869. ((PixelARGB*) dest)->premultiply();
  158870. dest += destData.pixelStride;
  158871. src += 3;
  158872. }
  158873. }
  158874. else
  158875. {
  158876. for (int i = width; --i >= 0;)
  158877. {
  158878. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158879. dest += destData.pixelStride;
  158880. src += 3;
  158881. }
  158882. }
  158883. }
  158884. jpeg_finish_decompress (&jpegDecompStruct);
  158885. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158886. }
  158887. jpeg_destroy_decompress (&jpegDecompStruct);
  158888. }
  158889. catch (...)
  158890. {}
  158891. }
  158892. return image;
  158893. }
  158894. bool juce_writeJPEGImageToStream (const Image& image,
  158895. OutputStream& out,
  158896. float quality)
  158897. {
  158898. using namespace jpeglibNamespace;
  158899. using namespace JPEGHelpers;
  158900. if (image.hasAlphaChannel())
  158901. {
  158902. // this method could fill the background in white and still save the image..
  158903. jassertfalse
  158904. return true;
  158905. }
  158906. struct jpeg_compress_struct jpegCompStruct;
  158907. struct jpeg_error_mgr jerr;
  158908. setupSilentErrorHandler (jerr);
  158909. jpegCompStruct.err = &jerr;
  158910. jpeg_create_compress (&jpegCompStruct);
  158911. JuceJpegDest dest;
  158912. jpegCompStruct.dest = &dest;
  158913. dest.output = &out;
  158914. HeapBlock <char> tempBuffer (jpegBufferSize);
  158915. dest.buffer = tempBuffer;
  158916. dest.next_output_byte = (JOCTET*) dest.buffer;
  158917. dest.free_in_buffer = jpegBufferSize;
  158918. dest.init_destination = jpegWriteInit;
  158919. dest.empty_output_buffer = jpegWriteFlush;
  158920. dest.term_destination = jpegWriteTerminate;
  158921. jpegCompStruct.image_width = image.getWidth();
  158922. jpegCompStruct.image_height = image.getHeight();
  158923. jpegCompStruct.input_components = 3;
  158924. jpegCompStruct.in_color_space = JCS_RGB;
  158925. jpegCompStruct.write_JFIF_header = 1;
  158926. jpegCompStruct.X_density = 72;
  158927. jpegCompStruct.Y_density = 72;
  158928. jpeg_set_defaults (&jpegCompStruct);
  158929. jpegCompStruct.dct_method = JDCT_FLOAT;
  158930. jpegCompStruct.optimize_coding = 1;
  158931. //jpegCompStruct.smoothing_factor = 10;
  158932. if (quality < 0.0f)
  158933. quality = 0.85f;
  158934. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  158935. jpeg_start_compress (&jpegCompStruct, TRUE);
  158936. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  158937. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  158938. JPOOL_IMAGE, strideBytes, 1);
  158939. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  158940. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  158941. {
  158942. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  158943. uint8* dst = *buffer;
  158944. for (int i = jpegCompStruct.image_width; --i >= 0;)
  158945. {
  158946. *dst++ = ((const PixelRGB*) src)->getRed();
  158947. *dst++ = ((const PixelRGB*) src)->getGreen();
  158948. *dst++ = ((const PixelRGB*) src)->getBlue();
  158949. src += srcData.pixelStride;
  158950. }
  158951. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  158952. }
  158953. jpeg_finish_compress (&jpegCompStruct);
  158954. jpeg_destroy_compress (&jpegCompStruct);
  158955. out.flush();
  158956. return true;
  158957. }
  158958. END_JUCE_NAMESPACE
  158959. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  158960. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  158961. #ifdef _MSC_VER
  158962. #pragma warning (push)
  158963. #pragma warning (disable: 4390 4611)
  158964. #endif
  158965. namespace zlibNamespace
  158966. {
  158967. #if JUCE_INCLUDE_ZLIB_CODE
  158968. #undef OS_CODE
  158969. #undef fdopen
  158970. #undef OS_CODE
  158971. #else
  158972. #include <zlib.h>
  158973. #endif
  158974. }
  158975. namespace pnglibNamespace
  158976. {
  158977. using namespace zlibNamespace;
  158978. #if JUCE_INCLUDE_PNGLIB_CODE
  158979. #if _MSC_VER != 1310
  158980. using ::calloc; // (causes conflict in VS.NET 2003)
  158981. using ::malloc;
  158982. using ::free;
  158983. #endif
  158984. extern "C"
  158985. {
  158986. using ::abs;
  158987. #define PNG_INTERNAL
  158988. #define NO_DUMMY_DECL
  158989. #define PNG_SETJMP_NOT_SUPPORTED
  158990. /*** Start of inlined file: png.h ***/
  158991. #ifndef PNG_H
  158992. #define PNG_H
  158993. #define PNG_LIBPNG_VER_STRING "1.2.21"
  158994. #define PNG_HEADER_VERSION_STRING \
  158995. " libpng version 1.2.21 - October 4, 2007\n"
  158996. #define PNG_LIBPNG_VER_SONUM 0
  158997. #define PNG_LIBPNG_VER_DLLNUM 13
  158998. #define PNG_LIBPNG_VER_MAJOR 1
  158999. #define PNG_LIBPNG_VER_MINOR 2
  159000. #define PNG_LIBPNG_VER_RELEASE 21
  159001. #define PNG_LIBPNG_VER_BUILD 0
  159002. #define PNG_LIBPNG_BUILD_ALPHA 1
  159003. #define PNG_LIBPNG_BUILD_BETA 2
  159004. #define PNG_LIBPNG_BUILD_RC 3
  159005. #define PNG_LIBPNG_BUILD_STABLE 4
  159006. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159007. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159008. PNG_LIBPNG_BUILD_STABLE only */
  159009. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159010. PNG_LIBPNG_BUILD_SPECIAL */
  159011. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159012. PNG_LIBPNG_BUILD_PRIVATE */
  159013. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159014. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159015. #ifndef PNG_VERSION_INFO_ONLY
  159016. #endif
  159017. /*** Start of inlined file: pngconf.h ***/
  159018. #ifndef PNGCONF_H
  159019. #define PNGCONF_H
  159020. #define PNG_1_2_X
  159021. // These are some Juce config settings that should remove any unnecessary code bloat..
  159022. #define PNG_NO_STDIO 1
  159023. #define PNG_DEBUG 0
  159024. #define PNG_NO_WARNINGS 1
  159025. #define PNG_NO_ERROR_TEXT 1
  159026. #define PNG_NO_ERROR_NUMBERS 1
  159027. #define PNG_NO_USER_MEM 1
  159028. #define PNG_NO_READ_iCCP 1
  159029. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159030. #define PNG_NO_READ_USER_CHUNKS 1
  159031. #define PNG_NO_READ_iTXt 1
  159032. #define PNG_NO_READ_sCAL 1
  159033. #define PNG_NO_READ_sPLT 1
  159034. #define png_error(a, b) png_err(a)
  159035. #define png_warning(a, b)
  159036. #define png_chunk_error(a, b) png_err(a)
  159037. #define png_chunk_warning(a, b)
  159038. #ifdef PNG_USER_CONFIG
  159039. # ifndef PNG_USER_PRIVATEBUILD
  159040. # define PNG_USER_PRIVATEBUILD
  159041. # endif
  159042. #include "pngusr.h"
  159043. #endif
  159044. #ifdef PNG_CONFIGURE_LIBPNG
  159045. #ifdef HAVE_CONFIG_H
  159046. #include "config.h"
  159047. #endif
  159048. #endif
  159049. #ifdef __STDC__
  159050. #ifdef SPECIALBUILD
  159051. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159052. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159053. #endif
  159054. #ifdef PRIVATEBUILD
  159055. # pragma message("PRIVATEBUILD is deprecated.\
  159056. Use PNG_USER_PRIVATEBUILD instead.")
  159057. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159058. #endif
  159059. #endif /* __STDC__ */
  159060. #ifndef PNG_VERSION_INFO_ONLY
  159061. # define PNG_WARN_UNINITIALIZED_ROW 1
  159062. #ifndef PNG_ZBUF_SIZE
  159063. # define PNG_ZBUF_SIZE 8192
  159064. #endif
  159065. #ifndef PNG_NO_READ_SUPPORTED
  159066. # define PNG_READ_SUPPORTED
  159067. #endif
  159068. #ifndef PNG_NO_WRITE_SUPPORTED
  159069. # define PNG_WRITE_SUPPORTED
  159070. #endif
  159071. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159072. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159073. # define PNG_MNG_FEATURES_SUPPORTED
  159074. # endif
  159075. #endif
  159076. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159077. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159078. # define PNG_FLOATING_POINT_SUPPORTED
  159079. # endif
  159080. #endif
  159081. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159082. # define PNG_MAX_MALLOC_64K
  159083. #endif
  159084. #if defined(__CYGWIN__)
  159085. # if defined(ALL_STATIC)
  159086. # if defined(PNG_BUILD_DLL)
  159087. # undef PNG_BUILD_DLL
  159088. # endif
  159089. # if defined(PNG_USE_DLL)
  159090. # undef PNG_USE_DLL
  159091. # endif
  159092. # if defined(PNG_DLL)
  159093. # undef PNG_DLL
  159094. # endif
  159095. # if !defined(PNG_STATIC)
  159096. # define PNG_STATIC
  159097. # endif
  159098. # else
  159099. # if defined (PNG_BUILD_DLL)
  159100. # if defined(PNG_STATIC)
  159101. # undef PNG_STATIC
  159102. # endif
  159103. # if defined(PNG_USE_DLL)
  159104. # undef PNG_USE_DLL
  159105. # endif
  159106. # if !defined(PNG_DLL)
  159107. # define PNG_DLL
  159108. # endif
  159109. # else
  159110. # if defined(PNG_STATIC)
  159111. # if defined(PNG_USE_DLL)
  159112. # undef PNG_USE_DLL
  159113. # endif
  159114. # if defined(PNG_DLL)
  159115. # undef PNG_DLL
  159116. # endif
  159117. # else
  159118. # if !defined(PNG_USE_DLL)
  159119. # define PNG_USE_DLL
  159120. # endif
  159121. # if !defined(PNG_DLL)
  159122. # define PNG_DLL
  159123. # endif
  159124. # endif
  159125. # endif
  159126. # endif
  159127. #endif
  159128. #if defined(_WIN32_WCE)
  159129. # include <windows.h>
  159130. # define PNG_NO_CONSOLE_IO
  159131. # ifdef PNG_DEBUG
  159132. # undef PNG_DEBUG
  159133. # endif
  159134. #endif
  159135. #ifdef PNG_BUILD_DLL
  159136. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159137. # ifndef PNG_NO_CONSOLE_IO
  159138. # define PNG_NO_CONSOLE_IO
  159139. # endif
  159140. # endif
  159141. #endif
  159142. # ifdef PNG_NO_STDIO
  159143. # ifndef PNG_NO_CONSOLE_IO
  159144. # define PNG_NO_CONSOLE_IO
  159145. # endif
  159146. # ifdef PNG_DEBUG
  159147. # if (PNG_DEBUG > 0)
  159148. # include <stdio.h>
  159149. # endif
  159150. # endif
  159151. # else
  159152. # if !defined(_WIN32_WCE)
  159153. # include <stdio.h>
  159154. # endif
  159155. # endif
  159156. #ifndef PNGARG
  159157. #ifdef OF /* zlib prototype munger */
  159158. # define PNGARG(arglist) OF(arglist)
  159159. #else
  159160. #ifdef _NO_PROTO
  159161. # define PNGARG(arglist) ()
  159162. # ifndef PNG_TYPECAST_NULL
  159163. # define PNG_TYPECAST_NULL
  159164. # endif
  159165. #else
  159166. # define PNGARG(arglist) arglist
  159167. #endif /* _NO_PROTO */
  159168. #endif /* OF */
  159169. #endif /* PNGARG */
  159170. #ifndef MACOS
  159171. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159172. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159173. # define MACOS
  159174. # endif
  159175. #endif
  159176. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159177. # include <sys/types.h>
  159178. #endif
  159179. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159180. # define PNG_SETJMP_SUPPORTED
  159181. #endif
  159182. #ifdef PNG_SETJMP_SUPPORTED
  159183. # ifdef __linux__
  159184. # ifdef _BSD_SOURCE
  159185. # define PNG_SAVE_BSD_SOURCE
  159186. # undef _BSD_SOURCE
  159187. # endif
  159188. # ifdef _SETJMP_H
  159189. __png.h__ already includes setjmp.h;
  159190. __dont__ include it again.;
  159191. # endif
  159192. # endif /* __linux__ */
  159193. # include <setjmp.h>
  159194. # ifdef __linux__
  159195. # ifdef PNG_SAVE_BSD_SOURCE
  159196. # define _BSD_SOURCE
  159197. # undef PNG_SAVE_BSD_SOURCE
  159198. # endif
  159199. # endif /* __linux__ */
  159200. #endif /* PNG_SETJMP_SUPPORTED */
  159201. #ifdef BSD
  159202. #if ! JUCE_MAC
  159203. # include <strings.h>
  159204. #endif
  159205. #else
  159206. # include <string.h>
  159207. #endif
  159208. #ifdef PNG_INTERNAL
  159209. #include <stdlib.h>
  159210. #define PNG_EXTERN
  159211. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159212. # if defined(MACOS)
  159213. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159214. # include <fp.h>
  159215. # endif
  159216. # else
  159217. # include <math.h>
  159218. # endif
  159219. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159220. # include <m68881.h>
  159221. # endif
  159222. #endif
  159223. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159224. # define PNG_ALWAYS_EXTERN
  159225. #endif
  159226. #if defined(__TURBOC__) && defined(__MSDOS__)
  159227. # include <mem.h>
  159228. # include <alloc.h>
  159229. #endif
  159230. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159231. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159232. # include <malloc.h>
  159233. #endif
  159234. #ifndef PNG_DITHER_RED_BITS
  159235. # define PNG_DITHER_RED_BITS 5
  159236. #endif
  159237. #ifndef PNG_DITHER_GREEN_BITS
  159238. # define PNG_DITHER_GREEN_BITS 5
  159239. #endif
  159240. #ifndef PNG_DITHER_BLUE_BITS
  159241. # define PNG_DITHER_BLUE_BITS 5
  159242. #endif
  159243. #ifndef PNG_MAX_GAMMA_8
  159244. # define PNG_MAX_GAMMA_8 11
  159245. #endif
  159246. #ifndef PNG_GAMMA_THRESHOLD
  159247. # define PNG_GAMMA_THRESHOLD 0.05
  159248. #endif
  159249. #endif /* PNG_INTERNAL */
  159250. #ifndef PNG_NO_CONST
  159251. # define PNG_CONST const
  159252. #else
  159253. # define PNG_CONST
  159254. #endif
  159255. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159256. # ifndef PNG_NO_iTXt_SUPPORTED
  159257. # define PNG_NO_iTXt_SUPPORTED
  159258. # endif
  159259. # ifndef PNG_NO_READ_iTXt
  159260. # define PNG_NO_READ_iTXt
  159261. # endif
  159262. # ifndef PNG_NO_WRITE_iTXt
  159263. # define PNG_NO_WRITE_iTXt
  159264. # endif
  159265. #endif
  159266. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159267. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159268. # define PNG_READ_iTXt
  159269. # endif
  159270. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159271. # define PNG_WRITE_iTXt
  159272. # endif
  159273. #endif
  159274. #ifdef PNG_LEGACY_SUPPORTED
  159275. # define PNG_NO_FREE_ME
  159276. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159277. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159278. # define PNG_NO_READ_USER_CHUNKS
  159279. # define PNG_NO_READ_iCCP
  159280. # define PNG_NO_WRITE_iCCP
  159281. # define PNG_NO_READ_iTXt
  159282. # define PNG_NO_WRITE_iTXt
  159283. # define PNG_NO_READ_sCAL
  159284. # define PNG_NO_WRITE_sCAL
  159285. # define PNG_NO_READ_sPLT
  159286. # define PNG_NO_WRITE_sPLT
  159287. # define PNG_NO_INFO_IMAGE
  159288. # define PNG_NO_READ_RGB_TO_GRAY
  159289. # define PNG_NO_READ_USER_TRANSFORM
  159290. # define PNG_NO_WRITE_USER_TRANSFORM
  159291. # define PNG_NO_USER_MEM
  159292. # define PNG_NO_READ_EMPTY_PLTE
  159293. # define PNG_NO_MNG_FEATURES
  159294. # define PNG_NO_FIXED_POINT_SUPPORTED
  159295. #endif
  159296. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159297. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159298. # define PNG_FIXED_POINT_SUPPORTED
  159299. #endif
  159300. #ifndef PNG_NO_FREE_ME
  159301. # define PNG_FREE_ME_SUPPORTED
  159302. #endif
  159303. #if defined(PNG_READ_SUPPORTED)
  159304. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159305. !defined(PNG_NO_READ_TRANSFORMS)
  159306. # define PNG_READ_TRANSFORMS_SUPPORTED
  159307. #endif
  159308. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159309. # ifndef PNG_NO_READ_EXPAND
  159310. # define PNG_READ_EXPAND_SUPPORTED
  159311. # endif
  159312. # ifndef PNG_NO_READ_SHIFT
  159313. # define PNG_READ_SHIFT_SUPPORTED
  159314. # endif
  159315. # ifndef PNG_NO_READ_PACK
  159316. # define PNG_READ_PACK_SUPPORTED
  159317. # endif
  159318. # ifndef PNG_NO_READ_BGR
  159319. # define PNG_READ_BGR_SUPPORTED
  159320. # endif
  159321. # ifndef PNG_NO_READ_SWAP
  159322. # define PNG_READ_SWAP_SUPPORTED
  159323. # endif
  159324. # ifndef PNG_NO_READ_PACKSWAP
  159325. # define PNG_READ_PACKSWAP_SUPPORTED
  159326. # endif
  159327. # ifndef PNG_NO_READ_INVERT
  159328. # define PNG_READ_INVERT_SUPPORTED
  159329. # endif
  159330. # ifndef PNG_NO_READ_DITHER
  159331. # define PNG_READ_DITHER_SUPPORTED
  159332. # endif
  159333. # ifndef PNG_NO_READ_BACKGROUND
  159334. # define PNG_READ_BACKGROUND_SUPPORTED
  159335. # endif
  159336. # ifndef PNG_NO_READ_16_TO_8
  159337. # define PNG_READ_16_TO_8_SUPPORTED
  159338. # endif
  159339. # ifndef PNG_NO_READ_FILLER
  159340. # define PNG_READ_FILLER_SUPPORTED
  159341. # endif
  159342. # ifndef PNG_NO_READ_GAMMA
  159343. # define PNG_READ_GAMMA_SUPPORTED
  159344. # endif
  159345. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159346. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159347. # endif
  159348. # ifndef PNG_NO_READ_SWAP_ALPHA
  159349. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159350. # endif
  159351. # ifndef PNG_NO_READ_INVERT_ALPHA
  159352. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159353. # endif
  159354. # ifndef PNG_NO_READ_STRIP_ALPHA
  159355. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159356. # endif
  159357. # ifndef PNG_NO_READ_USER_TRANSFORM
  159358. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159359. # endif
  159360. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159361. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159362. # endif
  159363. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159364. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159365. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159366. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159367. #endif /* about interlacing capability! You'll */
  159368. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159369. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159370. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159371. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159372. # endif
  159373. #endif
  159374. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159375. #ifndef PNG_NO_READ_EMPTY_PLTE
  159376. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159377. #endif
  159378. #endif
  159379. #endif /* PNG_READ_SUPPORTED */
  159380. #if defined(PNG_WRITE_SUPPORTED)
  159381. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159382. !defined(PNG_NO_WRITE_TRANSFORMS)
  159383. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159384. #endif
  159385. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159386. # ifndef PNG_NO_WRITE_SHIFT
  159387. # define PNG_WRITE_SHIFT_SUPPORTED
  159388. # endif
  159389. # ifndef PNG_NO_WRITE_PACK
  159390. # define PNG_WRITE_PACK_SUPPORTED
  159391. # endif
  159392. # ifndef PNG_NO_WRITE_BGR
  159393. # define PNG_WRITE_BGR_SUPPORTED
  159394. # endif
  159395. # ifndef PNG_NO_WRITE_SWAP
  159396. # define PNG_WRITE_SWAP_SUPPORTED
  159397. # endif
  159398. # ifndef PNG_NO_WRITE_PACKSWAP
  159399. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159400. # endif
  159401. # ifndef PNG_NO_WRITE_INVERT
  159402. # define PNG_WRITE_INVERT_SUPPORTED
  159403. # endif
  159404. # ifndef PNG_NO_WRITE_FILLER
  159405. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159406. # endif
  159407. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159408. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159409. # endif
  159410. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159411. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159412. # endif
  159413. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159414. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159415. # endif
  159416. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159417. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159418. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159419. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159420. encoders, but can cause trouble
  159421. if left undefined */
  159422. #endif
  159423. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159424. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159425. defined(PNG_FLOATING_POINT_SUPPORTED)
  159426. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159427. #endif
  159428. #ifndef PNG_NO_WRITE_FLUSH
  159429. # define PNG_WRITE_FLUSH_SUPPORTED
  159430. #endif
  159431. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159432. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159433. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159434. #endif
  159435. #endif
  159436. #endif /* PNG_WRITE_SUPPORTED */
  159437. #ifndef PNG_1_0_X
  159438. # ifndef PNG_NO_ERROR_NUMBERS
  159439. # define PNG_ERROR_NUMBERS_SUPPORTED
  159440. # endif
  159441. #endif /* PNG_1_0_X */
  159442. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159443. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159444. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159445. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159446. # endif
  159447. #endif
  159448. #ifndef PNG_NO_STDIO
  159449. # define PNG_TIME_RFC1123_SUPPORTED
  159450. #endif
  159451. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159452. # define PNG_EASY_ACCESS_SUPPORTED
  159453. #endif
  159454. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159455. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159456. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159457. # endif
  159458. #endif
  159459. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159460. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159461. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159462. # endif
  159463. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159464. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159465. # define PNG_NO_MMX_CODE
  159466. # endif
  159467. # endif
  159468. # if defined(__APPLE__)
  159469. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159470. # define PNG_NO_MMX_CODE
  159471. # endif
  159472. # endif
  159473. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159474. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159475. # define PNG_NO_MMX_CODE
  159476. # endif
  159477. # endif
  159478. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159479. # define PNG_MMX_CODE_SUPPORTED
  159480. # endif
  159481. #endif
  159482. #if !defined(PNG_1_0_X)
  159483. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159484. # define PNG_USER_MEM_SUPPORTED
  159485. #endif
  159486. #endif /* PNG_1_0_X */
  159487. #if !defined(PNG_1_0_X)
  159488. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159489. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159490. # define PNG_SET_USER_LIMITS_SUPPORTED
  159491. #endif
  159492. #endif
  159493. #endif /* PNG_1_0_X */
  159494. #ifndef PNG_USER_WIDTH_MAX
  159495. # define PNG_USER_WIDTH_MAX 1000000L
  159496. #endif
  159497. #ifndef PNG_USER_HEIGHT_MAX
  159498. # define PNG_USER_HEIGHT_MAX 1000000L
  159499. #endif
  159500. #if defined(PNG_READ_SUPPORTED) && \
  159501. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159502. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159503. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159504. #endif
  159505. #if defined(PNG_WRITE_SUPPORTED) && \
  159506. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159507. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159508. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159509. #endif
  159510. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159511. #ifdef PNG_NO_READ_TEXT
  159512. # define PNG_NO_READ_iTXt
  159513. # define PNG_NO_READ_tEXt
  159514. # define PNG_NO_READ_zTXt
  159515. #endif
  159516. #ifndef PNG_NO_READ_bKGD
  159517. # define PNG_READ_bKGD_SUPPORTED
  159518. # define PNG_bKGD_SUPPORTED
  159519. #endif
  159520. #ifndef PNG_NO_READ_cHRM
  159521. # define PNG_READ_cHRM_SUPPORTED
  159522. # define PNG_cHRM_SUPPORTED
  159523. #endif
  159524. #ifndef PNG_NO_READ_gAMA
  159525. # define PNG_READ_gAMA_SUPPORTED
  159526. # define PNG_gAMA_SUPPORTED
  159527. #endif
  159528. #ifndef PNG_NO_READ_hIST
  159529. # define PNG_READ_hIST_SUPPORTED
  159530. # define PNG_hIST_SUPPORTED
  159531. #endif
  159532. #ifndef PNG_NO_READ_iCCP
  159533. # define PNG_READ_iCCP_SUPPORTED
  159534. # define PNG_iCCP_SUPPORTED
  159535. #endif
  159536. #ifndef PNG_NO_READ_iTXt
  159537. # ifndef PNG_READ_iTXt_SUPPORTED
  159538. # define PNG_READ_iTXt_SUPPORTED
  159539. # endif
  159540. # ifndef PNG_iTXt_SUPPORTED
  159541. # define PNG_iTXt_SUPPORTED
  159542. # endif
  159543. #endif
  159544. #ifndef PNG_NO_READ_oFFs
  159545. # define PNG_READ_oFFs_SUPPORTED
  159546. # define PNG_oFFs_SUPPORTED
  159547. #endif
  159548. #ifndef PNG_NO_READ_pCAL
  159549. # define PNG_READ_pCAL_SUPPORTED
  159550. # define PNG_pCAL_SUPPORTED
  159551. #endif
  159552. #ifndef PNG_NO_READ_sCAL
  159553. # define PNG_READ_sCAL_SUPPORTED
  159554. # define PNG_sCAL_SUPPORTED
  159555. #endif
  159556. #ifndef PNG_NO_READ_pHYs
  159557. # define PNG_READ_pHYs_SUPPORTED
  159558. # define PNG_pHYs_SUPPORTED
  159559. #endif
  159560. #ifndef PNG_NO_READ_sBIT
  159561. # define PNG_READ_sBIT_SUPPORTED
  159562. # define PNG_sBIT_SUPPORTED
  159563. #endif
  159564. #ifndef PNG_NO_READ_sPLT
  159565. # define PNG_READ_sPLT_SUPPORTED
  159566. # define PNG_sPLT_SUPPORTED
  159567. #endif
  159568. #ifndef PNG_NO_READ_sRGB
  159569. # define PNG_READ_sRGB_SUPPORTED
  159570. # define PNG_sRGB_SUPPORTED
  159571. #endif
  159572. #ifndef PNG_NO_READ_tEXt
  159573. # define PNG_READ_tEXt_SUPPORTED
  159574. # define PNG_tEXt_SUPPORTED
  159575. #endif
  159576. #ifndef PNG_NO_READ_tIME
  159577. # define PNG_READ_tIME_SUPPORTED
  159578. # define PNG_tIME_SUPPORTED
  159579. #endif
  159580. #ifndef PNG_NO_READ_tRNS
  159581. # define PNG_READ_tRNS_SUPPORTED
  159582. # define PNG_tRNS_SUPPORTED
  159583. #endif
  159584. #ifndef PNG_NO_READ_zTXt
  159585. # define PNG_READ_zTXt_SUPPORTED
  159586. # define PNG_zTXt_SUPPORTED
  159587. #endif
  159588. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159589. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159590. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159591. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159592. # endif
  159593. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159594. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159595. # endif
  159596. #endif
  159597. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159598. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159599. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159600. # define PNG_USER_CHUNKS_SUPPORTED
  159601. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159602. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159603. # endif
  159604. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159605. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159606. # endif
  159607. #endif
  159608. #ifndef PNG_NO_READ_OPT_PLTE
  159609. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159610. #endif /* optional PLTE chunk in RGB and RGBA images */
  159611. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159612. defined(PNG_READ_zTXt_SUPPORTED)
  159613. # define PNG_READ_TEXT_SUPPORTED
  159614. # define PNG_TEXT_SUPPORTED
  159615. #endif
  159616. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159617. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159618. #ifdef PNG_NO_WRITE_TEXT
  159619. # define PNG_NO_WRITE_iTXt
  159620. # define PNG_NO_WRITE_tEXt
  159621. # define PNG_NO_WRITE_zTXt
  159622. #endif
  159623. #ifndef PNG_NO_WRITE_bKGD
  159624. # define PNG_WRITE_bKGD_SUPPORTED
  159625. # ifndef PNG_bKGD_SUPPORTED
  159626. # define PNG_bKGD_SUPPORTED
  159627. # endif
  159628. #endif
  159629. #ifndef PNG_NO_WRITE_cHRM
  159630. # define PNG_WRITE_cHRM_SUPPORTED
  159631. # ifndef PNG_cHRM_SUPPORTED
  159632. # define PNG_cHRM_SUPPORTED
  159633. # endif
  159634. #endif
  159635. #ifndef PNG_NO_WRITE_gAMA
  159636. # define PNG_WRITE_gAMA_SUPPORTED
  159637. # ifndef PNG_gAMA_SUPPORTED
  159638. # define PNG_gAMA_SUPPORTED
  159639. # endif
  159640. #endif
  159641. #ifndef PNG_NO_WRITE_hIST
  159642. # define PNG_WRITE_hIST_SUPPORTED
  159643. # ifndef PNG_hIST_SUPPORTED
  159644. # define PNG_hIST_SUPPORTED
  159645. # endif
  159646. #endif
  159647. #ifndef PNG_NO_WRITE_iCCP
  159648. # define PNG_WRITE_iCCP_SUPPORTED
  159649. # ifndef PNG_iCCP_SUPPORTED
  159650. # define PNG_iCCP_SUPPORTED
  159651. # endif
  159652. #endif
  159653. #ifndef PNG_NO_WRITE_iTXt
  159654. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159655. # define PNG_WRITE_iTXt_SUPPORTED
  159656. # endif
  159657. # ifndef PNG_iTXt_SUPPORTED
  159658. # define PNG_iTXt_SUPPORTED
  159659. # endif
  159660. #endif
  159661. #ifndef PNG_NO_WRITE_oFFs
  159662. # define PNG_WRITE_oFFs_SUPPORTED
  159663. # ifndef PNG_oFFs_SUPPORTED
  159664. # define PNG_oFFs_SUPPORTED
  159665. # endif
  159666. #endif
  159667. #ifndef PNG_NO_WRITE_pCAL
  159668. # define PNG_WRITE_pCAL_SUPPORTED
  159669. # ifndef PNG_pCAL_SUPPORTED
  159670. # define PNG_pCAL_SUPPORTED
  159671. # endif
  159672. #endif
  159673. #ifndef PNG_NO_WRITE_sCAL
  159674. # define PNG_WRITE_sCAL_SUPPORTED
  159675. # ifndef PNG_sCAL_SUPPORTED
  159676. # define PNG_sCAL_SUPPORTED
  159677. # endif
  159678. #endif
  159679. #ifndef PNG_NO_WRITE_pHYs
  159680. # define PNG_WRITE_pHYs_SUPPORTED
  159681. # ifndef PNG_pHYs_SUPPORTED
  159682. # define PNG_pHYs_SUPPORTED
  159683. # endif
  159684. #endif
  159685. #ifndef PNG_NO_WRITE_sBIT
  159686. # define PNG_WRITE_sBIT_SUPPORTED
  159687. # ifndef PNG_sBIT_SUPPORTED
  159688. # define PNG_sBIT_SUPPORTED
  159689. # endif
  159690. #endif
  159691. #ifndef PNG_NO_WRITE_sPLT
  159692. # define PNG_WRITE_sPLT_SUPPORTED
  159693. # ifndef PNG_sPLT_SUPPORTED
  159694. # define PNG_sPLT_SUPPORTED
  159695. # endif
  159696. #endif
  159697. #ifndef PNG_NO_WRITE_sRGB
  159698. # define PNG_WRITE_sRGB_SUPPORTED
  159699. # ifndef PNG_sRGB_SUPPORTED
  159700. # define PNG_sRGB_SUPPORTED
  159701. # endif
  159702. #endif
  159703. #ifndef PNG_NO_WRITE_tEXt
  159704. # define PNG_WRITE_tEXt_SUPPORTED
  159705. # ifndef PNG_tEXt_SUPPORTED
  159706. # define PNG_tEXt_SUPPORTED
  159707. # endif
  159708. #endif
  159709. #ifndef PNG_NO_WRITE_tIME
  159710. # define PNG_WRITE_tIME_SUPPORTED
  159711. # ifndef PNG_tIME_SUPPORTED
  159712. # define PNG_tIME_SUPPORTED
  159713. # endif
  159714. #endif
  159715. #ifndef PNG_NO_WRITE_tRNS
  159716. # define PNG_WRITE_tRNS_SUPPORTED
  159717. # ifndef PNG_tRNS_SUPPORTED
  159718. # define PNG_tRNS_SUPPORTED
  159719. # endif
  159720. #endif
  159721. #ifndef PNG_NO_WRITE_zTXt
  159722. # define PNG_WRITE_zTXt_SUPPORTED
  159723. # ifndef PNG_zTXt_SUPPORTED
  159724. # define PNG_zTXt_SUPPORTED
  159725. # endif
  159726. #endif
  159727. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159728. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159729. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159730. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159731. # endif
  159732. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159733. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159734. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159735. # endif
  159736. # endif
  159737. #endif
  159738. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159739. defined(PNG_WRITE_zTXt_SUPPORTED)
  159740. # define PNG_WRITE_TEXT_SUPPORTED
  159741. # ifndef PNG_TEXT_SUPPORTED
  159742. # define PNG_TEXT_SUPPORTED
  159743. # endif
  159744. #endif
  159745. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159746. #ifndef PNG_NO_INFO_IMAGE
  159747. # define PNG_INFO_IMAGE_SUPPORTED
  159748. #endif
  159749. #if defined(PNG_tIME_SUPPORTED)
  159750. # if !defined(_WIN32_WCE)
  159751. # include <time.h>
  159752. # endif
  159753. #endif
  159754. typedef unsigned long png_uint_32;
  159755. typedef long png_int_32;
  159756. typedef unsigned short png_uint_16;
  159757. typedef short png_int_16;
  159758. typedef unsigned char png_byte;
  159759. #ifdef PNG_SIZE_T
  159760. typedef PNG_SIZE_T png_size_t;
  159761. # define png_sizeof(x) png_convert_size(sizeof (x))
  159762. #else
  159763. typedef size_t png_size_t;
  159764. # define png_sizeof(x) sizeof (x)
  159765. #endif
  159766. #ifdef __BORLANDC__
  159767. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159768. # define LDATA 1
  159769. # else
  159770. # define LDATA 0
  159771. # endif
  159772. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159773. # define PNG_MAX_MALLOC_64K
  159774. # if (LDATA != 1)
  159775. # ifndef FAR
  159776. # define FAR __far
  159777. # endif
  159778. # define USE_FAR_KEYWORD
  159779. # endif /* LDATA != 1 */
  159780. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159781. #endif /* __BORLANDC__ */
  159782. #if defined(FAR)
  159783. # if defined(M_I86MM)
  159784. # define USE_FAR_KEYWORD
  159785. # define FARDATA FAR
  159786. # include <dos.h>
  159787. # endif
  159788. #endif
  159789. #ifndef FAR
  159790. # define FAR
  159791. #endif
  159792. #ifndef FARDATA
  159793. # define FARDATA
  159794. #endif
  159795. typedef png_int_32 png_fixed_point;
  159796. typedef void FAR * png_voidp;
  159797. typedef png_byte FAR * png_bytep;
  159798. typedef png_uint_32 FAR * png_uint_32p;
  159799. typedef png_int_32 FAR * png_int_32p;
  159800. typedef png_uint_16 FAR * png_uint_16p;
  159801. typedef png_int_16 FAR * png_int_16p;
  159802. typedef PNG_CONST char FAR * png_const_charp;
  159803. typedef char FAR * png_charp;
  159804. typedef png_fixed_point FAR * png_fixed_point_p;
  159805. #ifndef PNG_NO_STDIO
  159806. #if defined(_WIN32_WCE)
  159807. typedef HANDLE png_FILE_p;
  159808. #else
  159809. typedef FILE * png_FILE_p;
  159810. #endif
  159811. #endif
  159812. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159813. typedef double FAR * png_doublep;
  159814. #endif
  159815. typedef png_byte FAR * FAR * png_bytepp;
  159816. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159817. typedef png_int_32 FAR * FAR * png_int_32pp;
  159818. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159819. typedef png_int_16 FAR * FAR * png_int_16pp;
  159820. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159821. typedef char FAR * FAR * png_charpp;
  159822. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159823. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159824. typedef double FAR * FAR * png_doublepp;
  159825. #endif
  159826. typedef char FAR * FAR * FAR * png_charppp;
  159827. #if 0
  159828. typedef charf * png_zcharp;
  159829. typedef charf * FAR * png_zcharpp;
  159830. typedef z_stream FAR * png_zstreamp;
  159831. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159832. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159833. # define PNG_DLL
  159834. #endif
  159835. #if defined(__CYGWIN__)
  159836. # if !defined(PNG_STATIC)
  159837. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159838. # undef PNG_USE_GLOBAL_ARRAYS
  159839. # endif
  159840. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159841. # define PNG_USE_LOCAL_ARRAYS
  159842. # endif
  159843. # else
  159844. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159845. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159846. # undef PNG_USE_GLOBAL_ARRAYS
  159847. # endif
  159848. # endif
  159849. # endif
  159850. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159851. # define PNG_USE_LOCAL_ARRAYS
  159852. # endif
  159853. #endif
  159854. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159855. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159856. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159857. # define PNG_USE_LOCAL_ARRAYS
  159858. # else
  159859. # define PNG_USE_GLOBAL_ARRAYS
  159860. # endif
  159861. #endif
  159862. #if defined(__CYGWIN__)
  159863. # undef PNGAPI
  159864. # define PNGAPI __cdecl
  159865. # undef PNG_IMPEXP
  159866. # define PNG_IMPEXP
  159867. #endif
  159868. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159869. # ifndef PNG_NO_MODULEDEF
  159870. # define PNG_NO_MODULEDEF
  159871. # endif
  159872. #endif
  159873. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159874. # define PNG_IMPEXP
  159875. #endif
  159876. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159877. (( defined(_Windows) || defined(_WINDOWS) || \
  159878. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159879. # ifndef PNGAPI
  159880. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159881. # define PNGAPI __cdecl
  159882. # else
  159883. # define PNGAPI _cdecl
  159884. # endif
  159885. # endif
  159886. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159887. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159888. # define PNG_IMPEXP
  159889. # endif
  159890. # if !defined(PNG_IMPEXP)
  159891. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159892. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159893. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159894. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159895. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159896. # else
  159897. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159898. # if defined(PNG_BUILD_DLL)
  159899. # define PNG_IMPEXP __export
  159900. # else
  159901. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159902. VC++ */
  159903. # endif /* Exists in Borland C++ for
  159904. C++ classes (== huge) */
  159905. # endif
  159906. # endif
  159907. # if !defined(PNG_IMPEXP)
  159908. # if defined(PNG_BUILD_DLL)
  159909. # define PNG_IMPEXP __declspec(dllexport)
  159910. # else
  159911. # define PNG_IMPEXP __declspec(dllimport)
  159912. # endif
  159913. # endif
  159914. # endif /* PNG_IMPEXP */
  159915. #else /* !(DLL || non-cygwin WINDOWS) */
  159916. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  159917. # ifndef PNGAPI
  159918. # define PNGAPI _System
  159919. # endif
  159920. # else
  159921. # if 0 /* ... other platforms, with other meanings */
  159922. # endif
  159923. # endif
  159924. #endif
  159925. #ifndef PNGAPI
  159926. # define PNGAPI
  159927. #endif
  159928. #ifndef PNG_IMPEXP
  159929. # define PNG_IMPEXP
  159930. #endif
  159931. #ifdef PNG_BUILDSYMS
  159932. # ifndef PNG_EXPORT
  159933. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  159934. # endif
  159935. # ifdef PNG_USE_GLOBAL_ARRAYS
  159936. # ifndef PNG_EXPORT_VAR
  159937. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  159938. # endif
  159939. # endif
  159940. #endif
  159941. #ifndef PNG_EXPORT
  159942. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159943. #endif
  159944. #ifdef PNG_USE_GLOBAL_ARRAYS
  159945. # ifndef PNG_EXPORT_VAR
  159946. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  159947. # endif
  159948. #endif
  159949. #ifndef PNG_ABORT
  159950. # define PNG_ABORT() abort()
  159951. #endif
  159952. #ifdef PNG_SETJMP_SUPPORTED
  159953. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  159954. #else
  159955. # define png_jmpbuf(png_ptr) \
  159956. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  159957. #endif
  159958. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  159959. # define CHECK 1
  159960. # define NOCHECK 0
  159961. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  159962. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  159963. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  159964. # define png_strcpy _fstrcpy
  159965. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  159966. # define png_strlen _fstrlen
  159967. # define png_memcmp _fmemcmp /* SJT: added */
  159968. # define png_memcpy _fmemcpy
  159969. # define png_memset _fmemset
  159970. #else /* use the usual functions */
  159971. # define CVT_PTR(ptr) (ptr)
  159972. # define CVT_PTR_NOCHECK(ptr) (ptr)
  159973. # ifndef PNG_NO_SNPRINTF
  159974. # ifdef _MSC_VER
  159975. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  159976. # define png_snprintf2 _snprintf
  159977. # define png_snprintf6 _snprintf
  159978. # else
  159979. # define png_snprintf snprintf /* Added to v 1.2.19 */
  159980. # define png_snprintf2 snprintf
  159981. # define png_snprintf6 snprintf
  159982. # endif
  159983. # else
  159984. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  159985. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  159986. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  159987. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  159988. # endif
  159989. # define png_strcpy strcpy
  159990. # define png_strncpy strncpy /* Added to v 1.2.6 */
  159991. # define png_strlen strlen
  159992. # define png_memcmp memcmp /* SJT: added */
  159993. # define png_memcpy memcpy
  159994. # define png_memset memset
  159995. #endif
  159996. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  159997. # undef PNG_ZBUF_SIZE
  159998. # define PNG_ZBUF_SIZE 65536L
  159999. #endif
  160000. #endif /* PNG_VERSION_INFO_ONLY */
  160001. #endif /* PNGCONF_H */
  160002. /*** End of inlined file: pngconf.h ***/
  160003. #ifdef _MSC_VER
  160004. #pragma warning (disable: 4996 4100)
  160005. #endif
  160006. #if defined(PNG_USER_PRIVATEBUILD)
  160007. # define PNG_LIBPNG_BUILD_TYPE \
  160008. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160009. #else
  160010. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160011. # define PNG_LIBPNG_BUILD_TYPE \
  160012. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160013. # else
  160014. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160015. # endif
  160016. #endif
  160017. #ifndef PNG_VERSION_INFO_ONLY
  160018. #ifdef __cplusplus
  160019. extern "C" {
  160020. #endif /* __cplusplus */
  160021. #ifndef PNG_NO_TYPECAST_NULL
  160022. #define int_p_NULL (int *)NULL
  160023. #define png_bytep_NULL (png_bytep)NULL
  160024. #define png_bytepp_NULL (png_bytepp)NULL
  160025. #define png_doublep_NULL (png_doublep)NULL
  160026. #define png_error_ptr_NULL (png_error_ptr)NULL
  160027. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160028. #define png_free_ptr_NULL (png_free_ptr)NULL
  160029. #define png_infopp_NULL (png_infopp)NULL
  160030. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160031. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160032. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160033. #define png_structp_NULL (png_structp)NULL
  160034. #define png_uint_16p_NULL (png_uint_16p)NULL
  160035. #define png_voidp_NULL (png_voidp)NULL
  160036. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160037. #else
  160038. #define int_p_NULL NULL
  160039. #define png_bytep_NULL NULL
  160040. #define png_bytepp_NULL NULL
  160041. #define png_doublep_NULL NULL
  160042. #define png_error_ptr_NULL NULL
  160043. #define png_flush_ptr_NULL NULL
  160044. #define png_free_ptr_NULL NULL
  160045. #define png_infopp_NULL NULL
  160046. #define png_malloc_ptr_NULL NULL
  160047. #define png_read_status_ptr_NULL NULL
  160048. #define png_rw_ptr_NULL NULL
  160049. #define png_structp_NULL NULL
  160050. #define png_uint_16p_NULL NULL
  160051. #define png_voidp_NULL NULL
  160052. #define png_write_status_ptr_NULL NULL
  160053. #endif
  160054. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160055. #ifdef PNG_USE_GLOBAL_ARRAYS
  160056. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160057. #else
  160058. #define png_libpng_ver png_get_header_ver(NULL)
  160059. #endif
  160060. #ifdef PNG_USE_GLOBAL_ARRAYS
  160061. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160062. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160063. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160064. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160065. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160066. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160067. #endif
  160068. #endif /* PNG_NO_EXTERN */
  160069. typedef struct png_color_struct
  160070. {
  160071. png_byte red;
  160072. png_byte green;
  160073. png_byte blue;
  160074. } png_color;
  160075. typedef png_color FAR * png_colorp;
  160076. typedef png_color FAR * FAR * png_colorpp;
  160077. typedef struct png_color_16_struct
  160078. {
  160079. png_byte index; /* used for palette files */
  160080. png_uint_16 red; /* for use in red green blue files */
  160081. png_uint_16 green;
  160082. png_uint_16 blue;
  160083. png_uint_16 gray; /* for use in grayscale files */
  160084. } png_color_16;
  160085. typedef png_color_16 FAR * png_color_16p;
  160086. typedef png_color_16 FAR * FAR * png_color_16pp;
  160087. typedef struct png_color_8_struct
  160088. {
  160089. png_byte red; /* for use in red green blue files */
  160090. png_byte green;
  160091. png_byte blue;
  160092. png_byte gray; /* for use in grayscale files */
  160093. png_byte alpha; /* for alpha channel files */
  160094. } png_color_8;
  160095. typedef png_color_8 FAR * png_color_8p;
  160096. typedef png_color_8 FAR * FAR * png_color_8pp;
  160097. typedef struct png_sPLT_entry_struct
  160098. {
  160099. png_uint_16 red;
  160100. png_uint_16 green;
  160101. png_uint_16 blue;
  160102. png_uint_16 alpha;
  160103. png_uint_16 frequency;
  160104. } png_sPLT_entry;
  160105. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160106. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160107. typedef struct png_sPLT_struct
  160108. {
  160109. png_charp name; /* palette name */
  160110. png_byte depth; /* depth of palette samples */
  160111. png_sPLT_entryp entries; /* palette entries */
  160112. png_int_32 nentries; /* number of palette entries */
  160113. } png_sPLT_t;
  160114. typedef png_sPLT_t FAR * png_sPLT_tp;
  160115. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160116. #ifdef PNG_TEXT_SUPPORTED
  160117. typedef struct png_text_struct
  160118. {
  160119. int compression; /* compression value:
  160120. -1: tEXt, none
  160121. 0: zTXt, deflate
  160122. 1: iTXt, none
  160123. 2: iTXt, deflate */
  160124. png_charp key; /* keyword, 1-79 character description of "text" */
  160125. png_charp text; /* comment, may be an empty string (ie "")
  160126. or a NULL pointer */
  160127. png_size_t text_length; /* length of the text string */
  160128. #ifdef PNG_iTXt_SUPPORTED
  160129. png_size_t itxt_length; /* length of the itxt string */
  160130. png_charp lang; /* language code, 0-79 characters
  160131. or a NULL pointer */
  160132. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160133. chars or a NULL pointer */
  160134. #endif
  160135. } png_text;
  160136. typedef png_text FAR * png_textp;
  160137. typedef png_text FAR * FAR * png_textpp;
  160138. #endif
  160139. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160140. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160141. #define PNG_TEXT_COMPRESSION_NONE -1
  160142. #define PNG_TEXT_COMPRESSION_zTXt 0
  160143. #define PNG_ITXT_COMPRESSION_NONE 1
  160144. #define PNG_ITXT_COMPRESSION_zTXt 2
  160145. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160146. typedef struct png_time_struct
  160147. {
  160148. png_uint_16 year; /* full year, as in, 1995 */
  160149. png_byte month; /* month of year, 1 - 12 */
  160150. png_byte day; /* day of month, 1 - 31 */
  160151. png_byte hour; /* hour of day, 0 - 23 */
  160152. png_byte minute; /* minute of hour, 0 - 59 */
  160153. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160154. } png_time;
  160155. typedef png_time FAR * png_timep;
  160156. typedef png_time FAR * FAR * png_timepp;
  160157. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160158. typedef struct png_unknown_chunk_t
  160159. {
  160160. png_byte name[5];
  160161. png_byte *data;
  160162. png_size_t size;
  160163. png_byte location; /* mode of operation at read time */
  160164. }
  160165. png_unknown_chunk;
  160166. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160167. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160168. #endif
  160169. typedef struct png_info_struct
  160170. {
  160171. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160172. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160173. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160174. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160175. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160176. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160177. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160178. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160179. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160180. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160181. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160182. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160183. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160184. png_byte pixel_depth; /* number of bits per pixel */
  160185. png_byte spare_byte; /* to align the data, and for future use */
  160186. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160187. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160188. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160189. #endif
  160190. #if defined(PNG_sRGB_SUPPORTED)
  160191. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160192. #endif
  160193. #if defined(PNG_TEXT_SUPPORTED)
  160194. int num_text; /* number of comments read/to write */
  160195. int max_text; /* current size of text array */
  160196. png_textp text; /* array of comments read/to write */
  160197. #endif /* PNG_TEXT_SUPPORTED */
  160198. #if defined(PNG_tIME_SUPPORTED)
  160199. png_time mod_time;
  160200. #endif
  160201. #if defined(PNG_sBIT_SUPPORTED)
  160202. png_color_8 sig_bit; /* significant bits in color channels */
  160203. #endif
  160204. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160205. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160206. png_bytep trans; /* transparent values for paletted image */
  160207. png_color_16 trans_values; /* transparent color for non-palette image */
  160208. #endif
  160209. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160210. png_color_16 background;
  160211. #endif
  160212. #if defined(PNG_oFFs_SUPPORTED)
  160213. png_int_32 x_offset; /* x offset on page */
  160214. png_int_32 y_offset; /* y offset on page */
  160215. png_byte offset_unit_type; /* offset units type */
  160216. #endif
  160217. #if defined(PNG_pHYs_SUPPORTED)
  160218. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160219. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160220. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160221. #endif
  160222. #if defined(PNG_hIST_SUPPORTED)
  160223. png_uint_16p hist;
  160224. #endif
  160225. #ifdef PNG_cHRM_SUPPORTED
  160226. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160227. float x_white;
  160228. float y_white;
  160229. float x_red;
  160230. float y_red;
  160231. float x_green;
  160232. float y_green;
  160233. float x_blue;
  160234. float y_blue;
  160235. #endif
  160236. #endif
  160237. #if defined(PNG_pCAL_SUPPORTED)
  160238. png_charp pcal_purpose; /* pCAL chunk description string */
  160239. png_int_32 pcal_X0; /* minimum value */
  160240. png_int_32 pcal_X1; /* maximum value */
  160241. png_charp pcal_units; /* Latin-1 string giving physical units */
  160242. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160243. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160244. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160245. #endif
  160246. #ifdef PNG_FREE_ME_SUPPORTED
  160247. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160248. #endif
  160249. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160250. png_unknown_chunkp unknown_chunks;
  160251. png_size_t unknown_chunks_num;
  160252. #endif
  160253. #if defined(PNG_iCCP_SUPPORTED)
  160254. png_charp iccp_name; /* profile name */
  160255. png_charp iccp_profile; /* International Color Consortium profile data */
  160256. png_uint_32 iccp_proflen; /* ICC profile data length */
  160257. png_byte iccp_compression; /* Always zero */
  160258. #endif
  160259. #if defined(PNG_sPLT_SUPPORTED)
  160260. png_sPLT_tp splt_palettes;
  160261. png_uint_32 splt_palettes_num;
  160262. #endif
  160263. #if defined(PNG_sCAL_SUPPORTED)
  160264. png_byte scal_unit; /* unit of physical scale */
  160265. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160266. double scal_pixel_width; /* width of one pixel */
  160267. double scal_pixel_height; /* height of one pixel */
  160268. #endif
  160269. #ifdef PNG_FIXED_POINT_SUPPORTED
  160270. png_charp scal_s_width; /* string containing height */
  160271. png_charp scal_s_height; /* string containing width */
  160272. #endif
  160273. #endif
  160274. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160275. png_bytepp row_pointers; /* the image bits */
  160276. #endif
  160277. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160278. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160279. #endif
  160280. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160281. png_fixed_point int_x_white;
  160282. png_fixed_point int_y_white;
  160283. png_fixed_point int_x_red;
  160284. png_fixed_point int_y_red;
  160285. png_fixed_point int_x_green;
  160286. png_fixed_point int_y_green;
  160287. png_fixed_point int_x_blue;
  160288. png_fixed_point int_y_blue;
  160289. #endif
  160290. } png_info;
  160291. typedef png_info FAR * png_infop;
  160292. typedef png_info FAR * FAR * png_infopp;
  160293. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160294. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160295. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160296. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160297. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160298. #endif
  160299. #define PNG_COLOR_MASK_PALETTE 1
  160300. #define PNG_COLOR_MASK_COLOR 2
  160301. #define PNG_COLOR_MASK_ALPHA 4
  160302. #define PNG_COLOR_TYPE_GRAY 0
  160303. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160304. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160305. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160306. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160307. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160308. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160309. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160310. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160311. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160312. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160313. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160314. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160315. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160316. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160317. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160318. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160319. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160320. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160321. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160322. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160323. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160324. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160325. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160326. #define PNG_SCALE_METER 1 /* meters per pixel */
  160327. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160328. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160329. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160330. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160331. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160332. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160333. #define PNG_sRGB_INTENT_RELATIVE 1
  160334. #define PNG_sRGB_INTENT_SATURATION 2
  160335. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160336. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160337. #define PNG_KEYWORD_MAX_LENGTH 79
  160338. #define PNG_MAX_PALETTE_LENGTH 256
  160339. #define PNG_INFO_gAMA 0x0001
  160340. #define PNG_INFO_sBIT 0x0002
  160341. #define PNG_INFO_cHRM 0x0004
  160342. #define PNG_INFO_PLTE 0x0008
  160343. #define PNG_INFO_tRNS 0x0010
  160344. #define PNG_INFO_bKGD 0x0020
  160345. #define PNG_INFO_hIST 0x0040
  160346. #define PNG_INFO_pHYs 0x0080
  160347. #define PNG_INFO_oFFs 0x0100
  160348. #define PNG_INFO_tIME 0x0200
  160349. #define PNG_INFO_pCAL 0x0400
  160350. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160351. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160352. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160353. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160354. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160355. typedef struct png_row_info_struct
  160356. {
  160357. png_uint_32 width; /* width of row */
  160358. png_uint_32 rowbytes; /* number of bytes in row */
  160359. png_byte color_type; /* color type of row */
  160360. png_byte bit_depth; /* bit depth of row */
  160361. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160362. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160363. } png_row_info;
  160364. typedef png_row_info FAR * png_row_infop;
  160365. typedef png_row_info FAR * FAR * png_row_infopp;
  160366. typedef struct png_struct_def png_struct;
  160367. typedef png_struct FAR * png_structp;
  160368. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160369. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160370. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160371. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160372. int));
  160373. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160374. int));
  160375. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160376. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160377. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160378. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160379. png_uint_32, int));
  160380. #endif
  160381. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160382. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160383. defined(PNG_LEGACY_SUPPORTED)
  160384. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160385. png_row_infop, png_bytep));
  160386. #endif
  160387. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160388. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160389. #endif
  160390. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160391. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160392. #endif
  160393. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160394. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160395. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160396. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160397. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160398. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160399. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160400. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160401. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160402. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160403. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160404. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160405. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160406. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160407. #define PNG_FLAG_MNG_FILTER_64 0x04
  160408. #define PNG_ALL_MNG_FEATURES 0x05
  160409. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160410. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160411. struct png_struct_def
  160412. {
  160413. #ifdef PNG_SETJMP_SUPPORTED
  160414. jmp_buf jmpbuf; /* used in png_error */
  160415. #endif
  160416. png_error_ptr error_fn; /* function for printing errors and aborting */
  160417. png_error_ptr warning_fn; /* function for printing warnings */
  160418. png_voidp error_ptr; /* user supplied struct for error functions */
  160419. png_rw_ptr write_data_fn; /* function for writing output data */
  160420. png_rw_ptr read_data_fn; /* function for reading input data */
  160421. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160422. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160423. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160424. #endif
  160425. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160426. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160427. #endif
  160428. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160429. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160430. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160431. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160432. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160433. png_byte user_transform_channels; /* channels in user transformed pixels */
  160434. #endif
  160435. #endif
  160436. png_uint_32 mode; /* tells us where we are in the PNG file */
  160437. png_uint_32 flags; /* flags indicating various things to libpng */
  160438. png_uint_32 transformations; /* which transformations to perform */
  160439. z_stream zstream; /* pointer to decompression structure (below) */
  160440. png_bytep zbuf; /* buffer for zlib */
  160441. png_size_t zbuf_size; /* size of zbuf */
  160442. int zlib_level; /* holds zlib compression level */
  160443. int zlib_method; /* holds zlib compression method */
  160444. int zlib_window_bits; /* holds zlib compression window bits */
  160445. int zlib_mem_level; /* holds zlib compression memory level */
  160446. int zlib_strategy; /* holds zlib compression strategy */
  160447. png_uint_32 width; /* width of image in pixels */
  160448. png_uint_32 height; /* height of image in pixels */
  160449. png_uint_32 num_rows; /* number of rows in current pass */
  160450. png_uint_32 usr_width; /* width of row at start of write */
  160451. png_uint_32 rowbytes; /* size of row in bytes */
  160452. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160453. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160454. png_uint_32 row_number; /* current row in interlace pass */
  160455. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160456. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160457. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160458. png_bytep up_row; /* buffer to save "up" row when filtering */
  160459. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160460. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160461. png_row_info row_info; /* used for transformation routines */
  160462. png_uint_32 idat_size; /* current IDAT size for read */
  160463. png_uint_32 crc; /* current chunk CRC value */
  160464. png_colorp palette; /* palette from the input file */
  160465. png_uint_16 num_palette; /* number of color entries in palette */
  160466. png_uint_16 num_trans; /* number of transparency values */
  160467. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160468. png_byte compression; /* file compression type (always 0) */
  160469. png_byte filter; /* file filter type (always 0) */
  160470. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160471. png_byte pass; /* current interlace pass (0 - 6) */
  160472. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160473. png_byte color_type; /* color type of file */
  160474. png_byte bit_depth; /* bit depth of file */
  160475. png_byte usr_bit_depth; /* bit depth of users row */
  160476. png_byte pixel_depth; /* number of bits per pixel */
  160477. png_byte channels; /* number of channels in file */
  160478. png_byte usr_channels; /* channels at start of write */
  160479. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160480. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160481. #ifdef PNG_LEGACY_SUPPORTED
  160482. png_byte filler; /* filler byte for pixel expansion */
  160483. #else
  160484. png_uint_16 filler; /* filler bytes for pixel expansion */
  160485. #endif
  160486. #endif
  160487. #if defined(PNG_bKGD_SUPPORTED)
  160488. png_byte background_gamma_type;
  160489. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160490. float background_gamma;
  160491. # endif
  160492. png_color_16 background; /* background color in screen gamma space */
  160493. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160494. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160495. #endif
  160496. #endif /* PNG_bKGD_SUPPORTED */
  160497. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160498. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160499. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160500. png_uint_32 flush_rows; /* number of rows written since last flush */
  160501. #endif
  160502. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160503. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160504. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160505. float gamma; /* file gamma value */
  160506. float screen_gamma; /* screen gamma value (display_exponent) */
  160507. #endif
  160508. #endif
  160509. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160510. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160511. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160512. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160513. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160514. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160515. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160516. #endif
  160517. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160518. png_color_8 sig_bit; /* significant bits in each available channel */
  160519. #endif
  160520. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160521. png_color_8 shift; /* shift for significant bit tranformation */
  160522. #endif
  160523. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160524. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160525. png_bytep trans; /* transparency values for paletted files */
  160526. png_color_16 trans_values; /* transparency values for non-paletted files */
  160527. #endif
  160528. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160529. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160530. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160531. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160532. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160533. png_progressive_end_ptr end_fn; /* called after image is complete */
  160534. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160535. png_bytep save_buffer; /* buffer for previously read data */
  160536. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160537. png_bytep current_buffer; /* buffer for recently used data */
  160538. png_uint_32 push_length; /* size of current input chunk */
  160539. png_uint_32 skip_length; /* bytes to skip in input data */
  160540. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160541. png_size_t save_buffer_max; /* total size of save_buffer */
  160542. png_size_t buffer_size; /* total amount of available input data */
  160543. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160544. int process_mode; /* what push library is currently doing */
  160545. int cur_palette; /* current push library palette index */
  160546. # if defined(PNG_TEXT_SUPPORTED)
  160547. png_size_t current_text_size; /* current size of text input data */
  160548. png_size_t current_text_left; /* how much text left to read in input */
  160549. png_charp current_text; /* current text chunk buffer */
  160550. png_charp current_text_ptr; /* current location in current_text */
  160551. # endif /* PNG_TEXT_SUPPORTED */
  160552. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160553. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160554. png_bytepp offset_table_ptr;
  160555. png_bytep offset_table;
  160556. png_uint_16 offset_table_number;
  160557. png_uint_16 offset_table_count;
  160558. png_uint_16 offset_table_count_free;
  160559. #endif
  160560. #if defined(PNG_READ_DITHER_SUPPORTED)
  160561. png_bytep palette_lookup; /* lookup table for dithering */
  160562. png_bytep dither_index; /* index translation for palette files */
  160563. #endif
  160564. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160565. png_uint_16p hist; /* histogram */
  160566. #endif
  160567. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160568. png_byte heuristic_method; /* heuristic for row filter selection */
  160569. png_byte num_prev_filters; /* number of weights for previous rows */
  160570. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160571. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160572. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160573. png_uint_16p filter_costs; /* relative filter calculation cost */
  160574. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160575. #endif
  160576. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160577. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160578. #endif
  160579. #ifdef PNG_FREE_ME_SUPPORTED
  160580. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160581. #endif
  160582. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160583. png_voidp user_chunk_ptr;
  160584. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160585. #endif
  160586. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160587. int num_chunk_list;
  160588. png_bytep chunk_list;
  160589. #endif
  160590. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160591. png_byte rgb_to_gray_status;
  160592. png_uint_16 rgb_to_gray_red_coeff;
  160593. png_uint_16 rgb_to_gray_green_coeff;
  160594. png_uint_16 rgb_to_gray_blue_coeff;
  160595. #endif
  160596. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160597. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160598. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160599. #ifdef PNG_1_0_X
  160600. png_byte mng_features_permitted;
  160601. #else
  160602. png_uint_32 mng_features_permitted;
  160603. #endif /* PNG_1_0_X */
  160604. #endif
  160605. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160606. png_fixed_point int_gamma;
  160607. #endif
  160608. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160609. png_byte filter_type;
  160610. #endif
  160611. #if defined(PNG_1_0_X)
  160612. png_uint_32 row_buf_size;
  160613. #endif
  160614. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160615. # if !defined(PNG_1_0_X)
  160616. # if defined(PNG_MMX_CODE_SUPPORTED)
  160617. png_byte mmx_bitdepth_threshold;
  160618. png_uint_32 mmx_rowbytes_threshold;
  160619. # endif
  160620. png_uint_32 asm_flags;
  160621. # endif
  160622. #endif
  160623. #ifdef PNG_USER_MEM_SUPPORTED
  160624. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160625. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160626. png_free_ptr free_fn; /* function for freeing memory */
  160627. #endif
  160628. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160629. #if defined(PNG_READ_DITHER_SUPPORTED)
  160630. png_bytep dither_sort; /* working sort array */
  160631. png_bytep index_to_palette; /* where the original index currently is */
  160632. png_bytep palette_to_index; /* which original index points to this */
  160633. #endif
  160634. png_byte compression_type;
  160635. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160636. png_uint_32 user_width_max;
  160637. png_uint_32 user_height_max;
  160638. #endif
  160639. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160640. png_unknown_chunk unknown_chunk;
  160641. #endif
  160642. };
  160643. typedef png_structp version_1_2_21;
  160644. typedef png_struct FAR * FAR * png_structpp;
  160645. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160646. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160647. int num_bytes));
  160648. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160649. png_size_t num_to_check));
  160650. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160651. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160652. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160653. png_error_ptr error_fn, png_error_ptr warn_fn));
  160654. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160655. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160656. png_error_ptr error_fn, png_error_ptr warn_fn));
  160657. #ifdef PNG_WRITE_SUPPORTED
  160658. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160659. PNGARG((png_structp png_ptr));
  160660. #endif
  160661. #ifdef PNG_WRITE_SUPPORTED
  160662. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160663. PNGARG((png_structp png_ptr, png_uint_32 size));
  160664. #endif
  160665. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160666. #ifdef PNG_USER_MEM_SUPPORTED
  160667. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160668. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160669. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160670. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160671. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160672. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160673. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160674. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160675. #endif
  160676. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160677. png_bytep chunk_name, png_bytep data, png_size_t length));
  160678. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160679. png_bytep chunk_name, png_uint_32 length));
  160680. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160681. png_bytep data, png_size_t length));
  160682. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160683. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160684. PNGARG((png_structp png_ptr));
  160685. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160686. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160687. #undef png_info_init
  160688. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160689. png_sizeof(png_info));
  160690. #endif
  160691. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160692. png_size_t png_info_struct_size));
  160693. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160694. png_infop info_ptr));
  160695. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160696. png_infop info_ptr));
  160697. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160698. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160699. png_infop info_ptr));
  160700. #endif
  160701. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160702. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160703. PNGARG((png_structp png_ptr, png_timep ptime));
  160704. #endif
  160705. #if !defined(_WIN32_WCE)
  160706. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160707. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160708. struct tm FAR * ttime));
  160709. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160710. time_t ttime));
  160711. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160712. #endif /* _WIN32_WCE */
  160713. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160714. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160715. #if !defined(PNG_1_0_X)
  160716. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160717. png_ptr));
  160718. #endif
  160719. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160720. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160721. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160722. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160723. #endif
  160724. #endif
  160725. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160726. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160727. #endif
  160728. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160729. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160730. #endif
  160731. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160732. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160733. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160734. int error_action, double red, double green ));
  160735. #endif
  160736. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160737. int error_action, png_fixed_point red, png_fixed_point green ));
  160738. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160739. png_ptr));
  160740. #endif
  160741. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160742. png_colorp palette));
  160743. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160744. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160745. #endif
  160746. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160747. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160748. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160749. #endif
  160750. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160751. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160752. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160753. #endif
  160754. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160755. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160756. png_uint_32 filler, int flags));
  160757. #define PNG_FILLER_BEFORE 0
  160758. #define PNG_FILLER_AFTER 1
  160759. #if !defined(PNG_1_0_X)
  160760. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160761. png_uint_32 filler, int flags));
  160762. #endif
  160763. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160764. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160765. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160766. #endif
  160767. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160768. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160769. #endif
  160770. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160771. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160772. #endif
  160773. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160774. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160775. png_color_8p true_bits));
  160776. #endif
  160777. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160778. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160779. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160780. #endif
  160781. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160782. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160783. #endif
  160784. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160785. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160786. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160787. png_color_16p background_color, int background_gamma_code,
  160788. int need_expand, double background_gamma));
  160789. #endif
  160790. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160791. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160792. #define PNG_BACKGROUND_GAMMA_FILE 2
  160793. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160794. #endif
  160795. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160796. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160797. #endif
  160798. #if defined(PNG_READ_DITHER_SUPPORTED)
  160799. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160800. png_colorp palette, int num_palette, int maximum_colors,
  160801. png_uint_16p histogram, int full_dither));
  160802. #endif
  160803. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160804. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160805. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160806. double screen_gamma, double default_file_gamma));
  160807. #endif
  160808. #endif
  160809. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160810. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160811. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160812. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160813. int empty_plte_permitted));
  160814. #endif
  160815. #endif
  160816. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160817. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160818. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160819. #endif
  160820. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160821. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160822. png_infop info_ptr));
  160823. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160824. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160825. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160826. #endif
  160827. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160828. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160829. png_bytep row,
  160830. png_bytep display_row));
  160831. #endif
  160832. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160833. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160834. png_bytepp image));
  160835. #endif
  160836. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160837. png_bytep row));
  160838. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160839. png_bytepp row, png_uint_32 num_rows));
  160840. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160841. png_bytepp image));
  160842. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160843. png_infop info_ptr));
  160844. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160845. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160846. png_infop info_ptr));
  160847. #endif
  160848. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160849. png_infopp info_ptr_ptr));
  160850. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160851. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160852. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160853. png_infop end_info_ptr));
  160854. extern PNG_EXPORT(void,png_destroy_write_struct)
  160855. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160856. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160857. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160858. int crit_action, int ancil_action));
  160859. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160860. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160861. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160862. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160863. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160864. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160865. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160866. int filters));
  160867. #define PNG_NO_FILTERS 0x00
  160868. #define PNG_FILTER_NONE 0x08
  160869. #define PNG_FILTER_SUB 0x10
  160870. #define PNG_FILTER_UP 0x20
  160871. #define PNG_FILTER_AVG 0x40
  160872. #define PNG_FILTER_PAETH 0x80
  160873. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160874. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160875. #define PNG_FILTER_VALUE_NONE 0
  160876. #define PNG_FILTER_VALUE_SUB 1
  160877. #define PNG_FILTER_VALUE_UP 2
  160878. #define PNG_FILTER_VALUE_AVG 3
  160879. #define PNG_FILTER_VALUE_PAETH 4
  160880. #define PNG_FILTER_VALUE_LAST 5
  160881. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160882. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160883. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160884. int heuristic_method, int num_weights, png_doublep filter_weights,
  160885. png_doublep filter_costs));
  160886. #endif
  160887. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160888. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160889. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160890. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160891. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160892. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160893. int level));
  160894. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160895. PNGARG((png_structp png_ptr, int mem_level));
  160896. extern PNG_EXPORT(void,png_set_compression_strategy)
  160897. PNGARG((png_structp png_ptr, int strategy));
  160898. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160899. PNGARG((png_structp png_ptr, int window_bits));
  160900. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160901. int method));
  160902. #if !defined(PNG_NO_STDIO)
  160903. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160904. #endif
  160905. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160906. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160907. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160908. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160909. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160910. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160911. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160912. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160913. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160914. png_read_status_ptr read_row_fn));
  160915. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160916. png_write_status_ptr write_row_fn));
  160917. #ifdef PNG_USER_MEM_SUPPORTED
  160918. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  160919. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160920. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  160921. #endif
  160922. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160923. defined(PNG_LEGACY_SUPPORTED)
  160924. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  160925. png_ptr, png_user_transform_ptr read_user_transform_fn));
  160926. #endif
  160927. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160928. defined(PNG_LEGACY_SUPPORTED)
  160929. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  160930. png_ptr, png_user_transform_ptr write_user_transform_fn));
  160931. #endif
  160932. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160933. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160934. defined(PNG_LEGACY_SUPPORTED)
  160935. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  160936. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  160937. int user_transform_channels));
  160938. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  160939. PNGARG((png_structp png_ptr));
  160940. #endif
  160941. #ifdef PNG_USER_CHUNKS_SUPPORTED
  160942. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  160943. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  160944. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  160945. png_ptr));
  160946. #endif
  160947. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160948. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  160949. png_voidp progressive_ptr,
  160950. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  160951. png_progressive_end_ptr end_fn));
  160952. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  160953. PNGARG((png_structp png_ptr));
  160954. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  160955. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  160956. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  160957. png_bytep old_row, png_bytep new_row));
  160958. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160959. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  160960. png_uint_32 size));
  160961. #if defined(PNG_1_0_X)
  160962. # define png_malloc_warn png_malloc
  160963. #else
  160964. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  160965. png_uint_32 size));
  160966. #endif
  160967. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  160968. #if defined(PNG_1_0_X)
  160969. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  160970. uInt size));
  160971. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  160972. #endif
  160973. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  160974. png_infop info_ptr, png_uint_32 free_me, int num));
  160975. #ifdef PNG_FREE_ME_SUPPORTED
  160976. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  160977. png_infop info_ptr, int freer, png_uint_32 mask));
  160978. #endif
  160979. #define PNG_DESTROY_WILL_FREE_DATA 1
  160980. #define PNG_SET_WILL_FREE_DATA 1
  160981. #define PNG_USER_WILL_FREE_DATA 2
  160982. #define PNG_FREE_HIST 0x0008
  160983. #define PNG_FREE_ICCP 0x0010
  160984. #define PNG_FREE_SPLT 0x0020
  160985. #define PNG_FREE_ROWS 0x0040
  160986. #define PNG_FREE_PCAL 0x0080
  160987. #define PNG_FREE_SCAL 0x0100
  160988. #define PNG_FREE_UNKN 0x0200
  160989. #define PNG_FREE_LIST 0x0400
  160990. #define PNG_FREE_PLTE 0x1000
  160991. #define PNG_FREE_TRNS 0x2000
  160992. #define PNG_FREE_TEXT 0x4000
  160993. #define PNG_FREE_ALL 0x7fff
  160994. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  160995. #ifdef PNG_USER_MEM_SUPPORTED
  160996. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  160997. png_uint_32 size));
  160998. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  160999. png_voidp ptr));
  161000. #endif
  161001. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161002. png_voidp s1, png_voidp s2, png_uint_32 size));
  161003. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161004. png_voidp s1, int value, png_uint_32 size));
  161005. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161006. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161007. int check));
  161008. #endif /* USE_FAR_KEYWORD */
  161009. #ifndef PNG_NO_ERROR_TEXT
  161010. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161011. png_const_charp error_message));
  161012. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161013. png_const_charp error_message));
  161014. #else
  161015. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161016. #endif
  161017. #ifndef PNG_NO_WARNINGS
  161018. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161019. png_const_charp warning_message));
  161020. #ifdef PNG_READ_SUPPORTED
  161021. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161022. png_const_charp warning_message));
  161023. #endif /* PNG_READ_SUPPORTED */
  161024. #endif /* PNG_NO_WARNINGS */
  161025. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161026. png_infop info_ptr, png_uint_32 flag));
  161027. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161028. png_infop info_ptr));
  161029. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161030. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161031. png_infop info_ptr));
  161032. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161033. png_infop info_ptr, png_bytepp row_pointers));
  161034. #endif
  161035. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161036. png_infop info_ptr));
  161037. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161038. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161039. png_ptr, png_infop info_ptr));
  161040. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161041. png_ptr, png_infop info_ptr));
  161042. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161043. png_ptr, png_infop info_ptr));
  161044. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161045. png_ptr, png_infop info_ptr));
  161046. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161047. png_ptr, png_infop info_ptr));
  161048. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161049. png_ptr, png_infop info_ptr));
  161050. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161051. png_ptr, png_infop info_ptr));
  161052. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161053. png_ptr, png_infop info_ptr));
  161054. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161055. png_ptr, png_infop info_ptr));
  161056. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161057. png_ptr, png_infop info_ptr));
  161058. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161059. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161060. png_ptr, png_infop info_ptr));
  161061. #endif
  161062. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161063. png_ptr, png_infop info_ptr));
  161064. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161065. png_ptr, png_infop info_ptr));
  161066. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161067. png_ptr, png_infop info_ptr));
  161068. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161069. png_ptr, png_infop info_ptr));
  161070. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161071. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161072. png_infop info_ptr));
  161073. #if defined(PNG_bKGD_SUPPORTED)
  161074. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161075. png_infop info_ptr, png_color_16p *background));
  161076. #endif
  161077. #if defined(PNG_bKGD_SUPPORTED)
  161078. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161079. png_infop info_ptr, png_color_16p background));
  161080. #endif
  161081. #if defined(PNG_cHRM_SUPPORTED)
  161082. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161083. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161084. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161085. double *red_y, double *green_x, double *green_y, double *blue_x,
  161086. double *blue_y));
  161087. #endif
  161088. #ifdef PNG_FIXED_POINT_SUPPORTED
  161089. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161090. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161091. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161092. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161093. *int_blue_x, png_fixed_point *int_blue_y));
  161094. #endif
  161095. #endif
  161096. #if defined(PNG_cHRM_SUPPORTED)
  161097. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161098. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161099. png_infop info_ptr, double white_x, double white_y, double red_x,
  161100. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161101. #endif
  161102. #ifdef PNG_FIXED_POINT_SUPPORTED
  161103. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161104. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161105. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161106. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161107. png_fixed_point int_blue_y));
  161108. #endif
  161109. #endif
  161110. #if defined(PNG_gAMA_SUPPORTED)
  161111. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161112. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161113. png_infop info_ptr, double *file_gamma));
  161114. #endif
  161115. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161116. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161117. #endif
  161118. #if defined(PNG_gAMA_SUPPORTED)
  161119. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161120. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161121. png_infop info_ptr, double file_gamma));
  161122. #endif
  161123. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161124. png_infop info_ptr, png_fixed_point int_file_gamma));
  161125. #endif
  161126. #if defined(PNG_hIST_SUPPORTED)
  161127. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161128. png_infop info_ptr, png_uint_16p *hist));
  161129. #endif
  161130. #if defined(PNG_hIST_SUPPORTED)
  161131. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161132. png_infop info_ptr, png_uint_16p hist));
  161133. #endif
  161134. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161135. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161136. int *bit_depth, int *color_type, int *interlace_method,
  161137. int *compression_method, int *filter_method));
  161138. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161139. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161140. int color_type, int interlace_method, int compression_method,
  161141. int filter_method));
  161142. #if defined(PNG_oFFs_SUPPORTED)
  161143. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161144. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161145. int *unit_type));
  161146. #endif
  161147. #if defined(PNG_oFFs_SUPPORTED)
  161148. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161149. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161150. int unit_type));
  161151. #endif
  161152. #if defined(PNG_pCAL_SUPPORTED)
  161153. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161154. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161155. int *type, int *nparams, png_charp *units, png_charpp *params));
  161156. #endif
  161157. #if defined(PNG_pCAL_SUPPORTED)
  161158. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161159. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161160. int type, int nparams, png_charp units, png_charpp params));
  161161. #endif
  161162. #if defined(PNG_pHYs_SUPPORTED)
  161163. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161164. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161165. #endif
  161166. #if defined(PNG_pHYs_SUPPORTED)
  161167. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161168. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161169. #endif
  161170. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161171. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161172. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161173. png_infop info_ptr, png_colorp palette, int num_palette));
  161174. #if defined(PNG_sBIT_SUPPORTED)
  161175. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161176. png_infop info_ptr, png_color_8p *sig_bit));
  161177. #endif
  161178. #if defined(PNG_sBIT_SUPPORTED)
  161179. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161180. png_infop info_ptr, png_color_8p sig_bit));
  161181. #endif
  161182. #if defined(PNG_sRGB_SUPPORTED)
  161183. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161184. png_infop info_ptr, int *intent));
  161185. #endif
  161186. #if defined(PNG_sRGB_SUPPORTED)
  161187. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161188. png_infop info_ptr, int intent));
  161189. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161190. png_infop info_ptr, int intent));
  161191. #endif
  161192. #if defined(PNG_iCCP_SUPPORTED)
  161193. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161194. png_infop info_ptr, png_charpp name, int *compression_type,
  161195. png_charpp profile, png_uint_32 *proflen));
  161196. #endif
  161197. #if defined(PNG_iCCP_SUPPORTED)
  161198. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161199. png_infop info_ptr, png_charp name, int compression_type,
  161200. png_charp profile, png_uint_32 proflen));
  161201. #endif
  161202. #if defined(PNG_sPLT_SUPPORTED)
  161203. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161204. png_infop info_ptr, png_sPLT_tpp entries));
  161205. #endif
  161206. #if defined(PNG_sPLT_SUPPORTED)
  161207. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161208. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161209. #endif
  161210. #if defined(PNG_TEXT_SUPPORTED)
  161211. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161212. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161213. #endif
  161214. #if defined(PNG_TEXT_SUPPORTED)
  161215. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161216. png_infop info_ptr, png_textp text_ptr, int num_text));
  161217. #endif
  161218. #if defined(PNG_tIME_SUPPORTED)
  161219. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161220. png_infop info_ptr, png_timep *mod_time));
  161221. #endif
  161222. #if defined(PNG_tIME_SUPPORTED)
  161223. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161224. png_infop info_ptr, png_timep mod_time));
  161225. #endif
  161226. #if defined(PNG_tRNS_SUPPORTED)
  161227. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161228. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161229. png_color_16p *trans_values));
  161230. #endif
  161231. #if defined(PNG_tRNS_SUPPORTED)
  161232. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161233. png_infop info_ptr, png_bytep trans, int num_trans,
  161234. png_color_16p trans_values));
  161235. #endif
  161236. #if defined(PNG_tRNS_SUPPORTED)
  161237. #endif
  161238. #if defined(PNG_sCAL_SUPPORTED)
  161239. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161240. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161241. png_infop info_ptr, int *unit, double *width, double *height));
  161242. #else
  161243. #ifdef PNG_FIXED_POINT_SUPPORTED
  161244. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161245. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161246. #endif
  161247. #endif
  161248. #endif /* PNG_sCAL_SUPPORTED */
  161249. #if defined(PNG_sCAL_SUPPORTED)
  161250. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161251. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161252. png_infop info_ptr, int unit, double width, double height));
  161253. #else
  161254. #ifdef PNG_FIXED_POINT_SUPPORTED
  161255. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161256. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161257. #endif
  161258. #endif
  161259. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161260. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161261. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161262. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161263. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161264. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161265. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161266. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161267. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161268. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161269. #endif
  161270. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161271. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161272. chunk_name));
  161273. #endif
  161274. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161275. png_infop info_ptr, int mask));
  161276. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161277. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161278. png_infop info_ptr,
  161279. int transforms,
  161280. png_voidp params));
  161281. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161282. png_infop info_ptr,
  161283. int transforms,
  161284. png_voidp params));
  161285. #endif
  161286. #ifdef PNG_DEBUG
  161287. #if (PNG_DEBUG > 0)
  161288. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161289. #include <crtdbg.h>
  161290. #if (PNG_DEBUG > 1)
  161291. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161292. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161293. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161294. #endif
  161295. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161296. #ifndef PNG_DEBUG_FILE
  161297. #define PNG_DEBUG_FILE stderr
  161298. #endif /* PNG_DEBUG_FILE */
  161299. #if (PNG_DEBUG > 1)
  161300. #define png_debug(l,m) \
  161301. { \
  161302. int num_tabs=l; \
  161303. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161304. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161305. }
  161306. #define png_debug1(l,m,p1) \
  161307. { \
  161308. int num_tabs=l; \
  161309. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161310. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161311. }
  161312. #define png_debug2(l,m,p1,p2) \
  161313. { \
  161314. int num_tabs=l; \
  161315. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161316. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161317. }
  161318. #endif /* (PNG_DEBUG > 1) */
  161319. #endif /* _MSC_VER */
  161320. #endif /* (PNG_DEBUG > 0) */
  161321. #endif /* PNG_DEBUG */
  161322. #ifndef png_debug
  161323. #define png_debug(l, m)
  161324. #endif
  161325. #ifndef png_debug1
  161326. #define png_debug1(l, m, p1)
  161327. #endif
  161328. #ifndef png_debug2
  161329. #define png_debug2(l, m, p1, p2)
  161330. #endif
  161331. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161332. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161333. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161334. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161335. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161336. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161337. png_ptr, png_uint_32 mng_features_permitted));
  161338. #endif
  161339. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161340. #define PNG_HANDLE_CHUNK_NEVER 1
  161341. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161342. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161343. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161344. #if defined(PNG_MMX_CODE_SUPPORTED)
  161345. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161346. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161347. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161348. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161349. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161350. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161351. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161352. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161353. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161354. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161355. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161356. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161357. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161358. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161359. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161360. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161361. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161362. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161363. | PNG_MMX_READ_FLAGS \
  161364. | PNG_MMX_WRITE_FLAGS )
  161365. #define PNG_SELECT_READ 1
  161366. #define PNG_SELECT_WRITE 2
  161367. #endif /* PNG_MMX_CODE_SUPPORTED */
  161368. #if !defined(PNG_1_0_X)
  161369. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161370. PNGARG((int flag_select, int *compilerID));
  161371. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161372. PNGARG((int flag_select));
  161373. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161374. PNGARG((png_structp png_ptr));
  161375. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161376. PNGARG((png_structp png_ptr));
  161377. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161378. PNGARG((png_structp png_ptr));
  161379. extern PNG_EXPORT(void,png_set_asm_flags)
  161380. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161381. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161382. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161383. png_uint_32 mmx_rowbytes_threshold));
  161384. #endif /* PNG_1_0_X */
  161385. #if !defined(PNG_1_0_X)
  161386. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161387. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161388. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161389. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161390. png_ptr, png_uint_32 strip_mode));
  161391. #endif
  161392. #endif /* PNG_1_0_X */
  161393. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161394. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161395. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161396. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161397. png_ptr));
  161398. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161399. png_ptr));
  161400. #endif
  161401. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161402. # define png_composite(composite, fg, alpha, bg) \
  161403. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161404. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161405. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161406. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161407. # define png_composite_16(composite, fg, alpha, bg) \
  161408. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161409. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161410. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161411. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161412. #else /* standard method using integer division */
  161413. # define png_composite(composite, fg, alpha, bg) \
  161414. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161415. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161416. (png_uint_16)127) / 255)
  161417. # define png_composite_16(composite, fg, alpha, bg) \
  161418. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161419. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161420. (png_uint_32)32767) / (png_uint_32)65535L)
  161421. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161422. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161423. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161424. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161425. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161426. #else
  161427. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161428. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161429. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161430. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161431. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161432. PNGARG((png_structp png_ptr, png_bytep buf));
  161433. extern PNG_EXPORT(void,png_save_uint_32)
  161434. PNGARG((png_bytep buf, png_uint_32 i));
  161435. extern PNG_EXPORT(void,png_save_int_32)
  161436. PNGARG((png_bytep buf, png_int_32 i));
  161437. extern PNG_EXPORT(void,png_save_uint_16)
  161438. PNGARG((png_bytep buf, unsigned int i));
  161439. #define PNG_HAVE_IHDR 0x01
  161440. #define PNG_HAVE_PLTE 0x02
  161441. #define PNG_HAVE_IDAT 0x04
  161442. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161443. #define PNG_HAVE_IEND 0x10
  161444. #if defined(PNG_INTERNAL)
  161445. #define PNG_HAVE_gAMA 0x20
  161446. #define PNG_HAVE_cHRM 0x40
  161447. #define PNG_HAVE_sRGB 0x80
  161448. #define PNG_HAVE_CHUNK_HEADER 0x100
  161449. #define PNG_WROTE_tIME 0x200
  161450. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161451. #define PNG_BACKGROUND_IS_GRAY 0x800
  161452. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161453. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161454. #define PNG_BGR 0x0001
  161455. #define PNG_INTERLACE 0x0002
  161456. #define PNG_PACK 0x0004
  161457. #define PNG_SHIFT 0x0008
  161458. #define PNG_SWAP_BYTES 0x0010
  161459. #define PNG_INVERT_MONO 0x0020
  161460. #define PNG_DITHER 0x0040
  161461. #define PNG_BACKGROUND 0x0080
  161462. #define PNG_BACKGROUND_EXPAND 0x0100
  161463. #define PNG_16_TO_8 0x0400
  161464. #define PNG_RGBA 0x0800
  161465. #define PNG_EXPAND 0x1000
  161466. #define PNG_GAMMA 0x2000
  161467. #define PNG_GRAY_TO_RGB 0x4000
  161468. #define PNG_FILLER 0x8000L
  161469. #define PNG_PACKSWAP 0x10000L
  161470. #define PNG_SWAP_ALPHA 0x20000L
  161471. #define PNG_STRIP_ALPHA 0x40000L
  161472. #define PNG_INVERT_ALPHA 0x80000L
  161473. #define PNG_USER_TRANSFORM 0x100000L
  161474. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161475. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161476. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161477. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161478. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161479. #define PNG_STRUCT_PNG 0x0001
  161480. #define PNG_STRUCT_INFO 0x0002
  161481. #define PNG_WEIGHT_SHIFT 8
  161482. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161483. #define PNG_COST_SHIFT 3
  161484. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161485. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161486. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161487. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161488. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161489. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161490. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161491. #define PNG_FLAG_ROW_INIT 0x0040
  161492. #define PNG_FLAG_FILLER_AFTER 0x0080
  161493. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161494. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161495. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161496. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161497. #define PNG_FLAG_FREE_PLTE 0x1000
  161498. #define PNG_FLAG_FREE_TRNS 0x2000
  161499. #define PNG_FLAG_FREE_HIST 0x4000
  161500. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161501. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161502. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161503. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161504. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161505. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161506. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161507. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161508. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161509. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161510. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161511. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161512. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161513. PNG_FLAG_CRC_CRITICAL_MASK)
  161514. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161515. abs((int)((c1).green) - (int)((c2).green)) + \
  161516. abs((int)((c1).blue) - (int)((c2).blue)))
  161517. #define PNG_ROWBYTES(pixel_bits, width) \
  161518. ((pixel_bits) >= 8 ? \
  161519. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161520. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161521. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161522. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161523. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161524. #ifdef PNG_USE_GLOBAL_ARRAYS
  161525. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161526. #else
  161527. #endif
  161528. #endif /* PNG_NO_EXTERN */
  161529. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161530. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161531. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161532. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161533. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161534. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161535. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161536. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161537. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161538. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161539. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161540. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161541. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161542. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161543. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161544. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161545. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161546. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161547. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161548. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161549. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161550. #ifdef PNG_USE_GLOBAL_ARRAYS
  161551. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161552. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161553. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161554. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161555. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161556. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161557. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161558. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161559. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161560. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161561. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161562. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161563. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161564. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161565. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161566. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161567. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161568. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161569. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161570. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161571. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161572. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161573. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161574. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161575. #undef png_read_init
  161576. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161577. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161578. #endif
  161579. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161580. png_const_charp user_png_ver, png_size_t png_struct_size));
  161581. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161582. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161583. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161584. png_info_size));
  161585. #endif
  161586. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161587. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161588. #undef png_write_init
  161589. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161590. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161591. #endif
  161592. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161593. png_const_charp user_png_ver, png_size_t png_struct_size));
  161594. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161595. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161596. png_info_size));
  161597. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161598. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161599. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161600. malloc_fn, png_voidp mem_ptr));
  161601. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161602. png_free_ptr free_fn, png_voidp mem_ptr));
  161603. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161604. png_infop info_ptr));
  161605. #ifndef PNG_1_0_X
  161606. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161607. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161608. #ifdef PNG_SIZE_T
  161609. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161610. #endif
  161611. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161612. png_bytep data, png_size_t length));
  161613. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161614. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161615. png_bytep buffer, png_size_t length));
  161616. #endif
  161617. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161618. png_bytep data, png_size_t length));
  161619. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161620. #if !defined(PNG_NO_STDIO)
  161621. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161622. #endif
  161623. #endif
  161624. #else /* PNG_1_0_X */
  161625. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161626. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161627. png_bytep buffer, png_size_t length));
  161628. #endif
  161629. #endif /* PNG_1_0_X */
  161630. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161631. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161632. png_size_t length));
  161633. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161634. png_size_t length));
  161635. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161636. png_size_t length));
  161637. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161638. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161639. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161640. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161641. png_size_t prefix_length, png_size_t *data_length));
  161642. #endif
  161643. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161644. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161645. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161646. png_size_t length));
  161647. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161648. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161649. #endif
  161650. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161651. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161652. png_uint_32 height,
  161653. int bit_depth, int color_type, int compression_method, int filter_method,
  161654. int interlace_method));
  161655. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161656. png_uint_32 num_pal));
  161657. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161658. png_size_t length));
  161659. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161660. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161661. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161662. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161663. #endif
  161664. #ifdef PNG_FIXED_POINT_SUPPORTED
  161665. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161666. file_gamma));
  161667. #endif
  161668. #endif
  161669. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161670. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161671. int color_type));
  161672. #endif
  161673. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161674. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161675. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161676. double white_x, double white_y,
  161677. double red_x, double red_y, double green_x, double green_y,
  161678. double blue_x, double blue_y));
  161679. #endif
  161680. #ifdef PNG_FIXED_POINT_SUPPORTED
  161681. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161682. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161683. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161684. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161685. png_fixed_point int_blue_y));
  161686. #endif
  161687. #endif
  161688. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161689. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161690. int intent));
  161691. #endif
  161692. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161693. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161694. png_charp name, int compression_type,
  161695. png_charp profile, int proflen));
  161696. #endif
  161697. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161698. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161699. png_sPLT_tp palette));
  161700. #endif
  161701. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161702. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161703. png_color_16p values, int number, int color_type));
  161704. #endif
  161705. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161706. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161707. png_color_16p values, int color_type));
  161708. #endif
  161709. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161710. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161711. int num_hist));
  161712. #endif
  161713. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161714. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161715. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161716. png_charp key, png_charpp new_key));
  161717. #endif
  161718. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161719. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161720. png_charp text, png_size_t text_len));
  161721. #endif
  161722. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161723. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161724. png_charp text, png_size_t text_len, int compression));
  161725. #endif
  161726. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161727. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161728. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161729. png_charp text));
  161730. #endif
  161731. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161732. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161733. png_infop info_ptr, png_textp text_ptr, int num_text));
  161734. #endif
  161735. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161736. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161737. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161738. #endif
  161739. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161740. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161741. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161742. png_charp units, png_charpp params));
  161743. #endif
  161744. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161745. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161746. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161747. int unit_type));
  161748. #endif
  161749. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161750. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161751. png_timep mod_time));
  161752. #endif
  161753. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161754. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161755. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161756. int unit, double width, double height));
  161757. #else
  161758. #ifdef PNG_FIXED_POINT_SUPPORTED
  161759. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161760. int unit, png_charp width, png_charp height));
  161761. #endif
  161762. #endif
  161763. #endif
  161764. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161765. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161766. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161767. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161768. #endif
  161769. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161770. int mask));
  161771. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161772. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161773. #endif
  161774. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161775. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161776. png_bytep row, int pass));
  161777. #endif
  161778. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161779. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161780. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161781. png_row_infop row_info));
  161782. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161783. png_bytep filtered_row));
  161784. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161785. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161786. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161787. png_infop info_ptr));
  161788. #if defined(PNG_READ_FILLER_SUPPORTED)
  161789. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161790. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161791. #endif
  161792. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161793. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161794. png_bytep row));
  161795. #endif
  161796. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161797. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161798. png_bytep row));
  161799. #endif
  161800. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161801. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161802. png_bytep row));
  161803. #endif
  161804. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161805. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161806. png_bytep row));
  161807. #endif
  161808. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161809. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161810. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161811. png_bytep row, png_uint_32 flags));
  161812. #endif
  161813. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161814. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161815. #endif
  161816. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161817. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161818. #endif
  161819. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161820. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161821. row_info, png_bytep row));
  161822. #endif
  161823. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161824. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161825. png_bytep row));
  161826. #endif
  161827. #if defined(PNG_READ_PACK_SUPPORTED)
  161828. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161829. #endif
  161830. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161831. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161832. png_color_8p sig_bits));
  161833. #endif
  161834. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161835. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161836. #endif
  161837. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161838. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161839. #endif
  161840. #if defined(PNG_READ_DITHER_SUPPORTED)
  161841. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161842. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161843. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161844. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161845. png_colorp palette, int num_palette));
  161846. # endif
  161847. #endif
  161848. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161849. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161850. #endif
  161851. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161852. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161853. png_bytep row, png_uint_32 bit_depth));
  161854. #endif
  161855. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161856. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161857. png_color_8p bit_depth));
  161858. #endif
  161859. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161860. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161861. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161862. png_color_16p trans_values, png_color_16p background,
  161863. png_color_16p background_1,
  161864. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161865. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161866. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161867. #else
  161868. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161869. png_color_16p trans_values, png_color_16p background));
  161870. #endif
  161871. #endif
  161872. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161873. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161874. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161875. int gamma_shift));
  161876. #endif
  161877. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161878. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161879. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161880. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161881. png_bytep row, png_color_16p trans_value));
  161882. #endif
  161883. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161884. png_uint_32 length));
  161885. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161886. png_uint_32 length));
  161887. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161888. png_uint_32 length));
  161889. #if defined(PNG_READ_bKGD_SUPPORTED)
  161890. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161891. png_uint_32 length));
  161892. #endif
  161893. #if defined(PNG_READ_cHRM_SUPPORTED)
  161894. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161895. png_uint_32 length));
  161896. #endif
  161897. #if defined(PNG_READ_gAMA_SUPPORTED)
  161898. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161899. png_uint_32 length));
  161900. #endif
  161901. #if defined(PNG_READ_hIST_SUPPORTED)
  161902. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161903. png_uint_32 length));
  161904. #endif
  161905. #if defined(PNG_READ_iCCP_SUPPORTED)
  161906. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161907. png_uint_32 length));
  161908. #endif /* PNG_READ_iCCP_SUPPORTED */
  161909. #if defined(PNG_READ_iTXt_SUPPORTED)
  161910. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161911. png_uint_32 length));
  161912. #endif
  161913. #if defined(PNG_READ_oFFs_SUPPORTED)
  161914. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161915. png_uint_32 length));
  161916. #endif
  161917. #if defined(PNG_READ_pCAL_SUPPORTED)
  161918. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161919. png_uint_32 length));
  161920. #endif
  161921. #if defined(PNG_READ_pHYs_SUPPORTED)
  161922. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161923. png_uint_32 length));
  161924. #endif
  161925. #if defined(PNG_READ_sBIT_SUPPORTED)
  161926. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161927. png_uint_32 length));
  161928. #endif
  161929. #if defined(PNG_READ_sCAL_SUPPORTED)
  161930. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161931. png_uint_32 length));
  161932. #endif
  161933. #if defined(PNG_READ_sPLT_SUPPORTED)
  161934. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161935. png_uint_32 length));
  161936. #endif /* PNG_READ_sPLT_SUPPORTED */
  161937. #if defined(PNG_READ_sRGB_SUPPORTED)
  161938. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  161939. png_uint_32 length));
  161940. #endif
  161941. #if defined(PNG_READ_tEXt_SUPPORTED)
  161942. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161943. png_uint_32 length));
  161944. #endif
  161945. #if defined(PNG_READ_tIME_SUPPORTED)
  161946. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  161947. png_uint_32 length));
  161948. #endif
  161949. #if defined(PNG_READ_tRNS_SUPPORTED)
  161950. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  161951. png_uint_32 length));
  161952. #endif
  161953. #if defined(PNG_READ_zTXt_SUPPORTED)
  161954. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161955. png_uint_32 length));
  161956. #endif
  161957. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  161958. png_infop info_ptr, png_uint_32 length));
  161959. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  161960. png_bytep chunk_name));
  161961. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  161962. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  161963. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  161964. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161965. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  161966. png_infop info_ptr));
  161967. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  161968. png_infop info_ptr));
  161969. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  161970. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  161971. png_uint_32 length));
  161972. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  161973. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  161974. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  161975. png_bytep buffer, png_size_t buffer_length));
  161976. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  161977. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  161978. png_bytep buffer, png_size_t buffer_length));
  161979. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  161980. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  161981. png_infop info_ptr, png_uint_32 length));
  161982. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  161983. png_infop info_ptr));
  161984. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  161985. png_infop info_ptr));
  161986. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  161987. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  161988. png_infop info_ptr));
  161989. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  161990. png_infop info_ptr));
  161991. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  161992. #if defined(PNG_READ_tEXt_SUPPORTED)
  161993. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  161994. png_infop info_ptr, png_uint_32 length));
  161995. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  161996. png_infop info_ptr));
  161997. #endif
  161998. #if defined(PNG_READ_zTXt_SUPPORTED)
  161999. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162000. png_infop info_ptr, png_uint_32 length));
  162001. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162002. png_infop info_ptr));
  162003. #endif
  162004. #if defined(PNG_READ_iTXt_SUPPORTED)
  162005. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162006. png_infop info_ptr, png_uint_32 length));
  162007. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162008. png_infop info_ptr));
  162009. #endif
  162010. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162011. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162012. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162013. png_bytep row));
  162014. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162015. png_bytep row));
  162016. #endif
  162017. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162018. #if defined(PNG_MMX_CODE_SUPPORTED)
  162019. /* PRIVATE */
  162020. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162021. #endif
  162022. #endif
  162023. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162024. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162025. png_infop info_ptr));
  162026. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162027. png_infop info_ptr));
  162028. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162029. png_infop info_ptr));
  162030. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162031. png_infop info_ptr));
  162032. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162033. png_infop info_ptr));
  162034. #if defined(PNG_pHYs_SUPPORTED)
  162035. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162036. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162037. #endif /* PNG_pHYs_SUPPORTED */
  162038. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162039. #endif /* PNG_INTERNAL */
  162040. #ifdef __cplusplus
  162041. }
  162042. #endif
  162043. #endif /* PNG_VERSION_INFO_ONLY */
  162044. #endif /* PNG_H */
  162045. /*** End of inlined file: png.h ***/
  162046. #define PNG_NO_EXTERN
  162047. /*** Start of inlined file: png.c ***/
  162048. #define PNG_INTERNAL
  162049. #define PNG_NO_EXTERN
  162050. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162051. #ifdef PNG_USE_GLOBAL_ARRAYS
  162052. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162053. #ifdef PNG_READ_SUPPORTED
  162054. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162055. #endif /* PNG_READ_SUPPORTED */
  162056. PNG_IHDR;
  162057. PNG_IDAT;
  162058. PNG_IEND;
  162059. PNG_PLTE;
  162060. PNG_bKGD;
  162061. PNG_cHRM;
  162062. PNG_gAMA;
  162063. PNG_hIST;
  162064. PNG_iCCP;
  162065. PNG_iTXt;
  162066. PNG_oFFs;
  162067. PNG_pCAL;
  162068. PNG_sCAL;
  162069. PNG_pHYs;
  162070. PNG_sBIT;
  162071. PNG_sPLT;
  162072. PNG_sRGB;
  162073. PNG_tEXt;
  162074. PNG_tIME;
  162075. PNG_tRNS;
  162076. PNG_zTXt;
  162077. #ifdef PNG_READ_SUPPORTED
  162078. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162079. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162080. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162081. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162082. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162083. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162084. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162085. #endif /* PNG_READ_SUPPORTED */
  162086. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162087. #ifdef PNG_READ_SUPPORTED
  162088. void PNGAPI
  162089. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162090. {
  162091. if(png_ptr == NULL) return;
  162092. png_debug(1, "in png_set_sig_bytes\n");
  162093. if (num_bytes > 8)
  162094. png_error(png_ptr, "Too many bytes for PNG signature.");
  162095. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162096. }
  162097. int PNGAPI
  162098. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162099. {
  162100. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162101. if (num_to_check > 8)
  162102. num_to_check = 8;
  162103. else if (num_to_check < 1)
  162104. return (-1);
  162105. if (start > 7)
  162106. return (-1);
  162107. if (start + num_to_check > 8)
  162108. num_to_check = 8 - start;
  162109. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162110. }
  162111. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162112. int PNGAPI
  162113. png_check_sig(png_bytep sig, int num)
  162114. {
  162115. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162116. }
  162117. #endif
  162118. #endif /* PNG_READ_SUPPORTED */
  162119. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162120. #ifdef PNG_1_0_X
  162121. voidpf PNGAPI
  162122. #else
  162123. voidpf /* private */
  162124. #endif
  162125. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162126. {
  162127. png_voidp ptr;
  162128. png_structp p=(png_structp)png_ptr;
  162129. png_uint_32 save_flags=p->flags;
  162130. png_uint_32 num_bytes;
  162131. if(png_ptr == NULL) return (NULL);
  162132. if (items > PNG_UINT_32_MAX/size)
  162133. {
  162134. png_warning (p, "Potential overflow in png_zalloc()");
  162135. return (NULL);
  162136. }
  162137. num_bytes = (png_uint_32)items * size;
  162138. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162139. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162140. p->flags=save_flags;
  162141. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162142. if (ptr == NULL)
  162143. return ((voidpf)ptr);
  162144. if (num_bytes > (png_uint_32)0x8000L)
  162145. {
  162146. png_memset(ptr, 0, (png_size_t)0x8000L);
  162147. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162148. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162149. }
  162150. else
  162151. {
  162152. png_memset(ptr, 0, (png_size_t)num_bytes);
  162153. }
  162154. #endif
  162155. return ((voidpf)ptr);
  162156. }
  162157. #ifdef PNG_1_0_X
  162158. void PNGAPI
  162159. #else
  162160. void /* private */
  162161. #endif
  162162. png_zfree(voidpf png_ptr, voidpf ptr)
  162163. {
  162164. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162165. }
  162166. void /* PRIVATE */
  162167. png_reset_crc(png_structp png_ptr)
  162168. {
  162169. png_ptr->crc = crc32(0, Z_NULL, 0);
  162170. }
  162171. void /* PRIVATE */
  162172. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162173. {
  162174. int need_crc = 1;
  162175. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162176. {
  162177. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162178. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162179. need_crc = 0;
  162180. }
  162181. else /* critical */
  162182. {
  162183. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162184. need_crc = 0;
  162185. }
  162186. if (need_crc)
  162187. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162188. }
  162189. png_infop PNGAPI
  162190. png_create_info_struct(png_structp png_ptr)
  162191. {
  162192. png_infop info_ptr;
  162193. png_debug(1, "in png_create_info_struct\n");
  162194. if(png_ptr == NULL) return (NULL);
  162195. #ifdef PNG_USER_MEM_SUPPORTED
  162196. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162197. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162198. #else
  162199. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162200. #endif
  162201. if (info_ptr != NULL)
  162202. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162203. return (info_ptr);
  162204. }
  162205. void PNGAPI
  162206. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162207. {
  162208. png_infop info_ptr = NULL;
  162209. if(png_ptr == NULL) return;
  162210. png_debug(1, "in png_destroy_info_struct\n");
  162211. if (info_ptr_ptr != NULL)
  162212. info_ptr = *info_ptr_ptr;
  162213. if (info_ptr != NULL)
  162214. {
  162215. png_info_destroy(png_ptr, info_ptr);
  162216. #ifdef PNG_USER_MEM_SUPPORTED
  162217. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162218. png_ptr->mem_ptr);
  162219. #else
  162220. png_destroy_struct((png_voidp)info_ptr);
  162221. #endif
  162222. *info_ptr_ptr = NULL;
  162223. }
  162224. }
  162225. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162226. #undef png_info_init
  162227. void PNGAPI
  162228. png_info_init(png_infop info_ptr)
  162229. {
  162230. png_info_init_3(&info_ptr, 0);
  162231. }
  162232. #endif
  162233. void PNGAPI
  162234. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162235. {
  162236. png_infop info_ptr = *ptr_ptr;
  162237. if(info_ptr == NULL) return;
  162238. png_debug(1, "in png_info_init_3\n");
  162239. if(png_sizeof(png_info) > png_info_struct_size)
  162240. {
  162241. png_destroy_struct(info_ptr);
  162242. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162243. *ptr_ptr = info_ptr;
  162244. }
  162245. png_memset(info_ptr, 0, png_sizeof (png_info));
  162246. }
  162247. #ifdef PNG_FREE_ME_SUPPORTED
  162248. void PNGAPI
  162249. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162250. int freer, png_uint_32 mask)
  162251. {
  162252. png_debug(1, "in png_data_freer\n");
  162253. if (png_ptr == NULL || info_ptr == NULL)
  162254. return;
  162255. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162256. info_ptr->free_me |= mask;
  162257. else if(freer == PNG_USER_WILL_FREE_DATA)
  162258. info_ptr->free_me &= ~mask;
  162259. else
  162260. png_warning(png_ptr,
  162261. "Unknown freer parameter in png_data_freer.");
  162262. }
  162263. #endif
  162264. void PNGAPI
  162265. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162266. int num)
  162267. {
  162268. png_debug(1, "in png_free_data\n");
  162269. if (png_ptr == NULL || info_ptr == NULL)
  162270. return;
  162271. #if defined(PNG_TEXT_SUPPORTED)
  162272. #ifdef PNG_FREE_ME_SUPPORTED
  162273. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162274. #else
  162275. if (mask & PNG_FREE_TEXT)
  162276. #endif
  162277. {
  162278. if (num != -1)
  162279. {
  162280. if (info_ptr->text && info_ptr->text[num].key)
  162281. {
  162282. png_free(png_ptr, info_ptr->text[num].key);
  162283. info_ptr->text[num].key = NULL;
  162284. }
  162285. }
  162286. else
  162287. {
  162288. int i;
  162289. for (i = 0; i < info_ptr->num_text; i++)
  162290. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162291. png_free(png_ptr, info_ptr->text);
  162292. info_ptr->text = NULL;
  162293. info_ptr->num_text=0;
  162294. }
  162295. }
  162296. #endif
  162297. #if defined(PNG_tRNS_SUPPORTED)
  162298. #ifdef PNG_FREE_ME_SUPPORTED
  162299. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162300. #else
  162301. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162302. #endif
  162303. {
  162304. png_free(png_ptr, info_ptr->trans);
  162305. info_ptr->valid &= ~PNG_INFO_tRNS;
  162306. #ifndef PNG_FREE_ME_SUPPORTED
  162307. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162308. #endif
  162309. info_ptr->trans = NULL;
  162310. }
  162311. #endif
  162312. #if defined(PNG_sCAL_SUPPORTED)
  162313. #ifdef PNG_FREE_ME_SUPPORTED
  162314. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162315. #else
  162316. if (mask & PNG_FREE_SCAL)
  162317. #endif
  162318. {
  162319. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162320. png_free(png_ptr, info_ptr->scal_s_width);
  162321. png_free(png_ptr, info_ptr->scal_s_height);
  162322. info_ptr->scal_s_width = NULL;
  162323. info_ptr->scal_s_height = NULL;
  162324. #endif
  162325. info_ptr->valid &= ~PNG_INFO_sCAL;
  162326. }
  162327. #endif
  162328. #if defined(PNG_pCAL_SUPPORTED)
  162329. #ifdef PNG_FREE_ME_SUPPORTED
  162330. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162331. #else
  162332. if (mask & PNG_FREE_PCAL)
  162333. #endif
  162334. {
  162335. png_free(png_ptr, info_ptr->pcal_purpose);
  162336. png_free(png_ptr, info_ptr->pcal_units);
  162337. info_ptr->pcal_purpose = NULL;
  162338. info_ptr->pcal_units = NULL;
  162339. if (info_ptr->pcal_params != NULL)
  162340. {
  162341. int i;
  162342. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162343. {
  162344. png_free(png_ptr, info_ptr->pcal_params[i]);
  162345. info_ptr->pcal_params[i]=NULL;
  162346. }
  162347. png_free(png_ptr, info_ptr->pcal_params);
  162348. info_ptr->pcal_params = NULL;
  162349. }
  162350. info_ptr->valid &= ~PNG_INFO_pCAL;
  162351. }
  162352. #endif
  162353. #if defined(PNG_iCCP_SUPPORTED)
  162354. #ifdef PNG_FREE_ME_SUPPORTED
  162355. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162356. #else
  162357. if (mask & PNG_FREE_ICCP)
  162358. #endif
  162359. {
  162360. png_free(png_ptr, info_ptr->iccp_name);
  162361. png_free(png_ptr, info_ptr->iccp_profile);
  162362. info_ptr->iccp_name = NULL;
  162363. info_ptr->iccp_profile = NULL;
  162364. info_ptr->valid &= ~PNG_INFO_iCCP;
  162365. }
  162366. #endif
  162367. #if defined(PNG_sPLT_SUPPORTED)
  162368. #ifdef PNG_FREE_ME_SUPPORTED
  162369. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162370. #else
  162371. if (mask & PNG_FREE_SPLT)
  162372. #endif
  162373. {
  162374. if (num != -1)
  162375. {
  162376. if(info_ptr->splt_palettes)
  162377. {
  162378. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162379. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162380. info_ptr->splt_palettes[num].name = NULL;
  162381. info_ptr->splt_palettes[num].entries = NULL;
  162382. }
  162383. }
  162384. else
  162385. {
  162386. if(info_ptr->splt_palettes_num)
  162387. {
  162388. int i;
  162389. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162390. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162391. png_free(png_ptr, info_ptr->splt_palettes);
  162392. info_ptr->splt_palettes = NULL;
  162393. info_ptr->splt_palettes_num = 0;
  162394. }
  162395. info_ptr->valid &= ~PNG_INFO_sPLT;
  162396. }
  162397. }
  162398. #endif
  162399. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162400. if(png_ptr->unknown_chunk.data)
  162401. {
  162402. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162403. png_ptr->unknown_chunk.data = NULL;
  162404. }
  162405. #ifdef PNG_FREE_ME_SUPPORTED
  162406. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162407. #else
  162408. if (mask & PNG_FREE_UNKN)
  162409. #endif
  162410. {
  162411. if (num != -1)
  162412. {
  162413. if(info_ptr->unknown_chunks)
  162414. {
  162415. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162416. info_ptr->unknown_chunks[num].data = NULL;
  162417. }
  162418. }
  162419. else
  162420. {
  162421. int i;
  162422. if(info_ptr->unknown_chunks_num)
  162423. {
  162424. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162425. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162426. png_free(png_ptr, info_ptr->unknown_chunks);
  162427. info_ptr->unknown_chunks = NULL;
  162428. info_ptr->unknown_chunks_num = 0;
  162429. }
  162430. }
  162431. }
  162432. #endif
  162433. #if defined(PNG_hIST_SUPPORTED)
  162434. #ifdef PNG_FREE_ME_SUPPORTED
  162435. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162436. #else
  162437. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162438. #endif
  162439. {
  162440. png_free(png_ptr, info_ptr->hist);
  162441. info_ptr->hist = NULL;
  162442. info_ptr->valid &= ~PNG_INFO_hIST;
  162443. #ifndef PNG_FREE_ME_SUPPORTED
  162444. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162445. #endif
  162446. }
  162447. #endif
  162448. #ifdef PNG_FREE_ME_SUPPORTED
  162449. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162450. #else
  162451. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162452. #endif
  162453. {
  162454. png_zfree(png_ptr, info_ptr->palette);
  162455. info_ptr->palette = NULL;
  162456. info_ptr->valid &= ~PNG_INFO_PLTE;
  162457. #ifndef PNG_FREE_ME_SUPPORTED
  162458. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162459. #endif
  162460. info_ptr->num_palette = 0;
  162461. }
  162462. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162463. #ifdef PNG_FREE_ME_SUPPORTED
  162464. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162465. #else
  162466. if (mask & PNG_FREE_ROWS)
  162467. #endif
  162468. {
  162469. if(info_ptr->row_pointers)
  162470. {
  162471. int row;
  162472. for (row = 0; row < (int)info_ptr->height; row++)
  162473. {
  162474. png_free(png_ptr, info_ptr->row_pointers[row]);
  162475. info_ptr->row_pointers[row]=NULL;
  162476. }
  162477. png_free(png_ptr, info_ptr->row_pointers);
  162478. info_ptr->row_pointers=NULL;
  162479. }
  162480. info_ptr->valid &= ~PNG_INFO_IDAT;
  162481. }
  162482. #endif
  162483. #ifdef PNG_FREE_ME_SUPPORTED
  162484. if(num == -1)
  162485. info_ptr->free_me &= ~mask;
  162486. else
  162487. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162488. #endif
  162489. }
  162490. void /* PRIVATE */
  162491. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162492. {
  162493. png_debug(1, "in png_info_destroy\n");
  162494. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162495. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162496. if (png_ptr->num_chunk_list)
  162497. {
  162498. png_free(png_ptr, png_ptr->chunk_list);
  162499. png_ptr->chunk_list=NULL;
  162500. png_ptr->num_chunk_list=0;
  162501. }
  162502. #endif
  162503. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162504. }
  162505. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162506. png_voidp PNGAPI
  162507. png_get_io_ptr(png_structp png_ptr)
  162508. {
  162509. if(png_ptr == NULL) return (NULL);
  162510. return (png_ptr->io_ptr);
  162511. }
  162512. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162513. #if !defined(PNG_NO_STDIO)
  162514. void PNGAPI
  162515. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162516. {
  162517. png_debug(1, "in png_init_io\n");
  162518. if(png_ptr == NULL) return;
  162519. png_ptr->io_ptr = (png_voidp)fp;
  162520. }
  162521. #endif
  162522. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162523. png_charp PNGAPI
  162524. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162525. {
  162526. static PNG_CONST char short_months[12][4] =
  162527. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162528. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162529. if(png_ptr == NULL) return (NULL);
  162530. if (png_ptr->time_buffer == NULL)
  162531. {
  162532. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162533. png_sizeof(char)));
  162534. }
  162535. #if defined(_WIN32_WCE)
  162536. {
  162537. wchar_t time_buf[29];
  162538. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162539. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162540. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162541. ptime->second % 61);
  162542. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162543. NULL, NULL);
  162544. }
  162545. #else
  162546. #ifdef USE_FAR_KEYWORD
  162547. {
  162548. char near_time_buf[29];
  162549. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162550. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162551. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162552. ptime->second % 61);
  162553. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162554. 29*png_sizeof(char));
  162555. }
  162556. #else
  162557. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162558. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162559. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162560. ptime->second % 61);
  162561. #endif
  162562. #endif /* _WIN32_WCE */
  162563. return ((png_charp)png_ptr->time_buffer);
  162564. }
  162565. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162566. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162567. png_charp PNGAPI
  162568. png_get_copyright(png_structp png_ptr)
  162569. {
  162570. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162571. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162572. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162573. Copyright (c) 1996-1997 Andreas Dilger\n\
  162574. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162575. }
  162576. png_charp PNGAPI
  162577. png_get_libpng_ver(png_structp png_ptr)
  162578. {
  162579. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162580. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162581. }
  162582. png_charp PNGAPI
  162583. png_get_header_ver(png_structp png_ptr)
  162584. {
  162585. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162586. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162587. }
  162588. png_charp PNGAPI
  162589. png_get_header_version(png_structp png_ptr)
  162590. {
  162591. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162592. return ((png_charp) PNG_HEADER_VERSION_STRING
  162593. #ifndef PNG_READ_SUPPORTED
  162594. " (NO READ SUPPORT)"
  162595. #endif
  162596. "\n");
  162597. }
  162598. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162599. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162600. int PNGAPI
  162601. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162602. {
  162603. int i;
  162604. png_bytep p;
  162605. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162606. return 0;
  162607. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162608. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162609. if (!png_memcmp(chunk_name, p, 4))
  162610. return ((int)*(p+4));
  162611. return 0;
  162612. }
  162613. #endif
  162614. int PNGAPI
  162615. png_reset_zstream(png_structp png_ptr)
  162616. {
  162617. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162618. return (inflateReset(&png_ptr->zstream));
  162619. }
  162620. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162621. png_uint_32 PNGAPI
  162622. png_access_version_number(void)
  162623. {
  162624. return((png_uint_32) PNG_LIBPNG_VER);
  162625. }
  162626. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162627. #if !defined(PNG_1_0_X)
  162628. int PNGAPI
  162629. png_mmx_support(void)
  162630. {
  162631. return -1;
  162632. }
  162633. #endif /* PNG_1_0_X */
  162634. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162635. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162636. #ifdef PNG_SIZE_T
  162637. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162638. png_size_t PNGAPI
  162639. png_convert_size(size_t size)
  162640. {
  162641. if (size > (png_size_t)-1)
  162642. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162643. return ((png_size_t)size);
  162644. }
  162645. #endif /* PNG_SIZE_T */
  162646. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162647. /*** End of inlined file: png.c ***/
  162648. /*** Start of inlined file: pngerror.c ***/
  162649. #define PNG_INTERNAL
  162650. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162651. static void /* PRIVATE */
  162652. png_default_error PNGARG((png_structp png_ptr,
  162653. png_const_charp error_message));
  162654. #ifndef PNG_NO_WARNINGS
  162655. static void /* PRIVATE */
  162656. png_default_warning PNGARG((png_structp png_ptr,
  162657. png_const_charp warning_message));
  162658. #endif /* PNG_NO_WARNINGS */
  162659. #ifndef PNG_NO_ERROR_TEXT
  162660. void PNGAPI
  162661. png_error(png_structp png_ptr, png_const_charp error_message)
  162662. {
  162663. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162664. char msg[16];
  162665. if (png_ptr != NULL)
  162666. {
  162667. if (png_ptr->flags&
  162668. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162669. {
  162670. if (*error_message == '#')
  162671. {
  162672. int offset;
  162673. for (offset=1; offset<15; offset++)
  162674. if (*(error_message+offset) == ' ')
  162675. break;
  162676. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162677. {
  162678. int i;
  162679. for (i=0; i<offset-1; i++)
  162680. msg[i]=error_message[i+1];
  162681. msg[i]='\0';
  162682. error_message=msg;
  162683. }
  162684. else
  162685. error_message+=offset;
  162686. }
  162687. else
  162688. {
  162689. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162690. {
  162691. msg[0]='0';
  162692. msg[1]='\0';
  162693. error_message=msg;
  162694. }
  162695. }
  162696. }
  162697. }
  162698. #endif
  162699. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162700. (*(png_ptr->error_fn))(png_ptr, error_message);
  162701. png_default_error(png_ptr, error_message);
  162702. }
  162703. #else
  162704. void PNGAPI
  162705. png_err(png_structp png_ptr)
  162706. {
  162707. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162708. (*(png_ptr->error_fn))(png_ptr, '\0');
  162709. png_default_error(png_ptr, '\0');
  162710. }
  162711. #endif /* PNG_NO_ERROR_TEXT */
  162712. #ifndef PNG_NO_WARNINGS
  162713. void PNGAPI
  162714. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162715. {
  162716. int offset = 0;
  162717. if (png_ptr != NULL)
  162718. {
  162719. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162720. if (png_ptr->flags&
  162721. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162722. #endif
  162723. {
  162724. if (*warning_message == '#')
  162725. {
  162726. for (offset=1; offset<15; offset++)
  162727. if (*(warning_message+offset) == ' ')
  162728. break;
  162729. }
  162730. }
  162731. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162732. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162733. }
  162734. else
  162735. png_default_warning(png_ptr, warning_message+offset);
  162736. }
  162737. #endif /* PNG_NO_WARNINGS */
  162738. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162739. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162740. static void /* PRIVATE */
  162741. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162742. error_message)
  162743. {
  162744. int iout = 0, iin = 0;
  162745. while (iin < 4)
  162746. {
  162747. int c = png_ptr->chunk_name[iin++];
  162748. if (isnonalpha(c))
  162749. {
  162750. buffer[iout++] = '[';
  162751. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162752. buffer[iout++] = png_digit[c & 0x0f];
  162753. buffer[iout++] = ']';
  162754. }
  162755. else
  162756. {
  162757. buffer[iout++] = (png_byte)c;
  162758. }
  162759. }
  162760. if (error_message == NULL)
  162761. buffer[iout] = 0;
  162762. else
  162763. {
  162764. buffer[iout++] = ':';
  162765. buffer[iout++] = ' ';
  162766. png_strncpy(buffer+iout, error_message, 63);
  162767. buffer[iout+63] = 0;
  162768. }
  162769. }
  162770. #ifdef PNG_READ_SUPPORTED
  162771. void PNGAPI
  162772. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162773. {
  162774. char msg[18+64];
  162775. if (png_ptr == NULL)
  162776. png_error(png_ptr, error_message);
  162777. else
  162778. {
  162779. png_format_buffer(png_ptr, msg, error_message);
  162780. png_error(png_ptr, msg);
  162781. }
  162782. }
  162783. #endif /* PNG_READ_SUPPORTED */
  162784. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162785. #ifndef PNG_NO_WARNINGS
  162786. void PNGAPI
  162787. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162788. {
  162789. char msg[18+64];
  162790. if (png_ptr == NULL)
  162791. png_warning(png_ptr, warning_message);
  162792. else
  162793. {
  162794. png_format_buffer(png_ptr, msg, warning_message);
  162795. png_warning(png_ptr, msg);
  162796. }
  162797. }
  162798. #endif /* PNG_NO_WARNINGS */
  162799. static void /* PRIVATE */
  162800. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162801. {
  162802. #ifndef PNG_NO_CONSOLE_IO
  162803. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162804. if (*error_message == '#')
  162805. {
  162806. int offset;
  162807. char error_number[16];
  162808. for (offset=0; offset<15; offset++)
  162809. {
  162810. error_number[offset] = *(error_message+offset+1);
  162811. if (*(error_message+offset) == ' ')
  162812. break;
  162813. }
  162814. if((offset > 1) && (offset < 15))
  162815. {
  162816. error_number[offset-1]='\0';
  162817. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162818. error_message+offset);
  162819. }
  162820. else
  162821. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162822. }
  162823. else
  162824. #endif
  162825. fprintf(stderr, "libpng error: %s\n", error_message);
  162826. #endif
  162827. #ifdef PNG_SETJMP_SUPPORTED
  162828. if (png_ptr)
  162829. {
  162830. # ifdef USE_FAR_KEYWORD
  162831. {
  162832. jmp_buf jmpbuf;
  162833. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162834. longjmp(jmpbuf, 1);
  162835. }
  162836. # else
  162837. longjmp(png_ptr->jmpbuf, 1);
  162838. # endif
  162839. }
  162840. #else
  162841. PNG_ABORT();
  162842. #endif
  162843. #ifdef PNG_NO_CONSOLE_IO
  162844. error_message = error_message; /* make compiler happy */
  162845. #endif
  162846. }
  162847. #ifndef PNG_NO_WARNINGS
  162848. static void /* PRIVATE */
  162849. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162850. {
  162851. #ifndef PNG_NO_CONSOLE_IO
  162852. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162853. if (*warning_message == '#')
  162854. {
  162855. int offset;
  162856. char warning_number[16];
  162857. for (offset=0; offset<15; offset++)
  162858. {
  162859. warning_number[offset]=*(warning_message+offset+1);
  162860. if (*(warning_message+offset) == ' ')
  162861. break;
  162862. }
  162863. if((offset > 1) && (offset < 15))
  162864. {
  162865. warning_number[offset-1]='\0';
  162866. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162867. warning_message+offset);
  162868. }
  162869. else
  162870. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162871. }
  162872. else
  162873. # endif
  162874. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162875. #else
  162876. warning_message = warning_message; /* make compiler happy */
  162877. #endif
  162878. png_ptr = png_ptr; /* make compiler happy */
  162879. }
  162880. #endif /* PNG_NO_WARNINGS */
  162881. void PNGAPI
  162882. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162883. png_error_ptr error_fn, png_error_ptr warning_fn)
  162884. {
  162885. if (png_ptr == NULL)
  162886. return;
  162887. png_ptr->error_ptr = error_ptr;
  162888. png_ptr->error_fn = error_fn;
  162889. png_ptr->warning_fn = warning_fn;
  162890. }
  162891. png_voidp PNGAPI
  162892. png_get_error_ptr(png_structp png_ptr)
  162893. {
  162894. if (png_ptr == NULL)
  162895. return NULL;
  162896. return ((png_voidp)png_ptr->error_ptr);
  162897. }
  162898. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162899. void PNGAPI
  162900. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162901. {
  162902. if(png_ptr != NULL)
  162903. {
  162904. png_ptr->flags &=
  162905. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162906. }
  162907. }
  162908. #endif
  162909. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162910. /*** End of inlined file: pngerror.c ***/
  162911. /*** Start of inlined file: pngget.c ***/
  162912. #define PNG_INTERNAL
  162913. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162914. png_uint_32 PNGAPI
  162915. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162916. {
  162917. if (png_ptr != NULL && info_ptr != NULL)
  162918. return(info_ptr->valid & flag);
  162919. else
  162920. return(0);
  162921. }
  162922. png_uint_32 PNGAPI
  162923. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  162924. {
  162925. if (png_ptr != NULL && info_ptr != NULL)
  162926. return(info_ptr->rowbytes);
  162927. else
  162928. return(0);
  162929. }
  162930. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162931. png_bytepp PNGAPI
  162932. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  162933. {
  162934. if (png_ptr != NULL && info_ptr != NULL)
  162935. return(info_ptr->row_pointers);
  162936. else
  162937. return(0);
  162938. }
  162939. #endif
  162940. #ifdef PNG_EASY_ACCESS_SUPPORTED
  162941. png_uint_32 PNGAPI
  162942. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  162943. {
  162944. if (png_ptr != NULL && info_ptr != NULL)
  162945. {
  162946. return info_ptr->width;
  162947. }
  162948. return (0);
  162949. }
  162950. png_uint_32 PNGAPI
  162951. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  162952. {
  162953. if (png_ptr != NULL && info_ptr != NULL)
  162954. {
  162955. return info_ptr->height;
  162956. }
  162957. return (0);
  162958. }
  162959. png_byte PNGAPI
  162960. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  162961. {
  162962. if (png_ptr != NULL && info_ptr != NULL)
  162963. {
  162964. return info_ptr->bit_depth;
  162965. }
  162966. return (0);
  162967. }
  162968. png_byte PNGAPI
  162969. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  162970. {
  162971. if (png_ptr != NULL && info_ptr != NULL)
  162972. {
  162973. return info_ptr->color_type;
  162974. }
  162975. return (0);
  162976. }
  162977. png_byte PNGAPI
  162978. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  162979. {
  162980. if (png_ptr != NULL && info_ptr != NULL)
  162981. {
  162982. return info_ptr->filter_type;
  162983. }
  162984. return (0);
  162985. }
  162986. png_byte PNGAPI
  162987. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  162988. {
  162989. if (png_ptr != NULL && info_ptr != NULL)
  162990. {
  162991. return info_ptr->interlace_type;
  162992. }
  162993. return (0);
  162994. }
  162995. png_byte PNGAPI
  162996. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  162997. {
  162998. if (png_ptr != NULL && info_ptr != NULL)
  162999. {
  163000. return info_ptr->compression_type;
  163001. }
  163002. return (0);
  163003. }
  163004. png_uint_32 PNGAPI
  163005. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163006. {
  163007. if (png_ptr != NULL && info_ptr != NULL)
  163008. #if defined(PNG_pHYs_SUPPORTED)
  163009. if (info_ptr->valid & PNG_INFO_pHYs)
  163010. {
  163011. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163012. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163013. return (0);
  163014. else return (info_ptr->x_pixels_per_unit);
  163015. }
  163016. #else
  163017. return (0);
  163018. #endif
  163019. return (0);
  163020. }
  163021. png_uint_32 PNGAPI
  163022. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163023. {
  163024. if (png_ptr != NULL && info_ptr != NULL)
  163025. #if defined(PNG_pHYs_SUPPORTED)
  163026. if (info_ptr->valid & PNG_INFO_pHYs)
  163027. {
  163028. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163029. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163030. return (0);
  163031. else return (info_ptr->y_pixels_per_unit);
  163032. }
  163033. #else
  163034. return (0);
  163035. #endif
  163036. return (0);
  163037. }
  163038. png_uint_32 PNGAPI
  163039. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163040. {
  163041. if (png_ptr != NULL && info_ptr != NULL)
  163042. #if defined(PNG_pHYs_SUPPORTED)
  163043. if (info_ptr->valid & PNG_INFO_pHYs)
  163044. {
  163045. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163046. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163047. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163048. return (0);
  163049. else return (info_ptr->x_pixels_per_unit);
  163050. }
  163051. #else
  163052. return (0);
  163053. #endif
  163054. return (0);
  163055. }
  163056. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163057. float PNGAPI
  163058. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163059. {
  163060. if (png_ptr != NULL && info_ptr != NULL)
  163061. #if defined(PNG_pHYs_SUPPORTED)
  163062. if (info_ptr->valid & PNG_INFO_pHYs)
  163063. {
  163064. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163065. if (info_ptr->x_pixels_per_unit == 0)
  163066. return ((float)0.0);
  163067. else
  163068. return ((float)((float)info_ptr->y_pixels_per_unit
  163069. /(float)info_ptr->x_pixels_per_unit));
  163070. }
  163071. #else
  163072. return (0.0);
  163073. #endif
  163074. return ((float)0.0);
  163075. }
  163076. #endif
  163077. png_int_32 PNGAPI
  163078. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163079. {
  163080. if (png_ptr != NULL && info_ptr != NULL)
  163081. #if defined(PNG_oFFs_SUPPORTED)
  163082. if (info_ptr->valid & PNG_INFO_oFFs)
  163083. {
  163084. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163085. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163086. return (0);
  163087. else return (info_ptr->x_offset);
  163088. }
  163089. #else
  163090. return (0);
  163091. #endif
  163092. return (0);
  163093. }
  163094. png_int_32 PNGAPI
  163095. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163096. {
  163097. if (png_ptr != NULL && info_ptr != NULL)
  163098. #if defined(PNG_oFFs_SUPPORTED)
  163099. if (info_ptr->valid & PNG_INFO_oFFs)
  163100. {
  163101. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163102. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163103. return (0);
  163104. else return (info_ptr->y_offset);
  163105. }
  163106. #else
  163107. return (0);
  163108. #endif
  163109. return (0);
  163110. }
  163111. png_int_32 PNGAPI
  163112. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163113. {
  163114. if (png_ptr != NULL && info_ptr != NULL)
  163115. #if defined(PNG_oFFs_SUPPORTED)
  163116. if (info_ptr->valid & PNG_INFO_oFFs)
  163117. {
  163118. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163119. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163120. return (0);
  163121. else return (info_ptr->x_offset);
  163122. }
  163123. #else
  163124. return (0);
  163125. #endif
  163126. return (0);
  163127. }
  163128. png_int_32 PNGAPI
  163129. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163130. {
  163131. if (png_ptr != NULL && info_ptr != NULL)
  163132. #if defined(PNG_oFFs_SUPPORTED)
  163133. if (info_ptr->valid & PNG_INFO_oFFs)
  163134. {
  163135. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163136. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163137. return (0);
  163138. else return (info_ptr->y_offset);
  163139. }
  163140. #else
  163141. return (0);
  163142. #endif
  163143. return (0);
  163144. }
  163145. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163146. png_uint_32 PNGAPI
  163147. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163148. {
  163149. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163150. *.0254 +.5));
  163151. }
  163152. png_uint_32 PNGAPI
  163153. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163154. {
  163155. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163156. *.0254 +.5));
  163157. }
  163158. png_uint_32 PNGAPI
  163159. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163160. {
  163161. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163162. *.0254 +.5));
  163163. }
  163164. float PNGAPI
  163165. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163166. {
  163167. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163168. *.00003937);
  163169. }
  163170. float PNGAPI
  163171. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163172. {
  163173. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163174. *.00003937);
  163175. }
  163176. #if defined(PNG_pHYs_SUPPORTED)
  163177. png_uint_32 PNGAPI
  163178. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163179. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163180. {
  163181. png_uint_32 retval = 0;
  163182. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163183. {
  163184. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163185. if (res_x != NULL)
  163186. {
  163187. *res_x = info_ptr->x_pixels_per_unit;
  163188. retval |= PNG_INFO_pHYs;
  163189. }
  163190. if (res_y != NULL)
  163191. {
  163192. *res_y = info_ptr->y_pixels_per_unit;
  163193. retval |= PNG_INFO_pHYs;
  163194. }
  163195. if (unit_type != NULL)
  163196. {
  163197. *unit_type = (int)info_ptr->phys_unit_type;
  163198. retval |= PNG_INFO_pHYs;
  163199. if(*unit_type == 1)
  163200. {
  163201. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163202. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163203. }
  163204. }
  163205. }
  163206. return (retval);
  163207. }
  163208. #endif /* PNG_pHYs_SUPPORTED */
  163209. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163210. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163211. png_byte PNGAPI
  163212. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163213. {
  163214. if (png_ptr != NULL && info_ptr != NULL)
  163215. return(info_ptr->channels);
  163216. else
  163217. return (0);
  163218. }
  163219. png_bytep PNGAPI
  163220. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163221. {
  163222. if (png_ptr != NULL && info_ptr != NULL)
  163223. return(info_ptr->signature);
  163224. else
  163225. return (NULL);
  163226. }
  163227. #if defined(PNG_bKGD_SUPPORTED)
  163228. png_uint_32 PNGAPI
  163229. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163230. png_color_16p *background)
  163231. {
  163232. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163233. && background != NULL)
  163234. {
  163235. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163236. *background = &(info_ptr->background);
  163237. return (PNG_INFO_bKGD);
  163238. }
  163239. return (0);
  163240. }
  163241. #endif
  163242. #if defined(PNG_cHRM_SUPPORTED)
  163243. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163244. png_uint_32 PNGAPI
  163245. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163246. double *white_x, double *white_y, double *red_x, double *red_y,
  163247. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163248. {
  163249. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163250. {
  163251. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163252. if (white_x != NULL)
  163253. *white_x = (double)info_ptr->x_white;
  163254. if (white_y != NULL)
  163255. *white_y = (double)info_ptr->y_white;
  163256. if (red_x != NULL)
  163257. *red_x = (double)info_ptr->x_red;
  163258. if (red_y != NULL)
  163259. *red_y = (double)info_ptr->y_red;
  163260. if (green_x != NULL)
  163261. *green_x = (double)info_ptr->x_green;
  163262. if (green_y != NULL)
  163263. *green_y = (double)info_ptr->y_green;
  163264. if (blue_x != NULL)
  163265. *blue_x = (double)info_ptr->x_blue;
  163266. if (blue_y != NULL)
  163267. *blue_y = (double)info_ptr->y_blue;
  163268. return (PNG_INFO_cHRM);
  163269. }
  163270. return (0);
  163271. }
  163272. #endif
  163273. #ifdef PNG_FIXED_POINT_SUPPORTED
  163274. png_uint_32 PNGAPI
  163275. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163276. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163277. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163278. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163279. {
  163280. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163281. {
  163282. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163283. if (white_x != NULL)
  163284. *white_x = info_ptr->int_x_white;
  163285. if (white_y != NULL)
  163286. *white_y = info_ptr->int_y_white;
  163287. if (red_x != NULL)
  163288. *red_x = info_ptr->int_x_red;
  163289. if (red_y != NULL)
  163290. *red_y = info_ptr->int_y_red;
  163291. if (green_x != NULL)
  163292. *green_x = info_ptr->int_x_green;
  163293. if (green_y != NULL)
  163294. *green_y = info_ptr->int_y_green;
  163295. if (blue_x != NULL)
  163296. *blue_x = info_ptr->int_x_blue;
  163297. if (blue_y != NULL)
  163298. *blue_y = info_ptr->int_y_blue;
  163299. return (PNG_INFO_cHRM);
  163300. }
  163301. return (0);
  163302. }
  163303. #endif
  163304. #endif
  163305. #if defined(PNG_gAMA_SUPPORTED)
  163306. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163307. png_uint_32 PNGAPI
  163308. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163309. {
  163310. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163311. && file_gamma != NULL)
  163312. {
  163313. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163314. *file_gamma = (double)info_ptr->gamma;
  163315. return (PNG_INFO_gAMA);
  163316. }
  163317. return (0);
  163318. }
  163319. #endif
  163320. #ifdef PNG_FIXED_POINT_SUPPORTED
  163321. png_uint_32 PNGAPI
  163322. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163323. png_fixed_point *int_file_gamma)
  163324. {
  163325. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163326. && int_file_gamma != NULL)
  163327. {
  163328. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163329. *int_file_gamma = info_ptr->int_gamma;
  163330. return (PNG_INFO_gAMA);
  163331. }
  163332. return (0);
  163333. }
  163334. #endif
  163335. #endif
  163336. #if defined(PNG_sRGB_SUPPORTED)
  163337. png_uint_32 PNGAPI
  163338. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163339. {
  163340. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163341. && file_srgb_intent != NULL)
  163342. {
  163343. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163344. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163345. return (PNG_INFO_sRGB);
  163346. }
  163347. return (0);
  163348. }
  163349. #endif
  163350. #if defined(PNG_iCCP_SUPPORTED)
  163351. png_uint_32 PNGAPI
  163352. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163353. png_charpp name, int *compression_type,
  163354. png_charpp profile, png_uint_32 *proflen)
  163355. {
  163356. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163357. && name != NULL && profile != NULL && proflen != NULL)
  163358. {
  163359. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163360. *name = info_ptr->iccp_name;
  163361. *profile = info_ptr->iccp_profile;
  163362. *proflen = (int)info_ptr->iccp_proflen;
  163363. *compression_type = (int)info_ptr->iccp_compression;
  163364. return (PNG_INFO_iCCP);
  163365. }
  163366. return (0);
  163367. }
  163368. #endif
  163369. #if defined(PNG_sPLT_SUPPORTED)
  163370. png_uint_32 PNGAPI
  163371. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163372. png_sPLT_tpp spalettes)
  163373. {
  163374. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163375. {
  163376. *spalettes = info_ptr->splt_palettes;
  163377. return ((png_uint_32)info_ptr->splt_palettes_num);
  163378. }
  163379. return (0);
  163380. }
  163381. #endif
  163382. #if defined(PNG_hIST_SUPPORTED)
  163383. png_uint_32 PNGAPI
  163384. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163385. {
  163386. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163387. && hist != NULL)
  163388. {
  163389. png_debug1(1, "in %s retrieval function\n", "hIST");
  163390. *hist = info_ptr->hist;
  163391. return (PNG_INFO_hIST);
  163392. }
  163393. return (0);
  163394. }
  163395. #endif
  163396. png_uint_32 PNGAPI
  163397. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163398. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163399. int *color_type, int *interlace_type, int *compression_type,
  163400. int *filter_type)
  163401. {
  163402. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163403. bit_depth != NULL && color_type != NULL)
  163404. {
  163405. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163406. *width = info_ptr->width;
  163407. *height = info_ptr->height;
  163408. *bit_depth = info_ptr->bit_depth;
  163409. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163410. png_error(png_ptr, "Invalid bit depth");
  163411. *color_type = info_ptr->color_type;
  163412. if (info_ptr->color_type > 6)
  163413. png_error(png_ptr, "Invalid color type");
  163414. if (compression_type != NULL)
  163415. *compression_type = info_ptr->compression_type;
  163416. if (filter_type != NULL)
  163417. *filter_type = info_ptr->filter_type;
  163418. if (interlace_type != NULL)
  163419. *interlace_type = info_ptr->interlace_type;
  163420. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163421. png_error(png_ptr, "Invalid image width");
  163422. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163423. png_error(png_ptr, "Invalid image height");
  163424. if (info_ptr->width > (PNG_UINT_32_MAX
  163425. >> 3) /* 8-byte RGBA pixels */
  163426. - 64 /* bigrowbuf hack */
  163427. - 1 /* filter byte */
  163428. - 7*8 /* rounding of width to multiple of 8 pixels */
  163429. - 8) /* extra max_pixel_depth pad */
  163430. {
  163431. png_warning(png_ptr,
  163432. "Width too large for libpng to process image data.");
  163433. }
  163434. return (1);
  163435. }
  163436. return (0);
  163437. }
  163438. #if defined(PNG_oFFs_SUPPORTED)
  163439. png_uint_32 PNGAPI
  163440. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163441. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163442. {
  163443. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163444. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163445. {
  163446. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163447. *offset_x = info_ptr->x_offset;
  163448. *offset_y = info_ptr->y_offset;
  163449. *unit_type = (int)info_ptr->offset_unit_type;
  163450. return (PNG_INFO_oFFs);
  163451. }
  163452. return (0);
  163453. }
  163454. #endif
  163455. #if defined(PNG_pCAL_SUPPORTED)
  163456. png_uint_32 PNGAPI
  163457. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163458. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163459. png_charp *units, png_charpp *params)
  163460. {
  163461. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163462. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163463. nparams != NULL && units != NULL && params != NULL)
  163464. {
  163465. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163466. *purpose = info_ptr->pcal_purpose;
  163467. *X0 = info_ptr->pcal_X0;
  163468. *X1 = info_ptr->pcal_X1;
  163469. *type = (int)info_ptr->pcal_type;
  163470. *nparams = (int)info_ptr->pcal_nparams;
  163471. *units = info_ptr->pcal_units;
  163472. *params = info_ptr->pcal_params;
  163473. return (PNG_INFO_pCAL);
  163474. }
  163475. return (0);
  163476. }
  163477. #endif
  163478. #if defined(PNG_sCAL_SUPPORTED)
  163479. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163480. png_uint_32 PNGAPI
  163481. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163482. int *unit, double *width, double *height)
  163483. {
  163484. if (png_ptr != NULL && info_ptr != NULL &&
  163485. (info_ptr->valid & PNG_INFO_sCAL))
  163486. {
  163487. *unit = info_ptr->scal_unit;
  163488. *width = info_ptr->scal_pixel_width;
  163489. *height = info_ptr->scal_pixel_height;
  163490. return (PNG_INFO_sCAL);
  163491. }
  163492. return(0);
  163493. }
  163494. #else
  163495. #ifdef PNG_FIXED_POINT_SUPPORTED
  163496. png_uint_32 PNGAPI
  163497. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163498. int *unit, png_charpp width, png_charpp height)
  163499. {
  163500. if (png_ptr != NULL && info_ptr != NULL &&
  163501. (info_ptr->valid & PNG_INFO_sCAL))
  163502. {
  163503. *unit = info_ptr->scal_unit;
  163504. *width = info_ptr->scal_s_width;
  163505. *height = info_ptr->scal_s_height;
  163506. return (PNG_INFO_sCAL);
  163507. }
  163508. return(0);
  163509. }
  163510. #endif
  163511. #endif
  163512. #endif
  163513. #if defined(PNG_pHYs_SUPPORTED)
  163514. png_uint_32 PNGAPI
  163515. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163516. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163517. {
  163518. png_uint_32 retval = 0;
  163519. if (png_ptr != NULL && info_ptr != NULL &&
  163520. (info_ptr->valid & PNG_INFO_pHYs))
  163521. {
  163522. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163523. if (res_x != NULL)
  163524. {
  163525. *res_x = info_ptr->x_pixels_per_unit;
  163526. retval |= PNG_INFO_pHYs;
  163527. }
  163528. if (res_y != NULL)
  163529. {
  163530. *res_y = info_ptr->y_pixels_per_unit;
  163531. retval |= PNG_INFO_pHYs;
  163532. }
  163533. if (unit_type != NULL)
  163534. {
  163535. *unit_type = (int)info_ptr->phys_unit_type;
  163536. retval |= PNG_INFO_pHYs;
  163537. }
  163538. }
  163539. return (retval);
  163540. }
  163541. #endif
  163542. png_uint_32 PNGAPI
  163543. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163544. int *num_palette)
  163545. {
  163546. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163547. && palette != NULL)
  163548. {
  163549. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163550. *palette = info_ptr->palette;
  163551. *num_palette = info_ptr->num_palette;
  163552. png_debug1(3, "num_palette = %d\n", *num_palette);
  163553. return (PNG_INFO_PLTE);
  163554. }
  163555. return (0);
  163556. }
  163557. #if defined(PNG_sBIT_SUPPORTED)
  163558. png_uint_32 PNGAPI
  163559. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163560. {
  163561. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163562. && sig_bit != NULL)
  163563. {
  163564. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163565. *sig_bit = &(info_ptr->sig_bit);
  163566. return (PNG_INFO_sBIT);
  163567. }
  163568. return (0);
  163569. }
  163570. #endif
  163571. #if defined(PNG_TEXT_SUPPORTED)
  163572. png_uint_32 PNGAPI
  163573. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163574. int *num_text)
  163575. {
  163576. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163577. {
  163578. png_debug1(1, "in %s retrieval function\n",
  163579. (png_ptr->chunk_name[0] == '\0' ? "text"
  163580. : (png_const_charp)png_ptr->chunk_name));
  163581. if (text_ptr != NULL)
  163582. *text_ptr = info_ptr->text;
  163583. if (num_text != NULL)
  163584. *num_text = info_ptr->num_text;
  163585. return ((png_uint_32)info_ptr->num_text);
  163586. }
  163587. if (num_text != NULL)
  163588. *num_text = 0;
  163589. return(0);
  163590. }
  163591. #endif
  163592. #if defined(PNG_tIME_SUPPORTED)
  163593. png_uint_32 PNGAPI
  163594. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163595. {
  163596. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163597. && mod_time != NULL)
  163598. {
  163599. png_debug1(1, "in %s retrieval function\n", "tIME");
  163600. *mod_time = &(info_ptr->mod_time);
  163601. return (PNG_INFO_tIME);
  163602. }
  163603. return (0);
  163604. }
  163605. #endif
  163606. #if defined(PNG_tRNS_SUPPORTED)
  163607. png_uint_32 PNGAPI
  163608. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163609. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163610. {
  163611. png_uint_32 retval = 0;
  163612. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163613. {
  163614. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163615. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163616. {
  163617. if (trans != NULL)
  163618. {
  163619. *trans = info_ptr->trans;
  163620. retval |= PNG_INFO_tRNS;
  163621. }
  163622. if (trans_values != NULL)
  163623. *trans_values = &(info_ptr->trans_values);
  163624. }
  163625. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163626. {
  163627. if (trans_values != NULL)
  163628. {
  163629. *trans_values = &(info_ptr->trans_values);
  163630. retval |= PNG_INFO_tRNS;
  163631. }
  163632. if(trans != NULL)
  163633. *trans = NULL;
  163634. }
  163635. if(num_trans != NULL)
  163636. {
  163637. *num_trans = info_ptr->num_trans;
  163638. retval |= PNG_INFO_tRNS;
  163639. }
  163640. }
  163641. return (retval);
  163642. }
  163643. #endif
  163644. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163645. png_uint_32 PNGAPI
  163646. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163647. png_unknown_chunkpp unknowns)
  163648. {
  163649. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163650. {
  163651. *unknowns = info_ptr->unknown_chunks;
  163652. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163653. }
  163654. return (0);
  163655. }
  163656. #endif
  163657. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163658. png_byte PNGAPI
  163659. png_get_rgb_to_gray_status (png_structp png_ptr)
  163660. {
  163661. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163662. }
  163663. #endif
  163664. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163665. png_voidp PNGAPI
  163666. png_get_user_chunk_ptr(png_structp png_ptr)
  163667. {
  163668. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163669. }
  163670. #endif
  163671. #ifdef PNG_WRITE_SUPPORTED
  163672. png_uint_32 PNGAPI
  163673. png_get_compression_buffer_size(png_structp png_ptr)
  163674. {
  163675. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163676. }
  163677. #endif
  163678. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163679. #ifndef PNG_1_0_X
  163680. png_uint_32 PNGAPI
  163681. png_get_asm_flags (png_structp png_ptr)
  163682. {
  163683. return (png_ptr? 0L: 0L);
  163684. }
  163685. png_uint_32 PNGAPI
  163686. png_get_asm_flagmask (int flag_select)
  163687. {
  163688. flag_select=flag_select;
  163689. return 0L;
  163690. }
  163691. png_uint_32 PNGAPI
  163692. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163693. {
  163694. flag_select=flag_select;
  163695. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163696. return 0L;
  163697. }
  163698. png_byte PNGAPI
  163699. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163700. {
  163701. return (png_ptr? 0: 0);
  163702. }
  163703. png_uint_32 PNGAPI
  163704. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163705. {
  163706. return (png_ptr? 0L: 0L);
  163707. }
  163708. #endif /* ?PNG_1_0_X */
  163709. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163710. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163711. png_uint_32 PNGAPI
  163712. png_get_user_width_max (png_structp png_ptr)
  163713. {
  163714. return (png_ptr? png_ptr->user_width_max : 0);
  163715. }
  163716. png_uint_32 PNGAPI
  163717. png_get_user_height_max (png_structp png_ptr)
  163718. {
  163719. return (png_ptr? png_ptr->user_height_max : 0);
  163720. }
  163721. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163722. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163723. /*** End of inlined file: pngget.c ***/
  163724. /*** Start of inlined file: pngmem.c ***/
  163725. #define PNG_INTERNAL
  163726. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163727. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163728. png_voidp /* PRIVATE */
  163729. png_create_struct(int type)
  163730. {
  163731. #ifdef PNG_USER_MEM_SUPPORTED
  163732. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163733. }
  163734. png_voidp /* PRIVATE */
  163735. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163736. {
  163737. #endif /* PNG_USER_MEM_SUPPORTED */
  163738. png_size_t size;
  163739. png_voidp struct_ptr;
  163740. if (type == PNG_STRUCT_INFO)
  163741. size = png_sizeof(png_info);
  163742. else if (type == PNG_STRUCT_PNG)
  163743. size = png_sizeof(png_struct);
  163744. else
  163745. return (png_get_copyright(NULL));
  163746. #ifdef PNG_USER_MEM_SUPPORTED
  163747. if(malloc_fn != NULL)
  163748. {
  163749. png_struct dummy_struct;
  163750. png_structp png_ptr = &dummy_struct;
  163751. png_ptr->mem_ptr=mem_ptr;
  163752. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163753. }
  163754. else
  163755. #endif /* PNG_USER_MEM_SUPPORTED */
  163756. struct_ptr = (png_voidp)farmalloc(size);
  163757. if (struct_ptr != NULL)
  163758. png_memset(struct_ptr, 0, size);
  163759. return (struct_ptr);
  163760. }
  163761. void /* PRIVATE */
  163762. png_destroy_struct(png_voidp struct_ptr)
  163763. {
  163764. #ifdef PNG_USER_MEM_SUPPORTED
  163765. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163766. }
  163767. void /* PRIVATE */
  163768. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163769. png_voidp mem_ptr)
  163770. {
  163771. #endif
  163772. if (struct_ptr != NULL)
  163773. {
  163774. #ifdef PNG_USER_MEM_SUPPORTED
  163775. if(free_fn != NULL)
  163776. {
  163777. png_struct dummy_struct;
  163778. png_structp png_ptr = &dummy_struct;
  163779. png_ptr->mem_ptr=mem_ptr;
  163780. (*(free_fn))(png_ptr, struct_ptr);
  163781. return;
  163782. }
  163783. #endif /* PNG_USER_MEM_SUPPORTED */
  163784. farfree (struct_ptr);
  163785. }
  163786. }
  163787. png_voidp PNGAPI
  163788. png_malloc(png_structp png_ptr, png_uint_32 size)
  163789. {
  163790. png_voidp ret;
  163791. if (png_ptr == NULL || size == 0)
  163792. return (NULL);
  163793. #ifdef PNG_USER_MEM_SUPPORTED
  163794. if(png_ptr->malloc_fn != NULL)
  163795. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163796. else
  163797. ret = (png_malloc_default(png_ptr, size));
  163798. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163799. png_error(png_ptr, "Out of memory!");
  163800. return (ret);
  163801. }
  163802. png_voidp PNGAPI
  163803. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163804. {
  163805. png_voidp ret;
  163806. #endif /* PNG_USER_MEM_SUPPORTED */
  163807. if (png_ptr == NULL || size == 0)
  163808. return (NULL);
  163809. #ifdef PNG_MAX_MALLOC_64K
  163810. if (size > (png_uint_32)65536L)
  163811. {
  163812. png_warning(png_ptr, "Cannot Allocate > 64K");
  163813. ret = NULL;
  163814. }
  163815. else
  163816. #endif
  163817. if (size != (size_t)size)
  163818. ret = NULL;
  163819. else if (size == (png_uint_32)65536L)
  163820. {
  163821. if (png_ptr->offset_table == NULL)
  163822. {
  163823. ret = farmalloc(size);
  163824. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163825. {
  163826. int num_blocks;
  163827. png_uint_32 total_size;
  163828. png_bytep table;
  163829. int i;
  163830. png_byte huge * hptr;
  163831. if (ret != NULL)
  163832. {
  163833. farfree(ret);
  163834. ret = NULL;
  163835. }
  163836. if(png_ptr->zlib_window_bits > 14)
  163837. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163838. else
  163839. num_blocks = 1;
  163840. if (png_ptr->zlib_mem_level >= 7)
  163841. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163842. else
  163843. num_blocks++;
  163844. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163845. table = farmalloc(total_size);
  163846. if (table == NULL)
  163847. {
  163848. #ifndef PNG_USER_MEM_SUPPORTED
  163849. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163850. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163851. else
  163852. png_warning(png_ptr, "Out Of Memory.");
  163853. #endif
  163854. return (NULL);
  163855. }
  163856. if ((png_size_t)table & 0xfff0)
  163857. {
  163858. #ifndef PNG_USER_MEM_SUPPORTED
  163859. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163860. png_error(png_ptr,
  163861. "Farmalloc didn't return normalized pointer");
  163862. else
  163863. png_warning(png_ptr,
  163864. "Farmalloc didn't return normalized pointer");
  163865. #endif
  163866. return (NULL);
  163867. }
  163868. png_ptr->offset_table = table;
  163869. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163870. png_sizeof (png_bytep));
  163871. if (png_ptr->offset_table_ptr == NULL)
  163872. {
  163873. #ifndef PNG_USER_MEM_SUPPORTED
  163874. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163875. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163876. else
  163877. png_warning(png_ptr, "Out Of memory.");
  163878. #endif
  163879. return (NULL);
  163880. }
  163881. hptr = (png_byte huge *)table;
  163882. if ((png_size_t)hptr & 0xf)
  163883. {
  163884. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163885. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163886. }
  163887. for (i = 0; i < num_blocks; i++)
  163888. {
  163889. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163890. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163891. }
  163892. png_ptr->offset_table_number = num_blocks;
  163893. png_ptr->offset_table_count = 0;
  163894. png_ptr->offset_table_count_free = 0;
  163895. }
  163896. }
  163897. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163898. {
  163899. #ifndef PNG_USER_MEM_SUPPORTED
  163900. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163901. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163902. else
  163903. png_warning(png_ptr, "Out of Memory.");
  163904. #endif
  163905. return (NULL);
  163906. }
  163907. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163908. }
  163909. else
  163910. ret = farmalloc(size);
  163911. #ifndef PNG_USER_MEM_SUPPORTED
  163912. if (ret == NULL)
  163913. {
  163914. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163915. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163916. else
  163917. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163918. }
  163919. #endif
  163920. return (ret);
  163921. }
  163922. void PNGAPI
  163923. png_free(png_structp png_ptr, png_voidp ptr)
  163924. {
  163925. if (png_ptr == NULL || ptr == NULL)
  163926. return;
  163927. #ifdef PNG_USER_MEM_SUPPORTED
  163928. if (png_ptr->free_fn != NULL)
  163929. {
  163930. (*(png_ptr->free_fn))(png_ptr, ptr);
  163931. return;
  163932. }
  163933. else png_free_default(png_ptr, ptr);
  163934. }
  163935. void PNGAPI
  163936. png_free_default(png_structp png_ptr, png_voidp ptr)
  163937. {
  163938. #endif /* PNG_USER_MEM_SUPPORTED */
  163939. if(png_ptr == NULL) return;
  163940. if (png_ptr->offset_table != NULL)
  163941. {
  163942. int i;
  163943. for (i = 0; i < png_ptr->offset_table_count; i++)
  163944. {
  163945. if (ptr == png_ptr->offset_table_ptr[i])
  163946. {
  163947. ptr = NULL;
  163948. png_ptr->offset_table_count_free++;
  163949. break;
  163950. }
  163951. }
  163952. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  163953. {
  163954. farfree(png_ptr->offset_table);
  163955. farfree(png_ptr->offset_table_ptr);
  163956. png_ptr->offset_table = NULL;
  163957. png_ptr->offset_table_ptr = NULL;
  163958. }
  163959. }
  163960. if (ptr != NULL)
  163961. {
  163962. farfree(ptr);
  163963. }
  163964. }
  163965. #else /* Not the Borland DOS special memory handler */
  163966. png_voidp /* PRIVATE */
  163967. png_create_struct(int type)
  163968. {
  163969. #ifdef PNG_USER_MEM_SUPPORTED
  163970. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163971. }
  163972. png_voidp /* PRIVATE */
  163973. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163974. {
  163975. #endif /* PNG_USER_MEM_SUPPORTED */
  163976. png_size_t size;
  163977. png_voidp struct_ptr;
  163978. if (type == PNG_STRUCT_INFO)
  163979. size = png_sizeof(png_info);
  163980. else if (type == PNG_STRUCT_PNG)
  163981. size = png_sizeof(png_struct);
  163982. else
  163983. return (NULL);
  163984. #ifdef PNG_USER_MEM_SUPPORTED
  163985. if(malloc_fn != NULL)
  163986. {
  163987. png_struct dummy_struct;
  163988. png_structp png_ptr = &dummy_struct;
  163989. png_ptr->mem_ptr=mem_ptr;
  163990. struct_ptr = (*(malloc_fn))(png_ptr, size);
  163991. if (struct_ptr != NULL)
  163992. png_memset(struct_ptr, 0, size);
  163993. return (struct_ptr);
  163994. }
  163995. #endif /* PNG_USER_MEM_SUPPORTED */
  163996. #if defined(__TURBOC__) && !defined(__FLAT__)
  163997. struct_ptr = (png_voidp)farmalloc(size);
  163998. #else
  163999. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164000. struct_ptr = (png_voidp)halloc(size,1);
  164001. # else
  164002. struct_ptr = (png_voidp)malloc(size);
  164003. # endif
  164004. #endif
  164005. if (struct_ptr != NULL)
  164006. png_memset(struct_ptr, 0, size);
  164007. return (struct_ptr);
  164008. }
  164009. void /* PRIVATE */
  164010. png_destroy_struct(png_voidp struct_ptr)
  164011. {
  164012. #ifdef PNG_USER_MEM_SUPPORTED
  164013. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164014. }
  164015. void /* PRIVATE */
  164016. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164017. png_voidp mem_ptr)
  164018. {
  164019. #endif /* PNG_USER_MEM_SUPPORTED */
  164020. if (struct_ptr != NULL)
  164021. {
  164022. #ifdef PNG_USER_MEM_SUPPORTED
  164023. if(free_fn != NULL)
  164024. {
  164025. png_struct dummy_struct;
  164026. png_structp png_ptr = &dummy_struct;
  164027. png_ptr->mem_ptr=mem_ptr;
  164028. (*(free_fn))(png_ptr, struct_ptr);
  164029. return;
  164030. }
  164031. #endif /* PNG_USER_MEM_SUPPORTED */
  164032. #if defined(__TURBOC__) && !defined(__FLAT__)
  164033. farfree(struct_ptr);
  164034. #else
  164035. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164036. hfree(struct_ptr);
  164037. # else
  164038. free(struct_ptr);
  164039. # endif
  164040. #endif
  164041. }
  164042. }
  164043. png_voidp PNGAPI
  164044. png_malloc(png_structp png_ptr, png_uint_32 size)
  164045. {
  164046. png_voidp ret;
  164047. #ifdef PNG_USER_MEM_SUPPORTED
  164048. if (png_ptr == NULL || size == 0)
  164049. return (NULL);
  164050. if(png_ptr->malloc_fn != NULL)
  164051. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164052. else
  164053. ret = (png_malloc_default(png_ptr, size));
  164054. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164055. png_error(png_ptr, "Out of Memory!");
  164056. return (ret);
  164057. }
  164058. png_voidp PNGAPI
  164059. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164060. {
  164061. png_voidp ret;
  164062. #endif /* PNG_USER_MEM_SUPPORTED */
  164063. if (png_ptr == NULL || size == 0)
  164064. return (NULL);
  164065. #ifdef PNG_MAX_MALLOC_64K
  164066. if (size > (png_uint_32)65536L)
  164067. {
  164068. #ifndef PNG_USER_MEM_SUPPORTED
  164069. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164070. png_error(png_ptr, "Cannot Allocate > 64K");
  164071. else
  164072. #endif
  164073. return NULL;
  164074. }
  164075. #endif
  164076. #if defined(__TURBOC__) && !defined(__FLAT__)
  164077. if (size != (unsigned long)size)
  164078. ret = NULL;
  164079. else
  164080. ret = farmalloc(size);
  164081. #else
  164082. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164083. if (size != (unsigned long)size)
  164084. ret = NULL;
  164085. else
  164086. ret = halloc(size, 1);
  164087. # else
  164088. if (size != (size_t)size)
  164089. ret = NULL;
  164090. else
  164091. ret = malloc((size_t)size);
  164092. # endif
  164093. #endif
  164094. #ifndef PNG_USER_MEM_SUPPORTED
  164095. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164096. png_error(png_ptr, "Out of Memory");
  164097. #endif
  164098. return (ret);
  164099. }
  164100. void PNGAPI
  164101. png_free(png_structp png_ptr, png_voidp ptr)
  164102. {
  164103. if (png_ptr == NULL || ptr == NULL)
  164104. return;
  164105. #ifdef PNG_USER_MEM_SUPPORTED
  164106. if (png_ptr->free_fn != NULL)
  164107. {
  164108. (*(png_ptr->free_fn))(png_ptr, ptr);
  164109. return;
  164110. }
  164111. else png_free_default(png_ptr, ptr);
  164112. }
  164113. void PNGAPI
  164114. png_free_default(png_structp png_ptr, png_voidp ptr)
  164115. {
  164116. if (png_ptr == NULL || ptr == NULL)
  164117. return;
  164118. #endif /* PNG_USER_MEM_SUPPORTED */
  164119. #if defined(__TURBOC__) && !defined(__FLAT__)
  164120. farfree(ptr);
  164121. #else
  164122. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164123. hfree(ptr);
  164124. # else
  164125. free(ptr);
  164126. # endif
  164127. #endif
  164128. }
  164129. #endif /* Not Borland DOS special memory handler */
  164130. #if defined(PNG_1_0_X)
  164131. # define png_malloc_warn png_malloc
  164132. #else
  164133. png_voidp PNGAPI
  164134. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164135. {
  164136. png_voidp ptr;
  164137. png_uint_32 save_flags;
  164138. if(png_ptr == NULL) return (NULL);
  164139. save_flags=png_ptr->flags;
  164140. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164141. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164142. png_ptr->flags=save_flags;
  164143. return(ptr);
  164144. }
  164145. #endif
  164146. png_voidp PNGAPI
  164147. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164148. png_uint_32 length)
  164149. {
  164150. png_size_t size;
  164151. size = (png_size_t)length;
  164152. if ((png_uint_32)size != length)
  164153. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164154. return(png_memcpy (s1, s2, size));
  164155. }
  164156. png_voidp PNGAPI
  164157. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164158. png_uint_32 length)
  164159. {
  164160. png_size_t size;
  164161. size = (png_size_t)length;
  164162. if ((png_uint_32)size != length)
  164163. png_error(png_ptr,"Overflow in png_memset_check.");
  164164. return (png_memset (s1, value, size));
  164165. }
  164166. #ifdef PNG_USER_MEM_SUPPORTED
  164167. void PNGAPI
  164168. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164169. malloc_fn, png_free_ptr free_fn)
  164170. {
  164171. if(png_ptr != NULL) {
  164172. png_ptr->mem_ptr = mem_ptr;
  164173. png_ptr->malloc_fn = malloc_fn;
  164174. png_ptr->free_fn = free_fn;
  164175. }
  164176. }
  164177. png_voidp PNGAPI
  164178. png_get_mem_ptr(png_structp png_ptr)
  164179. {
  164180. if(png_ptr == NULL) return (NULL);
  164181. return ((png_voidp)png_ptr->mem_ptr);
  164182. }
  164183. #endif /* PNG_USER_MEM_SUPPORTED */
  164184. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164185. /*** End of inlined file: pngmem.c ***/
  164186. /*** Start of inlined file: pngread.c ***/
  164187. #define PNG_INTERNAL
  164188. #if defined(PNG_READ_SUPPORTED)
  164189. png_structp PNGAPI
  164190. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164191. png_error_ptr error_fn, png_error_ptr warn_fn)
  164192. {
  164193. #ifdef PNG_USER_MEM_SUPPORTED
  164194. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164195. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164196. }
  164197. png_structp PNGAPI
  164198. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164199. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164200. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164201. {
  164202. #endif /* PNG_USER_MEM_SUPPORTED */
  164203. png_structp png_ptr;
  164204. #ifdef PNG_SETJMP_SUPPORTED
  164205. #ifdef USE_FAR_KEYWORD
  164206. jmp_buf jmpbuf;
  164207. #endif
  164208. #endif
  164209. int i;
  164210. png_debug(1, "in png_create_read_struct\n");
  164211. #ifdef PNG_USER_MEM_SUPPORTED
  164212. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164213. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164214. #else
  164215. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164216. #endif
  164217. if (png_ptr == NULL)
  164218. return (NULL);
  164219. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164220. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164221. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164222. #endif
  164223. #ifdef PNG_SETJMP_SUPPORTED
  164224. #ifdef USE_FAR_KEYWORD
  164225. if (setjmp(jmpbuf))
  164226. #else
  164227. if (setjmp(png_ptr->jmpbuf))
  164228. #endif
  164229. {
  164230. png_free(png_ptr, png_ptr->zbuf);
  164231. png_ptr->zbuf=NULL;
  164232. #ifdef PNG_USER_MEM_SUPPORTED
  164233. png_destroy_struct_2((png_voidp)png_ptr,
  164234. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164235. #else
  164236. png_destroy_struct((png_voidp)png_ptr);
  164237. #endif
  164238. return (NULL);
  164239. }
  164240. #ifdef USE_FAR_KEYWORD
  164241. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164242. #endif
  164243. #endif
  164244. #ifdef PNG_USER_MEM_SUPPORTED
  164245. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164246. #endif
  164247. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164248. i=0;
  164249. do
  164250. {
  164251. if(user_png_ver[i] != png_libpng_ver[i])
  164252. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164253. } while (png_libpng_ver[i++]);
  164254. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164255. {
  164256. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164257. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164258. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164259. {
  164260. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164261. char msg[80];
  164262. if (user_png_ver)
  164263. {
  164264. png_snprintf(msg, 80,
  164265. "Application was compiled with png.h from libpng-%.20s",
  164266. user_png_ver);
  164267. png_warning(png_ptr, msg);
  164268. }
  164269. png_snprintf(msg, 80,
  164270. "Application is running with png.c from libpng-%.20s",
  164271. png_libpng_ver);
  164272. png_warning(png_ptr, msg);
  164273. #endif
  164274. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164275. png_ptr->flags=0;
  164276. #endif
  164277. png_error(png_ptr,
  164278. "Incompatible libpng version in application and library");
  164279. }
  164280. }
  164281. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164282. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164283. (png_uint_32)png_ptr->zbuf_size);
  164284. png_ptr->zstream.zalloc = png_zalloc;
  164285. png_ptr->zstream.zfree = png_zfree;
  164286. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164287. switch (inflateInit(&png_ptr->zstream))
  164288. {
  164289. case Z_OK: /* Do nothing */ break;
  164290. case Z_MEM_ERROR:
  164291. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164292. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164293. default: png_error(png_ptr, "Unknown zlib error");
  164294. }
  164295. png_ptr->zstream.next_out = png_ptr->zbuf;
  164296. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164297. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164298. #ifdef PNG_SETJMP_SUPPORTED
  164299. #ifdef USE_FAR_KEYWORD
  164300. if (setjmp(jmpbuf))
  164301. PNG_ABORT();
  164302. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164303. #else
  164304. if (setjmp(png_ptr->jmpbuf))
  164305. PNG_ABORT();
  164306. #endif
  164307. #endif
  164308. return (png_ptr);
  164309. }
  164310. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164311. #undef png_read_init
  164312. void PNGAPI
  164313. png_read_init(png_structp png_ptr)
  164314. {
  164315. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164316. }
  164317. void PNGAPI
  164318. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164319. png_size_t png_struct_size, png_size_t png_info_size)
  164320. {
  164321. if(png_ptr == NULL) return;
  164322. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164323. if(png_sizeof(png_struct) > png_struct_size ||
  164324. png_sizeof(png_info) > png_info_size)
  164325. {
  164326. char msg[80];
  164327. png_ptr->warning_fn=NULL;
  164328. if (user_png_ver)
  164329. {
  164330. png_snprintf(msg, 80,
  164331. "Application was compiled with png.h from libpng-%.20s",
  164332. user_png_ver);
  164333. png_warning(png_ptr, msg);
  164334. }
  164335. png_snprintf(msg, 80,
  164336. "Application is running with png.c from libpng-%.20s",
  164337. png_libpng_ver);
  164338. png_warning(png_ptr, msg);
  164339. }
  164340. #endif
  164341. if(png_sizeof(png_struct) > png_struct_size)
  164342. {
  164343. png_ptr->error_fn=NULL;
  164344. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164345. png_ptr->flags=0;
  164346. #endif
  164347. png_error(png_ptr,
  164348. "The png struct allocated by the application for reading is too small.");
  164349. }
  164350. if(png_sizeof(png_info) > png_info_size)
  164351. {
  164352. png_ptr->error_fn=NULL;
  164353. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164354. png_ptr->flags=0;
  164355. #endif
  164356. png_error(png_ptr,
  164357. "The info struct allocated by application for reading is too small.");
  164358. }
  164359. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164360. }
  164361. #endif /* PNG_1_0_X || PNG_1_2_X */
  164362. void PNGAPI
  164363. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164364. png_size_t png_struct_size)
  164365. {
  164366. #ifdef PNG_SETJMP_SUPPORTED
  164367. jmp_buf tmp_jmp; /* to save current jump buffer */
  164368. #endif
  164369. int i=0;
  164370. png_structp png_ptr=*ptr_ptr;
  164371. if(png_ptr == NULL) return;
  164372. do
  164373. {
  164374. if(user_png_ver[i] != png_libpng_ver[i])
  164375. {
  164376. #ifdef PNG_LEGACY_SUPPORTED
  164377. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164378. #else
  164379. png_ptr->warning_fn=NULL;
  164380. png_warning(png_ptr,
  164381. "Application uses deprecated png_read_init() and should be recompiled.");
  164382. break;
  164383. #endif
  164384. }
  164385. } while (png_libpng_ver[i++]);
  164386. png_debug(1, "in png_read_init_3\n");
  164387. #ifdef PNG_SETJMP_SUPPORTED
  164388. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164389. #endif
  164390. if(png_sizeof(png_struct) > png_struct_size)
  164391. {
  164392. png_destroy_struct(png_ptr);
  164393. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164394. png_ptr = *ptr_ptr;
  164395. }
  164396. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164397. #ifdef PNG_SETJMP_SUPPORTED
  164398. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164399. #endif
  164400. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164401. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164402. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164403. #endif
  164404. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164405. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164406. (png_uint_32)png_ptr->zbuf_size);
  164407. png_ptr->zstream.zalloc = png_zalloc;
  164408. png_ptr->zstream.zfree = png_zfree;
  164409. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164410. switch (inflateInit(&png_ptr->zstream))
  164411. {
  164412. case Z_OK: /* Do nothing */ break;
  164413. case Z_MEM_ERROR:
  164414. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164415. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164416. default: png_error(png_ptr, "Unknown zlib error");
  164417. }
  164418. png_ptr->zstream.next_out = png_ptr->zbuf;
  164419. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164420. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164421. }
  164422. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164423. void PNGAPI
  164424. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164425. {
  164426. if(png_ptr == NULL) return;
  164427. png_debug(1, "in png_read_info\n");
  164428. if (png_ptr->sig_bytes < 8)
  164429. {
  164430. png_size_t num_checked = png_ptr->sig_bytes,
  164431. num_to_check = 8 - num_checked;
  164432. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164433. png_ptr->sig_bytes = 8;
  164434. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164435. {
  164436. if (num_checked < 4 &&
  164437. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164438. png_error(png_ptr, "Not a PNG file");
  164439. else
  164440. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164441. }
  164442. if (num_checked < 3)
  164443. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164444. }
  164445. for(;;)
  164446. {
  164447. #ifdef PNG_USE_LOCAL_ARRAYS
  164448. PNG_CONST PNG_IHDR;
  164449. PNG_CONST PNG_IDAT;
  164450. PNG_CONST PNG_IEND;
  164451. PNG_CONST PNG_PLTE;
  164452. #if defined(PNG_READ_bKGD_SUPPORTED)
  164453. PNG_CONST PNG_bKGD;
  164454. #endif
  164455. #if defined(PNG_READ_cHRM_SUPPORTED)
  164456. PNG_CONST PNG_cHRM;
  164457. #endif
  164458. #if defined(PNG_READ_gAMA_SUPPORTED)
  164459. PNG_CONST PNG_gAMA;
  164460. #endif
  164461. #if defined(PNG_READ_hIST_SUPPORTED)
  164462. PNG_CONST PNG_hIST;
  164463. #endif
  164464. #if defined(PNG_READ_iCCP_SUPPORTED)
  164465. PNG_CONST PNG_iCCP;
  164466. #endif
  164467. #if defined(PNG_READ_iTXt_SUPPORTED)
  164468. PNG_CONST PNG_iTXt;
  164469. #endif
  164470. #if defined(PNG_READ_oFFs_SUPPORTED)
  164471. PNG_CONST PNG_oFFs;
  164472. #endif
  164473. #if defined(PNG_READ_pCAL_SUPPORTED)
  164474. PNG_CONST PNG_pCAL;
  164475. #endif
  164476. #if defined(PNG_READ_pHYs_SUPPORTED)
  164477. PNG_CONST PNG_pHYs;
  164478. #endif
  164479. #if defined(PNG_READ_sBIT_SUPPORTED)
  164480. PNG_CONST PNG_sBIT;
  164481. #endif
  164482. #if defined(PNG_READ_sCAL_SUPPORTED)
  164483. PNG_CONST PNG_sCAL;
  164484. #endif
  164485. #if defined(PNG_READ_sPLT_SUPPORTED)
  164486. PNG_CONST PNG_sPLT;
  164487. #endif
  164488. #if defined(PNG_READ_sRGB_SUPPORTED)
  164489. PNG_CONST PNG_sRGB;
  164490. #endif
  164491. #if defined(PNG_READ_tEXt_SUPPORTED)
  164492. PNG_CONST PNG_tEXt;
  164493. #endif
  164494. #if defined(PNG_READ_tIME_SUPPORTED)
  164495. PNG_CONST PNG_tIME;
  164496. #endif
  164497. #if defined(PNG_READ_tRNS_SUPPORTED)
  164498. PNG_CONST PNG_tRNS;
  164499. #endif
  164500. #if defined(PNG_READ_zTXt_SUPPORTED)
  164501. PNG_CONST PNG_zTXt;
  164502. #endif
  164503. #endif /* PNG_USE_LOCAL_ARRAYS */
  164504. png_byte chunk_length[4];
  164505. png_uint_32 length;
  164506. png_read_data(png_ptr, chunk_length, 4);
  164507. length = png_get_uint_31(png_ptr,chunk_length);
  164508. png_reset_crc(png_ptr);
  164509. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164510. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164511. length);
  164512. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164513. if(png_ptr->mode & PNG_AFTER_IDAT)
  164514. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164515. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164516. png_handle_IHDR(png_ptr, info_ptr, length);
  164517. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164518. png_handle_IEND(png_ptr, info_ptr, length);
  164519. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164520. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164521. {
  164522. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164523. png_ptr->mode |= PNG_HAVE_IDAT;
  164524. png_handle_unknown(png_ptr, info_ptr, length);
  164525. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164526. png_ptr->mode |= PNG_HAVE_PLTE;
  164527. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164528. {
  164529. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164530. png_error(png_ptr, "Missing IHDR before IDAT");
  164531. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164532. !(png_ptr->mode & PNG_HAVE_PLTE))
  164533. png_error(png_ptr, "Missing PLTE before IDAT");
  164534. break;
  164535. }
  164536. }
  164537. #endif
  164538. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164539. png_handle_PLTE(png_ptr, info_ptr, length);
  164540. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164541. {
  164542. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164543. png_error(png_ptr, "Missing IHDR before IDAT");
  164544. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164545. !(png_ptr->mode & PNG_HAVE_PLTE))
  164546. png_error(png_ptr, "Missing PLTE before IDAT");
  164547. png_ptr->idat_size = length;
  164548. png_ptr->mode |= PNG_HAVE_IDAT;
  164549. break;
  164550. }
  164551. #if defined(PNG_READ_bKGD_SUPPORTED)
  164552. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164553. png_handle_bKGD(png_ptr, info_ptr, length);
  164554. #endif
  164555. #if defined(PNG_READ_cHRM_SUPPORTED)
  164556. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164557. png_handle_cHRM(png_ptr, info_ptr, length);
  164558. #endif
  164559. #if defined(PNG_READ_gAMA_SUPPORTED)
  164560. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164561. png_handle_gAMA(png_ptr, info_ptr, length);
  164562. #endif
  164563. #if defined(PNG_READ_hIST_SUPPORTED)
  164564. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164565. png_handle_hIST(png_ptr, info_ptr, length);
  164566. #endif
  164567. #if defined(PNG_READ_oFFs_SUPPORTED)
  164568. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164569. png_handle_oFFs(png_ptr, info_ptr, length);
  164570. #endif
  164571. #if defined(PNG_READ_pCAL_SUPPORTED)
  164572. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164573. png_handle_pCAL(png_ptr, info_ptr, length);
  164574. #endif
  164575. #if defined(PNG_READ_sCAL_SUPPORTED)
  164576. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164577. png_handle_sCAL(png_ptr, info_ptr, length);
  164578. #endif
  164579. #if defined(PNG_READ_pHYs_SUPPORTED)
  164580. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164581. png_handle_pHYs(png_ptr, info_ptr, length);
  164582. #endif
  164583. #if defined(PNG_READ_sBIT_SUPPORTED)
  164584. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164585. png_handle_sBIT(png_ptr, info_ptr, length);
  164586. #endif
  164587. #if defined(PNG_READ_sRGB_SUPPORTED)
  164588. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164589. png_handle_sRGB(png_ptr, info_ptr, length);
  164590. #endif
  164591. #if defined(PNG_READ_iCCP_SUPPORTED)
  164592. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164593. png_handle_iCCP(png_ptr, info_ptr, length);
  164594. #endif
  164595. #if defined(PNG_READ_sPLT_SUPPORTED)
  164596. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164597. png_handle_sPLT(png_ptr, info_ptr, length);
  164598. #endif
  164599. #if defined(PNG_READ_tEXt_SUPPORTED)
  164600. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164601. png_handle_tEXt(png_ptr, info_ptr, length);
  164602. #endif
  164603. #if defined(PNG_READ_tIME_SUPPORTED)
  164604. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164605. png_handle_tIME(png_ptr, info_ptr, length);
  164606. #endif
  164607. #if defined(PNG_READ_tRNS_SUPPORTED)
  164608. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164609. png_handle_tRNS(png_ptr, info_ptr, length);
  164610. #endif
  164611. #if defined(PNG_READ_zTXt_SUPPORTED)
  164612. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164613. png_handle_zTXt(png_ptr, info_ptr, length);
  164614. #endif
  164615. #if defined(PNG_READ_iTXt_SUPPORTED)
  164616. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164617. png_handle_iTXt(png_ptr, info_ptr, length);
  164618. #endif
  164619. else
  164620. png_handle_unknown(png_ptr, info_ptr, length);
  164621. }
  164622. }
  164623. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164624. void PNGAPI
  164625. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164626. {
  164627. png_debug(1, "in png_read_update_info\n");
  164628. if(png_ptr == NULL) return;
  164629. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164630. png_read_start_row(png_ptr);
  164631. else
  164632. png_warning(png_ptr,
  164633. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164634. png_read_transform_info(png_ptr, info_ptr);
  164635. }
  164636. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164637. void PNGAPI
  164638. png_start_read_image(png_structp png_ptr)
  164639. {
  164640. png_debug(1, "in png_start_read_image\n");
  164641. if(png_ptr == NULL) return;
  164642. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164643. png_read_start_row(png_ptr);
  164644. }
  164645. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164646. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164647. void PNGAPI
  164648. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164649. {
  164650. #ifdef PNG_USE_LOCAL_ARRAYS
  164651. PNG_CONST PNG_IDAT;
  164652. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164653. 0xff};
  164654. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164655. #endif
  164656. int ret;
  164657. if(png_ptr == NULL) return;
  164658. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164659. png_ptr->row_number, png_ptr->pass);
  164660. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164661. png_read_start_row(png_ptr);
  164662. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164663. {
  164664. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164665. if (png_ptr->transformations & PNG_INVERT_MONO)
  164666. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164667. #endif
  164668. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164669. if (png_ptr->transformations & PNG_FILLER)
  164670. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164671. #endif
  164672. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164673. if (png_ptr->transformations & PNG_PACKSWAP)
  164674. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164675. #endif
  164676. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164677. if (png_ptr->transformations & PNG_PACK)
  164678. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164679. #endif
  164680. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164681. if (png_ptr->transformations & PNG_SHIFT)
  164682. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164683. #endif
  164684. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164685. if (png_ptr->transformations & PNG_BGR)
  164686. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164687. #endif
  164688. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164689. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164690. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164691. #endif
  164692. }
  164693. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164694. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164695. {
  164696. switch (png_ptr->pass)
  164697. {
  164698. case 0:
  164699. if (png_ptr->row_number & 0x07)
  164700. {
  164701. if (dsp_row != NULL)
  164702. png_combine_row(png_ptr, dsp_row,
  164703. png_pass_dsp_mask[png_ptr->pass]);
  164704. png_read_finish_row(png_ptr);
  164705. return;
  164706. }
  164707. break;
  164708. case 1:
  164709. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164710. {
  164711. if (dsp_row != NULL)
  164712. png_combine_row(png_ptr, dsp_row,
  164713. png_pass_dsp_mask[png_ptr->pass]);
  164714. png_read_finish_row(png_ptr);
  164715. return;
  164716. }
  164717. break;
  164718. case 2:
  164719. if ((png_ptr->row_number & 0x07) != 4)
  164720. {
  164721. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164722. png_combine_row(png_ptr, dsp_row,
  164723. png_pass_dsp_mask[png_ptr->pass]);
  164724. png_read_finish_row(png_ptr);
  164725. return;
  164726. }
  164727. break;
  164728. case 3:
  164729. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164730. {
  164731. if (dsp_row != NULL)
  164732. png_combine_row(png_ptr, dsp_row,
  164733. png_pass_dsp_mask[png_ptr->pass]);
  164734. png_read_finish_row(png_ptr);
  164735. return;
  164736. }
  164737. break;
  164738. case 4:
  164739. if ((png_ptr->row_number & 3) != 2)
  164740. {
  164741. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164742. png_combine_row(png_ptr, dsp_row,
  164743. png_pass_dsp_mask[png_ptr->pass]);
  164744. png_read_finish_row(png_ptr);
  164745. return;
  164746. }
  164747. break;
  164748. case 5:
  164749. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164750. {
  164751. if (dsp_row != NULL)
  164752. png_combine_row(png_ptr, dsp_row,
  164753. png_pass_dsp_mask[png_ptr->pass]);
  164754. png_read_finish_row(png_ptr);
  164755. return;
  164756. }
  164757. break;
  164758. case 6:
  164759. if (!(png_ptr->row_number & 1))
  164760. {
  164761. png_read_finish_row(png_ptr);
  164762. return;
  164763. }
  164764. break;
  164765. }
  164766. }
  164767. #endif
  164768. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164769. png_error(png_ptr, "Invalid attempt to read row data");
  164770. png_ptr->zstream.next_out = png_ptr->row_buf;
  164771. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164772. do
  164773. {
  164774. if (!(png_ptr->zstream.avail_in))
  164775. {
  164776. while (!png_ptr->idat_size)
  164777. {
  164778. png_byte chunk_length[4];
  164779. png_crc_finish(png_ptr, 0);
  164780. png_read_data(png_ptr, chunk_length, 4);
  164781. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164782. png_reset_crc(png_ptr);
  164783. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164784. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164785. png_error(png_ptr, "Not enough image data");
  164786. }
  164787. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164788. png_ptr->zstream.next_in = png_ptr->zbuf;
  164789. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164790. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164791. png_crc_read(png_ptr, png_ptr->zbuf,
  164792. (png_size_t)png_ptr->zstream.avail_in);
  164793. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164794. }
  164795. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164796. if (ret == Z_STREAM_END)
  164797. {
  164798. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164799. png_ptr->idat_size)
  164800. png_error(png_ptr, "Extra compressed data");
  164801. png_ptr->mode |= PNG_AFTER_IDAT;
  164802. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164803. break;
  164804. }
  164805. if (ret != Z_OK)
  164806. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164807. "Decompression error");
  164808. } while (png_ptr->zstream.avail_out);
  164809. png_ptr->row_info.color_type = png_ptr->color_type;
  164810. png_ptr->row_info.width = png_ptr->iwidth;
  164811. png_ptr->row_info.channels = png_ptr->channels;
  164812. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164813. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164814. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164815. png_ptr->row_info.width);
  164816. if(png_ptr->row_buf[0])
  164817. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164818. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164819. (int)(png_ptr->row_buf[0]));
  164820. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164821. png_ptr->rowbytes + 1);
  164822. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164823. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164824. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164825. {
  164826. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164827. }
  164828. #endif
  164829. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164830. png_do_read_transformations(png_ptr);
  164831. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164832. if (png_ptr->interlaced &&
  164833. (png_ptr->transformations & PNG_INTERLACE))
  164834. {
  164835. if (png_ptr->pass < 6)
  164836. png_do_read_interlace(png_ptr);
  164837. if (dsp_row != NULL)
  164838. png_combine_row(png_ptr, dsp_row,
  164839. png_pass_dsp_mask[png_ptr->pass]);
  164840. if (row != NULL)
  164841. png_combine_row(png_ptr, row,
  164842. png_pass_mask[png_ptr->pass]);
  164843. }
  164844. else
  164845. #endif
  164846. {
  164847. if (row != NULL)
  164848. png_combine_row(png_ptr, row, 0xff);
  164849. if (dsp_row != NULL)
  164850. png_combine_row(png_ptr, dsp_row, 0xff);
  164851. }
  164852. png_read_finish_row(png_ptr);
  164853. if (png_ptr->read_row_fn != NULL)
  164854. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164855. }
  164856. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164857. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164858. void PNGAPI
  164859. png_read_rows(png_structp png_ptr, png_bytepp row,
  164860. png_bytepp display_row, png_uint_32 num_rows)
  164861. {
  164862. png_uint_32 i;
  164863. png_bytepp rp;
  164864. png_bytepp dp;
  164865. png_debug(1, "in png_read_rows\n");
  164866. if(png_ptr == NULL) return;
  164867. rp = row;
  164868. dp = display_row;
  164869. if (rp != NULL && dp != NULL)
  164870. for (i = 0; i < num_rows; i++)
  164871. {
  164872. png_bytep rptr = *rp++;
  164873. png_bytep dptr = *dp++;
  164874. png_read_row(png_ptr, rptr, dptr);
  164875. }
  164876. else if(rp != NULL)
  164877. for (i = 0; i < num_rows; i++)
  164878. {
  164879. png_bytep rptr = *rp;
  164880. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164881. rp++;
  164882. }
  164883. else if(dp != NULL)
  164884. for (i = 0; i < num_rows; i++)
  164885. {
  164886. png_bytep dptr = *dp;
  164887. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164888. dp++;
  164889. }
  164890. }
  164891. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164892. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164893. void PNGAPI
  164894. png_read_image(png_structp png_ptr, png_bytepp image)
  164895. {
  164896. png_uint_32 i,image_height;
  164897. int pass, j;
  164898. png_bytepp rp;
  164899. png_debug(1, "in png_read_image\n");
  164900. if(png_ptr == NULL) return;
  164901. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164902. pass = png_set_interlace_handling(png_ptr);
  164903. #else
  164904. if (png_ptr->interlaced)
  164905. png_error(png_ptr,
  164906. "Cannot read interlaced image -- interlace handler disabled.");
  164907. pass = 1;
  164908. #endif
  164909. image_height=png_ptr->height;
  164910. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164911. for (j = 0; j < pass; j++)
  164912. {
  164913. rp = image;
  164914. for (i = 0; i < image_height; i++)
  164915. {
  164916. png_read_row(png_ptr, *rp, png_bytep_NULL);
  164917. rp++;
  164918. }
  164919. }
  164920. }
  164921. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164922. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164923. void PNGAPI
  164924. png_read_end(png_structp png_ptr, png_infop info_ptr)
  164925. {
  164926. png_byte chunk_length[4];
  164927. png_uint_32 length;
  164928. png_debug(1, "in png_read_end\n");
  164929. if(png_ptr == NULL) return;
  164930. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  164931. do
  164932. {
  164933. #ifdef PNG_USE_LOCAL_ARRAYS
  164934. PNG_CONST PNG_IHDR;
  164935. PNG_CONST PNG_IDAT;
  164936. PNG_CONST PNG_IEND;
  164937. PNG_CONST PNG_PLTE;
  164938. #if defined(PNG_READ_bKGD_SUPPORTED)
  164939. PNG_CONST PNG_bKGD;
  164940. #endif
  164941. #if defined(PNG_READ_cHRM_SUPPORTED)
  164942. PNG_CONST PNG_cHRM;
  164943. #endif
  164944. #if defined(PNG_READ_gAMA_SUPPORTED)
  164945. PNG_CONST PNG_gAMA;
  164946. #endif
  164947. #if defined(PNG_READ_hIST_SUPPORTED)
  164948. PNG_CONST PNG_hIST;
  164949. #endif
  164950. #if defined(PNG_READ_iCCP_SUPPORTED)
  164951. PNG_CONST PNG_iCCP;
  164952. #endif
  164953. #if defined(PNG_READ_iTXt_SUPPORTED)
  164954. PNG_CONST PNG_iTXt;
  164955. #endif
  164956. #if defined(PNG_READ_oFFs_SUPPORTED)
  164957. PNG_CONST PNG_oFFs;
  164958. #endif
  164959. #if defined(PNG_READ_pCAL_SUPPORTED)
  164960. PNG_CONST PNG_pCAL;
  164961. #endif
  164962. #if defined(PNG_READ_pHYs_SUPPORTED)
  164963. PNG_CONST PNG_pHYs;
  164964. #endif
  164965. #if defined(PNG_READ_sBIT_SUPPORTED)
  164966. PNG_CONST PNG_sBIT;
  164967. #endif
  164968. #if defined(PNG_READ_sCAL_SUPPORTED)
  164969. PNG_CONST PNG_sCAL;
  164970. #endif
  164971. #if defined(PNG_READ_sPLT_SUPPORTED)
  164972. PNG_CONST PNG_sPLT;
  164973. #endif
  164974. #if defined(PNG_READ_sRGB_SUPPORTED)
  164975. PNG_CONST PNG_sRGB;
  164976. #endif
  164977. #if defined(PNG_READ_tEXt_SUPPORTED)
  164978. PNG_CONST PNG_tEXt;
  164979. #endif
  164980. #if defined(PNG_READ_tIME_SUPPORTED)
  164981. PNG_CONST PNG_tIME;
  164982. #endif
  164983. #if defined(PNG_READ_tRNS_SUPPORTED)
  164984. PNG_CONST PNG_tRNS;
  164985. #endif
  164986. #if defined(PNG_READ_zTXt_SUPPORTED)
  164987. PNG_CONST PNG_zTXt;
  164988. #endif
  164989. #endif /* PNG_USE_LOCAL_ARRAYS */
  164990. png_read_data(png_ptr, chunk_length, 4);
  164991. length = png_get_uint_31(png_ptr,chunk_length);
  164992. png_reset_crc(png_ptr);
  164993. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164994. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  164995. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164996. png_handle_IHDR(png_ptr, info_ptr, length);
  164997. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164998. png_handle_IEND(png_ptr, info_ptr, length);
  164999. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165000. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165001. {
  165002. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165003. {
  165004. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165005. png_error(png_ptr, "Too many IDAT's found");
  165006. }
  165007. png_handle_unknown(png_ptr, info_ptr, length);
  165008. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165009. png_ptr->mode |= PNG_HAVE_PLTE;
  165010. }
  165011. #endif
  165012. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165013. {
  165014. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165015. png_error(png_ptr, "Too many IDAT's found");
  165016. png_crc_finish(png_ptr, length);
  165017. }
  165018. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165019. png_handle_PLTE(png_ptr, info_ptr, length);
  165020. #if defined(PNG_READ_bKGD_SUPPORTED)
  165021. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165022. png_handle_bKGD(png_ptr, info_ptr, length);
  165023. #endif
  165024. #if defined(PNG_READ_cHRM_SUPPORTED)
  165025. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165026. png_handle_cHRM(png_ptr, info_ptr, length);
  165027. #endif
  165028. #if defined(PNG_READ_gAMA_SUPPORTED)
  165029. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165030. png_handle_gAMA(png_ptr, info_ptr, length);
  165031. #endif
  165032. #if defined(PNG_READ_hIST_SUPPORTED)
  165033. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165034. png_handle_hIST(png_ptr, info_ptr, length);
  165035. #endif
  165036. #if defined(PNG_READ_oFFs_SUPPORTED)
  165037. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165038. png_handle_oFFs(png_ptr, info_ptr, length);
  165039. #endif
  165040. #if defined(PNG_READ_pCAL_SUPPORTED)
  165041. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165042. png_handle_pCAL(png_ptr, info_ptr, length);
  165043. #endif
  165044. #if defined(PNG_READ_sCAL_SUPPORTED)
  165045. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165046. png_handle_sCAL(png_ptr, info_ptr, length);
  165047. #endif
  165048. #if defined(PNG_READ_pHYs_SUPPORTED)
  165049. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165050. png_handle_pHYs(png_ptr, info_ptr, length);
  165051. #endif
  165052. #if defined(PNG_READ_sBIT_SUPPORTED)
  165053. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165054. png_handle_sBIT(png_ptr, info_ptr, length);
  165055. #endif
  165056. #if defined(PNG_READ_sRGB_SUPPORTED)
  165057. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165058. png_handle_sRGB(png_ptr, info_ptr, length);
  165059. #endif
  165060. #if defined(PNG_READ_iCCP_SUPPORTED)
  165061. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165062. png_handle_iCCP(png_ptr, info_ptr, length);
  165063. #endif
  165064. #if defined(PNG_READ_sPLT_SUPPORTED)
  165065. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165066. png_handle_sPLT(png_ptr, info_ptr, length);
  165067. #endif
  165068. #if defined(PNG_READ_tEXt_SUPPORTED)
  165069. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165070. png_handle_tEXt(png_ptr, info_ptr, length);
  165071. #endif
  165072. #if defined(PNG_READ_tIME_SUPPORTED)
  165073. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165074. png_handle_tIME(png_ptr, info_ptr, length);
  165075. #endif
  165076. #if defined(PNG_READ_tRNS_SUPPORTED)
  165077. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165078. png_handle_tRNS(png_ptr, info_ptr, length);
  165079. #endif
  165080. #if defined(PNG_READ_zTXt_SUPPORTED)
  165081. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165082. png_handle_zTXt(png_ptr, info_ptr, length);
  165083. #endif
  165084. #if defined(PNG_READ_iTXt_SUPPORTED)
  165085. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165086. png_handle_iTXt(png_ptr, info_ptr, length);
  165087. #endif
  165088. else
  165089. png_handle_unknown(png_ptr, info_ptr, length);
  165090. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165091. }
  165092. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165093. void PNGAPI
  165094. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165095. png_infopp end_info_ptr_ptr)
  165096. {
  165097. png_structp png_ptr = NULL;
  165098. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165099. #ifdef PNG_USER_MEM_SUPPORTED
  165100. png_free_ptr free_fn;
  165101. png_voidp mem_ptr;
  165102. #endif
  165103. png_debug(1, "in png_destroy_read_struct\n");
  165104. if (png_ptr_ptr != NULL)
  165105. png_ptr = *png_ptr_ptr;
  165106. if (info_ptr_ptr != NULL)
  165107. info_ptr = *info_ptr_ptr;
  165108. if (end_info_ptr_ptr != NULL)
  165109. end_info_ptr = *end_info_ptr_ptr;
  165110. #ifdef PNG_USER_MEM_SUPPORTED
  165111. free_fn = png_ptr->free_fn;
  165112. mem_ptr = png_ptr->mem_ptr;
  165113. #endif
  165114. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165115. if (info_ptr != NULL)
  165116. {
  165117. #if defined(PNG_TEXT_SUPPORTED)
  165118. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165119. #endif
  165120. #ifdef PNG_USER_MEM_SUPPORTED
  165121. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165122. (png_voidp)mem_ptr);
  165123. #else
  165124. png_destroy_struct((png_voidp)info_ptr);
  165125. #endif
  165126. *info_ptr_ptr = NULL;
  165127. }
  165128. if (end_info_ptr != NULL)
  165129. {
  165130. #if defined(PNG_READ_TEXT_SUPPORTED)
  165131. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165132. #endif
  165133. #ifdef PNG_USER_MEM_SUPPORTED
  165134. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165135. (png_voidp)mem_ptr);
  165136. #else
  165137. png_destroy_struct((png_voidp)end_info_ptr);
  165138. #endif
  165139. *end_info_ptr_ptr = NULL;
  165140. }
  165141. if (png_ptr != NULL)
  165142. {
  165143. #ifdef PNG_USER_MEM_SUPPORTED
  165144. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165145. (png_voidp)mem_ptr);
  165146. #else
  165147. png_destroy_struct((png_voidp)png_ptr);
  165148. #endif
  165149. *png_ptr_ptr = NULL;
  165150. }
  165151. }
  165152. void /* PRIVATE */
  165153. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165154. {
  165155. #ifdef PNG_SETJMP_SUPPORTED
  165156. jmp_buf tmp_jmp;
  165157. #endif
  165158. png_error_ptr error_fn;
  165159. png_error_ptr warning_fn;
  165160. png_voidp error_ptr;
  165161. #ifdef PNG_USER_MEM_SUPPORTED
  165162. png_free_ptr free_fn;
  165163. #endif
  165164. png_debug(1, "in png_read_destroy\n");
  165165. if (info_ptr != NULL)
  165166. png_info_destroy(png_ptr, info_ptr);
  165167. if (end_info_ptr != NULL)
  165168. png_info_destroy(png_ptr, end_info_ptr);
  165169. png_free(png_ptr, png_ptr->zbuf);
  165170. png_free(png_ptr, png_ptr->big_row_buf);
  165171. png_free(png_ptr, png_ptr->prev_row);
  165172. #if defined(PNG_READ_DITHER_SUPPORTED)
  165173. png_free(png_ptr, png_ptr->palette_lookup);
  165174. png_free(png_ptr, png_ptr->dither_index);
  165175. #endif
  165176. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165177. png_free(png_ptr, png_ptr->gamma_table);
  165178. #endif
  165179. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165180. png_free(png_ptr, png_ptr->gamma_from_1);
  165181. png_free(png_ptr, png_ptr->gamma_to_1);
  165182. #endif
  165183. #ifdef PNG_FREE_ME_SUPPORTED
  165184. if (png_ptr->free_me & PNG_FREE_PLTE)
  165185. png_zfree(png_ptr, png_ptr->palette);
  165186. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165187. #else
  165188. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165189. png_zfree(png_ptr, png_ptr->palette);
  165190. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165191. #endif
  165192. #if defined(PNG_tRNS_SUPPORTED) || \
  165193. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165194. #ifdef PNG_FREE_ME_SUPPORTED
  165195. if (png_ptr->free_me & PNG_FREE_TRNS)
  165196. png_free(png_ptr, png_ptr->trans);
  165197. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165198. #else
  165199. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165200. png_free(png_ptr, png_ptr->trans);
  165201. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165202. #endif
  165203. #endif
  165204. #if defined(PNG_READ_hIST_SUPPORTED)
  165205. #ifdef PNG_FREE_ME_SUPPORTED
  165206. if (png_ptr->free_me & PNG_FREE_HIST)
  165207. png_free(png_ptr, png_ptr->hist);
  165208. png_ptr->free_me &= ~PNG_FREE_HIST;
  165209. #else
  165210. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165211. png_free(png_ptr, png_ptr->hist);
  165212. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165213. #endif
  165214. #endif
  165215. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165216. if (png_ptr->gamma_16_table != NULL)
  165217. {
  165218. int i;
  165219. int istop = (1 << (8 - png_ptr->gamma_shift));
  165220. for (i = 0; i < istop; i++)
  165221. {
  165222. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165223. }
  165224. png_free(png_ptr, png_ptr->gamma_16_table);
  165225. }
  165226. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165227. if (png_ptr->gamma_16_from_1 != NULL)
  165228. {
  165229. int i;
  165230. int istop = (1 << (8 - png_ptr->gamma_shift));
  165231. for (i = 0; i < istop; i++)
  165232. {
  165233. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165234. }
  165235. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165236. }
  165237. if (png_ptr->gamma_16_to_1 != NULL)
  165238. {
  165239. int i;
  165240. int istop = (1 << (8 - png_ptr->gamma_shift));
  165241. for (i = 0; i < istop; i++)
  165242. {
  165243. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165244. }
  165245. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165246. }
  165247. #endif
  165248. #endif
  165249. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165250. png_free(png_ptr, png_ptr->time_buffer);
  165251. #endif
  165252. inflateEnd(&png_ptr->zstream);
  165253. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165254. png_free(png_ptr, png_ptr->save_buffer);
  165255. #endif
  165256. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165257. #ifdef PNG_TEXT_SUPPORTED
  165258. png_free(png_ptr, png_ptr->current_text);
  165259. #endif /* PNG_TEXT_SUPPORTED */
  165260. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165261. #ifdef PNG_SETJMP_SUPPORTED
  165262. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165263. #endif
  165264. error_fn = png_ptr->error_fn;
  165265. warning_fn = png_ptr->warning_fn;
  165266. error_ptr = png_ptr->error_ptr;
  165267. #ifdef PNG_USER_MEM_SUPPORTED
  165268. free_fn = png_ptr->free_fn;
  165269. #endif
  165270. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165271. png_ptr->error_fn = error_fn;
  165272. png_ptr->warning_fn = warning_fn;
  165273. png_ptr->error_ptr = error_ptr;
  165274. #ifdef PNG_USER_MEM_SUPPORTED
  165275. png_ptr->free_fn = free_fn;
  165276. #endif
  165277. #ifdef PNG_SETJMP_SUPPORTED
  165278. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165279. #endif
  165280. }
  165281. void PNGAPI
  165282. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165283. {
  165284. if(png_ptr == NULL) return;
  165285. png_ptr->read_row_fn = read_row_fn;
  165286. }
  165287. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165288. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165289. void PNGAPI
  165290. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165291. int transforms,
  165292. voidp params)
  165293. {
  165294. int row;
  165295. if(png_ptr == NULL) return;
  165296. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165297. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165298. png_set_invert_alpha(png_ptr);
  165299. #endif
  165300. png_read_info(png_ptr, info_ptr);
  165301. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165302. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165303. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165304. if (transforms & PNG_TRANSFORM_STRIP_16)
  165305. png_set_strip_16(png_ptr);
  165306. #endif
  165307. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165308. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165309. png_set_strip_alpha(png_ptr);
  165310. #endif
  165311. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165312. if (transforms & PNG_TRANSFORM_PACKING)
  165313. png_set_packing(png_ptr);
  165314. #endif
  165315. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165316. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165317. png_set_packswap(png_ptr);
  165318. #endif
  165319. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165320. if (transforms & PNG_TRANSFORM_EXPAND)
  165321. if ((png_ptr->bit_depth < 8) ||
  165322. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165323. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165324. png_set_expand(png_ptr);
  165325. #endif
  165326. #if defined(PNG_READ_INVERT_SUPPORTED)
  165327. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165328. png_set_invert_mono(png_ptr);
  165329. #endif
  165330. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165331. if ((transforms & PNG_TRANSFORM_SHIFT)
  165332. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165333. {
  165334. png_color_8p sig_bit;
  165335. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165336. png_set_shift(png_ptr, sig_bit);
  165337. }
  165338. #endif
  165339. #if defined(PNG_READ_BGR_SUPPORTED)
  165340. if (transforms & PNG_TRANSFORM_BGR)
  165341. png_set_bgr(png_ptr);
  165342. #endif
  165343. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165344. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165345. png_set_swap_alpha(png_ptr);
  165346. #endif
  165347. #if defined(PNG_READ_SWAP_SUPPORTED)
  165348. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165349. png_set_swap(png_ptr);
  165350. #endif
  165351. png_read_update_info(png_ptr, info_ptr);
  165352. #ifdef PNG_FREE_ME_SUPPORTED
  165353. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165354. #endif
  165355. if(info_ptr->row_pointers == NULL)
  165356. {
  165357. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165358. info_ptr->height * png_sizeof(png_bytep));
  165359. #ifdef PNG_FREE_ME_SUPPORTED
  165360. info_ptr->free_me |= PNG_FREE_ROWS;
  165361. #endif
  165362. for (row = 0; row < (int)info_ptr->height; row++)
  165363. {
  165364. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165365. png_get_rowbytes(png_ptr, info_ptr));
  165366. }
  165367. }
  165368. png_read_image(png_ptr, info_ptr->row_pointers);
  165369. info_ptr->valid |= PNG_INFO_IDAT;
  165370. png_read_end(png_ptr, info_ptr);
  165371. transforms = transforms; /* quiet compiler warnings */
  165372. params = params;
  165373. }
  165374. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165375. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165376. #endif /* PNG_READ_SUPPORTED */
  165377. /*** End of inlined file: pngread.c ***/
  165378. /*** Start of inlined file: pngpread.c ***/
  165379. #define PNG_INTERNAL
  165380. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165381. #define PNG_READ_SIG_MODE 0
  165382. #define PNG_READ_CHUNK_MODE 1
  165383. #define PNG_READ_IDAT_MODE 2
  165384. #define PNG_SKIP_MODE 3
  165385. #define PNG_READ_tEXt_MODE 4
  165386. #define PNG_READ_zTXt_MODE 5
  165387. #define PNG_READ_DONE_MODE 6
  165388. #define PNG_READ_iTXt_MODE 7
  165389. #define PNG_ERROR_MODE 8
  165390. void PNGAPI
  165391. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165392. png_bytep buffer, png_size_t buffer_size)
  165393. {
  165394. if(png_ptr == NULL) return;
  165395. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165396. while (png_ptr->buffer_size)
  165397. {
  165398. png_process_some_data(png_ptr, info_ptr);
  165399. }
  165400. }
  165401. void /* PRIVATE */
  165402. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165403. {
  165404. if(png_ptr == NULL) return;
  165405. switch (png_ptr->process_mode)
  165406. {
  165407. case PNG_READ_SIG_MODE:
  165408. {
  165409. png_push_read_sig(png_ptr, info_ptr);
  165410. break;
  165411. }
  165412. case PNG_READ_CHUNK_MODE:
  165413. {
  165414. png_push_read_chunk(png_ptr, info_ptr);
  165415. break;
  165416. }
  165417. case PNG_READ_IDAT_MODE:
  165418. {
  165419. png_push_read_IDAT(png_ptr);
  165420. break;
  165421. }
  165422. #if defined(PNG_READ_tEXt_SUPPORTED)
  165423. case PNG_READ_tEXt_MODE:
  165424. {
  165425. png_push_read_tEXt(png_ptr, info_ptr);
  165426. break;
  165427. }
  165428. #endif
  165429. #if defined(PNG_READ_zTXt_SUPPORTED)
  165430. case PNG_READ_zTXt_MODE:
  165431. {
  165432. png_push_read_zTXt(png_ptr, info_ptr);
  165433. break;
  165434. }
  165435. #endif
  165436. #if defined(PNG_READ_iTXt_SUPPORTED)
  165437. case PNG_READ_iTXt_MODE:
  165438. {
  165439. png_push_read_iTXt(png_ptr, info_ptr);
  165440. break;
  165441. }
  165442. #endif
  165443. case PNG_SKIP_MODE:
  165444. {
  165445. png_push_crc_finish(png_ptr);
  165446. break;
  165447. }
  165448. default:
  165449. {
  165450. png_ptr->buffer_size = 0;
  165451. break;
  165452. }
  165453. }
  165454. }
  165455. void /* PRIVATE */
  165456. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165457. {
  165458. png_size_t num_checked = png_ptr->sig_bytes,
  165459. num_to_check = 8 - num_checked;
  165460. if (png_ptr->buffer_size < num_to_check)
  165461. {
  165462. num_to_check = png_ptr->buffer_size;
  165463. }
  165464. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165465. num_to_check);
  165466. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165467. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165468. {
  165469. if (num_checked < 4 &&
  165470. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165471. png_error(png_ptr, "Not a PNG file");
  165472. else
  165473. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165474. }
  165475. else
  165476. {
  165477. if (png_ptr->sig_bytes >= 8)
  165478. {
  165479. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165480. }
  165481. }
  165482. }
  165483. void /* PRIVATE */
  165484. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165485. {
  165486. #ifdef PNG_USE_LOCAL_ARRAYS
  165487. PNG_CONST PNG_IHDR;
  165488. PNG_CONST PNG_IDAT;
  165489. PNG_CONST PNG_IEND;
  165490. PNG_CONST PNG_PLTE;
  165491. #if defined(PNG_READ_bKGD_SUPPORTED)
  165492. PNG_CONST PNG_bKGD;
  165493. #endif
  165494. #if defined(PNG_READ_cHRM_SUPPORTED)
  165495. PNG_CONST PNG_cHRM;
  165496. #endif
  165497. #if defined(PNG_READ_gAMA_SUPPORTED)
  165498. PNG_CONST PNG_gAMA;
  165499. #endif
  165500. #if defined(PNG_READ_hIST_SUPPORTED)
  165501. PNG_CONST PNG_hIST;
  165502. #endif
  165503. #if defined(PNG_READ_iCCP_SUPPORTED)
  165504. PNG_CONST PNG_iCCP;
  165505. #endif
  165506. #if defined(PNG_READ_iTXt_SUPPORTED)
  165507. PNG_CONST PNG_iTXt;
  165508. #endif
  165509. #if defined(PNG_READ_oFFs_SUPPORTED)
  165510. PNG_CONST PNG_oFFs;
  165511. #endif
  165512. #if defined(PNG_READ_pCAL_SUPPORTED)
  165513. PNG_CONST PNG_pCAL;
  165514. #endif
  165515. #if defined(PNG_READ_pHYs_SUPPORTED)
  165516. PNG_CONST PNG_pHYs;
  165517. #endif
  165518. #if defined(PNG_READ_sBIT_SUPPORTED)
  165519. PNG_CONST PNG_sBIT;
  165520. #endif
  165521. #if defined(PNG_READ_sCAL_SUPPORTED)
  165522. PNG_CONST PNG_sCAL;
  165523. #endif
  165524. #if defined(PNG_READ_sRGB_SUPPORTED)
  165525. PNG_CONST PNG_sRGB;
  165526. #endif
  165527. #if defined(PNG_READ_sPLT_SUPPORTED)
  165528. PNG_CONST PNG_sPLT;
  165529. #endif
  165530. #if defined(PNG_READ_tEXt_SUPPORTED)
  165531. PNG_CONST PNG_tEXt;
  165532. #endif
  165533. #if defined(PNG_READ_tIME_SUPPORTED)
  165534. PNG_CONST PNG_tIME;
  165535. #endif
  165536. #if defined(PNG_READ_tRNS_SUPPORTED)
  165537. PNG_CONST PNG_tRNS;
  165538. #endif
  165539. #if defined(PNG_READ_zTXt_SUPPORTED)
  165540. PNG_CONST PNG_zTXt;
  165541. #endif
  165542. #endif /* PNG_USE_LOCAL_ARRAYS */
  165543. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165544. {
  165545. png_byte chunk_length[4];
  165546. if (png_ptr->buffer_size < 8)
  165547. {
  165548. png_push_save_buffer(png_ptr);
  165549. return;
  165550. }
  165551. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165552. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165553. png_reset_crc(png_ptr);
  165554. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165555. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165556. }
  165557. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165558. if(png_ptr->mode & PNG_AFTER_IDAT)
  165559. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165560. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165561. {
  165562. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165563. {
  165564. png_push_save_buffer(png_ptr);
  165565. return;
  165566. }
  165567. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165568. }
  165569. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165570. {
  165571. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165572. {
  165573. png_push_save_buffer(png_ptr);
  165574. return;
  165575. }
  165576. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165577. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165578. png_push_have_end(png_ptr, info_ptr);
  165579. }
  165580. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165581. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165582. {
  165583. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165584. {
  165585. png_push_save_buffer(png_ptr);
  165586. return;
  165587. }
  165588. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165589. png_ptr->mode |= PNG_HAVE_IDAT;
  165590. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165591. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165592. png_ptr->mode |= PNG_HAVE_PLTE;
  165593. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165594. {
  165595. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165596. png_error(png_ptr, "Missing IHDR before IDAT");
  165597. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165598. !(png_ptr->mode & PNG_HAVE_PLTE))
  165599. png_error(png_ptr, "Missing PLTE before IDAT");
  165600. }
  165601. }
  165602. #endif
  165603. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165604. {
  165605. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165606. {
  165607. png_push_save_buffer(png_ptr);
  165608. return;
  165609. }
  165610. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165611. }
  165612. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165613. {
  165614. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165615. png_error(png_ptr, "Missing IHDR before IDAT");
  165616. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165617. !(png_ptr->mode & PNG_HAVE_PLTE))
  165618. png_error(png_ptr, "Missing PLTE before IDAT");
  165619. if (png_ptr->mode & PNG_HAVE_IDAT)
  165620. {
  165621. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165622. if (png_ptr->push_length == 0)
  165623. return;
  165624. if (png_ptr->mode & PNG_AFTER_IDAT)
  165625. png_error(png_ptr, "Too many IDAT's found");
  165626. }
  165627. png_ptr->idat_size = png_ptr->push_length;
  165628. png_ptr->mode |= PNG_HAVE_IDAT;
  165629. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165630. png_push_have_info(png_ptr, info_ptr);
  165631. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165632. png_ptr->zstream.next_out = png_ptr->row_buf;
  165633. return;
  165634. }
  165635. #if defined(PNG_READ_gAMA_SUPPORTED)
  165636. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165637. {
  165638. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165639. {
  165640. png_push_save_buffer(png_ptr);
  165641. return;
  165642. }
  165643. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165644. }
  165645. #endif
  165646. #if defined(PNG_READ_sBIT_SUPPORTED)
  165647. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165648. {
  165649. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165650. {
  165651. png_push_save_buffer(png_ptr);
  165652. return;
  165653. }
  165654. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165655. }
  165656. #endif
  165657. #if defined(PNG_READ_cHRM_SUPPORTED)
  165658. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165659. {
  165660. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165661. {
  165662. png_push_save_buffer(png_ptr);
  165663. return;
  165664. }
  165665. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165666. }
  165667. #endif
  165668. #if defined(PNG_READ_sRGB_SUPPORTED)
  165669. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165670. {
  165671. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165672. {
  165673. png_push_save_buffer(png_ptr);
  165674. return;
  165675. }
  165676. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165677. }
  165678. #endif
  165679. #if defined(PNG_READ_iCCP_SUPPORTED)
  165680. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165681. {
  165682. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165683. {
  165684. png_push_save_buffer(png_ptr);
  165685. return;
  165686. }
  165687. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165688. }
  165689. #endif
  165690. #if defined(PNG_READ_sPLT_SUPPORTED)
  165691. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165692. {
  165693. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165694. {
  165695. png_push_save_buffer(png_ptr);
  165696. return;
  165697. }
  165698. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165699. }
  165700. #endif
  165701. #if defined(PNG_READ_tRNS_SUPPORTED)
  165702. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165703. {
  165704. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165705. {
  165706. png_push_save_buffer(png_ptr);
  165707. return;
  165708. }
  165709. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165710. }
  165711. #endif
  165712. #if defined(PNG_READ_bKGD_SUPPORTED)
  165713. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165714. {
  165715. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165716. {
  165717. png_push_save_buffer(png_ptr);
  165718. return;
  165719. }
  165720. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165721. }
  165722. #endif
  165723. #if defined(PNG_READ_hIST_SUPPORTED)
  165724. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165725. {
  165726. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165727. {
  165728. png_push_save_buffer(png_ptr);
  165729. return;
  165730. }
  165731. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165732. }
  165733. #endif
  165734. #if defined(PNG_READ_pHYs_SUPPORTED)
  165735. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165736. {
  165737. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165738. {
  165739. png_push_save_buffer(png_ptr);
  165740. return;
  165741. }
  165742. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165743. }
  165744. #endif
  165745. #if defined(PNG_READ_oFFs_SUPPORTED)
  165746. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165747. {
  165748. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165749. {
  165750. png_push_save_buffer(png_ptr);
  165751. return;
  165752. }
  165753. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165754. }
  165755. #endif
  165756. #if defined(PNG_READ_pCAL_SUPPORTED)
  165757. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165758. {
  165759. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165760. {
  165761. png_push_save_buffer(png_ptr);
  165762. return;
  165763. }
  165764. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165765. }
  165766. #endif
  165767. #if defined(PNG_READ_sCAL_SUPPORTED)
  165768. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165769. {
  165770. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165771. {
  165772. png_push_save_buffer(png_ptr);
  165773. return;
  165774. }
  165775. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165776. }
  165777. #endif
  165778. #if defined(PNG_READ_tIME_SUPPORTED)
  165779. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165780. {
  165781. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165782. {
  165783. png_push_save_buffer(png_ptr);
  165784. return;
  165785. }
  165786. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165787. }
  165788. #endif
  165789. #if defined(PNG_READ_tEXt_SUPPORTED)
  165790. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165791. {
  165792. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165793. {
  165794. png_push_save_buffer(png_ptr);
  165795. return;
  165796. }
  165797. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165798. }
  165799. #endif
  165800. #if defined(PNG_READ_zTXt_SUPPORTED)
  165801. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165802. {
  165803. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165804. {
  165805. png_push_save_buffer(png_ptr);
  165806. return;
  165807. }
  165808. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165809. }
  165810. #endif
  165811. #if defined(PNG_READ_iTXt_SUPPORTED)
  165812. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165813. {
  165814. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165815. {
  165816. png_push_save_buffer(png_ptr);
  165817. return;
  165818. }
  165819. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165820. }
  165821. #endif
  165822. else
  165823. {
  165824. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165825. {
  165826. png_push_save_buffer(png_ptr);
  165827. return;
  165828. }
  165829. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165830. }
  165831. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165832. }
  165833. void /* PRIVATE */
  165834. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165835. {
  165836. png_ptr->process_mode = PNG_SKIP_MODE;
  165837. png_ptr->skip_length = skip;
  165838. }
  165839. void /* PRIVATE */
  165840. png_push_crc_finish(png_structp png_ptr)
  165841. {
  165842. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165843. {
  165844. png_size_t save_size;
  165845. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165846. save_size = (png_size_t)png_ptr->skip_length;
  165847. else
  165848. save_size = png_ptr->save_buffer_size;
  165849. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165850. png_ptr->skip_length -= save_size;
  165851. png_ptr->buffer_size -= save_size;
  165852. png_ptr->save_buffer_size -= save_size;
  165853. png_ptr->save_buffer_ptr += save_size;
  165854. }
  165855. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165856. {
  165857. png_size_t save_size;
  165858. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165859. save_size = (png_size_t)png_ptr->skip_length;
  165860. else
  165861. save_size = png_ptr->current_buffer_size;
  165862. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165863. png_ptr->skip_length -= save_size;
  165864. png_ptr->buffer_size -= save_size;
  165865. png_ptr->current_buffer_size -= save_size;
  165866. png_ptr->current_buffer_ptr += save_size;
  165867. }
  165868. if (!png_ptr->skip_length)
  165869. {
  165870. if (png_ptr->buffer_size < 4)
  165871. {
  165872. png_push_save_buffer(png_ptr);
  165873. return;
  165874. }
  165875. png_crc_finish(png_ptr, 0);
  165876. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165877. }
  165878. }
  165879. void PNGAPI
  165880. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165881. {
  165882. png_bytep ptr;
  165883. if(png_ptr == NULL) return;
  165884. ptr = buffer;
  165885. if (png_ptr->save_buffer_size)
  165886. {
  165887. png_size_t save_size;
  165888. if (length < png_ptr->save_buffer_size)
  165889. save_size = length;
  165890. else
  165891. save_size = png_ptr->save_buffer_size;
  165892. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165893. length -= save_size;
  165894. ptr += save_size;
  165895. png_ptr->buffer_size -= save_size;
  165896. png_ptr->save_buffer_size -= save_size;
  165897. png_ptr->save_buffer_ptr += save_size;
  165898. }
  165899. if (length && png_ptr->current_buffer_size)
  165900. {
  165901. png_size_t save_size;
  165902. if (length < png_ptr->current_buffer_size)
  165903. save_size = length;
  165904. else
  165905. save_size = png_ptr->current_buffer_size;
  165906. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165907. png_ptr->buffer_size -= save_size;
  165908. png_ptr->current_buffer_size -= save_size;
  165909. png_ptr->current_buffer_ptr += save_size;
  165910. }
  165911. }
  165912. void /* PRIVATE */
  165913. png_push_save_buffer(png_structp png_ptr)
  165914. {
  165915. if (png_ptr->save_buffer_size)
  165916. {
  165917. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  165918. {
  165919. png_size_t i,istop;
  165920. png_bytep sp;
  165921. png_bytep dp;
  165922. istop = png_ptr->save_buffer_size;
  165923. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  165924. i < istop; i++, sp++, dp++)
  165925. {
  165926. *dp = *sp;
  165927. }
  165928. }
  165929. }
  165930. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  165931. png_ptr->save_buffer_max)
  165932. {
  165933. png_size_t new_max;
  165934. png_bytep old_buffer;
  165935. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  165936. (png_ptr->current_buffer_size + 256))
  165937. {
  165938. png_error(png_ptr, "Potential overflow of save_buffer");
  165939. }
  165940. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  165941. old_buffer = png_ptr->save_buffer;
  165942. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  165943. (png_uint_32)new_max);
  165944. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  165945. png_free(png_ptr, old_buffer);
  165946. png_ptr->save_buffer_max = new_max;
  165947. }
  165948. if (png_ptr->current_buffer_size)
  165949. {
  165950. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  165951. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  165952. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  165953. png_ptr->current_buffer_size = 0;
  165954. }
  165955. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  165956. png_ptr->buffer_size = 0;
  165957. }
  165958. void /* PRIVATE */
  165959. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  165960. png_size_t buffer_length)
  165961. {
  165962. png_ptr->current_buffer = buffer;
  165963. png_ptr->current_buffer_size = buffer_length;
  165964. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  165965. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  165966. }
  165967. void /* PRIVATE */
  165968. png_push_read_IDAT(png_structp png_ptr)
  165969. {
  165970. #ifdef PNG_USE_LOCAL_ARRAYS
  165971. PNG_CONST PNG_IDAT;
  165972. #endif
  165973. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165974. {
  165975. png_byte chunk_length[4];
  165976. if (png_ptr->buffer_size < 8)
  165977. {
  165978. png_push_save_buffer(png_ptr);
  165979. return;
  165980. }
  165981. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165982. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165983. png_reset_crc(png_ptr);
  165984. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165985. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165986. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165987. {
  165988. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165989. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165990. png_error(png_ptr, "Not enough compressed data");
  165991. return;
  165992. }
  165993. png_ptr->idat_size = png_ptr->push_length;
  165994. }
  165995. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  165996. {
  165997. png_size_t save_size;
  165998. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  165999. {
  166000. save_size = (png_size_t)png_ptr->idat_size;
  166001. if((png_uint_32)save_size != png_ptr->idat_size)
  166002. png_error(png_ptr, "save_size overflowed in pngpread");
  166003. }
  166004. else
  166005. save_size = png_ptr->save_buffer_size;
  166006. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166007. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166008. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166009. png_ptr->idat_size -= save_size;
  166010. png_ptr->buffer_size -= save_size;
  166011. png_ptr->save_buffer_size -= save_size;
  166012. png_ptr->save_buffer_ptr += save_size;
  166013. }
  166014. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166015. {
  166016. png_size_t save_size;
  166017. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166018. {
  166019. save_size = (png_size_t)png_ptr->idat_size;
  166020. if((png_uint_32)save_size != png_ptr->idat_size)
  166021. png_error(png_ptr, "save_size overflowed in pngpread");
  166022. }
  166023. else
  166024. save_size = png_ptr->current_buffer_size;
  166025. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166026. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166027. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166028. png_ptr->idat_size -= save_size;
  166029. png_ptr->buffer_size -= save_size;
  166030. png_ptr->current_buffer_size -= save_size;
  166031. png_ptr->current_buffer_ptr += save_size;
  166032. }
  166033. if (!png_ptr->idat_size)
  166034. {
  166035. if (png_ptr->buffer_size < 4)
  166036. {
  166037. png_push_save_buffer(png_ptr);
  166038. return;
  166039. }
  166040. png_crc_finish(png_ptr, 0);
  166041. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166042. png_ptr->mode |= PNG_AFTER_IDAT;
  166043. }
  166044. }
  166045. void /* PRIVATE */
  166046. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166047. png_size_t buffer_length)
  166048. {
  166049. int ret;
  166050. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166051. png_error(png_ptr, "Extra compression data");
  166052. png_ptr->zstream.next_in = buffer;
  166053. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166054. for(;;)
  166055. {
  166056. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166057. if (ret != Z_OK)
  166058. {
  166059. if (ret == Z_STREAM_END)
  166060. {
  166061. if (png_ptr->zstream.avail_in)
  166062. png_error(png_ptr, "Extra compressed data");
  166063. if (!(png_ptr->zstream.avail_out))
  166064. {
  166065. png_push_process_row(png_ptr);
  166066. }
  166067. png_ptr->mode |= PNG_AFTER_IDAT;
  166068. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166069. break;
  166070. }
  166071. else if (ret == Z_BUF_ERROR)
  166072. break;
  166073. else
  166074. png_error(png_ptr, "Decompression Error");
  166075. }
  166076. if (!(png_ptr->zstream.avail_out))
  166077. {
  166078. if ((
  166079. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166080. png_ptr->interlaced && png_ptr->pass > 6) ||
  166081. (!png_ptr->interlaced &&
  166082. #endif
  166083. png_ptr->row_number == png_ptr->num_rows))
  166084. {
  166085. if (png_ptr->zstream.avail_in)
  166086. {
  166087. png_warning(png_ptr, "Too much data in IDAT chunks");
  166088. }
  166089. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166090. break;
  166091. }
  166092. png_push_process_row(png_ptr);
  166093. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166094. png_ptr->zstream.next_out = png_ptr->row_buf;
  166095. }
  166096. else
  166097. break;
  166098. }
  166099. }
  166100. void /* PRIVATE */
  166101. png_push_process_row(png_structp png_ptr)
  166102. {
  166103. png_ptr->row_info.color_type = png_ptr->color_type;
  166104. png_ptr->row_info.width = png_ptr->iwidth;
  166105. png_ptr->row_info.channels = png_ptr->channels;
  166106. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166107. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166108. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166109. png_ptr->row_info.width);
  166110. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166111. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166112. (int)(png_ptr->row_buf[0]));
  166113. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166114. png_ptr->rowbytes + 1);
  166115. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166116. png_do_read_transformations(png_ptr);
  166117. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166118. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166119. {
  166120. if (png_ptr->pass < 6)
  166121. png_do_read_interlace(png_ptr);
  166122. switch (png_ptr->pass)
  166123. {
  166124. case 0:
  166125. {
  166126. int i;
  166127. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166128. {
  166129. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166130. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166131. }
  166132. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166133. {
  166134. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166135. {
  166136. png_push_have_row(png_ptr, png_bytep_NULL);
  166137. png_read_push_finish_row(png_ptr);
  166138. }
  166139. }
  166140. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166141. {
  166142. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166143. {
  166144. png_push_have_row(png_ptr, png_bytep_NULL);
  166145. png_read_push_finish_row(png_ptr);
  166146. }
  166147. }
  166148. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166149. {
  166150. png_push_have_row(png_ptr, png_bytep_NULL);
  166151. png_read_push_finish_row(png_ptr);
  166152. }
  166153. break;
  166154. }
  166155. case 1:
  166156. {
  166157. int i;
  166158. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166159. {
  166160. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166161. png_read_push_finish_row(png_ptr);
  166162. }
  166163. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166164. {
  166165. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166166. {
  166167. png_push_have_row(png_ptr, png_bytep_NULL);
  166168. png_read_push_finish_row(png_ptr);
  166169. }
  166170. }
  166171. break;
  166172. }
  166173. case 2:
  166174. {
  166175. int i;
  166176. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166177. {
  166178. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166179. png_read_push_finish_row(png_ptr);
  166180. }
  166181. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166182. {
  166183. png_push_have_row(png_ptr, png_bytep_NULL);
  166184. png_read_push_finish_row(png_ptr);
  166185. }
  166186. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166187. {
  166188. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166189. {
  166190. png_push_have_row(png_ptr, png_bytep_NULL);
  166191. png_read_push_finish_row(png_ptr);
  166192. }
  166193. }
  166194. break;
  166195. }
  166196. case 3:
  166197. {
  166198. int i;
  166199. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166200. {
  166201. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166202. png_read_push_finish_row(png_ptr);
  166203. }
  166204. if (png_ptr->pass == 4) /* skip top two generated rows */
  166205. {
  166206. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166207. {
  166208. png_push_have_row(png_ptr, png_bytep_NULL);
  166209. png_read_push_finish_row(png_ptr);
  166210. }
  166211. }
  166212. break;
  166213. }
  166214. case 4:
  166215. {
  166216. int i;
  166217. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166218. {
  166219. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166220. png_read_push_finish_row(png_ptr);
  166221. }
  166222. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166223. {
  166224. png_push_have_row(png_ptr, png_bytep_NULL);
  166225. png_read_push_finish_row(png_ptr);
  166226. }
  166227. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166228. {
  166229. png_push_have_row(png_ptr, png_bytep_NULL);
  166230. png_read_push_finish_row(png_ptr);
  166231. }
  166232. break;
  166233. }
  166234. case 5:
  166235. {
  166236. int i;
  166237. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166238. {
  166239. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166240. png_read_push_finish_row(png_ptr);
  166241. }
  166242. if (png_ptr->pass == 6) /* skip top generated row */
  166243. {
  166244. png_push_have_row(png_ptr, png_bytep_NULL);
  166245. png_read_push_finish_row(png_ptr);
  166246. }
  166247. break;
  166248. }
  166249. case 6:
  166250. {
  166251. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166252. png_read_push_finish_row(png_ptr);
  166253. if (png_ptr->pass != 6)
  166254. break;
  166255. png_push_have_row(png_ptr, png_bytep_NULL);
  166256. png_read_push_finish_row(png_ptr);
  166257. }
  166258. }
  166259. }
  166260. else
  166261. #endif
  166262. {
  166263. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166264. png_read_push_finish_row(png_ptr);
  166265. }
  166266. }
  166267. void /* PRIVATE */
  166268. png_read_push_finish_row(png_structp png_ptr)
  166269. {
  166270. #ifdef PNG_USE_LOCAL_ARRAYS
  166271. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166272. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166273. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166274. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166275. #endif
  166276. png_ptr->row_number++;
  166277. if (png_ptr->row_number < png_ptr->num_rows)
  166278. return;
  166279. if (png_ptr->interlaced)
  166280. {
  166281. png_ptr->row_number = 0;
  166282. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166283. png_ptr->rowbytes + 1);
  166284. do
  166285. {
  166286. png_ptr->pass++;
  166287. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166288. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166289. (png_ptr->pass == 5 && png_ptr->width < 2))
  166290. png_ptr->pass++;
  166291. if (png_ptr->pass > 7)
  166292. png_ptr->pass--;
  166293. if (png_ptr->pass >= 7)
  166294. break;
  166295. png_ptr->iwidth = (png_ptr->width +
  166296. png_pass_inc[png_ptr->pass] - 1 -
  166297. png_pass_start[png_ptr->pass]) /
  166298. png_pass_inc[png_ptr->pass];
  166299. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166300. png_ptr->iwidth) + 1;
  166301. if (png_ptr->transformations & PNG_INTERLACE)
  166302. break;
  166303. png_ptr->num_rows = (png_ptr->height +
  166304. png_pass_yinc[png_ptr->pass] - 1 -
  166305. png_pass_ystart[png_ptr->pass]) /
  166306. png_pass_yinc[png_ptr->pass];
  166307. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166308. }
  166309. }
  166310. #if defined(PNG_READ_tEXt_SUPPORTED)
  166311. void /* PRIVATE */
  166312. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166313. length)
  166314. {
  166315. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166316. {
  166317. png_error(png_ptr, "Out of place tEXt");
  166318. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166319. }
  166320. #ifdef PNG_MAX_MALLOC_64K
  166321. png_ptr->skip_length = 0; /* This may not be necessary */
  166322. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166323. {
  166324. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166325. png_ptr->skip_length = length - (png_uint_32)65535L;
  166326. length = (png_uint_32)65535L;
  166327. }
  166328. #endif
  166329. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166330. (png_uint_32)(length+1));
  166331. png_ptr->current_text[length] = '\0';
  166332. png_ptr->current_text_ptr = png_ptr->current_text;
  166333. png_ptr->current_text_size = (png_size_t)length;
  166334. png_ptr->current_text_left = (png_size_t)length;
  166335. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166336. }
  166337. void /* PRIVATE */
  166338. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166339. {
  166340. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166341. {
  166342. png_size_t text_size;
  166343. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166344. text_size = png_ptr->buffer_size;
  166345. else
  166346. text_size = png_ptr->current_text_left;
  166347. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166348. png_ptr->current_text_left -= text_size;
  166349. png_ptr->current_text_ptr += text_size;
  166350. }
  166351. if (!(png_ptr->current_text_left))
  166352. {
  166353. png_textp text_ptr;
  166354. png_charp text;
  166355. png_charp key;
  166356. int ret;
  166357. if (png_ptr->buffer_size < 4)
  166358. {
  166359. png_push_save_buffer(png_ptr);
  166360. return;
  166361. }
  166362. png_push_crc_finish(png_ptr);
  166363. #if defined(PNG_MAX_MALLOC_64K)
  166364. if (png_ptr->skip_length)
  166365. return;
  166366. #endif
  166367. key = png_ptr->current_text;
  166368. for (text = key; *text; text++)
  166369. ;
  166370. if (text < key + png_ptr->current_text_size)
  166371. text++;
  166372. text_ptr = (png_textp)png_malloc(png_ptr,
  166373. (png_uint_32)png_sizeof(png_text));
  166374. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166375. text_ptr->key = key;
  166376. #ifdef PNG_iTXt_SUPPORTED
  166377. text_ptr->lang = NULL;
  166378. text_ptr->lang_key = NULL;
  166379. #endif
  166380. text_ptr->text = text;
  166381. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166382. png_free(png_ptr, key);
  166383. png_free(png_ptr, text_ptr);
  166384. png_ptr->current_text = NULL;
  166385. if (ret)
  166386. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166387. }
  166388. }
  166389. #endif
  166390. #if defined(PNG_READ_zTXt_SUPPORTED)
  166391. void /* PRIVATE */
  166392. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166393. length)
  166394. {
  166395. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166396. {
  166397. png_error(png_ptr, "Out of place zTXt");
  166398. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166399. }
  166400. #ifdef PNG_MAX_MALLOC_64K
  166401. if (length > (png_uint_32)65535L)
  166402. {
  166403. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166404. png_push_crc_skip(png_ptr, length);
  166405. return;
  166406. }
  166407. #endif
  166408. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166409. (png_uint_32)(length+1));
  166410. png_ptr->current_text[length] = '\0';
  166411. png_ptr->current_text_ptr = png_ptr->current_text;
  166412. png_ptr->current_text_size = (png_size_t)length;
  166413. png_ptr->current_text_left = (png_size_t)length;
  166414. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166415. }
  166416. void /* PRIVATE */
  166417. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166418. {
  166419. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166420. {
  166421. png_size_t text_size;
  166422. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166423. text_size = png_ptr->buffer_size;
  166424. else
  166425. text_size = png_ptr->current_text_left;
  166426. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166427. png_ptr->current_text_left -= text_size;
  166428. png_ptr->current_text_ptr += text_size;
  166429. }
  166430. if (!(png_ptr->current_text_left))
  166431. {
  166432. png_textp text_ptr;
  166433. png_charp text;
  166434. png_charp key;
  166435. int ret;
  166436. png_size_t text_size, key_size;
  166437. if (png_ptr->buffer_size < 4)
  166438. {
  166439. png_push_save_buffer(png_ptr);
  166440. return;
  166441. }
  166442. png_push_crc_finish(png_ptr);
  166443. key = png_ptr->current_text;
  166444. for (text = key; *text; text++)
  166445. ;
  166446. if (text >= key + png_ptr->current_text_size)
  166447. {
  166448. png_ptr->current_text = NULL;
  166449. png_free(png_ptr, key);
  166450. return;
  166451. }
  166452. text++;
  166453. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166454. {
  166455. png_ptr->current_text = NULL;
  166456. png_free(png_ptr, key);
  166457. return;
  166458. }
  166459. text++;
  166460. png_ptr->zstream.next_in = (png_bytep )text;
  166461. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166462. (text - key));
  166463. png_ptr->zstream.next_out = png_ptr->zbuf;
  166464. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166465. key_size = text - key;
  166466. text_size = 0;
  166467. text = NULL;
  166468. ret = Z_STREAM_END;
  166469. while (png_ptr->zstream.avail_in)
  166470. {
  166471. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166472. if (ret != Z_OK && ret != Z_STREAM_END)
  166473. {
  166474. inflateReset(&png_ptr->zstream);
  166475. png_ptr->zstream.avail_in = 0;
  166476. png_ptr->current_text = NULL;
  166477. png_free(png_ptr, key);
  166478. png_free(png_ptr, text);
  166479. return;
  166480. }
  166481. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166482. {
  166483. if (text == NULL)
  166484. {
  166485. text = (png_charp)png_malloc(png_ptr,
  166486. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166487. + key_size + 1));
  166488. png_memcpy(text + key_size, png_ptr->zbuf,
  166489. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166490. png_memcpy(text, key, key_size);
  166491. text_size = key_size + png_ptr->zbuf_size -
  166492. png_ptr->zstream.avail_out;
  166493. *(text + text_size) = '\0';
  166494. }
  166495. else
  166496. {
  166497. png_charp tmp;
  166498. tmp = text;
  166499. text = (png_charp)png_malloc(png_ptr, text_size +
  166500. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166501. + 1));
  166502. png_memcpy(text, tmp, text_size);
  166503. png_free(png_ptr, tmp);
  166504. png_memcpy(text + text_size, png_ptr->zbuf,
  166505. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166506. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166507. *(text + text_size) = '\0';
  166508. }
  166509. if (ret != Z_STREAM_END)
  166510. {
  166511. png_ptr->zstream.next_out = png_ptr->zbuf;
  166512. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166513. }
  166514. }
  166515. else
  166516. {
  166517. break;
  166518. }
  166519. if (ret == Z_STREAM_END)
  166520. break;
  166521. }
  166522. inflateReset(&png_ptr->zstream);
  166523. png_ptr->zstream.avail_in = 0;
  166524. if (ret != Z_STREAM_END)
  166525. {
  166526. png_ptr->current_text = NULL;
  166527. png_free(png_ptr, key);
  166528. png_free(png_ptr, text);
  166529. return;
  166530. }
  166531. png_ptr->current_text = NULL;
  166532. png_free(png_ptr, key);
  166533. key = text;
  166534. text += key_size;
  166535. text_ptr = (png_textp)png_malloc(png_ptr,
  166536. (png_uint_32)png_sizeof(png_text));
  166537. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166538. text_ptr->key = key;
  166539. #ifdef PNG_iTXt_SUPPORTED
  166540. text_ptr->lang = NULL;
  166541. text_ptr->lang_key = NULL;
  166542. #endif
  166543. text_ptr->text = text;
  166544. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166545. png_free(png_ptr, key);
  166546. png_free(png_ptr, text_ptr);
  166547. if (ret)
  166548. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166549. }
  166550. }
  166551. #endif
  166552. #if defined(PNG_READ_iTXt_SUPPORTED)
  166553. void /* PRIVATE */
  166554. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166555. length)
  166556. {
  166557. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166558. {
  166559. png_error(png_ptr, "Out of place iTXt");
  166560. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166561. }
  166562. #ifdef PNG_MAX_MALLOC_64K
  166563. png_ptr->skip_length = 0; /* This may not be necessary */
  166564. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166565. {
  166566. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166567. png_ptr->skip_length = length - (png_uint_32)65535L;
  166568. length = (png_uint_32)65535L;
  166569. }
  166570. #endif
  166571. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166572. (png_uint_32)(length+1));
  166573. png_ptr->current_text[length] = '\0';
  166574. png_ptr->current_text_ptr = png_ptr->current_text;
  166575. png_ptr->current_text_size = (png_size_t)length;
  166576. png_ptr->current_text_left = (png_size_t)length;
  166577. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166578. }
  166579. void /* PRIVATE */
  166580. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166581. {
  166582. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166583. {
  166584. png_size_t text_size;
  166585. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166586. text_size = png_ptr->buffer_size;
  166587. else
  166588. text_size = png_ptr->current_text_left;
  166589. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166590. png_ptr->current_text_left -= text_size;
  166591. png_ptr->current_text_ptr += text_size;
  166592. }
  166593. if (!(png_ptr->current_text_left))
  166594. {
  166595. png_textp text_ptr;
  166596. png_charp key;
  166597. int comp_flag;
  166598. png_charp lang;
  166599. png_charp lang_key;
  166600. png_charp text;
  166601. int ret;
  166602. if (png_ptr->buffer_size < 4)
  166603. {
  166604. png_push_save_buffer(png_ptr);
  166605. return;
  166606. }
  166607. png_push_crc_finish(png_ptr);
  166608. #if defined(PNG_MAX_MALLOC_64K)
  166609. if (png_ptr->skip_length)
  166610. return;
  166611. #endif
  166612. key = png_ptr->current_text;
  166613. for (lang = key; *lang; lang++)
  166614. ;
  166615. if (lang < key + png_ptr->current_text_size - 3)
  166616. lang++;
  166617. comp_flag = *lang++;
  166618. lang++; /* skip comp_type, always zero */
  166619. for (lang_key = lang; *lang_key; lang_key++)
  166620. ;
  166621. lang_key++; /* skip NUL separator */
  166622. text=lang_key;
  166623. if (lang_key < key + png_ptr->current_text_size - 1)
  166624. {
  166625. for (; *text; text++)
  166626. ;
  166627. }
  166628. if (text < key + png_ptr->current_text_size)
  166629. text++;
  166630. text_ptr = (png_textp)png_malloc(png_ptr,
  166631. (png_uint_32)png_sizeof(png_text));
  166632. text_ptr->compression = comp_flag + 2;
  166633. text_ptr->key = key;
  166634. text_ptr->lang = lang;
  166635. text_ptr->lang_key = lang_key;
  166636. text_ptr->text = text;
  166637. text_ptr->text_length = 0;
  166638. text_ptr->itxt_length = png_strlen(text);
  166639. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166640. png_ptr->current_text = NULL;
  166641. png_free(png_ptr, text_ptr);
  166642. if (ret)
  166643. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166644. }
  166645. }
  166646. #endif
  166647. void /* PRIVATE */
  166648. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166649. length)
  166650. {
  166651. png_uint_32 skip=0;
  166652. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166653. if (!(png_ptr->chunk_name[0] & 0x20))
  166654. {
  166655. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166656. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166657. PNG_HANDLE_CHUNK_ALWAYS
  166658. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166659. && png_ptr->read_user_chunk_fn == NULL
  166660. #endif
  166661. )
  166662. #endif
  166663. png_chunk_error(png_ptr, "unknown critical chunk");
  166664. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166665. }
  166666. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166667. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166668. {
  166669. #ifdef PNG_MAX_MALLOC_64K
  166670. if (length > (png_uint_32)65535L)
  166671. {
  166672. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166673. skip = length - (png_uint_32)65535L;
  166674. length = (png_uint_32)65535L;
  166675. }
  166676. #endif
  166677. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166678. (png_charp)png_ptr->chunk_name, 5);
  166679. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166680. png_ptr->unknown_chunk.size = (png_size_t)length;
  166681. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166682. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166683. if(png_ptr->read_user_chunk_fn != NULL)
  166684. {
  166685. int ret;
  166686. ret = (*(png_ptr->read_user_chunk_fn))
  166687. (png_ptr, &png_ptr->unknown_chunk);
  166688. if (ret < 0)
  166689. png_chunk_error(png_ptr, "error in user chunk");
  166690. if (ret == 0)
  166691. {
  166692. if (!(png_ptr->chunk_name[0] & 0x20))
  166693. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166694. PNG_HANDLE_CHUNK_ALWAYS)
  166695. png_chunk_error(png_ptr, "unknown critical chunk");
  166696. png_set_unknown_chunks(png_ptr, info_ptr,
  166697. &png_ptr->unknown_chunk, 1);
  166698. }
  166699. }
  166700. #else
  166701. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166702. #endif
  166703. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166704. png_ptr->unknown_chunk.data = NULL;
  166705. }
  166706. else
  166707. #endif
  166708. skip=length;
  166709. png_push_crc_skip(png_ptr, skip);
  166710. }
  166711. void /* PRIVATE */
  166712. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166713. {
  166714. if (png_ptr->info_fn != NULL)
  166715. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166716. }
  166717. void /* PRIVATE */
  166718. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166719. {
  166720. if (png_ptr->end_fn != NULL)
  166721. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166722. }
  166723. void /* PRIVATE */
  166724. png_push_have_row(png_structp png_ptr, png_bytep row)
  166725. {
  166726. if (png_ptr->row_fn != NULL)
  166727. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166728. (int)png_ptr->pass);
  166729. }
  166730. void PNGAPI
  166731. png_progressive_combine_row (png_structp png_ptr,
  166732. png_bytep old_row, png_bytep new_row)
  166733. {
  166734. #ifdef PNG_USE_LOCAL_ARRAYS
  166735. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166736. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166737. #endif
  166738. if(png_ptr == NULL) return;
  166739. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166740. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166741. }
  166742. void PNGAPI
  166743. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166744. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166745. png_progressive_end_ptr end_fn)
  166746. {
  166747. if(png_ptr == NULL) return;
  166748. png_ptr->info_fn = info_fn;
  166749. png_ptr->row_fn = row_fn;
  166750. png_ptr->end_fn = end_fn;
  166751. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166752. }
  166753. png_voidp PNGAPI
  166754. png_get_progressive_ptr(png_structp png_ptr)
  166755. {
  166756. if(png_ptr == NULL) return (NULL);
  166757. return png_ptr->io_ptr;
  166758. }
  166759. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166760. /*** End of inlined file: pngpread.c ***/
  166761. /*** Start of inlined file: pngrio.c ***/
  166762. #define PNG_INTERNAL
  166763. #if defined(PNG_READ_SUPPORTED)
  166764. void /* PRIVATE */
  166765. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166766. {
  166767. png_debug1(4,"reading %d bytes\n", (int)length);
  166768. if (png_ptr->read_data_fn != NULL)
  166769. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166770. else
  166771. png_error(png_ptr, "Call to NULL read function");
  166772. }
  166773. #if !defined(PNG_NO_STDIO)
  166774. #ifndef USE_FAR_KEYWORD
  166775. void PNGAPI
  166776. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166777. {
  166778. png_size_t check;
  166779. if(png_ptr == NULL) return;
  166780. #if defined(_WIN32_WCE)
  166781. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166782. check = 0;
  166783. #else
  166784. check = (png_size_t)fread(data, (png_size_t)1, length,
  166785. (png_FILE_p)png_ptr->io_ptr);
  166786. #endif
  166787. if (check != length)
  166788. png_error(png_ptr, "Read Error");
  166789. }
  166790. #else
  166791. #define NEAR_BUF_SIZE 1024
  166792. #define MIN(a,b) (a <= b ? a : b)
  166793. static void PNGAPI
  166794. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166795. {
  166796. int check;
  166797. png_byte *n_data;
  166798. png_FILE_p io_ptr;
  166799. if(png_ptr == NULL) return;
  166800. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166801. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166802. if ((png_bytep)n_data == data)
  166803. {
  166804. #if defined(_WIN32_WCE)
  166805. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166806. check = 0;
  166807. #else
  166808. check = fread(n_data, 1, length, io_ptr);
  166809. #endif
  166810. }
  166811. else
  166812. {
  166813. png_byte buf[NEAR_BUF_SIZE];
  166814. png_size_t read, remaining, err;
  166815. check = 0;
  166816. remaining = length;
  166817. do
  166818. {
  166819. read = MIN(NEAR_BUF_SIZE, remaining);
  166820. #if defined(_WIN32_WCE)
  166821. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166822. err = 0;
  166823. #else
  166824. err = fread(buf, (png_size_t)1, read, io_ptr);
  166825. #endif
  166826. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166827. if(err != read)
  166828. break;
  166829. else
  166830. check += err;
  166831. data += read;
  166832. remaining -= read;
  166833. }
  166834. while (remaining != 0);
  166835. }
  166836. if ((png_uint_32)check != (png_uint_32)length)
  166837. png_error(png_ptr, "read Error");
  166838. }
  166839. #endif
  166840. #endif
  166841. void PNGAPI
  166842. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166843. png_rw_ptr read_data_fn)
  166844. {
  166845. if(png_ptr == NULL) return;
  166846. png_ptr->io_ptr = io_ptr;
  166847. #if !defined(PNG_NO_STDIO)
  166848. if (read_data_fn != NULL)
  166849. png_ptr->read_data_fn = read_data_fn;
  166850. else
  166851. png_ptr->read_data_fn = png_default_read_data;
  166852. #else
  166853. png_ptr->read_data_fn = read_data_fn;
  166854. #endif
  166855. if (png_ptr->write_data_fn != NULL)
  166856. {
  166857. png_ptr->write_data_fn = NULL;
  166858. png_warning(png_ptr,
  166859. "It's an error to set both read_data_fn and write_data_fn in the ");
  166860. png_warning(png_ptr,
  166861. "same structure. Resetting write_data_fn to NULL.");
  166862. }
  166863. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166864. png_ptr->output_flush_fn = NULL;
  166865. #endif
  166866. }
  166867. #endif /* PNG_READ_SUPPORTED */
  166868. /*** End of inlined file: pngrio.c ***/
  166869. /*** Start of inlined file: pngrtran.c ***/
  166870. #define PNG_INTERNAL
  166871. #if defined(PNG_READ_SUPPORTED)
  166872. void PNGAPI
  166873. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166874. {
  166875. png_debug(1, "in png_set_crc_action\n");
  166876. if(png_ptr == NULL) return;
  166877. switch (crit_action)
  166878. {
  166879. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166880. break;
  166881. case PNG_CRC_WARN_USE: /* warn/use data */
  166882. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166883. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166884. break;
  166885. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166886. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166887. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166888. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166889. break;
  166890. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166891. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166892. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166893. case PNG_CRC_DEFAULT:
  166894. default:
  166895. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166896. break;
  166897. }
  166898. switch (ancil_action)
  166899. {
  166900. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166901. break;
  166902. case PNG_CRC_WARN_USE: /* warn/use data */
  166903. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166904. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166905. break;
  166906. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166907. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166908. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166909. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166910. break;
  166911. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166912. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166913. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166914. break;
  166915. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166916. case PNG_CRC_DEFAULT:
  166917. default:
  166918. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166919. break;
  166920. }
  166921. }
  166922. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  166923. defined(PNG_FLOATING_POINT_SUPPORTED)
  166924. void PNGAPI
  166925. png_set_background(png_structp png_ptr,
  166926. png_color_16p background_color, int background_gamma_code,
  166927. int need_expand, double background_gamma)
  166928. {
  166929. png_debug(1, "in png_set_background\n");
  166930. if(png_ptr == NULL) return;
  166931. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  166932. {
  166933. png_warning(png_ptr, "Application must supply a known background gamma");
  166934. return;
  166935. }
  166936. png_ptr->transformations |= PNG_BACKGROUND;
  166937. png_memcpy(&(png_ptr->background), background_color,
  166938. png_sizeof(png_color_16));
  166939. png_ptr->background_gamma = (float)background_gamma;
  166940. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  166941. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  166942. }
  166943. #endif
  166944. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166945. void PNGAPI
  166946. png_set_strip_16(png_structp png_ptr)
  166947. {
  166948. png_debug(1, "in png_set_strip_16\n");
  166949. if(png_ptr == NULL) return;
  166950. png_ptr->transformations |= PNG_16_TO_8;
  166951. }
  166952. #endif
  166953. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166954. void PNGAPI
  166955. png_set_strip_alpha(png_structp png_ptr)
  166956. {
  166957. png_debug(1, "in png_set_strip_alpha\n");
  166958. if(png_ptr == NULL) return;
  166959. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  166960. }
  166961. #endif
  166962. #if defined(PNG_READ_DITHER_SUPPORTED)
  166963. typedef struct png_dsort_struct
  166964. {
  166965. struct png_dsort_struct FAR * next;
  166966. png_byte left;
  166967. png_byte right;
  166968. } png_dsort;
  166969. typedef png_dsort FAR * png_dsortp;
  166970. typedef png_dsort FAR * FAR * png_dsortpp;
  166971. void PNGAPI
  166972. png_set_dither(png_structp png_ptr, png_colorp palette,
  166973. int num_palette, int maximum_colors, png_uint_16p histogram,
  166974. int full_dither)
  166975. {
  166976. png_debug(1, "in png_set_dither\n");
  166977. if(png_ptr == NULL) return;
  166978. png_ptr->transformations |= PNG_DITHER;
  166979. if (!full_dither)
  166980. {
  166981. int i;
  166982. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  166983. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166984. for (i = 0; i < num_palette; i++)
  166985. png_ptr->dither_index[i] = (png_byte)i;
  166986. }
  166987. if (num_palette > maximum_colors)
  166988. {
  166989. if (histogram != NULL)
  166990. {
  166991. int i;
  166992. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  166993. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166994. for (i = 0; i < num_palette; i++)
  166995. png_ptr->dither_sort[i] = (png_byte)i;
  166996. for (i = num_palette - 1; i >= maximum_colors; i--)
  166997. {
  166998. int done; /* to stop early if the list is pre-sorted */
  166999. int j;
  167000. done = 1;
  167001. for (j = 0; j < i; j++)
  167002. {
  167003. if (histogram[png_ptr->dither_sort[j]]
  167004. < histogram[png_ptr->dither_sort[j + 1]])
  167005. {
  167006. png_byte t;
  167007. t = png_ptr->dither_sort[j];
  167008. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167009. png_ptr->dither_sort[j + 1] = t;
  167010. done = 0;
  167011. }
  167012. }
  167013. if (done)
  167014. break;
  167015. }
  167016. if (full_dither)
  167017. {
  167018. int j = num_palette;
  167019. for (i = 0; i < maximum_colors; i++)
  167020. {
  167021. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167022. {
  167023. do
  167024. j--;
  167025. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167026. palette[i] = palette[j];
  167027. }
  167028. }
  167029. }
  167030. else
  167031. {
  167032. int j = num_palette;
  167033. for (i = 0; i < maximum_colors; i++)
  167034. {
  167035. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167036. {
  167037. png_color tmp_color;
  167038. do
  167039. j--;
  167040. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167041. tmp_color = palette[j];
  167042. palette[j] = palette[i];
  167043. palette[i] = tmp_color;
  167044. png_ptr->dither_index[j] = (png_byte)i;
  167045. png_ptr->dither_index[i] = (png_byte)j;
  167046. }
  167047. }
  167048. for (i = 0; i < num_palette; i++)
  167049. {
  167050. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167051. {
  167052. int min_d, k, min_k, d_index;
  167053. d_index = png_ptr->dither_index[i];
  167054. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167055. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167056. {
  167057. int d;
  167058. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167059. if (d < min_d)
  167060. {
  167061. min_d = d;
  167062. min_k = k;
  167063. }
  167064. }
  167065. png_ptr->dither_index[i] = (png_byte)min_k;
  167066. }
  167067. }
  167068. }
  167069. png_free(png_ptr, png_ptr->dither_sort);
  167070. png_ptr->dither_sort=NULL;
  167071. }
  167072. else
  167073. {
  167074. int i;
  167075. int max_d;
  167076. int num_new_palette;
  167077. png_dsortp t;
  167078. png_dsortpp hash;
  167079. t=NULL;
  167080. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167081. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167082. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167083. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167084. for (i = 0; i < num_palette; i++)
  167085. {
  167086. png_ptr->index_to_palette[i] = (png_byte)i;
  167087. png_ptr->palette_to_index[i] = (png_byte)i;
  167088. }
  167089. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167090. png_sizeof (png_dsortp)));
  167091. for (i = 0; i < 769; i++)
  167092. hash[i] = NULL;
  167093. num_new_palette = num_palette;
  167094. max_d = 96;
  167095. while (num_new_palette > maximum_colors)
  167096. {
  167097. for (i = 0; i < num_new_palette - 1; i++)
  167098. {
  167099. int j;
  167100. for (j = i + 1; j < num_new_palette; j++)
  167101. {
  167102. int d;
  167103. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167104. if (d <= max_d)
  167105. {
  167106. t = (png_dsortp)png_malloc_warn(png_ptr,
  167107. (png_uint_32)(png_sizeof(png_dsort)));
  167108. if (t == NULL)
  167109. break;
  167110. t->next = hash[d];
  167111. t->left = (png_byte)i;
  167112. t->right = (png_byte)j;
  167113. hash[d] = t;
  167114. }
  167115. }
  167116. if (t == NULL)
  167117. break;
  167118. }
  167119. if (t != NULL)
  167120. for (i = 0; i <= max_d; i++)
  167121. {
  167122. if (hash[i] != NULL)
  167123. {
  167124. png_dsortp p;
  167125. for (p = hash[i]; p; p = p->next)
  167126. {
  167127. if ((int)png_ptr->index_to_palette[p->left]
  167128. < num_new_palette &&
  167129. (int)png_ptr->index_to_palette[p->right]
  167130. < num_new_palette)
  167131. {
  167132. int j, next_j;
  167133. if (num_new_palette & 0x01)
  167134. {
  167135. j = p->left;
  167136. next_j = p->right;
  167137. }
  167138. else
  167139. {
  167140. j = p->right;
  167141. next_j = p->left;
  167142. }
  167143. num_new_palette--;
  167144. palette[png_ptr->index_to_palette[j]]
  167145. = palette[num_new_palette];
  167146. if (!full_dither)
  167147. {
  167148. int k;
  167149. for (k = 0; k < num_palette; k++)
  167150. {
  167151. if (png_ptr->dither_index[k] ==
  167152. png_ptr->index_to_palette[j])
  167153. png_ptr->dither_index[k] =
  167154. png_ptr->index_to_palette[next_j];
  167155. if ((int)png_ptr->dither_index[k] ==
  167156. num_new_palette)
  167157. png_ptr->dither_index[k] =
  167158. png_ptr->index_to_palette[j];
  167159. }
  167160. }
  167161. png_ptr->index_to_palette[png_ptr->palette_to_index
  167162. [num_new_palette]] = png_ptr->index_to_palette[j];
  167163. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167164. = png_ptr->palette_to_index[num_new_palette];
  167165. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167166. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167167. }
  167168. if (num_new_palette <= maximum_colors)
  167169. break;
  167170. }
  167171. if (num_new_palette <= maximum_colors)
  167172. break;
  167173. }
  167174. }
  167175. for (i = 0; i < 769; i++)
  167176. {
  167177. if (hash[i] != NULL)
  167178. {
  167179. png_dsortp p = hash[i];
  167180. while (p)
  167181. {
  167182. t = p->next;
  167183. png_free(png_ptr, p);
  167184. p = t;
  167185. }
  167186. }
  167187. hash[i] = 0;
  167188. }
  167189. max_d += 96;
  167190. }
  167191. png_free(png_ptr, hash);
  167192. png_free(png_ptr, png_ptr->palette_to_index);
  167193. png_free(png_ptr, png_ptr->index_to_palette);
  167194. png_ptr->palette_to_index=NULL;
  167195. png_ptr->index_to_palette=NULL;
  167196. }
  167197. num_palette = maximum_colors;
  167198. }
  167199. if (png_ptr->palette == NULL)
  167200. {
  167201. png_ptr->palette = palette;
  167202. }
  167203. png_ptr->num_palette = (png_uint_16)num_palette;
  167204. if (full_dither)
  167205. {
  167206. int i;
  167207. png_bytep distance;
  167208. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167209. PNG_DITHER_BLUE_BITS;
  167210. int num_red = (1 << PNG_DITHER_RED_BITS);
  167211. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167212. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167213. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167214. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167215. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167216. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167217. png_sizeof (png_byte));
  167218. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167219. png_sizeof(png_byte)));
  167220. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167221. for (i = 0; i < num_palette; i++)
  167222. {
  167223. int ir, ig, ib;
  167224. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167225. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167226. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167227. for (ir = 0; ir < num_red; ir++)
  167228. {
  167229. int dr = ((ir > r) ? ir - r : r - ir);
  167230. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167231. for (ig = 0; ig < num_green; ig++)
  167232. {
  167233. int dg = ((ig > g) ? ig - g : g - ig);
  167234. int dt = dr + dg;
  167235. int dm = ((dr > dg) ? dr : dg);
  167236. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167237. for (ib = 0; ib < num_blue; ib++)
  167238. {
  167239. int d_index = index_g | ib;
  167240. int db = ((ib > b) ? ib - b : b - ib);
  167241. int dmax = ((dm > db) ? dm : db);
  167242. int d = dmax + dt + db;
  167243. if (d < (int)distance[d_index])
  167244. {
  167245. distance[d_index] = (png_byte)d;
  167246. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167247. }
  167248. }
  167249. }
  167250. }
  167251. }
  167252. png_free(png_ptr, distance);
  167253. }
  167254. }
  167255. #endif
  167256. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167257. void PNGAPI
  167258. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167259. {
  167260. png_debug(1, "in png_set_gamma\n");
  167261. if(png_ptr == NULL) return;
  167262. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167263. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167264. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167265. png_ptr->transformations |= PNG_GAMMA;
  167266. png_ptr->gamma = (float)file_gamma;
  167267. png_ptr->screen_gamma = (float)scrn_gamma;
  167268. }
  167269. #endif
  167270. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167271. void PNGAPI
  167272. png_set_expand(png_structp png_ptr)
  167273. {
  167274. png_debug(1, "in png_set_expand\n");
  167275. if(png_ptr == NULL) return;
  167276. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167277. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167278. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167279. #endif
  167280. }
  167281. void PNGAPI
  167282. png_set_palette_to_rgb(png_structp png_ptr)
  167283. {
  167284. png_debug(1, "in png_set_palette_to_rgb\n");
  167285. if(png_ptr == NULL) return;
  167286. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167287. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167288. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167289. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167290. #endif
  167291. }
  167292. #if !defined(PNG_1_0_X)
  167293. void PNGAPI
  167294. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167295. {
  167296. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167297. if(png_ptr == NULL) return;
  167298. png_ptr->transformations |= PNG_EXPAND;
  167299. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167300. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167301. #endif
  167302. }
  167303. #endif
  167304. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167305. void PNGAPI
  167306. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167307. {
  167308. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167309. if(png_ptr == NULL) return;
  167310. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167311. }
  167312. #endif
  167313. void PNGAPI
  167314. png_set_tRNS_to_alpha(png_structp png_ptr)
  167315. {
  167316. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167317. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167318. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167319. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167320. #endif
  167321. }
  167322. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167323. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167324. void PNGAPI
  167325. png_set_gray_to_rgb(png_structp png_ptr)
  167326. {
  167327. png_debug(1, "in png_set_gray_to_rgb\n");
  167328. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167329. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167330. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167331. #endif
  167332. }
  167333. #endif
  167334. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167335. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167336. void PNGAPI
  167337. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167338. double green)
  167339. {
  167340. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167341. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167342. if(png_ptr == NULL) return;
  167343. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167344. }
  167345. #endif
  167346. void PNGAPI
  167347. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167348. png_fixed_point red, png_fixed_point green)
  167349. {
  167350. png_debug(1, "in png_set_rgb_to_gray\n");
  167351. if(png_ptr == NULL) return;
  167352. switch(error_action)
  167353. {
  167354. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167355. break;
  167356. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167357. break;
  167358. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167359. }
  167360. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167361. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167362. png_ptr->transformations |= PNG_EXPAND;
  167363. #else
  167364. {
  167365. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167366. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167367. }
  167368. #endif
  167369. {
  167370. png_uint_16 red_int, green_int;
  167371. if(red < 0 || green < 0)
  167372. {
  167373. red_int = 6968; /* .212671 * 32768 + .5 */
  167374. green_int = 23434; /* .715160 * 32768 + .5 */
  167375. }
  167376. else if(red + green < 100000L)
  167377. {
  167378. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167379. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167380. }
  167381. else
  167382. {
  167383. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167384. red_int = 6968;
  167385. green_int = 23434;
  167386. }
  167387. png_ptr->rgb_to_gray_red_coeff = red_int;
  167388. png_ptr->rgb_to_gray_green_coeff = green_int;
  167389. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167390. }
  167391. }
  167392. #endif
  167393. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167394. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167395. defined(PNG_LEGACY_SUPPORTED)
  167396. void PNGAPI
  167397. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167398. read_user_transform_fn)
  167399. {
  167400. png_debug(1, "in png_set_read_user_transform_fn\n");
  167401. if(png_ptr == NULL) return;
  167402. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167403. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167404. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167405. #endif
  167406. #ifdef PNG_LEGACY_SUPPORTED
  167407. if(read_user_transform_fn)
  167408. png_warning(png_ptr,
  167409. "This version of libpng does not support user transforms");
  167410. #endif
  167411. }
  167412. #endif
  167413. void /* PRIVATE */
  167414. png_init_read_transformations(png_structp png_ptr)
  167415. {
  167416. png_debug(1, "in png_init_read_transformations\n");
  167417. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167418. if(png_ptr != NULL)
  167419. #endif
  167420. {
  167421. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167422. || defined(PNG_READ_GAMMA_SUPPORTED)
  167423. int color_type = png_ptr->color_type;
  167424. #endif
  167425. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167426. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167427. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167428. !(color_type & PNG_COLOR_MASK_COLOR))
  167429. {
  167430. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167431. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167432. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167433. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167434. png_ptr->background.red == png_ptr->background.green &&
  167435. png_ptr->background.red == png_ptr->background.blue)
  167436. {
  167437. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167438. png_ptr->background.gray = png_ptr->background.red;
  167439. }
  167440. #endif
  167441. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167442. (png_ptr->transformations & PNG_EXPAND))
  167443. {
  167444. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167445. {
  167446. switch (png_ptr->bit_depth)
  167447. {
  167448. case 1:
  167449. png_ptr->background.gray *= (png_uint_16)0xff;
  167450. png_ptr->background.red = png_ptr->background.green
  167451. = png_ptr->background.blue = png_ptr->background.gray;
  167452. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167453. {
  167454. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167455. png_ptr->trans_values.red = png_ptr->trans_values.green
  167456. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167457. }
  167458. break;
  167459. case 2:
  167460. png_ptr->background.gray *= (png_uint_16)0x55;
  167461. png_ptr->background.red = png_ptr->background.green
  167462. = png_ptr->background.blue = png_ptr->background.gray;
  167463. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167464. {
  167465. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167466. png_ptr->trans_values.red = png_ptr->trans_values.green
  167467. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167468. }
  167469. break;
  167470. case 4:
  167471. png_ptr->background.gray *= (png_uint_16)0x11;
  167472. png_ptr->background.red = png_ptr->background.green
  167473. = png_ptr->background.blue = png_ptr->background.gray;
  167474. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167475. {
  167476. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167477. png_ptr->trans_values.red = png_ptr->trans_values.green
  167478. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167479. }
  167480. break;
  167481. case 8:
  167482. case 16:
  167483. png_ptr->background.red = png_ptr->background.green
  167484. = png_ptr->background.blue = png_ptr->background.gray;
  167485. break;
  167486. }
  167487. }
  167488. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167489. {
  167490. png_ptr->background.red =
  167491. png_ptr->palette[png_ptr->background.index].red;
  167492. png_ptr->background.green =
  167493. png_ptr->palette[png_ptr->background.index].green;
  167494. png_ptr->background.blue =
  167495. png_ptr->palette[png_ptr->background.index].blue;
  167496. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167497. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167498. {
  167499. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167500. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167501. #endif
  167502. {
  167503. int i,istop;
  167504. istop=(int)png_ptr->num_trans;
  167505. for (i=0; i<istop; i++)
  167506. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167507. }
  167508. }
  167509. #endif
  167510. }
  167511. }
  167512. #endif
  167513. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167514. png_ptr->background_1 = png_ptr->background;
  167515. #endif
  167516. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167517. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167518. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167519. < PNG_GAMMA_THRESHOLD))
  167520. {
  167521. int i,k;
  167522. k=0;
  167523. for (i=0; i<png_ptr->num_trans; i++)
  167524. {
  167525. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167526. k=1; /* partial transparency is present */
  167527. }
  167528. if (k == 0)
  167529. png_ptr->transformations &= (~PNG_GAMMA);
  167530. }
  167531. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167532. png_ptr->gamma != 0.0)
  167533. {
  167534. png_build_gamma_table(png_ptr);
  167535. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167536. if (png_ptr->transformations & PNG_BACKGROUND)
  167537. {
  167538. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167539. {
  167540. png_color back, back_1;
  167541. png_colorp palette = png_ptr->palette;
  167542. int num_palette = png_ptr->num_palette;
  167543. int i;
  167544. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167545. {
  167546. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167547. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167548. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167549. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167550. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167551. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167552. }
  167553. else
  167554. {
  167555. double g, gs;
  167556. switch (png_ptr->background_gamma_type)
  167557. {
  167558. case PNG_BACKGROUND_GAMMA_SCREEN:
  167559. g = (png_ptr->screen_gamma);
  167560. gs = 1.0;
  167561. break;
  167562. case PNG_BACKGROUND_GAMMA_FILE:
  167563. g = 1.0 / (png_ptr->gamma);
  167564. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167565. break;
  167566. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167567. g = 1.0 / (png_ptr->background_gamma);
  167568. gs = 1.0 / (png_ptr->background_gamma *
  167569. png_ptr->screen_gamma);
  167570. break;
  167571. default:
  167572. g = 1.0; /* back_1 */
  167573. gs = 1.0; /* back */
  167574. }
  167575. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167576. {
  167577. back.red = (png_byte)png_ptr->background.red;
  167578. back.green = (png_byte)png_ptr->background.green;
  167579. back.blue = (png_byte)png_ptr->background.blue;
  167580. }
  167581. else
  167582. {
  167583. back.red = (png_byte)(pow(
  167584. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167585. back.green = (png_byte)(pow(
  167586. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167587. back.blue = (png_byte)(pow(
  167588. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167589. }
  167590. back_1.red = (png_byte)(pow(
  167591. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167592. back_1.green = (png_byte)(pow(
  167593. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167594. back_1.blue = (png_byte)(pow(
  167595. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167596. }
  167597. for (i = 0; i < num_palette; i++)
  167598. {
  167599. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167600. {
  167601. if (png_ptr->trans[i] == 0)
  167602. {
  167603. palette[i] = back;
  167604. }
  167605. else /* if (png_ptr->trans[i] != 0xff) */
  167606. {
  167607. png_byte v, w;
  167608. v = png_ptr->gamma_to_1[palette[i].red];
  167609. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167610. palette[i].red = png_ptr->gamma_from_1[w];
  167611. v = png_ptr->gamma_to_1[palette[i].green];
  167612. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167613. palette[i].green = png_ptr->gamma_from_1[w];
  167614. v = png_ptr->gamma_to_1[palette[i].blue];
  167615. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167616. palette[i].blue = png_ptr->gamma_from_1[w];
  167617. }
  167618. }
  167619. else
  167620. {
  167621. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167622. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167623. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167624. }
  167625. }
  167626. }
  167627. else
  167628. {
  167629. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167630. double g = 1.0;
  167631. double gs = 1.0;
  167632. switch (png_ptr->background_gamma_type)
  167633. {
  167634. case PNG_BACKGROUND_GAMMA_SCREEN:
  167635. g = (png_ptr->screen_gamma);
  167636. gs = 1.0;
  167637. break;
  167638. case PNG_BACKGROUND_GAMMA_FILE:
  167639. g = 1.0 / (png_ptr->gamma);
  167640. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167641. break;
  167642. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167643. g = 1.0 / (png_ptr->background_gamma);
  167644. gs = 1.0 / (png_ptr->background_gamma *
  167645. png_ptr->screen_gamma);
  167646. break;
  167647. }
  167648. png_ptr->background_1.gray = (png_uint_16)(pow(
  167649. (double)png_ptr->background.gray / m, g) * m + .5);
  167650. png_ptr->background.gray = (png_uint_16)(pow(
  167651. (double)png_ptr->background.gray / m, gs) * m + .5);
  167652. if ((png_ptr->background.red != png_ptr->background.green) ||
  167653. (png_ptr->background.red != png_ptr->background.blue) ||
  167654. (png_ptr->background.red != png_ptr->background.gray))
  167655. {
  167656. png_ptr->background_1.red = (png_uint_16)(pow(
  167657. (double)png_ptr->background.red / m, g) * m + .5);
  167658. png_ptr->background_1.green = (png_uint_16)(pow(
  167659. (double)png_ptr->background.green / m, g) * m + .5);
  167660. png_ptr->background_1.blue = (png_uint_16)(pow(
  167661. (double)png_ptr->background.blue / m, g) * m + .5);
  167662. png_ptr->background.red = (png_uint_16)(pow(
  167663. (double)png_ptr->background.red / m, gs) * m + .5);
  167664. png_ptr->background.green = (png_uint_16)(pow(
  167665. (double)png_ptr->background.green / m, gs) * m + .5);
  167666. png_ptr->background.blue = (png_uint_16)(pow(
  167667. (double)png_ptr->background.blue / m, gs) * m + .5);
  167668. }
  167669. else
  167670. {
  167671. png_ptr->background_1.red = png_ptr->background_1.green
  167672. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167673. png_ptr->background.red = png_ptr->background.green
  167674. = png_ptr->background.blue = png_ptr->background.gray;
  167675. }
  167676. }
  167677. }
  167678. else
  167679. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167680. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167681. {
  167682. png_colorp palette = png_ptr->palette;
  167683. int num_palette = png_ptr->num_palette;
  167684. int i;
  167685. for (i = 0; i < num_palette; i++)
  167686. {
  167687. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167688. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167689. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167690. }
  167691. }
  167692. }
  167693. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167694. else
  167695. #endif
  167696. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167697. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167698. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167699. (color_type == PNG_COLOR_TYPE_PALETTE))
  167700. {
  167701. int i;
  167702. int istop = (int)png_ptr->num_trans;
  167703. png_color back;
  167704. png_colorp palette = png_ptr->palette;
  167705. back.red = (png_byte)png_ptr->background.red;
  167706. back.green = (png_byte)png_ptr->background.green;
  167707. back.blue = (png_byte)png_ptr->background.blue;
  167708. for (i = 0; i < istop; i++)
  167709. {
  167710. if (png_ptr->trans[i] == 0)
  167711. {
  167712. palette[i] = back;
  167713. }
  167714. else if (png_ptr->trans[i] != 0xff)
  167715. {
  167716. png_composite(palette[i].red, palette[i].red,
  167717. png_ptr->trans[i], back.red);
  167718. png_composite(palette[i].green, palette[i].green,
  167719. png_ptr->trans[i], back.green);
  167720. png_composite(palette[i].blue, palette[i].blue,
  167721. png_ptr->trans[i], back.blue);
  167722. }
  167723. }
  167724. }
  167725. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167726. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167727. if ((png_ptr->transformations & PNG_SHIFT) &&
  167728. (color_type == PNG_COLOR_TYPE_PALETTE))
  167729. {
  167730. png_uint_16 i;
  167731. png_uint_16 istop = png_ptr->num_palette;
  167732. int sr = 8 - png_ptr->sig_bit.red;
  167733. int sg = 8 - png_ptr->sig_bit.green;
  167734. int sb = 8 - png_ptr->sig_bit.blue;
  167735. if (sr < 0 || sr > 8)
  167736. sr = 0;
  167737. if (sg < 0 || sg > 8)
  167738. sg = 0;
  167739. if (sb < 0 || sb > 8)
  167740. sb = 0;
  167741. for (i = 0; i < istop; i++)
  167742. {
  167743. png_ptr->palette[i].red >>= sr;
  167744. png_ptr->palette[i].green >>= sg;
  167745. png_ptr->palette[i].blue >>= sb;
  167746. }
  167747. }
  167748. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167749. }
  167750. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167751. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167752. if(png_ptr)
  167753. return;
  167754. #endif
  167755. }
  167756. void /* PRIVATE */
  167757. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167758. {
  167759. png_debug(1, "in png_read_transform_info\n");
  167760. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167761. if (png_ptr->transformations & PNG_EXPAND)
  167762. {
  167763. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167764. {
  167765. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167766. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167767. else
  167768. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167769. info_ptr->bit_depth = 8;
  167770. info_ptr->num_trans = 0;
  167771. }
  167772. else
  167773. {
  167774. if (png_ptr->num_trans)
  167775. {
  167776. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167777. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167778. else
  167779. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167780. }
  167781. if (info_ptr->bit_depth < 8)
  167782. info_ptr->bit_depth = 8;
  167783. info_ptr->num_trans = 0;
  167784. }
  167785. }
  167786. #endif
  167787. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167788. if (png_ptr->transformations & PNG_BACKGROUND)
  167789. {
  167790. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167791. info_ptr->num_trans = 0;
  167792. info_ptr->background = png_ptr->background;
  167793. }
  167794. #endif
  167795. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167796. if (png_ptr->transformations & PNG_GAMMA)
  167797. {
  167798. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167799. info_ptr->gamma = png_ptr->gamma;
  167800. #endif
  167801. #ifdef PNG_FIXED_POINT_SUPPORTED
  167802. info_ptr->int_gamma = png_ptr->int_gamma;
  167803. #endif
  167804. }
  167805. #endif
  167806. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167807. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167808. info_ptr->bit_depth = 8;
  167809. #endif
  167810. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167811. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167812. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167813. #endif
  167814. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167815. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167816. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167817. #endif
  167818. #if defined(PNG_READ_DITHER_SUPPORTED)
  167819. if (png_ptr->transformations & PNG_DITHER)
  167820. {
  167821. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167822. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167823. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167824. {
  167825. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167826. }
  167827. }
  167828. #endif
  167829. #if defined(PNG_READ_PACK_SUPPORTED)
  167830. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167831. info_ptr->bit_depth = 8;
  167832. #endif
  167833. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167834. info_ptr->channels = 1;
  167835. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167836. info_ptr->channels = 3;
  167837. else
  167838. info_ptr->channels = 1;
  167839. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167840. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167841. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167842. #endif
  167843. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167844. info_ptr->channels++;
  167845. #if defined(PNG_READ_FILLER_SUPPORTED)
  167846. if ((png_ptr->transformations & PNG_FILLER) &&
  167847. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167848. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167849. {
  167850. info_ptr->channels++;
  167851. #if !defined(PNG_1_0_X)
  167852. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167853. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167854. #endif
  167855. }
  167856. #endif
  167857. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167858. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167859. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167860. {
  167861. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167862. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167863. if(info_ptr->channels < png_ptr->user_transform_channels)
  167864. info_ptr->channels = png_ptr->user_transform_channels;
  167865. }
  167866. #endif
  167867. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167868. info_ptr->bit_depth);
  167869. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167870. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167871. if(png_ptr)
  167872. return;
  167873. #endif
  167874. }
  167875. void /* PRIVATE */
  167876. png_do_read_transformations(png_structp png_ptr)
  167877. {
  167878. png_debug(1, "in png_do_read_transformations\n");
  167879. if (png_ptr->row_buf == NULL)
  167880. {
  167881. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167882. char msg[50];
  167883. png_snprintf2(msg, 50,
  167884. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167885. png_ptr->pass);
  167886. png_error(png_ptr, msg);
  167887. #else
  167888. png_error(png_ptr, "NULL row buffer");
  167889. #endif
  167890. }
  167891. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167892. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167893. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167894. png_error(png_ptr, "Uninitialized row");
  167895. #else
  167896. png_warning(png_ptr, "Uninitialized row");
  167897. #endif
  167898. #endif
  167899. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167900. if (png_ptr->transformations & PNG_EXPAND)
  167901. {
  167902. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167903. {
  167904. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167905. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167906. }
  167907. else
  167908. {
  167909. if (png_ptr->num_trans &&
  167910. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167911. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167912. &(png_ptr->trans_values));
  167913. else
  167914. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167915. NULL);
  167916. }
  167917. }
  167918. #endif
  167919. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167920. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167921. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167922. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  167923. #endif
  167924. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167925. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167926. {
  167927. int rgb_error =
  167928. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  167929. if(rgb_error)
  167930. {
  167931. png_ptr->rgb_to_gray_status=1;
  167932. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167933. PNG_RGB_TO_GRAY_WARN)
  167934. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167935. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167936. PNG_RGB_TO_GRAY_ERR)
  167937. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167938. }
  167939. }
  167940. #endif
  167941. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167942. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167943. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167944. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167945. #endif
  167946. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167947. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167948. ((png_ptr->num_trans != 0 ) ||
  167949. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  167950. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167951. &(png_ptr->trans_values), &(png_ptr->background)
  167952. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167953. , &(png_ptr->background_1),
  167954. png_ptr->gamma_table, png_ptr->gamma_from_1,
  167955. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  167956. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  167957. png_ptr->gamma_shift
  167958. #endif
  167959. );
  167960. #endif
  167961. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167962. if ((png_ptr->transformations & PNG_GAMMA) &&
  167963. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167964. !((png_ptr->transformations & PNG_BACKGROUND) &&
  167965. ((png_ptr->num_trans != 0) ||
  167966. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  167967. #endif
  167968. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  167969. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167970. png_ptr->gamma_table, png_ptr->gamma_16_table,
  167971. png_ptr->gamma_shift);
  167972. #endif
  167973. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167974. if (png_ptr->transformations & PNG_16_TO_8)
  167975. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167976. #endif
  167977. #if defined(PNG_READ_DITHER_SUPPORTED)
  167978. if (png_ptr->transformations & PNG_DITHER)
  167979. {
  167980. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  167981. png_ptr->palette_lookup, png_ptr->dither_index);
  167982. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  167983. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  167984. }
  167985. #endif
  167986. #if defined(PNG_READ_INVERT_SUPPORTED)
  167987. if (png_ptr->transformations & PNG_INVERT_MONO)
  167988. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167989. #endif
  167990. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167991. if (png_ptr->transformations & PNG_SHIFT)
  167992. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167993. &(png_ptr->shift));
  167994. #endif
  167995. #if defined(PNG_READ_PACK_SUPPORTED)
  167996. if (png_ptr->transformations & PNG_PACK)
  167997. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167998. #endif
  167999. #if defined(PNG_READ_BGR_SUPPORTED)
  168000. if (png_ptr->transformations & PNG_BGR)
  168001. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168002. #endif
  168003. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168004. if (png_ptr->transformations & PNG_PACKSWAP)
  168005. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168006. #endif
  168007. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168008. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168009. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168010. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168011. #endif
  168012. #if defined(PNG_READ_FILLER_SUPPORTED)
  168013. if (png_ptr->transformations & PNG_FILLER)
  168014. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168015. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168016. #endif
  168017. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168018. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168019. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168020. #endif
  168021. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168022. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168023. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168024. #endif
  168025. #if defined(PNG_READ_SWAP_SUPPORTED)
  168026. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168027. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168028. #endif
  168029. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168030. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168031. {
  168032. if(png_ptr->read_user_transform_fn != NULL)
  168033. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168034. (png_ptr, /* png_ptr */
  168035. &(png_ptr->row_info), /* row_info: */
  168036. png_ptr->row_buf + 1); /* start of pixel data for row */
  168037. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168038. if(png_ptr->user_transform_depth)
  168039. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168040. if(png_ptr->user_transform_channels)
  168041. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168042. #endif
  168043. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168044. png_ptr->row_info.channels);
  168045. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168046. png_ptr->row_info.width);
  168047. }
  168048. #endif
  168049. }
  168050. #if defined(PNG_READ_PACK_SUPPORTED)
  168051. void /* PRIVATE */
  168052. png_do_unpack(png_row_infop row_info, png_bytep row)
  168053. {
  168054. png_debug(1, "in png_do_unpack\n");
  168055. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168056. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168057. #else
  168058. if (row_info->bit_depth < 8)
  168059. #endif
  168060. {
  168061. png_uint_32 i;
  168062. png_uint_32 row_width=row_info->width;
  168063. switch (row_info->bit_depth)
  168064. {
  168065. case 1:
  168066. {
  168067. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168068. png_bytep dp = row + (png_size_t)row_width - 1;
  168069. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168070. for (i = 0; i < row_width; i++)
  168071. {
  168072. *dp = (png_byte)((*sp >> shift) & 0x01);
  168073. if (shift == 7)
  168074. {
  168075. shift = 0;
  168076. sp--;
  168077. }
  168078. else
  168079. shift++;
  168080. dp--;
  168081. }
  168082. break;
  168083. }
  168084. case 2:
  168085. {
  168086. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168087. png_bytep dp = row + (png_size_t)row_width - 1;
  168088. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168089. for (i = 0; i < row_width; i++)
  168090. {
  168091. *dp = (png_byte)((*sp >> shift) & 0x03);
  168092. if (shift == 6)
  168093. {
  168094. shift = 0;
  168095. sp--;
  168096. }
  168097. else
  168098. shift += 2;
  168099. dp--;
  168100. }
  168101. break;
  168102. }
  168103. case 4:
  168104. {
  168105. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168106. png_bytep dp = row + (png_size_t)row_width - 1;
  168107. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168108. for (i = 0; i < row_width; i++)
  168109. {
  168110. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168111. if (shift == 4)
  168112. {
  168113. shift = 0;
  168114. sp--;
  168115. }
  168116. else
  168117. shift = 4;
  168118. dp--;
  168119. }
  168120. break;
  168121. }
  168122. }
  168123. row_info->bit_depth = 8;
  168124. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168125. row_info->rowbytes = row_width * row_info->channels;
  168126. }
  168127. }
  168128. #endif
  168129. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168130. void /* PRIVATE */
  168131. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168132. {
  168133. png_debug(1, "in png_do_unshift\n");
  168134. if (
  168135. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168136. row != NULL && row_info != NULL && sig_bits != NULL &&
  168137. #endif
  168138. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168139. {
  168140. int shift[4];
  168141. int channels = 0;
  168142. int c;
  168143. png_uint_16 value = 0;
  168144. png_uint_32 row_width = row_info->width;
  168145. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168146. {
  168147. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168148. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168149. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168150. }
  168151. else
  168152. {
  168153. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168154. }
  168155. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168156. {
  168157. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168158. }
  168159. for (c = 0; c < channels; c++)
  168160. {
  168161. if (shift[c] <= 0)
  168162. shift[c] = 0;
  168163. else
  168164. value = 1;
  168165. }
  168166. if (!value)
  168167. return;
  168168. switch (row_info->bit_depth)
  168169. {
  168170. case 2:
  168171. {
  168172. png_bytep bp;
  168173. png_uint_32 i;
  168174. png_uint_32 istop = row_info->rowbytes;
  168175. for (bp = row, i = 0; i < istop; i++)
  168176. {
  168177. *bp >>= 1;
  168178. *bp++ &= 0x55;
  168179. }
  168180. break;
  168181. }
  168182. case 4:
  168183. {
  168184. png_bytep bp = row;
  168185. png_uint_32 i;
  168186. png_uint_32 istop = row_info->rowbytes;
  168187. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168188. (png_byte)((int)0xf >> shift[0]));
  168189. for (i = 0; i < istop; i++)
  168190. {
  168191. *bp >>= shift[0];
  168192. *bp++ &= mask;
  168193. }
  168194. break;
  168195. }
  168196. case 8:
  168197. {
  168198. png_bytep bp = row;
  168199. png_uint_32 i;
  168200. png_uint_32 istop = row_width * channels;
  168201. for (i = 0; i < istop; i++)
  168202. {
  168203. *bp++ >>= shift[i%channels];
  168204. }
  168205. break;
  168206. }
  168207. case 16:
  168208. {
  168209. png_bytep bp = row;
  168210. png_uint_32 i;
  168211. png_uint_32 istop = channels * row_width;
  168212. for (i = 0; i < istop; i++)
  168213. {
  168214. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168215. value >>= shift[i%channels];
  168216. *bp++ = (png_byte)(value >> 8);
  168217. *bp++ = (png_byte)(value & 0xff);
  168218. }
  168219. break;
  168220. }
  168221. }
  168222. }
  168223. }
  168224. #endif
  168225. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168226. void /* PRIVATE */
  168227. png_do_chop(png_row_infop row_info, png_bytep row)
  168228. {
  168229. png_debug(1, "in png_do_chop\n");
  168230. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168231. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168232. #else
  168233. if (row_info->bit_depth == 16)
  168234. #endif
  168235. {
  168236. png_bytep sp = row;
  168237. png_bytep dp = row;
  168238. png_uint_32 i;
  168239. png_uint_32 istop = row_info->width * row_info->channels;
  168240. for (i = 0; i<istop; i++, sp += 2, dp++)
  168241. {
  168242. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168243. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168244. #else
  168245. *dp = *sp;
  168246. #endif
  168247. }
  168248. row_info->bit_depth = 8;
  168249. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168250. row_info->rowbytes = row_info->width * row_info->channels;
  168251. }
  168252. }
  168253. #endif
  168254. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168255. void /* PRIVATE */
  168256. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168257. {
  168258. png_debug(1, "in png_do_read_swap_alpha\n");
  168259. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168260. if (row != NULL && row_info != NULL)
  168261. #endif
  168262. {
  168263. png_uint_32 row_width = row_info->width;
  168264. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168265. {
  168266. if (row_info->bit_depth == 8)
  168267. {
  168268. png_bytep sp = row + row_info->rowbytes;
  168269. png_bytep dp = sp;
  168270. png_byte save;
  168271. png_uint_32 i;
  168272. for (i = 0; i < row_width; i++)
  168273. {
  168274. save = *(--sp);
  168275. *(--dp) = *(--sp);
  168276. *(--dp) = *(--sp);
  168277. *(--dp) = *(--sp);
  168278. *(--dp) = save;
  168279. }
  168280. }
  168281. else
  168282. {
  168283. png_bytep sp = row + row_info->rowbytes;
  168284. png_bytep dp = sp;
  168285. png_byte save[2];
  168286. png_uint_32 i;
  168287. for (i = 0; i < row_width; i++)
  168288. {
  168289. save[0] = *(--sp);
  168290. save[1] = *(--sp);
  168291. *(--dp) = *(--sp);
  168292. *(--dp) = *(--sp);
  168293. *(--dp) = *(--sp);
  168294. *(--dp) = *(--sp);
  168295. *(--dp) = *(--sp);
  168296. *(--dp) = *(--sp);
  168297. *(--dp) = save[0];
  168298. *(--dp) = save[1];
  168299. }
  168300. }
  168301. }
  168302. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168303. {
  168304. if (row_info->bit_depth == 8)
  168305. {
  168306. png_bytep sp = row + row_info->rowbytes;
  168307. png_bytep dp = sp;
  168308. png_byte save;
  168309. png_uint_32 i;
  168310. for (i = 0; i < row_width; i++)
  168311. {
  168312. save = *(--sp);
  168313. *(--dp) = *(--sp);
  168314. *(--dp) = save;
  168315. }
  168316. }
  168317. else
  168318. {
  168319. png_bytep sp = row + row_info->rowbytes;
  168320. png_bytep dp = sp;
  168321. png_byte save[2];
  168322. png_uint_32 i;
  168323. for (i = 0; i < row_width; i++)
  168324. {
  168325. save[0] = *(--sp);
  168326. save[1] = *(--sp);
  168327. *(--dp) = *(--sp);
  168328. *(--dp) = *(--sp);
  168329. *(--dp) = save[0];
  168330. *(--dp) = save[1];
  168331. }
  168332. }
  168333. }
  168334. }
  168335. }
  168336. #endif
  168337. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168338. void /* PRIVATE */
  168339. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168340. {
  168341. png_debug(1, "in png_do_read_invert_alpha\n");
  168342. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168343. if (row != NULL && row_info != NULL)
  168344. #endif
  168345. {
  168346. png_uint_32 row_width = row_info->width;
  168347. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168348. {
  168349. if (row_info->bit_depth == 8)
  168350. {
  168351. png_bytep sp = row + row_info->rowbytes;
  168352. png_bytep dp = sp;
  168353. png_uint_32 i;
  168354. for (i = 0; i < row_width; i++)
  168355. {
  168356. *(--dp) = (png_byte)(255 - *(--sp));
  168357. sp-=3;
  168358. dp=sp;
  168359. }
  168360. }
  168361. else
  168362. {
  168363. png_bytep sp = row + row_info->rowbytes;
  168364. png_bytep dp = sp;
  168365. png_uint_32 i;
  168366. for (i = 0; i < row_width; i++)
  168367. {
  168368. *(--dp) = (png_byte)(255 - *(--sp));
  168369. *(--dp) = (png_byte)(255 - *(--sp));
  168370. sp-=6;
  168371. dp=sp;
  168372. }
  168373. }
  168374. }
  168375. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168376. {
  168377. if (row_info->bit_depth == 8)
  168378. {
  168379. png_bytep sp = row + row_info->rowbytes;
  168380. png_bytep dp = sp;
  168381. png_uint_32 i;
  168382. for (i = 0; i < row_width; i++)
  168383. {
  168384. *(--dp) = (png_byte)(255 - *(--sp));
  168385. *(--dp) = *(--sp);
  168386. }
  168387. }
  168388. else
  168389. {
  168390. png_bytep sp = row + row_info->rowbytes;
  168391. png_bytep dp = sp;
  168392. png_uint_32 i;
  168393. for (i = 0; i < row_width; i++)
  168394. {
  168395. *(--dp) = (png_byte)(255 - *(--sp));
  168396. *(--dp) = (png_byte)(255 - *(--sp));
  168397. sp-=2;
  168398. dp=sp;
  168399. }
  168400. }
  168401. }
  168402. }
  168403. }
  168404. #endif
  168405. #if defined(PNG_READ_FILLER_SUPPORTED)
  168406. void /* PRIVATE */
  168407. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168408. png_uint_32 filler, png_uint_32 flags)
  168409. {
  168410. png_uint_32 i;
  168411. png_uint_32 row_width = row_info->width;
  168412. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168413. png_byte lo_filler = (png_byte)(filler & 0xff);
  168414. png_debug(1, "in png_do_read_filler\n");
  168415. if (
  168416. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168417. row != NULL && row_info != NULL &&
  168418. #endif
  168419. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168420. {
  168421. if(row_info->bit_depth == 8)
  168422. {
  168423. if (flags & PNG_FLAG_FILLER_AFTER)
  168424. {
  168425. png_bytep sp = row + (png_size_t)row_width;
  168426. png_bytep dp = sp + (png_size_t)row_width;
  168427. for (i = 1; i < row_width; i++)
  168428. {
  168429. *(--dp) = lo_filler;
  168430. *(--dp) = *(--sp);
  168431. }
  168432. *(--dp) = lo_filler;
  168433. row_info->channels = 2;
  168434. row_info->pixel_depth = 16;
  168435. row_info->rowbytes = row_width * 2;
  168436. }
  168437. else
  168438. {
  168439. png_bytep sp = row + (png_size_t)row_width;
  168440. png_bytep dp = sp + (png_size_t)row_width;
  168441. for (i = 0; i < row_width; i++)
  168442. {
  168443. *(--dp) = *(--sp);
  168444. *(--dp) = lo_filler;
  168445. }
  168446. row_info->channels = 2;
  168447. row_info->pixel_depth = 16;
  168448. row_info->rowbytes = row_width * 2;
  168449. }
  168450. }
  168451. else if(row_info->bit_depth == 16)
  168452. {
  168453. if (flags & PNG_FLAG_FILLER_AFTER)
  168454. {
  168455. png_bytep sp = row + (png_size_t)row_width * 2;
  168456. png_bytep dp = sp + (png_size_t)row_width * 2;
  168457. for (i = 1; i < row_width; i++)
  168458. {
  168459. *(--dp) = hi_filler;
  168460. *(--dp) = lo_filler;
  168461. *(--dp) = *(--sp);
  168462. *(--dp) = *(--sp);
  168463. }
  168464. *(--dp) = hi_filler;
  168465. *(--dp) = lo_filler;
  168466. row_info->channels = 2;
  168467. row_info->pixel_depth = 32;
  168468. row_info->rowbytes = row_width * 4;
  168469. }
  168470. else
  168471. {
  168472. png_bytep sp = row + (png_size_t)row_width * 2;
  168473. png_bytep dp = sp + (png_size_t)row_width * 2;
  168474. for (i = 0; i < row_width; i++)
  168475. {
  168476. *(--dp) = *(--sp);
  168477. *(--dp) = *(--sp);
  168478. *(--dp) = hi_filler;
  168479. *(--dp) = lo_filler;
  168480. }
  168481. row_info->channels = 2;
  168482. row_info->pixel_depth = 32;
  168483. row_info->rowbytes = row_width * 4;
  168484. }
  168485. }
  168486. } /* COLOR_TYPE == GRAY */
  168487. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  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 * 3;
  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. *(--dp) = *(--sp);
  168500. *(--dp) = *(--sp);
  168501. }
  168502. *(--dp) = lo_filler;
  168503. row_info->channels = 4;
  168504. row_info->pixel_depth = 32;
  168505. row_info->rowbytes = row_width * 4;
  168506. }
  168507. else
  168508. {
  168509. png_bytep sp = row + (png_size_t)row_width * 3;
  168510. png_bytep dp = sp + (png_size_t)row_width;
  168511. for (i = 0; i < row_width; i++)
  168512. {
  168513. *(--dp) = *(--sp);
  168514. *(--dp) = *(--sp);
  168515. *(--dp) = *(--sp);
  168516. *(--dp) = lo_filler;
  168517. }
  168518. row_info->channels = 4;
  168519. row_info->pixel_depth = 32;
  168520. row_info->rowbytes = row_width * 4;
  168521. }
  168522. }
  168523. else if(row_info->bit_depth == 16)
  168524. {
  168525. if (flags & PNG_FLAG_FILLER_AFTER)
  168526. {
  168527. png_bytep sp = row + (png_size_t)row_width * 6;
  168528. png_bytep dp = sp + (png_size_t)row_width * 2;
  168529. for (i = 1; i < row_width; i++)
  168530. {
  168531. *(--dp) = hi_filler;
  168532. *(--dp) = lo_filler;
  168533. *(--dp) = *(--sp);
  168534. *(--dp) = *(--sp);
  168535. *(--dp) = *(--sp);
  168536. *(--dp) = *(--sp);
  168537. *(--dp) = *(--sp);
  168538. *(--dp) = *(--sp);
  168539. }
  168540. *(--dp) = hi_filler;
  168541. *(--dp) = lo_filler;
  168542. row_info->channels = 4;
  168543. row_info->pixel_depth = 64;
  168544. row_info->rowbytes = row_width * 8;
  168545. }
  168546. else
  168547. {
  168548. png_bytep sp = row + (png_size_t)row_width * 6;
  168549. png_bytep dp = sp + (png_size_t)row_width * 2;
  168550. for (i = 0; i < row_width; i++)
  168551. {
  168552. *(--dp) = *(--sp);
  168553. *(--dp) = *(--sp);
  168554. *(--dp) = *(--sp);
  168555. *(--dp) = *(--sp);
  168556. *(--dp) = *(--sp);
  168557. *(--dp) = *(--sp);
  168558. *(--dp) = hi_filler;
  168559. *(--dp) = lo_filler;
  168560. }
  168561. row_info->channels = 4;
  168562. row_info->pixel_depth = 64;
  168563. row_info->rowbytes = row_width * 8;
  168564. }
  168565. }
  168566. } /* COLOR_TYPE == RGB */
  168567. }
  168568. #endif
  168569. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168570. void /* PRIVATE */
  168571. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168572. {
  168573. png_uint_32 i;
  168574. png_uint_32 row_width = row_info->width;
  168575. png_debug(1, "in png_do_gray_to_rgb\n");
  168576. if (row_info->bit_depth >= 8 &&
  168577. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168578. row != NULL && row_info != NULL &&
  168579. #endif
  168580. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168581. {
  168582. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168583. {
  168584. if (row_info->bit_depth == 8)
  168585. {
  168586. png_bytep sp = row + (png_size_t)row_width - 1;
  168587. png_bytep dp = sp + (png_size_t)row_width * 2;
  168588. for (i = 0; i < row_width; i++)
  168589. {
  168590. *(dp--) = *sp;
  168591. *(dp--) = *sp;
  168592. *(dp--) = *(sp--);
  168593. }
  168594. }
  168595. else
  168596. {
  168597. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168598. png_bytep dp = sp + (png_size_t)row_width * 4;
  168599. for (i = 0; i < row_width; i++)
  168600. {
  168601. *(dp--) = *sp;
  168602. *(dp--) = *(sp - 1);
  168603. *(dp--) = *sp;
  168604. *(dp--) = *(sp - 1);
  168605. *(dp--) = *(sp--);
  168606. *(dp--) = *(sp--);
  168607. }
  168608. }
  168609. }
  168610. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168611. {
  168612. if (row_info->bit_depth == 8)
  168613. {
  168614. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168615. png_bytep dp = sp + (png_size_t)row_width * 2;
  168616. for (i = 0; i < row_width; i++)
  168617. {
  168618. *(dp--) = *(sp--);
  168619. *(dp--) = *sp;
  168620. *(dp--) = *sp;
  168621. *(dp--) = *(sp--);
  168622. }
  168623. }
  168624. else
  168625. {
  168626. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168627. png_bytep dp = sp + (png_size_t)row_width * 4;
  168628. for (i = 0; i < row_width; i++)
  168629. {
  168630. *(dp--) = *(sp--);
  168631. *(dp--) = *(sp--);
  168632. *(dp--) = *sp;
  168633. *(dp--) = *(sp - 1);
  168634. *(dp--) = *sp;
  168635. *(dp--) = *(sp - 1);
  168636. *(dp--) = *(sp--);
  168637. *(dp--) = *(sp--);
  168638. }
  168639. }
  168640. }
  168641. row_info->channels += (png_byte)2;
  168642. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168643. row_info->pixel_depth = (png_byte)(row_info->channels *
  168644. row_info->bit_depth);
  168645. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168646. }
  168647. }
  168648. #endif
  168649. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168650. int /* PRIVATE */
  168651. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168652. {
  168653. png_uint_32 i;
  168654. png_uint_32 row_width = row_info->width;
  168655. int rgb_error = 0;
  168656. png_debug(1, "in png_do_rgb_to_gray\n");
  168657. if (
  168658. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168659. row != NULL && row_info != NULL &&
  168660. #endif
  168661. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168662. {
  168663. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168664. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168665. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168666. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168667. {
  168668. if (row_info->bit_depth == 8)
  168669. {
  168670. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168671. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168672. {
  168673. png_bytep sp = row;
  168674. png_bytep dp = row;
  168675. for (i = 0; i < row_width; i++)
  168676. {
  168677. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168678. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168679. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168680. if(red != green || red != blue)
  168681. {
  168682. rgb_error |= 1;
  168683. *(dp++) = png_ptr->gamma_from_1[
  168684. (rc*red+gc*green+bc*blue)>>15];
  168685. }
  168686. else
  168687. *(dp++) = *(sp-1);
  168688. }
  168689. }
  168690. else
  168691. #endif
  168692. {
  168693. png_bytep sp = row;
  168694. png_bytep dp = row;
  168695. for (i = 0; i < row_width; i++)
  168696. {
  168697. png_byte red = *(sp++);
  168698. png_byte green = *(sp++);
  168699. png_byte blue = *(sp++);
  168700. if(red != green || red != blue)
  168701. {
  168702. rgb_error |= 1;
  168703. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168704. }
  168705. else
  168706. *(dp++) = *(sp-1);
  168707. }
  168708. }
  168709. }
  168710. else /* RGB bit_depth == 16 */
  168711. {
  168712. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168713. if (png_ptr->gamma_16_to_1 != NULL &&
  168714. png_ptr->gamma_16_from_1 != NULL)
  168715. {
  168716. png_bytep sp = row;
  168717. png_bytep dp = row;
  168718. for (i = 0; i < row_width; i++)
  168719. {
  168720. png_uint_16 red, green, blue, w;
  168721. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168722. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168723. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168724. if(red == green && red == blue)
  168725. w = red;
  168726. else
  168727. {
  168728. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168729. png_ptr->gamma_shift][red>>8];
  168730. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168731. png_ptr->gamma_shift][green>>8];
  168732. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168733. png_ptr->gamma_shift][blue>>8];
  168734. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168735. + bc*blue_1)>>15);
  168736. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168737. png_ptr->gamma_shift][gray16 >> 8];
  168738. rgb_error |= 1;
  168739. }
  168740. *(dp++) = (png_byte)((w>>8) & 0xff);
  168741. *(dp++) = (png_byte)(w & 0xff);
  168742. }
  168743. }
  168744. else
  168745. #endif
  168746. {
  168747. png_bytep sp = row;
  168748. png_bytep dp = row;
  168749. for (i = 0; i < row_width; i++)
  168750. {
  168751. png_uint_16 red, green, blue, gray16;
  168752. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168753. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168754. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168755. if(red != green || red != blue)
  168756. rgb_error |= 1;
  168757. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168758. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168759. *(dp++) = (png_byte)(gray16 & 0xff);
  168760. }
  168761. }
  168762. }
  168763. }
  168764. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168765. {
  168766. if (row_info->bit_depth == 8)
  168767. {
  168768. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168769. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168770. {
  168771. png_bytep sp = row;
  168772. png_bytep dp = row;
  168773. for (i = 0; i < row_width; i++)
  168774. {
  168775. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168776. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168777. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168778. if(red != green || red != blue)
  168779. rgb_error |= 1;
  168780. *(dp++) = png_ptr->gamma_from_1
  168781. [(rc*red + gc*green + bc*blue)>>15];
  168782. *(dp++) = *(sp++); /* alpha */
  168783. }
  168784. }
  168785. else
  168786. #endif
  168787. {
  168788. png_bytep sp = row;
  168789. png_bytep dp = row;
  168790. for (i = 0; i < row_width; i++)
  168791. {
  168792. png_byte red = *(sp++);
  168793. png_byte green = *(sp++);
  168794. png_byte blue = *(sp++);
  168795. if(red != green || red != blue)
  168796. rgb_error |= 1;
  168797. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168798. *(dp++) = *(sp++); /* alpha */
  168799. }
  168800. }
  168801. }
  168802. else /* RGBA bit_depth == 16 */
  168803. {
  168804. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168805. if (png_ptr->gamma_16_to_1 != NULL &&
  168806. png_ptr->gamma_16_from_1 != NULL)
  168807. {
  168808. png_bytep sp = row;
  168809. png_bytep dp = row;
  168810. for (i = 0; i < row_width; i++)
  168811. {
  168812. png_uint_16 red, green, blue, w;
  168813. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168814. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168815. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168816. if(red == green && red == blue)
  168817. w = red;
  168818. else
  168819. {
  168820. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168821. png_ptr->gamma_shift][red>>8];
  168822. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168823. png_ptr->gamma_shift][green>>8];
  168824. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168825. png_ptr->gamma_shift][blue>>8];
  168826. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168827. + gc * green_1 + bc * blue_1)>>15);
  168828. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168829. png_ptr->gamma_shift][gray16 >> 8];
  168830. rgb_error |= 1;
  168831. }
  168832. *(dp++) = (png_byte)((w>>8) & 0xff);
  168833. *(dp++) = (png_byte)(w & 0xff);
  168834. *(dp++) = *(sp++); /* alpha */
  168835. *(dp++) = *(sp++);
  168836. }
  168837. }
  168838. else
  168839. #endif
  168840. {
  168841. png_bytep sp = row;
  168842. png_bytep dp = row;
  168843. for (i = 0; i < row_width; i++)
  168844. {
  168845. png_uint_16 red, green, blue, gray16;
  168846. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168847. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168848. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168849. if(red != green || red != blue)
  168850. rgb_error |= 1;
  168851. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168852. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168853. *(dp++) = (png_byte)(gray16 & 0xff);
  168854. *(dp++) = *(sp++); /* alpha */
  168855. *(dp++) = *(sp++);
  168856. }
  168857. }
  168858. }
  168859. }
  168860. row_info->channels -= (png_byte)2;
  168861. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168862. row_info->pixel_depth = (png_byte)(row_info->channels *
  168863. row_info->bit_depth);
  168864. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168865. }
  168866. return rgb_error;
  168867. }
  168868. #endif
  168869. void PNGAPI
  168870. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168871. {
  168872. int num_palette;
  168873. int color_inc;
  168874. int i;
  168875. int v;
  168876. png_debug(1, "in png_do_build_grayscale_palette\n");
  168877. if (palette == NULL)
  168878. return;
  168879. switch (bit_depth)
  168880. {
  168881. case 1:
  168882. num_palette = 2;
  168883. color_inc = 0xff;
  168884. break;
  168885. case 2:
  168886. num_palette = 4;
  168887. color_inc = 0x55;
  168888. break;
  168889. case 4:
  168890. num_palette = 16;
  168891. color_inc = 0x11;
  168892. break;
  168893. case 8:
  168894. num_palette = 256;
  168895. color_inc = 1;
  168896. break;
  168897. default:
  168898. num_palette = 0;
  168899. color_inc = 0;
  168900. break;
  168901. }
  168902. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168903. {
  168904. palette[i].red = (png_byte)v;
  168905. palette[i].green = (png_byte)v;
  168906. palette[i].blue = (png_byte)v;
  168907. }
  168908. }
  168909. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168910. void /* PRIVATE */
  168911. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168912. int num_palette)
  168913. {
  168914. png_debug(1, "in png_correct_palette\n");
  168915. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168916. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168917. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  168918. {
  168919. png_color back, back_1;
  168920. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168921. {
  168922. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168923. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168924. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168925. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168926. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168927. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168928. }
  168929. else
  168930. {
  168931. double g;
  168932. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  168933. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  168934. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  168935. {
  168936. back.red = png_ptr->background.red;
  168937. back.green = png_ptr->background.green;
  168938. back.blue = png_ptr->background.blue;
  168939. }
  168940. else
  168941. {
  168942. back.red =
  168943. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168944. 255.0 + 0.5);
  168945. back.green =
  168946. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168947. 255.0 + 0.5);
  168948. back.blue =
  168949. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168950. 255.0 + 0.5);
  168951. }
  168952. g = 1.0 / png_ptr->background_gamma;
  168953. back_1.red =
  168954. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168955. 255.0 + 0.5);
  168956. back_1.green =
  168957. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168958. 255.0 + 0.5);
  168959. back_1.blue =
  168960. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168961. 255.0 + 0.5);
  168962. }
  168963. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168964. {
  168965. png_uint_32 i;
  168966. for (i = 0; i < (png_uint_32)num_palette; i++)
  168967. {
  168968. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  168969. {
  168970. palette[i] = back;
  168971. }
  168972. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168973. {
  168974. png_byte v, w;
  168975. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  168976. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168977. palette[i].red = png_ptr->gamma_from_1[w];
  168978. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  168979. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168980. palette[i].green = png_ptr->gamma_from_1[w];
  168981. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  168982. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168983. palette[i].blue = png_ptr->gamma_from_1[w];
  168984. }
  168985. else
  168986. {
  168987. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168988. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168989. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168990. }
  168991. }
  168992. }
  168993. else
  168994. {
  168995. int i;
  168996. for (i = 0; i < num_palette; i++)
  168997. {
  168998. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  168999. {
  169000. palette[i] = back;
  169001. }
  169002. else
  169003. {
  169004. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169005. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169006. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169007. }
  169008. }
  169009. }
  169010. }
  169011. else
  169012. #endif
  169013. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169014. if (png_ptr->transformations & PNG_GAMMA)
  169015. {
  169016. int i;
  169017. for (i = 0; i < num_palette; i++)
  169018. {
  169019. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169020. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169021. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169022. }
  169023. }
  169024. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169025. else
  169026. #endif
  169027. #endif
  169028. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169029. if (png_ptr->transformations & PNG_BACKGROUND)
  169030. {
  169031. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169032. {
  169033. png_color back;
  169034. back.red = (png_byte)png_ptr->background.red;
  169035. back.green = (png_byte)png_ptr->background.green;
  169036. back.blue = (png_byte)png_ptr->background.blue;
  169037. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169038. {
  169039. if (png_ptr->trans[i] == 0)
  169040. {
  169041. palette[i].red = back.red;
  169042. palette[i].green = back.green;
  169043. palette[i].blue = back.blue;
  169044. }
  169045. else if (png_ptr->trans[i] != 0xff)
  169046. {
  169047. png_composite(palette[i].red, png_ptr->palette[i].red,
  169048. png_ptr->trans[i], back.red);
  169049. png_composite(palette[i].green, png_ptr->palette[i].green,
  169050. png_ptr->trans[i], back.green);
  169051. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169052. png_ptr->trans[i], back.blue);
  169053. }
  169054. }
  169055. }
  169056. else /* assume grayscale palette (what else could it be?) */
  169057. {
  169058. int i;
  169059. for (i = 0; i < num_palette; i++)
  169060. {
  169061. if (i == (png_byte)png_ptr->trans_values.gray)
  169062. {
  169063. palette[i].red = (png_byte)png_ptr->background.red;
  169064. palette[i].green = (png_byte)png_ptr->background.green;
  169065. palette[i].blue = (png_byte)png_ptr->background.blue;
  169066. }
  169067. }
  169068. }
  169069. }
  169070. #endif
  169071. }
  169072. #endif
  169073. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169074. void /* PRIVATE */
  169075. png_do_background(png_row_infop row_info, png_bytep row,
  169076. png_color_16p trans_values, png_color_16p background
  169077. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169078. , png_color_16p background_1,
  169079. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169080. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169081. png_uint_16pp gamma_16_to_1, int gamma_shift
  169082. #endif
  169083. )
  169084. {
  169085. png_bytep sp, dp;
  169086. png_uint_32 i;
  169087. png_uint_32 row_width=row_info->width;
  169088. int shift;
  169089. png_debug(1, "in png_do_background\n");
  169090. if (background != NULL &&
  169091. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169092. row != NULL && row_info != NULL &&
  169093. #endif
  169094. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169095. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169096. {
  169097. switch (row_info->color_type)
  169098. {
  169099. case PNG_COLOR_TYPE_GRAY:
  169100. {
  169101. switch (row_info->bit_depth)
  169102. {
  169103. case 1:
  169104. {
  169105. sp = row;
  169106. shift = 7;
  169107. for (i = 0; i < row_width; i++)
  169108. {
  169109. if ((png_uint_16)((*sp >> shift) & 0x01)
  169110. == trans_values->gray)
  169111. {
  169112. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169113. *sp |= (png_byte)(background->gray << shift);
  169114. }
  169115. if (!shift)
  169116. {
  169117. shift = 7;
  169118. sp++;
  169119. }
  169120. else
  169121. shift--;
  169122. }
  169123. break;
  169124. }
  169125. case 2:
  169126. {
  169127. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169128. if (gamma_table != NULL)
  169129. {
  169130. sp = row;
  169131. shift = 6;
  169132. for (i = 0; i < row_width; i++)
  169133. {
  169134. if ((png_uint_16)((*sp >> shift) & 0x03)
  169135. == trans_values->gray)
  169136. {
  169137. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169138. *sp |= (png_byte)(background->gray << shift);
  169139. }
  169140. else
  169141. {
  169142. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169143. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169144. (p << 4) | (p << 6)] >> 6) & 0x03);
  169145. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169146. *sp |= (png_byte)(g << shift);
  169147. }
  169148. if (!shift)
  169149. {
  169150. shift = 6;
  169151. sp++;
  169152. }
  169153. else
  169154. shift -= 2;
  169155. }
  169156. }
  169157. else
  169158. #endif
  169159. {
  169160. sp = row;
  169161. shift = 6;
  169162. for (i = 0; i < row_width; i++)
  169163. {
  169164. if ((png_uint_16)((*sp >> shift) & 0x03)
  169165. == trans_values->gray)
  169166. {
  169167. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169168. *sp |= (png_byte)(background->gray << shift);
  169169. }
  169170. if (!shift)
  169171. {
  169172. shift = 6;
  169173. sp++;
  169174. }
  169175. else
  169176. shift -= 2;
  169177. }
  169178. }
  169179. break;
  169180. }
  169181. case 4:
  169182. {
  169183. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169184. if (gamma_table != NULL)
  169185. {
  169186. sp = row;
  169187. shift = 4;
  169188. for (i = 0; i < row_width; i++)
  169189. {
  169190. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169191. == trans_values->gray)
  169192. {
  169193. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169194. *sp |= (png_byte)(background->gray << shift);
  169195. }
  169196. else
  169197. {
  169198. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169199. png_byte g = (png_byte)((gamma_table[p |
  169200. (p << 4)] >> 4) & 0x0f);
  169201. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169202. *sp |= (png_byte)(g << shift);
  169203. }
  169204. if (!shift)
  169205. {
  169206. shift = 4;
  169207. sp++;
  169208. }
  169209. else
  169210. shift -= 4;
  169211. }
  169212. }
  169213. else
  169214. #endif
  169215. {
  169216. sp = row;
  169217. shift = 4;
  169218. for (i = 0; i < row_width; i++)
  169219. {
  169220. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169221. == trans_values->gray)
  169222. {
  169223. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169224. *sp |= (png_byte)(background->gray << shift);
  169225. }
  169226. if (!shift)
  169227. {
  169228. shift = 4;
  169229. sp++;
  169230. }
  169231. else
  169232. shift -= 4;
  169233. }
  169234. }
  169235. break;
  169236. }
  169237. case 8:
  169238. {
  169239. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169240. if (gamma_table != NULL)
  169241. {
  169242. sp = row;
  169243. for (i = 0; i < row_width; i++, sp++)
  169244. {
  169245. if (*sp == trans_values->gray)
  169246. {
  169247. *sp = (png_byte)background->gray;
  169248. }
  169249. else
  169250. {
  169251. *sp = gamma_table[*sp];
  169252. }
  169253. }
  169254. }
  169255. else
  169256. #endif
  169257. {
  169258. sp = row;
  169259. for (i = 0; i < row_width; i++, sp++)
  169260. {
  169261. if (*sp == trans_values->gray)
  169262. {
  169263. *sp = (png_byte)background->gray;
  169264. }
  169265. }
  169266. }
  169267. break;
  169268. }
  169269. case 16:
  169270. {
  169271. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169272. if (gamma_16 != NULL)
  169273. {
  169274. sp = row;
  169275. for (i = 0; i < row_width; i++, sp += 2)
  169276. {
  169277. png_uint_16 v;
  169278. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169279. if (v == trans_values->gray)
  169280. {
  169281. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169282. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169283. }
  169284. else
  169285. {
  169286. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169287. *sp = (png_byte)((v >> 8) & 0xff);
  169288. *(sp + 1) = (png_byte)(v & 0xff);
  169289. }
  169290. }
  169291. }
  169292. else
  169293. #endif
  169294. {
  169295. sp = row;
  169296. for (i = 0; i < row_width; i++, sp += 2)
  169297. {
  169298. png_uint_16 v;
  169299. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169300. if (v == trans_values->gray)
  169301. {
  169302. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169303. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169304. }
  169305. }
  169306. }
  169307. break;
  169308. }
  169309. }
  169310. break;
  169311. }
  169312. case PNG_COLOR_TYPE_RGB:
  169313. {
  169314. if (row_info->bit_depth == 8)
  169315. {
  169316. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169317. if (gamma_table != NULL)
  169318. {
  169319. sp = row;
  169320. for (i = 0; i < row_width; i++, sp += 3)
  169321. {
  169322. if (*sp == trans_values->red &&
  169323. *(sp + 1) == trans_values->green &&
  169324. *(sp + 2) == trans_values->blue)
  169325. {
  169326. *sp = (png_byte)background->red;
  169327. *(sp + 1) = (png_byte)background->green;
  169328. *(sp + 2) = (png_byte)background->blue;
  169329. }
  169330. else
  169331. {
  169332. *sp = gamma_table[*sp];
  169333. *(sp + 1) = gamma_table[*(sp + 1)];
  169334. *(sp + 2) = gamma_table[*(sp + 2)];
  169335. }
  169336. }
  169337. }
  169338. else
  169339. #endif
  169340. {
  169341. sp = row;
  169342. for (i = 0; i < row_width; i++, sp += 3)
  169343. {
  169344. if (*sp == trans_values->red &&
  169345. *(sp + 1) == trans_values->green &&
  169346. *(sp + 2) == trans_values->blue)
  169347. {
  169348. *sp = (png_byte)background->red;
  169349. *(sp + 1) = (png_byte)background->green;
  169350. *(sp + 2) = (png_byte)background->blue;
  169351. }
  169352. }
  169353. }
  169354. }
  169355. else /* if (row_info->bit_depth == 16) */
  169356. {
  169357. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169358. if (gamma_16 != NULL)
  169359. {
  169360. sp = row;
  169361. for (i = 0; i < row_width; i++, sp += 6)
  169362. {
  169363. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169364. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169365. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169366. if (r == trans_values->red && g == trans_values->green &&
  169367. b == trans_values->blue)
  169368. {
  169369. *sp = (png_byte)((background->red >> 8) & 0xff);
  169370. *(sp + 1) = (png_byte)(background->red & 0xff);
  169371. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169372. *(sp + 3) = (png_byte)(background->green & 0xff);
  169373. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169374. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169375. }
  169376. else
  169377. {
  169378. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169379. *sp = (png_byte)((v >> 8) & 0xff);
  169380. *(sp + 1) = (png_byte)(v & 0xff);
  169381. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169382. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169383. *(sp + 3) = (png_byte)(v & 0xff);
  169384. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169385. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169386. *(sp + 5) = (png_byte)(v & 0xff);
  169387. }
  169388. }
  169389. }
  169390. else
  169391. #endif
  169392. {
  169393. sp = row;
  169394. for (i = 0; i < row_width; i++, sp += 6)
  169395. {
  169396. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169397. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169398. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169399. if (r == trans_values->red && g == trans_values->green &&
  169400. b == trans_values->blue)
  169401. {
  169402. *sp = (png_byte)((background->red >> 8) & 0xff);
  169403. *(sp + 1) = (png_byte)(background->red & 0xff);
  169404. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169405. *(sp + 3) = (png_byte)(background->green & 0xff);
  169406. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169407. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169408. }
  169409. }
  169410. }
  169411. }
  169412. break;
  169413. }
  169414. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169415. {
  169416. if (row_info->bit_depth == 8)
  169417. {
  169418. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169419. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169420. gamma_table != NULL)
  169421. {
  169422. sp = row;
  169423. dp = row;
  169424. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169425. {
  169426. png_uint_16 a = *(sp + 1);
  169427. if (a == 0xff)
  169428. {
  169429. *dp = gamma_table[*sp];
  169430. }
  169431. else if (a == 0)
  169432. {
  169433. *dp = (png_byte)background->gray;
  169434. }
  169435. else
  169436. {
  169437. png_byte v, w;
  169438. v = gamma_to_1[*sp];
  169439. png_composite(w, v, a, background_1->gray);
  169440. *dp = gamma_from_1[w];
  169441. }
  169442. }
  169443. }
  169444. else
  169445. #endif
  169446. {
  169447. sp = row;
  169448. dp = row;
  169449. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169450. {
  169451. png_byte a = *(sp + 1);
  169452. if (a == 0xff)
  169453. {
  169454. *dp = *sp;
  169455. }
  169456. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169457. else if (a == 0)
  169458. {
  169459. *dp = (png_byte)background->gray;
  169460. }
  169461. else
  169462. {
  169463. png_composite(*dp, *sp, a, background_1->gray);
  169464. }
  169465. #else
  169466. *dp = (png_byte)background->gray;
  169467. #endif
  169468. }
  169469. }
  169470. }
  169471. else /* if (png_ptr->bit_depth == 16) */
  169472. {
  169473. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169474. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169475. gamma_16_to_1 != NULL)
  169476. {
  169477. sp = row;
  169478. dp = row;
  169479. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169480. {
  169481. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169482. if (a == (png_uint_16)0xffff)
  169483. {
  169484. png_uint_16 v;
  169485. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169486. *dp = (png_byte)((v >> 8) & 0xff);
  169487. *(dp + 1) = (png_byte)(v & 0xff);
  169488. }
  169489. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169490. else if (a == 0)
  169491. #else
  169492. else
  169493. #endif
  169494. {
  169495. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169496. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169497. }
  169498. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169499. else
  169500. {
  169501. png_uint_16 g, v, w;
  169502. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169503. png_composite_16(v, g, a, background_1->gray);
  169504. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169505. *dp = (png_byte)((w >> 8) & 0xff);
  169506. *(dp + 1) = (png_byte)(w & 0xff);
  169507. }
  169508. #endif
  169509. }
  169510. }
  169511. else
  169512. #endif
  169513. {
  169514. sp = row;
  169515. dp = row;
  169516. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169517. {
  169518. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169519. if (a == (png_uint_16)0xffff)
  169520. {
  169521. png_memcpy(dp, sp, 2);
  169522. }
  169523. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169524. else if (a == 0)
  169525. #else
  169526. else
  169527. #endif
  169528. {
  169529. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169530. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169531. }
  169532. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169533. else
  169534. {
  169535. png_uint_16 g, v;
  169536. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169537. png_composite_16(v, g, a, background_1->gray);
  169538. *dp = (png_byte)((v >> 8) & 0xff);
  169539. *(dp + 1) = (png_byte)(v & 0xff);
  169540. }
  169541. #endif
  169542. }
  169543. }
  169544. }
  169545. break;
  169546. }
  169547. case PNG_COLOR_TYPE_RGB_ALPHA:
  169548. {
  169549. if (row_info->bit_depth == 8)
  169550. {
  169551. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169552. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169553. gamma_table != NULL)
  169554. {
  169555. sp = row;
  169556. dp = row;
  169557. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169558. {
  169559. png_byte a = *(sp + 3);
  169560. if (a == 0xff)
  169561. {
  169562. *dp = gamma_table[*sp];
  169563. *(dp + 1) = gamma_table[*(sp + 1)];
  169564. *(dp + 2) = gamma_table[*(sp + 2)];
  169565. }
  169566. else if (a == 0)
  169567. {
  169568. *dp = (png_byte)background->red;
  169569. *(dp + 1) = (png_byte)background->green;
  169570. *(dp + 2) = (png_byte)background->blue;
  169571. }
  169572. else
  169573. {
  169574. png_byte v, w;
  169575. v = gamma_to_1[*sp];
  169576. png_composite(w, v, a, background_1->red);
  169577. *dp = gamma_from_1[w];
  169578. v = gamma_to_1[*(sp + 1)];
  169579. png_composite(w, v, a, background_1->green);
  169580. *(dp + 1) = gamma_from_1[w];
  169581. v = gamma_to_1[*(sp + 2)];
  169582. png_composite(w, v, a, background_1->blue);
  169583. *(dp + 2) = gamma_from_1[w];
  169584. }
  169585. }
  169586. }
  169587. else
  169588. #endif
  169589. {
  169590. sp = row;
  169591. dp = row;
  169592. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169593. {
  169594. png_byte a = *(sp + 3);
  169595. if (a == 0xff)
  169596. {
  169597. *dp = *sp;
  169598. *(dp + 1) = *(sp + 1);
  169599. *(dp + 2) = *(sp + 2);
  169600. }
  169601. else if (a == 0)
  169602. {
  169603. *dp = (png_byte)background->red;
  169604. *(dp + 1) = (png_byte)background->green;
  169605. *(dp + 2) = (png_byte)background->blue;
  169606. }
  169607. else
  169608. {
  169609. png_composite(*dp, *sp, a, background->red);
  169610. png_composite(*(dp + 1), *(sp + 1), a,
  169611. background->green);
  169612. png_composite(*(dp + 2), *(sp + 2), a,
  169613. background->blue);
  169614. }
  169615. }
  169616. }
  169617. }
  169618. else /* if (row_info->bit_depth == 16) */
  169619. {
  169620. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169621. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169622. gamma_16_to_1 != NULL)
  169623. {
  169624. sp = row;
  169625. dp = row;
  169626. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169627. {
  169628. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169629. << 8) + (png_uint_16)(*(sp + 7)));
  169630. if (a == (png_uint_16)0xffff)
  169631. {
  169632. png_uint_16 v;
  169633. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169634. *dp = (png_byte)((v >> 8) & 0xff);
  169635. *(dp + 1) = (png_byte)(v & 0xff);
  169636. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169637. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169638. *(dp + 3) = (png_byte)(v & 0xff);
  169639. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169640. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169641. *(dp + 5) = (png_byte)(v & 0xff);
  169642. }
  169643. else if (a == 0)
  169644. {
  169645. *dp = (png_byte)((background->red >> 8) & 0xff);
  169646. *(dp + 1) = (png_byte)(background->red & 0xff);
  169647. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169648. *(dp + 3) = (png_byte)(background->green & 0xff);
  169649. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169650. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169651. }
  169652. else
  169653. {
  169654. png_uint_16 v, w, x;
  169655. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169656. png_composite_16(w, v, a, background_1->red);
  169657. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169658. *dp = (png_byte)((x >> 8) & 0xff);
  169659. *(dp + 1) = (png_byte)(x & 0xff);
  169660. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169661. png_composite_16(w, v, a, background_1->green);
  169662. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169663. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169664. *(dp + 3) = (png_byte)(x & 0xff);
  169665. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169666. png_composite_16(w, v, a, background_1->blue);
  169667. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169668. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169669. *(dp + 5) = (png_byte)(x & 0xff);
  169670. }
  169671. }
  169672. }
  169673. else
  169674. #endif
  169675. {
  169676. sp = row;
  169677. dp = row;
  169678. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169679. {
  169680. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169681. << 8) + (png_uint_16)(*(sp + 7)));
  169682. if (a == (png_uint_16)0xffff)
  169683. {
  169684. png_memcpy(dp, sp, 6);
  169685. }
  169686. else if (a == 0)
  169687. {
  169688. *dp = (png_byte)((background->red >> 8) & 0xff);
  169689. *(dp + 1) = (png_byte)(background->red & 0xff);
  169690. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169691. *(dp + 3) = (png_byte)(background->green & 0xff);
  169692. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169693. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169694. }
  169695. else
  169696. {
  169697. png_uint_16 v;
  169698. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169699. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169700. + *(sp + 3));
  169701. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169702. + *(sp + 5));
  169703. png_composite_16(v, r, a, background->red);
  169704. *dp = (png_byte)((v >> 8) & 0xff);
  169705. *(dp + 1) = (png_byte)(v & 0xff);
  169706. png_composite_16(v, g, a, background->green);
  169707. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169708. *(dp + 3) = (png_byte)(v & 0xff);
  169709. png_composite_16(v, b, a, background->blue);
  169710. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169711. *(dp + 5) = (png_byte)(v & 0xff);
  169712. }
  169713. }
  169714. }
  169715. }
  169716. break;
  169717. }
  169718. }
  169719. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169720. {
  169721. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169722. row_info->channels--;
  169723. row_info->pixel_depth = (png_byte)(row_info->channels *
  169724. row_info->bit_depth);
  169725. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169726. }
  169727. }
  169728. }
  169729. #endif
  169730. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169731. void /* PRIVATE */
  169732. png_do_gamma(png_row_infop row_info, png_bytep row,
  169733. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169734. int gamma_shift)
  169735. {
  169736. png_bytep sp;
  169737. png_uint_32 i;
  169738. png_uint_32 row_width=row_info->width;
  169739. png_debug(1, "in png_do_gamma\n");
  169740. if (
  169741. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169742. row != NULL && row_info != NULL &&
  169743. #endif
  169744. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169745. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169746. {
  169747. switch (row_info->color_type)
  169748. {
  169749. case PNG_COLOR_TYPE_RGB:
  169750. {
  169751. if (row_info->bit_depth == 8)
  169752. {
  169753. sp = row;
  169754. for (i = 0; i < row_width; i++)
  169755. {
  169756. *sp = gamma_table[*sp];
  169757. sp++;
  169758. *sp = gamma_table[*sp];
  169759. sp++;
  169760. *sp = gamma_table[*sp];
  169761. sp++;
  169762. }
  169763. }
  169764. else /* if (row_info->bit_depth == 16) */
  169765. {
  169766. sp = row;
  169767. for (i = 0; i < row_width; i++)
  169768. {
  169769. png_uint_16 v;
  169770. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169771. *sp = (png_byte)((v >> 8) & 0xff);
  169772. *(sp + 1) = (png_byte)(v & 0xff);
  169773. sp += 2;
  169774. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169775. *sp = (png_byte)((v >> 8) & 0xff);
  169776. *(sp + 1) = (png_byte)(v & 0xff);
  169777. sp += 2;
  169778. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169779. *sp = (png_byte)((v >> 8) & 0xff);
  169780. *(sp + 1) = (png_byte)(v & 0xff);
  169781. sp += 2;
  169782. }
  169783. }
  169784. break;
  169785. }
  169786. case PNG_COLOR_TYPE_RGB_ALPHA:
  169787. {
  169788. if (row_info->bit_depth == 8)
  169789. {
  169790. sp = row;
  169791. for (i = 0; i < row_width; i++)
  169792. {
  169793. *sp = gamma_table[*sp];
  169794. sp++;
  169795. *sp = gamma_table[*sp];
  169796. sp++;
  169797. *sp = gamma_table[*sp];
  169798. sp++;
  169799. sp++;
  169800. }
  169801. }
  169802. else /* if (row_info->bit_depth == 16) */
  169803. {
  169804. sp = row;
  169805. for (i = 0; i < row_width; i++)
  169806. {
  169807. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169808. *sp = (png_byte)((v >> 8) & 0xff);
  169809. *(sp + 1) = (png_byte)(v & 0xff);
  169810. sp += 2;
  169811. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169812. *sp = (png_byte)((v >> 8) & 0xff);
  169813. *(sp + 1) = (png_byte)(v & 0xff);
  169814. sp += 2;
  169815. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169816. *sp = (png_byte)((v >> 8) & 0xff);
  169817. *(sp + 1) = (png_byte)(v & 0xff);
  169818. sp += 4;
  169819. }
  169820. }
  169821. break;
  169822. }
  169823. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169824. {
  169825. if (row_info->bit_depth == 8)
  169826. {
  169827. sp = row;
  169828. for (i = 0; i < row_width; i++)
  169829. {
  169830. *sp = gamma_table[*sp];
  169831. sp += 2;
  169832. }
  169833. }
  169834. else /* if (row_info->bit_depth == 16) */
  169835. {
  169836. sp = row;
  169837. for (i = 0; i < row_width; i++)
  169838. {
  169839. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169840. *sp = (png_byte)((v >> 8) & 0xff);
  169841. *(sp + 1) = (png_byte)(v & 0xff);
  169842. sp += 4;
  169843. }
  169844. }
  169845. break;
  169846. }
  169847. case PNG_COLOR_TYPE_GRAY:
  169848. {
  169849. if (row_info->bit_depth == 2)
  169850. {
  169851. sp = row;
  169852. for (i = 0; i < row_width; i += 4)
  169853. {
  169854. int a = *sp & 0xc0;
  169855. int b = *sp & 0x30;
  169856. int c = *sp & 0x0c;
  169857. int d = *sp & 0x03;
  169858. *sp = (png_byte)(
  169859. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169860. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169861. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169862. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169863. sp++;
  169864. }
  169865. }
  169866. if (row_info->bit_depth == 4)
  169867. {
  169868. sp = row;
  169869. for (i = 0; i < row_width; i += 2)
  169870. {
  169871. int msb = *sp & 0xf0;
  169872. int lsb = *sp & 0x0f;
  169873. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169874. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169875. sp++;
  169876. }
  169877. }
  169878. else if (row_info->bit_depth == 8)
  169879. {
  169880. sp = row;
  169881. for (i = 0; i < row_width; i++)
  169882. {
  169883. *sp = gamma_table[*sp];
  169884. sp++;
  169885. }
  169886. }
  169887. else if (row_info->bit_depth == 16)
  169888. {
  169889. sp = row;
  169890. for (i = 0; i < row_width; i++)
  169891. {
  169892. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169893. *sp = (png_byte)((v >> 8) & 0xff);
  169894. *(sp + 1) = (png_byte)(v & 0xff);
  169895. sp += 2;
  169896. }
  169897. }
  169898. break;
  169899. }
  169900. }
  169901. }
  169902. }
  169903. #endif
  169904. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169905. void /* PRIVATE */
  169906. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169907. png_colorp palette, png_bytep trans, int num_trans)
  169908. {
  169909. int shift, value;
  169910. png_bytep sp, dp;
  169911. png_uint_32 i;
  169912. png_uint_32 row_width=row_info->width;
  169913. png_debug(1, "in png_do_expand_palette\n");
  169914. if (
  169915. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169916. row != NULL && row_info != NULL &&
  169917. #endif
  169918. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  169919. {
  169920. if (row_info->bit_depth < 8)
  169921. {
  169922. switch (row_info->bit_depth)
  169923. {
  169924. case 1:
  169925. {
  169926. sp = row + (png_size_t)((row_width - 1) >> 3);
  169927. dp = row + (png_size_t)row_width - 1;
  169928. shift = 7 - (int)((row_width + 7) & 0x07);
  169929. for (i = 0; i < row_width; i++)
  169930. {
  169931. if ((*sp >> shift) & 0x01)
  169932. *dp = 1;
  169933. else
  169934. *dp = 0;
  169935. if (shift == 7)
  169936. {
  169937. shift = 0;
  169938. sp--;
  169939. }
  169940. else
  169941. shift++;
  169942. dp--;
  169943. }
  169944. break;
  169945. }
  169946. case 2:
  169947. {
  169948. sp = row + (png_size_t)((row_width - 1) >> 2);
  169949. dp = row + (png_size_t)row_width - 1;
  169950. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169951. for (i = 0; i < row_width; i++)
  169952. {
  169953. value = (*sp >> shift) & 0x03;
  169954. *dp = (png_byte)value;
  169955. if (shift == 6)
  169956. {
  169957. shift = 0;
  169958. sp--;
  169959. }
  169960. else
  169961. shift += 2;
  169962. dp--;
  169963. }
  169964. break;
  169965. }
  169966. case 4:
  169967. {
  169968. sp = row + (png_size_t)((row_width - 1) >> 1);
  169969. dp = row + (png_size_t)row_width - 1;
  169970. shift = (int)((row_width & 0x01) << 2);
  169971. for (i = 0; i < row_width; i++)
  169972. {
  169973. value = (*sp >> shift) & 0x0f;
  169974. *dp = (png_byte)value;
  169975. if (shift == 4)
  169976. {
  169977. shift = 0;
  169978. sp--;
  169979. }
  169980. else
  169981. shift += 4;
  169982. dp--;
  169983. }
  169984. break;
  169985. }
  169986. }
  169987. row_info->bit_depth = 8;
  169988. row_info->pixel_depth = 8;
  169989. row_info->rowbytes = row_width;
  169990. }
  169991. switch (row_info->bit_depth)
  169992. {
  169993. case 8:
  169994. {
  169995. if (trans != NULL)
  169996. {
  169997. sp = row + (png_size_t)row_width - 1;
  169998. dp = row + (png_size_t)(row_width << 2) - 1;
  169999. for (i = 0; i < row_width; i++)
  170000. {
  170001. if ((int)(*sp) >= num_trans)
  170002. *dp-- = 0xff;
  170003. else
  170004. *dp-- = trans[*sp];
  170005. *dp-- = palette[*sp].blue;
  170006. *dp-- = palette[*sp].green;
  170007. *dp-- = palette[*sp].red;
  170008. sp--;
  170009. }
  170010. row_info->bit_depth = 8;
  170011. row_info->pixel_depth = 32;
  170012. row_info->rowbytes = row_width * 4;
  170013. row_info->color_type = 6;
  170014. row_info->channels = 4;
  170015. }
  170016. else
  170017. {
  170018. sp = row + (png_size_t)row_width - 1;
  170019. dp = row + (png_size_t)(row_width * 3) - 1;
  170020. for (i = 0; i < row_width; i++)
  170021. {
  170022. *dp-- = palette[*sp].blue;
  170023. *dp-- = palette[*sp].green;
  170024. *dp-- = palette[*sp].red;
  170025. sp--;
  170026. }
  170027. row_info->bit_depth = 8;
  170028. row_info->pixel_depth = 24;
  170029. row_info->rowbytes = row_width * 3;
  170030. row_info->color_type = 2;
  170031. row_info->channels = 3;
  170032. }
  170033. break;
  170034. }
  170035. }
  170036. }
  170037. }
  170038. void /* PRIVATE */
  170039. png_do_expand(png_row_infop row_info, png_bytep row,
  170040. png_color_16p trans_value)
  170041. {
  170042. int shift, value;
  170043. png_bytep sp, dp;
  170044. png_uint_32 i;
  170045. png_uint_32 row_width=row_info->width;
  170046. png_debug(1, "in png_do_expand\n");
  170047. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170048. if (row != NULL && row_info != NULL)
  170049. #endif
  170050. {
  170051. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170052. {
  170053. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170054. if (row_info->bit_depth < 8)
  170055. {
  170056. switch (row_info->bit_depth)
  170057. {
  170058. case 1:
  170059. {
  170060. gray = (png_uint_16)((gray&0x01)*0xff);
  170061. sp = row + (png_size_t)((row_width - 1) >> 3);
  170062. dp = row + (png_size_t)row_width - 1;
  170063. shift = 7 - (int)((row_width + 7) & 0x07);
  170064. for (i = 0; i < row_width; i++)
  170065. {
  170066. if ((*sp >> shift) & 0x01)
  170067. *dp = 0xff;
  170068. else
  170069. *dp = 0;
  170070. if (shift == 7)
  170071. {
  170072. shift = 0;
  170073. sp--;
  170074. }
  170075. else
  170076. shift++;
  170077. dp--;
  170078. }
  170079. break;
  170080. }
  170081. case 2:
  170082. {
  170083. gray = (png_uint_16)((gray&0x03)*0x55);
  170084. sp = row + (png_size_t)((row_width - 1) >> 2);
  170085. dp = row + (png_size_t)row_width - 1;
  170086. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170087. for (i = 0; i < row_width; i++)
  170088. {
  170089. value = (*sp >> shift) & 0x03;
  170090. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170091. (value << 6));
  170092. if (shift == 6)
  170093. {
  170094. shift = 0;
  170095. sp--;
  170096. }
  170097. else
  170098. shift += 2;
  170099. dp--;
  170100. }
  170101. break;
  170102. }
  170103. case 4:
  170104. {
  170105. gray = (png_uint_16)((gray&0x0f)*0x11);
  170106. sp = row + (png_size_t)((row_width - 1) >> 1);
  170107. dp = row + (png_size_t)row_width - 1;
  170108. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170109. for (i = 0; i < row_width; i++)
  170110. {
  170111. value = (*sp >> shift) & 0x0f;
  170112. *dp = (png_byte)(value | (value << 4));
  170113. if (shift == 4)
  170114. {
  170115. shift = 0;
  170116. sp--;
  170117. }
  170118. else
  170119. shift = 4;
  170120. dp--;
  170121. }
  170122. break;
  170123. }
  170124. }
  170125. row_info->bit_depth = 8;
  170126. row_info->pixel_depth = 8;
  170127. row_info->rowbytes = row_width;
  170128. }
  170129. if (trans_value != NULL)
  170130. {
  170131. if (row_info->bit_depth == 8)
  170132. {
  170133. gray = gray & 0xff;
  170134. sp = row + (png_size_t)row_width - 1;
  170135. dp = row + (png_size_t)(row_width << 1) - 1;
  170136. for (i = 0; i < row_width; i++)
  170137. {
  170138. if (*sp == gray)
  170139. *dp-- = 0;
  170140. else
  170141. *dp-- = 0xff;
  170142. *dp-- = *sp--;
  170143. }
  170144. }
  170145. else if (row_info->bit_depth == 16)
  170146. {
  170147. png_byte gray_high = (gray >> 8) & 0xff;
  170148. png_byte gray_low = gray & 0xff;
  170149. sp = row + row_info->rowbytes - 1;
  170150. dp = row + (row_info->rowbytes << 1) - 1;
  170151. for (i = 0; i < row_width; i++)
  170152. {
  170153. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170154. {
  170155. *dp-- = 0;
  170156. *dp-- = 0;
  170157. }
  170158. else
  170159. {
  170160. *dp-- = 0xff;
  170161. *dp-- = 0xff;
  170162. }
  170163. *dp-- = *sp--;
  170164. *dp-- = *sp--;
  170165. }
  170166. }
  170167. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170168. row_info->channels = 2;
  170169. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170170. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170171. row_width);
  170172. }
  170173. }
  170174. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170175. {
  170176. if (row_info->bit_depth == 8)
  170177. {
  170178. png_byte red = trans_value->red & 0xff;
  170179. png_byte green = trans_value->green & 0xff;
  170180. png_byte blue = trans_value->blue & 0xff;
  170181. sp = row + (png_size_t)row_info->rowbytes - 1;
  170182. dp = row + (png_size_t)(row_width << 2) - 1;
  170183. for (i = 0; i < row_width; i++)
  170184. {
  170185. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170186. *dp-- = 0;
  170187. else
  170188. *dp-- = 0xff;
  170189. *dp-- = *sp--;
  170190. *dp-- = *sp--;
  170191. *dp-- = *sp--;
  170192. }
  170193. }
  170194. else if (row_info->bit_depth == 16)
  170195. {
  170196. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170197. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170198. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170199. png_byte red_low = trans_value->red & 0xff;
  170200. png_byte green_low = trans_value->green & 0xff;
  170201. png_byte blue_low = trans_value->blue & 0xff;
  170202. sp = row + row_info->rowbytes - 1;
  170203. dp = row + (png_size_t)(row_width << 3) - 1;
  170204. for (i = 0; i < row_width; i++)
  170205. {
  170206. if (*(sp - 5) == red_high &&
  170207. *(sp - 4) == red_low &&
  170208. *(sp - 3) == green_high &&
  170209. *(sp - 2) == green_low &&
  170210. *(sp - 1) == blue_high &&
  170211. *(sp ) == blue_low)
  170212. {
  170213. *dp-- = 0;
  170214. *dp-- = 0;
  170215. }
  170216. else
  170217. {
  170218. *dp-- = 0xff;
  170219. *dp-- = 0xff;
  170220. }
  170221. *dp-- = *sp--;
  170222. *dp-- = *sp--;
  170223. *dp-- = *sp--;
  170224. *dp-- = *sp--;
  170225. *dp-- = *sp--;
  170226. *dp-- = *sp--;
  170227. }
  170228. }
  170229. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170230. row_info->channels = 4;
  170231. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170232. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170233. }
  170234. }
  170235. }
  170236. #endif
  170237. #if defined(PNG_READ_DITHER_SUPPORTED)
  170238. void /* PRIVATE */
  170239. png_do_dither(png_row_infop row_info, png_bytep row,
  170240. png_bytep palette_lookup, png_bytep dither_lookup)
  170241. {
  170242. png_bytep sp, dp;
  170243. png_uint_32 i;
  170244. png_uint_32 row_width=row_info->width;
  170245. png_debug(1, "in png_do_dither\n");
  170246. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170247. if (row != NULL && row_info != NULL)
  170248. #endif
  170249. {
  170250. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170251. palette_lookup && row_info->bit_depth == 8)
  170252. {
  170253. int r, g, b, p;
  170254. sp = row;
  170255. dp = row;
  170256. for (i = 0; i < row_width; i++)
  170257. {
  170258. r = *sp++;
  170259. g = *sp++;
  170260. b = *sp++;
  170261. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170262. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170263. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170264. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170265. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170266. (PNG_DITHER_BLUE_BITS)) |
  170267. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170268. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170269. *dp++ = palette_lookup[p];
  170270. }
  170271. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170272. row_info->channels = 1;
  170273. row_info->pixel_depth = row_info->bit_depth;
  170274. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170275. }
  170276. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170277. palette_lookup != NULL && row_info->bit_depth == 8)
  170278. {
  170279. int r, g, b, p;
  170280. sp = row;
  170281. dp = row;
  170282. for (i = 0; i < row_width; i++)
  170283. {
  170284. r = *sp++;
  170285. g = *sp++;
  170286. b = *sp++;
  170287. sp++;
  170288. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170289. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170290. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170291. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170292. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170293. (PNG_DITHER_BLUE_BITS)) |
  170294. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170295. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170296. *dp++ = palette_lookup[p];
  170297. }
  170298. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170299. row_info->channels = 1;
  170300. row_info->pixel_depth = row_info->bit_depth;
  170301. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170302. }
  170303. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170304. dither_lookup && row_info->bit_depth == 8)
  170305. {
  170306. sp = row;
  170307. for (i = 0; i < row_width; i++, sp++)
  170308. {
  170309. *sp = dither_lookup[*sp];
  170310. }
  170311. }
  170312. }
  170313. }
  170314. #endif
  170315. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170316. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170317. static PNG_CONST int png_gamma_shift[] =
  170318. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170319. void /* PRIVATE */
  170320. png_build_gamma_table(png_structp png_ptr)
  170321. {
  170322. png_debug(1, "in png_build_gamma_table\n");
  170323. if (png_ptr->bit_depth <= 8)
  170324. {
  170325. int i;
  170326. double g;
  170327. if (png_ptr->screen_gamma > .000001)
  170328. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170329. else
  170330. g = 1.0;
  170331. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170332. (png_uint_32)256);
  170333. for (i = 0; i < 256; i++)
  170334. {
  170335. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170336. g) * 255.0 + .5);
  170337. }
  170338. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170339. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170340. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170341. {
  170342. g = 1.0 / (png_ptr->gamma);
  170343. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170344. (png_uint_32)256);
  170345. for (i = 0; i < 256; i++)
  170346. {
  170347. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170348. g) * 255.0 + .5);
  170349. }
  170350. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170351. (png_uint_32)256);
  170352. if(png_ptr->screen_gamma > 0.000001)
  170353. g = 1.0 / png_ptr->screen_gamma;
  170354. else
  170355. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170356. for (i = 0; i < 256; i++)
  170357. {
  170358. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170359. g) * 255.0 + .5);
  170360. }
  170361. }
  170362. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170363. }
  170364. else
  170365. {
  170366. double g;
  170367. int i, j, shift, num;
  170368. int sig_bit;
  170369. png_uint_32 ig;
  170370. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170371. {
  170372. sig_bit = (int)png_ptr->sig_bit.red;
  170373. if ((int)png_ptr->sig_bit.green > sig_bit)
  170374. sig_bit = png_ptr->sig_bit.green;
  170375. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170376. sig_bit = png_ptr->sig_bit.blue;
  170377. }
  170378. else
  170379. {
  170380. sig_bit = (int)png_ptr->sig_bit.gray;
  170381. }
  170382. if (sig_bit > 0)
  170383. shift = 16 - sig_bit;
  170384. else
  170385. shift = 0;
  170386. if (png_ptr->transformations & PNG_16_TO_8)
  170387. {
  170388. if (shift < (16 - PNG_MAX_GAMMA_8))
  170389. shift = (16 - PNG_MAX_GAMMA_8);
  170390. }
  170391. if (shift > 8)
  170392. shift = 8;
  170393. if (shift < 0)
  170394. shift = 0;
  170395. png_ptr->gamma_shift = (png_byte)shift;
  170396. num = (1 << (8 - shift));
  170397. if (png_ptr->screen_gamma > .000001)
  170398. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170399. else
  170400. g = 1.0;
  170401. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170402. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170403. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170404. {
  170405. double fin, fout;
  170406. png_uint_32 last, max;
  170407. for (i = 0; i < num; i++)
  170408. {
  170409. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170410. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170411. }
  170412. g = 1.0 / g;
  170413. last = 0;
  170414. for (i = 0; i < 256; i++)
  170415. {
  170416. fout = ((double)i + 0.5) / 256.0;
  170417. fin = pow(fout, g);
  170418. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170419. while (last <= max)
  170420. {
  170421. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170422. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170423. (png_uint_16)i | ((png_uint_16)i << 8));
  170424. last++;
  170425. }
  170426. }
  170427. while (last < ((png_uint_32)num << 8))
  170428. {
  170429. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170430. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170431. last++;
  170432. }
  170433. }
  170434. else
  170435. {
  170436. for (i = 0; i < num; i++)
  170437. {
  170438. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170439. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170440. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170441. for (j = 0; j < 256; j++)
  170442. {
  170443. png_ptr->gamma_16_table[i][j] =
  170444. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170445. 65535.0, g) * 65535.0 + .5);
  170446. }
  170447. }
  170448. }
  170449. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170450. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170451. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170452. {
  170453. g = 1.0 / (png_ptr->gamma);
  170454. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170455. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170456. for (i = 0; i < num; i++)
  170457. {
  170458. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170459. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170460. ig = (((png_uint_32)i *
  170461. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170462. for (j = 0; j < 256; j++)
  170463. {
  170464. png_ptr->gamma_16_to_1[i][j] =
  170465. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170466. 65535.0, g) * 65535.0 + .5);
  170467. }
  170468. }
  170469. if(png_ptr->screen_gamma > 0.000001)
  170470. g = 1.0 / png_ptr->screen_gamma;
  170471. else
  170472. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170473. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170474. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170475. for (i = 0; i < num; i++)
  170476. {
  170477. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170478. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170479. ig = (((png_uint_32)i *
  170480. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170481. for (j = 0; j < 256; j++)
  170482. {
  170483. png_ptr->gamma_16_from_1[i][j] =
  170484. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170485. 65535.0, g) * 65535.0 + .5);
  170486. }
  170487. }
  170488. }
  170489. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170490. }
  170491. }
  170492. #endif
  170493. #endif
  170494. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170495. void /* PRIVATE */
  170496. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170497. {
  170498. png_debug(1, "in png_do_read_intrapixel\n");
  170499. if (
  170500. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170501. row != NULL && row_info != NULL &&
  170502. #endif
  170503. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170504. {
  170505. int bytes_per_pixel;
  170506. png_uint_32 row_width = row_info->width;
  170507. if (row_info->bit_depth == 8)
  170508. {
  170509. png_bytep rp;
  170510. png_uint_32 i;
  170511. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170512. bytes_per_pixel = 3;
  170513. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170514. bytes_per_pixel = 4;
  170515. else
  170516. return;
  170517. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170518. {
  170519. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170520. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170521. }
  170522. }
  170523. else if (row_info->bit_depth == 16)
  170524. {
  170525. png_bytep rp;
  170526. png_uint_32 i;
  170527. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170528. bytes_per_pixel = 6;
  170529. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170530. bytes_per_pixel = 8;
  170531. else
  170532. return;
  170533. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170534. {
  170535. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170536. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170537. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170538. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170539. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170540. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170541. *(rp+1) = (png_byte)(red & 0xff);
  170542. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170543. *(rp+5) = (png_byte)(blue & 0xff);
  170544. }
  170545. }
  170546. }
  170547. }
  170548. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170549. #endif /* PNG_READ_SUPPORTED */
  170550. /*** End of inlined file: pngrtran.c ***/
  170551. /*** Start of inlined file: pngrutil.c ***/
  170552. #define PNG_INTERNAL
  170553. #if defined(PNG_READ_SUPPORTED)
  170554. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170555. # define WIN32_WCE_OLD
  170556. #endif
  170557. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170558. # if defined(WIN32_WCE_OLD)
  170559. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170560. {
  170561. double result = 0;
  170562. int len;
  170563. wchar_t *str, *end;
  170564. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170565. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170566. if ( NULL != str )
  170567. {
  170568. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170569. result = wcstod(str, &end);
  170570. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170571. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170572. png_free(png_ptr, str);
  170573. }
  170574. return result;
  170575. }
  170576. # else
  170577. # define png_strtod(p,a,b) strtod(a,b)
  170578. # endif
  170579. #endif
  170580. png_uint_32 PNGAPI
  170581. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170582. {
  170583. png_uint_32 i = png_get_uint_32(buf);
  170584. if (i > PNG_UINT_31_MAX)
  170585. png_error(png_ptr, "PNG unsigned integer out of range.");
  170586. return (i);
  170587. }
  170588. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170589. png_uint_32 PNGAPI
  170590. png_get_uint_32(png_bytep buf)
  170591. {
  170592. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170593. ((png_uint_32)(*(buf + 1)) << 16) +
  170594. ((png_uint_32)(*(buf + 2)) << 8) +
  170595. (png_uint_32)(*(buf + 3));
  170596. return (i);
  170597. }
  170598. png_int_32 PNGAPI
  170599. png_get_int_32(png_bytep buf)
  170600. {
  170601. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170602. ((png_int_32)(*(buf + 1)) << 16) +
  170603. ((png_int_32)(*(buf + 2)) << 8) +
  170604. (png_int_32)(*(buf + 3));
  170605. return (i);
  170606. }
  170607. png_uint_16 PNGAPI
  170608. png_get_uint_16(png_bytep buf)
  170609. {
  170610. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170611. (png_uint_16)(*(buf + 1)));
  170612. return (i);
  170613. }
  170614. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170615. void /* PRIVATE */
  170616. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170617. {
  170618. if(png_ptr == NULL) return;
  170619. png_read_data(png_ptr, buf, length);
  170620. png_calculate_crc(png_ptr, buf, length);
  170621. }
  170622. int /* PRIVATE */
  170623. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170624. {
  170625. png_size_t i;
  170626. png_size_t istop = png_ptr->zbuf_size;
  170627. for (i = (png_size_t)skip; i > istop; i -= istop)
  170628. {
  170629. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170630. }
  170631. if (i)
  170632. {
  170633. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170634. }
  170635. if (png_crc_error(png_ptr))
  170636. {
  170637. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170638. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170639. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170640. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170641. {
  170642. png_chunk_warning(png_ptr, "CRC error");
  170643. }
  170644. else
  170645. {
  170646. png_chunk_error(png_ptr, "CRC error");
  170647. }
  170648. return (1);
  170649. }
  170650. return (0);
  170651. }
  170652. int /* PRIVATE */
  170653. png_crc_error(png_structp png_ptr)
  170654. {
  170655. png_byte crc_bytes[4];
  170656. png_uint_32 crc;
  170657. int need_crc = 1;
  170658. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170659. {
  170660. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170661. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170662. need_crc = 0;
  170663. }
  170664. else /* critical */
  170665. {
  170666. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170667. need_crc = 0;
  170668. }
  170669. png_read_data(png_ptr, crc_bytes, 4);
  170670. if (need_crc)
  170671. {
  170672. crc = png_get_uint_32(crc_bytes);
  170673. return ((int)(crc != png_ptr->crc));
  170674. }
  170675. else
  170676. return (0);
  170677. }
  170678. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170679. defined(PNG_READ_iCCP_SUPPORTED)
  170680. png_charp /* PRIVATE */
  170681. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170682. png_charp chunkdata, png_size_t chunklength,
  170683. png_size_t prefix_size, png_size_t *newlength)
  170684. {
  170685. static PNG_CONST char msg[] = "Error decoding compressed text";
  170686. png_charp text;
  170687. png_size_t text_size;
  170688. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170689. {
  170690. int ret = Z_OK;
  170691. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170692. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170693. png_ptr->zstream.next_out = png_ptr->zbuf;
  170694. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170695. text_size = 0;
  170696. text = NULL;
  170697. while (png_ptr->zstream.avail_in)
  170698. {
  170699. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170700. if (ret != Z_OK && ret != Z_STREAM_END)
  170701. {
  170702. if (png_ptr->zstream.msg != NULL)
  170703. png_warning(png_ptr, png_ptr->zstream.msg);
  170704. else
  170705. png_warning(png_ptr, msg);
  170706. inflateReset(&png_ptr->zstream);
  170707. png_ptr->zstream.avail_in = 0;
  170708. if (text == NULL)
  170709. {
  170710. text_size = prefix_size + png_sizeof(msg) + 1;
  170711. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170712. if (text == NULL)
  170713. {
  170714. png_free(png_ptr,chunkdata);
  170715. png_error(png_ptr,"Not enough memory to decompress chunk");
  170716. }
  170717. png_memcpy(text, chunkdata, prefix_size);
  170718. }
  170719. text[text_size - 1] = 0x00;
  170720. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170721. text_size = png_sizeof(msg) > text_size ? text_size :
  170722. png_sizeof(msg);
  170723. png_memcpy(text + prefix_size, msg, text_size + 1);
  170724. break;
  170725. }
  170726. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170727. {
  170728. if (text == NULL)
  170729. {
  170730. text_size = prefix_size +
  170731. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170732. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170733. if (text == NULL)
  170734. {
  170735. png_free(png_ptr,chunkdata);
  170736. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170737. }
  170738. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170739. text_size - prefix_size);
  170740. png_memcpy(text, chunkdata, prefix_size);
  170741. *(text + text_size) = 0x00;
  170742. }
  170743. else
  170744. {
  170745. png_charp tmp;
  170746. tmp = text;
  170747. text = (png_charp)png_malloc_warn(png_ptr,
  170748. (png_uint_32)(text_size +
  170749. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170750. if (text == NULL)
  170751. {
  170752. png_free(png_ptr, tmp);
  170753. png_free(png_ptr, chunkdata);
  170754. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170755. }
  170756. png_memcpy(text, tmp, text_size);
  170757. png_free(png_ptr, tmp);
  170758. png_memcpy(text + text_size, png_ptr->zbuf,
  170759. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170760. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170761. *(text + text_size) = 0x00;
  170762. }
  170763. if (ret == Z_STREAM_END)
  170764. break;
  170765. else
  170766. {
  170767. png_ptr->zstream.next_out = png_ptr->zbuf;
  170768. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170769. }
  170770. }
  170771. }
  170772. if (ret != Z_STREAM_END)
  170773. {
  170774. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170775. char umsg[52];
  170776. if (ret == Z_BUF_ERROR)
  170777. png_snprintf(umsg, 52,
  170778. "Buffer error in compressed datastream in %s chunk",
  170779. png_ptr->chunk_name);
  170780. else if (ret == Z_DATA_ERROR)
  170781. png_snprintf(umsg, 52,
  170782. "Data error in compressed datastream in %s chunk",
  170783. png_ptr->chunk_name);
  170784. else
  170785. png_snprintf(umsg, 52,
  170786. "Incomplete compressed datastream in %s chunk",
  170787. png_ptr->chunk_name);
  170788. png_warning(png_ptr, umsg);
  170789. #else
  170790. png_warning(png_ptr,
  170791. "Incomplete compressed datastream in chunk other than IDAT");
  170792. #endif
  170793. text_size=prefix_size;
  170794. if (text == NULL)
  170795. {
  170796. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170797. if (text == NULL)
  170798. {
  170799. png_free(png_ptr, chunkdata);
  170800. png_error(png_ptr,"Not enough memory for text.");
  170801. }
  170802. png_memcpy(text, chunkdata, prefix_size);
  170803. }
  170804. *(text + text_size) = 0x00;
  170805. }
  170806. inflateReset(&png_ptr->zstream);
  170807. png_ptr->zstream.avail_in = 0;
  170808. png_free(png_ptr, chunkdata);
  170809. chunkdata = text;
  170810. *newlength=text_size;
  170811. }
  170812. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170813. {
  170814. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170815. char umsg[50];
  170816. png_snprintf(umsg, 50,
  170817. "Unknown zTXt compression type %d", comp_type);
  170818. png_warning(png_ptr, umsg);
  170819. #else
  170820. png_warning(png_ptr, "Unknown zTXt compression type");
  170821. #endif
  170822. *(chunkdata + prefix_size) = 0x00;
  170823. *newlength=prefix_size;
  170824. }
  170825. return chunkdata;
  170826. }
  170827. #endif
  170828. void /* PRIVATE */
  170829. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170830. {
  170831. png_byte buf[13];
  170832. png_uint_32 width, height;
  170833. int bit_depth, color_type, compression_type, filter_type;
  170834. int interlace_type;
  170835. png_debug(1, "in png_handle_IHDR\n");
  170836. if (png_ptr->mode & PNG_HAVE_IHDR)
  170837. png_error(png_ptr, "Out of place IHDR");
  170838. if (length != 13)
  170839. png_error(png_ptr, "Invalid IHDR chunk");
  170840. png_ptr->mode |= PNG_HAVE_IHDR;
  170841. png_crc_read(png_ptr, buf, 13);
  170842. png_crc_finish(png_ptr, 0);
  170843. width = png_get_uint_31(png_ptr, buf);
  170844. height = png_get_uint_31(png_ptr, buf + 4);
  170845. bit_depth = buf[8];
  170846. color_type = buf[9];
  170847. compression_type = buf[10];
  170848. filter_type = buf[11];
  170849. interlace_type = buf[12];
  170850. png_ptr->width = width;
  170851. png_ptr->height = height;
  170852. png_ptr->bit_depth = (png_byte)bit_depth;
  170853. png_ptr->interlaced = (png_byte)interlace_type;
  170854. png_ptr->color_type = (png_byte)color_type;
  170855. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170856. png_ptr->filter_type = (png_byte)filter_type;
  170857. #endif
  170858. png_ptr->compression_type = (png_byte)compression_type;
  170859. switch (png_ptr->color_type)
  170860. {
  170861. case PNG_COLOR_TYPE_GRAY:
  170862. case PNG_COLOR_TYPE_PALETTE:
  170863. png_ptr->channels = 1;
  170864. break;
  170865. case PNG_COLOR_TYPE_RGB:
  170866. png_ptr->channels = 3;
  170867. break;
  170868. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170869. png_ptr->channels = 2;
  170870. break;
  170871. case PNG_COLOR_TYPE_RGB_ALPHA:
  170872. png_ptr->channels = 4;
  170873. break;
  170874. }
  170875. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170876. png_ptr->channels);
  170877. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170878. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170879. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170880. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170881. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170882. color_type, interlace_type, compression_type, filter_type);
  170883. }
  170884. void /* PRIVATE */
  170885. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170886. {
  170887. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170888. int num, i;
  170889. #ifndef PNG_NO_POINTER_INDEXING
  170890. png_colorp pal_ptr;
  170891. #endif
  170892. png_debug(1, "in png_handle_PLTE\n");
  170893. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170894. png_error(png_ptr, "Missing IHDR before PLTE");
  170895. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170896. {
  170897. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170898. png_crc_finish(png_ptr, length);
  170899. return;
  170900. }
  170901. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170902. png_error(png_ptr, "Duplicate PLTE chunk");
  170903. png_ptr->mode |= PNG_HAVE_PLTE;
  170904. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170905. {
  170906. png_warning(png_ptr,
  170907. "Ignoring PLTE chunk in grayscale PNG");
  170908. png_crc_finish(png_ptr, length);
  170909. return;
  170910. }
  170911. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170912. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170913. {
  170914. png_crc_finish(png_ptr, length);
  170915. return;
  170916. }
  170917. #endif
  170918. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  170919. {
  170920. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170921. {
  170922. png_warning(png_ptr, "Invalid palette chunk");
  170923. png_crc_finish(png_ptr, length);
  170924. return;
  170925. }
  170926. else
  170927. {
  170928. png_error(png_ptr, "Invalid palette chunk");
  170929. }
  170930. }
  170931. num = (int)length / 3;
  170932. #ifndef PNG_NO_POINTER_INDEXING
  170933. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  170934. {
  170935. png_byte buf[3];
  170936. png_crc_read(png_ptr, buf, 3);
  170937. pal_ptr->red = buf[0];
  170938. pal_ptr->green = buf[1];
  170939. pal_ptr->blue = buf[2];
  170940. }
  170941. #else
  170942. for (i = 0; i < num; i++)
  170943. {
  170944. png_byte buf[3];
  170945. png_crc_read(png_ptr, buf, 3);
  170946. palette[i].red = buf[0];
  170947. palette[i].green = buf[1];
  170948. palette[i].blue = buf[2];
  170949. }
  170950. #endif
  170951. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170952. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170953. #endif
  170954. {
  170955. png_crc_finish(png_ptr, 0);
  170956. }
  170957. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170958. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  170959. {
  170960. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  170961. {
  170962. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  170963. {
  170964. png_chunk_error(png_ptr, "CRC error");
  170965. }
  170966. else
  170967. {
  170968. png_chunk_warning(png_ptr, "CRC error");
  170969. return;
  170970. }
  170971. }
  170972. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170973. {
  170974. png_chunk_warning(png_ptr, "CRC error");
  170975. }
  170976. }
  170977. #endif
  170978. png_set_PLTE(png_ptr, info_ptr, palette, num);
  170979. #if defined(PNG_READ_tRNS_SUPPORTED)
  170980. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170981. {
  170982. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  170983. {
  170984. if (png_ptr->num_trans > (png_uint_16)num)
  170985. {
  170986. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  170987. png_ptr->num_trans = (png_uint_16)num;
  170988. }
  170989. if (info_ptr->num_trans > (png_uint_16)num)
  170990. {
  170991. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  170992. info_ptr->num_trans = (png_uint_16)num;
  170993. }
  170994. }
  170995. }
  170996. #endif
  170997. }
  170998. void /* PRIVATE */
  170999. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171000. {
  171001. png_debug(1, "in png_handle_IEND\n");
  171002. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171003. {
  171004. png_error(png_ptr, "No image in file");
  171005. }
  171006. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171007. if (length != 0)
  171008. {
  171009. png_warning(png_ptr, "Incorrect IEND chunk length");
  171010. }
  171011. png_crc_finish(png_ptr, length);
  171012. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171013. }
  171014. #if defined(PNG_READ_gAMA_SUPPORTED)
  171015. void /* PRIVATE */
  171016. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171017. {
  171018. png_fixed_point igamma;
  171019. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171020. float file_gamma;
  171021. #endif
  171022. png_byte buf[4];
  171023. png_debug(1, "in png_handle_gAMA\n");
  171024. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171025. png_error(png_ptr, "Missing IHDR before gAMA");
  171026. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171027. {
  171028. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171029. png_crc_finish(png_ptr, length);
  171030. return;
  171031. }
  171032. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171033. png_warning(png_ptr, "Out of place gAMA chunk");
  171034. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171035. #if defined(PNG_READ_sRGB_SUPPORTED)
  171036. && !(info_ptr->valid & PNG_INFO_sRGB)
  171037. #endif
  171038. )
  171039. {
  171040. png_warning(png_ptr, "Duplicate gAMA chunk");
  171041. png_crc_finish(png_ptr, length);
  171042. return;
  171043. }
  171044. if (length != 4)
  171045. {
  171046. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171047. png_crc_finish(png_ptr, length);
  171048. return;
  171049. }
  171050. png_crc_read(png_ptr, buf, 4);
  171051. if (png_crc_finish(png_ptr, 0))
  171052. return;
  171053. igamma = (png_fixed_point)png_get_uint_32(buf);
  171054. if (igamma == 0)
  171055. {
  171056. png_warning(png_ptr,
  171057. "Ignoring gAMA chunk with gamma=0");
  171058. return;
  171059. }
  171060. #if defined(PNG_READ_sRGB_SUPPORTED)
  171061. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171062. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171063. {
  171064. png_warning(png_ptr,
  171065. "Ignoring incorrect gAMA value when sRGB is also present");
  171066. #ifndef PNG_NO_CONSOLE_IO
  171067. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171068. #endif
  171069. return;
  171070. }
  171071. #endif /* PNG_READ_sRGB_SUPPORTED */
  171072. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171073. file_gamma = (float)igamma / (float)100000.0;
  171074. # ifdef PNG_READ_GAMMA_SUPPORTED
  171075. png_ptr->gamma = file_gamma;
  171076. # endif
  171077. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171078. #endif
  171079. #ifdef PNG_FIXED_POINT_SUPPORTED
  171080. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171081. #endif
  171082. }
  171083. #endif
  171084. #if defined(PNG_READ_sBIT_SUPPORTED)
  171085. void /* PRIVATE */
  171086. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171087. {
  171088. png_size_t truelen;
  171089. png_byte buf[4];
  171090. png_debug(1, "in png_handle_sBIT\n");
  171091. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171092. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171093. png_error(png_ptr, "Missing IHDR before sBIT");
  171094. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171095. {
  171096. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171097. png_crc_finish(png_ptr, length);
  171098. return;
  171099. }
  171100. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171101. {
  171102. png_warning(png_ptr, "Out of place sBIT chunk");
  171103. }
  171104. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171105. {
  171106. png_warning(png_ptr, "Duplicate sBIT chunk");
  171107. png_crc_finish(png_ptr, length);
  171108. return;
  171109. }
  171110. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171111. truelen = 3;
  171112. else
  171113. truelen = (png_size_t)png_ptr->channels;
  171114. if (length != truelen || length > 4)
  171115. {
  171116. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171117. png_crc_finish(png_ptr, length);
  171118. return;
  171119. }
  171120. png_crc_read(png_ptr, buf, truelen);
  171121. if (png_crc_finish(png_ptr, 0))
  171122. return;
  171123. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171124. {
  171125. png_ptr->sig_bit.red = buf[0];
  171126. png_ptr->sig_bit.green = buf[1];
  171127. png_ptr->sig_bit.blue = buf[2];
  171128. png_ptr->sig_bit.alpha = buf[3];
  171129. }
  171130. else
  171131. {
  171132. png_ptr->sig_bit.gray = buf[0];
  171133. png_ptr->sig_bit.red = buf[0];
  171134. png_ptr->sig_bit.green = buf[0];
  171135. png_ptr->sig_bit.blue = buf[0];
  171136. png_ptr->sig_bit.alpha = buf[1];
  171137. }
  171138. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171139. }
  171140. #endif
  171141. #if defined(PNG_READ_cHRM_SUPPORTED)
  171142. void /* PRIVATE */
  171143. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171144. {
  171145. png_byte buf[4];
  171146. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171147. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171148. #endif
  171149. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171150. int_y_green, int_x_blue, int_y_blue;
  171151. png_uint_32 uint_x, uint_y;
  171152. png_debug(1, "in png_handle_cHRM\n");
  171153. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171154. png_error(png_ptr, "Missing IHDR before cHRM");
  171155. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171156. {
  171157. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171158. png_crc_finish(png_ptr, length);
  171159. return;
  171160. }
  171161. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171162. png_warning(png_ptr, "Missing PLTE before cHRM");
  171163. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171164. #if defined(PNG_READ_sRGB_SUPPORTED)
  171165. && !(info_ptr->valid & PNG_INFO_sRGB)
  171166. #endif
  171167. )
  171168. {
  171169. png_warning(png_ptr, "Duplicate cHRM chunk");
  171170. png_crc_finish(png_ptr, length);
  171171. return;
  171172. }
  171173. if (length != 32)
  171174. {
  171175. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171176. png_crc_finish(png_ptr, length);
  171177. return;
  171178. }
  171179. png_crc_read(png_ptr, buf, 4);
  171180. uint_x = png_get_uint_32(buf);
  171181. png_crc_read(png_ptr, buf, 4);
  171182. uint_y = png_get_uint_32(buf);
  171183. if (uint_x > 80000L || uint_y > 80000L ||
  171184. uint_x + uint_y > 100000L)
  171185. {
  171186. png_warning(png_ptr, "Invalid cHRM white point");
  171187. png_crc_finish(png_ptr, 24);
  171188. return;
  171189. }
  171190. int_x_white = (png_fixed_point)uint_x;
  171191. int_y_white = (png_fixed_point)uint_y;
  171192. png_crc_read(png_ptr, buf, 4);
  171193. uint_x = png_get_uint_32(buf);
  171194. png_crc_read(png_ptr, buf, 4);
  171195. uint_y = png_get_uint_32(buf);
  171196. if (uint_x + uint_y > 100000L)
  171197. {
  171198. png_warning(png_ptr, "Invalid cHRM red point");
  171199. png_crc_finish(png_ptr, 16);
  171200. return;
  171201. }
  171202. int_x_red = (png_fixed_point)uint_x;
  171203. int_y_red = (png_fixed_point)uint_y;
  171204. png_crc_read(png_ptr, buf, 4);
  171205. uint_x = png_get_uint_32(buf);
  171206. png_crc_read(png_ptr, buf, 4);
  171207. uint_y = png_get_uint_32(buf);
  171208. if (uint_x + uint_y > 100000L)
  171209. {
  171210. png_warning(png_ptr, "Invalid cHRM green point");
  171211. png_crc_finish(png_ptr, 8);
  171212. return;
  171213. }
  171214. int_x_green = (png_fixed_point)uint_x;
  171215. int_y_green = (png_fixed_point)uint_y;
  171216. png_crc_read(png_ptr, buf, 4);
  171217. uint_x = png_get_uint_32(buf);
  171218. png_crc_read(png_ptr, buf, 4);
  171219. uint_y = png_get_uint_32(buf);
  171220. if (uint_x + uint_y > 100000L)
  171221. {
  171222. png_warning(png_ptr, "Invalid cHRM blue point");
  171223. png_crc_finish(png_ptr, 0);
  171224. return;
  171225. }
  171226. int_x_blue = (png_fixed_point)uint_x;
  171227. int_y_blue = (png_fixed_point)uint_y;
  171228. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171229. white_x = (float)int_x_white / (float)100000.0;
  171230. white_y = (float)int_y_white / (float)100000.0;
  171231. red_x = (float)int_x_red / (float)100000.0;
  171232. red_y = (float)int_y_red / (float)100000.0;
  171233. green_x = (float)int_x_green / (float)100000.0;
  171234. green_y = (float)int_y_green / (float)100000.0;
  171235. blue_x = (float)int_x_blue / (float)100000.0;
  171236. blue_y = (float)int_y_blue / (float)100000.0;
  171237. #endif
  171238. #if defined(PNG_READ_sRGB_SUPPORTED)
  171239. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171240. {
  171241. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171242. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171243. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171244. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171245. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171246. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171247. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171248. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171249. {
  171250. png_warning(png_ptr,
  171251. "Ignoring incorrect cHRM value when sRGB is also present");
  171252. #ifndef PNG_NO_CONSOLE_IO
  171253. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171254. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171255. white_x, white_y, red_x, red_y);
  171256. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171257. green_x, green_y, blue_x, blue_y);
  171258. #else
  171259. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171260. int_x_white, int_y_white, int_x_red, int_y_red);
  171261. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171262. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171263. #endif
  171264. #endif /* PNG_NO_CONSOLE_IO */
  171265. }
  171266. png_crc_finish(png_ptr, 0);
  171267. return;
  171268. }
  171269. #endif /* PNG_READ_sRGB_SUPPORTED */
  171270. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171271. png_set_cHRM(png_ptr, info_ptr,
  171272. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171273. #endif
  171274. #ifdef PNG_FIXED_POINT_SUPPORTED
  171275. png_set_cHRM_fixed(png_ptr, info_ptr,
  171276. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171277. int_y_green, int_x_blue, int_y_blue);
  171278. #endif
  171279. if (png_crc_finish(png_ptr, 0))
  171280. return;
  171281. }
  171282. #endif
  171283. #if defined(PNG_READ_sRGB_SUPPORTED)
  171284. void /* PRIVATE */
  171285. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171286. {
  171287. int intent;
  171288. png_byte buf[1];
  171289. png_debug(1, "in png_handle_sRGB\n");
  171290. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171291. png_error(png_ptr, "Missing IHDR before sRGB");
  171292. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171293. {
  171294. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171295. png_crc_finish(png_ptr, length);
  171296. return;
  171297. }
  171298. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171299. png_warning(png_ptr, "Out of place sRGB chunk");
  171300. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171301. {
  171302. png_warning(png_ptr, "Duplicate sRGB chunk");
  171303. png_crc_finish(png_ptr, length);
  171304. return;
  171305. }
  171306. if (length != 1)
  171307. {
  171308. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171309. png_crc_finish(png_ptr, length);
  171310. return;
  171311. }
  171312. png_crc_read(png_ptr, buf, 1);
  171313. if (png_crc_finish(png_ptr, 0))
  171314. return;
  171315. intent = buf[0];
  171316. if (intent >= PNG_sRGB_INTENT_LAST)
  171317. {
  171318. png_warning(png_ptr, "Unknown sRGB intent");
  171319. return;
  171320. }
  171321. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171322. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171323. {
  171324. png_fixed_point igamma;
  171325. #ifdef PNG_FIXED_POINT_SUPPORTED
  171326. igamma=info_ptr->int_gamma;
  171327. #else
  171328. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171329. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171330. # endif
  171331. #endif
  171332. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171333. {
  171334. png_warning(png_ptr,
  171335. "Ignoring incorrect gAMA value when sRGB is also present");
  171336. #ifndef PNG_NO_CONSOLE_IO
  171337. # ifdef PNG_FIXED_POINT_SUPPORTED
  171338. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171339. # else
  171340. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171341. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171342. # endif
  171343. # endif
  171344. #endif
  171345. }
  171346. }
  171347. #endif /* PNG_READ_gAMA_SUPPORTED */
  171348. #ifdef PNG_READ_cHRM_SUPPORTED
  171349. #ifdef PNG_FIXED_POINT_SUPPORTED
  171350. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171351. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171352. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171353. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171354. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171355. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171356. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171357. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171358. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171359. {
  171360. png_warning(png_ptr,
  171361. "Ignoring incorrect cHRM value when sRGB is also present");
  171362. }
  171363. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171364. #endif /* PNG_READ_cHRM_SUPPORTED */
  171365. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171366. }
  171367. #endif /* PNG_READ_sRGB_SUPPORTED */
  171368. #if defined(PNG_READ_iCCP_SUPPORTED)
  171369. void /* PRIVATE */
  171370. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171371. {
  171372. png_charp chunkdata;
  171373. png_byte compression_type;
  171374. png_bytep pC;
  171375. png_charp profile;
  171376. png_uint_32 skip = 0;
  171377. png_uint_32 profile_size, profile_length;
  171378. png_size_t slength, prefix_length, data_length;
  171379. png_debug(1, "in png_handle_iCCP\n");
  171380. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171381. png_error(png_ptr, "Missing IHDR before iCCP");
  171382. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171383. {
  171384. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171385. png_crc_finish(png_ptr, length);
  171386. return;
  171387. }
  171388. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171389. png_warning(png_ptr, "Out of place iCCP chunk");
  171390. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171391. {
  171392. png_warning(png_ptr, "Duplicate iCCP chunk");
  171393. png_crc_finish(png_ptr, length);
  171394. return;
  171395. }
  171396. #ifdef PNG_MAX_MALLOC_64K
  171397. if (length > (png_uint_32)65535L)
  171398. {
  171399. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171400. skip = length - (png_uint_32)65535L;
  171401. length = (png_uint_32)65535L;
  171402. }
  171403. #endif
  171404. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171405. slength = (png_size_t)length;
  171406. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171407. if (png_crc_finish(png_ptr, skip))
  171408. {
  171409. png_free(png_ptr, chunkdata);
  171410. return;
  171411. }
  171412. chunkdata[slength] = 0x00;
  171413. for (profile = chunkdata; *profile; profile++)
  171414. ;
  171415. ++profile;
  171416. if ( profile >= chunkdata + slength - 1)
  171417. {
  171418. png_free(png_ptr, chunkdata);
  171419. png_warning(png_ptr, "Malformed iCCP chunk");
  171420. return;
  171421. }
  171422. compression_type = *profile++;
  171423. if (compression_type)
  171424. {
  171425. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171426. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171427. wrote nonzero) */
  171428. }
  171429. prefix_length = profile - chunkdata;
  171430. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171431. slength, prefix_length, &data_length);
  171432. profile_length = data_length - prefix_length;
  171433. if ( prefix_length > data_length || profile_length < 4)
  171434. {
  171435. png_free(png_ptr, chunkdata);
  171436. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171437. return;
  171438. }
  171439. pC = (png_bytep)(chunkdata+prefix_length);
  171440. profile_size = ((*(pC ))<<24) |
  171441. ((*(pC+1))<<16) |
  171442. ((*(pC+2))<< 8) |
  171443. ((*(pC+3)) );
  171444. if(profile_size < profile_length)
  171445. profile_length = profile_size;
  171446. if(profile_size > profile_length)
  171447. {
  171448. png_free(png_ptr, chunkdata);
  171449. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171450. return;
  171451. }
  171452. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171453. chunkdata + prefix_length, profile_length);
  171454. png_free(png_ptr, chunkdata);
  171455. }
  171456. #endif /* PNG_READ_iCCP_SUPPORTED */
  171457. #if defined(PNG_READ_sPLT_SUPPORTED)
  171458. void /* PRIVATE */
  171459. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171460. {
  171461. png_bytep chunkdata;
  171462. png_bytep entry_start;
  171463. png_sPLT_t new_palette;
  171464. #ifdef PNG_NO_POINTER_INDEXING
  171465. png_sPLT_entryp pp;
  171466. #endif
  171467. int data_length, entry_size, i;
  171468. png_uint_32 skip = 0;
  171469. png_size_t slength;
  171470. png_debug(1, "in png_handle_sPLT\n");
  171471. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171472. png_error(png_ptr, "Missing IHDR before sPLT");
  171473. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171474. {
  171475. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171476. png_crc_finish(png_ptr, length);
  171477. return;
  171478. }
  171479. #ifdef PNG_MAX_MALLOC_64K
  171480. if (length > (png_uint_32)65535L)
  171481. {
  171482. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171483. skip = length - (png_uint_32)65535L;
  171484. length = (png_uint_32)65535L;
  171485. }
  171486. #endif
  171487. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171488. slength = (png_size_t)length;
  171489. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171490. if (png_crc_finish(png_ptr, skip))
  171491. {
  171492. png_free(png_ptr, chunkdata);
  171493. return;
  171494. }
  171495. chunkdata[slength] = 0x00;
  171496. for (entry_start = chunkdata; *entry_start; entry_start++)
  171497. ;
  171498. ++entry_start;
  171499. if (entry_start > chunkdata + slength - 2)
  171500. {
  171501. png_free(png_ptr, chunkdata);
  171502. png_warning(png_ptr, "malformed sPLT chunk");
  171503. return;
  171504. }
  171505. new_palette.depth = *entry_start++;
  171506. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171507. data_length = (slength - (entry_start - chunkdata));
  171508. if (data_length % entry_size)
  171509. {
  171510. png_free(png_ptr, chunkdata);
  171511. png_warning(png_ptr, "sPLT chunk has bad length");
  171512. return;
  171513. }
  171514. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171515. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171516. png_sizeof(png_sPLT_entry)))
  171517. {
  171518. png_warning(png_ptr, "sPLT chunk too long");
  171519. return;
  171520. }
  171521. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171522. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171523. if (new_palette.entries == NULL)
  171524. {
  171525. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171526. return;
  171527. }
  171528. #ifndef PNG_NO_POINTER_INDEXING
  171529. for (i = 0; i < new_palette.nentries; i++)
  171530. {
  171531. png_sPLT_entryp pp = new_palette.entries + i;
  171532. if (new_palette.depth == 8)
  171533. {
  171534. pp->red = *entry_start++;
  171535. pp->green = *entry_start++;
  171536. pp->blue = *entry_start++;
  171537. pp->alpha = *entry_start++;
  171538. }
  171539. else
  171540. {
  171541. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171542. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171543. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171544. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171545. }
  171546. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171547. }
  171548. #else
  171549. pp = new_palette.entries;
  171550. for (i = 0; i < new_palette.nentries; i++)
  171551. {
  171552. if (new_palette.depth == 8)
  171553. {
  171554. pp[i].red = *entry_start++;
  171555. pp[i].green = *entry_start++;
  171556. pp[i].blue = *entry_start++;
  171557. pp[i].alpha = *entry_start++;
  171558. }
  171559. else
  171560. {
  171561. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171562. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171563. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171564. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171565. }
  171566. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171567. }
  171568. #endif
  171569. new_palette.name = (png_charp)chunkdata;
  171570. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171571. png_free(png_ptr, chunkdata);
  171572. png_free(png_ptr, new_palette.entries);
  171573. }
  171574. #endif /* PNG_READ_sPLT_SUPPORTED */
  171575. #if defined(PNG_READ_tRNS_SUPPORTED)
  171576. void /* PRIVATE */
  171577. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171578. {
  171579. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171580. int bit_mask;
  171581. png_debug(1, "in png_handle_tRNS\n");
  171582. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171583. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171584. png_error(png_ptr, "Missing IHDR before tRNS");
  171585. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171586. {
  171587. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171588. png_crc_finish(png_ptr, length);
  171589. return;
  171590. }
  171591. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171592. {
  171593. png_warning(png_ptr, "Duplicate tRNS chunk");
  171594. png_crc_finish(png_ptr, length);
  171595. return;
  171596. }
  171597. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171598. {
  171599. png_byte buf[2];
  171600. if (length != 2)
  171601. {
  171602. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171603. png_crc_finish(png_ptr, length);
  171604. return;
  171605. }
  171606. png_crc_read(png_ptr, buf, 2);
  171607. png_ptr->num_trans = 1;
  171608. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171609. }
  171610. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171611. {
  171612. png_byte buf[6];
  171613. if (length != 6)
  171614. {
  171615. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171616. png_crc_finish(png_ptr, length);
  171617. return;
  171618. }
  171619. png_crc_read(png_ptr, buf, (png_size_t)length);
  171620. png_ptr->num_trans = 1;
  171621. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171622. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171623. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171624. }
  171625. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171626. {
  171627. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171628. {
  171629. png_warning(png_ptr, "Missing PLTE before tRNS");
  171630. }
  171631. if (length > (png_uint_32)png_ptr->num_palette ||
  171632. length > PNG_MAX_PALETTE_LENGTH)
  171633. {
  171634. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171635. png_crc_finish(png_ptr, length);
  171636. return;
  171637. }
  171638. if (length == 0)
  171639. {
  171640. png_warning(png_ptr, "Zero length tRNS chunk");
  171641. png_crc_finish(png_ptr, length);
  171642. return;
  171643. }
  171644. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171645. png_ptr->num_trans = (png_uint_16)length;
  171646. }
  171647. else
  171648. {
  171649. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171650. png_crc_finish(png_ptr, length);
  171651. return;
  171652. }
  171653. if (png_crc_finish(png_ptr, 0))
  171654. {
  171655. png_ptr->num_trans = 0;
  171656. return;
  171657. }
  171658. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171659. &(png_ptr->trans_values));
  171660. }
  171661. #endif
  171662. #if defined(PNG_READ_bKGD_SUPPORTED)
  171663. void /* PRIVATE */
  171664. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171665. {
  171666. png_size_t truelen;
  171667. png_byte buf[6];
  171668. png_debug(1, "in png_handle_bKGD\n");
  171669. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171670. png_error(png_ptr, "Missing IHDR before bKGD");
  171671. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171672. {
  171673. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171674. png_crc_finish(png_ptr, length);
  171675. return;
  171676. }
  171677. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171678. !(png_ptr->mode & PNG_HAVE_PLTE))
  171679. {
  171680. png_warning(png_ptr, "Missing PLTE before bKGD");
  171681. png_crc_finish(png_ptr, length);
  171682. return;
  171683. }
  171684. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171685. {
  171686. png_warning(png_ptr, "Duplicate bKGD chunk");
  171687. png_crc_finish(png_ptr, length);
  171688. return;
  171689. }
  171690. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171691. truelen = 1;
  171692. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171693. truelen = 6;
  171694. else
  171695. truelen = 2;
  171696. if (length != truelen)
  171697. {
  171698. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171699. png_crc_finish(png_ptr, length);
  171700. return;
  171701. }
  171702. png_crc_read(png_ptr, buf, truelen);
  171703. if (png_crc_finish(png_ptr, 0))
  171704. return;
  171705. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171706. {
  171707. png_ptr->background.index = buf[0];
  171708. if(info_ptr->num_palette)
  171709. {
  171710. if(buf[0] > info_ptr->num_palette)
  171711. {
  171712. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171713. return;
  171714. }
  171715. png_ptr->background.red =
  171716. (png_uint_16)png_ptr->palette[buf[0]].red;
  171717. png_ptr->background.green =
  171718. (png_uint_16)png_ptr->palette[buf[0]].green;
  171719. png_ptr->background.blue =
  171720. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171721. }
  171722. }
  171723. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171724. {
  171725. png_ptr->background.red =
  171726. png_ptr->background.green =
  171727. png_ptr->background.blue =
  171728. png_ptr->background.gray = png_get_uint_16(buf);
  171729. }
  171730. else
  171731. {
  171732. png_ptr->background.red = png_get_uint_16(buf);
  171733. png_ptr->background.green = png_get_uint_16(buf + 2);
  171734. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171735. }
  171736. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171737. }
  171738. #endif
  171739. #if defined(PNG_READ_hIST_SUPPORTED)
  171740. void /* PRIVATE */
  171741. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171742. {
  171743. unsigned int num, i;
  171744. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171745. png_debug(1, "in png_handle_hIST\n");
  171746. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171747. png_error(png_ptr, "Missing IHDR before hIST");
  171748. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171749. {
  171750. png_warning(png_ptr, "Invalid hIST after IDAT");
  171751. png_crc_finish(png_ptr, length);
  171752. return;
  171753. }
  171754. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171755. {
  171756. png_warning(png_ptr, "Missing PLTE before hIST");
  171757. png_crc_finish(png_ptr, length);
  171758. return;
  171759. }
  171760. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171761. {
  171762. png_warning(png_ptr, "Duplicate hIST chunk");
  171763. png_crc_finish(png_ptr, length);
  171764. return;
  171765. }
  171766. num = length / 2 ;
  171767. if (num != (unsigned int) png_ptr->num_palette || num >
  171768. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171769. {
  171770. png_warning(png_ptr, "Incorrect hIST chunk length");
  171771. png_crc_finish(png_ptr, length);
  171772. return;
  171773. }
  171774. for (i = 0; i < num; i++)
  171775. {
  171776. png_byte buf[2];
  171777. png_crc_read(png_ptr, buf, 2);
  171778. readbuf[i] = png_get_uint_16(buf);
  171779. }
  171780. if (png_crc_finish(png_ptr, 0))
  171781. return;
  171782. png_set_hIST(png_ptr, info_ptr, readbuf);
  171783. }
  171784. #endif
  171785. #if defined(PNG_READ_pHYs_SUPPORTED)
  171786. void /* PRIVATE */
  171787. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171788. {
  171789. png_byte buf[9];
  171790. png_uint_32 res_x, res_y;
  171791. int unit_type;
  171792. png_debug(1, "in png_handle_pHYs\n");
  171793. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171794. png_error(png_ptr, "Missing IHDR before pHYs");
  171795. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171796. {
  171797. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171798. png_crc_finish(png_ptr, length);
  171799. return;
  171800. }
  171801. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171802. {
  171803. png_warning(png_ptr, "Duplicate pHYs chunk");
  171804. png_crc_finish(png_ptr, length);
  171805. return;
  171806. }
  171807. if (length != 9)
  171808. {
  171809. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171810. png_crc_finish(png_ptr, length);
  171811. return;
  171812. }
  171813. png_crc_read(png_ptr, buf, 9);
  171814. if (png_crc_finish(png_ptr, 0))
  171815. return;
  171816. res_x = png_get_uint_32(buf);
  171817. res_y = png_get_uint_32(buf + 4);
  171818. unit_type = buf[8];
  171819. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171820. }
  171821. #endif
  171822. #if defined(PNG_READ_oFFs_SUPPORTED)
  171823. void /* PRIVATE */
  171824. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171825. {
  171826. png_byte buf[9];
  171827. png_int_32 offset_x, offset_y;
  171828. int unit_type;
  171829. png_debug(1, "in png_handle_oFFs\n");
  171830. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171831. png_error(png_ptr, "Missing IHDR before oFFs");
  171832. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171833. {
  171834. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171835. png_crc_finish(png_ptr, length);
  171836. return;
  171837. }
  171838. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171839. {
  171840. png_warning(png_ptr, "Duplicate oFFs chunk");
  171841. png_crc_finish(png_ptr, length);
  171842. return;
  171843. }
  171844. if (length != 9)
  171845. {
  171846. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171847. png_crc_finish(png_ptr, length);
  171848. return;
  171849. }
  171850. png_crc_read(png_ptr, buf, 9);
  171851. if (png_crc_finish(png_ptr, 0))
  171852. return;
  171853. offset_x = png_get_int_32(buf);
  171854. offset_y = png_get_int_32(buf + 4);
  171855. unit_type = buf[8];
  171856. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171857. }
  171858. #endif
  171859. #if defined(PNG_READ_pCAL_SUPPORTED)
  171860. void /* PRIVATE */
  171861. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171862. {
  171863. png_charp purpose;
  171864. png_int_32 X0, X1;
  171865. png_byte type, nparams;
  171866. png_charp buf, units, endptr;
  171867. png_charpp params;
  171868. png_size_t slength;
  171869. int i;
  171870. png_debug(1, "in png_handle_pCAL\n");
  171871. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171872. png_error(png_ptr, "Missing IHDR before pCAL");
  171873. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171874. {
  171875. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171876. png_crc_finish(png_ptr, length);
  171877. return;
  171878. }
  171879. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171880. {
  171881. png_warning(png_ptr, "Duplicate pCAL chunk");
  171882. png_crc_finish(png_ptr, length);
  171883. return;
  171884. }
  171885. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171886. length + 1);
  171887. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171888. if (purpose == NULL)
  171889. {
  171890. png_warning(png_ptr, "No memory for pCAL purpose.");
  171891. return;
  171892. }
  171893. slength = (png_size_t)length;
  171894. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171895. if (png_crc_finish(png_ptr, 0))
  171896. {
  171897. png_free(png_ptr, purpose);
  171898. return;
  171899. }
  171900. purpose[slength] = 0x00; /* null terminate the last string */
  171901. png_debug(3, "Finding end of pCAL purpose string\n");
  171902. for (buf = purpose; *buf; buf++)
  171903. ;
  171904. endptr = purpose + slength;
  171905. if (endptr <= buf + 12)
  171906. {
  171907. png_warning(png_ptr, "Invalid pCAL data");
  171908. png_free(png_ptr, purpose);
  171909. return;
  171910. }
  171911. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171912. X0 = png_get_int_32((png_bytep)buf+1);
  171913. X1 = png_get_int_32((png_bytep)buf+5);
  171914. type = buf[9];
  171915. nparams = buf[10];
  171916. units = buf + 11;
  171917. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  171918. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  171919. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  171920. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  171921. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  171922. {
  171923. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  171924. png_free(png_ptr, purpose);
  171925. return;
  171926. }
  171927. else if (type >= PNG_EQUATION_LAST)
  171928. {
  171929. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  171930. }
  171931. for (buf = units; *buf; buf++)
  171932. ;
  171933. png_debug(3, "Allocating pCAL parameters array\n");
  171934. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  171935. *png_sizeof(png_charp))) ;
  171936. if (params == NULL)
  171937. {
  171938. png_free(png_ptr, purpose);
  171939. png_warning(png_ptr, "No memory for pCAL params.");
  171940. return;
  171941. }
  171942. for (i = 0; i < (int)nparams; i++)
  171943. {
  171944. buf++; /* Skip the null string terminator from previous parameter. */
  171945. png_debug1(3, "Reading pCAL parameter %d\n", i);
  171946. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  171947. ;
  171948. if (buf > endptr)
  171949. {
  171950. png_warning(png_ptr, "Invalid pCAL data");
  171951. png_free(png_ptr, purpose);
  171952. png_free(png_ptr, params);
  171953. return;
  171954. }
  171955. }
  171956. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  171957. units, params);
  171958. png_free(png_ptr, purpose);
  171959. png_free(png_ptr, params);
  171960. }
  171961. #endif
  171962. #if defined(PNG_READ_sCAL_SUPPORTED)
  171963. void /* PRIVATE */
  171964. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171965. {
  171966. png_charp buffer, ep;
  171967. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171968. double width, height;
  171969. png_charp vp;
  171970. #else
  171971. #ifdef PNG_FIXED_POINT_SUPPORTED
  171972. png_charp swidth, sheight;
  171973. #endif
  171974. #endif
  171975. png_size_t slength;
  171976. png_debug(1, "in png_handle_sCAL\n");
  171977. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171978. png_error(png_ptr, "Missing IHDR before sCAL");
  171979. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171980. {
  171981. png_warning(png_ptr, "Invalid sCAL after IDAT");
  171982. png_crc_finish(png_ptr, length);
  171983. return;
  171984. }
  171985. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  171986. {
  171987. png_warning(png_ptr, "Duplicate sCAL chunk");
  171988. png_crc_finish(png_ptr, length);
  171989. return;
  171990. }
  171991. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  171992. length + 1);
  171993. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171994. if (buffer == NULL)
  171995. {
  171996. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  171997. return;
  171998. }
  171999. slength = (png_size_t)length;
  172000. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172001. if (png_crc_finish(png_ptr, 0))
  172002. {
  172003. png_free(png_ptr, buffer);
  172004. return;
  172005. }
  172006. buffer[slength] = 0x00; /* null terminate the last string */
  172007. ep = buffer + 1; /* skip unit byte */
  172008. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172009. width = png_strtod(png_ptr, ep, &vp);
  172010. if (*vp)
  172011. {
  172012. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172013. return;
  172014. }
  172015. #else
  172016. #ifdef PNG_FIXED_POINT_SUPPORTED
  172017. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172018. if (swidth == NULL)
  172019. {
  172020. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172021. return;
  172022. }
  172023. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172024. #endif
  172025. #endif
  172026. for (ep = buffer; *ep; ep++)
  172027. ;
  172028. ep++;
  172029. if (buffer + slength < ep)
  172030. {
  172031. png_warning(png_ptr, "Truncated sCAL chunk");
  172032. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172033. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172034. png_free(png_ptr, swidth);
  172035. #endif
  172036. png_free(png_ptr, buffer);
  172037. return;
  172038. }
  172039. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172040. height = png_strtod(png_ptr, ep, &vp);
  172041. if (*vp)
  172042. {
  172043. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172044. return;
  172045. }
  172046. #else
  172047. #ifdef PNG_FIXED_POINT_SUPPORTED
  172048. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172049. if (swidth == NULL)
  172050. {
  172051. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172052. return;
  172053. }
  172054. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172055. #endif
  172056. #endif
  172057. if (buffer + slength < ep
  172058. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172059. || width <= 0. || height <= 0.
  172060. #endif
  172061. )
  172062. {
  172063. png_warning(png_ptr, "Invalid sCAL data");
  172064. png_free(png_ptr, buffer);
  172065. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172066. png_free(png_ptr, swidth);
  172067. png_free(png_ptr, sheight);
  172068. #endif
  172069. return;
  172070. }
  172071. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172072. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172073. #else
  172074. #ifdef PNG_FIXED_POINT_SUPPORTED
  172075. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172076. #endif
  172077. #endif
  172078. png_free(png_ptr, buffer);
  172079. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172080. png_free(png_ptr, swidth);
  172081. png_free(png_ptr, sheight);
  172082. #endif
  172083. }
  172084. #endif
  172085. #if defined(PNG_READ_tIME_SUPPORTED)
  172086. void /* PRIVATE */
  172087. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172088. {
  172089. png_byte buf[7];
  172090. png_time mod_time;
  172091. png_debug(1, "in png_handle_tIME\n");
  172092. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172093. png_error(png_ptr, "Out of place tIME chunk");
  172094. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172095. {
  172096. png_warning(png_ptr, "Duplicate tIME chunk");
  172097. png_crc_finish(png_ptr, length);
  172098. return;
  172099. }
  172100. if (png_ptr->mode & PNG_HAVE_IDAT)
  172101. png_ptr->mode |= PNG_AFTER_IDAT;
  172102. if (length != 7)
  172103. {
  172104. png_warning(png_ptr, "Incorrect tIME chunk length");
  172105. png_crc_finish(png_ptr, length);
  172106. return;
  172107. }
  172108. png_crc_read(png_ptr, buf, 7);
  172109. if (png_crc_finish(png_ptr, 0))
  172110. return;
  172111. mod_time.second = buf[6];
  172112. mod_time.minute = buf[5];
  172113. mod_time.hour = buf[4];
  172114. mod_time.day = buf[3];
  172115. mod_time.month = buf[2];
  172116. mod_time.year = png_get_uint_16(buf);
  172117. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172118. }
  172119. #endif
  172120. #if defined(PNG_READ_tEXt_SUPPORTED)
  172121. void /* PRIVATE */
  172122. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172123. {
  172124. png_textp text_ptr;
  172125. png_charp key;
  172126. png_charp text;
  172127. png_uint_32 skip = 0;
  172128. png_size_t slength;
  172129. int ret;
  172130. png_debug(1, "in png_handle_tEXt\n");
  172131. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172132. png_error(png_ptr, "Missing IHDR before tEXt");
  172133. if (png_ptr->mode & PNG_HAVE_IDAT)
  172134. png_ptr->mode |= PNG_AFTER_IDAT;
  172135. #ifdef PNG_MAX_MALLOC_64K
  172136. if (length > (png_uint_32)65535L)
  172137. {
  172138. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172139. skip = length - (png_uint_32)65535L;
  172140. length = (png_uint_32)65535L;
  172141. }
  172142. #endif
  172143. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172144. if (key == NULL)
  172145. {
  172146. png_warning(png_ptr, "No memory to process text chunk.");
  172147. return;
  172148. }
  172149. slength = (png_size_t)length;
  172150. png_crc_read(png_ptr, (png_bytep)key, slength);
  172151. if (png_crc_finish(png_ptr, skip))
  172152. {
  172153. png_free(png_ptr, key);
  172154. return;
  172155. }
  172156. key[slength] = 0x00;
  172157. for (text = key; *text; text++)
  172158. ;
  172159. if (text != key + slength)
  172160. text++;
  172161. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172162. (png_uint_32)png_sizeof(png_text));
  172163. if (text_ptr == NULL)
  172164. {
  172165. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172166. png_free(png_ptr, key);
  172167. return;
  172168. }
  172169. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172170. text_ptr->key = key;
  172171. #ifdef PNG_iTXt_SUPPORTED
  172172. text_ptr->lang = NULL;
  172173. text_ptr->lang_key = NULL;
  172174. text_ptr->itxt_length = 0;
  172175. #endif
  172176. text_ptr->text = text;
  172177. text_ptr->text_length = png_strlen(text);
  172178. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172179. png_free(png_ptr, key);
  172180. png_free(png_ptr, text_ptr);
  172181. if (ret)
  172182. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172183. }
  172184. #endif
  172185. #if defined(PNG_READ_zTXt_SUPPORTED)
  172186. void /* PRIVATE */
  172187. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172188. {
  172189. png_textp text_ptr;
  172190. png_charp chunkdata;
  172191. png_charp text;
  172192. int comp_type;
  172193. int ret;
  172194. png_size_t slength, prefix_len, data_len;
  172195. png_debug(1, "in png_handle_zTXt\n");
  172196. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172197. png_error(png_ptr, "Missing IHDR before zTXt");
  172198. if (png_ptr->mode & PNG_HAVE_IDAT)
  172199. png_ptr->mode |= PNG_AFTER_IDAT;
  172200. #ifdef PNG_MAX_MALLOC_64K
  172201. if (length > (png_uint_32)65535L)
  172202. {
  172203. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172204. png_crc_finish(png_ptr, length);
  172205. return;
  172206. }
  172207. #endif
  172208. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172209. if (chunkdata == NULL)
  172210. {
  172211. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172212. return;
  172213. }
  172214. slength = (png_size_t)length;
  172215. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172216. if (png_crc_finish(png_ptr, 0))
  172217. {
  172218. png_free(png_ptr, chunkdata);
  172219. return;
  172220. }
  172221. chunkdata[slength] = 0x00;
  172222. for (text = chunkdata; *text; text++)
  172223. ;
  172224. if (text >= chunkdata + slength - 2)
  172225. {
  172226. png_warning(png_ptr, "Truncated zTXt chunk");
  172227. png_free(png_ptr, chunkdata);
  172228. return;
  172229. }
  172230. else
  172231. {
  172232. comp_type = *(++text);
  172233. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172234. {
  172235. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172236. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172237. }
  172238. text++; /* skip the compression_method byte */
  172239. }
  172240. prefix_len = text - chunkdata;
  172241. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172242. (png_size_t)length, prefix_len, &data_len);
  172243. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172244. (png_uint_32)png_sizeof(png_text));
  172245. if (text_ptr == NULL)
  172246. {
  172247. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172248. png_free(png_ptr, chunkdata);
  172249. return;
  172250. }
  172251. text_ptr->compression = comp_type;
  172252. text_ptr->key = chunkdata;
  172253. #ifdef PNG_iTXt_SUPPORTED
  172254. text_ptr->lang = NULL;
  172255. text_ptr->lang_key = NULL;
  172256. text_ptr->itxt_length = 0;
  172257. #endif
  172258. text_ptr->text = chunkdata + prefix_len;
  172259. text_ptr->text_length = data_len;
  172260. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172261. png_free(png_ptr, text_ptr);
  172262. png_free(png_ptr, chunkdata);
  172263. if (ret)
  172264. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172265. }
  172266. #endif
  172267. #if defined(PNG_READ_iTXt_SUPPORTED)
  172268. void /* PRIVATE */
  172269. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172270. {
  172271. png_textp text_ptr;
  172272. png_charp chunkdata;
  172273. png_charp key, lang, text, lang_key;
  172274. int comp_flag;
  172275. int comp_type = 0;
  172276. int ret;
  172277. png_size_t slength, prefix_len, data_len;
  172278. png_debug(1, "in png_handle_iTXt\n");
  172279. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172280. png_error(png_ptr, "Missing IHDR before iTXt");
  172281. if (png_ptr->mode & PNG_HAVE_IDAT)
  172282. png_ptr->mode |= PNG_AFTER_IDAT;
  172283. #ifdef PNG_MAX_MALLOC_64K
  172284. if (length > (png_uint_32)65535L)
  172285. {
  172286. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172287. png_crc_finish(png_ptr, length);
  172288. return;
  172289. }
  172290. #endif
  172291. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172292. if (chunkdata == NULL)
  172293. {
  172294. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172295. return;
  172296. }
  172297. slength = (png_size_t)length;
  172298. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172299. if (png_crc_finish(png_ptr, 0))
  172300. {
  172301. png_free(png_ptr, chunkdata);
  172302. return;
  172303. }
  172304. chunkdata[slength] = 0x00;
  172305. for (lang = chunkdata; *lang; lang++)
  172306. ;
  172307. lang++; /* skip NUL separator */
  172308. if (lang >= chunkdata + slength - 3)
  172309. {
  172310. png_warning(png_ptr, "Truncated iTXt chunk");
  172311. png_free(png_ptr, chunkdata);
  172312. return;
  172313. }
  172314. else
  172315. {
  172316. comp_flag = *lang++;
  172317. comp_type = *lang++;
  172318. }
  172319. for (lang_key = lang; *lang_key; lang_key++)
  172320. ;
  172321. lang_key++; /* skip NUL separator */
  172322. if (lang_key >= chunkdata + slength)
  172323. {
  172324. png_warning(png_ptr, "Truncated iTXt chunk");
  172325. png_free(png_ptr, chunkdata);
  172326. return;
  172327. }
  172328. for (text = lang_key; *text; text++)
  172329. ;
  172330. text++; /* skip NUL separator */
  172331. if (text >= chunkdata + slength)
  172332. {
  172333. png_warning(png_ptr, "Malformed iTXt chunk");
  172334. png_free(png_ptr, chunkdata);
  172335. return;
  172336. }
  172337. prefix_len = text - chunkdata;
  172338. key=chunkdata;
  172339. if (comp_flag)
  172340. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172341. (size_t)length, prefix_len, &data_len);
  172342. else
  172343. data_len=png_strlen(chunkdata + prefix_len);
  172344. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172345. (png_uint_32)png_sizeof(png_text));
  172346. if (text_ptr == NULL)
  172347. {
  172348. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172349. png_free(png_ptr, chunkdata);
  172350. return;
  172351. }
  172352. text_ptr->compression = (int)comp_flag + 1;
  172353. text_ptr->lang_key = chunkdata+(lang_key-key);
  172354. text_ptr->lang = chunkdata+(lang-key);
  172355. text_ptr->itxt_length = data_len;
  172356. text_ptr->text_length = 0;
  172357. text_ptr->key = chunkdata;
  172358. text_ptr->text = chunkdata + prefix_len;
  172359. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172360. png_free(png_ptr, text_ptr);
  172361. png_free(png_ptr, chunkdata);
  172362. if (ret)
  172363. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172364. }
  172365. #endif
  172366. void /* PRIVATE */
  172367. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172368. {
  172369. png_uint_32 skip = 0;
  172370. png_debug(1, "in png_handle_unknown\n");
  172371. if (png_ptr->mode & PNG_HAVE_IDAT)
  172372. {
  172373. #ifdef PNG_USE_LOCAL_ARRAYS
  172374. PNG_CONST PNG_IDAT;
  172375. #endif
  172376. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172377. png_ptr->mode |= PNG_AFTER_IDAT;
  172378. }
  172379. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172380. if (!(png_ptr->chunk_name[0] & 0x20))
  172381. {
  172382. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172383. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172384. PNG_HANDLE_CHUNK_ALWAYS
  172385. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172386. && png_ptr->read_user_chunk_fn == NULL
  172387. #endif
  172388. )
  172389. #endif
  172390. png_chunk_error(png_ptr, "unknown critical chunk");
  172391. }
  172392. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172393. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172394. (png_ptr->read_user_chunk_fn != NULL))
  172395. {
  172396. #ifdef PNG_MAX_MALLOC_64K
  172397. if (length > (png_uint_32)65535L)
  172398. {
  172399. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172400. skip = length - (png_uint_32)65535L;
  172401. length = (png_uint_32)65535L;
  172402. }
  172403. #endif
  172404. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172405. (png_charp)png_ptr->chunk_name, 5);
  172406. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172407. png_ptr->unknown_chunk.size = (png_size_t)length;
  172408. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172409. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172410. if(png_ptr->read_user_chunk_fn != NULL)
  172411. {
  172412. int ret;
  172413. ret = (*(png_ptr->read_user_chunk_fn))
  172414. (png_ptr, &png_ptr->unknown_chunk);
  172415. if (ret < 0)
  172416. png_chunk_error(png_ptr, "error in user chunk");
  172417. if (ret == 0)
  172418. {
  172419. if (!(png_ptr->chunk_name[0] & 0x20))
  172420. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172421. PNG_HANDLE_CHUNK_ALWAYS)
  172422. png_chunk_error(png_ptr, "unknown critical chunk");
  172423. png_set_unknown_chunks(png_ptr, info_ptr,
  172424. &png_ptr->unknown_chunk, 1);
  172425. }
  172426. }
  172427. #else
  172428. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172429. #endif
  172430. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172431. png_ptr->unknown_chunk.data = NULL;
  172432. }
  172433. else
  172434. #endif
  172435. skip = length;
  172436. png_crc_finish(png_ptr, skip);
  172437. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172438. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172439. #endif
  172440. }
  172441. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172442. void /* PRIVATE */
  172443. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172444. {
  172445. png_debug(1, "in png_check_chunk_name\n");
  172446. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172447. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172448. {
  172449. png_chunk_error(png_ptr, "invalid chunk type");
  172450. }
  172451. }
  172452. void /* PRIVATE */
  172453. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172454. {
  172455. png_debug(1,"in png_combine_row\n");
  172456. if (mask == 0xff)
  172457. {
  172458. png_memcpy(row, png_ptr->row_buf + 1,
  172459. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172460. }
  172461. else
  172462. {
  172463. switch (png_ptr->row_info.pixel_depth)
  172464. {
  172465. case 1:
  172466. {
  172467. png_bytep sp = png_ptr->row_buf + 1;
  172468. png_bytep dp = row;
  172469. int s_inc, s_start, s_end;
  172470. int m = 0x80;
  172471. int shift;
  172472. png_uint_32 i;
  172473. png_uint_32 row_width = png_ptr->width;
  172474. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172475. if (png_ptr->transformations & PNG_PACKSWAP)
  172476. {
  172477. s_start = 0;
  172478. s_end = 7;
  172479. s_inc = 1;
  172480. }
  172481. else
  172482. #endif
  172483. {
  172484. s_start = 7;
  172485. s_end = 0;
  172486. s_inc = -1;
  172487. }
  172488. shift = s_start;
  172489. for (i = 0; i < row_width; i++)
  172490. {
  172491. if (m & mask)
  172492. {
  172493. int value;
  172494. value = (*sp >> shift) & 0x01;
  172495. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172496. *dp |= (png_byte)(value << shift);
  172497. }
  172498. if (shift == s_end)
  172499. {
  172500. shift = s_start;
  172501. sp++;
  172502. dp++;
  172503. }
  172504. else
  172505. shift += s_inc;
  172506. if (m == 1)
  172507. m = 0x80;
  172508. else
  172509. m >>= 1;
  172510. }
  172511. break;
  172512. }
  172513. case 2:
  172514. {
  172515. png_bytep sp = png_ptr->row_buf + 1;
  172516. png_bytep dp = row;
  172517. int s_start, s_end, s_inc;
  172518. int m = 0x80;
  172519. int shift;
  172520. png_uint_32 i;
  172521. png_uint_32 row_width = png_ptr->width;
  172522. int value;
  172523. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172524. if (png_ptr->transformations & PNG_PACKSWAP)
  172525. {
  172526. s_start = 0;
  172527. s_end = 6;
  172528. s_inc = 2;
  172529. }
  172530. else
  172531. #endif
  172532. {
  172533. s_start = 6;
  172534. s_end = 0;
  172535. s_inc = -2;
  172536. }
  172537. shift = s_start;
  172538. for (i = 0; i < row_width; i++)
  172539. {
  172540. if (m & mask)
  172541. {
  172542. value = (*sp >> shift) & 0x03;
  172543. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172544. *dp |= (png_byte)(value << shift);
  172545. }
  172546. if (shift == s_end)
  172547. {
  172548. shift = s_start;
  172549. sp++;
  172550. dp++;
  172551. }
  172552. else
  172553. shift += s_inc;
  172554. if (m == 1)
  172555. m = 0x80;
  172556. else
  172557. m >>= 1;
  172558. }
  172559. break;
  172560. }
  172561. case 4:
  172562. {
  172563. png_bytep sp = png_ptr->row_buf + 1;
  172564. png_bytep dp = row;
  172565. int s_start, s_end, s_inc;
  172566. int m = 0x80;
  172567. int shift;
  172568. png_uint_32 i;
  172569. png_uint_32 row_width = png_ptr->width;
  172570. int value;
  172571. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172572. if (png_ptr->transformations & PNG_PACKSWAP)
  172573. {
  172574. s_start = 0;
  172575. s_end = 4;
  172576. s_inc = 4;
  172577. }
  172578. else
  172579. #endif
  172580. {
  172581. s_start = 4;
  172582. s_end = 0;
  172583. s_inc = -4;
  172584. }
  172585. shift = s_start;
  172586. for (i = 0; i < row_width; i++)
  172587. {
  172588. if (m & mask)
  172589. {
  172590. value = (*sp >> shift) & 0xf;
  172591. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172592. *dp |= (png_byte)(value << shift);
  172593. }
  172594. if (shift == s_end)
  172595. {
  172596. shift = s_start;
  172597. sp++;
  172598. dp++;
  172599. }
  172600. else
  172601. shift += s_inc;
  172602. if (m == 1)
  172603. m = 0x80;
  172604. else
  172605. m >>= 1;
  172606. }
  172607. break;
  172608. }
  172609. default:
  172610. {
  172611. png_bytep sp = png_ptr->row_buf + 1;
  172612. png_bytep dp = row;
  172613. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172614. png_uint_32 i;
  172615. png_uint_32 row_width = png_ptr->width;
  172616. png_byte m = 0x80;
  172617. for (i = 0; i < row_width; i++)
  172618. {
  172619. if (m & mask)
  172620. {
  172621. png_memcpy(dp, sp, pixel_bytes);
  172622. }
  172623. sp += pixel_bytes;
  172624. dp += pixel_bytes;
  172625. if (m == 1)
  172626. m = 0x80;
  172627. else
  172628. m >>= 1;
  172629. }
  172630. break;
  172631. }
  172632. }
  172633. }
  172634. }
  172635. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172636. void /* PRIVATE */
  172637. png_do_read_interlace(png_structp png_ptr)
  172638. {
  172639. png_row_infop row_info = &(png_ptr->row_info);
  172640. png_bytep row = png_ptr->row_buf + 1;
  172641. int pass = png_ptr->pass;
  172642. png_uint_32 transformations = png_ptr->transformations;
  172643. #ifdef PNG_USE_LOCAL_ARRAYS
  172644. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172645. #endif
  172646. png_debug(1,"in png_do_read_interlace\n");
  172647. if (row != NULL && row_info != NULL)
  172648. {
  172649. png_uint_32 final_width;
  172650. final_width = row_info->width * png_pass_inc[pass];
  172651. switch (row_info->pixel_depth)
  172652. {
  172653. case 1:
  172654. {
  172655. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172656. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172657. int sshift, dshift;
  172658. int s_start, s_end, s_inc;
  172659. int jstop = png_pass_inc[pass];
  172660. png_byte v;
  172661. png_uint_32 i;
  172662. int j;
  172663. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172664. if (transformations & PNG_PACKSWAP)
  172665. {
  172666. sshift = (int)((row_info->width + 7) & 0x07);
  172667. dshift = (int)((final_width + 7) & 0x07);
  172668. s_start = 7;
  172669. s_end = 0;
  172670. s_inc = -1;
  172671. }
  172672. else
  172673. #endif
  172674. {
  172675. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172676. dshift = 7 - (int)((final_width + 7) & 0x07);
  172677. s_start = 0;
  172678. s_end = 7;
  172679. s_inc = 1;
  172680. }
  172681. for (i = 0; i < row_info->width; i++)
  172682. {
  172683. v = (png_byte)((*sp >> sshift) & 0x01);
  172684. for (j = 0; j < jstop; j++)
  172685. {
  172686. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172687. *dp |= (png_byte)(v << dshift);
  172688. if (dshift == s_end)
  172689. {
  172690. dshift = s_start;
  172691. dp--;
  172692. }
  172693. else
  172694. dshift += s_inc;
  172695. }
  172696. if (sshift == s_end)
  172697. {
  172698. sshift = s_start;
  172699. sp--;
  172700. }
  172701. else
  172702. sshift += s_inc;
  172703. }
  172704. break;
  172705. }
  172706. case 2:
  172707. {
  172708. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172709. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172710. int sshift, dshift;
  172711. int s_start, s_end, s_inc;
  172712. int jstop = png_pass_inc[pass];
  172713. png_uint_32 i;
  172714. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172715. if (transformations & PNG_PACKSWAP)
  172716. {
  172717. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172718. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172719. s_start = 6;
  172720. s_end = 0;
  172721. s_inc = -2;
  172722. }
  172723. else
  172724. #endif
  172725. {
  172726. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172727. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172728. s_start = 0;
  172729. s_end = 6;
  172730. s_inc = 2;
  172731. }
  172732. for (i = 0; i < row_info->width; i++)
  172733. {
  172734. png_byte v;
  172735. int j;
  172736. v = (png_byte)((*sp >> sshift) & 0x03);
  172737. for (j = 0; j < jstop; j++)
  172738. {
  172739. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172740. *dp |= (png_byte)(v << dshift);
  172741. if (dshift == s_end)
  172742. {
  172743. dshift = s_start;
  172744. dp--;
  172745. }
  172746. else
  172747. dshift += s_inc;
  172748. }
  172749. if (sshift == s_end)
  172750. {
  172751. sshift = s_start;
  172752. sp--;
  172753. }
  172754. else
  172755. sshift += s_inc;
  172756. }
  172757. break;
  172758. }
  172759. case 4:
  172760. {
  172761. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172762. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172763. int sshift, dshift;
  172764. int s_start, s_end, s_inc;
  172765. png_uint_32 i;
  172766. int jstop = png_pass_inc[pass];
  172767. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172768. if (transformations & PNG_PACKSWAP)
  172769. {
  172770. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172771. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172772. s_start = 4;
  172773. s_end = 0;
  172774. s_inc = -4;
  172775. }
  172776. else
  172777. #endif
  172778. {
  172779. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172780. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172781. s_start = 0;
  172782. s_end = 4;
  172783. s_inc = 4;
  172784. }
  172785. for (i = 0; i < row_info->width; i++)
  172786. {
  172787. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172788. int j;
  172789. for (j = 0; j < jstop; j++)
  172790. {
  172791. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172792. *dp |= (png_byte)(v << dshift);
  172793. if (dshift == s_end)
  172794. {
  172795. dshift = s_start;
  172796. dp--;
  172797. }
  172798. else
  172799. dshift += s_inc;
  172800. }
  172801. if (sshift == s_end)
  172802. {
  172803. sshift = s_start;
  172804. sp--;
  172805. }
  172806. else
  172807. sshift += s_inc;
  172808. }
  172809. break;
  172810. }
  172811. default:
  172812. {
  172813. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172814. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172815. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172816. int jstop = png_pass_inc[pass];
  172817. png_uint_32 i;
  172818. for (i = 0; i < row_info->width; i++)
  172819. {
  172820. png_byte v[8];
  172821. int j;
  172822. png_memcpy(v, sp, pixel_bytes);
  172823. for (j = 0; j < jstop; j++)
  172824. {
  172825. png_memcpy(dp, v, pixel_bytes);
  172826. dp -= pixel_bytes;
  172827. }
  172828. sp -= pixel_bytes;
  172829. }
  172830. break;
  172831. }
  172832. }
  172833. row_info->width = final_width;
  172834. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172835. }
  172836. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172837. transformations = transformations; /* silence compiler warning */
  172838. #endif
  172839. }
  172840. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172841. void /* PRIVATE */
  172842. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172843. png_bytep prev_row, int filter)
  172844. {
  172845. png_debug(1, "in png_read_filter_row\n");
  172846. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172847. switch (filter)
  172848. {
  172849. case PNG_FILTER_VALUE_NONE:
  172850. break;
  172851. case PNG_FILTER_VALUE_SUB:
  172852. {
  172853. png_uint_32 i;
  172854. png_uint_32 istop = row_info->rowbytes;
  172855. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172856. png_bytep rp = row + bpp;
  172857. png_bytep lp = row;
  172858. for (i = bpp; i < istop; i++)
  172859. {
  172860. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172861. rp++;
  172862. }
  172863. break;
  172864. }
  172865. case PNG_FILTER_VALUE_UP:
  172866. {
  172867. png_uint_32 i;
  172868. png_uint_32 istop = row_info->rowbytes;
  172869. png_bytep rp = row;
  172870. png_bytep pp = prev_row;
  172871. for (i = 0; i < istop; i++)
  172872. {
  172873. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172874. rp++;
  172875. }
  172876. break;
  172877. }
  172878. case PNG_FILTER_VALUE_AVG:
  172879. {
  172880. png_uint_32 i;
  172881. png_bytep rp = row;
  172882. png_bytep pp = prev_row;
  172883. png_bytep lp = row;
  172884. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172885. png_uint_32 istop = row_info->rowbytes - bpp;
  172886. for (i = 0; i < bpp; i++)
  172887. {
  172888. *rp = (png_byte)(((int)(*rp) +
  172889. ((int)(*pp++) / 2 )) & 0xff);
  172890. rp++;
  172891. }
  172892. for (i = 0; i < istop; i++)
  172893. {
  172894. *rp = (png_byte)(((int)(*rp) +
  172895. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172896. rp++;
  172897. }
  172898. break;
  172899. }
  172900. case PNG_FILTER_VALUE_PAETH:
  172901. {
  172902. png_uint_32 i;
  172903. png_bytep rp = row;
  172904. png_bytep pp = prev_row;
  172905. png_bytep lp = row;
  172906. png_bytep cp = prev_row;
  172907. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172908. png_uint_32 istop=row_info->rowbytes - bpp;
  172909. for (i = 0; i < bpp; i++)
  172910. {
  172911. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172912. rp++;
  172913. }
  172914. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172915. {
  172916. int a, b, c, pa, pb, pc, p;
  172917. a = *lp++;
  172918. b = *pp++;
  172919. c = *cp++;
  172920. p = b - c;
  172921. pc = a - c;
  172922. #ifdef PNG_USE_ABS
  172923. pa = abs(p);
  172924. pb = abs(pc);
  172925. pc = abs(p + pc);
  172926. #else
  172927. pa = p < 0 ? -p : p;
  172928. pb = pc < 0 ? -pc : pc;
  172929. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  172930. #endif
  172931. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  172932. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  172933. rp++;
  172934. }
  172935. break;
  172936. }
  172937. default:
  172938. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  172939. *row=0;
  172940. break;
  172941. }
  172942. }
  172943. void /* PRIVATE */
  172944. png_read_finish_row(png_structp png_ptr)
  172945. {
  172946. #ifdef PNG_USE_LOCAL_ARRAYS
  172947. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  172948. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172949. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  172950. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  172951. #endif
  172952. png_debug(1, "in png_read_finish_row\n");
  172953. png_ptr->row_number++;
  172954. if (png_ptr->row_number < png_ptr->num_rows)
  172955. return;
  172956. if (png_ptr->interlaced)
  172957. {
  172958. png_ptr->row_number = 0;
  172959. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  172960. png_ptr->rowbytes + 1);
  172961. do
  172962. {
  172963. png_ptr->pass++;
  172964. if (png_ptr->pass >= 7)
  172965. break;
  172966. png_ptr->iwidth = (png_ptr->width +
  172967. png_pass_inc[png_ptr->pass] - 1 -
  172968. png_pass_start[png_ptr->pass]) /
  172969. png_pass_inc[png_ptr->pass];
  172970. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  172971. png_ptr->iwidth) + 1;
  172972. if (!(png_ptr->transformations & PNG_INTERLACE))
  172973. {
  172974. png_ptr->num_rows = (png_ptr->height +
  172975. png_pass_yinc[png_ptr->pass] - 1 -
  172976. png_pass_ystart[png_ptr->pass]) /
  172977. png_pass_yinc[png_ptr->pass];
  172978. if (!(png_ptr->num_rows))
  172979. continue;
  172980. }
  172981. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  172982. break;
  172983. } while (png_ptr->iwidth == 0);
  172984. if (png_ptr->pass < 7)
  172985. return;
  172986. }
  172987. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  172988. {
  172989. #ifdef PNG_USE_LOCAL_ARRAYS
  172990. PNG_CONST PNG_IDAT;
  172991. #endif
  172992. char extra;
  172993. int ret;
  172994. png_ptr->zstream.next_out = (Bytef *)&extra;
  172995. png_ptr->zstream.avail_out = (uInt)1;
  172996. for(;;)
  172997. {
  172998. if (!(png_ptr->zstream.avail_in))
  172999. {
  173000. while (!png_ptr->idat_size)
  173001. {
  173002. png_byte chunk_length[4];
  173003. png_crc_finish(png_ptr, 0);
  173004. png_read_data(png_ptr, chunk_length, 4);
  173005. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173006. png_reset_crc(png_ptr);
  173007. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173008. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173009. png_error(png_ptr, "Not enough image data");
  173010. }
  173011. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173012. png_ptr->zstream.next_in = png_ptr->zbuf;
  173013. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173014. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173015. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173016. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173017. }
  173018. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173019. if (ret == Z_STREAM_END)
  173020. {
  173021. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173022. png_ptr->idat_size)
  173023. png_warning(png_ptr, "Extra compressed data");
  173024. png_ptr->mode |= PNG_AFTER_IDAT;
  173025. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173026. break;
  173027. }
  173028. if (ret != Z_OK)
  173029. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173030. "Decompression Error");
  173031. if (!(png_ptr->zstream.avail_out))
  173032. {
  173033. png_warning(png_ptr, "Extra compressed data.");
  173034. png_ptr->mode |= PNG_AFTER_IDAT;
  173035. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173036. break;
  173037. }
  173038. }
  173039. png_ptr->zstream.avail_out = 0;
  173040. }
  173041. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173042. png_warning(png_ptr, "Extra compression data");
  173043. inflateReset(&png_ptr->zstream);
  173044. png_ptr->mode |= PNG_AFTER_IDAT;
  173045. }
  173046. void /* PRIVATE */
  173047. png_read_start_row(png_structp png_ptr)
  173048. {
  173049. #ifdef PNG_USE_LOCAL_ARRAYS
  173050. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173051. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173052. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173053. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173054. #endif
  173055. int max_pixel_depth;
  173056. png_uint_32 row_bytes;
  173057. png_debug(1, "in png_read_start_row\n");
  173058. png_ptr->zstream.avail_in = 0;
  173059. png_init_read_transformations(png_ptr);
  173060. if (png_ptr->interlaced)
  173061. {
  173062. if (!(png_ptr->transformations & PNG_INTERLACE))
  173063. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173064. png_pass_ystart[0]) / png_pass_yinc[0];
  173065. else
  173066. png_ptr->num_rows = png_ptr->height;
  173067. png_ptr->iwidth = (png_ptr->width +
  173068. png_pass_inc[png_ptr->pass] - 1 -
  173069. png_pass_start[png_ptr->pass]) /
  173070. png_pass_inc[png_ptr->pass];
  173071. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173072. png_ptr->irowbytes = (png_size_t)row_bytes;
  173073. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173074. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173075. }
  173076. else
  173077. {
  173078. png_ptr->num_rows = png_ptr->height;
  173079. png_ptr->iwidth = png_ptr->width;
  173080. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173081. }
  173082. max_pixel_depth = png_ptr->pixel_depth;
  173083. #if defined(PNG_READ_PACK_SUPPORTED)
  173084. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173085. max_pixel_depth = 8;
  173086. #endif
  173087. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173088. if (png_ptr->transformations & PNG_EXPAND)
  173089. {
  173090. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173091. {
  173092. if (png_ptr->num_trans)
  173093. max_pixel_depth = 32;
  173094. else
  173095. max_pixel_depth = 24;
  173096. }
  173097. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173098. {
  173099. if (max_pixel_depth < 8)
  173100. max_pixel_depth = 8;
  173101. if (png_ptr->num_trans)
  173102. max_pixel_depth *= 2;
  173103. }
  173104. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173105. {
  173106. if (png_ptr->num_trans)
  173107. {
  173108. max_pixel_depth *= 4;
  173109. max_pixel_depth /= 3;
  173110. }
  173111. }
  173112. }
  173113. #endif
  173114. #if defined(PNG_READ_FILLER_SUPPORTED)
  173115. if (png_ptr->transformations & (PNG_FILLER))
  173116. {
  173117. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173118. max_pixel_depth = 32;
  173119. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173120. {
  173121. if (max_pixel_depth <= 8)
  173122. max_pixel_depth = 16;
  173123. else
  173124. max_pixel_depth = 32;
  173125. }
  173126. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173127. {
  173128. if (max_pixel_depth <= 32)
  173129. max_pixel_depth = 32;
  173130. else
  173131. max_pixel_depth = 64;
  173132. }
  173133. }
  173134. #endif
  173135. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173136. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173137. {
  173138. if (
  173139. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173140. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173141. #endif
  173142. #if defined(PNG_READ_FILLER_SUPPORTED)
  173143. (png_ptr->transformations & (PNG_FILLER)) ||
  173144. #endif
  173145. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173146. {
  173147. if (max_pixel_depth <= 16)
  173148. max_pixel_depth = 32;
  173149. else
  173150. max_pixel_depth = 64;
  173151. }
  173152. else
  173153. {
  173154. if (max_pixel_depth <= 8)
  173155. {
  173156. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173157. max_pixel_depth = 32;
  173158. else
  173159. max_pixel_depth = 24;
  173160. }
  173161. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173162. max_pixel_depth = 64;
  173163. else
  173164. max_pixel_depth = 48;
  173165. }
  173166. }
  173167. #endif
  173168. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173169. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173170. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173171. {
  173172. int user_pixel_depth=png_ptr->user_transform_depth*
  173173. png_ptr->user_transform_channels;
  173174. if(user_pixel_depth > max_pixel_depth)
  173175. max_pixel_depth=user_pixel_depth;
  173176. }
  173177. #endif
  173178. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173179. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173180. 1 + ((max_pixel_depth + 7) >> 3);
  173181. #ifdef PNG_MAX_MALLOC_64K
  173182. if (row_bytes > (png_uint_32)65536L)
  173183. png_error(png_ptr, "This image requires a row greater than 64KB");
  173184. #endif
  173185. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173186. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173187. #ifdef PNG_MAX_MALLOC_64K
  173188. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173189. png_error(png_ptr, "This image requires a row greater than 64KB");
  173190. #endif
  173191. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173192. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173193. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173194. png_ptr->rowbytes + 1));
  173195. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173196. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173197. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173198. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173199. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173200. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173201. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173202. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173203. }
  173204. #endif /* PNG_READ_SUPPORTED */
  173205. /*** End of inlined file: pngrutil.c ***/
  173206. /*** Start of inlined file: pngset.c ***/
  173207. #define PNG_INTERNAL
  173208. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173209. #if defined(PNG_bKGD_SUPPORTED)
  173210. void PNGAPI
  173211. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173212. {
  173213. png_debug1(1, "in %s storage function\n", "bKGD");
  173214. if (png_ptr == NULL || info_ptr == NULL)
  173215. return;
  173216. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173217. info_ptr->valid |= PNG_INFO_bKGD;
  173218. }
  173219. #endif
  173220. #if defined(PNG_cHRM_SUPPORTED)
  173221. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173222. void PNGAPI
  173223. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173224. double white_x, double white_y, double red_x, double red_y,
  173225. double green_x, double green_y, double blue_x, double blue_y)
  173226. {
  173227. png_debug1(1, "in %s storage function\n", "cHRM");
  173228. if (png_ptr == NULL || info_ptr == NULL)
  173229. return;
  173230. if (white_x < 0.0 || white_y < 0.0 ||
  173231. red_x < 0.0 || red_y < 0.0 ||
  173232. green_x < 0.0 || green_y < 0.0 ||
  173233. blue_x < 0.0 || blue_y < 0.0)
  173234. {
  173235. png_warning(png_ptr,
  173236. "Ignoring attempt to set negative chromaticity value");
  173237. return;
  173238. }
  173239. if (white_x > 21474.83 || white_y > 21474.83 ||
  173240. red_x > 21474.83 || red_y > 21474.83 ||
  173241. green_x > 21474.83 || green_y > 21474.83 ||
  173242. blue_x > 21474.83 || blue_y > 21474.83)
  173243. {
  173244. png_warning(png_ptr,
  173245. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173246. return;
  173247. }
  173248. info_ptr->x_white = (float)white_x;
  173249. info_ptr->y_white = (float)white_y;
  173250. info_ptr->x_red = (float)red_x;
  173251. info_ptr->y_red = (float)red_y;
  173252. info_ptr->x_green = (float)green_x;
  173253. info_ptr->y_green = (float)green_y;
  173254. info_ptr->x_blue = (float)blue_x;
  173255. info_ptr->y_blue = (float)blue_y;
  173256. #ifdef PNG_FIXED_POINT_SUPPORTED
  173257. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173258. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173259. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173260. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173261. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173262. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173263. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173264. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173265. #endif
  173266. info_ptr->valid |= PNG_INFO_cHRM;
  173267. }
  173268. #endif
  173269. #ifdef PNG_FIXED_POINT_SUPPORTED
  173270. void PNGAPI
  173271. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173272. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173273. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173274. png_fixed_point blue_x, png_fixed_point blue_y)
  173275. {
  173276. png_debug1(1, "in %s storage function\n", "cHRM");
  173277. if (png_ptr == NULL || info_ptr == NULL)
  173278. return;
  173279. if (white_x < 0 || white_y < 0 ||
  173280. red_x < 0 || red_y < 0 ||
  173281. green_x < 0 || green_y < 0 ||
  173282. blue_x < 0 || blue_y < 0)
  173283. {
  173284. png_warning(png_ptr,
  173285. "Ignoring attempt to set negative chromaticity value");
  173286. return;
  173287. }
  173288. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173289. if (white_x > (double) PNG_UINT_31_MAX ||
  173290. white_y > (double) PNG_UINT_31_MAX ||
  173291. red_x > (double) PNG_UINT_31_MAX ||
  173292. red_y > (double) PNG_UINT_31_MAX ||
  173293. green_x > (double) PNG_UINT_31_MAX ||
  173294. green_y > (double) PNG_UINT_31_MAX ||
  173295. blue_x > (double) PNG_UINT_31_MAX ||
  173296. blue_y > (double) PNG_UINT_31_MAX)
  173297. #else
  173298. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173299. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173300. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173301. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173302. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173303. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173304. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173305. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173306. #endif
  173307. {
  173308. png_warning(png_ptr,
  173309. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173310. return;
  173311. }
  173312. info_ptr->int_x_white = white_x;
  173313. info_ptr->int_y_white = white_y;
  173314. info_ptr->int_x_red = red_x;
  173315. info_ptr->int_y_red = red_y;
  173316. info_ptr->int_x_green = green_x;
  173317. info_ptr->int_y_green = green_y;
  173318. info_ptr->int_x_blue = blue_x;
  173319. info_ptr->int_y_blue = blue_y;
  173320. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173321. info_ptr->x_white = (float)(white_x/100000.);
  173322. info_ptr->y_white = (float)(white_y/100000.);
  173323. info_ptr->x_red = (float)( red_x/100000.);
  173324. info_ptr->y_red = (float)( red_y/100000.);
  173325. info_ptr->x_green = (float)(green_x/100000.);
  173326. info_ptr->y_green = (float)(green_y/100000.);
  173327. info_ptr->x_blue = (float)( blue_x/100000.);
  173328. info_ptr->y_blue = (float)( blue_y/100000.);
  173329. #endif
  173330. info_ptr->valid |= PNG_INFO_cHRM;
  173331. }
  173332. #endif
  173333. #endif
  173334. #if defined(PNG_gAMA_SUPPORTED)
  173335. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173336. void PNGAPI
  173337. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173338. {
  173339. double gamma;
  173340. png_debug1(1, "in %s storage function\n", "gAMA");
  173341. if (png_ptr == NULL || info_ptr == NULL)
  173342. return;
  173343. if (file_gamma > 21474.83)
  173344. {
  173345. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173346. gamma=21474.83;
  173347. }
  173348. else
  173349. gamma=file_gamma;
  173350. info_ptr->gamma = (float)gamma;
  173351. #ifdef PNG_FIXED_POINT_SUPPORTED
  173352. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173353. #endif
  173354. info_ptr->valid |= PNG_INFO_gAMA;
  173355. if(gamma == 0.0)
  173356. png_warning(png_ptr, "Setting gamma=0");
  173357. }
  173358. #endif
  173359. void PNGAPI
  173360. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173361. int_gamma)
  173362. {
  173363. png_fixed_point gamma;
  173364. png_debug1(1, "in %s storage function\n", "gAMA");
  173365. if (png_ptr == NULL || info_ptr == NULL)
  173366. return;
  173367. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173368. {
  173369. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173370. gamma=PNG_UINT_31_MAX;
  173371. }
  173372. else
  173373. {
  173374. if (int_gamma < 0)
  173375. {
  173376. png_warning(png_ptr, "Setting negative gamma to zero");
  173377. gamma=0;
  173378. }
  173379. else
  173380. gamma=int_gamma;
  173381. }
  173382. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173383. info_ptr->gamma = (float)(gamma/100000.);
  173384. #endif
  173385. #ifdef PNG_FIXED_POINT_SUPPORTED
  173386. info_ptr->int_gamma = gamma;
  173387. #endif
  173388. info_ptr->valid |= PNG_INFO_gAMA;
  173389. if(gamma == 0)
  173390. png_warning(png_ptr, "Setting gamma=0");
  173391. }
  173392. #endif
  173393. #if defined(PNG_hIST_SUPPORTED)
  173394. void PNGAPI
  173395. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173396. {
  173397. int i;
  173398. png_debug1(1, "in %s storage function\n", "hIST");
  173399. if (png_ptr == NULL || info_ptr == NULL)
  173400. return;
  173401. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173402. > PNG_MAX_PALETTE_LENGTH)
  173403. {
  173404. png_warning(png_ptr,
  173405. "Invalid palette size, hIST allocation skipped.");
  173406. return;
  173407. }
  173408. #ifdef PNG_FREE_ME_SUPPORTED
  173409. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173410. #endif
  173411. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173412. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173413. if (png_ptr->hist == NULL)
  173414. {
  173415. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173416. return;
  173417. }
  173418. for (i = 0; i < info_ptr->num_palette; i++)
  173419. png_ptr->hist[i] = hist[i];
  173420. info_ptr->hist = png_ptr->hist;
  173421. info_ptr->valid |= PNG_INFO_hIST;
  173422. #ifdef PNG_FREE_ME_SUPPORTED
  173423. info_ptr->free_me |= PNG_FREE_HIST;
  173424. #else
  173425. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173426. #endif
  173427. }
  173428. #endif
  173429. void PNGAPI
  173430. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173431. png_uint_32 width, png_uint_32 height, int bit_depth,
  173432. int color_type, int interlace_type, int compression_type,
  173433. int filter_type)
  173434. {
  173435. png_debug1(1, "in %s storage function\n", "IHDR");
  173436. if (png_ptr == NULL || info_ptr == NULL)
  173437. return;
  173438. if (width == 0 || height == 0)
  173439. png_error(png_ptr, "Image width or height is zero in IHDR");
  173440. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173441. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173442. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173443. #else
  173444. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173445. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173446. #endif
  173447. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173448. png_error(png_ptr, "Invalid image size in IHDR");
  173449. if ( width > (PNG_UINT_32_MAX
  173450. >> 3) /* 8-byte RGBA pixels */
  173451. - 64 /* bigrowbuf hack */
  173452. - 1 /* filter byte */
  173453. - 7*8 /* rounding of width to multiple of 8 pixels */
  173454. - 8) /* extra max_pixel_depth pad */
  173455. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173456. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173457. bit_depth != 8 && bit_depth != 16)
  173458. png_error(png_ptr, "Invalid bit depth in IHDR");
  173459. if (color_type < 0 || color_type == 1 ||
  173460. color_type == 5 || color_type > 6)
  173461. png_error(png_ptr, "Invalid color type in IHDR");
  173462. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173463. ((color_type == PNG_COLOR_TYPE_RGB ||
  173464. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173465. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173466. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173467. if (interlace_type >= PNG_INTERLACE_LAST)
  173468. png_error(png_ptr, "Unknown interlace method in IHDR");
  173469. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173470. png_error(png_ptr, "Unknown compression method in IHDR");
  173471. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173472. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173473. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173474. if(filter_type != PNG_FILTER_TYPE_BASE)
  173475. {
  173476. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173477. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173478. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173479. (color_type == PNG_COLOR_TYPE_RGB ||
  173480. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173481. png_error(png_ptr, "Unknown filter method in IHDR");
  173482. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173483. png_warning(png_ptr, "Invalid filter method in IHDR");
  173484. }
  173485. #else
  173486. if(filter_type != PNG_FILTER_TYPE_BASE)
  173487. png_error(png_ptr, "Unknown filter method in IHDR");
  173488. #endif
  173489. info_ptr->width = width;
  173490. info_ptr->height = height;
  173491. info_ptr->bit_depth = (png_byte)bit_depth;
  173492. info_ptr->color_type =(png_byte) color_type;
  173493. info_ptr->compression_type = (png_byte)compression_type;
  173494. info_ptr->filter_type = (png_byte)filter_type;
  173495. info_ptr->interlace_type = (png_byte)interlace_type;
  173496. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173497. info_ptr->channels = 1;
  173498. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173499. info_ptr->channels = 3;
  173500. else
  173501. info_ptr->channels = 1;
  173502. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173503. info_ptr->channels++;
  173504. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173505. if (width > (PNG_UINT_32_MAX
  173506. >> 3) /* 8-byte RGBA pixels */
  173507. - 64 /* bigrowbuf hack */
  173508. - 1 /* filter byte */
  173509. - 7*8 /* rounding of width to multiple of 8 pixels */
  173510. - 8) /* extra max_pixel_depth pad */
  173511. info_ptr->rowbytes = (png_size_t)0;
  173512. else
  173513. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173514. }
  173515. #if defined(PNG_oFFs_SUPPORTED)
  173516. void PNGAPI
  173517. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173518. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173519. {
  173520. png_debug1(1, "in %s storage function\n", "oFFs");
  173521. if (png_ptr == NULL || info_ptr == NULL)
  173522. return;
  173523. info_ptr->x_offset = offset_x;
  173524. info_ptr->y_offset = offset_y;
  173525. info_ptr->offset_unit_type = (png_byte)unit_type;
  173526. info_ptr->valid |= PNG_INFO_oFFs;
  173527. }
  173528. #endif
  173529. #if defined(PNG_pCAL_SUPPORTED)
  173530. void PNGAPI
  173531. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173532. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173533. png_charp units, png_charpp params)
  173534. {
  173535. png_uint_32 length;
  173536. int i;
  173537. png_debug1(1, "in %s storage function\n", "pCAL");
  173538. if (png_ptr == NULL || info_ptr == NULL)
  173539. return;
  173540. length = png_strlen(purpose) + 1;
  173541. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173542. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173543. if (info_ptr->pcal_purpose == NULL)
  173544. {
  173545. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173546. return;
  173547. }
  173548. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173549. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173550. info_ptr->pcal_X0 = X0;
  173551. info_ptr->pcal_X1 = X1;
  173552. info_ptr->pcal_type = (png_byte)type;
  173553. info_ptr->pcal_nparams = (png_byte)nparams;
  173554. length = png_strlen(units) + 1;
  173555. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173556. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173557. if (info_ptr->pcal_units == NULL)
  173558. {
  173559. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173560. return;
  173561. }
  173562. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173563. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173564. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173565. if (info_ptr->pcal_params == NULL)
  173566. {
  173567. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173568. return;
  173569. }
  173570. info_ptr->pcal_params[nparams] = NULL;
  173571. for (i = 0; i < nparams; i++)
  173572. {
  173573. length = png_strlen(params[i]) + 1;
  173574. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173575. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173576. if (info_ptr->pcal_params[i] == NULL)
  173577. {
  173578. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173579. return;
  173580. }
  173581. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173582. }
  173583. info_ptr->valid |= PNG_INFO_pCAL;
  173584. #ifdef PNG_FREE_ME_SUPPORTED
  173585. info_ptr->free_me |= PNG_FREE_PCAL;
  173586. #endif
  173587. }
  173588. #endif
  173589. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173590. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173591. void PNGAPI
  173592. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173593. int unit, double width, double height)
  173594. {
  173595. png_debug1(1, "in %s storage function\n", "sCAL");
  173596. if (png_ptr == NULL || info_ptr == NULL)
  173597. return;
  173598. info_ptr->scal_unit = (png_byte)unit;
  173599. info_ptr->scal_pixel_width = width;
  173600. info_ptr->scal_pixel_height = height;
  173601. info_ptr->valid |= PNG_INFO_sCAL;
  173602. }
  173603. #else
  173604. #ifdef PNG_FIXED_POINT_SUPPORTED
  173605. void PNGAPI
  173606. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173607. int unit, png_charp swidth, png_charp sheight)
  173608. {
  173609. png_uint_32 length;
  173610. png_debug1(1, "in %s storage function\n", "sCAL");
  173611. if (png_ptr == NULL || info_ptr == NULL)
  173612. return;
  173613. info_ptr->scal_unit = (png_byte)unit;
  173614. length = png_strlen(swidth) + 1;
  173615. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173616. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173617. if (info_ptr->scal_s_width == NULL)
  173618. {
  173619. png_warning(png_ptr,
  173620. "Memory allocation failed while processing sCAL.");
  173621. }
  173622. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173623. length = png_strlen(sheight) + 1;
  173624. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173625. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173626. if (info_ptr->scal_s_height == NULL)
  173627. {
  173628. png_free (png_ptr, info_ptr->scal_s_width);
  173629. png_warning(png_ptr,
  173630. "Memory allocation failed while processing sCAL.");
  173631. }
  173632. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173633. info_ptr->valid |= PNG_INFO_sCAL;
  173634. #ifdef PNG_FREE_ME_SUPPORTED
  173635. info_ptr->free_me |= PNG_FREE_SCAL;
  173636. #endif
  173637. }
  173638. #endif
  173639. #endif
  173640. #endif
  173641. #if defined(PNG_pHYs_SUPPORTED)
  173642. void PNGAPI
  173643. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173644. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173645. {
  173646. png_debug1(1, "in %s storage function\n", "pHYs");
  173647. if (png_ptr == NULL || info_ptr == NULL)
  173648. return;
  173649. info_ptr->x_pixels_per_unit = res_x;
  173650. info_ptr->y_pixels_per_unit = res_y;
  173651. info_ptr->phys_unit_type = (png_byte)unit_type;
  173652. info_ptr->valid |= PNG_INFO_pHYs;
  173653. }
  173654. #endif
  173655. void PNGAPI
  173656. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173657. png_colorp palette, int num_palette)
  173658. {
  173659. png_debug1(1, "in %s storage function\n", "PLTE");
  173660. if (png_ptr == NULL || info_ptr == NULL)
  173661. return;
  173662. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173663. {
  173664. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173665. png_error(png_ptr, "Invalid palette length");
  173666. else
  173667. {
  173668. png_warning(png_ptr, "Invalid palette length");
  173669. return;
  173670. }
  173671. }
  173672. #ifdef PNG_FREE_ME_SUPPORTED
  173673. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173674. #endif
  173675. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173676. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173677. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173678. png_sizeof(png_color));
  173679. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173680. info_ptr->palette = png_ptr->palette;
  173681. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173682. #ifdef PNG_FREE_ME_SUPPORTED
  173683. info_ptr->free_me |= PNG_FREE_PLTE;
  173684. #else
  173685. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173686. #endif
  173687. info_ptr->valid |= PNG_INFO_PLTE;
  173688. }
  173689. #if defined(PNG_sBIT_SUPPORTED)
  173690. void PNGAPI
  173691. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173692. png_color_8p sig_bit)
  173693. {
  173694. png_debug1(1, "in %s storage function\n", "sBIT");
  173695. if (png_ptr == NULL || info_ptr == NULL)
  173696. return;
  173697. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173698. info_ptr->valid |= PNG_INFO_sBIT;
  173699. }
  173700. #endif
  173701. #if defined(PNG_sRGB_SUPPORTED)
  173702. void PNGAPI
  173703. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173704. {
  173705. png_debug1(1, "in %s storage function\n", "sRGB");
  173706. if (png_ptr == NULL || info_ptr == NULL)
  173707. return;
  173708. info_ptr->srgb_intent = (png_byte)intent;
  173709. info_ptr->valid |= PNG_INFO_sRGB;
  173710. }
  173711. void PNGAPI
  173712. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173713. int intent)
  173714. {
  173715. #if defined(PNG_gAMA_SUPPORTED)
  173716. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173717. float file_gamma;
  173718. #endif
  173719. #ifdef PNG_FIXED_POINT_SUPPORTED
  173720. png_fixed_point int_file_gamma;
  173721. #endif
  173722. #endif
  173723. #if defined(PNG_cHRM_SUPPORTED)
  173724. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173725. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173726. #endif
  173727. #ifdef PNG_FIXED_POINT_SUPPORTED
  173728. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173729. int_green_y, int_blue_x, int_blue_y;
  173730. #endif
  173731. #endif
  173732. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173733. if (png_ptr == NULL || info_ptr == NULL)
  173734. return;
  173735. png_set_sRGB(png_ptr, info_ptr, intent);
  173736. #if defined(PNG_gAMA_SUPPORTED)
  173737. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173738. file_gamma = (float).45455;
  173739. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173740. #endif
  173741. #ifdef PNG_FIXED_POINT_SUPPORTED
  173742. int_file_gamma = 45455L;
  173743. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173744. #endif
  173745. #endif
  173746. #if defined(PNG_cHRM_SUPPORTED)
  173747. #ifdef PNG_FIXED_POINT_SUPPORTED
  173748. int_white_x = 31270L;
  173749. int_white_y = 32900L;
  173750. int_red_x = 64000L;
  173751. int_red_y = 33000L;
  173752. int_green_x = 30000L;
  173753. int_green_y = 60000L;
  173754. int_blue_x = 15000L;
  173755. int_blue_y = 6000L;
  173756. png_set_cHRM_fixed(png_ptr, info_ptr,
  173757. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173758. int_blue_x, int_blue_y);
  173759. #endif
  173760. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173761. white_x = (float).3127;
  173762. white_y = (float).3290;
  173763. red_x = (float).64;
  173764. red_y = (float).33;
  173765. green_x = (float).30;
  173766. green_y = (float).60;
  173767. blue_x = (float).15;
  173768. blue_y = (float).06;
  173769. png_set_cHRM(png_ptr, info_ptr,
  173770. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173771. #endif
  173772. #endif
  173773. }
  173774. #endif
  173775. #if defined(PNG_iCCP_SUPPORTED)
  173776. void PNGAPI
  173777. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173778. png_charp name, int compression_type,
  173779. png_charp profile, png_uint_32 proflen)
  173780. {
  173781. png_charp new_iccp_name;
  173782. png_charp new_iccp_profile;
  173783. png_debug1(1, "in %s storage function\n", "iCCP");
  173784. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173785. return;
  173786. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173787. if (new_iccp_name == NULL)
  173788. {
  173789. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173790. return;
  173791. }
  173792. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173793. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173794. if (new_iccp_profile == NULL)
  173795. {
  173796. png_free (png_ptr, new_iccp_name);
  173797. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173798. return;
  173799. }
  173800. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173801. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173802. info_ptr->iccp_proflen = proflen;
  173803. info_ptr->iccp_name = new_iccp_name;
  173804. info_ptr->iccp_profile = new_iccp_profile;
  173805. info_ptr->iccp_compression = (png_byte)compression_type;
  173806. #ifdef PNG_FREE_ME_SUPPORTED
  173807. info_ptr->free_me |= PNG_FREE_ICCP;
  173808. #endif
  173809. info_ptr->valid |= PNG_INFO_iCCP;
  173810. }
  173811. #endif
  173812. #if defined(PNG_TEXT_SUPPORTED)
  173813. void PNGAPI
  173814. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173815. int num_text)
  173816. {
  173817. int ret;
  173818. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173819. if (ret)
  173820. png_error(png_ptr, "Insufficient memory to store text");
  173821. }
  173822. int /* PRIVATE */
  173823. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173824. int num_text)
  173825. {
  173826. int i;
  173827. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173828. "text" : (png_const_charp)png_ptr->chunk_name));
  173829. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173830. return(0);
  173831. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173832. {
  173833. if (info_ptr->text != NULL)
  173834. {
  173835. png_textp old_text;
  173836. int old_max;
  173837. old_max = info_ptr->max_text;
  173838. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173839. old_text = info_ptr->text;
  173840. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173841. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173842. if (info_ptr->text == NULL)
  173843. {
  173844. png_free(png_ptr, old_text);
  173845. return(1);
  173846. }
  173847. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173848. png_sizeof(png_text)));
  173849. png_free(png_ptr, old_text);
  173850. }
  173851. else
  173852. {
  173853. info_ptr->max_text = num_text + 8;
  173854. info_ptr->num_text = 0;
  173855. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173856. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173857. if (info_ptr->text == NULL)
  173858. return(1);
  173859. #ifdef PNG_FREE_ME_SUPPORTED
  173860. info_ptr->free_me |= PNG_FREE_TEXT;
  173861. #endif
  173862. }
  173863. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173864. info_ptr->max_text);
  173865. }
  173866. for (i = 0; i < num_text; i++)
  173867. {
  173868. png_size_t text_length,key_len;
  173869. png_size_t lang_len,lang_key_len;
  173870. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173871. if (text_ptr[i].key == NULL)
  173872. continue;
  173873. key_len = png_strlen(text_ptr[i].key);
  173874. if(text_ptr[i].compression <= 0)
  173875. {
  173876. lang_len = 0;
  173877. lang_key_len = 0;
  173878. }
  173879. else
  173880. #ifdef PNG_iTXt_SUPPORTED
  173881. {
  173882. if (text_ptr[i].lang != NULL)
  173883. lang_len = png_strlen(text_ptr[i].lang);
  173884. else
  173885. lang_len = 0;
  173886. if (text_ptr[i].lang_key != NULL)
  173887. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173888. else
  173889. lang_key_len = 0;
  173890. }
  173891. #else
  173892. {
  173893. png_warning(png_ptr, "iTXt chunk not supported.");
  173894. continue;
  173895. }
  173896. #endif
  173897. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173898. {
  173899. text_length = 0;
  173900. #ifdef PNG_iTXt_SUPPORTED
  173901. if(text_ptr[i].compression > 0)
  173902. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173903. else
  173904. #endif
  173905. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173906. }
  173907. else
  173908. {
  173909. text_length = png_strlen(text_ptr[i].text);
  173910. textp->compression = text_ptr[i].compression;
  173911. }
  173912. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173913. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173914. if (textp->key == NULL)
  173915. return(1);
  173916. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  173917. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  173918. (int)textp->key);
  173919. png_memcpy(textp->key, text_ptr[i].key,
  173920. (png_size_t)(key_len));
  173921. *(textp->key+key_len) = '\0';
  173922. #ifdef PNG_iTXt_SUPPORTED
  173923. if (text_ptr[i].compression > 0)
  173924. {
  173925. textp->lang=textp->key + key_len + 1;
  173926. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  173927. *(textp->lang+lang_len) = '\0';
  173928. textp->lang_key=textp->lang + lang_len + 1;
  173929. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  173930. *(textp->lang_key+lang_key_len) = '\0';
  173931. textp->text=textp->lang_key + lang_key_len + 1;
  173932. }
  173933. else
  173934. #endif
  173935. {
  173936. #ifdef PNG_iTXt_SUPPORTED
  173937. textp->lang=NULL;
  173938. textp->lang_key=NULL;
  173939. #endif
  173940. textp->text=textp->key + key_len + 1;
  173941. }
  173942. if(text_length)
  173943. png_memcpy(textp->text, text_ptr[i].text,
  173944. (png_size_t)(text_length));
  173945. *(textp->text+text_length) = '\0';
  173946. #ifdef PNG_iTXt_SUPPORTED
  173947. if(textp->compression > 0)
  173948. {
  173949. textp->text_length = 0;
  173950. textp->itxt_length = text_length;
  173951. }
  173952. else
  173953. #endif
  173954. {
  173955. textp->text_length = text_length;
  173956. #ifdef PNG_iTXt_SUPPORTED
  173957. textp->itxt_length = 0;
  173958. #endif
  173959. }
  173960. info_ptr->num_text++;
  173961. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  173962. }
  173963. return(0);
  173964. }
  173965. #endif
  173966. #if defined(PNG_tIME_SUPPORTED)
  173967. void PNGAPI
  173968. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  173969. {
  173970. png_debug1(1, "in %s storage function\n", "tIME");
  173971. if (png_ptr == NULL || info_ptr == NULL ||
  173972. (png_ptr->mode & PNG_WROTE_tIME))
  173973. return;
  173974. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  173975. info_ptr->valid |= PNG_INFO_tIME;
  173976. }
  173977. #endif
  173978. #if defined(PNG_tRNS_SUPPORTED)
  173979. void PNGAPI
  173980. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  173981. png_bytep trans, int num_trans, png_color_16p trans_values)
  173982. {
  173983. png_debug1(1, "in %s storage function\n", "tRNS");
  173984. if (png_ptr == NULL || info_ptr == NULL)
  173985. return;
  173986. if (trans != NULL)
  173987. {
  173988. #ifdef PNG_FREE_ME_SUPPORTED
  173989. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  173990. #endif
  173991. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  173992. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  173993. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  173994. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  173995. #ifdef PNG_FREE_ME_SUPPORTED
  173996. info_ptr->free_me |= PNG_FREE_TRNS;
  173997. #else
  173998. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  173999. #endif
  174000. }
  174001. if (trans_values != NULL)
  174002. {
  174003. png_memcpy(&(info_ptr->trans_values), trans_values,
  174004. png_sizeof(png_color_16));
  174005. if (num_trans == 0)
  174006. num_trans = 1;
  174007. }
  174008. info_ptr->num_trans = (png_uint_16)num_trans;
  174009. info_ptr->valid |= PNG_INFO_tRNS;
  174010. }
  174011. #endif
  174012. #if defined(PNG_sPLT_SUPPORTED)
  174013. void PNGAPI
  174014. png_set_sPLT(png_structp png_ptr,
  174015. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174016. {
  174017. png_sPLT_tp np;
  174018. int i;
  174019. if (png_ptr == NULL || info_ptr == NULL)
  174020. return;
  174021. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174022. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174023. if (np == NULL)
  174024. {
  174025. png_warning(png_ptr, "No memory for sPLT palettes.");
  174026. return;
  174027. }
  174028. png_memcpy(np, info_ptr->splt_palettes,
  174029. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174030. png_free(png_ptr, info_ptr->splt_palettes);
  174031. info_ptr->splt_palettes=NULL;
  174032. for (i = 0; i < nentries; i++)
  174033. {
  174034. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174035. png_sPLT_tp from = entries + i;
  174036. to->name = (png_charp)png_malloc_warn(png_ptr,
  174037. png_strlen(from->name) + 1);
  174038. if (to->name == NULL)
  174039. {
  174040. png_warning(png_ptr,
  174041. "Out of memory while processing sPLT chunk");
  174042. }
  174043. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174044. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174045. from->nentries * png_sizeof(png_sPLT_entry));
  174046. png_memcpy(to->entries, from->entries,
  174047. from->nentries * png_sizeof(png_sPLT_entry));
  174048. if (to->entries == NULL)
  174049. {
  174050. png_warning(png_ptr,
  174051. "Out of memory while processing sPLT chunk");
  174052. png_free(png_ptr,to->name);
  174053. to->name = NULL;
  174054. }
  174055. to->nentries = from->nentries;
  174056. to->depth = from->depth;
  174057. }
  174058. info_ptr->splt_palettes = np;
  174059. info_ptr->splt_palettes_num += nentries;
  174060. info_ptr->valid |= PNG_INFO_sPLT;
  174061. #ifdef PNG_FREE_ME_SUPPORTED
  174062. info_ptr->free_me |= PNG_FREE_SPLT;
  174063. #endif
  174064. }
  174065. #endif /* PNG_sPLT_SUPPORTED */
  174066. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174067. void PNGAPI
  174068. png_set_unknown_chunks(png_structp png_ptr,
  174069. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174070. {
  174071. png_unknown_chunkp np;
  174072. int i;
  174073. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174074. return;
  174075. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174076. (info_ptr->unknown_chunks_num + num_unknowns) *
  174077. png_sizeof(png_unknown_chunk));
  174078. if (np == NULL)
  174079. {
  174080. png_warning(png_ptr,
  174081. "Out of memory while processing unknown chunk.");
  174082. return;
  174083. }
  174084. png_memcpy(np, info_ptr->unknown_chunks,
  174085. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174086. png_free(png_ptr, info_ptr->unknown_chunks);
  174087. info_ptr->unknown_chunks=NULL;
  174088. for (i = 0; i < num_unknowns; i++)
  174089. {
  174090. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174091. png_unknown_chunkp from = unknowns + i;
  174092. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174093. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174094. if (to->data == NULL)
  174095. {
  174096. png_warning(png_ptr,
  174097. "Out of memory while processing unknown chunk.");
  174098. }
  174099. else
  174100. {
  174101. png_memcpy(to->data, from->data, from->size);
  174102. to->size = from->size;
  174103. to->location = (png_byte)(png_ptr->mode & 0xff);
  174104. }
  174105. }
  174106. info_ptr->unknown_chunks = np;
  174107. info_ptr->unknown_chunks_num += num_unknowns;
  174108. #ifdef PNG_FREE_ME_SUPPORTED
  174109. info_ptr->free_me |= PNG_FREE_UNKN;
  174110. #endif
  174111. }
  174112. void PNGAPI
  174113. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174114. int chunk, int location)
  174115. {
  174116. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174117. (int)info_ptr->unknown_chunks_num)
  174118. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174119. }
  174120. #endif
  174121. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174122. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174123. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174124. void PNGAPI
  174125. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174126. {
  174127. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174128. if (png_ptr == NULL)
  174129. return;
  174130. png_ptr->mng_features_permitted = (png_byte)
  174131. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174132. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174133. }
  174134. #endif
  174135. #endif
  174136. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174137. png_uint_32 PNGAPI
  174138. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174139. {
  174140. png_debug(1, "in png_permit_mng_features\n");
  174141. if (png_ptr == NULL)
  174142. return (png_uint_32)0;
  174143. png_ptr->mng_features_permitted =
  174144. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174145. return (png_uint_32)png_ptr->mng_features_permitted;
  174146. }
  174147. #endif
  174148. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174149. void PNGAPI
  174150. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174151. chunk_list, int num_chunks)
  174152. {
  174153. png_bytep new_list, p;
  174154. int i, old_num_chunks;
  174155. if (png_ptr == NULL)
  174156. return;
  174157. if (num_chunks == 0)
  174158. {
  174159. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174160. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174161. else
  174162. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174163. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174164. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174165. else
  174166. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174167. return;
  174168. }
  174169. if (chunk_list == NULL)
  174170. return;
  174171. old_num_chunks=png_ptr->num_chunk_list;
  174172. new_list=(png_bytep)png_malloc(png_ptr,
  174173. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174174. if(png_ptr->chunk_list != NULL)
  174175. {
  174176. png_memcpy(new_list, png_ptr->chunk_list,
  174177. (png_size_t)(5*old_num_chunks));
  174178. png_free(png_ptr, png_ptr->chunk_list);
  174179. png_ptr->chunk_list=NULL;
  174180. }
  174181. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174182. (png_size_t)(5*num_chunks));
  174183. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174184. *p=(png_byte)keep;
  174185. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174186. png_ptr->chunk_list=new_list;
  174187. #ifdef PNG_FREE_ME_SUPPORTED
  174188. png_ptr->free_me |= PNG_FREE_LIST;
  174189. #endif
  174190. }
  174191. #endif
  174192. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174193. void PNGAPI
  174194. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174195. png_user_chunk_ptr read_user_chunk_fn)
  174196. {
  174197. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174198. if (png_ptr == NULL)
  174199. return;
  174200. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174201. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174202. }
  174203. #endif
  174204. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174205. void PNGAPI
  174206. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174207. {
  174208. png_debug1(1, "in %s storage function\n", "rows");
  174209. if (png_ptr == NULL || info_ptr == NULL)
  174210. return;
  174211. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174212. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174213. info_ptr->row_pointers = row_pointers;
  174214. if(row_pointers)
  174215. info_ptr->valid |= PNG_INFO_IDAT;
  174216. }
  174217. #endif
  174218. #ifdef PNG_WRITE_SUPPORTED
  174219. void PNGAPI
  174220. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174221. {
  174222. if (png_ptr == NULL)
  174223. return;
  174224. if(png_ptr->zbuf)
  174225. png_free(png_ptr, png_ptr->zbuf);
  174226. png_ptr->zbuf_size = (png_size_t)size;
  174227. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174228. png_ptr->zstream.next_out = png_ptr->zbuf;
  174229. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174230. }
  174231. #endif
  174232. void PNGAPI
  174233. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174234. {
  174235. if (png_ptr && info_ptr)
  174236. info_ptr->valid &= ~(mask);
  174237. }
  174238. #ifndef PNG_1_0_X
  174239. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174240. void PNGAPI
  174241. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174242. {
  174243. if (png_ptr != NULL)
  174244. png_ptr->asm_flags = 0;
  174245. }
  174246. void PNGAPI
  174247. png_set_mmx_thresholds (png_structp png_ptr,
  174248. png_byte mmx_bitdepth_threshold,
  174249. png_uint_32 mmx_rowbytes_threshold)
  174250. {
  174251. if (png_ptr == NULL)
  174252. return;
  174253. }
  174254. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174255. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174256. void PNGAPI
  174257. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174258. png_uint_32 user_height_max)
  174259. {
  174260. if(png_ptr == NULL) return;
  174261. png_ptr->user_width_max = user_width_max;
  174262. png_ptr->user_height_max = user_height_max;
  174263. }
  174264. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174265. #endif /* ?PNG_1_0_X */
  174266. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174267. /*** End of inlined file: pngset.c ***/
  174268. /*** Start of inlined file: pngtrans.c ***/
  174269. #define PNG_INTERNAL
  174270. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174271. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174272. void PNGAPI
  174273. png_set_bgr(png_structp png_ptr)
  174274. {
  174275. png_debug(1, "in png_set_bgr\n");
  174276. if(png_ptr == NULL) return;
  174277. png_ptr->transformations |= PNG_BGR;
  174278. }
  174279. #endif
  174280. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174281. void PNGAPI
  174282. png_set_swap(png_structp png_ptr)
  174283. {
  174284. png_debug(1, "in png_set_swap\n");
  174285. if(png_ptr == NULL) return;
  174286. if (png_ptr->bit_depth == 16)
  174287. png_ptr->transformations |= PNG_SWAP_BYTES;
  174288. }
  174289. #endif
  174290. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174291. void PNGAPI
  174292. png_set_packing(png_structp png_ptr)
  174293. {
  174294. png_debug(1, "in png_set_packing\n");
  174295. if(png_ptr == NULL) return;
  174296. if (png_ptr->bit_depth < 8)
  174297. {
  174298. png_ptr->transformations |= PNG_PACK;
  174299. png_ptr->usr_bit_depth = 8;
  174300. }
  174301. }
  174302. #endif
  174303. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174304. void PNGAPI
  174305. png_set_packswap(png_structp png_ptr)
  174306. {
  174307. png_debug(1, "in png_set_packswap\n");
  174308. if(png_ptr == NULL) return;
  174309. if (png_ptr->bit_depth < 8)
  174310. png_ptr->transformations |= PNG_PACKSWAP;
  174311. }
  174312. #endif
  174313. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174314. void PNGAPI
  174315. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174316. {
  174317. png_debug(1, "in png_set_shift\n");
  174318. if(png_ptr == NULL) return;
  174319. png_ptr->transformations |= PNG_SHIFT;
  174320. png_ptr->shift = *true_bits;
  174321. }
  174322. #endif
  174323. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174324. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174325. int PNGAPI
  174326. png_set_interlace_handling(png_structp png_ptr)
  174327. {
  174328. png_debug(1, "in png_set_interlace handling\n");
  174329. if (png_ptr && png_ptr->interlaced)
  174330. {
  174331. png_ptr->transformations |= PNG_INTERLACE;
  174332. return (7);
  174333. }
  174334. return (1);
  174335. }
  174336. #endif
  174337. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174338. void PNGAPI
  174339. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174340. {
  174341. png_debug(1, "in png_set_filler\n");
  174342. if(png_ptr == NULL) return;
  174343. png_ptr->transformations |= PNG_FILLER;
  174344. png_ptr->filler = (png_byte)filler;
  174345. if (filler_loc == PNG_FILLER_AFTER)
  174346. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174347. else
  174348. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174349. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174350. {
  174351. png_ptr->usr_channels = 4;
  174352. }
  174353. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174354. {
  174355. png_ptr->usr_channels = 2;
  174356. }
  174357. }
  174358. #if !defined(PNG_1_0_X)
  174359. void PNGAPI
  174360. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174361. {
  174362. png_debug(1, "in png_set_add_alpha\n");
  174363. if(png_ptr == NULL) return;
  174364. png_set_filler(png_ptr, filler, filler_loc);
  174365. png_ptr->transformations |= PNG_ADD_ALPHA;
  174366. }
  174367. #endif
  174368. #endif
  174369. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174370. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174371. void PNGAPI
  174372. png_set_swap_alpha(png_structp png_ptr)
  174373. {
  174374. png_debug(1, "in png_set_swap_alpha\n");
  174375. if(png_ptr == NULL) return;
  174376. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174377. }
  174378. #endif
  174379. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174380. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174381. void PNGAPI
  174382. png_set_invert_alpha(png_structp png_ptr)
  174383. {
  174384. png_debug(1, "in png_set_invert_alpha\n");
  174385. if(png_ptr == NULL) return;
  174386. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174387. }
  174388. #endif
  174389. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174390. void PNGAPI
  174391. png_set_invert_mono(png_structp png_ptr)
  174392. {
  174393. png_debug(1, "in png_set_invert_mono\n");
  174394. if(png_ptr == NULL) return;
  174395. png_ptr->transformations |= PNG_INVERT_MONO;
  174396. }
  174397. void /* PRIVATE */
  174398. png_do_invert(png_row_infop row_info, png_bytep row)
  174399. {
  174400. png_debug(1, "in png_do_invert\n");
  174401. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174402. if (row == NULL || row_info == NULL)
  174403. return;
  174404. #endif
  174405. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174406. {
  174407. png_bytep rp = row;
  174408. png_uint_32 i;
  174409. png_uint_32 istop = row_info->rowbytes;
  174410. for (i = 0; i < istop; i++)
  174411. {
  174412. *rp = (png_byte)(~(*rp));
  174413. rp++;
  174414. }
  174415. }
  174416. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174417. row_info->bit_depth == 8)
  174418. {
  174419. png_bytep rp = row;
  174420. png_uint_32 i;
  174421. png_uint_32 istop = row_info->rowbytes;
  174422. for (i = 0; i < istop; i+=2)
  174423. {
  174424. *rp = (png_byte)(~(*rp));
  174425. rp+=2;
  174426. }
  174427. }
  174428. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174429. row_info->bit_depth == 16)
  174430. {
  174431. png_bytep rp = row;
  174432. png_uint_32 i;
  174433. png_uint_32 istop = row_info->rowbytes;
  174434. for (i = 0; i < istop; i+=4)
  174435. {
  174436. *rp = (png_byte)(~(*rp));
  174437. *(rp+1) = (png_byte)(~(*(rp+1)));
  174438. rp+=4;
  174439. }
  174440. }
  174441. }
  174442. #endif
  174443. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174444. void /* PRIVATE */
  174445. png_do_swap(png_row_infop row_info, png_bytep row)
  174446. {
  174447. png_debug(1, "in png_do_swap\n");
  174448. if (
  174449. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174450. row != NULL && row_info != NULL &&
  174451. #endif
  174452. row_info->bit_depth == 16)
  174453. {
  174454. png_bytep rp = row;
  174455. png_uint_32 i;
  174456. png_uint_32 istop= row_info->width * row_info->channels;
  174457. for (i = 0; i < istop; i++, rp += 2)
  174458. {
  174459. png_byte t = *rp;
  174460. *rp = *(rp + 1);
  174461. *(rp + 1) = t;
  174462. }
  174463. }
  174464. }
  174465. #endif
  174466. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174467. static PNG_CONST png_byte onebppswaptable[256] = {
  174468. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174469. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174470. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174471. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174472. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174473. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174474. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174475. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174476. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174477. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174478. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174479. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174480. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174481. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174482. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174483. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174484. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174485. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174486. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174487. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174488. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174489. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174490. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174491. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174492. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174493. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174494. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174495. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174496. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174497. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174498. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174499. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174500. };
  174501. static PNG_CONST png_byte twobppswaptable[256] = {
  174502. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174503. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174504. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174505. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174506. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174507. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174508. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174509. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174510. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174511. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174512. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174513. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174514. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174515. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174516. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174517. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174518. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174519. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174520. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174521. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174522. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174523. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174524. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174525. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174526. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174527. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174528. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174529. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174530. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174531. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174532. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174533. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174534. };
  174535. static PNG_CONST png_byte fourbppswaptable[256] = {
  174536. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174537. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174538. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174539. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174540. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174541. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174542. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174543. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174544. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174545. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174546. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174547. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174548. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174549. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174550. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174551. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174552. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174553. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174554. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174555. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174556. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174557. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174558. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174559. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174560. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174561. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174562. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174563. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174564. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174565. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174566. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174567. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174568. };
  174569. void /* PRIVATE */
  174570. png_do_packswap(png_row_infop row_info, png_bytep row)
  174571. {
  174572. png_debug(1, "in png_do_packswap\n");
  174573. if (
  174574. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174575. row != NULL && row_info != NULL &&
  174576. #endif
  174577. row_info->bit_depth < 8)
  174578. {
  174579. png_bytep rp, end, table;
  174580. end = row + row_info->rowbytes;
  174581. if (row_info->bit_depth == 1)
  174582. table = (png_bytep)onebppswaptable;
  174583. else if (row_info->bit_depth == 2)
  174584. table = (png_bytep)twobppswaptable;
  174585. else if (row_info->bit_depth == 4)
  174586. table = (png_bytep)fourbppswaptable;
  174587. else
  174588. return;
  174589. for (rp = row; rp < end; rp++)
  174590. *rp = table[*rp];
  174591. }
  174592. }
  174593. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174594. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174595. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174596. void /* PRIVATE */
  174597. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174598. {
  174599. png_debug(1, "in png_do_strip_filler\n");
  174600. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174601. if (row != NULL && row_info != NULL)
  174602. #endif
  174603. {
  174604. png_bytep sp=row;
  174605. png_bytep dp=row;
  174606. png_uint_32 row_width=row_info->width;
  174607. png_uint_32 i;
  174608. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174609. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174610. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174611. row_info->channels == 4)
  174612. {
  174613. if (row_info->bit_depth == 8)
  174614. {
  174615. if (flags & PNG_FLAG_FILLER_AFTER)
  174616. {
  174617. dp+=3; sp+=4;
  174618. for (i = 1; i < row_width; i++)
  174619. {
  174620. *dp++ = *sp++;
  174621. *dp++ = *sp++;
  174622. *dp++ = *sp++;
  174623. sp++;
  174624. }
  174625. }
  174626. else
  174627. {
  174628. for (i = 0; i < row_width; i++)
  174629. {
  174630. sp++;
  174631. *dp++ = *sp++;
  174632. *dp++ = *sp++;
  174633. *dp++ = *sp++;
  174634. }
  174635. }
  174636. row_info->pixel_depth = 24;
  174637. row_info->rowbytes = row_width * 3;
  174638. }
  174639. else /* if (row_info->bit_depth == 16) */
  174640. {
  174641. if (flags & PNG_FLAG_FILLER_AFTER)
  174642. {
  174643. sp += 8; dp += 6;
  174644. for (i = 1; i < row_width; i++)
  174645. {
  174646. *dp++ = *sp++;
  174647. *dp++ = *sp++;
  174648. *dp++ = *sp++;
  174649. *dp++ = *sp++;
  174650. *dp++ = *sp++;
  174651. *dp++ = *sp++;
  174652. sp += 2;
  174653. }
  174654. }
  174655. else
  174656. {
  174657. for (i = 0; i < row_width; i++)
  174658. {
  174659. sp+=2;
  174660. *dp++ = *sp++;
  174661. *dp++ = *sp++;
  174662. *dp++ = *sp++;
  174663. *dp++ = *sp++;
  174664. *dp++ = *sp++;
  174665. *dp++ = *sp++;
  174666. }
  174667. }
  174668. row_info->pixel_depth = 48;
  174669. row_info->rowbytes = row_width * 6;
  174670. }
  174671. row_info->channels = 3;
  174672. }
  174673. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174674. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174675. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174676. row_info->channels == 2)
  174677. {
  174678. if (row_info->bit_depth == 8)
  174679. {
  174680. if (flags & PNG_FLAG_FILLER_AFTER)
  174681. {
  174682. for (i = 0; i < row_width; i++)
  174683. {
  174684. *dp++ = *sp++;
  174685. sp++;
  174686. }
  174687. }
  174688. else
  174689. {
  174690. for (i = 0; i < row_width; i++)
  174691. {
  174692. sp++;
  174693. *dp++ = *sp++;
  174694. }
  174695. }
  174696. row_info->pixel_depth = 8;
  174697. row_info->rowbytes = row_width;
  174698. }
  174699. else /* if (row_info->bit_depth == 16) */
  174700. {
  174701. if (flags & PNG_FLAG_FILLER_AFTER)
  174702. {
  174703. sp += 4; dp += 2;
  174704. for (i = 1; i < row_width; i++)
  174705. {
  174706. *dp++ = *sp++;
  174707. *dp++ = *sp++;
  174708. sp += 2;
  174709. }
  174710. }
  174711. else
  174712. {
  174713. for (i = 0; i < row_width; i++)
  174714. {
  174715. sp += 2;
  174716. *dp++ = *sp++;
  174717. *dp++ = *sp++;
  174718. }
  174719. }
  174720. row_info->pixel_depth = 16;
  174721. row_info->rowbytes = row_width * 2;
  174722. }
  174723. row_info->channels = 1;
  174724. }
  174725. if (flags & PNG_FLAG_STRIP_ALPHA)
  174726. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174727. }
  174728. }
  174729. #endif
  174730. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174731. void /* PRIVATE */
  174732. png_do_bgr(png_row_infop row_info, png_bytep row)
  174733. {
  174734. png_debug(1, "in png_do_bgr\n");
  174735. if (
  174736. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174737. row != NULL && row_info != NULL &&
  174738. #endif
  174739. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174740. {
  174741. png_uint_32 row_width = row_info->width;
  174742. if (row_info->bit_depth == 8)
  174743. {
  174744. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174745. {
  174746. png_bytep rp;
  174747. png_uint_32 i;
  174748. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174749. {
  174750. png_byte save = *rp;
  174751. *rp = *(rp + 2);
  174752. *(rp + 2) = save;
  174753. }
  174754. }
  174755. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174756. {
  174757. png_bytep rp;
  174758. png_uint_32 i;
  174759. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174760. {
  174761. png_byte save = *rp;
  174762. *rp = *(rp + 2);
  174763. *(rp + 2) = save;
  174764. }
  174765. }
  174766. }
  174767. else if (row_info->bit_depth == 16)
  174768. {
  174769. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174770. {
  174771. png_bytep rp;
  174772. png_uint_32 i;
  174773. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174774. {
  174775. png_byte save = *rp;
  174776. *rp = *(rp + 4);
  174777. *(rp + 4) = save;
  174778. save = *(rp + 1);
  174779. *(rp + 1) = *(rp + 5);
  174780. *(rp + 5) = save;
  174781. }
  174782. }
  174783. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174784. {
  174785. png_bytep rp;
  174786. png_uint_32 i;
  174787. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174788. {
  174789. png_byte save = *rp;
  174790. *rp = *(rp + 4);
  174791. *(rp + 4) = save;
  174792. save = *(rp + 1);
  174793. *(rp + 1) = *(rp + 5);
  174794. *(rp + 5) = save;
  174795. }
  174796. }
  174797. }
  174798. }
  174799. }
  174800. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174801. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174802. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174803. defined(PNG_LEGACY_SUPPORTED)
  174804. void PNGAPI
  174805. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174806. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174807. {
  174808. png_debug(1, "in png_set_user_transform_info\n");
  174809. if(png_ptr == NULL) return;
  174810. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174811. png_ptr->user_transform_ptr = user_transform_ptr;
  174812. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174813. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174814. #else
  174815. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174816. png_warning(png_ptr,
  174817. "This version of libpng does not support user transform info");
  174818. #endif
  174819. }
  174820. #endif
  174821. png_voidp PNGAPI
  174822. png_get_user_transform_ptr(png_structp png_ptr)
  174823. {
  174824. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174825. if (png_ptr == NULL) return (NULL);
  174826. return ((png_voidp)png_ptr->user_transform_ptr);
  174827. #else
  174828. return (NULL);
  174829. #endif
  174830. }
  174831. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174832. /*** End of inlined file: pngtrans.c ***/
  174833. /*** Start of inlined file: pngwio.c ***/
  174834. #define PNG_INTERNAL
  174835. #ifdef PNG_WRITE_SUPPORTED
  174836. void /* PRIVATE */
  174837. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174838. {
  174839. if (png_ptr->write_data_fn != NULL )
  174840. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174841. else
  174842. png_error(png_ptr, "Call to NULL write function");
  174843. }
  174844. #if !defined(PNG_NO_STDIO)
  174845. #ifndef USE_FAR_KEYWORD
  174846. void PNGAPI
  174847. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174848. {
  174849. png_uint_32 check;
  174850. if(png_ptr == NULL) return;
  174851. #if defined(_WIN32_WCE)
  174852. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174853. check = 0;
  174854. #else
  174855. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174856. #endif
  174857. if (check != length)
  174858. png_error(png_ptr, "Write Error");
  174859. }
  174860. #else
  174861. #define NEAR_BUF_SIZE 1024
  174862. #define MIN(a,b) (a <= b ? a : b)
  174863. void PNGAPI
  174864. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174865. {
  174866. png_uint_32 check;
  174867. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174868. png_FILE_p io_ptr;
  174869. if(png_ptr == NULL) return;
  174870. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174871. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174872. if ((png_bytep)near_data == data)
  174873. {
  174874. #if defined(_WIN32_WCE)
  174875. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174876. check = 0;
  174877. #else
  174878. check = fwrite(near_data, 1, length, io_ptr);
  174879. #endif
  174880. }
  174881. else
  174882. {
  174883. png_byte buf[NEAR_BUF_SIZE];
  174884. png_size_t written, remaining, err;
  174885. check = 0;
  174886. remaining = length;
  174887. do
  174888. {
  174889. written = MIN(NEAR_BUF_SIZE, remaining);
  174890. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174891. #if defined(_WIN32_WCE)
  174892. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174893. err = 0;
  174894. #else
  174895. err = fwrite(buf, 1, written, io_ptr);
  174896. #endif
  174897. if (err != written)
  174898. break;
  174899. else
  174900. check += err;
  174901. data += written;
  174902. remaining -= written;
  174903. }
  174904. while (remaining != 0);
  174905. }
  174906. if (check != length)
  174907. png_error(png_ptr, "Write Error");
  174908. }
  174909. #endif
  174910. #endif
  174911. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174912. void /* PRIVATE */
  174913. png_flush(png_structp png_ptr)
  174914. {
  174915. if (png_ptr->output_flush_fn != NULL)
  174916. (*(png_ptr->output_flush_fn))(png_ptr);
  174917. }
  174918. #if !defined(PNG_NO_STDIO)
  174919. void PNGAPI
  174920. png_default_flush(png_structp png_ptr)
  174921. {
  174922. #if !defined(_WIN32_WCE)
  174923. png_FILE_p io_ptr;
  174924. #endif
  174925. if(png_ptr == NULL) return;
  174926. #if !defined(_WIN32_WCE)
  174927. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  174928. if (io_ptr != NULL)
  174929. fflush(io_ptr);
  174930. #endif
  174931. }
  174932. #endif
  174933. #endif
  174934. void PNGAPI
  174935. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  174936. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  174937. {
  174938. if(png_ptr == NULL) return;
  174939. png_ptr->io_ptr = io_ptr;
  174940. #if !defined(PNG_NO_STDIO)
  174941. if (write_data_fn != NULL)
  174942. png_ptr->write_data_fn = write_data_fn;
  174943. else
  174944. png_ptr->write_data_fn = png_default_write_data;
  174945. #else
  174946. png_ptr->write_data_fn = write_data_fn;
  174947. #endif
  174948. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174949. #if !defined(PNG_NO_STDIO)
  174950. if (output_flush_fn != NULL)
  174951. png_ptr->output_flush_fn = output_flush_fn;
  174952. else
  174953. png_ptr->output_flush_fn = png_default_flush;
  174954. #else
  174955. png_ptr->output_flush_fn = output_flush_fn;
  174956. #endif
  174957. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  174958. if (png_ptr->read_data_fn != NULL)
  174959. {
  174960. png_ptr->read_data_fn = NULL;
  174961. png_warning(png_ptr,
  174962. "Attempted to set both read_data_fn and write_data_fn in");
  174963. png_warning(png_ptr,
  174964. "the same structure. Resetting read_data_fn to NULL.");
  174965. }
  174966. }
  174967. #if defined(USE_FAR_KEYWORD)
  174968. #if defined(_MSC_VER)
  174969. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174970. {
  174971. void *near_ptr;
  174972. void FAR *far_ptr;
  174973. FP_OFF(near_ptr) = FP_OFF(ptr);
  174974. far_ptr = (void FAR *)near_ptr;
  174975. if(check != 0)
  174976. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  174977. png_error(png_ptr,"segment lost in conversion");
  174978. return(near_ptr);
  174979. }
  174980. # else
  174981. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174982. {
  174983. void *near_ptr;
  174984. void FAR *far_ptr;
  174985. near_ptr = (void FAR *)ptr;
  174986. far_ptr = (void FAR *)near_ptr;
  174987. if(check != 0)
  174988. if(far_ptr != ptr)
  174989. png_error(png_ptr,"segment lost in conversion");
  174990. return(near_ptr);
  174991. }
  174992. # endif
  174993. # endif
  174994. #endif /* PNG_WRITE_SUPPORTED */
  174995. /*** End of inlined file: pngwio.c ***/
  174996. /*** Start of inlined file: pngwrite.c ***/
  174997. #define PNG_INTERNAL
  174998. #ifdef PNG_WRITE_SUPPORTED
  174999. void PNGAPI
  175000. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175001. {
  175002. png_debug(1, "in png_write_info_before_PLTE\n");
  175003. if (png_ptr == NULL || info_ptr == NULL)
  175004. return;
  175005. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175006. {
  175007. png_write_sig(png_ptr); /* write PNG signature */
  175008. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175009. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175010. {
  175011. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175012. png_ptr->mng_features_permitted=0;
  175013. }
  175014. #endif
  175015. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175016. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175017. info_ptr->filter_type,
  175018. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175019. info_ptr->interlace_type);
  175020. #else
  175021. 0);
  175022. #endif
  175023. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175024. if (info_ptr->valid & PNG_INFO_gAMA)
  175025. {
  175026. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175027. png_write_gAMA(png_ptr, info_ptr->gamma);
  175028. #else
  175029. #ifdef PNG_FIXED_POINT_SUPPORTED
  175030. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175031. # endif
  175032. #endif
  175033. }
  175034. #endif
  175035. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175036. if (info_ptr->valid & PNG_INFO_sRGB)
  175037. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175038. #endif
  175039. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175040. if (info_ptr->valid & PNG_INFO_iCCP)
  175041. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175042. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175043. #endif
  175044. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175045. if (info_ptr->valid & PNG_INFO_sBIT)
  175046. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175047. #endif
  175048. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175049. if (info_ptr->valid & PNG_INFO_cHRM)
  175050. {
  175051. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175052. png_write_cHRM(png_ptr,
  175053. info_ptr->x_white, info_ptr->y_white,
  175054. info_ptr->x_red, info_ptr->y_red,
  175055. info_ptr->x_green, info_ptr->y_green,
  175056. info_ptr->x_blue, info_ptr->y_blue);
  175057. #else
  175058. # ifdef PNG_FIXED_POINT_SUPPORTED
  175059. png_write_cHRM_fixed(png_ptr,
  175060. info_ptr->int_x_white, info_ptr->int_y_white,
  175061. info_ptr->int_x_red, info_ptr->int_y_red,
  175062. info_ptr->int_x_green, info_ptr->int_y_green,
  175063. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175064. # endif
  175065. #endif
  175066. }
  175067. #endif
  175068. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175069. if (info_ptr->unknown_chunks_num)
  175070. {
  175071. png_unknown_chunk *up;
  175072. png_debug(5, "writing extra chunks\n");
  175073. for (up = info_ptr->unknown_chunks;
  175074. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175075. up++)
  175076. {
  175077. int keep=png_handle_as_unknown(png_ptr, up->name);
  175078. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175079. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175080. !(up->location & PNG_HAVE_IDAT) &&
  175081. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175082. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175083. {
  175084. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175085. }
  175086. }
  175087. }
  175088. #endif
  175089. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175090. }
  175091. }
  175092. void PNGAPI
  175093. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175094. {
  175095. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175096. int i;
  175097. #endif
  175098. png_debug(1, "in png_write_info\n");
  175099. if (png_ptr == NULL || info_ptr == NULL)
  175100. return;
  175101. png_write_info_before_PLTE(png_ptr, info_ptr);
  175102. if (info_ptr->valid & PNG_INFO_PLTE)
  175103. png_write_PLTE(png_ptr, info_ptr->palette,
  175104. (png_uint_32)info_ptr->num_palette);
  175105. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175106. png_error(png_ptr, "Valid palette required for paletted images");
  175107. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175108. if (info_ptr->valid & PNG_INFO_tRNS)
  175109. {
  175110. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175111. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175112. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175113. {
  175114. int j;
  175115. for (j=0; j<(int)info_ptr->num_trans; j++)
  175116. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175117. }
  175118. #endif
  175119. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175120. info_ptr->num_trans, info_ptr->color_type);
  175121. }
  175122. #endif
  175123. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175124. if (info_ptr->valid & PNG_INFO_bKGD)
  175125. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175126. #endif
  175127. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175128. if (info_ptr->valid & PNG_INFO_hIST)
  175129. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175130. #endif
  175131. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175132. if (info_ptr->valid & PNG_INFO_oFFs)
  175133. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175134. info_ptr->offset_unit_type);
  175135. #endif
  175136. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175137. if (info_ptr->valid & PNG_INFO_pCAL)
  175138. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175139. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175140. info_ptr->pcal_units, info_ptr->pcal_params);
  175141. #endif
  175142. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175143. if (info_ptr->valid & PNG_INFO_sCAL)
  175144. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175145. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175146. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175147. #else
  175148. #ifdef PNG_FIXED_POINT_SUPPORTED
  175149. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175150. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175151. #else
  175152. png_warning(png_ptr,
  175153. "png_write_sCAL not supported; sCAL chunk not written.");
  175154. #endif
  175155. #endif
  175156. #endif
  175157. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175158. if (info_ptr->valid & PNG_INFO_pHYs)
  175159. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175160. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175161. #endif
  175162. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175163. if (info_ptr->valid & PNG_INFO_tIME)
  175164. {
  175165. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175166. png_ptr->mode |= PNG_WROTE_tIME;
  175167. }
  175168. #endif
  175169. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175170. if (info_ptr->valid & PNG_INFO_sPLT)
  175171. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175172. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175173. #endif
  175174. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175175. for (i = 0; i < info_ptr->num_text; i++)
  175176. {
  175177. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175178. info_ptr->text[i].compression);
  175179. if (info_ptr->text[i].compression > 0)
  175180. {
  175181. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175182. png_write_iTXt(png_ptr,
  175183. info_ptr->text[i].compression,
  175184. info_ptr->text[i].key,
  175185. info_ptr->text[i].lang,
  175186. info_ptr->text[i].lang_key,
  175187. info_ptr->text[i].text);
  175188. #else
  175189. png_warning(png_ptr, "Unable to write international text");
  175190. #endif
  175191. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175192. }
  175193. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175194. {
  175195. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175196. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175197. info_ptr->text[i].text, 0,
  175198. info_ptr->text[i].compression);
  175199. #else
  175200. png_warning(png_ptr, "Unable to write compressed text");
  175201. #endif
  175202. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175203. }
  175204. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175205. {
  175206. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175207. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175208. info_ptr->text[i].text,
  175209. 0);
  175210. #else
  175211. png_warning(png_ptr, "Unable to write uncompressed text");
  175212. #endif
  175213. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175214. }
  175215. }
  175216. #endif
  175217. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175218. if (info_ptr->unknown_chunks_num)
  175219. {
  175220. png_unknown_chunk *up;
  175221. png_debug(5, "writing extra chunks\n");
  175222. for (up = info_ptr->unknown_chunks;
  175223. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175224. up++)
  175225. {
  175226. int keep=png_handle_as_unknown(png_ptr, up->name);
  175227. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175228. up->location && (up->location & PNG_HAVE_PLTE) &&
  175229. !(up->location & PNG_HAVE_IDAT) &&
  175230. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175231. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175232. {
  175233. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175234. }
  175235. }
  175236. }
  175237. #endif
  175238. }
  175239. void PNGAPI
  175240. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175241. {
  175242. png_debug(1, "in png_write_end\n");
  175243. if (png_ptr == NULL)
  175244. return;
  175245. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175246. png_error(png_ptr, "No IDATs written into file");
  175247. if (info_ptr != NULL)
  175248. {
  175249. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175250. int i; /* local index variable */
  175251. #endif
  175252. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175253. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175254. !(png_ptr->mode & PNG_WROTE_tIME))
  175255. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175256. #endif
  175257. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175258. for (i = 0; i < info_ptr->num_text; i++)
  175259. {
  175260. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175261. info_ptr->text[i].compression);
  175262. if (info_ptr->text[i].compression > 0)
  175263. {
  175264. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175265. png_write_iTXt(png_ptr,
  175266. info_ptr->text[i].compression,
  175267. info_ptr->text[i].key,
  175268. info_ptr->text[i].lang,
  175269. info_ptr->text[i].lang_key,
  175270. info_ptr->text[i].text);
  175271. #else
  175272. png_warning(png_ptr, "Unable to write international text");
  175273. #endif
  175274. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175275. }
  175276. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175277. {
  175278. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175279. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175280. info_ptr->text[i].text, 0,
  175281. info_ptr->text[i].compression);
  175282. #else
  175283. png_warning(png_ptr, "Unable to write compressed text");
  175284. #endif
  175285. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175286. }
  175287. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175288. {
  175289. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175290. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175291. info_ptr->text[i].text, 0);
  175292. #else
  175293. png_warning(png_ptr, "Unable to write uncompressed text");
  175294. #endif
  175295. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175296. }
  175297. }
  175298. #endif
  175299. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175300. if (info_ptr->unknown_chunks_num)
  175301. {
  175302. png_unknown_chunk *up;
  175303. png_debug(5, "writing extra chunks\n");
  175304. for (up = info_ptr->unknown_chunks;
  175305. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175306. up++)
  175307. {
  175308. int keep=png_handle_as_unknown(png_ptr, up->name);
  175309. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175310. up->location && (up->location & PNG_AFTER_IDAT) &&
  175311. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175312. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175313. {
  175314. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175315. }
  175316. }
  175317. }
  175318. #endif
  175319. }
  175320. png_ptr->mode |= PNG_AFTER_IDAT;
  175321. png_write_IEND(png_ptr);
  175322. }
  175323. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175324. #if !defined(_WIN32_WCE)
  175325. void PNGAPI
  175326. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175327. {
  175328. png_debug(1, "in png_convert_from_struct_tm\n");
  175329. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175330. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175331. ptime->day = (png_byte)ttime->tm_mday;
  175332. ptime->hour = (png_byte)ttime->tm_hour;
  175333. ptime->minute = (png_byte)ttime->tm_min;
  175334. ptime->second = (png_byte)ttime->tm_sec;
  175335. }
  175336. void PNGAPI
  175337. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175338. {
  175339. struct tm *tbuf;
  175340. png_debug(1, "in png_convert_from_time_t\n");
  175341. tbuf = gmtime(&ttime);
  175342. png_convert_from_struct_tm(ptime, tbuf);
  175343. }
  175344. #endif
  175345. #endif
  175346. png_structp PNGAPI
  175347. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175348. png_error_ptr error_fn, png_error_ptr warn_fn)
  175349. {
  175350. #ifdef PNG_USER_MEM_SUPPORTED
  175351. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175352. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175353. }
  175354. png_structp PNGAPI
  175355. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175356. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175357. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175358. {
  175359. #endif /* PNG_USER_MEM_SUPPORTED */
  175360. png_structp png_ptr;
  175361. #ifdef PNG_SETJMP_SUPPORTED
  175362. #ifdef USE_FAR_KEYWORD
  175363. jmp_buf jmpbuf;
  175364. #endif
  175365. #endif
  175366. int i;
  175367. png_debug(1, "in png_create_write_struct\n");
  175368. #ifdef PNG_USER_MEM_SUPPORTED
  175369. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175370. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175371. #else
  175372. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175373. #endif /* PNG_USER_MEM_SUPPORTED */
  175374. if (png_ptr == NULL)
  175375. return (NULL);
  175376. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175377. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175378. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175379. #endif
  175380. #ifdef PNG_SETJMP_SUPPORTED
  175381. #ifdef USE_FAR_KEYWORD
  175382. if (setjmp(jmpbuf))
  175383. #else
  175384. if (setjmp(png_ptr->jmpbuf))
  175385. #endif
  175386. {
  175387. png_free(png_ptr, png_ptr->zbuf);
  175388. png_ptr->zbuf=NULL;
  175389. png_destroy_struct(png_ptr);
  175390. return (NULL);
  175391. }
  175392. #ifdef USE_FAR_KEYWORD
  175393. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175394. #endif
  175395. #endif
  175396. #ifdef PNG_USER_MEM_SUPPORTED
  175397. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175398. #endif /* PNG_USER_MEM_SUPPORTED */
  175399. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175400. i=0;
  175401. do
  175402. {
  175403. if(user_png_ver[i] != png_libpng_ver[i])
  175404. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175405. } while (png_libpng_ver[i++]);
  175406. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175407. {
  175408. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175409. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175410. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175411. {
  175412. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175413. char msg[80];
  175414. if (user_png_ver)
  175415. {
  175416. png_snprintf(msg, 80,
  175417. "Application was compiled with png.h from libpng-%.20s",
  175418. user_png_ver);
  175419. png_warning(png_ptr, msg);
  175420. }
  175421. png_snprintf(msg, 80,
  175422. "Application is running with png.c from libpng-%.20s",
  175423. png_libpng_ver);
  175424. png_warning(png_ptr, msg);
  175425. #endif
  175426. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175427. png_ptr->flags=0;
  175428. #endif
  175429. png_error(png_ptr,
  175430. "Incompatible libpng version in application and library");
  175431. }
  175432. }
  175433. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175434. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175435. (png_uint_32)png_ptr->zbuf_size);
  175436. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175437. png_flush_ptr_NULL);
  175438. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175439. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175440. 1, png_doublep_NULL, png_doublep_NULL);
  175441. #endif
  175442. #ifdef PNG_SETJMP_SUPPORTED
  175443. #ifdef USE_FAR_KEYWORD
  175444. if (setjmp(jmpbuf))
  175445. PNG_ABORT();
  175446. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175447. #else
  175448. if (setjmp(png_ptr->jmpbuf))
  175449. PNG_ABORT();
  175450. #endif
  175451. #endif
  175452. return (png_ptr);
  175453. }
  175454. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175455. #undef png_write_init
  175456. void PNGAPI
  175457. png_write_init(png_structp png_ptr)
  175458. {
  175459. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175460. }
  175461. void PNGAPI
  175462. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175463. png_size_t png_struct_size, png_size_t png_info_size)
  175464. {
  175465. if(png_ptr == NULL) return;
  175466. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175467. if(png_sizeof(png_struct) > png_struct_size ||
  175468. png_sizeof(png_info) > png_info_size)
  175469. {
  175470. char msg[80];
  175471. png_ptr->warning_fn=NULL;
  175472. if (user_png_ver)
  175473. {
  175474. png_snprintf(msg, 80,
  175475. "Application was compiled with png.h from libpng-%.20s",
  175476. user_png_ver);
  175477. png_warning(png_ptr, msg);
  175478. }
  175479. png_snprintf(msg, 80,
  175480. "Application is running with png.c from libpng-%.20s",
  175481. png_libpng_ver);
  175482. png_warning(png_ptr, msg);
  175483. }
  175484. #endif
  175485. if(png_sizeof(png_struct) > png_struct_size)
  175486. {
  175487. png_ptr->error_fn=NULL;
  175488. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175489. png_ptr->flags=0;
  175490. #endif
  175491. png_error(png_ptr,
  175492. "The png struct allocated by the application for writing is too small.");
  175493. }
  175494. if(png_sizeof(png_info) > png_info_size)
  175495. {
  175496. png_ptr->error_fn=NULL;
  175497. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175498. png_ptr->flags=0;
  175499. #endif
  175500. png_error(png_ptr,
  175501. "The info struct allocated by the application for writing is too small.");
  175502. }
  175503. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175504. }
  175505. #endif /* PNG_1_0_X || PNG_1_2_X */
  175506. void PNGAPI
  175507. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175508. png_size_t png_struct_size)
  175509. {
  175510. png_structp png_ptr=*ptr_ptr;
  175511. #ifdef PNG_SETJMP_SUPPORTED
  175512. jmp_buf tmp_jmp; /* to save current jump buffer */
  175513. #endif
  175514. int i = 0;
  175515. if (png_ptr == NULL)
  175516. return;
  175517. do
  175518. {
  175519. if (user_png_ver[i] != png_libpng_ver[i])
  175520. {
  175521. #ifdef PNG_LEGACY_SUPPORTED
  175522. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175523. #else
  175524. png_ptr->warning_fn=NULL;
  175525. png_warning(png_ptr,
  175526. "Application uses deprecated png_write_init() and should be recompiled.");
  175527. break;
  175528. #endif
  175529. }
  175530. } while (png_libpng_ver[i++]);
  175531. png_debug(1, "in png_write_init_3\n");
  175532. #ifdef PNG_SETJMP_SUPPORTED
  175533. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175534. #endif
  175535. if (png_sizeof(png_struct) > png_struct_size)
  175536. {
  175537. png_destroy_struct(png_ptr);
  175538. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175539. *ptr_ptr = png_ptr;
  175540. }
  175541. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175542. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175543. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175544. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175545. #endif
  175546. #ifdef PNG_SETJMP_SUPPORTED
  175547. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175548. #endif
  175549. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175550. png_flush_ptr_NULL);
  175551. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175552. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175553. (png_uint_32)png_ptr->zbuf_size);
  175554. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175555. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175556. 1, png_doublep_NULL, png_doublep_NULL);
  175557. #endif
  175558. }
  175559. void PNGAPI
  175560. png_write_rows(png_structp png_ptr, png_bytepp row,
  175561. png_uint_32 num_rows)
  175562. {
  175563. png_uint_32 i; /* row counter */
  175564. png_bytepp rp; /* row pointer */
  175565. png_debug(1, "in png_write_rows\n");
  175566. if (png_ptr == NULL)
  175567. return;
  175568. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175569. {
  175570. png_write_row(png_ptr, *rp);
  175571. }
  175572. }
  175573. void PNGAPI
  175574. png_write_image(png_structp png_ptr, png_bytepp image)
  175575. {
  175576. png_uint_32 i; /* row index */
  175577. int pass, num_pass; /* pass variables */
  175578. png_bytepp rp; /* points to current row */
  175579. if (png_ptr == NULL)
  175580. return;
  175581. png_debug(1, "in png_write_image\n");
  175582. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175583. num_pass = png_set_interlace_handling(png_ptr);
  175584. #else
  175585. num_pass = 1;
  175586. #endif
  175587. for (pass = 0; pass < num_pass; pass++)
  175588. {
  175589. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175590. {
  175591. png_write_row(png_ptr, *rp);
  175592. }
  175593. }
  175594. }
  175595. void PNGAPI
  175596. png_write_row(png_structp png_ptr, png_bytep row)
  175597. {
  175598. if (png_ptr == NULL)
  175599. return;
  175600. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175601. png_ptr->row_number, png_ptr->pass);
  175602. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175603. {
  175604. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175605. png_error(png_ptr,
  175606. "png_write_info was never called before png_write_row.");
  175607. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175608. if (png_ptr->transformations & PNG_INVERT_MONO)
  175609. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175610. #endif
  175611. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175612. if (png_ptr->transformations & PNG_FILLER)
  175613. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175614. #endif
  175615. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175616. if (png_ptr->transformations & PNG_PACKSWAP)
  175617. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175618. #endif
  175619. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175620. if (png_ptr->transformations & PNG_PACK)
  175621. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175622. #endif
  175623. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175624. if (png_ptr->transformations & PNG_SHIFT)
  175625. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175626. #endif
  175627. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175628. if (png_ptr->transformations & PNG_BGR)
  175629. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175630. #endif
  175631. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175632. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175633. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175634. #endif
  175635. png_write_start_row(png_ptr);
  175636. }
  175637. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175638. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175639. {
  175640. switch (png_ptr->pass)
  175641. {
  175642. case 0:
  175643. if (png_ptr->row_number & 0x07)
  175644. {
  175645. png_write_finish_row(png_ptr);
  175646. return;
  175647. }
  175648. break;
  175649. case 1:
  175650. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175651. {
  175652. png_write_finish_row(png_ptr);
  175653. return;
  175654. }
  175655. break;
  175656. case 2:
  175657. if ((png_ptr->row_number & 0x07) != 4)
  175658. {
  175659. png_write_finish_row(png_ptr);
  175660. return;
  175661. }
  175662. break;
  175663. case 3:
  175664. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175665. {
  175666. png_write_finish_row(png_ptr);
  175667. return;
  175668. }
  175669. break;
  175670. case 4:
  175671. if ((png_ptr->row_number & 0x03) != 2)
  175672. {
  175673. png_write_finish_row(png_ptr);
  175674. return;
  175675. }
  175676. break;
  175677. case 5:
  175678. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175679. {
  175680. png_write_finish_row(png_ptr);
  175681. return;
  175682. }
  175683. break;
  175684. case 6:
  175685. if (!(png_ptr->row_number & 0x01))
  175686. {
  175687. png_write_finish_row(png_ptr);
  175688. return;
  175689. }
  175690. break;
  175691. }
  175692. }
  175693. #endif
  175694. png_ptr->row_info.color_type = png_ptr->color_type;
  175695. png_ptr->row_info.width = png_ptr->usr_width;
  175696. png_ptr->row_info.channels = png_ptr->usr_channels;
  175697. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175698. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175699. png_ptr->row_info.channels);
  175700. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175701. png_ptr->row_info.width);
  175702. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175703. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175704. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175705. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175706. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175707. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175708. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175709. png_ptr->row_info.rowbytes);
  175710. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175711. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175712. (png_ptr->transformations & PNG_INTERLACE))
  175713. {
  175714. png_do_write_interlace(&(png_ptr->row_info),
  175715. png_ptr->row_buf + 1, png_ptr->pass);
  175716. if (!(png_ptr->row_info.width))
  175717. {
  175718. png_write_finish_row(png_ptr);
  175719. return;
  175720. }
  175721. }
  175722. #endif
  175723. if (png_ptr->transformations)
  175724. png_do_write_transformations(png_ptr);
  175725. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175726. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175727. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175728. {
  175729. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175730. }
  175731. #endif
  175732. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175733. if (png_ptr->write_row_fn != NULL)
  175734. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175735. }
  175736. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175737. void PNGAPI
  175738. png_set_flush(png_structp png_ptr, int nrows)
  175739. {
  175740. png_debug(1, "in png_set_flush\n");
  175741. if (png_ptr == NULL)
  175742. return;
  175743. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175744. }
  175745. void PNGAPI
  175746. png_write_flush(png_structp png_ptr)
  175747. {
  175748. int wrote_IDAT;
  175749. png_debug(1, "in png_write_flush\n");
  175750. if (png_ptr == NULL)
  175751. return;
  175752. if (png_ptr->row_number >= png_ptr->num_rows)
  175753. return;
  175754. do
  175755. {
  175756. int ret;
  175757. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175758. wrote_IDAT = 0;
  175759. if (ret != Z_OK)
  175760. {
  175761. if (png_ptr->zstream.msg != NULL)
  175762. png_error(png_ptr, png_ptr->zstream.msg);
  175763. else
  175764. png_error(png_ptr, "zlib error");
  175765. }
  175766. if (!(png_ptr->zstream.avail_out))
  175767. {
  175768. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175769. png_ptr->zbuf_size);
  175770. png_ptr->zstream.next_out = png_ptr->zbuf;
  175771. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175772. wrote_IDAT = 1;
  175773. }
  175774. } while(wrote_IDAT == 1);
  175775. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175776. {
  175777. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175778. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175779. png_ptr->zstream.next_out = png_ptr->zbuf;
  175780. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175781. }
  175782. png_ptr->flush_rows = 0;
  175783. png_flush(png_ptr);
  175784. }
  175785. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175786. void PNGAPI
  175787. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175788. {
  175789. png_structp png_ptr = NULL;
  175790. png_infop info_ptr = NULL;
  175791. #ifdef PNG_USER_MEM_SUPPORTED
  175792. png_free_ptr free_fn = NULL;
  175793. png_voidp mem_ptr = NULL;
  175794. #endif
  175795. png_debug(1, "in png_destroy_write_struct\n");
  175796. if (png_ptr_ptr != NULL)
  175797. {
  175798. png_ptr = *png_ptr_ptr;
  175799. #ifdef PNG_USER_MEM_SUPPORTED
  175800. free_fn = png_ptr->free_fn;
  175801. mem_ptr = png_ptr->mem_ptr;
  175802. #endif
  175803. }
  175804. if (info_ptr_ptr != NULL)
  175805. info_ptr = *info_ptr_ptr;
  175806. if (info_ptr != NULL)
  175807. {
  175808. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175809. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175810. if (png_ptr->num_chunk_list)
  175811. {
  175812. png_free(png_ptr, png_ptr->chunk_list);
  175813. png_ptr->chunk_list=NULL;
  175814. png_ptr->num_chunk_list=0;
  175815. }
  175816. #endif
  175817. #ifdef PNG_USER_MEM_SUPPORTED
  175818. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175819. (png_voidp)mem_ptr);
  175820. #else
  175821. png_destroy_struct((png_voidp)info_ptr);
  175822. #endif
  175823. *info_ptr_ptr = NULL;
  175824. }
  175825. if (png_ptr != NULL)
  175826. {
  175827. png_write_destroy(png_ptr);
  175828. #ifdef PNG_USER_MEM_SUPPORTED
  175829. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175830. (png_voidp)mem_ptr);
  175831. #else
  175832. png_destroy_struct((png_voidp)png_ptr);
  175833. #endif
  175834. *png_ptr_ptr = NULL;
  175835. }
  175836. }
  175837. void /* PRIVATE */
  175838. png_write_destroy(png_structp png_ptr)
  175839. {
  175840. #ifdef PNG_SETJMP_SUPPORTED
  175841. jmp_buf tmp_jmp; /* save jump buffer */
  175842. #endif
  175843. png_error_ptr error_fn;
  175844. png_error_ptr warning_fn;
  175845. png_voidp error_ptr;
  175846. #ifdef PNG_USER_MEM_SUPPORTED
  175847. png_free_ptr free_fn;
  175848. #endif
  175849. png_debug(1, "in png_write_destroy\n");
  175850. deflateEnd(&png_ptr->zstream);
  175851. png_free(png_ptr, png_ptr->zbuf);
  175852. png_free(png_ptr, png_ptr->row_buf);
  175853. png_free(png_ptr, png_ptr->prev_row);
  175854. png_free(png_ptr, png_ptr->sub_row);
  175855. png_free(png_ptr, png_ptr->up_row);
  175856. png_free(png_ptr, png_ptr->avg_row);
  175857. png_free(png_ptr, png_ptr->paeth_row);
  175858. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175859. png_free(png_ptr, png_ptr->time_buffer);
  175860. #endif
  175861. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175862. png_free(png_ptr, png_ptr->prev_filters);
  175863. png_free(png_ptr, png_ptr->filter_weights);
  175864. png_free(png_ptr, png_ptr->inv_filter_weights);
  175865. png_free(png_ptr, png_ptr->filter_costs);
  175866. png_free(png_ptr, png_ptr->inv_filter_costs);
  175867. #endif
  175868. #ifdef PNG_SETJMP_SUPPORTED
  175869. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175870. #endif
  175871. error_fn = png_ptr->error_fn;
  175872. warning_fn = png_ptr->warning_fn;
  175873. error_ptr = png_ptr->error_ptr;
  175874. #ifdef PNG_USER_MEM_SUPPORTED
  175875. free_fn = png_ptr->free_fn;
  175876. #endif
  175877. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175878. png_ptr->error_fn = error_fn;
  175879. png_ptr->warning_fn = warning_fn;
  175880. png_ptr->error_ptr = error_ptr;
  175881. #ifdef PNG_USER_MEM_SUPPORTED
  175882. png_ptr->free_fn = free_fn;
  175883. #endif
  175884. #ifdef PNG_SETJMP_SUPPORTED
  175885. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175886. #endif
  175887. }
  175888. void PNGAPI
  175889. png_set_filter(png_structp png_ptr, int method, int filters)
  175890. {
  175891. png_debug(1, "in png_set_filter\n");
  175892. if (png_ptr == NULL)
  175893. return;
  175894. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175895. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175896. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175897. method = PNG_FILTER_TYPE_BASE;
  175898. #endif
  175899. if (method == PNG_FILTER_TYPE_BASE)
  175900. {
  175901. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175902. {
  175903. #ifndef PNG_NO_WRITE_FILTER
  175904. case 5:
  175905. case 6:
  175906. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175907. #endif /* PNG_NO_WRITE_FILTER */
  175908. case PNG_FILTER_VALUE_NONE:
  175909. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175910. #ifndef PNG_NO_WRITE_FILTER
  175911. case PNG_FILTER_VALUE_SUB:
  175912. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175913. case PNG_FILTER_VALUE_UP:
  175914. png_ptr->do_filter=PNG_FILTER_UP; break;
  175915. case PNG_FILTER_VALUE_AVG:
  175916. png_ptr->do_filter=PNG_FILTER_AVG; break;
  175917. case PNG_FILTER_VALUE_PAETH:
  175918. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  175919. default: png_ptr->do_filter = (png_byte)filters; break;
  175920. #else
  175921. default: png_warning(png_ptr, "Unknown row filter for method 0");
  175922. #endif /* PNG_NO_WRITE_FILTER */
  175923. }
  175924. if (png_ptr->row_buf != NULL)
  175925. {
  175926. #ifndef PNG_NO_WRITE_FILTER
  175927. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  175928. {
  175929. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  175930. (png_ptr->rowbytes + 1));
  175931. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  175932. }
  175933. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  175934. {
  175935. if (png_ptr->prev_row == NULL)
  175936. {
  175937. png_warning(png_ptr, "Can't add Up filter after starting");
  175938. png_ptr->do_filter &= ~PNG_FILTER_UP;
  175939. }
  175940. else
  175941. {
  175942. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  175943. (png_ptr->rowbytes + 1));
  175944. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  175945. }
  175946. }
  175947. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  175948. {
  175949. if (png_ptr->prev_row == NULL)
  175950. {
  175951. png_warning(png_ptr, "Can't add Average filter after starting");
  175952. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  175953. }
  175954. else
  175955. {
  175956. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  175957. (png_ptr->rowbytes + 1));
  175958. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  175959. }
  175960. }
  175961. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  175962. png_ptr->paeth_row == NULL)
  175963. {
  175964. if (png_ptr->prev_row == NULL)
  175965. {
  175966. png_warning(png_ptr, "Can't add Paeth filter after starting");
  175967. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  175968. }
  175969. else
  175970. {
  175971. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  175972. (png_ptr->rowbytes + 1));
  175973. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  175974. }
  175975. }
  175976. if (png_ptr->do_filter == PNG_NO_FILTERS)
  175977. #endif /* PNG_NO_WRITE_FILTER */
  175978. png_ptr->do_filter = PNG_FILTER_NONE;
  175979. }
  175980. }
  175981. else
  175982. png_error(png_ptr, "Unknown custom filter method");
  175983. }
  175984. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  175985. void PNGAPI
  175986. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  175987. int num_weights, png_doublep filter_weights,
  175988. png_doublep filter_costs)
  175989. {
  175990. int i;
  175991. png_debug(1, "in png_set_filter_heuristics\n");
  175992. if (png_ptr == NULL)
  175993. return;
  175994. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  175995. {
  175996. png_warning(png_ptr, "Unknown filter heuristic method");
  175997. return;
  175998. }
  175999. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176000. {
  176001. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176002. }
  176003. if (num_weights < 0 || filter_weights == NULL ||
  176004. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176005. {
  176006. num_weights = 0;
  176007. }
  176008. png_ptr->num_prev_filters = (png_byte)num_weights;
  176009. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176010. if (num_weights > 0)
  176011. {
  176012. if (png_ptr->prev_filters == NULL)
  176013. {
  176014. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176015. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176016. for (i = 0; i < num_weights; i++)
  176017. {
  176018. png_ptr->prev_filters[i] = 255;
  176019. }
  176020. }
  176021. if (png_ptr->filter_weights == NULL)
  176022. {
  176023. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176024. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176025. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176026. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176027. for (i = 0; i < num_weights; i++)
  176028. {
  176029. png_ptr->inv_filter_weights[i] =
  176030. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176031. }
  176032. }
  176033. for (i = 0; i < num_weights; i++)
  176034. {
  176035. if (filter_weights[i] < 0.0)
  176036. {
  176037. png_ptr->inv_filter_weights[i] =
  176038. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176039. }
  176040. else
  176041. {
  176042. png_ptr->inv_filter_weights[i] =
  176043. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176044. png_ptr->filter_weights[i] =
  176045. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176046. }
  176047. }
  176048. }
  176049. if (png_ptr->filter_costs == NULL)
  176050. {
  176051. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176052. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176053. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176054. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176055. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176056. {
  176057. png_ptr->inv_filter_costs[i] =
  176058. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176059. }
  176060. }
  176061. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176062. {
  176063. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176064. {
  176065. png_ptr->inv_filter_costs[i] =
  176066. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176067. }
  176068. else if (filter_costs[i] >= 1.0)
  176069. {
  176070. png_ptr->inv_filter_costs[i] =
  176071. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176072. png_ptr->filter_costs[i] =
  176073. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176074. }
  176075. }
  176076. }
  176077. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176078. void PNGAPI
  176079. png_set_compression_level(png_structp png_ptr, int level)
  176080. {
  176081. png_debug(1, "in png_set_compression_level\n");
  176082. if (png_ptr == NULL)
  176083. return;
  176084. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176085. png_ptr->zlib_level = level;
  176086. }
  176087. void PNGAPI
  176088. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176089. {
  176090. png_debug(1, "in png_set_compression_mem_level\n");
  176091. if (png_ptr == NULL)
  176092. return;
  176093. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176094. png_ptr->zlib_mem_level = mem_level;
  176095. }
  176096. void PNGAPI
  176097. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176098. {
  176099. png_debug(1, "in png_set_compression_strategy\n");
  176100. if (png_ptr == NULL)
  176101. return;
  176102. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176103. png_ptr->zlib_strategy = strategy;
  176104. }
  176105. void PNGAPI
  176106. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176107. {
  176108. if (png_ptr == NULL)
  176109. return;
  176110. if (window_bits > 15)
  176111. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176112. else if (window_bits < 8)
  176113. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176114. #ifndef WBITS_8_OK
  176115. if (window_bits == 8)
  176116. {
  176117. png_warning(png_ptr, "Compression window is being reset to 512");
  176118. window_bits=9;
  176119. }
  176120. #endif
  176121. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176122. png_ptr->zlib_window_bits = window_bits;
  176123. }
  176124. void PNGAPI
  176125. png_set_compression_method(png_structp png_ptr, int method)
  176126. {
  176127. png_debug(1, "in png_set_compression_method\n");
  176128. if (png_ptr == NULL)
  176129. return;
  176130. if (method != 8)
  176131. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176132. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176133. png_ptr->zlib_method = method;
  176134. }
  176135. void PNGAPI
  176136. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176137. {
  176138. if (png_ptr == NULL)
  176139. return;
  176140. png_ptr->write_row_fn = write_row_fn;
  176141. }
  176142. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176143. void PNGAPI
  176144. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176145. write_user_transform_fn)
  176146. {
  176147. png_debug(1, "in png_set_write_user_transform_fn\n");
  176148. if (png_ptr == NULL)
  176149. return;
  176150. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176151. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176152. }
  176153. #endif
  176154. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176155. void PNGAPI
  176156. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176157. int transforms, voidp params)
  176158. {
  176159. if (png_ptr == NULL || info_ptr == NULL)
  176160. return;
  176161. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176162. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176163. png_set_invert_alpha(png_ptr);
  176164. #endif
  176165. png_write_info(png_ptr, info_ptr);
  176166. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176167. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176168. png_set_invert_mono(png_ptr);
  176169. #endif
  176170. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176171. if ((transforms & PNG_TRANSFORM_SHIFT)
  176172. && (info_ptr->valid & PNG_INFO_sBIT))
  176173. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176174. #endif
  176175. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176176. if (transforms & PNG_TRANSFORM_PACKING)
  176177. png_set_packing(png_ptr);
  176178. #endif
  176179. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176180. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176181. png_set_swap_alpha(png_ptr);
  176182. #endif
  176183. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176184. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176185. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176186. #endif
  176187. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176188. if (transforms & PNG_TRANSFORM_BGR)
  176189. png_set_bgr(png_ptr);
  176190. #endif
  176191. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176192. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176193. png_set_swap(png_ptr);
  176194. #endif
  176195. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176196. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176197. png_set_packswap(png_ptr);
  176198. #endif
  176199. if (info_ptr->valid & PNG_INFO_IDAT)
  176200. png_write_image(png_ptr, info_ptr->row_pointers);
  176201. png_write_end(png_ptr, info_ptr);
  176202. transforms = transforms; /* quiet compiler warnings */
  176203. params = params;
  176204. }
  176205. #endif
  176206. #endif /* PNG_WRITE_SUPPORTED */
  176207. /*** End of inlined file: pngwrite.c ***/
  176208. /*** Start of inlined file: pngwtran.c ***/
  176209. #define PNG_INTERNAL
  176210. #ifdef PNG_WRITE_SUPPORTED
  176211. void /* PRIVATE */
  176212. png_do_write_transformations(png_structp png_ptr)
  176213. {
  176214. png_debug(1, "in png_do_write_transformations\n");
  176215. if (png_ptr == NULL)
  176216. return;
  176217. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176218. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176219. if(png_ptr->write_user_transform_fn != NULL)
  176220. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176221. (png_ptr, /* png_ptr */
  176222. &(png_ptr->row_info), /* row_info: */
  176223. png_ptr->row_buf + 1); /* start of pixel data for row */
  176224. #endif
  176225. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176226. if (png_ptr->transformations & PNG_FILLER)
  176227. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176228. png_ptr->flags);
  176229. #endif
  176230. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176231. if (png_ptr->transformations & PNG_PACKSWAP)
  176232. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176233. #endif
  176234. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176235. if (png_ptr->transformations & PNG_PACK)
  176236. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176237. (png_uint_32)png_ptr->bit_depth);
  176238. #endif
  176239. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176240. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176241. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176242. #endif
  176243. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176244. if (png_ptr->transformations & PNG_SHIFT)
  176245. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176246. &(png_ptr->shift));
  176247. #endif
  176248. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176249. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176250. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176251. #endif
  176252. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176253. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176254. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176255. #endif
  176256. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176257. if (png_ptr->transformations & PNG_BGR)
  176258. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176259. #endif
  176260. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176261. if (png_ptr->transformations & PNG_INVERT_MONO)
  176262. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176263. #endif
  176264. }
  176265. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176266. void /* PRIVATE */
  176267. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176268. {
  176269. png_debug(1, "in png_do_pack\n");
  176270. if (row_info->bit_depth == 8 &&
  176271. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176272. row != NULL && row_info != NULL &&
  176273. #endif
  176274. row_info->channels == 1)
  176275. {
  176276. switch ((int)bit_depth)
  176277. {
  176278. case 1:
  176279. {
  176280. png_bytep sp, dp;
  176281. int mask, v;
  176282. png_uint_32 i;
  176283. png_uint_32 row_width = row_info->width;
  176284. sp = row;
  176285. dp = row;
  176286. mask = 0x80;
  176287. v = 0;
  176288. for (i = 0; i < row_width; i++)
  176289. {
  176290. if (*sp != 0)
  176291. v |= mask;
  176292. sp++;
  176293. if (mask > 1)
  176294. mask >>= 1;
  176295. else
  176296. {
  176297. mask = 0x80;
  176298. *dp = (png_byte)v;
  176299. dp++;
  176300. v = 0;
  176301. }
  176302. }
  176303. if (mask != 0x80)
  176304. *dp = (png_byte)v;
  176305. break;
  176306. }
  176307. case 2:
  176308. {
  176309. png_bytep sp, dp;
  176310. int shift, v;
  176311. png_uint_32 i;
  176312. png_uint_32 row_width = row_info->width;
  176313. sp = row;
  176314. dp = row;
  176315. shift = 6;
  176316. v = 0;
  176317. for (i = 0; i < row_width; i++)
  176318. {
  176319. png_byte value;
  176320. value = (png_byte)(*sp & 0x03);
  176321. v |= (value << shift);
  176322. if (shift == 0)
  176323. {
  176324. shift = 6;
  176325. *dp = (png_byte)v;
  176326. dp++;
  176327. v = 0;
  176328. }
  176329. else
  176330. shift -= 2;
  176331. sp++;
  176332. }
  176333. if (shift != 6)
  176334. *dp = (png_byte)v;
  176335. break;
  176336. }
  176337. case 4:
  176338. {
  176339. png_bytep sp, dp;
  176340. int shift, v;
  176341. png_uint_32 i;
  176342. png_uint_32 row_width = row_info->width;
  176343. sp = row;
  176344. dp = row;
  176345. shift = 4;
  176346. v = 0;
  176347. for (i = 0; i < row_width; i++)
  176348. {
  176349. png_byte value;
  176350. value = (png_byte)(*sp & 0x0f);
  176351. v |= (value << shift);
  176352. if (shift == 0)
  176353. {
  176354. shift = 4;
  176355. *dp = (png_byte)v;
  176356. dp++;
  176357. v = 0;
  176358. }
  176359. else
  176360. shift -= 4;
  176361. sp++;
  176362. }
  176363. if (shift != 4)
  176364. *dp = (png_byte)v;
  176365. break;
  176366. }
  176367. }
  176368. row_info->bit_depth = (png_byte)bit_depth;
  176369. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176370. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176371. row_info->width);
  176372. }
  176373. }
  176374. #endif
  176375. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176376. void /* PRIVATE */
  176377. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176378. {
  176379. png_debug(1, "in png_do_shift\n");
  176380. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176381. if (row != NULL && row_info != NULL &&
  176382. #else
  176383. if (
  176384. #endif
  176385. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176386. {
  176387. int shift_start[4], shift_dec[4];
  176388. int channels = 0;
  176389. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176390. {
  176391. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176392. shift_dec[channels] = bit_depth->red;
  176393. channels++;
  176394. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176395. shift_dec[channels] = bit_depth->green;
  176396. channels++;
  176397. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176398. shift_dec[channels] = bit_depth->blue;
  176399. channels++;
  176400. }
  176401. else
  176402. {
  176403. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176404. shift_dec[channels] = bit_depth->gray;
  176405. channels++;
  176406. }
  176407. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176408. {
  176409. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176410. shift_dec[channels] = bit_depth->alpha;
  176411. channels++;
  176412. }
  176413. if (row_info->bit_depth < 8)
  176414. {
  176415. png_bytep bp = row;
  176416. png_uint_32 i;
  176417. png_byte mask;
  176418. png_uint_32 row_bytes = row_info->rowbytes;
  176419. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176420. mask = 0x55;
  176421. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176422. mask = 0x11;
  176423. else
  176424. mask = 0xff;
  176425. for (i = 0; i < row_bytes; i++, bp++)
  176426. {
  176427. png_uint_16 v;
  176428. int j;
  176429. v = *bp;
  176430. *bp = 0;
  176431. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176432. {
  176433. if (j > 0)
  176434. *bp |= (png_byte)((v << j) & 0xff);
  176435. else
  176436. *bp |= (png_byte)((v >> (-j)) & mask);
  176437. }
  176438. }
  176439. }
  176440. else if (row_info->bit_depth == 8)
  176441. {
  176442. png_bytep bp = row;
  176443. png_uint_32 i;
  176444. png_uint_32 istop = channels * row_info->width;
  176445. for (i = 0; i < istop; i++, bp++)
  176446. {
  176447. png_uint_16 v;
  176448. int j;
  176449. int c = (int)(i%channels);
  176450. v = *bp;
  176451. *bp = 0;
  176452. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176453. {
  176454. if (j > 0)
  176455. *bp |= (png_byte)((v << j) & 0xff);
  176456. else
  176457. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176458. }
  176459. }
  176460. }
  176461. else
  176462. {
  176463. png_bytep bp;
  176464. png_uint_32 i;
  176465. png_uint_32 istop = channels * row_info->width;
  176466. for (bp = row, i = 0; i < istop; i++)
  176467. {
  176468. int c = (int)(i%channels);
  176469. png_uint_16 value, v;
  176470. int j;
  176471. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176472. value = 0;
  176473. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176474. {
  176475. if (j > 0)
  176476. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176477. else
  176478. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176479. }
  176480. *bp++ = (png_byte)(value >> 8);
  176481. *bp++ = (png_byte)(value & 0xff);
  176482. }
  176483. }
  176484. }
  176485. }
  176486. #endif
  176487. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176488. void /* PRIVATE */
  176489. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176490. {
  176491. png_debug(1, "in png_do_write_swap_alpha\n");
  176492. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176493. if (row != NULL && row_info != NULL)
  176494. #endif
  176495. {
  176496. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176497. {
  176498. if (row_info->bit_depth == 8)
  176499. {
  176500. png_bytep sp, dp;
  176501. png_uint_32 i;
  176502. png_uint_32 row_width = row_info->width;
  176503. for (i = 0, sp = dp = row; i < row_width; i++)
  176504. {
  176505. png_byte save = *(sp++);
  176506. *(dp++) = *(sp++);
  176507. *(dp++) = *(sp++);
  176508. *(dp++) = *(sp++);
  176509. *(dp++) = save;
  176510. }
  176511. }
  176512. else
  176513. {
  176514. png_bytep sp, dp;
  176515. png_uint_32 i;
  176516. png_uint_32 row_width = row_info->width;
  176517. for (i = 0, sp = dp = row; i < row_width; i++)
  176518. {
  176519. png_byte save[2];
  176520. save[0] = *(sp++);
  176521. save[1] = *(sp++);
  176522. *(dp++) = *(sp++);
  176523. *(dp++) = *(sp++);
  176524. *(dp++) = *(sp++);
  176525. *(dp++) = *(sp++);
  176526. *(dp++) = *(sp++);
  176527. *(dp++) = *(sp++);
  176528. *(dp++) = save[0];
  176529. *(dp++) = save[1];
  176530. }
  176531. }
  176532. }
  176533. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176534. {
  176535. if (row_info->bit_depth == 8)
  176536. {
  176537. png_bytep sp, dp;
  176538. png_uint_32 i;
  176539. png_uint_32 row_width = row_info->width;
  176540. for (i = 0, sp = dp = row; i < row_width; i++)
  176541. {
  176542. png_byte save = *(sp++);
  176543. *(dp++) = *(sp++);
  176544. *(dp++) = save;
  176545. }
  176546. }
  176547. else
  176548. {
  176549. png_bytep sp, dp;
  176550. png_uint_32 i;
  176551. png_uint_32 row_width = row_info->width;
  176552. for (i = 0, sp = dp = row; i < row_width; i++)
  176553. {
  176554. png_byte save[2];
  176555. save[0] = *(sp++);
  176556. save[1] = *(sp++);
  176557. *(dp++) = *(sp++);
  176558. *(dp++) = *(sp++);
  176559. *(dp++) = save[0];
  176560. *(dp++) = save[1];
  176561. }
  176562. }
  176563. }
  176564. }
  176565. }
  176566. #endif
  176567. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176568. void /* PRIVATE */
  176569. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176570. {
  176571. png_debug(1, "in png_do_write_invert_alpha\n");
  176572. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176573. if (row != NULL && row_info != NULL)
  176574. #endif
  176575. {
  176576. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176577. {
  176578. if (row_info->bit_depth == 8)
  176579. {
  176580. png_bytep sp, dp;
  176581. png_uint_32 i;
  176582. png_uint_32 row_width = row_info->width;
  176583. for (i = 0, sp = dp = row; i < row_width; i++)
  176584. {
  176585. sp+=3; dp = sp;
  176586. *(dp++) = (png_byte)(255 - *(sp++));
  176587. }
  176588. }
  176589. else
  176590. {
  176591. png_bytep sp, dp;
  176592. png_uint_32 i;
  176593. png_uint_32 row_width = row_info->width;
  176594. for (i = 0, sp = dp = row; i < row_width; i++)
  176595. {
  176596. sp+=6; dp = sp;
  176597. *(dp++) = (png_byte)(255 - *(sp++));
  176598. *(dp++) = (png_byte)(255 - *(sp++));
  176599. }
  176600. }
  176601. }
  176602. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176603. {
  176604. if (row_info->bit_depth == 8)
  176605. {
  176606. png_bytep sp, dp;
  176607. png_uint_32 i;
  176608. png_uint_32 row_width = row_info->width;
  176609. for (i = 0, sp = dp = row; i < row_width; i++)
  176610. {
  176611. *(dp++) = *(sp++);
  176612. *(dp++) = (png_byte)(255 - *(sp++));
  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. sp+=2; dp = sp;
  176623. *(dp++) = (png_byte)(255 - *(sp++));
  176624. *(dp++) = (png_byte)(255 - *(sp++));
  176625. }
  176626. }
  176627. }
  176628. }
  176629. }
  176630. #endif
  176631. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176632. void /* PRIVATE */
  176633. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176634. {
  176635. png_debug(1, "in png_do_write_intrapixel\n");
  176636. if (
  176637. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176638. row != NULL && row_info != NULL &&
  176639. #endif
  176640. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176641. {
  176642. int bytes_per_pixel;
  176643. png_uint_32 row_width = row_info->width;
  176644. if (row_info->bit_depth == 8)
  176645. {
  176646. png_bytep rp;
  176647. png_uint_32 i;
  176648. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176649. bytes_per_pixel = 3;
  176650. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176651. bytes_per_pixel = 4;
  176652. else
  176653. return;
  176654. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176655. {
  176656. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176657. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176658. }
  176659. }
  176660. else if (row_info->bit_depth == 16)
  176661. {
  176662. png_bytep rp;
  176663. png_uint_32 i;
  176664. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176665. bytes_per_pixel = 6;
  176666. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176667. bytes_per_pixel = 8;
  176668. else
  176669. return;
  176670. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176671. {
  176672. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176673. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176674. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176675. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176676. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176677. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176678. *(rp+1) = (png_byte)(red & 0xff);
  176679. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176680. *(rp+5) = (png_byte)(blue & 0xff);
  176681. }
  176682. }
  176683. }
  176684. }
  176685. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176686. #endif /* PNG_WRITE_SUPPORTED */
  176687. /*** End of inlined file: pngwtran.c ***/
  176688. /*** Start of inlined file: pngwutil.c ***/
  176689. #define PNG_INTERNAL
  176690. #ifdef PNG_WRITE_SUPPORTED
  176691. void PNGAPI
  176692. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176693. {
  176694. buf[0] = (png_byte)((i >> 24) & 0xff);
  176695. buf[1] = (png_byte)((i >> 16) & 0xff);
  176696. buf[2] = (png_byte)((i >> 8) & 0xff);
  176697. buf[3] = (png_byte)(i & 0xff);
  176698. }
  176699. void PNGAPI
  176700. png_save_int_32(png_bytep buf, png_int_32 i)
  176701. {
  176702. buf[0] = (png_byte)((i >> 24) & 0xff);
  176703. buf[1] = (png_byte)((i >> 16) & 0xff);
  176704. buf[2] = (png_byte)((i >> 8) & 0xff);
  176705. buf[3] = (png_byte)(i & 0xff);
  176706. }
  176707. void PNGAPI
  176708. png_save_uint_16(png_bytep buf, unsigned int i)
  176709. {
  176710. buf[0] = (png_byte)((i >> 8) & 0xff);
  176711. buf[1] = (png_byte)(i & 0xff);
  176712. }
  176713. void PNGAPI
  176714. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176715. png_bytep data, png_size_t length)
  176716. {
  176717. if(png_ptr == NULL) return;
  176718. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176719. png_write_chunk_data(png_ptr, data, length);
  176720. png_write_chunk_end(png_ptr);
  176721. }
  176722. void PNGAPI
  176723. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176724. png_uint_32 length)
  176725. {
  176726. png_byte buf[4];
  176727. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176728. if(png_ptr == NULL) return;
  176729. png_save_uint_32(buf, length);
  176730. png_write_data(png_ptr, buf, (png_size_t)4);
  176731. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176732. png_reset_crc(png_ptr);
  176733. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176734. }
  176735. void PNGAPI
  176736. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176737. {
  176738. if(png_ptr == NULL) return;
  176739. if (data != NULL && length > 0)
  176740. {
  176741. png_calculate_crc(png_ptr, data, length);
  176742. png_write_data(png_ptr, data, length);
  176743. }
  176744. }
  176745. void PNGAPI
  176746. png_write_chunk_end(png_structp png_ptr)
  176747. {
  176748. png_byte buf[4];
  176749. if(png_ptr == NULL) return;
  176750. png_save_uint_32(buf, png_ptr->crc);
  176751. png_write_data(png_ptr, buf, (png_size_t)4);
  176752. }
  176753. void /* PRIVATE */
  176754. png_write_sig(png_structp png_ptr)
  176755. {
  176756. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176757. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176758. (png_size_t)8 - png_ptr->sig_bytes);
  176759. if(png_ptr->sig_bytes < 3)
  176760. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176761. }
  176762. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176763. typedef struct
  176764. {
  176765. char *input; /* the uncompressed input data */
  176766. int input_len; /* its length */
  176767. int num_output_ptr; /* number of output pointers used */
  176768. int max_output_ptr; /* size of output_ptr */
  176769. png_charpp output_ptr; /* array of pointers to output */
  176770. } compression_state;
  176771. static int /* PRIVATE */
  176772. png_text_compress(png_structp png_ptr,
  176773. png_charp text, png_size_t text_len, int compression,
  176774. compression_state *comp)
  176775. {
  176776. int ret;
  176777. comp->num_output_ptr = 0;
  176778. comp->max_output_ptr = 0;
  176779. comp->output_ptr = NULL;
  176780. comp->input = NULL;
  176781. comp->input_len = 0;
  176782. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176783. {
  176784. comp->input = text;
  176785. comp->input_len = text_len;
  176786. return((int)text_len);
  176787. }
  176788. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176789. {
  176790. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176791. char msg[50];
  176792. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176793. png_warning(png_ptr, msg);
  176794. #else
  176795. png_warning(png_ptr, "Unknown compression type");
  176796. #endif
  176797. }
  176798. png_ptr->zstream.avail_in = (uInt)text_len;
  176799. png_ptr->zstream.next_in = (Bytef *)text;
  176800. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176801. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176802. do
  176803. {
  176804. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176805. if (ret != Z_OK)
  176806. {
  176807. if (png_ptr->zstream.msg != NULL)
  176808. png_error(png_ptr, png_ptr->zstream.msg);
  176809. else
  176810. png_error(png_ptr, "zlib error");
  176811. }
  176812. if (!(png_ptr->zstream.avail_out))
  176813. {
  176814. if (comp->num_output_ptr >= comp->max_output_ptr)
  176815. {
  176816. int old_max;
  176817. old_max = comp->max_output_ptr;
  176818. comp->max_output_ptr = comp->num_output_ptr + 4;
  176819. if (comp->output_ptr != NULL)
  176820. {
  176821. png_charpp old_ptr;
  176822. old_ptr = comp->output_ptr;
  176823. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176824. (png_uint_32)(comp->max_output_ptr *
  176825. png_sizeof (png_charpp)));
  176826. png_memcpy(comp->output_ptr, old_ptr, old_max
  176827. * png_sizeof (png_charp));
  176828. png_free(png_ptr, old_ptr);
  176829. }
  176830. else
  176831. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176832. (png_uint_32)(comp->max_output_ptr *
  176833. png_sizeof (png_charp)));
  176834. }
  176835. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176836. (png_uint_32)png_ptr->zbuf_size);
  176837. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176838. png_ptr->zbuf_size);
  176839. comp->num_output_ptr++;
  176840. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176841. png_ptr->zstream.next_out = png_ptr->zbuf;
  176842. }
  176843. } while (png_ptr->zstream.avail_in);
  176844. do
  176845. {
  176846. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176847. if (ret == Z_OK)
  176848. {
  176849. if (!(png_ptr->zstream.avail_out))
  176850. {
  176851. if (comp->num_output_ptr >= comp->max_output_ptr)
  176852. {
  176853. int old_max;
  176854. old_max = comp->max_output_ptr;
  176855. comp->max_output_ptr = comp->num_output_ptr + 4;
  176856. if (comp->output_ptr != NULL)
  176857. {
  176858. png_charpp old_ptr;
  176859. old_ptr = comp->output_ptr;
  176860. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176861. (png_uint_32)(comp->max_output_ptr *
  176862. png_sizeof (png_charpp)));
  176863. png_memcpy(comp->output_ptr, old_ptr,
  176864. old_max * png_sizeof (png_charp));
  176865. png_free(png_ptr, old_ptr);
  176866. }
  176867. else
  176868. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176869. (png_uint_32)(comp->max_output_ptr *
  176870. png_sizeof (png_charp)));
  176871. }
  176872. comp->output_ptr[comp->num_output_ptr] =
  176873. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176874. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176875. png_ptr->zbuf_size);
  176876. comp->num_output_ptr++;
  176877. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176878. png_ptr->zstream.next_out = png_ptr->zbuf;
  176879. }
  176880. }
  176881. else if (ret != Z_STREAM_END)
  176882. {
  176883. if (png_ptr->zstream.msg != NULL)
  176884. png_error(png_ptr, png_ptr->zstream.msg);
  176885. else
  176886. png_error(png_ptr, "zlib error");
  176887. }
  176888. } while (ret != Z_STREAM_END);
  176889. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176890. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176891. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176892. return((int)text_len);
  176893. }
  176894. static void /* PRIVATE */
  176895. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176896. {
  176897. int i;
  176898. if (comp->input)
  176899. {
  176900. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176901. (png_size_t)comp->input_len);
  176902. return;
  176903. }
  176904. for (i = 0; i < comp->num_output_ptr; i++)
  176905. {
  176906. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176907. png_ptr->zbuf_size);
  176908. png_free(png_ptr, comp->output_ptr[i]);
  176909. comp->output_ptr[i]=NULL;
  176910. }
  176911. if (comp->max_output_ptr != 0)
  176912. png_free(png_ptr, comp->output_ptr);
  176913. comp->output_ptr=NULL;
  176914. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176915. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176916. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176917. deflateReset(&png_ptr->zstream);
  176918. png_ptr->zstream.data_type = Z_BINARY;
  176919. }
  176920. #endif
  176921. void /* PRIVATE */
  176922. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  176923. int bit_depth, int color_type, int compression_type, int filter_type,
  176924. int interlace_type)
  176925. {
  176926. #ifdef PNG_USE_LOCAL_ARRAYS
  176927. PNG_IHDR;
  176928. #endif
  176929. png_byte buf[13]; /* buffer to store the IHDR info */
  176930. png_debug(1, "in png_write_IHDR\n");
  176931. switch (color_type)
  176932. {
  176933. case PNG_COLOR_TYPE_GRAY:
  176934. switch (bit_depth)
  176935. {
  176936. case 1:
  176937. case 2:
  176938. case 4:
  176939. case 8:
  176940. case 16: png_ptr->channels = 1; break;
  176941. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  176942. }
  176943. break;
  176944. case PNG_COLOR_TYPE_RGB:
  176945. if (bit_depth != 8 && bit_depth != 16)
  176946. png_error(png_ptr, "Invalid bit depth for RGB image");
  176947. png_ptr->channels = 3;
  176948. break;
  176949. case PNG_COLOR_TYPE_PALETTE:
  176950. switch (bit_depth)
  176951. {
  176952. case 1:
  176953. case 2:
  176954. case 4:
  176955. case 8: png_ptr->channels = 1; break;
  176956. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  176957. }
  176958. break;
  176959. case PNG_COLOR_TYPE_GRAY_ALPHA:
  176960. if (bit_depth != 8 && bit_depth != 16)
  176961. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  176962. png_ptr->channels = 2;
  176963. break;
  176964. case PNG_COLOR_TYPE_RGB_ALPHA:
  176965. if (bit_depth != 8 && bit_depth != 16)
  176966. png_error(png_ptr, "Invalid bit depth for RGBA image");
  176967. png_ptr->channels = 4;
  176968. break;
  176969. default:
  176970. png_error(png_ptr, "Invalid image color type specified");
  176971. }
  176972. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  176973. {
  176974. png_warning(png_ptr, "Invalid compression type specified");
  176975. compression_type = PNG_COMPRESSION_TYPE_BASE;
  176976. }
  176977. if (
  176978. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176979. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176980. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  176981. (color_type == PNG_COLOR_TYPE_RGB ||
  176982. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  176983. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  176984. #endif
  176985. filter_type != PNG_FILTER_TYPE_BASE)
  176986. {
  176987. png_warning(png_ptr, "Invalid filter type specified");
  176988. filter_type = PNG_FILTER_TYPE_BASE;
  176989. }
  176990. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  176991. if (interlace_type != PNG_INTERLACE_NONE &&
  176992. interlace_type != PNG_INTERLACE_ADAM7)
  176993. {
  176994. png_warning(png_ptr, "Invalid interlace type specified");
  176995. interlace_type = PNG_INTERLACE_ADAM7;
  176996. }
  176997. #else
  176998. interlace_type=PNG_INTERLACE_NONE;
  176999. #endif
  177000. png_ptr->bit_depth = (png_byte)bit_depth;
  177001. png_ptr->color_type = (png_byte)color_type;
  177002. png_ptr->interlaced = (png_byte)interlace_type;
  177003. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177004. png_ptr->filter_type = (png_byte)filter_type;
  177005. #endif
  177006. png_ptr->compression_type = (png_byte)compression_type;
  177007. png_ptr->width = width;
  177008. png_ptr->height = height;
  177009. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177010. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177011. png_ptr->usr_width = png_ptr->width;
  177012. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177013. png_ptr->usr_channels = png_ptr->channels;
  177014. png_save_uint_32(buf, width);
  177015. png_save_uint_32(buf + 4, height);
  177016. buf[8] = (png_byte)bit_depth;
  177017. buf[9] = (png_byte)color_type;
  177018. buf[10] = (png_byte)compression_type;
  177019. buf[11] = (png_byte)filter_type;
  177020. buf[12] = (png_byte)interlace_type;
  177021. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177022. png_ptr->zstream.zalloc = png_zalloc;
  177023. png_ptr->zstream.zfree = png_zfree;
  177024. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177025. if (!(png_ptr->do_filter))
  177026. {
  177027. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177028. png_ptr->bit_depth < 8)
  177029. png_ptr->do_filter = PNG_FILTER_NONE;
  177030. else
  177031. png_ptr->do_filter = PNG_ALL_FILTERS;
  177032. }
  177033. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177034. {
  177035. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177036. png_ptr->zlib_strategy = Z_FILTERED;
  177037. else
  177038. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177039. }
  177040. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177041. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177042. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177043. png_ptr->zlib_mem_level = 8;
  177044. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177045. png_ptr->zlib_window_bits = 15;
  177046. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177047. png_ptr->zlib_method = 8;
  177048. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177049. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177050. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177051. png_error(png_ptr, "zlib failed to initialize compressor");
  177052. png_ptr->zstream.next_out = png_ptr->zbuf;
  177053. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177054. png_ptr->zstream.data_type = Z_BINARY;
  177055. png_ptr->mode = PNG_HAVE_IHDR;
  177056. }
  177057. void /* PRIVATE */
  177058. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177059. {
  177060. #ifdef PNG_USE_LOCAL_ARRAYS
  177061. PNG_PLTE;
  177062. #endif
  177063. png_uint_32 i;
  177064. png_colorp pal_ptr;
  177065. png_byte buf[3];
  177066. png_debug(1, "in png_write_PLTE\n");
  177067. if ((
  177068. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177069. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177070. #endif
  177071. num_pal == 0) || num_pal > 256)
  177072. {
  177073. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177074. {
  177075. png_error(png_ptr, "Invalid number of colors in palette");
  177076. }
  177077. else
  177078. {
  177079. png_warning(png_ptr, "Invalid number of colors in palette");
  177080. return;
  177081. }
  177082. }
  177083. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177084. {
  177085. png_warning(png_ptr,
  177086. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177087. return;
  177088. }
  177089. png_ptr->num_palette = (png_uint_16)num_pal;
  177090. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177091. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177092. #ifndef PNG_NO_POINTER_INDEXING
  177093. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177094. {
  177095. buf[0] = pal_ptr->red;
  177096. buf[1] = pal_ptr->green;
  177097. buf[2] = pal_ptr->blue;
  177098. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177099. }
  177100. #else
  177101. pal_ptr=palette;
  177102. for (i = 0; i < num_pal; i++)
  177103. {
  177104. buf[0] = pal_ptr[i].red;
  177105. buf[1] = pal_ptr[i].green;
  177106. buf[2] = pal_ptr[i].blue;
  177107. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177108. }
  177109. #endif
  177110. png_write_chunk_end(png_ptr);
  177111. png_ptr->mode |= PNG_HAVE_PLTE;
  177112. }
  177113. void /* PRIVATE */
  177114. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177115. {
  177116. #ifdef PNG_USE_LOCAL_ARRAYS
  177117. PNG_IDAT;
  177118. #endif
  177119. png_debug(1, "in png_write_IDAT\n");
  177120. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177121. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177122. {
  177123. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177124. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177125. {
  177126. if (length >= 2 &&
  177127. png_ptr->height < 16384 && png_ptr->width < 16384)
  177128. {
  177129. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177130. ((png_ptr->width *
  177131. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177132. unsigned int z_cinfo = z_cmf >> 4;
  177133. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177134. while (uncompressed_idat_size <= half_z_window_size &&
  177135. half_z_window_size >= 256)
  177136. {
  177137. z_cinfo--;
  177138. half_z_window_size >>= 1;
  177139. }
  177140. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177141. if (data[0] != (png_byte)z_cmf)
  177142. {
  177143. data[0] = (png_byte)z_cmf;
  177144. data[1] &= 0xe0;
  177145. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177146. }
  177147. }
  177148. }
  177149. else
  177150. png_error(png_ptr,
  177151. "Invalid zlib compression method or flags in IDAT");
  177152. }
  177153. png_write_chunk(png_ptr, png_IDAT, data, length);
  177154. png_ptr->mode |= PNG_HAVE_IDAT;
  177155. }
  177156. void /* PRIVATE */
  177157. png_write_IEND(png_structp png_ptr)
  177158. {
  177159. #ifdef PNG_USE_LOCAL_ARRAYS
  177160. PNG_IEND;
  177161. #endif
  177162. png_debug(1, "in png_write_IEND\n");
  177163. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177164. (png_size_t)0);
  177165. png_ptr->mode |= PNG_HAVE_IEND;
  177166. }
  177167. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177168. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177169. void /* PRIVATE */
  177170. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177171. {
  177172. #ifdef PNG_USE_LOCAL_ARRAYS
  177173. PNG_gAMA;
  177174. #endif
  177175. png_uint_32 igamma;
  177176. png_byte buf[4];
  177177. png_debug(1, "in png_write_gAMA\n");
  177178. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177179. png_save_uint_32(buf, igamma);
  177180. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177181. }
  177182. #endif
  177183. #ifdef PNG_FIXED_POINT_SUPPORTED
  177184. void /* PRIVATE */
  177185. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177186. {
  177187. #ifdef PNG_USE_LOCAL_ARRAYS
  177188. PNG_gAMA;
  177189. #endif
  177190. png_byte buf[4];
  177191. png_debug(1, "in png_write_gAMA\n");
  177192. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177193. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177194. }
  177195. #endif
  177196. #endif
  177197. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177198. void /* PRIVATE */
  177199. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177200. {
  177201. #ifdef PNG_USE_LOCAL_ARRAYS
  177202. PNG_sRGB;
  177203. #endif
  177204. png_byte buf[1];
  177205. png_debug(1, "in png_write_sRGB\n");
  177206. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177207. png_warning(png_ptr,
  177208. "Invalid sRGB rendering intent specified");
  177209. buf[0]=(png_byte)srgb_intent;
  177210. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177211. }
  177212. #endif
  177213. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177214. void /* PRIVATE */
  177215. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177216. png_charp profile, int profile_len)
  177217. {
  177218. #ifdef PNG_USE_LOCAL_ARRAYS
  177219. PNG_iCCP;
  177220. #endif
  177221. png_size_t name_len;
  177222. png_charp new_name;
  177223. compression_state comp;
  177224. int embedded_profile_len = 0;
  177225. png_debug(1, "in png_write_iCCP\n");
  177226. comp.num_output_ptr = 0;
  177227. comp.max_output_ptr = 0;
  177228. comp.output_ptr = NULL;
  177229. comp.input = NULL;
  177230. comp.input_len = 0;
  177231. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177232. &new_name)) == 0)
  177233. {
  177234. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177235. return;
  177236. }
  177237. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177238. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177239. if (profile == NULL)
  177240. profile_len = 0;
  177241. if (profile_len > 3)
  177242. embedded_profile_len =
  177243. ((*( (png_bytep)profile ))<<24) |
  177244. ((*( (png_bytep)profile+1))<<16) |
  177245. ((*( (png_bytep)profile+2))<< 8) |
  177246. ((*( (png_bytep)profile+3)) );
  177247. if (profile_len < embedded_profile_len)
  177248. {
  177249. png_warning(png_ptr,
  177250. "Embedded profile length too large in iCCP chunk");
  177251. return;
  177252. }
  177253. if (profile_len > embedded_profile_len)
  177254. {
  177255. png_warning(png_ptr,
  177256. "Truncating profile to actual length in iCCP chunk");
  177257. profile_len = embedded_profile_len;
  177258. }
  177259. if (profile_len)
  177260. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177261. PNG_COMPRESSION_TYPE_BASE, &comp);
  177262. png_write_chunk_start(png_ptr, png_iCCP,
  177263. (png_uint_32)name_len+profile_len+2);
  177264. new_name[name_len+1]=0x00;
  177265. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177266. if (profile_len)
  177267. png_write_compressed_data_out(png_ptr, &comp);
  177268. png_write_chunk_end(png_ptr);
  177269. png_free(png_ptr, new_name);
  177270. }
  177271. #endif
  177272. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177273. void /* PRIVATE */
  177274. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177275. {
  177276. #ifdef PNG_USE_LOCAL_ARRAYS
  177277. PNG_sPLT;
  177278. #endif
  177279. png_size_t name_len;
  177280. png_charp new_name;
  177281. png_byte entrybuf[10];
  177282. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177283. int palette_size = entry_size * spalette->nentries;
  177284. png_sPLT_entryp ep;
  177285. #ifdef PNG_NO_POINTER_INDEXING
  177286. int i;
  177287. #endif
  177288. png_debug(1, "in png_write_sPLT\n");
  177289. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177290. spalette->name, &new_name))==0)
  177291. {
  177292. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177293. return;
  177294. }
  177295. png_write_chunk_start(png_ptr, png_sPLT,
  177296. (png_uint_32)(name_len + 2 + palette_size));
  177297. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177298. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177299. #ifndef PNG_NO_POINTER_INDEXING
  177300. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177301. {
  177302. if (spalette->depth == 8)
  177303. {
  177304. entrybuf[0] = (png_byte)ep->red;
  177305. entrybuf[1] = (png_byte)ep->green;
  177306. entrybuf[2] = (png_byte)ep->blue;
  177307. entrybuf[3] = (png_byte)ep->alpha;
  177308. png_save_uint_16(entrybuf + 4, ep->frequency);
  177309. }
  177310. else
  177311. {
  177312. png_save_uint_16(entrybuf + 0, ep->red);
  177313. png_save_uint_16(entrybuf + 2, ep->green);
  177314. png_save_uint_16(entrybuf + 4, ep->blue);
  177315. png_save_uint_16(entrybuf + 6, ep->alpha);
  177316. png_save_uint_16(entrybuf + 8, ep->frequency);
  177317. }
  177318. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177319. }
  177320. #else
  177321. ep=spalette->entries;
  177322. for (i=0; i>spalette->nentries; i++)
  177323. {
  177324. if (spalette->depth == 8)
  177325. {
  177326. entrybuf[0] = (png_byte)ep[i].red;
  177327. entrybuf[1] = (png_byte)ep[i].green;
  177328. entrybuf[2] = (png_byte)ep[i].blue;
  177329. entrybuf[3] = (png_byte)ep[i].alpha;
  177330. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177331. }
  177332. else
  177333. {
  177334. png_save_uint_16(entrybuf + 0, ep[i].red);
  177335. png_save_uint_16(entrybuf + 2, ep[i].green);
  177336. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177337. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177338. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177339. }
  177340. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177341. }
  177342. #endif
  177343. png_write_chunk_end(png_ptr);
  177344. png_free(png_ptr, new_name);
  177345. }
  177346. #endif
  177347. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177348. void /* PRIVATE */
  177349. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177350. {
  177351. #ifdef PNG_USE_LOCAL_ARRAYS
  177352. PNG_sBIT;
  177353. #endif
  177354. png_byte buf[4];
  177355. png_size_t size;
  177356. png_debug(1, "in png_write_sBIT\n");
  177357. if (color_type & PNG_COLOR_MASK_COLOR)
  177358. {
  177359. png_byte maxbits;
  177360. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177361. png_ptr->usr_bit_depth);
  177362. if (sbit->red == 0 || sbit->red > maxbits ||
  177363. sbit->green == 0 || sbit->green > maxbits ||
  177364. sbit->blue == 0 || sbit->blue > maxbits)
  177365. {
  177366. png_warning(png_ptr, "Invalid sBIT depth specified");
  177367. return;
  177368. }
  177369. buf[0] = sbit->red;
  177370. buf[1] = sbit->green;
  177371. buf[2] = sbit->blue;
  177372. size = 3;
  177373. }
  177374. else
  177375. {
  177376. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177377. {
  177378. png_warning(png_ptr, "Invalid sBIT depth specified");
  177379. return;
  177380. }
  177381. buf[0] = sbit->gray;
  177382. size = 1;
  177383. }
  177384. if (color_type & PNG_COLOR_MASK_ALPHA)
  177385. {
  177386. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177387. {
  177388. png_warning(png_ptr, "Invalid sBIT depth specified");
  177389. return;
  177390. }
  177391. buf[size++] = sbit->alpha;
  177392. }
  177393. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177394. }
  177395. #endif
  177396. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177397. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177398. void /* PRIVATE */
  177399. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177400. double red_x, double red_y, double green_x, double green_y,
  177401. double blue_x, double blue_y)
  177402. {
  177403. #ifdef PNG_USE_LOCAL_ARRAYS
  177404. PNG_cHRM;
  177405. #endif
  177406. png_byte buf[32];
  177407. png_uint_32 itemp;
  177408. png_debug(1, "in png_write_cHRM\n");
  177409. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177410. white_x + white_y > 1.0)
  177411. {
  177412. png_warning(png_ptr, "Invalid cHRM white point specified");
  177413. #if !defined(PNG_NO_CONSOLE_IO)
  177414. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177415. #endif
  177416. return;
  177417. }
  177418. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177419. png_save_uint_32(buf, itemp);
  177420. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177421. png_save_uint_32(buf + 4, itemp);
  177422. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177423. {
  177424. png_warning(png_ptr, "Invalid cHRM red point specified");
  177425. return;
  177426. }
  177427. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177428. png_save_uint_32(buf + 8, itemp);
  177429. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177430. png_save_uint_32(buf + 12, itemp);
  177431. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177432. {
  177433. png_warning(png_ptr, "Invalid cHRM green point specified");
  177434. return;
  177435. }
  177436. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177437. png_save_uint_32(buf + 16, itemp);
  177438. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177439. png_save_uint_32(buf + 20, itemp);
  177440. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177441. {
  177442. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177443. return;
  177444. }
  177445. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177446. png_save_uint_32(buf + 24, itemp);
  177447. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177448. png_save_uint_32(buf + 28, itemp);
  177449. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177450. }
  177451. #endif
  177452. #ifdef PNG_FIXED_POINT_SUPPORTED
  177453. void /* PRIVATE */
  177454. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177455. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177456. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177457. png_fixed_point blue_y)
  177458. {
  177459. #ifdef PNG_USE_LOCAL_ARRAYS
  177460. PNG_cHRM;
  177461. #endif
  177462. png_byte buf[32];
  177463. png_debug(1, "in png_write_cHRM\n");
  177464. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177465. {
  177466. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177467. #if !defined(PNG_NO_CONSOLE_IO)
  177468. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177469. #endif
  177470. return;
  177471. }
  177472. png_save_uint_32(buf, (png_uint_32)white_x);
  177473. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177474. if (red_x + red_y > 100000L)
  177475. {
  177476. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177477. return;
  177478. }
  177479. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177480. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177481. if (green_x + green_y > 100000L)
  177482. {
  177483. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177484. return;
  177485. }
  177486. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177487. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177488. if (blue_x + blue_y > 100000L)
  177489. {
  177490. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177491. return;
  177492. }
  177493. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177494. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177495. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177496. }
  177497. #endif
  177498. #endif
  177499. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177500. void /* PRIVATE */
  177501. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177502. int num_trans, int color_type)
  177503. {
  177504. #ifdef PNG_USE_LOCAL_ARRAYS
  177505. PNG_tRNS;
  177506. #endif
  177507. png_byte buf[6];
  177508. png_debug(1, "in png_write_tRNS\n");
  177509. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177510. {
  177511. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177512. {
  177513. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177514. return;
  177515. }
  177516. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177517. }
  177518. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177519. {
  177520. if(tran->gray >= (1 << png_ptr->bit_depth))
  177521. {
  177522. png_warning(png_ptr,
  177523. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177524. return;
  177525. }
  177526. png_save_uint_16(buf, tran->gray);
  177527. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177528. }
  177529. else if (color_type == PNG_COLOR_TYPE_RGB)
  177530. {
  177531. png_save_uint_16(buf, tran->red);
  177532. png_save_uint_16(buf + 2, tran->green);
  177533. png_save_uint_16(buf + 4, tran->blue);
  177534. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177535. {
  177536. png_warning(png_ptr,
  177537. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177538. return;
  177539. }
  177540. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177541. }
  177542. else
  177543. {
  177544. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177545. }
  177546. }
  177547. #endif
  177548. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177549. void /* PRIVATE */
  177550. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177551. {
  177552. #ifdef PNG_USE_LOCAL_ARRAYS
  177553. PNG_bKGD;
  177554. #endif
  177555. png_byte buf[6];
  177556. png_debug(1, "in png_write_bKGD\n");
  177557. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177558. {
  177559. if (
  177560. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177561. (png_ptr->num_palette ||
  177562. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177563. #endif
  177564. back->index > png_ptr->num_palette)
  177565. {
  177566. png_warning(png_ptr, "Invalid background palette index");
  177567. return;
  177568. }
  177569. buf[0] = back->index;
  177570. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177571. }
  177572. else if (color_type & PNG_COLOR_MASK_COLOR)
  177573. {
  177574. png_save_uint_16(buf, back->red);
  177575. png_save_uint_16(buf + 2, back->green);
  177576. png_save_uint_16(buf + 4, back->blue);
  177577. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177578. {
  177579. png_warning(png_ptr,
  177580. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177581. return;
  177582. }
  177583. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177584. }
  177585. else
  177586. {
  177587. if(back->gray >= (1 << png_ptr->bit_depth))
  177588. {
  177589. png_warning(png_ptr,
  177590. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177591. return;
  177592. }
  177593. png_save_uint_16(buf, back->gray);
  177594. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177595. }
  177596. }
  177597. #endif
  177598. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177599. void /* PRIVATE */
  177600. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177601. {
  177602. #ifdef PNG_USE_LOCAL_ARRAYS
  177603. PNG_hIST;
  177604. #endif
  177605. int i;
  177606. png_byte buf[3];
  177607. png_debug(1, "in png_write_hIST\n");
  177608. if (num_hist > (int)png_ptr->num_palette)
  177609. {
  177610. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177611. png_ptr->num_palette);
  177612. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177613. return;
  177614. }
  177615. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177616. for (i = 0; i < num_hist; i++)
  177617. {
  177618. png_save_uint_16(buf, hist[i]);
  177619. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177620. }
  177621. png_write_chunk_end(png_ptr);
  177622. }
  177623. #endif
  177624. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177625. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177626. png_size_t /* PRIVATE */
  177627. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177628. {
  177629. png_size_t key_len;
  177630. png_charp kp, dp;
  177631. int kflag;
  177632. int kwarn=0;
  177633. png_debug(1, "in png_check_keyword\n");
  177634. *new_key = NULL;
  177635. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177636. {
  177637. png_warning(png_ptr, "zero length keyword");
  177638. return ((png_size_t)0);
  177639. }
  177640. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177641. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177642. if (*new_key == NULL)
  177643. {
  177644. png_warning(png_ptr, "Out of memory while procesing keyword");
  177645. return ((png_size_t)0);
  177646. }
  177647. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177648. {
  177649. if ((png_byte)*kp < 0x20 ||
  177650. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177651. {
  177652. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177653. char msg[40];
  177654. png_snprintf(msg, 40,
  177655. "invalid keyword character 0x%02X", (png_byte)*kp);
  177656. png_warning(png_ptr, msg);
  177657. #else
  177658. png_warning(png_ptr, "invalid character in keyword");
  177659. #endif
  177660. *dp = ' ';
  177661. }
  177662. else
  177663. {
  177664. *dp = *kp;
  177665. }
  177666. }
  177667. *dp = '\0';
  177668. kp = *new_key + key_len - 1;
  177669. if (*kp == ' ')
  177670. {
  177671. png_warning(png_ptr, "trailing spaces removed from keyword");
  177672. while (*kp == ' ')
  177673. {
  177674. *(kp--) = '\0';
  177675. key_len--;
  177676. }
  177677. }
  177678. kp = *new_key;
  177679. if (*kp == ' ')
  177680. {
  177681. png_warning(png_ptr, "leading spaces removed from keyword");
  177682. while (*kp == ' ')
  177683. {
  177684. kp++;
  177685. key_len--;
  177686. }
  177687. }
  177688. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177689. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177690. {
  177691. if (*kp == ' ' && kflag == 0)
  177692. {
  177693. *(dp++) = *kp;
  177694. kflag = 1;
  177695. }
  177696. else if (*kp == ' ')
  177697. {
  177698. key_len--;
  177699. kwarn=1;
  177700. }
  177701. else
  177702. {
  177703. *(dp++) = *kp;
  177704. kflag = 0;
  177705. }
  177706. }
  177707. *dp = '\0';
  177708. if(kwarn)
  177709. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177710. if (key_len == 0)
  177711. {
  177712. png_free(png_ptr, *new_key);
  177713. *new_key=NULL;
  177714. png_warning(png_ptr, "Zero length keyword");
  177715. }
  177716. if (key_len > 79)
  177717. {
  177718. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177719. new_key[79] = '\0';
  177720. key_len = 79;
  177721. }
  177722. return (key_len);
  177723. }
  177724. #endif
  177725. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177726. void /* PRIVATE */
  177727. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177728. png_size_t text_len)
  177729. {
  177730. #ifdef PNG_USE_LOCAL_ARRAYS
  177731. PNG_tEXt;
  177732. #endif
  177733. png_size_t key_len;
  177734. png_charp new_key;
  177735. png_debug(1, "in png_write_tEXt\n");
  177736. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177737. {
  177738. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177739. return;
  177740. }
  177741. if (text == NULL || *text == '\0')
  177742. text_len = 0;
  177743. else
  177744. text_len = png_strlen(text);
  177745. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177746. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177747. if (text_len)
  177748. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177749. png_write_chunk_end(png_ptr);
  177750. png_free(png_ptr, new_key);
  177751. }
  177752. #endif
  177753. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177754. void /* PRIVATE */
  177755. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177756. png_size_t text_len, int compression)
  177757. {
  177758. #ifdef PNG_USE_LOCAL_ARRAYS
  177759. PNG_zTXt;
  177760. #endif
  177761. png_size_t key_len;
  177762. char buf[1];
  177763. png_charp new_key;
  177764. compression_state comp;
  177765. png_debug(1, "in png_write_zTXt\n");
  177766. comp.num_output_ptr = 0;
  177767. comp.max_output_ptr = 0;
  177768. comp.output_ptr = NULL;
  177769. comp.input = NULL;
  177770. comp.input_len = 0;
  177771. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177772. {
  177773. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177774. return;
  177775. }
  177776. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177777. {
  177778. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177779. png_free(png_ptr, new_key);
  177780. return;
  177781. }
  177782. text_len = png_strlen(text);
  177783. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177784. &comp);
  177785. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177786. (key_len+text_len+2));
  177787. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177788. png_free(png_ptr, new_key);
  177789. buf[0] = (png_byte)compression;
  177790. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177791. png_write_compressed_data_out(png_ptr, &comp);
  177792. png_write_chunk_end(png_ptr);
  177793. }
  177794. #endif
  177795. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177796. void /* PRIVATE */
  177797. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177798. png_charp lang, png_charp lang_key, png_charp text)
  177799. {
  177800. #ifdef PNG_USE_LOCAL_ARRAYS
  177801. PNG_iTXt;
  177802. #endif
  177803. png_size_t lang_len, key_len, lang_key_len, text_len;
  177804. png_charp new_lang, new_key;
  177805. png_byte cbuf[2];
  177806. compression_state comp;
  177807. png_debug(1, "in png_write_iTXt\n");
  177808. comp.num_output_ptr = 0;
  177809. comp.max_output_ptr = 0;
  177810. comp.output_ptr = NULL;
  177811. comp.input = NULL;
  177812. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177813. {
  177814. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177815. return;
  177816. }
  177817. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177818. {
  177819. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177820. new_lang = NULL;
  177821. lang_len = 0;
  177822. }
  177823. if (lang_key == NULL)
  177824. lang_key_len = 0;
  177825. else
  177826. lang_key_len = png_strlen(lang_key);
  177827. if (text == NULL)
  177828. text_len = 0;
  177829. else
  177830. text_len = png_strlen(text);
  177831. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177832. &comp);
  177833. png_write_chunk_start(png_ptr, png_iTXt,
  177834. (png_uint_32)(
  177835. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177836. + key_len
  177837. + lang_len
  177838. + lang_key_len
  177839. + text_len));
  177840. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177841. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177842. compression == PNG_TEXT_COMPRESSION_NONE)
  177843. cbuf[0] = 0;
  177844. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177845. cbuf[0] = 1;
  177846. cbuf[1] = 0;
  177847. png_write_chunk_data(png_ptr, cbuf, 2);
  177848. cbuf[0] = 0;
  177849. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177850. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177851. png_write_compressed_data_out(png_ptr, &comp);
  177852. png_write_chunk_end(png_ptr);
  177853. png_free(png_ptr, new_key);
  177854. if (new_lang)
  177855. png_free(png_ptr, new_lang);
  177856. }
  177857. #endif
  177858. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177859. void /* PRIVATE */
  177860. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177861. int unit_type)
  177862. {
  177863. #ifdef PNG_USE_LOCAL_ARRAYS
  177864. PNG_oFFs;
  177865. #endif
  177866. png_byte buf[9];
  177867. png_debug(1, "in png_write_oFFs\n");
  177868. if (unit_type >= PNG_OFFSET_LAST)
  177869. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177870. png_save_int_32(buf, x_offset);
  177871. png_save_int_32(buf + 4, y_offset);
  177872. buf[8] = (png_byte)unit_type;
  177873. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177874. }
  177875. #endif
  177876. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177877. void /* PRIVATE */
  177878. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177879. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177880. {
  177881. #ifdef PNG_USE_LOCAL_ARRAYS
  177882. PNG_pCAL;
  177883. #endif
  177884. png_size_t purpose_len, units_len, total_len;
  177885. png_uint_32p params_len;
  177886. png_byte buf[10];
  177887. png_charp new_purpose;
  177888. int i;
  177889. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177890. if (type >= PNG_EQUATION_LAST)
  177891. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177892. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177893. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177894. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177895. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177896. total_len = purpose_len + units_len + 10;
  177897. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177898. *png_sizeof(png_uint_32)));
  177899. for (i = 0; i < nparams; i++)
  177900. {
  177901. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177902. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177903. total_len += (png_size_t)params_len[i];
  177904. }
  177905. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177906. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177907. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177908. png_save_int_32(buf, X0);
  177909. png_save_int_32(buf + 4, X1);
  177910. buf[8] = (png_byte)type;
  177911. buf[9] = (png_byte)nparams;
  177912. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177913. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177914. png_free(png_ptr, new_purpose);
  177915. for (i = 0; i < nparams; i++)
  177916. {
  177917. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  177918. (png_size_t)params_len[i]);
  177919. }
  177920. png_free(png_ptr, params_len);
  177921. png_write_chunk_end(png_ptr);
  177922. }
  177923. #endif
  177924. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  177925. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  177926. void /* PRIVATE */
  177927. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  177928. {
  177929. #ifdef PNG_USE_LOCAL_ARRAYS
  177930. PNG_sCAL;
  177931. #endif
  177932. char buf[64];
  177933. png_size_t total_len;
  177934. png_debug(1, "in png_write_sCAL\n");
  177935. buf[0] = (char)unit;
  177936. #if defined(_WIN32_WCE)
  177937. {
  177938. wchar_t wc_buf[32];
  177939. size_t wc_len;
  177940. swprintf(wc_buf, TEXT("%12.12e"), width);
  177941. wc_len = wcslen(wc_buf);
  177942. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  177943. total_len = wc_len + 2;
  177944. swprintf(wc_buf, TEXT("%12.12e"), height);
  177945. wc_len = wcslen(wc_buf);
  177946. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  177947. NULL, NULL);
  177948. total_len += wc_len;
  177949. }
  177950. #else
  177951. png_snprintf(buf + 1, 63, "%12.12e", width);
  177952. total_len = 1 + png_strlen(buf + 1) + 1;
  177953. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  177954. total_len += png_strlen(buf + total_len);
  177955. #endif
  177956. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177957. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  177958. }
  177959. #else
  177960. #ifdef PNG_FIXED_POINT_SUPPORTED
  177961. void /* PRIVATE */
  177962. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  177963. png_charp height)
  177964. {
  177965. #ifdef PNG_USE_LOCAL_ARRAYS
  177966. PNG_sCAL;
  177967. #endif
  177968. png_byte buf[64];
  177969. png_size_t wlen, hlen, total_len;
  177970. png_debug(1, "in png_write_sCAL_s\n");
  177971. wlen = png_strlen(width);
  177972. hlen = png_strlen(height);
  177973. total_len = wlen + hlen + 2;
  177974. if (total_len > 64)
  177975. {
  177976. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  177977. return;
  177978. }
  177979. buf[0] = (png_byte)unit;
  177980. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  177981. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  177982. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177983. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  177984. }
  177985. #endif
  177986. #endif
  177987. #endif
  177988. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  177989. void /* PRIVATE */
  177990. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  177991. png_uint_32 y_pixels_per_unit,
  177992. int unit_type)
  177993. {
  177994. #ifdef PNG_USE_LOCAL_ARRAYS
  177995. PNG_pHYs;
  177996. #endif
  177997. png_byte buf[9];
  177998. png_debug(1, "in png_write_pHYs\n");
  177999. if (unit_type >= PNG_RESOLUTION_LAST)
  178000. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178001. png_save_uint_32(buf, x_pixels_per_unit);
  178002. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178003. buf[8] = (png_byte)unit_type;
  178004. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178005. }
  178006. #endif
  178007. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178008. void /* PRIVATE */
  178009. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178010. {
  178011. #ifdef PNG_USE_LOCAL_ARRAYS
  178012. PNG_tIME;
  178013. #endif
  178014. png_byte buf[7];
  178015. png_debug(1, "in png_write_tIME\n");
  178016. if (mod_time->month > 12 || mod_time->month < 1 ||
  178017. mod_time->day > 31 || mod_time->day < 1 ||
  178018. mod_time->hour > 23 || mod_time->second > 60)
  178019. {
  178020. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178021. return;
  178022. }
  178023. png_save_uint_16(buf, mod_time->year);
  178024. buf[2] = mod_time->month;
  178025. buf[3] = mod_time->day;
  178026. buf[4] = mod_time->hour;
  178027. buf[5] = mod_time->minute;
  178028. buf[6] = mod_time->second;
  178029. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178030. }
  178031. #endif
  178032. void /* PRIVATE */
  178033. png_write_start_row(png_structp png_ptr)
  178034. {
  178035. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178036. #ifdef PNG_USE_LOCAL_ARRAYS
  178037. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178038. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178039. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178040. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178041. #endif
  178042. #endif
  178043. png_size_t buf_size;
  178044. png_debug(1, "in png_write_start_row\n");
  178045. buf_size = (png_size_t)(PNG_ROWBYTES(
  178046. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178047. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178048. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178049. #ifndef PNG_NO_WRITE_FILTERING
  178050. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178051. {
  178052. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178053. (png_ptr->rowbytes + 1));
  178054. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178055. }
  178056. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178057. {
  178058. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178059. png_memset(png_ptr->prev_row, 0, buf_size);
  178060. if (png_ptr->do_filter & PNG_FILTER_UP)
  178061. {
  178062. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178063. (png_ptr->rowbytes + 1));
  178064. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178065. }
  178066. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178067. {
  178068. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178069. (png_ptr->rowbytes + 1));
  178070. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178071. }
  178072. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178073. {
  178074. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178075. (png_ptr->rowbytes + 1));
  178076. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178077. }
  178078. #endif /* PNG_NO_WRITE_FILTERING */
  178079. }
  178080. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178081. if (png_ptr->interlaced)
  178082. {
  178083. if (!(png_ptr->transformations & PNG_INTERLACE))
  178084. {
  178085. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178086. png_pass_ystart[0]) / png_pass_yinc[0];
  178087. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178088. png_pass_start[0]) / png_pass_inc[0];
  178089. }
  178090. else
  178091. {
  178092. png_ptr->num_rows = png_ptr->height;
  178093. png_ptr->usr_width = png_ptr->width;
  178094. }
  178095. }
  178096. else
  178097. #endif
  178098. {
  178099. png_ptr->num_rows = png_ptr->height;
  178100. png_ptr->usr_width = png_ptr->width;
  178101. }
  178102. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178103. png_ptr->zstream.next_out = png_ptr->zbuf;
  178104. }
  178105. void /* PRIVATE */
  178106. png_write_finish_row(png_structp png_ptr)
  178107. {
  178108. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178109. #ifdef PNG_USE_LOCAL_ARRAYS
  178110. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178111. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178112. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178113. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178114. #endif
  178115. #endif
  178116. int ret;
  178117. png_debug(1, "in png_write_finish_row\n");
  178118. png_ptr->row_number++;
  178119. if (png_ptr->row_number < png_ptr->num_rows)
  178120. return;
  178121. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178122. if (png_ptr->interlaced)
  178123. {
  178124. png_ptr->row_number = 0;
  178125. if (png_ptr->transformations & PNG_INTERLACE)
  178126. {
  178127. png_ptr->pass++;
  178128. }
  178129. else
  178130. {
  178131. do
  178132. {
  178133. png_ptr->pass++;
  178134. if (png_ptr->pass >= 7)
  178135. break;
  178136. png_ptr->usr_width = (png_ptr->width +
  178137. png_pass_inc[png_ptr->pass] - 1 -
  178138. png_pass_start[png_ptr->pass]) /
  178139. png_pass_inc[png_ptr->pass];
  178140. png_ptr->num_rows = (png_ptr->height +
  178141. png_pass_yinc[png_ptr->pass] - 1 -
  178142. png_pass_ystart[png_ptr->pass]) /
  178143. png_pass_yinc[png_ptr->pass];
  178144. if (png_ptr->transformations & PNG_INTERLACE)
  178145. break;
  178146. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178147. }
  178148. if (png_ptr->pass < 7)
  178149. {
  178150. if (png_ptr->prev_row != NULL)
  178151. png_memset(png_ptr->prev_row, 0,
  178152. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178153. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178154. return;
  178155. }
  178156. }
  178157. #endif
  178158. do
  178159. {
  178160. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178161. if (ret == Z_OK)
  178162. {
  178163. if (!(png_ptr->zstream.avail_out))
  178164. {
  178165. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178166. png_ptr->zstream.next_out = png_ptr->zbuf;
  178167. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178168. }
  178169. }
  178170. else if (ret != Z_STREAM_END)
  178171. {
  178172. if (png_ptr->zstream.msg != NULL)
  178173. png_error(png_ptr, png_ptr->zstream.msg);
  178174. else
  178175. png_error(png_ptr, "zlib error");
  178176. }
  178177. } while (ret != Z_STREAM_END);
  178178. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178179. {
  178180. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178181. png_ptr->zstream.avail_out);
  178182. }
  178183. deflateReset(&png_ptr->zstream);
  178184. png_ptr->zstream.data_type = Z_BINARY;
  178185. }
  178186. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178187. void /* PRIVATE */
  178188. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178189. {
  178190. #ifdef PNG_USE_LOCAL_ARRAYS
  178191. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178192. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178193. #endif
  178194. png_debug(1, "in png_do_write_interlace\n");
  178195. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178196. if (row != NULL && row_info != NULL && pass < 6)
  178197. #else
  178198. if (pass < 6)
  178199. #endif
  178200. {
  178201. switch (row_info->pixel_depth)
  178202. {
  178203. case 1:
  178204. {
  178205. png_bytep sp;
  178206. png_bytep dp;
  178207. int shift;
  178208. int d;
  178209. int value;
  178210. png_uint_32 i;
  178211. png_uint_32 row_width = row_info->width;
  178212. dp = row;
  178213. d = 0;
  178214. shift = 7;
  178215. for (i = png_pass_start[pass]; i < row_width;
  178216. i += png_pass_inc[pass])
  178217. {
  178218. sp = row + (png_size_t)(i >> 3);
  178219. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178220. d |= (value << shift);
  178221. if (shift == 0)
  178222. {
  178223. shift = 7;
  178224. *dp++ = (png_byte)d;
  178225. d = 0;
  178226. }
  178227. else
  178228. shift--;
  178229. }
  178230. if (shift != 7)
  178231. *dp = (png_byte)d;
  178232. break;
  178233. }
  178234. case 2:
  178235. {
  178236. png_bytep sp;
  178237. png_bytep dp;
  178238. int shift;
  178239. int d;
  178240. int value;
  178241. png_uint_32 i;
  178242. png_uint_32 row_width = row_info->width;
  178243. dp = row;
  178244. shift = 6;
  178245. d = 0;
  178246. for (i = png_pass_start[pass]; i < row_width;
  178247. i += png_pass_inc[pass])
  178248. {
  178249. sp = row + (png_size_t)(i >> 2);
  178250. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178251. d |= (value << shift);
  178252. if (shift == 0)
  178253. {
  178254. shift = 6;
  178255. *dp++ = (png_byte)d;
  178256. d = 0;
  178257. }
  178258. else
  178259. shift -= 2;
  178260. }
  178261. if (shift != 6)
  178262. *dp = (png_byte)d;
  178263. break;
  178264. }
  178265. case 4:
  178266. {
  178267. png_bytep sp;
  178268. png_bytep dp;
  178269. int shift;
  178270. int d;
  178271. int value;
  178272. png_uint_32 i;
  178273. png_uint_32 row_width = row_info->width;
  178274. dp = row;
  178275. shift = 4;
  178276. d = 0;
  178277. for (i = png_pass_start[pass]; i < row_width;
  178278. i += png_pass_inc[pass])
  178279. {
  178280. sp = row + (png_size_t)(i >> 1);
  178281. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178282. d |= (value << shift);
  178283. if (shift == 0)
  178284. {
  178285. shift = 4;
  178286. *dp++ = (png_byte)d;
  178287. d = 0;
  178288. }
  178289. else
  178290. shift -= 4;
  178291. }
  178292. if (shift != 4)
  178293. *dp = (png_byte)d;
  178294. break;
  178295. }
  178296. default:
  178297. {
  178298. png_bytep sp;
  178299. png_bytep dp;
  178300. png_uint_32 i;
  178301. png_uint_32 row_width = row_info->width;
  178302. png_size_t pixel_bytes;
  178303. dp = row;
  178304. pixel_bytes = (row_info->pixel_depth >> 3);
  178305. for (i = png_pass_start[pass]; i < row_width;
  178306. i += png_pass_inc[pass])
  178307. {
  178308. sp = row + (png_size_t)i * pixel_bytes;
  178309. if (dp != sp)
  178310. png_memcpy(dp, sp, pixel_bytes);
  178311. dp += pixel_bytes;
  178312. }
  178313. break;
  178314. }
  178315. }
  178316. row_info->width = (row_info->width +
  178317. png_pass_inc[pass] - 1 -
  178318. png_pass_start[pass]) /
  178319. png_pass_inc[pass];
  178320. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178321. row_info->width);
  178322. }
  178323. }
  178324. #endif
  178325. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178326. #define PNG_HISHIFT 10
  178327. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178328. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178329. void /* PRIVATE */
  178330. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178331. {
  178332. png_bytep best_row;
  178333. #ifndef PNG_NO_WRITE_FILTER
  178334. png_bytep prev_row, row_buf;
  178335. png_uint_32 mins, bpp;
  178336. png_byte filter_to_do = png_ptr->do_filter;
  178337. png_uint_32 row_bytes = row_info->rowbytes;
  178338. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178339. int num_p_filters = (int)png_ptr->num_prev_filters;
  178340. #endif
  178341. png_debug(1, "in png_write_find_filter\n");
  178342. bpp = (row_info->pixel_depth + 7) >> 3;
  178343. prev_row = png_ptr->prev_row;
  178344. #endif
  178345. best_row = png_ptr->row_buf;
  178346. #ifndef PNG_NO_WRITE_FILTER
  178347. row_buf = best_row;
  178348. mins = PNG_MAXSUM;
  178349. if ((filter_to_do & PNG_FILTER_NONE) &&
  178350. filter_to_do != PNG_FILTER_NONE)
  178351. {
  178352. png_bytep rp;
  178353. png_uint_32 sum = 0;
  178354. png_uint_32 i;
  178355. int v;
  178356. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178357. {
  178358. v = *rp;
  178359. sum += (v < 128) ? v : 256 - v;
  178360. }
  178361. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178362. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178363. {
  178364. png_uint_32 sumhi, sumlo;
  178365. int j;
  178366. sumlo = sum & PNG_LOMASK;
  178367. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178368. for (j = 0; j < num_p_filters; j++)
  178369. {
  178370. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178371. {
  178372. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178373. PNG_WEIGHT_SHIFT;
  178374. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178375. PNG_WEIGHT_SHIFT;
  178376. }
  178377. }
  178378. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178379. PNG_COST_SHIFT;
  178380. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178381. PNG_COST_SHIFT;
  178382. if (sumhi > PNG_HIMASK)
  178383. sum = PNG_MAXSUM;
  178384. else
  178385. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178386. }
  178387. #endif
  178388. mins = sum;
  178389. }
  178390. if (filter_to_do == PNG_FILTER_SUB)
  178391. {
  178392. png_bytep rp, lp, dp;
  178393. png_uint_32 i;
  178394. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178395. i++, rp++, dp++)
  178396. {
  178397. *dp = *rp;
  178398. }
  178399. for (lp = row_buf + 1; i < row_bytes;
  178400. i++, rp++, lp++, dp++)
  178401. {
  178402. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178403. }
  178404. best_row = png_ptr->sub_row;
  178405. }
  178406. else if (filter_to_do & PNG_FILTER_SUB)
  178407. {
  178408. png_bytep rp, dp, lp;
  178409. png_uint_32 sum = 0, lmins = mins;
  178410. png_uint_32 i;
  178411. int v;
  178412. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178413. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178414. {
  178415. int j;
  178416. png_uint_32 lmhi, lmlo;
  178417. lmlo = lmins & PNG_LOMASK;
  178418. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178419. for (j = 0; j < num_p_filters; j++)
  178420. {
  178421. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178422. {
  178423. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178424. PNG_WEIGHT_SHIFT;
  178425. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178426. PNG_WEIGHT_SHIFT;
  178427. }
  178428. }
  178429. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178430. PNG_COST_SHIFT;
  178431. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178432. PNG_COST_SHIFT;
  178433. if (lmhi > PNG_HIMASK)
  178434. lmins = PNG_MAXSUM;
  178435. else
  178436. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178437. }
  178438. #endif
  178439. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178440. i++, rp++, dp++)
  178441. {
  178442. v = *dp = *rp;
  178443. sum += (v < 128) ? v : 256 - v;
  178444. }
  178445. for (lp = row_buf + 1; i < row_bytes;
  178446. i++, rp++, lp++, dp++)
  178447. {
  178448. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178449. sum += (v < 128) ? v : 256 - v;
  178450. if (sum > lmins) /* We are already worse, don't continue. */
  178451. break;
  178452. }
  178453. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178454. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178455. {
  178456. int j;
  178457. png_uint_32 sumhi, sumlo;
  178458. sumlo = sum & PNG_LOMASK;
  178459. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178460. for (j = 0; j < num_p_filters; j++)
  178461. {
  178462. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178463. {
  178464. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178465. PNG_WEIGHT_SHIFT;
  178466. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178467. PNG_WEIGHT_SHIFT;
  178468. }
  178469. }
  178470. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178471. PNG_COST_SHIFT;
  178472. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178473. PNG_COST_SHIFT;
  178474. if (sumhi > PNG_HIMASK)
  178475. sum = PNG_MAXSUM;
  178476. else
  178477. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178478. }
  178479. #endif
  178480. if (sum < mins)
  178481. {
  178482. mins = sum;
  178483. best_row = png_ptr->sub_row;
  178484. }
  178485. }
  178486. if (filter_to_do == PNG_FILTER_UP)
  178487. {
  178488. png_bytep rp, dp, pp;
  178489. png_uint_32 i;
  178490. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178491. pp = prev_row + 1; i < row_bytes;
  178492. i++, rp++, pp++, dp++)
  178493. {
  178494. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178495. }
  178496. best_row = png_ptr->up_row;
  178497. }
  178498. else if (filter_to_do & PNG_FILTER_UP)
  178499. {
  178500. png_bytep rp, dp, pp;
  178501. png_uint_32 sum = 0, lmins = mins;
  178502. png_uint_32 i;
  178503. int v;
  178504. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178505. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178506. {
  178507. int j;
  178508. png_uint_32 lmhi, lmlo;
  178509. lmlo = lmins & PNG_LOMASK;
  178510. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178511. for (j = 0; j < num_p_filters; j++)
  178512. {
  178513. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178514. {
  178515. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178516. PNG_WEIGHT_SHIFT;
  178517. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178518. PNG_WEIGHT_SHIFT;
  178519. }
  178520. }
  178521. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178522. PNG_COST_SHIFT;
  178523. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178524. PNG_COST_SHIFT;
  178525. if (lmhi > PNG_HIMASK)
  178526. lmins = PNG_MAXSUM;
  178527. else
  178528. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178529. }
  178530. #endif
  178531. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178532. pp = prev_row + 1; i < row_bytes; i++)
  178533. {
  178534. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178535. sum += (v < 128) ? v : 256 - v;
  178536. if (sum > lmins) /* We are already worse, don't continue. */
  178537. break;
  178538. }
  178539. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178540. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178541. {
  178542. int j;
  178543. png_uint_32 sumhi, sumlo;
  178544. sumlo = sum & PNG_LOMASK;
  178545. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178546. for (j = 0; j < num_p_filters; j++)
  178547. {
  178548. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178549. {
  178550. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178551. PNG_WEIGHT_SHIFT;
  178552. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178553. PNG_WEIGHT_SHIFT;
  178554. }
  178555. }
  178556. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178557. PNG_COST_SHIFT;
  178558. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178559. PNG_COST_SHIFT;
  178560. if (sumhi > PNG_HIMASK)
  178561. sum = PNG_MAXSUM;
  178562. else
  178563. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178564. }
  178565. #endif
  178566. if (sum < mins)
  178567. {
  178568. mins = sum;
  178569. best_row = png_ptr->up_row;
  178570. }
  178571. }
  178572. if (filter_to_do == PNG_FILTER_AVG)
  178573. {
  178574. png_bytep rp, dp, pp, lp;
  178575. png_uint_32 i;
  178576. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178577. pp = prev_row + 1; i < bpp; i++)
  178578. {
  178579. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178580. }
  178581. for (lp = row_buf + 1; i < row_bytes; i++)
  178582. {
  178583. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178584. & 0xff);
  178585. }
  178586. best_row = png_ptr->avg_row;
  178587. }
  178588. else if (filter_to_do & PNG_FILTER_AVG)
  178589. {
  178590. png_bytep rp, dp, pp, lp;
  178591. png_uint_32 sum = 0, lmins = mins;
  178592. png_uint_32 i;
  178593. int v;
  178594. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178595. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178596. {
  178597. int j;
  178598. png_uint_32 lmhi, lmlo;
  178599. lmlo = lmins & PNG_LOMASK;
  178600. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178601. for (j = 0; j < num_p_filters; j++)
  178602. {
  178603. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178604. {
  178605. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178606. PNG_WEIGHT_SHIFT;
  178607. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178608. PNG_WEIGHT_SHIFT;
  178609. }
  178610. }
  178611. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178612. PNG_COST_SHIFT;
  178613. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178614. PNG_COST_SHIFT;
  178615. if (lmhi > PNG_HIMASK)
  178616. lmins = PNG_MAXSUM;
  178617. else
  178618. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178619. }
  178620. #endif
  178621. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178622. pp = prev_row + 1; i < bpp; i++)
  178623. {
  178624. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178625. sum += (v < 128) ? v : 256 - v;
  178626. }
  178627. for (lp = row_buf + 1; i < row_bytes; i++)
  178628. {
  178629. v = *dp++ =
  178630. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178631. sum += (v < 128) ? v : 256 - v;
  178632. if (sum > lmins) /* We are already worse, don't continue. */
  178633. break;
  178634. }
  178635. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178636. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178637. {
  178638. int j;
  178639. png_uint_32 sumhi, sumlo;
  178640. sumlo = sum & PNG_LOMASK;
  178641. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178642. for (j = 0; j < num_p_filters; j++)
  178643. {
  178644. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178645. {
  178646. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178647. PNG_WEIGHT_SHIFT;
  178648. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178649. PNG_WEIGHT_SHIFT;
  178650. }
  178651. }
  178652. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178653. PNG_COST_SHIFT;
  178654. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178655. PNG_COST_SHIFT;
  178656. if (sumhi > PNG_HIMASK)
  178657. sum = PNG_MAXSUM;
  178658. else
  178659. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178660. }
  178661. #endif
  178662. if (sum < mins)
  178663. {
  178664. mins = sum;
  178665. best_row = png_ptr->avg_row;
  178666. }
  178667. }
  178668. if (filter_to_do == PNG_FILTER_PAETH)
  178669. {
  178670. png_bytep rp, dp, pp, cp, lp;
  178671. png_uint_32 i;
  178672. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178673. pp = prev_row + 1; i < bpp; i++)
  178674. {
  178675. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178676. }
  178677. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178678. {
  178679. int a, b, c, pa, pb, pc, p;
  178680. b = *pp++;
  178681. c = *cp++;
  178682. a = *lp++;
  178683. p = b - c;
  178684. pc = a - c;
  178685. #ifdef PNG_USE_ABS
  178686. pa = abs(p);
  178687. pb = abs(pc);
  178688. pc = abs(p + pc);
  178689. #else
  178690. pa = p < 0 ? -p : p;
  178691. pb = pc < 0 ? -pc : pc;
  178692. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178693. #endif
  178694. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178695. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178696. }
  178697. best_row = png_ptr->paeth_row;
  178698. }
  178699. else if (filter_to_do & PNG_FILTER_PAETH)
  178700. {
  178701. png_bytep rp, dp, pp, cp, lp;
  178702. png_uint_32 sum = 0, lmins = mins;
  178703. png_uint_32 i;
  178704. int v;
  178705. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178706. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178707. {
  178708. int j;
  178709. png_uint_32 lmhi, lmlo;
  178710. lmlo = lmins & PNG_LOMASK;
  178711. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178712. for (j = 0; j < num_p_filters; j++)
  178713. {
  178714. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178715. {
  178716. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178717. PNG_WEIGHT_SHIFT;
  178718. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178719. PNG_WEIGHT_SHIFT;
  178720. }
  178721. }
  178722. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178723. PNG_COST_SHIFT;
  178724. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178725. PNG_COST_SHIFT;
  178726. if (lmhi > PNG_HIMASK)
  178727. lmins = PNG_MAXSUM;
  178728. else
  178729. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178730. }
  178731. #endif
  178732. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178733. pp = prev_row + 1; i < bpp; i++)
  178734. {
  178735. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178736. sum += (v < 128) ? v : 256 - v;
  178737. }
  178738. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178739. {
  178740. int a, b, c, pa, pb, pc, p;
  178741. b = *pp++;
  178742. c = *cp++;
  178743. a = *lp++;
  178744. #ifndef PNG_SLOW_PAETH
  178745. p = b - c;
  178746. pc = a - c;
  178747. #ifdef PNG_USE_ABS
  178748. pa = abs(p);
  178749. pb = abs(pc);
  178750. pc = abs(p + pc);
  178751. #else
  178752. pa = p < 0 ? -p : p;
  178753. pb = pc < 0 ? -pc : pc;
  178754. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178755. #endif
  178756. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178757. #else /* PNG_SLOW_PAETH */
  178758. p = a + b - c;
  178759. pa = abs(p - a);
  178760. pb = abs(p - b);
  178761. pc = abs(p - c);
  178762. if (pa <= pb && pa <= pc)
  178763. p = a;
  178764. else if (pb <= pc)
  178765. p = b;
  178766. else
  178767. p = c;
  178768. #endif /* PNG_SLOW_PAETH */
  178769. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178770. sum += (v < 128) ? v : 256 - v;
  178771. if (sum > lmins) /* We are already worse, don't continue. */
  178772. break;
  178773. }
  178774. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178775. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178776. {
  178777. int j;
  178778. png_uint_32 sumhi, sumlo;
  178779. sumlo = sum & PNG_LOMASK;
  178780. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178781. for (j = 0; j < num_p_filters; j++)
  178782. {
  178783. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178784. {
  178785. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178786. PNG_WEIGHT_SHIFT;
  178787. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178788. PNG_WEIGHT_SHIFT;
  178789. }
  178790. }
  178791. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178792. PNG_COST_SHIFT;
  178793. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178794. PNG_COST_SHIFT;
  178795. if (sumhi > PNG_HIMASK)
  178796. sum = PNG_MAXSUM;
  178797. else
  178798. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178799. }
  178800. #endif
  178801. if (sum < mins)
  178802. {
  178803. best_row = png_ptr->paeth_row;
  178804. }
  178805. }
  178806. #endif /* PNG_NO_WRITE_FILTER */
  178807. png_write_filtered_row(png_ptr, best_row);
  178808. #ifndef PNG_NO_WRITE_FILTER
  178809. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178810. if (png_ptr->num_prev_filters > 0)
  178811. {
  178812. int j;
  178813. for (j = 1; j < num_p_filters; j++)
  178814. {
  178815. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178816. }
  178817. png_ptr->prev_filters[j] = best_row[0];
  178818. }
  178819. #endif
  178820. #endif /* PNG_NO_WRITE_FILTER */
  178821. }
  178822. void /* PRIVATE */
  178823. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178824. {
  178825. png_debug(1, "in png_write_filtered_row\n");
  178826. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178827. png_ptr->zstream.next_in = filtered_row;
  178828. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178829. do
  178830. {
  178831. int ret; /* return of zlib */
  178832. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178833. if (ret != Z_OK)
  178834. {
  178835. if (png_ptr->zstream.msg != NULL)
  178836. png_error(png_ptr, png_ptr->zstream.msg);
  178837. else
  178838. png_error(png_ptr, "zlib error");
  178839. }
  178840. if (!(png_ptr->zstream.avail_out))
  178841. {
  178842. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178843. png_ptr->zstream.next_out = png_ptr->zbuf;
  178844. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178845. }
  178846. } while (png_ptr->zstream.avail_in);
  178847. if (png_ptr->prev_row != NULL)
  178848. {
  178849. png_bytep tptr;
  178850. tptr = png_ptr->prev_row;
  178851. png_ptr->prev_row = png_ptr->row_buf;
  178852. png_ptr->row_buf = tptr;
  178853. }
  178854. png_write_finish_row(png_ptr);
  178855. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178856. png_ptr->flush_rows++;
  178857. if (png_ptr->flush_dist > 0 &&
  178858. png_ptr->flush_rows >= png_ptr->flush_dist)
  178859. {
  178860. png_write_flush(png_ptr);
  178861. }
  178862. #endif
  178863. }
  178864. #endif /* PNG_WRITE_SUPPORTED */
  178865. /*** End of inlined file: pngwutil.c ***/
  178866. }
  178867. #else
  178868. #define PNG_INTERNAL
  178869. #define PNG_SETJMP_NOT_SUPPORTED
  178870. #include <png.h>
  178871. #include <pngconf.h>
  178872. #endif
  178873. }
  178874. #undef max
  178875. #undef min
  178876. #ifdef _MSC_VER
  178877. #pragma warning (pop)
  178878. #endif
  178879. BEGIN_JUCE_NAMESPACE
  178880. using ::calloc;
  178881. using ::malloc;
  178882. using ::free;
  178883. namespace PNGHelpers
  178884. {
  178885. using namespace pnglibNamespace;
  178886. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178887. {
  178888. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  178889. }
  178890. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178891. {
  178892. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, (int) length);
  178893. }
  178894. struct PNGErrorStruct {};
  178895. static void errorCallback (png_structp, png_const_charp)
  178896. {
  178897. throw PNGErrorStruct();
  178898. }
  178899. }
  178900. Image* juce_loadPNGImageFromStream (InputStream& in)
  178901. {
  178902. using namespace pnglibNamespace;
  178903. Image* image = 0;
  178904. png_structp pngReadStruct;
  178905. png_infop pngInfoStruct;
  178906. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178907. if (pngReadStruct != 0)
  178908. {
  178909. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178910. if (pngInfoStruct == 0)
  178911. {
  178912. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178913. return 0;
  178914. }
  178915. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178916. // read the header..
  178917. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  178918. png_uint_32 width, height;
  178919. int bitDepth, colorType, interlaceType;
  178920. png_read_info (pngReadStruct, pngInfoStruct);
  178921. png_get_IHDR (pngReadStruct, pngInfoStruct,
  178922. &width, &height,
  178923. &bitDepth, &colorType,
  178924. &interlaceType, 0, 0);
  178925. if (bitDepth == 16)
  178926. png_set_strip_16 (pngReadStruct);
  178927. if (colorType == PNG_COLOR_TYPE_PALETTE)
  178928. png_set_expand (pngReadStruct);
  178929. if (bitDepth < 8)
  178930. png_set_expand (pngReadStruct);
  178931. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  178932. png_set_expand (pngReadStruct);
  178933. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  178934. png_set_gray_to_rgb (pngReadStruct);
  178935. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  178936. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  178937. || pngInfoStruct->num_trans > 0;
  178938. // Load the image into a temp buffer in the pnglib format..
  178939. HeapBlock <uint8> tempBuffer (height * (width << 2));
  178940. {
  178941. HeapBlock <png_bytep> rows (height);
  178942. for (int y = (int) height; --y >= 0;)
  178943. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  178944. png_read_image (pngReadStruct, rows);
  178945. png_read_end (pngReadStruct, pngInfoStruct);
  178946. }
  178947. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  178948. // now convert the data to a juce image format..
  178949. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  178950. (int) width, (int) height, hasAlphaChan);
  178951. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  178952. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  178953. uint8* srcRow = tempBuffer;
  178954. uint8* destRow = destData.data;
  178955. for (int y = 0; y < (int) height; ++y)
  178956. {
  178957. const uint8* src = srcRow;
  178958. srcRow += (width << 2);
  178959. uint8* dest = destRow;
  178960. destRow += destData.lineStride;
  178961. if (hasAlphaChan)
  178962. {
  178963. for (int i = (int) width; --i >= 0;)
  178964. {
  178965. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  178966. ((PixelARGB*) dest)->premultiply();
  178967. dest += destData.pixelStride;
  178968. src += 4;
  178969. }
  178970. }
  178971. else
  178972. {
  178973. for (int i = (int) width; --i >= 0;)
  178974. {
  178975. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  178976. dest += destData.pixelStride;
  178977. src += 4;
  178978. }
  178979. }
  178980. }
  178981. }
  178982. return image;
  178983. }
  178984. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  178985. {
  178986. using namespace pnglibNamespace;
  178987. const int width = image.getWidth();
  178988. const int height = image.getHeight();
  178989. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178990. if (pngWriteStruct == 0)
  178991. return false;
  178992. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  178993. if (pngInfoStruct == 0)
  178994. {
  178995. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  178996. return false;
  178997. }
  178998. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  178999. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179000. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179001. : PNG_COLOR_TYPE_RGB,
  179002. PNG_INTERLACE_NONE,
  179003. PNG_COMPRESSION_TYPE_BASE,
  179004. PNG_FILTER_TYPE_BASE);
  179005. HeapBlock <uint8> rowData (width * 4);
  179006. png_color_8 sig_bit;
  179007. sig_bit.red = 8;
  179008. sig_bit.green = 8;
  179009. sig_bit.blue = 8;
  179010. sig_bit.alpha = 8;
  179011. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179012. png_write_info (pngWriteStruct, pngInfoStruct);
  179013. png_set_shift (pngWriteStruct, &sig_bit);
  179014. png_set_packing (pngWriteStruct);
  179015. const Image::BitmapData srcData (image, 0, 0, width, height);
  179016. for (int y = 0; y < height; ++y)
  179017. {
  179018. uint8* dst = rowData;
  179019. const uint8* src = srcData.getLinePointer (y);
  179020. if (image.hasAlphaChannel())
  179021. {
  179022. for (int i = width; --i >= 0;)
  179023. {
  179024. PixelARGB p (*(const PixelARGB*) src);
  179025. p.unpremultiply();
  179026. *dst++ = p.getRed();
  179027. *dst++ = p.getGreen();
  179028. *dst++ = p.getBlue();
  179029. *dst++ = p.getAlpha();
  179030. src += srcData.pixelStride;
  179031. }
  179032. }
  179033. else
  179034. {
  179035. for (int i = width; --i >= 0;)
  179036. {
  179037. *dst++ = ((const PixelRGB*) src)->getRed();
  179038. *dst++ = ((const PixelRGB*) src)->getGreen();
  179039. *dst++ = ((const PixelRGB*) src)->getBlue();
  179040. src += srcData.pixelStride;
  179041. }
  179042. }
  179043. png_write_rows (pngWriteStruct, &rowData, 1);
  179044. }
  179045. png_write_end (pngWriteStruct, pngInfoStruct);
  179046. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179047. out.flush();
  179048. return true;
  179049. }
  179050. END_JUCE_NAMESPACE
  179051. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179052. #endif
  179053. //==============================================================================
  179054. #if JUCE_BUILD_NATIVE
  179055. #if JUCE_WINDOWS
  179056. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179057. #if JUCE_WINDOWS
  179058. BEGIN_JUCE_NAMESPACE
  179059. #define JUCE_INCLUDED_FILE 1
  179060. // Now include the actual code files..
  179061. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179062. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179063. // compiled on its own).
  179064. #if JUCE_INCLUDED_FILE
  179065. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179066. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179067. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179068. #ifndef DOXYGEN
  179069. // use with DynamicLibraryLoader to simplify importing functions
  179070. //
  179071. // functionName: function to import
  179072. // localFunctionName: name you want to use to actually call it (must be different)
  179073. // returnType: the return type
  179074. // object: the DynamicLibraryLoader to use
  179075. // params: list of params (bracketed)
  179076. //
  179077. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179078. typedef returnType (WINAPI *type##localFunctionName) params; \
  179079. type##localFunctionName localFunctionName \
  179080. = (type##localFunctionName)object.findProcAddress (#functionName);
  179081. // loads and unloads a DLL automatically
  179082. class JUCE_API DynamicLibraryLoader
  179083. {
  179084. public:
  179085. DynamicLibraryLoader (const String& name);
  179086. ~DynamicLibraryLoader();
  179087. void* findProcAddress (const String& functionName);
  179088. private:
  179089. void* libHandle;
  179090. };
  179091. #endif
  179092. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179093. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179094. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179095. {
  179096. libHandle = LoadLibrary (name);
  179097. }
  179098. DynamicLibraryLoader::~DynamicLibraryLoader()
  179099. {
  179100. FreeLibrary ((HMODULE) libHandle);
  179101. }
  179102. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179103. {
  179104. return GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179105. }
  179106. #endif
  179107. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179108. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179109. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179110. // compiled on its own).
  179111. #if JUCE_INCLUDED_FILE
  179112. extern void juce_initialiseThreadEvents();
  179113. void Logger::outputDebugString (const String& text) throw()
  179114. {
  179115. OutputDebugString (text + "\n");
  179116. }
  179117. static int64 hiResTicksPerSecond;
  179118. static double hiResTicksScaleFactor;
  179119. #if JUCE_USE_INTRINSICS
  179120. // CPU info functions using intrinsics...
  179121. #pragma intrinsic (__cpuid)
  179122. #pragma intrinsic (__rdtsc)
  179123. const String SystemStats::getCpuVendor() throw()
  179124. {
  179125. int info [4];
  179126. __cpuid (info, 0);
  179127. char v [12];
  179128. memcpy (v, info + 1, 4);
  179129. memcpy (v + 4, info + 3, 4);
  179130. memcpy (v + 8, info + 2, 4);
  179131. return String (v, 12);
  179132. }
  179133. #else
  179134. // CPU info functions using old fashioned inline asm...
  179135. static void juce_getCpuVendor (char* const v)
  179136. {
  179137. int vendor[4];
  179138. zeromem (vendor, 16);
  179139. #ifdef JUCE_64BIT
  179140. #else
  179141. #ifndef __MINGW32__
  179142. __try
  179143. #endif
  179144. {
  179145. #if JUCE_GCC
  179146. unsigned int dummy = 0;
  179147. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179148. #else
  179149. __asm
  179150. {
  179151. mov eax, 0
  179152. cpuid
  179153. mov [vendor], ebx
  179154. mov [vendor + 4], edx
  179155. mov [vendor + 8], ecx
  179156. }
  179157. #endif
  179158. }
  179159. #ifndef __MINGW32__
  179160. __except (EXCEPTION_EXECUTE_HANDLER)
  179161. {
  179162. *v = 0;
  179163. }
  179164. #endif
  179165. #endif
  179166. memcpy (v, vendor, 16);
  179167. }
  179168. const String SystemStats::getCpuVendor() throw()
  179169. {
  179170. char v [16];
  179171. juce_getCpuVendor (v);
  179172. return String (v, 16);
  179173. }
  179174. #endif
  179175. struct CPUFlags
  179176. {
  179177. bool hasMMX : 1;
  179178. bool hasSSE : 1;
  179179. bool hasSSE2 : 1;
  179180. bool has3DNow : 1;
  179181. };
  179182. static CPUFlags cpuFlags;
  179183. bool SystemStats::hasMMX() throw()
  179184. {
  179185. return cpuFlags.hasMMX;
  179186. }
  179187. bool SystemStats::hasSSE() throw()
  179188. {
  179189. return cpuFlags.hasSSE;
  179190. }
  179191. bool SystemStats::hasSSE2() throw()
  179192. {
  179193. return cpuFlags.hasSSE2;
  179194. }
  179195. bool SystemStats::has3DNow() throw()
  179196. {
  179197. return cpuFlags.has3DNow;
  179198. }
  179199. void SystemStats::initialiseStats() throw()
  179200. {
  179201. juce_initialiseThreadEvents();
  179202. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179203. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179204. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179205. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179206. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179207. #else
  179208. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179209. #endif
  179210. LARGE_INTEGER f;
  179211. QueryPerformanceFrequency (&f);
  179212. hiResTicksPerSecond = f.QuadPart;
  179213. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179214. String s (SystemStats::getJUCEVersion());
  179215. #ifdef JUCE_DEBUG
  179216. const MMRESULT res = timeBeginPeriod (1);
  179217. jassert (res == TIMERR_NOERROR);
  179218. #else
  179219. timeBeginPeriod (1);
  179220. #endif
  179221. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179222. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179223. #endif
  179224. }
  179225. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179226. {
  179227. OSVERSIONINFO info;
  179228. info.dwOSVersionInfoSize = sizeof (info);
  179229. GetVersionEx (&info);
  179230. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179231. {
  179232. switch (info.dwMajorVersion)
  179233. {
  179234. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179235. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179236. default: jassertfalse; break; // !! not a supported OS!
  179237. }
  179238. }
  179239. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179240. {
  179241. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179242. return Win98;
  179243. }
  179244. return UnknownOS;
  179245. }
  179246. const String SystemStats::getOperatingSystemName() throw()
  179247. {
  179248. const char* name = "Unknown OS";
  179249. switch (getOperatingSystemType())
  179250. {
  179251. case Windows7: name = "Windows 7"; break;
  179252. case WinVista: name = "Windows Vista"; break;
  179253. case WinXP: name = "Windows XP"; break;
  179254. case Win2000: name = "Windows 2000"; break;
  179255. case Win98: name = "Windows 98"; break;
  179256. default: jassertfalse; break; // !! new type of OS?
  179257. }
  179258. return name;
  179259. }
  179260. bool SystemStats::isOperatingSystem64Bit() throw()
  179261. {
  179262. #ifdef _WIN64
  179263. return true;
  179264. #else
  179265. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179266. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179267. BOOL isWow64 = FALSE;
  179268. return (fnIsWow64Process != 0)
  179269. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179270. && (isWow64 != FALSE);
  179271. #endif
  179272. }
  179273. int SystemStats::getMemorySizeInMegabytes() throw()
  179274. {
  179275. MEMORYSTATUSEX mem;
  179276. mem.dwLength = sizeof (mem);
  179277. GlobalMemoryStatusEx (&mem);
  179278. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179279. }
  179280. int SystemStats::getNumCpus() throw()
  179281. {
  179282. SYSTEM_INFO systemInfo;
  179283. GetSystemInfo (&systemInfo);
  179284. return systemInfo.dwNumberOfProcessors;
  179285. }
  179286. uint32 juce_millisecondsSinceStartup() throw()
  179287. {
  179288. return (uint32) GetTickCount();
  179289. }
  179290. int64 Time::getHighResolutionTicks() throw()
  179291. {
  179292. LARGE_INTEGER ticks;
  179293. QueryPerformanceCounter (&ticks);
  179294. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179295. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179296. // fix for a very obscure PCI hardware bug that can make the counter
  179297. // sometimes jump forwards by a few seconds..
  179298. static int64 hiResTicksOffset = 0;
  179299. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179300. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179301. hiResTicksOffset = newOffset;
  179302. return ticks.QuadPart + hiResTicksOffset;
  179303. }
  179304. double Time::getMillisecondCounterHiRes() throw()
  179305. {
  179306. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179307. }
  179308. int64 Time::getHighResolutionTicksPerSecond() throw()
  179309. {
  179310. return hiResTicksPerSecond;
  179311. }
  179312. int64 SystemStats::getClockCycleCounter() throw()
  179313. {
  179314. #if JUCE_USE_INTRINSICS
  179315. // MS intrinsics version...
  179316. return __rdtsc();
  179317. #elif JUCE_GCC
  179318. // GNU inline asm version...
  179319. unsigned int hi = 0, lo = 0;
  179320. __asm__ __volatile__ (
  179321. "xor %%eax, %%eax \n\
  179322. xor %%edx, %%edx \n\
  179323. rdtsc \n\
  179324. movl %%eax, %[lo] \n\
  179325. movl %%edx, %[hi]"
  179326. :
  179327. : [hi] "m" (hi),
  179328. [lo] "m" (lo)
  179329. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179330. return (int64) ((((uint64) hi) << 32) | lo);
  179331. #else
  179332. // MSVC inline asm version...
  179333. unsigned int hi = 0, lo = 0;
  179334. __asm
  179335. {
  179336. xor eax, eax
  179337. xor edx, edx
  179338. rdtsc
  179339. mov lo, eax
  179340. mov hi, edx
  179341. }
  179342. return (int64) ((((uint64) hi) << 32) | lo);
  179343. #endif
  179344. }
  179345. int SystemStats::getCpuSpeedInMegaherz() throw()
  179346. {
  179347. const int64 cycles = SystemStats::getClockCycleCounter();
  179348. const uint32 millis = Time::getMillisecondCounter();
  179349. int lastResult = 0;
  179350. for (;;)
  179351. {
  179352. int n = 1000000;
  179353. while (--n > 0) {}
  179354. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179355. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179356. if (millisElapsed > 80)
  179357. {
  179358. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179359. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179360. return newResult;
  179361. lastResult = newResult;
  179362. }
  179363. }
  179364. }
  179365. bool Time::setSystemTimeToThisTime() const throw()
  179366. {
  179367. SYSTEMTIME st;
  179368. st.wDayOfWeek = 0;
  179369. st.wYear = (WORD) getYear();
  179370. st.wMonth = (WORD) (getMonth() + 1);
  179371. st.wDay = (WORD) getDayOfMonth();
  179372. st.wHour = (WORD) getHours();
  179373. st.wMinute = (WORD) getMinutes();
  179374. st.wSecond = (WORD) getSeconds();
  179375. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179376. // do this twice because of daylight saving conversion problems - the
  179377. // first one sets it up, the second one kicks it in.
  179378. return SetLocalTime (&st) != 0
  179379. && SetLocalTime (&st) != 0;
  179380. }
  179381. int SystemStats::getPageSize() throw()
  179382. {
  179383. SYSTEM_INFO systemInfo;
  179384. GetSystemInfo (&systemInfo);
  179385. return systemInfo.dwPageSize;
  179386. }
  179387. const String SystemStats::getLogonName()
  179388. {
  179389. TCHAR text [256];
  179390. DWORD len = numElementsInArray (text) - 2;
  179391. zerostruct (text);
  179392. GetUserName (text, &len);
  179393. return String (text, len);
  179394. }
  179395. const String SystemStats::getFullUserName()
  179396. {
  179397. return getLogonName();
  179398. }
  179399. #endif
  179400. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179401. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179402. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179403. // compiled on its own).
  179404. #if JUCE_INCLUDED_FILE
  179405. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179406. extern HWND juce_messageWindowHandle;
  179407. #endif
  179408. #if ! JUCE_USE_INTRINSICS
  179409. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179410. // older ones we have to actually call the ops as win32 functions..
  179411. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179412. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179413. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179414. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179415. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179416. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179417. #endif
  179418. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179419. CriticalSection::CriticalSection() throw()
  179420. {
  179421. // (just to check the MS haven't changed this structure and broken things...)
  179422. #if _MSC_VER >= 1400
  179423. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179424. #else
  179425. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179426. #endif
  179427. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179428. }
  179429. CriticalSection::~CriticalSection() throw()
  179430. {
  179431. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179432. }
  179433. void CriticalSection::enter() const throw()
  179434. {
  179435. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179436. }
  179437. bool CriticalSection::tryEnter() const throw()
  179438. {
  179439. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179440. }
  179441. void CriticalSection::exit() const throw()
  179442. {
  179443. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179444. }
  179445. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  179446. : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0))
  179447. {
  179448. }
  179449. WaitableEvent::~WaitableEvent() throw()
  179450. {
  179451. CloseHandle (internal);
  179452. }
  179453. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179454. {
  179455. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179456. }
  179457. void WaitableEvent::signal() const throw()
  179458. {
  179459. SetEvent (internal);
  179460. }
  179461. void WaitableEvent::reset() const throw()
  179462. {
  179463. ResetEvent (internal);
  179464. }
  179465. void JUCE_API juce_threadEntryPoint (void*);
  179466. static unsigned int __stdcall threadEntryProc (void* userData)
  179467. {
  179468. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179469. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179470. GetCurrentThreadId(), TRUE);
  179471. #endif
  179472. juce_threadEntryPoint (userData);
  179473. _endthreadex (0);
  179474. return 0;
  179475. }
  179476. void juce_CloseThreadHandle (void* handle)
  179477. {
  179478. CloseHandle ((HANDLE) handle);
  179479. }
  179480. void* juce_createThread (void* userData)
  179481. {
  179482. unsigned int threadId;
  179483. return (void*) _beginthreadex (0, 0,
  179484. &threadEntryProc,
  179485. userData,
  179486. 0, &threadId);
  179487. }
  179488. void juce_killThread (void* handle)
  179489. {
  179490. if (handle != 0)
  179491. {
  179492. #ifdef JUCE_DEBUG
  179493. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179494. #endif
  179495. TerminateThread (handle, 0);
  179496. }
  179497. }
  179498. void juce_setCurrentThreadName (const String& name)
  179499. {
  179500. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179501. struct
  179502. {
  179503. DWORD dwType;
  179504. LPCSTR szName;
  179505. DWORD dwThreadID;
  179506. DWORD dwFlags;
  179507. } info;
  179508. info.dwType = 0x1000;
  179509. info.szName = name.toCString();
  179510. info.dwThreadID = GetCurrentThreadId();
  179511. info.dwFlags = 0;
  179512. __try
  179513. {
  179514. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179515. }
  179516. __except (EXCEPTION_CONTINUE_EXECUTION)
  179517. {}
  179518. #else
  179519. (void) name;
  179520. #endif
  179521. }
  179522. Thread::ThreadID Thread::getCurrentThreadId()
  179523. {
  179524. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179525. }
  179526. // priority 1 to 10 where 5=normal, 1=low
  179527. bool juce_setThreadPriority (void* threadHandle, int priority)
  179528. {
  179529. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179530. if (priority < 1)
  179531. pri = THREAD_PRIORITY_IDLE;
  179532. else if (priority < 2)
  179533. pri = THREAD_PRIORITY_LOWEST;
  179534. else if (priority < 5)
  179535. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179536. else if (priority < 7)
  179537. pri = THREAD_PRIORITY_NORMAL;
  179538. else if (priority < 9)
  179539. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179540. else if (priority < 10)
  179541. pri = THREAD_PRIORITY_HIGHEST;
  179542. if (threadHandle == 0)
  179543. threadHandle = GetCurrentThread();
  179544. return SetThreadPriority (threadHandle, pri) != FALSE;
  179545. }
  179546. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179547. {
  179548. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179549. }
  179550. static HANDLE sleepEvent = 0;
  179551. void juce_initialiseThreadEvents()
  179552. {
  179553. if (sleepEvent == 0)
  179554. #ifdef JUCE_DEBUG
  179555. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179556. #else
  179557. sleepEvent = CreateEvent (0, 0, 0, 0);
  179558. #endif
  179559. }
  179560. void Thread::yield()
  179561. {
  179562. Sleep (0);
  179563. }
  179564. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179565. {
  179566. if (millisecs >= 10)
  179567. {
  179568. Sleep (millisecs);
  179569. }
  179570. else
  179571. {
  179572. jassert (sleepEvent != 0);
  179573. // unlike Sleep() this is guaranteed to return to the current thread after
  179574. // the time expires, so we'll use this for short waits, which are more likely
  179575. // to need to be accurate
  179576. WaitForSingleObject (sleepEvent, millisecs);
  179577. }
  179578. }
  179579. static int lastProcessPriority = -1;
  179580. // called by WindowDriver because Windows does wierd things to process priority
  179581. // when you swap apps, and this forces an update when the app is brought to the front.
  179582. void juce_repeatLastProcessPriority()
  179583. {
  179584. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179585. {
  179586. DWORD p;
  179587. switch (lastProcessPriority)
  179588. {
  179589. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179590. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179591. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179592. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179593. default: jassertfalse; return; // bad priority value
  179594. }
  179595. SetPriorityClass (GetCurrentProcess(), p);
  179596. }
  179597. }
  179598. void Process::setPriority (ProcessPriority prior)
  179599. {
  179600. if (lastProcessPriority != (int) prior)
  179601. {
  179602. lastProcessPriority = (int) prior;
  179603. juce_repeatLastProcessPriority();
  179604. }
  179605. }
  179606. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179607. {
  179608. return IsDebuggerPresent() != FALSE;
  179609. }
  179610. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179611. {
  179612. return juce_isRunningUnderDebugger();
  179613. }
  179614. void Process::raisePrivilege()
  179615. {
  179616. jassertfalse // xxx not implemented
  179617. }
  179618. void Process::lowerPrivilege()
  179619. {
  179620. jassertfalse // xxx not implemented
  179621. }
  179622. void Process::terminate()
  179623. {
  179624. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179625. _CrtDumpMemoryLeaks();
  179626. #endif
  179627. // bullet in the head in case there's a problem shutting down..
  179628. ExitProcess (0);
  179629. }
  179630. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179631. {
  179632. void* result = 0;
  179633. JUCE_TRY
  179634. {
  179635. result = LoadLibrary (name);
  179636. }
  179637. JUCE_CATCH_ALL
  179638. return result;
  179639. }
  179640. void PlatformUtilities::freeDynamicLibrary (void* h)
  179641. {
  179642. JUCE_TRY
  179643. {
  179644. if (h != 0)
  179645. FreeLibrary ((HMODULE) h);
  179646. }
  179647. JUCE_CATCH_ALL
  179648. }
  179649. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179650. {
  179651. return (h != 0) ? GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179652. }
  179653. class InterProcessLock::Pimpl
  179654. {
  179655. public:
  179656. Pimpl (const String& name, const int timeOutMillisecs)
  179657. : handle (0), refCount (1)
  179658. {
  179659. handle = CreateMutex (0, TRUE, "Global\\" + name.replaceCharacter ('\\','/'));
  179660. if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179661. {
  179662. if (timeOutMillisecs == 0)
  179663. {
  179664. close();
  179665. return;
  179666. }
  179667. switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs))
  179668. {
  179669. case WAIT_OBJECT_0:
  179670. case WAIT_ABANDONED:
  179671. break;
  179672. case WAIT_TIMEOUT:
  179673. default:
  179674. close();
  179675. break;
  179676. }
  179677. }
  179678. }
  179679. ~Pimpl()
  179680. {
  179681. close();
  179682. }
  179683. void close()
  179684. {
  179685. if (handle != 0)
  179686. {
  179687. ReleaseMutex (handle);
  179688. CloseHandle (handle);
  179689. handle = 0;
  179690. }
  179691. }
  179692. HANDLE handle;
  179693. int refCount;
  179694. };
  179695. InterProcessLock::InterProcessLock (const String& name_)
  179696. : name (name_)
  179697. {
  179698. }
  179699. InterProcessLock::~InterProcessLock()
  179700. {
  179701. }
  179702. bool InterProcessLock::enter (const int timeOutMillisecs)
  179703. {
  179704. const ScopedLock sl (lock);
  179705. if (pimpl == 0)
  179706. {
  179707. pimpl = new Pimpl (name, timeOutMillisecs);
  179708. if (pimpl->handle == 0)
  179709. pimpl = 0;
  179710. }
  179711. else
  179712. {
  179713. pimpl->refCount++;
  179714. }
  179715. return pimpl != 0;
  179716. }
  179717. void InterProcessLock::exit()
  179718. {
  179719. const ScopedLock sl (lock);
  179720. // Trying to release the lock too many times!
  179721. jassert (pimpl != 0);
  179722. if (pimpl != 0 && --(pimpl->refCount) == 0)
  179723. pimpl = 0;
  179724. }
  179725. #endif
  179726. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179727. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179728. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179729. // compiled on its own).
  179730. #if JUCE_INCLUDED_FILE
  179731. #ifndef CSIDL_MYMUSIC
  179732. #define CSIDL_MYMUSIC 0x000d
  179733. #endif
  179734. #ifndef CSIDL_MYVIDEO
  179735. #define CSIDL_MYVIDEO 0x000e
  179736. #endif
  179737. #ifndef INVALID_FILE_ATTRIBUTES
  179738. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179739. #endif
  179740. const juce_wchar File::separator = '\\';
  179741. const juce_wchar* File::separatorString = T("\\");
  179742. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179743. {
  179744. if (fileName.isEmpty())
  179745. return false;
  179746. const DWORD attr = GetFileAttributes (fileName);
  179747. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179748. : (attr != INVALID_FILE_ATTRIBUTES);
  179749. }
  179750. bool juce_isDirectory (const String& fileName)
  179751. {
  179752. const DWORD attr = GetFileAttributes (fileName);
  179753. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179754. }
  179755. bool juce_canWriteToFile (const String& fileName)
  179756. {
  179757. const DWORD attr = GetFileAttributes (fileName);
  179758. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179759. }
  179760. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179761. {
  179762. DWORD attr = GetFileAttributes (fileName);
  179763. if (attr == INVALID_FILE_ATTRIBUTES)
  179764. return false;
  179765. if (isReadOnly != juce_canWriteToFile (fileName))
  179766. return true;
  179767. if (isReadOnly)
  179768. attr |= FILE_ATTRIBUTE_READONLY;
  179769. else
  179770. attr &= ~FILE_ATTRIBUTE_READONLY;
  179771. return SetFileAttributes (fileName, attr) != FALSE;
  179772. }
  179773. bool File::isHidden() const
  179774. {
  179775. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179776. }
  179777. bool juce_deleteFile (const String& fileName)
  179778. {
  179779. if (juce_isDirectory (fileName))
  179780. return RemoveDirectory (fileName) != 0;
  179781. return DeleteFile (fileName) != 0;
  179782. }
  179783. bool File::moveToTrash() const
  179784. {
  179785. if (! exists())
  179786. return true;
  179787. SHFILEOPSTRUCT fos;
  179788. zerostruct (fos);
  179789. // The string we pass in must be double null terminated..
  179790. String doubleNullTermPath (getFullPathName() + " ");
  179791. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179792. p [getFullPathName().length()] = 0;
  179793. fos.wFunc = FO_DELETE;
  179794. fos.pFrom = p;
  179795. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179796. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179797. return SHFileOperation (&fos) == 0;
  179798. }
  179799. bool juce_moveFile (const String& source, const String& dest)
  179800. {
  179801. return MoveFile (source, dest) != 0;
  179802. }
  179803. bool juce_copyFile (const String& source, const String& dest)
  179804. {
  179805. return CopyFile (source, dest, false) != 0;
  179806. }
  179807. void juce_createDirectory (const String& fileName)
  179808. {
  179809. if (! juce_fileExists (fileName, true))
  179810. CreateDirectory (fileName, 0);
  179811. }
  179812. // return 0 if not possible
  179813. void* juce_fileOpen (const String& fileName, bool forWriting)
  179814. {
  179815. HANDLE h;
  179816. if (forWriting)
  179817. {
  179818. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179819. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179820. if (h != INVALID_HANDLE_VALUE)
  179821. SetFilePointer (h, 0, 0, FILE_END);
  179822. else
  179823. h = 0;
  179824. }
  179825. else
  179826. {
  179827. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179828. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179829. if (h == INVALID_HANDLE_VALUE)
  179830. h = 0;
  179831. }
  179832. return h;
  179833. }
  179834. void juce_fileClose (void* handle)
  179835. {
  179836. CloseHandle (handle);
  179837. }
  179838. int juce_fileRead (void* handle, void* buffer, int size)
  179839. {
  179840. DWORD num = 0;
  179841. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179842. return (int) num;
  179843. }
  179844. int juce_fileWrite (void* handle, const void* buffer, int size)
  179845. {
  179846. DWORD num;
  179847. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179848. return (int) num;
  179849. }
  179850. int64 juce_fileSetPosition (void* handle, int64 pos)
  179851. {
  179852. LARGE_INTEGER li;
  179853. li.QuadPart = pos;
  179854. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179855. return li.QuadPart;
  179856. }
  179857. int64 juce_fileGetPosition (void* handle)
  179858. {
  179859. LARGE_INTEGER li;
  179860. li.QuadPart = 0;
  179861. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179862. return jmax ((int64) 0, li.QuadPart);
  179863. }
  179864. void juce_fileFlush (void* handle)
  179865. {
  179866. FlushFileBuffers ((HANDLE) handle);
  179867. }
  179868. int64 juce_getFileSize (const String& fileName)
  179869. {
  179870. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179871. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179872. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179873. return 0;
  179874. }
  179875. static int64 fileTimeToTime (const FILETIME* const ft)
  179876. {
  179877. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179878. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179879. }
  179880. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179881. {
  179882. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179883. }
  179884. void juce_getFileTimes (const String& fileName,
  179885. int64& modificationTime,
  179886. int64& accessTime,
  179887. int64& creationTime)
  179888. {
  179889. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179890. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179891. {
  179892. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179893. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179894. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179895. }
  179896. else
  179897. {
  179898. creationTime = accessTime = modificationTime = 0;
  179899. }
  179900. }
  179901. bool juce_setFileTimes (const String& fileName,
  179902. int64 modificationTime,
  179903. int64 accessTime,
  179904. int64 creationTime)
  179905. {
  179906. void* const h = juce_fileOpen (fileName, true);
  179907. bool ok = false;
  179908. if (h != 0)
  179909. {
  179910. FILETIME m, a, c;
  179911. timeToFileTime (modificationTime, &m);
  179912. timeToFileTime (accessTime, &a);
  179913. timeToFileTime (creationTime, &c);
  179914. ok = SetFileTime ((HANDLE) h,
  179915. creationTime > 0 ? &c : 0,
  179916. accessTime > 0 ? &a : 0,
  179917. modificationTime > 0 ? &m : 0) != 0;
  179918. juce_fileClose (h);
  179919. }
  179920. return ok;
  179921. }
  179922. // return '\0' separated list of strings
  179923. const StringArray juce_getFileSystemRoots()
  179924. {
  179925. TCHAR buffer [2048];
  179926. buffer[0] = 0;
  179927. buffer[1] = 0;
  179928. GetLogicalDriveStrings (2048, buffer);
  179929. const TCHAR* n = buffer;
  179930. StringArray roots;
  179931. while (*n != 0)
  179932. {
  179933. roots.add (String (n));
  179934. while (*n++ != 0)
  179935. {}
  179936. }
  179937. roots.sort (true);
  179938. return roots;
  179939. }
  179940. static const String getDriveFromPath (const String& path)
  179941. {
  179942. if (path.isNotEmpty() && path[1] == ':')
  179943. return path.substring (0, 2) + '\\';
  179944. return path;
  179945. }
  179946. const String juce_getVolumeLabel (const String& filenameOnVolume,
  179947. int& volumeSerialNumber)
  179948. {
  179949. TCHAR dest[64];
  179950. DWORD serialNum;
  179951. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  179952. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  179953. {
  179954. dest[0] = 0;
  179955. serialNum = 0;
  179956. }
  179957. volumeSerialNumber = serialNum;
  179958. return dest;
  179959. }
  179960. static int64 getDiskSpaceInfo (const String& path, const bool total)
  179961. {
  179962. ULARGE_INTEGER spc, tot, totFree;
  179963. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  179964. return total ? (int64) tot.QuadPart
  179965. : (int64) spc.QuadPart;
  179966. return 0;
  179967. }
  179968. int64 File::getBytesFreeOnVolume() const
  179969. {
  179970. return getDiskSpaceInfo (getFullPathName(), false);
  179971. }
  179972. int64 File::getVolumeTotalSize() const
  179973. {
  179974. return getDiskSpaceInfo (getFullPathName(), true);
  179975. }
  179976. static unsigned int getWindowsDriveType (const String& path)
  179977. {
  179978. return GetDriveType (getDriveFromPath (path));
  179979. }
  179980. bool File::isOnCDRomDrive() const
  179981. {
  179982. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  179983. }
  179984. bool File::isOnHardDisk() const
  179985. {
  179986. if (fullPath.isEmpty())
  179987. return false;
  179988. const unsigned int n = getWindowsDriveType (getFullPathName());
  179989. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  179990. return n != DRIVE_REMOVABLE;
  179991. else
  179992. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  179993. }
  179994. bool File::isOnRemovableDrive() const
  179995. {
  179996. if (fullPath.isEmpty())
  179997. return false;
  179998. const unsigned int n = getWindowsDriveType (getFullPathName());
  179999. return n == DRIVE_CDROM
  180000. || n == DRIVE_REMOTE
  180001. || n == DRIVE_REMOVABLE
  180002. || n == DRIVE_RAMDISK;
  180003. }
  180004. static const File juce_getSpecialFolderPath (int type)
  180005. {
  180006. WCHAR path [MAX_PATH + 256];
  180007. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  180008. return File (String (path));
  180009. return File::nonexistent;
  180010. }
  180011. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180012. {
  180013. int csidlType = 0;
  180014. switch (type)
  180015. {
  180016. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  180017. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  180018. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  180019. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  180020. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  180021. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  180022. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  180023. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  180024. case tempDirectory:
  180025. {
  180026. WCHAR dest [2048];
  180027. dest[0] = 0;
  180028. GetTempPath (numElementsInArray (dest), dest);
  180029. return File (String (dest));
  180030. }
  180031. case invokedExecutableFile:
  180032. case currentExecutableFile:
  180033. case currentApplicationFile:
  180034. {
  180035. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180036. WCHAR dest [MAX_PATH + 256];
  180037. dest[0] = 0;
  180038. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180039. return File (String (dest));
  180040. }
  180041. break;
  180042. default:
  180043. jassertfalse // unknown type?
  180044. return File::nonexistent;
  180045. }
  180046. return juce_getSpecialFolderPath (csidlType);
  180047. }
  180048. const File File::getCurrentWorkingDirectory()
  180049. {
  180050. WCHAR dest [MAX_PATH + 256];
  180051. dest[0] = 0;
  180052. GetCurrentDirectory (numElementsInArray (dest), dest);
  180053. return File (String (dest));
  180054. }
  180055. bool File::setAsCurrentWorkingDirectory() const
  180056. {
  180057. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180058. }
  180059. const String File::getVersion() const
  180060. {
  180061. String result;
  180062. DWORD handle = 0;
  180063. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180064. HeapBlock<char> buffer;
  180065. buffer.calloc (bufferSize);
  180066. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180067. {
  180068. VS_FIXEDFILEINFO* vffi;
  180069. UINT len = 0;
  180070. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180071. {
  180072. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180073. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180074. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180075. << (int) LOWORD (vffi->dwFileVersionLS);
  180076. }
  180077. }
  180078. return result;
  180079. }
  180080. const File File::getLinkedTarget() const
  180081. {
  180082. File result (*this);
  180083. String p (getFullPathName());
  180084. if (! exists())
  180085. p += ".lnk";
  180086. else if (getFileExtension() != ".lnk")
  180087. return result;
  180088. ComSmartPtr <IShellLink> shellLink;
  180089. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180090. {
  180091. ComSmartPtr <IPersistFile> persistFile;
  180092. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180093. {
  180094. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180095. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180096. {
  180097. WIN32_FIND_DATA winFindData;
  180098. WCHAR resolvedPath [MAX_PATH];
  180099. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180100. result = File (resolvedPath);
  180101. }
  180102. }
  180103. }
  180104. return result;
  180105. }
  180106. template <class FindDataType>
  180107. static void getFindFileInfo (FindDataType& findData,
  180108. String& filename, bool* const isDir, bool* const isHidden,
  180109. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180110. bool* const isReadOnly)
  180111. {
  180112. filename = findData.cFileName;
  180113. if (isDir != 0)
  180114. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180115. if (isHidden != 0)
  180116. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180117. if (fileSize != 0)
  180118. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180119. if (modTime != 0)
  180120. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180121. if (creationTime != 0)
  180122. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180123. if (isReadOnly != 0)
  180124. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180125. }
  180126. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180127. bool* isDir, bool* isHidden, int64* fileSize,
  180128. Time* modTime, Time* creationTime, bool* isReadOnly)
  180129. {
  180130. String wc (directory);
  180131. if (! wc.endsWithChar (File::separator))
  180132. wc += File::separator;
  180133. wc += wildCard;
  180134. WIN32_FIND_DATA findData;
  180135. HANDLE h = FindFirstFile (wc, &findData);
  180136. if (h != INVALID_HANDLE_VALUE)
  180137. {
  180138. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180139. modTime, creationTime, isReadOnly);
  180140. return h;
  180141. }
  180142. firstResult = String::empty;
  180143. return 0;
  180144. }
  180145. bool juce_findFileNext (void* handle, String& resultFile,
  180146. bool* isDir, bool* isHidden, int64* fileSize,
  180147. Time* modTime, Time* creationTime, bool* isReadOnly)
  180148. {
  180149. WIN32_FIND_DATA findData;
  180150. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180151. {
  180152. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180153. modTime, creationTime, isReadOnly);
  180154. return true;
  180155. }
  180156. resultFile = String::empty;
  180157. return false;
  180158. }
  180159. void juce_findFileClose (void* handle)
  180160. {
  180161. FindClose (handle);
  180162. }
  180163. bool juce_launchFile (const String& fileName, const String& parameters)
  180164. {
  180165. HINSTANCE hInstance = 0;
  180166. JUCE_TRY
  180167. {
  180168. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180169. }
  180170. JUCE_CATCH_ALL
  180171. return hInstance > (HINSTANCE) 32;
  180172. }
  180173. void File::revealToUser() const
  180174. {
  180175. if (isDirectory())
  180176. startAsProcess();
  180177. else if (getParentDirectory().exists())
  180178. getParentDirectory().startAsProcess();
  180179. }
  180180. class NamedPipeInternal
  180181. {
  180182. public:
  180183. NamedPipeInternal (const String& file, const bool isPipe_)
  180184. : pipeH (0),
  180185. cancelEvent (0),
  180186. connected (false),
  180187. isPipe (isPipe_)
  180188. {
  180189. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180190. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180191. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180192. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180193. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180194. }
  180195. ~NamedPipeInternal()
  180196. {
  180197. disconnectPipe();
  180198. if (pipeH != 0)
  180199. CloseHandle (pipeH);
  180200. CloseHandle (cancelEvent);
  180201. }
  180202. bool connect (const int timeOutMs)
  180203. {
  180204. if (! isPipe)
  180205. return true;
  180206. if (! connected)
  180207. {
  180208. OVERLAPPED over;
  180209. zerostruct (over);
  180210. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180211. if (ConnectNamedPipe (pipeH, &over))
  180212. {
  180213. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180214. }
  180215. else
  180216. {
  180217. const int err = GetLastError();
  180218. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180219. {
  180220. HANDLE handles[] = { over.hEvent, cancelEvent };
  180221. if (WaitForMultipleObjects (2, handles, FALSE,
  180222. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180223. connected = true;
  180224. }
  180225. else if (err == ERROR_PIPE_CONNECTED)
  180226. {
  180227. connected = true;
  180228. }
  180229. }
  180230. CloseHandle (over.hEvent);
  180231. }
  180232. return connected;
  180233. }
  180234. void disconnectPipe()
  180235. {
  180236. if (connected)
  180237. {
  180238. DisconnectNamedPipe (pipeH);
  180239. connected = false;
  180240. }
  180241. }
  180242. HANDLE pipeH;
  180243. HANDLE cancelEvent;
  180244. bool connected, isPipe;
  180245. };
  180246. void NamedPipe::close()
  180247. {
  180248. cancelPendingReads();
  180249. const ScopedLock sl (lock);
  180250. delete static_cast<NamedPipeInternal*> (internal);
  180251. internal = 0;
  180252. }
  180253. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180254. {
  180255. close();
  180256. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180257. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180258. {
  180259. internal = intern.release();
  180260. return true;
  180261. }
  180262. return false;
  180263. }
  180264. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180265. {
  180266. const ScopedLock sl (lock);
  180267. int bytesRead = -1;
  180268. bool waitAgain = true;
  180269. while (waitAgain && internal != 0)
  180270. {
  180271. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180272. waitAgain = false;
  180273. if (! intern->connect (timeOutMilliseconds))
  180274. break;
  180275. if (maxBytesToRead <= 0)
  180276. return 0;
  180277. OVERLAPPED over;
  180278. zerostruct (over);
  180279. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180280. unsigned long numRead;
  180281. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180282. {
  180283. bytesRead = (int) numRead;
  180284. }
  180285. else if (GetLastError() == ERROR_IO_PENDING)
  180286. {
  180287. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180288. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180289. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180290. : INFINITE);
  180291. if (waitResult != WAIT_OBJECT_0)
  180292. {
  180293. // if the operation timed out, let's cancel it...
  180294. CancelIo (intern->pipeH);
  180295. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180296. }
  180297. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180298. {
  180299. bytesRead = (int) numRead;
  180300. }
  180301. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180302. {
  180303. intern->disconnectPipe();
  180304. waitAgain = true;
  180305. }
  180306. }
  180307. else
  180308. {
  180309. waitAgain = internal != 0;
  180310. Sleep (5);
  180311. }
  180312. CloseHandle (over.hEvent);
  180313. }
  180314. return bytesRead;
  180315. }
  180316. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180317. {
  180318. int bytesWritten = -1;
  180319. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180320. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180321. {
  180322. if (numBytesToWrite <= 0)
  180323. return 0;
  180324. OVERLAPPED over;
  180325. zerostruct (over);
  180326. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180327. unsigned long numWritten;
  180328. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180329. {
  180330. bytesWritten = (int) numWritten;
  180331. }
  180332. else if (GetLastError() == ERROR_IO_PENDING)
  180333. {
  180334. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180335. DWORD waitResult;
  180336. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180337. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180338. : INFINITE);
  180339. if (waitResult != WAIT_OBJECT_0)
  180340. {
  180341. CancelIo (intern->pipeH);
  180342. WaitForSingleObject (over.hEvent, INFINITE);
  180343. }
  180344. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180345. {
  180346. bytesWritten = (int) numWritten;
  180347. }
  180348. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180349. {
  180350. intern->disconnectPipe();
  180351. }
  180352. }
  180353. CloseHandle (over.hEvent);
  180354. }
  180355. return bytesWritten;
  180356. }
  180357. void NamedPipe::cancelPendingReads()
  180358. {
  180359. if (internal != 0)
  180360. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180361. }
  180362. #endif
  180363. /*** End of inlined file: juce_win32_Files.cpp ***/
  180364. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180365. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180366. // compiled on its own).
  180367. #if JUCE_INCLUDED_FILE
  180368. #ifndef INTERNET_FLAG_NEED_FILE
  180369. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180370. #endif
  180371. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180372. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180373. #endif
  180374. bool juce_isOnLine()
  180375. {
  180376. DWORD connectionType;
  180377. return InternetGetConnectedState (&connectionType, 0) != 0
  180378. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180379. }
  180380. struct ConnectionAndRequestStruct
  180381. {
  180382. HINTERNET connection, request;
  180383. };
  180384. static HINTERNET sessionHandle = 0;
  180385. #ifndef WORKAROUND_TIMEOUT_BUG
  180386. //#define WORKAROUND_TIMEOUT_BUG 1
  180387. #endif
  180388. #if WORKAROUND_TIMEOUT_BUG
  180389. // Required because of a Microsoft bug in setting a timeout
  180390. class InternetConnectThread : public Thread
  180391. {
  180392. public:
  180393. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180394. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180395. {
  180396. startThread();
  180397. }
  180398. ~InternetConnectThread()
  180399. {
  180400. stopThread (60000);
  180401. }
  180402. void run()
  180403. {
  180404. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180405. uc.nPort, _T(""), _T(""),
  180406. isFtp ? INTERNET_SERVICE_FTP
  180407. : INTERNET_SERVICE_HTTP,
  180408. 0, 0);
  180409. notify();
  180410. }
  180411. juce_UseDebuggingNewOperator
  180412. private:
  180413. URL_COMPONENTS& uc;
  180414. HINTERNET& connection;
  180415. const bool isFtp;
  180416. InternetConnectThread (const InternetConnectThread&);
  180417. InternetConnectThread& operator= (const InternetConnectThread&);
  180418. };
  180419. #endif
  180420. void* juce_openInternetFile (const String& url,
  180421. const String& headers,
  180422. const MemoryBlock& postData,
  180423. const bool isPost,
  180424. URL::OpenStreamProgressCallback* callback,
  180425. void* callbackContext,
  180426. int timeOutMs)
  180427. {
  180428. if (sessionHandle == 0)
  180429. sessionHandle = InternetOpen (_T("juce"),
  180430. INTERNET_OPEN_TYPE_PRECONFIG,
  180431. 0, 0, 0);
  180432. if (sessionHandle != 0)
  180433. {
  180434. // break up the url..
  180435. TCHAR file[1024], server[1024];
  180436. URL_COMPONENTS uc;
  180437. zerostruct (uc);
  180438. uc.dwStructSize = sizeof (uc);
  180439. uc.dwUrlPathLength = sizeof (file);
  180440. uc.dwHostNameLength = sizeof (server);
  180441. uc.lpszUrlPath = file;
  180442. uc.lpszHostName = server;
  180443. if (InternetCrackUrl (url, 0, 0, &uc))
  180444. {
  180445. int disable = 1;
  180446. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180447. if (timeOutMs == 0)
  180448. timeOutMs = 30000;
  180449. else if (timeOutMs < 0)
  180450. timeOutMs = -1;
  180451. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180452. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180453. #if WORKAROUND_TIMEOUT_BUG
  180454. HINTERNET connection = 0;
  180455. {
  180456. InternetConnectThread connectThread (uc, connection, isFtp);
  180457. connectThread.wait (timeOutMs);
  180458. if (connection == 0)
  180459. {
  180460. InternetCloseHandle (sessionHandle);
  180461. sessionHandle = 0;
  180462. }
  180463. }
  180464. #else
  180465. HINTERNET connection = InternetConnect (sessionHandle,
  180466. uc.lpszHostName,
  180467. uc.nPort,
  180468. _T(""), _T(""),
  180469. isFtp ? INTERNET_SERVICE_FTP
  180470. : INTERNET_SERVICE_HTTP,
  180471. 0, 0);
  180472. #endif
  180473. if (connection != 0)
  180474. {
  180475. if (isFtp)
  180476. {
  180477. HINTERNET request = FtpOpenFile (connection,
  180478. uc.lpszUrlPath,
  180479. GENERIC_READ,
  180480. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180481. 0);
  180482. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180483. result->connection = connection;
  180484. result->request = request;
  180485. return result;
  180486. }
  180487. else
  180488. {
  180489. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180490. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180491. if (url.startsWithIgnoreCase ("https:"))
  180492. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180493. // IE7 seems to automatically work out when it's https)
  180494. HINTERNET request = HttpOpenRequest (connection,
  180495. isPost ? _T("POST")
  180496. : _T("GET"),
  180497. uc.lpszUrlPath,
  180498. 0, 0, mimeTypes, flags, 0);
  180499. if (request != 0)
  180500. {
  180501. INTERNET_BUFFERS buffers;
  180502. zerostruct (buffers);
  180503. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180504. buffers.lpcszHeader = (LPCTSTR) headers;
  180505. buffers.dwHeadersLength = headers.length();
  180506. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180507. ConnectionAndRequestStruct* result = 0;
  180508. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180509. {
  180510. int bytesSent = 0;
  180511. for (;;)
  180512. {
  180513. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180514. DWORD bytesDone = 0;
  180515. if (bytesToDo > 0
  180516. && ! InternetWriteFile (request,
  180517. static_cast <const char*> (postData.getData()) + bytesSent,
  180518. bytesToDo, &bytesDone))
  180519. {
  180520. break;
  180521. }
  180522. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180523. {
  180524. result = new ConnectionAndRequestStruct();
  180525. result->connection = connection;
  180526. result->request = request;
  180527. HttpEndRequest (request, 0, 0, 0);
  180528. return result;
  180529. }
  180530. bytesSent += bytesDone;
  180531. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180532. break;
  180533. }
  180534. }
  180535. InternetCloseHandle (request);
  180536. }
  180537. InternetCloseHandle (connection);
  180538. }
  180539. }
  180540. }
  180541. }
  180542. return 0;
  180543. }
  180544. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180545. {
  180546. DWORD bytesRead = 0;
  180547. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180548. if (crs != 0)
  180549. InternetReadFile (crs->request,
  180550. buffer, bytesToRead,
  180551. &bytesRead);
  180552. return bytesRead;
  180553. }
  180554. int juce_seekInInternetFile (void* handle, int newPosition)
  180555. {
  180556. if (handle != 0)
  180557. {
  180558. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180559. return InternetSetFilePointer (crs->request, newPosition, 0, FILE_BEGIN, 0);
  180560. }
  180561. else
  180562. {
  180563. return -1;
  180564. }
  180565. }
  180566. int64 juce_getInternetFileContentLength (void* handle)
  180567. {
  180568. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180569. if (crs != 0)
  180570. {
  180571. DWORD index = 0, result = 0, size = sizeof (result);
  180572. if (HttpQueryInfo (crs->request, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180573. &result, &size, &index))
  180574. {
  180575. return (int64) result;
  180576. }
  180577. }
  180578. return -1;
  180579. }
  180580. void juce_closeInternetFile (void* handle)
  180581. {
  180582. if (handle != 0)
  180583. {
  180584. ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180585. InternetCloseHandle (crs->request);
  180586. InternetCloseHandle (crs->connection);
  180587. delete crs;
  180588. }
  180589. }
  180590. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180591. {
  180592. int numFound = 0;
  180593. DynamicLibraryLoader dll ("iphlpapi.dll");
  180594. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180595. if (getAdaptersInfo != 0)
  180596. {
  180597. ULONG len = sizeof (IP_ADAPTER_INFO);
  180598. MemoryBlock mb;
  180599. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180600. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180601. {
  180602. mb.setSize (len);
  180603. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180604. }
  180605. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180606. {
  180607. PIP_ADAPTER_INFO adapter = adapterInfo;
  180608. while (adapter != 0)
  180609. {
  180610. int64 mac = 0;
  180611. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180612. mac = (mac << 8) | adapter->Address[i];
  180613. if (littleEndian)
  180614. mac = (int64) ByteOrder::swap ((uint64) mac);
  180615. if (numFound < maxNum && mac != 0)
  180616. addresses [numFound++] = mac;
  180617. adapter = adapter->Next;
  180618. }
  180619. }
  180620. }
  180621. return numFound;
  180622. }
  180623. struct ASTAT
  180624. {
  180625. ADAPTER_STATUS adapt;
  180626. NAME_BUFFER NameBuff [30];
  180627. };
  180628. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180629. {
  180630. int numFound = 0;
  180631. DynamicLibraryLoader dll ("netapi32.dll");
  180632. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180633. if (NetbiosCall != 0)
  180634. {
  180635. NCB ncb;
  180636. zerostruct (ncb);
  180637. ASTAT astat;
  180638. zerostruct (astat);
  180639. LANA_ENUM enums;
  180640. zerostruct (enums);
  180641. ncb.ncb_command = NCBENUM;
  180642. ncb.ncb_buffer = (unsigned char*) &enums;
  180643. ncb.ncb_length = sizeof (LANA_ENUM);
  180644. NetbiosCall (&ncb);
  180645. for (int i = 0; i < enums.length; ++i)
  180646. {
  180647. zerostruct (ncb);
  180648. ncb.ncb_command = NCBRESET;
  180649. ncb.ncb_lana_num = enums.lana[i];
  180650. if (NetbiosCall (&ncb) == 0)
  180651. {
  180652. zerostruct (ncb);
  180653. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180654. ncb.ncb_command = NCBASTAT;
  180655. ncb.ncb_lana_num = enums.lana[i];
  180656. ncb.ncb_buffer = (unsigned char*) &astat;
  180657. ncb.ncb_length = sizeof (ASTAT);
  180658. if (NetbiosCall (&ncb) == 0)
  180659. {
  180660. if (astat.adapt.adapter_type == 0xfe)
  180661. {
  180662. uint64 mac = 0;
  180663. for (int i = 6; --i >= 0;)
  180664. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180665. if (numFound < maxNum && mac != 0)
  180666. addresses [numFound++] = mac;
  180667. }
  180668. }
  180669. }
  180670. }
  180671. }
  180672. return numFound;
  180673. }
  180674. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180675. {
  180676. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180677. if (numFound == 0)
  180678. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180679. return numFound;
  180680. }
  180681. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180682. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180683. const String& emailSubject,
  180684. const String& bodyText,
  180685. const StringArray& filesToAttach)
  180686. {
  180687. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180688. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180689. bool ok = false;
  180690. if (mapiSendMail != 0)
  180691. {
  180692. MapiMessage message;
  180693. zerostruct (message);
  180694. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180695. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180696. MapiRecipDesc recip;
  180697. zerostruct (recip);
  180698. recip.ulRecipClass = MAPI_TO;
  180699. String targetEmailAddress_ (targetEmailAddress);
  180700. if (targetEmailAddress_.isEmpty())
  180701. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180702. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180703. message.nRecipCount = 1;
  180704. message.lpRecips = &recip;
  180705. HeapBlock <MapiFileDesc> files;
  180706. files.calloc (filesToAttach.size());
  180707. message.nFileCount = filesToAttach.size();
  180708. message.lpFiles = files;
  180709. for (int i = 0; i < filesToAttach.size(); ++i)
  180710. {
  180711. files[i].nPosition = (ULONG) -1;
  180712. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180713. }
  180714. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180715. }
  180716. FreeLibrary (h);
  180717. return ok;
  180718. }
  180719. #endif
  180720. /*** End of inlined file: juce_win32_Network.cpp ***/
  180721. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180722. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180723. // compiled on its own).
  180724. #if JUCE_INCLUDED_FILE
  180725. static HKEY findKeyForPath (String name,
  180726. const bool createForWriting,
  180727. String& valueName)
  180728. {
  180729. HKEY rootKey = 0;
  180730. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180731. rootKey = HKEY_CURRENT_USER;
  180732. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180733. rootKey = HKEY_LOCAL_MACHINE;
  180734. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180735. rootKey = HKEY_CLASSES_ROOT;
  180736. if (rootKey != 0)
  180737. {
  180738. name = name.substring (name.indexOfChar ('\\') + 1);
  180739. const int lastSlash = name.lastIndexOfChar ('\\');
  180740. valueName = name.substring (lastSlash + 1);
  180741. name = name.substring (0, lastSlash);
  180742. HKEY key;
  180743. DWORD result;
  180744. if (createForWriting)
  180745. {
  180746. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180747. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180748. return key;
  180749. }
  180750. else
  180751. {
  180752. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180753. return key;
  180754. }
  180755. }
  180756. return 0;
  180757. }
  180758. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180759. const String& defaultValue)
  180760. {
  180761. String valueName, result (defaultValue);
  180762. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180763. if (k != 0)
  180764. {
  180765. WCHAR buffer [2048];
  180766. unsigned long bufferSize = sizeof (buffer);
  180767. DWORD type = REG_SZ;
  180768. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180769. {
  180770. if (type == REG_SZ)
  180771. result = buffer;
  180772. else if (type == REG_DWORD)
  180773. result = String ((int) *(DWORD*) buffer);
  180774. }
  180775. RegCloseKey (k);
  180776. }
  180777. return result;
  180778. }
  180779. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180780. const String& value)
  180781. {
  180782. String valueName;
  180783. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180784. if (k != 0)
  180785. {
  180786. RegSetValueEx (k, valueName, 0, REG_SZ,
  180787. (const BYTE*) (const WCHAR*) value,
  180788. sizeof (WCHAR) * (value.length() + 1));
  180789. RegCloseKey (k);
  180790. }
  180791. }
  180792. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180793. {
  180794. bool exists = false;
  180795. String valueName;
  180796. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180797. if (k != 0)
  180798. {
  180799. unsigned char buffer [2048];
  180800. unsigned long bufferSize = sizeof (buffer);
  180801. DWORD type = 0;
  180802. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180803. exists = true;
  180804. RegCloseKey (k);
  180805. }
  180806. return exists;
  180807. }
  180808. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180809. {
  180810. String valueName;
  180811. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180812. if (k != 0)
  180813. {
  180814. RegDeleteValue (k, valueName);
  180815. RegCloseKey (k);
  180816. }
  180817. }
  180818. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180819. {
  180820. String valueName;
  180821. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180822. if (k != 0)
  180823. {
  180824. RegDeleteKey (k, valueName);
  180825. RegCloseKey (k);
  180826. }
  180827. }
  180828. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180829. const String& symbolicDescription,
  180830. const String& fullDescription,
  180831. const File& targetExecutable,
  180832. int iconResourceNumber)
  180833. {
  180834. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180835. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180836. if (iconResourceNumber != 0)
  180837. setRegistryValue (key + "\\DefaultIcon\\",
  180838. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180839. setRegistryValue (key + "\\", fullDescription);
  180840. setRegistryValue (key + "\\shell\\open\\command\\",
  180841. targetExecutable.getFullPathName() + " %1");
  180842. }
  180843. bool juce_IsRunningInWine()
  180844. {
  180845. HKEY key;
  180846. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180847. {
  180848. RegCloseKey (key);
  180849. return true;
  180850. }
  180851. return false;
  180852. }
  180853. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180854. {
  180855. String s (::GetCommandLineW());
  180856. StringArray tokens;
  180857. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180858. return tokens.joinIntoString (" ", 1);
  180859. }
  180860. static void* currentModuleHandle = 0;
  180861. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180862. {
  180863. if (currentModuleHandle == 0)
  180864. currentModuleHandle = GetModuleHandle (0);
  180865. return currentModuleHandle;
  180866. }
  180867. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180868. {
  180869. currentModuleHandle = newHandle;
  180870. }
  180871. void PlatformUtilities::fpuReset()
  180872. {
  180873. #if JUCE_MSVC
  180874. _clearfp();
  180875. #endif
  180876. }
  180877. void PlatformUtilities::beep()
  180878. {
  180879. MessageBeep (MB_OK);
  180880. }
  180881. #endif
  180882. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180883. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180884. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180885. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180886. // compiled on its own).
  180887. #if JUCE_INCLUDED_FILE
  180888. static const unsigned int specialId = WM_APP + 0x4400;
  180889. static const unsigned int broadcastId = WM_APP + 0x4403;
  180890. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180891. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180892. HWND juce_messageWindowHandle = 0;
  180893. extern long improbableWindowNumber; // defined in windowing.cpp
  180894. #ifndef WM_APPCOMMAND
  180895. #define WM_APPCOMMAND 0x0319
  180896. #endif
  180897. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180898. const UINT message,
  180899. const WPARAM wParam,
  180900. const LPARAM lParam) throw()
  180901. {
  180902. JUCE_TRY
  180903. {
  180904. if (h == juce_messageWindowHandle)
  180905. {
  180906. if (message == specialCallbackId)
  180907. {
  180908. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180909. return (LRESULT) (*func) ((void*) lParam);
  180910. }
  180911. else if (message == specialId)
  180912. {
  180913. // these are trapped early in the dispatch call, but must also be checked
  180914. // here in case there are windows modal dialog boxes doing their own
  180915. // dispatch loop and not calling our version
  180916. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180917. return 0;
  180918. }
  180919. else if (message == broadcastId)
  180920. {
  180921. const ScopedPointer <String> messageString ((String*) lParam);
  180922. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180923. return 0;
  180924. }
  180925. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180926. {
  180927. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180928. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180929. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180930. return 0;
  180931. }
  180932. }
  180933. }
  180934. JUCE_CATCH_EXCEPTION
  180935. return DefWindowProc (h, message, wParam, lParam);
  180936. }
  180937. static bool isEventBlockedByModalComps (MSG& m)
  180938. {
  180939. if (Component::getNumCurrentlyModalComponents() == 0
  180940. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  180941. return false;
  180942. switch (m.message)
  180943. {
  180944. case WM_MOUSEMOVE:
  180945. case WM_NCMOUSEMOVE:
  180946. case 0x020A: /* WM_MOUSEWHEEL */
  180947. case 0x020E: /* WM_MOUSEHWHEEL */
  180948. case WM_KEYUP:
  180949. case WM_SYSKEYUP:
  180950. case WM_CHAR:
  180951. case WM_APPCOMMAND:
  180952. case WM_LBUTTONUP:
  180953. case WM_MBUTTONUP:
  180954. case WM_RBUTTONUP:
  180955. case WM_MOUSEACTIVATE:
  180956. case WM_NCMOUSEHOVER:
  180957. case WM_MOUSEHOVER:
  180958. return true;
  180959. case WM_NCLBUTTONDOWN:
  180960. case WM_NCLBUTTONDBLCLK:
  180961. case WM_NCRBUTTONDOWN:
  180962. case WM_NCRBUTTONDBLCLK:
  180963. case WM_NCMBUTTONDOWN:
  180964. case WM_NCMBUTTONDBLCLK:
  180965. case WM_LBUTTONDOWN:
  180966. case WM_LBUTTONDBLCLK:
  180967. case WM_MBUTTONDOWN:
  180968. case WM_MBUTTONDBLCLK:
  180969. case WM_RBUTTONDOWN:
  180970. case WM_RBUTTONDBLCLK:
  180971. case WM_KEYDOWN:
  180972. case WM_SYSKEYDOWN:
  180973. {
  180974. Component* const modal = Component::getCurrentlyModalComponent (0);
  180975. if (modal != 0)
  180976. modal->inputAttemptWhenModal();
  180977. return true;
  180978. }
  180979. default:
  180980. break;
  180981. }
  180982. return false;
  180983. }
  180984. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  180985. {
  180986. MSG m;
  180987. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  180988. return false;
  180989. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  180990. {
  180991. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  180992. {
  180993. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  180994. }
  180995. else if (m.message == WM_QUIT)
  180996. {
  180997. if (JUCEApplication::getInstance())
  180998. JUCEApplication::getInstance()->systemRequestedQuit();
  180999. }
  181000. else if (! isEventBlockedByModalComps (m))
  181001. {
  181002. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181003. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181004. {
  181005. // if it's someone else's window being clicked on, and the focus is
  181006. // currently on a juce window, pass the kb focus over..
  181007. HWND currentFocus = GetFocus();
  181008. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181009. SetFocus (m.hwnd);
  181010. }
  181011. TranslateMessage (&m);
  181012. DispatchMessage (&m);
  181013. }
  181014. }
  181015. return true;
  181016. }
  181017. bool juce_postMessageToSystemQueue (void* message)
  181018. {
  181019. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181020. }
  181021. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181022. void* userData)
  181023. {
  181024. if (MessageManager::getInstance()->isThisTheMessageThread())
  181025. {
  181026. return (*callback) (userData);
  181027. }
  181028. else
  181029. {
  181030. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181031. // deadlock because the message manager is blocked from running, and can't
  181032. // call your function..
  181033. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181034. return (void*) SendMessage (juce_messageWindowHandle,
  181035. specialCallbackId,
  181036. (WPARAM) callback,
  181037. (LPARAM) userData);
  181038. }
  181039. }
  181040. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181041. {
  181042. if (hwnd != juce_messageWindowHandle)
  181043. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  181044. return TRUE;
  181045. }
  181046. void MessageManager::broadcastMessage (const String& value) throw()
  181047. {
  181048. VoidArray windows;
  181049. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181050. const String localCopy (value);
  181051. COPYDATASTRUCT data;
  181052. data.dwData = broadcastId;
  181053. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181054. data.lpData = (void*) static_cast <const juce_wchar*> (localCopy);
  181055. for (int i = windows.size(); --i >= 0;)
  181056. {
  181057. HWND hwnd = (HWND) windows.getUnchecked(i);
  181058. TCHAR windowName [64]; // no need to read longer strings than this
  181059. GetWindowText (hwnd, windowName, 64);
  181060. windowName [63] = 0;
  181061. if (String (windowName) == String (messageWindowName))
  181062. {
  181063. DWORD_PTR result;
  181064. SendMessageTimeout (hwnd, WM_COPYDATA,
  181065. (WPARAM) juce_messageWindowHandle,
  181066. (LPARAM) &data,
  181067. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181068. 8000,
  181069. &result);
  181070. }
  181071. }
  181072. }
  181073. static const String getMessageWindowClassName()
  181074. {
  181075. // this name has to be different for each app/dll instance because otherwise
  181076. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181077. // window class).
  181078. static int number = 0;
  181079. if (number == 0)
  181080. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181081. return "JUCEcs_" + String (number);
  181082. }
  181083. void MessageManager::doPlatformSpecificInitialisation()
  181084. {
  181085. OleInitialize (0);
  181086. const String className (getMessageWindowClassName());
  181087. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181088. WNDCLASSEX wc;
  181089. zerostruct (wc);
  181090. wc.cbSize = sizeof (wc);
  181091. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181092. wc.cbWndExtra = 4;
  181093. wc.hInstance = hmod;
  181094. wc.lpszClassName = className;
  181095. RegisterClassEx (&wc);
  181096. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181097. messageWindowName,
  181098. 0, 0, 0, 0, 0, 0, 0,
  181099. hmod, 0);
  181100. }
  181101. void MessageManager::doPlatformSpecificShutdown()
  181102. {
  181103. DestroyWindow (juce_messageWindowHandle);
  181104. UnregisterClass (getMessageWindowClassName(), 0);
  181105. OleUninitialize();
  181106. }
  181107. #endif
  181108. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181109. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181110. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181111. // compiled on its own).
  181112. #if JUCE_INCLUDED_FILE
  181113. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181114. // these are in the windows SDK, but need to be repeated here for GCC..
  181115. #ifndef GET_APPCOMMAND_LPARAM
  181116. #define FAPPCOMMAND_MASK 0xF000
  181117. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181118. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181119. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181120. #define APPCOMMAND_MEDIA_STOP 13
  181121. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181122. #define WM_APPCOMMAND 0x0319
  181123. #endif
  181124. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181125. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181126. extern bool juce_IsRunningInWine();
  181127. #ifndef ULW_ALPHA
  181128. #define ULW_ALPHA 0x00000002
  181129. #endif
  181130. #ifndef AC_SRC_ALPHA
  181131. #define AC_SRC_ALPHA 0x01
  181132. #endif
  181133. static HPALETTE palette = 0;
  181134. static bool createPaletteIfNeeded = true;
  181135. static bool shouldDeactivateTitleBar = true;
  181136. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181137. #define WM_TRAYNOTIFY WM_USER + 100
  181138. using ::abs;
  181139. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181140. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181141. bool Desktop::canUseSemiTransparentWindows() throw()
  181142. {
  181143. if (updateLayeredWindow == 0)
  181144. {
  181145. if (! juce_IsRunningInWine())
  181146. {
  181147. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181148. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181149. }
  181150. }
  181151. return updateLayeredWindow != 0;
  181152. }
  181153. const int extendedKeyModifier = 0x10000;
  181154. const int KeyPress::spaceKey = VK_SPACE;
  181155. const int KeyPress::returnKey = VK_RETURN;
  181156. const int KeyPress::escapeKey = VK_ESCAPE;
  181157. const int KeyPress::backspaceKey = VK_BACK;
  181158. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181159. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181160. const int KeyPress::tabKey = VK_TAB;
  181161. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181162. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181163. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181164. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181165. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181166. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181167. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181168. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181169. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181170. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181171. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181172. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181173. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181174. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181175. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181176. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181177. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181178. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181179. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181180. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181181. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181182. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181183. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181184. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181185. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181186. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181187. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181188. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181189. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181190. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181191. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181192. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181193. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181194. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181195. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181196. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181197. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181198. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181199. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181200. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181201. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181202. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181203. const int KeyPress::playKey = 0x30000;
  181204. const int KeyPress::stopKey = 0x30001;
  181205. const int KeyPress::fastForwardKey = 0x30002;
  181206. const int KeyPress::rewindKey = 0x30003;
  181207. class WindowsBitmapImage : public Image
  181208. {
  181209. public:
  181210. HBITMAP hBitmap;
  181211. BITMAPV4HEADER bitmapInfo;
  181212. HDC hdc;
  181213. unsigned char* bitmapData;
  181214. WindowsBitmapImage (const PixelFormat format_,
  181215. const int w, const int h, const bool clearImage)
  181216. : Image (format_, w, h)
  181217. {
  181218. jassert (format_ == RGB || format_ == ARGB);
  181219. pixelStride = (format_ == RGB) ? 3 : 4;
  181220. zerostruct (bitmapInfo);
  181221. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181222. bitmapInfo.bV4Width = w;
  181223. bitmapInfo.bV4Height = h;
  181224. bitmapInfo.bV4Planes = 1;
  181225. bitmapInfo.bV4CSType = 1;
  181226. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181227. if (format_ == ARGB)
  181228. {
  181229. bitmapInfo.bV4AlphaMask = 0xff000000;
  181230. bitmapInfo.bV4RedMask = 0xff0000;
  181231. bitmapInfo.bV4GreenMask = 0xff00;
  181232. bitmapInfo.bV4BlueMask = 0xff;
  181233. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181234. }
  181235. else
  181236. {
  181237. bitmapInfo.bV4V4Compression = BI_RGB;
  181238. }
  181239. lineStride = -((w * pixelStride + 3) & ~3);
  181240. HDC dc = GetDC (0);
  181241. hdc = CreateCompatibleDC (dc);
  181242. ReleaseDC (0, dc);
  181243. SetMapMode (hdc, MM_TEXT);
  181244. hBitmap = CreateDIBSection (hdc,
  181245. (BITMAPINFO*) &(bitmapInfo),
  181246. DIB_RGB_COLORS,
  181247. (void**) &bitmapData,
  181248. 0, 0);
  181249. SelectObject (hdc, hBitmap);
  181250. if (format_ == ARGB && clearImage)
  181251. zeromem (bitmapData, abs (h * lineStride));
  181252. imageData = bitmapData - (lineStride * (h - 1));
  181253. }
  181254. ~WindowsBitmapImage()
  181255. {
  181256. DeleteDC (hdc);
  181257. DeleteObject (hBitmap);
  181258. }
  181259. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181260. const int x, const int y,
  181261. const RectangleList& maskedRegion) throw()
  181262. {
  181263. static HDRAWDIB hdd = 0;
  181264. static bool needToCreateDrawDib = true;
  181265. if (needToCreateDrawDib)
  181266. {
  181267. needToCreateDrawDib = false;
  181268. HDC dc = GetDC (0);
  181269. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181270. ReleaseDC (0, dc);
  181271. // only open if we're not palettised
  181272. if (n > 8)
  181273. hdd = DrawDibOpen();
  181274. }
  181275. if (createPaletteIfNeeded)
  181276. {
  181277. HDC dc = GetDC (0);
  181278. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181279. ReleaseDC (0, dc);
  181280. if (n <= 8)
  181281. palette = CreateHalftonePalette (dc);
  181282. createPaletteIfNeeded = false;
  181283. }
  181284. if (palette != 0)
  181285. {
  181286. SelectPalette (dc, palette, FALSE);
  181287. RealizePalette (dc);
  181288. SetStretchBltMode (dc, HALFTONE);
  181289. }
  181290. SetMapMode (dc, MM_TEXT);
  181291. if (transparent)
  181292. {
  181293. POINT p, pos;
  181294. SIZE size;
  181295. RECT windowBounds;
  181296. GetWindowRect (hwnd, &windowBounds);
  181297. p.x = -x;
  181298. p.y = -y;
  181299. pos.x = windowBounds.left;
  181300. pos.y = windowBounds.top;
  181301. size.cx = windowBounds.right - windowBounds.left;
  181302. size.cy = windowBounds.bottom - windowBounds.top;
  181303. BLENDFUNCTION bf;
  181304. bf.AlphaFormat = AC_SRC_ALPHA;
  181305. bf.BlendFlags = 0;
  181306. bf.BlendOp = AC_SRC_OVER;
  181307. bf.SourceConstantAlpha = 0xff;
  181308. if (! maskedRegion.isEmpty())
  181309. {
  181310. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181311. {
  181312. const Rectangle<int>& r = *i.getRectangle();
  181313. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181314. }
  181315. }
  181316. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181317. }
  181318. else
  181319. {
  181320. int savedDC = 0;
  181321. if (! maskedRegion.isEmpty())
  181322. {
  181323. savedDC = SaveDC (dc);
  181324. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181325. {
  181326. const Rectangle<int>& r = *i.getRectangle();
  181327. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181328. }
  181329. }
  181330. const int w = getWidth();
  181331. const int h = getHeight();
  181332. if (hdd == 0)
  181333. {
  181334. StretchDIBits (dc,
  181335. x, y, w, h,
  181336. 0, 0, w, h,
  181337. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181338. DIB_RGB_COLORS, SRCCOPY);
  181339. }
  181340. else
  181341. {
  181342. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181343. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181344. 0, 0, w, h, 0);
  181345. }
  181346. if (! maskedRegion.isEmpty())
  181347. RestoreDC (dc, savedDC);
  181348. }
  181349. }
  181350. juce_UseDebuggingNewOperator
  181351. private:
  181352. WindowsBitmapImage (const WindowsBitmapImage&);
  181353. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181354. };
  181355. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181356. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  181357. {
  181358. SHORT k = (SHORT) keyCode;
  181359. if ((keyCode & extendedKeyModifier) == 0
  181360. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181361. k += (SHORT) 'A' - (SHORT) 'a';
  181362. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181363. (SHORT) '+', VK_OEM_PLUS,
  181364. (SHORT) '-', VK_OEM_MINUS,
  181365. (SHORT) '.', VK_OEM_PERIOD,
  181366. (SHORT) ';', VK_OEM_1,
  181367. (SHORT) ':', VK_OEM_1,
  181368. (SHORT) '/', VK_OEM_2,
  181369. (SHORT) '?', VK_OEM_2,
  181370. (SHORT) '[', VK_OEM_4,
  181371. (SHORT) ']', VK_OEM_6 };
  181372. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181373. if (k == translatedValues [i])
  181374. k = translatedValues [i + 1];
  181375. return (GetKeyState (k) & 0x8000) != 0;
  181376. }
  181377. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181378. {
  181379. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181380. return callback (userData);
  181381. else
  181382. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181383. }
  181384. class Win32ComponentPeer : public ComponentPeer
  181385. {
  181386. public:
  181387. Win32ComponentPeer (Component* const component,
  181388. const int windowStyleFlags)
  181389. : ComponentPeer (component, windowStyleFlags),
  181390. dontRepaint (false),
  181391. fullScreen (false),
  181392. isDragging (false),
  181393. isMouseOver (false),
  181394. hasCreatedCaret (false),
  181395. currentWindowIcon (0),
  181396. taskBarIcon (0),
  181397. dropTarget (0)
  181398. {
  181399. callFunctionIfNotLocked (&createWindowCallback, this);
  181400. setTitle (component->getName());
  181401. if ((windowStyleFlags & windowHasDropShadow) != 0
  181402. && Desktop::canUseSemiTransparentWindows())
  181403. {
  181404. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181405. if (shadower != 0)
  181406. shadower->setOwner (component);
  181407. }
  181408. else
  181409. {
  181410. shadower = 0;
  181411. }
  181412. }
  181413. ~Win32ComponentPeer()
  181414. {
  181415. setTaskBarIcon (0);
  181416. deleteAndZero (shadower);
  181417. // do this before the next bit to avoid messages arriving for this window
  181418. // before it's destroyed
  181419. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181420. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181421. if (currentWindowIcon != 0)
  181422. DestroyIcon (currentWindowIcon);
  181423. if (dropTarget != 0)
  181424. {
  181425. dropTarget->Release();
  181426. dropTarget = 0;
  181427. }
  181428. }
  181429. void* getNativeHandle() const
  181430. {
  181431. return hwnd;
  181432. }
  181433. void setVisible (bool shouldBeVisible)
  181434. {
  181435. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181436. if (shouldBeVisible)
  181437. InvalidateRect (hwnd, 0, 0);
  181438. else
  181439. lastPaintTime = 0;
  181440. }
  181441. void setTitle (const String& title)
  181442. {
  181443. SetWindowText (hwnd, title);
  181444. }
  181445. void setPosition (int x, int y)
  181446. {
  181447. offsetWithinParent (x, y);
  181448. SetWindowPos (hwnd, 0,
  181449. x - windowBorder.getLeft(),
  181450. y - windowBorder.getTop(),
  181451. 0, 0,
  181452. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181453. }
  181454. void repaintNowIfTransparent()
  181455. {
  181456. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181457. handlePaintMessage();
  181458. }
  181459. void updateBorderSize()
  181460. {
  181461. WINDOWINFO info;
  181462. info.cbSize = sizeof (info);
  181463. if (GetWindowInfo (hwnd, &info))
  181464. {
  181465. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181466. info.rcClient.left - info.rcWindow.left,
  181467. info.rcWindow.bottom - info.rcClient.bottom,
  181468. info.rcWindow.right - info.rcClient.right);
  181469. }
  181470. }
  181471. void setSize (int w, int h)
  181472. {
  181473. SetWindowPos (hwnd, 0, 0, 0,
  181474. w + windowBorder.getLeftAndRight(),
  181475. h + windowBorder.getTopAndBottom(),
  181476. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181477. updateBorderSize();
  181478. repaintNowIfTransparent();
  181479. }
  181480. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181481. {
  181482. fullScreen = isNowFullScreen;
  181483. offsetWithinParent (x, y);
  181484. SetWindowPos (hwnd, 0,
  181485. x - windowBorder.getLeft(),
  181486. y - windowBorder.getTop(),
  181487. w + windowBorder.getLeftAndRight(),
  181488. h + windowBorder.getTopAndBottom(),
  181489. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181490. updateBorderSize();
  181491. repaintNowIfTransparent();
  181492. }
  181493. const Rectangle<int> getBounds() const
  181494. {
  181495. RECT r;
  181496. GetWindowRect (hwnd, &r);
  181497. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181498. HWND parentH = GetParent (hwnd);
  181499. if (parentH != 0)
  181500. {
  181501. GetWindowRect (parentH, &r);
  181502. bounds.translate (-r.left, -r.top);
  181503. }
  181504. return windowBorder.subtractedFrom (bounds);
  181505. }
  181506. const Point<int> getScreenPosition() const
  181507. {
  181508. RECT r;
  181509. GetWindowRect (hwnd, &r);
  181510. return Point<int> (r.left + windowBorder.getLeft(),
  181511. r.top + windowBorder.getTop());
  181512. }
  181513. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181514. {
  181515. return relativePosition + getScreenPosition();
  181516. }
  181517. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181518. {
  181519. return screenPosition - getScreenPosition();
  181520. }
  181521. void setMinimised (bool shouldBeMinimised)
  181522. {
  181523. if (shouldBeMinimised != isMinimised())
  181524. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181525. }
  181526. bool isMinimised() const
  181527. {
  181528. WINDOWPLACEMENT wp;
  181529. wp.length = sizeof (WINDOWPLACEMENT);
  181530. GetWindowPlacement (hwnd, &wp);
  181531. return wp.showCmd == SW_SHOWMINIMIZED;
  181532. }
  181533. void setFullScreen (bool shouldBeFullScreen)
  181534. {
  181535. setMinimised (false);
  181536. if (fullScreen != shouldBeFullScreen)
  181537. {
  181538. fullScreen = shouldBeFullScreen;
  181539. const Component::SafePointer<Component> deletionChecker (component);
  181540. if (! fullScreen)
  181541. {
  181542. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181543. if (hasTitleBar())
  181544. ShowWindow (hwnd, SW_SHOWNORMAL);
  181545. if (! boundsCopy.isEmpty())
  181546. {
  181547. setBounds (boundsCopy.getX(),
  181548. boundsCopy.getY(),
  181549. boundsCopy.getWidth(),
  181550. boundsCopy.getHeight(),
  181551. false);
  181552. }
  181553. }
  181554. else
  181555. {
  181556. if (hasTitleBar())
  181557. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181558. else
  181559. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181560. }
  181561. if (deletionChecker != 0)
  181562. handleMovedOrResized();
  181563. }
  181564. }
  181565. bool isFullScreen() const
  181566. {
  181567. if (! hasTitleBar())
  181568. return fullScreen;
  181569. WINDOWPLACEMENT wp;
  181570. wp.length = sizeof (wp);
  181571. GetWindowPlacement (hwnd, &wp);
  181572. return wp.showCmd == SW_SHOWMAXIMIZED;
  181573. }
  181574. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181575. {
  181576. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181577. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181578. return false;
  181579. RECT r;
  181580. GetWindowRect (hwnd, &r);
  181581. POINT p;
  181582. p.x = position.getX() + r.left + windowBorder.getLeft();
  181583. p.y = position.getY() + r.top + windowBorder.getTop();
  181584. HWND w = WindowFromPoint (p);
  181585. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181586. }
  181587. const BorderSize getFrameSize() const
  181588. {
  181589. return windowBorder;
  181590. }
  181591. bool setAlwaysOnTop (bool alwaysOnTop)
  181592. {
  181593. const bool oldDeactivate = shouldDeactivateTitleBar;
  181594. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181595. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181596. 0, 0, 0, 0,
  181597. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181598. shouldDeactivateTitleBar = oldDeactivate;
  181599. if (shadower != 0)
  181600. shadower->componentBroughtToFront (*component);
  181601. return true;
  181602. }
  181603. void toFront (bool makeActive)
  181604. {
  181605. setMinimised (false);
  181606. const bool oldDeactivate = shouldDeactivateTitleBar;
  181607. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181608. callFunctionIfNotLocked (makeActive ? &toFrontCallback1 : &toFrontCallback2, hwnd);
  181609. shouldDeactivateTitleBar = oldDeactivate;
  181610. if (! makeActive)
  181611. {
  181612. // in this case a broughttofront call won't have occured, so do it now..
  181613. handleBroughtToFront();
  181614. }
  181615. }
  181616. void toBehind (ComponentPeer* other)
  181617. {
  181618. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181619. jassert (otherPeer != 0); // wrong type of window?
  181620. if (otherPeer != 0)
  181621. {
  181622. setMinimised (false);
  181623. // must be careful not to try to put a topmost window behind a normal one, or win32
  181624. // promotes the normal one to be topmost!
  181625. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181626. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181627. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181628. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181629. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181630. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181631. }
  181632. }
  181633. bool isFocused() const
  181634. {
  181635. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181636. }
  181637. void grabFocus()
  181638. {
  181639. const bool oldDeactivate = shouldDeactivateTitleBar;
  181640. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181641. callFunctionIfNotLocked (&setFocusCallback, hwnd);
  181642. shouldDeactivateTitleBar = oldDeactivate;
  181643. }
  181644. void textInputRequired (const Point<int>&)
  181645. {
  181646. if (! hasCreatedCaret)
  181647. {
  181648. hasCreatedCaret = true;
  181649. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181650. }
  181651. ShowCaret (hwnd);
  181652. SetCaretPos (0, 0);
  181653. }
  181654. void repaint (int x, int y, int w, int h)
  181655. {
  181656. const RECT r = { x, y, x + w, y + h };
  181657. InvalidateRect (hwnd, &r, FALSE);
  181658. }
  181659. void performAnyPendingRepaintsNow()
  181660. {
  181661. MSG m;
  181662. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181663. DispatchMessage (&m);
  181664. }
  181665. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181666. {
  181667. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181668. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181669. return 0;
  181670. }
  181671. void setTaskBarIcon (const Image* const image)
  181672. {
  181673. if (image != 0)
  181674. {
  181675. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181676. if (taskBarIcon == 0)
  181677. {
  181678. taskBarIcon = new NOTIFYICONDATA();
  181679. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181680. taskBarIcon->hWnd = (HWND) hwnd;
  181681. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181682. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181683. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181684. taskBarIcon->hIcon = hicon;
  181685. taskBarIcon->szTip[0] = 0;
  181686. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181687. }
  181688. else
  181689. {
  181690. HICON oldIcon = taskBarIcon->hIcon;
  181691. taskBarIcon->hIcon = hicon;
  181692. taskBarIcon->uFlags = NIF_ICON;
  181693. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181694. DestroyIcon (oldIcon);
  181695. }
  181696. DestroyIcon (hicon);
  181697. }
  181698. else if (taskBarIcon != 0)
  181699. {
  181700. taskBarIcon->uFlags = 0;
  181701. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181702. DestroyIcon (taskBarIcon->hIcon);
  181703. deleteAndZero (taskBarIcon);
  181704. }
  181705. }
  181706. void setTaskBarIconToolTip (const String& toolTip) const
  181707. {
  181708. if (taskBarIcon != 0)
  181709. {
  181710. taskBarIcon->uFlags = NIF_TIP;
  181711. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181712. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181713. }
  181714. }
  181715. bool isInside (HWND h) const
  181716. {
  181717. return GetAncestor (hwnd, GA_ROOT) == h;
  181718. }
  181719. static void updateKeyModifiers() throw()
  181720. {
  181721. int keyMods = 0;
  181722. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181723. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181724. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181725. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181726. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181727. }
  181728. static void updateModifiersFromWParam (const WPARAM wParam)
  181729. {
  181730. int mouseMods = 0;
  181731. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181732. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181733. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181734. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181735. updateKeyModifiers();
  181736. }
  181737. static int64 getMouseEventTime()
  181738. {
  181739. static int64 eventTimeOffset = 0;
  181740. static DWORD lastMessageTime = 0;
  181741. const DWORD thisMessageTime = GetMessageTime();
  181742. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181743. {
  181744. lastMessageTime = thisMessageTime;
  181745. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181746. }
  181747. return eventTimeOffset + thisMessageTime;
  181748. }
  181749. juce_UseDebuggingNewOperator
  181750. bool dontRepaint;
  181751. static ModifierKeys currentModifiers;
  181752. static ModifierKeys modifiersAtLastCallback;
  181753. private:
  181754. HWND hwnd;
  181755. DropShadower* shadower;
  181756. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181757. BorderSize windowBorder;
  181758. HICON currentWindowIcon;
  181759. NOTIFYICONDATA* taskBarIcon;
  181760. IDropTarget* dropTarget;
  181761. class TemporaryImage : public Timer
  181762. {
  181763. public:
  181764. TemporaryImage()
  181765. : image (0)
  181766. {
  181767. }
  181768. ~TemporaryImage()
  181769. {
  181770. delete image;
  181771. }
  181772. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181773. {
  181774. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181775. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181776. {
  181777. delete image;
  181778. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181779. }
  181780. startTimer (3000);
  181781. return image;
  181782. }
  181783. void timerCallback()
  181784. {
  181785. stopTimer();
  181786. deleteAndZero (image);
  181787. }
  181788. private:
  181789. WindowsBitmapImage* image;
  181790. TemporaryImage (const TemporaryImage&);
  181791. TemporaryImage& operator= (const TemporaryImage&);
  181792. };
  181793. TemporaryImage offscreenImageGenerator;
  181794. class WindowClassHolder : public DeletedAtShutdown
  181795. {
  181796. public:
  181797. WindowClassHolder()
  181798. : windowClassName ("JUCE_")
  181799. {
  181800. // this name has to be different for each app/dll instance because otherwise
  181801. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181802. // window class).
  181803. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181804. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181805. TCHAR moduleFile [1024];
  181806. moduleFile[0] = 0;
  181807. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181808. WORD iconNum = 0;
  181809. WNDCLASSEX wcex;
  181810. wcex.cbSize = sizeof (wcex);
  181811. wcex.style = CS_OWNDC;
  181812. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181813. wcex.lpszClassName = windowClassName;
  181814. wcex.cbClsExtra = 0;
  181815. wcex.cbWndExtra = 32;
  181816. wcex.hInstance = moduleHandle;
  181817. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181818. iconNum = 1;
  181819. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181820. wcex.hCursor = 0;
  181821. wcex.hbrBackground = 0;
  181822. wcex.lpszMenuName = 0;
  181823. RegisterClassEx (&wcex);
  181824. }
  181825. ~WindowClassHolder()
  181826. {
  181827. if (ComponentPeer::getNumPeers() == 0)
  181828. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181829. clearSingletonInstance();
  181830. }
  181831. String windowClassName;
  181832. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181833. };
  181834. static void* createWindowCallback (void* userData)
  181835. {
  181836. static_cast <Win32ComponentPeer*> (userData)->createWindow();
  181837. return 0;
  181838. }
  181839. void createWindow()
  181840. {
  181841. DWORD exstyle = WS_EX_ACCEPTFILES;
  181842. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181843. if (hasTitleBar())
  181844. {
  181845. type |= WS_OVERLAPPED;
  181846. exstyle |= WS_EX_APPWINDOW;
  181847. if ((styleFlags & windowHasCloseButton) != 0)
  181848. {
  181849. type |= WS_SYSMENU;
  181850. }
  181851. else
  181852. {
  181853. // annoyingly, windows won't let you have a min/max button without a close button
  181854. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181855. }
  181856. if ((styleFlags & windowIsResizable) != 0)
  181857. type |= WS_THICKFRAME;
  181858. }
  181859. else
  181860. {
  181861. type |= WS_POPUP | WS_SYSMENU;
  181862. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181863. exstyle |= WS_EX_TOOLWINDOW;
  181864. else
  181865. exstyle |= WS_EX_APPWINDOW;
  181866. }
  181867. if ((styleFlags & windowHasMinimiseButton) != 0)
  181868. type |= WS_MINIMIZEBOX;
  181869. if ((styleFlags & windowHasMaximiseButton) != 0)
  181870. type |= WS_MAXIMIZEBOX;
  181871. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181872. exstyle |= WS_EX_TRANSPARENT;
  181873. if ((styleFlags & windowIsSemiTransparent) != 0
  181874. && Desktop::canUseSemiTransparentWindows())
  181875. exstyle |= WS_EX_LAYERED;
  181876. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181877. if (hwnd != 0)
  181878. {
  181879. SetWindowLongPtr (hwnd, 0, 0);
  181880. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181881. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181882. if (dropTarget == 0)
  181883. dropTarget = new JuceDropTarget (this);
  181884. RegisterDragDrop (hwnd, dropTarget);
  181885. updateBorderSize();
  181886. // Calling this function here is (for some reason) necessary to make Windows
  181887. // correctly enable the menu items that we specify in the wm_initmenu message.
  181888. GetSystemMenu (hwnd, false);
  181889. }
  181890. else
  181891. {
  181892. jassertfalse
  181893. }
  181894. }
  181895. static void* destroyWindowCallback (void* handle)
  181896. {
  181897. RevokeDragDrop ((HWND) handle);
  181898. DestroyWindow ((HWND) handle);
  181899. return 0;
  181900. }
  181901. static void* toFrontCallback1 (void* h)
  181902. {
  181903. SetForegroundWindow ((HWND) h);
  181904. return 0;
  181905. }
  181906. static void* toFrontCallback2 (void* h)
  181907. {
  181908. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181909. return 0;
  181910. }
  181911. static void* setFocusCallback (void* h)
  181912. {
  181913. SetFocus ((HWND) h);
  181914. return 0;
  181915. }
  181916. static void* getFocusCallback (void*)
  181917. {
  181918. return GetFocus();
  181919. }
  181920. void offsetWithinParent (int& x, int& y) const
  181921. {
  181922. if (isTransparent())
  181923. {
  181924. HWND parentHwnd = GetParent (hwnd);
  181925. if (parentHwnd != 0)
  181926. {
  181927. RECT parentRect;
  181928. GetWindowRect (parentHwnd, &parentRect);
  181929. x += parentRect.left;
  181930. y += parentRect.top;
  181931. }
  181932. }
  181933. }
  181934. bool isTransparent() const
  181935. {
  181936. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  181937. }
  181938. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  181939. void setIcon (const Image& newIcon)
  181940. {
  181941. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  181942. if (hicon != 0)
  181943. {
  181944. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  181945. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  181946. if (currentWindowIcon != 0)
  181947. DestroyIcon (currentWindowIcon);
  181948. currentWindowIcon = hicon;
  181949. }
  181950. }
  181951. void handlePaintMessage()
  181952. {
  181953. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  181954. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  181955. PAINTSTRUCT paintStruct;
  181956. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  181957. // message and become re-entrant, but that's OK
  181958. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  181959. // corrupt the image it's using to paint into, so do a check here.
  181960. static bool reentrant = false;
  181961. if (reentrant)
  181962. {
  181963. DeleteObject (rgn);
  181964. EndPaint (hwnd, &paintStruct);
  181965. return;
  181966. }
  181967. reentrant = true;
  181968. // this is the rectangle to update..
  181969. int x = paintStruct.rcPaint.left;
  181970. int y = paintStruct.rcPaint.top;
  181971. int w = paintStruct.rcPaint.right - x;
  181972. int h = paintStruct.rcPaint.bottom - y;
  181973. const bool transparent = isTransparent();
  181974. if (transparent)
  181975. {
  181976. // it's not possible to have a transparent window with a title bar at the moment!
  181977. jassert (! hasTitleBar());
  181978. RECT r;
  181979. GetWindowRect (hwnd, &r);
  181980. x = y = 0;
  181981. w = r.right - r.left;
  181982. h = r.bottom - r.top;
  181983. }
  181984. if (w > 0 && h > 0)
  181985. {
  181986. clearMaskedRegion();
  181987. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  181988. RectangleList contextClip;
  181989. bool needToPaintAll = true;
  181990. if (regionType == COMPLEXREGION && ! transparent)
  181991. {
  181992. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  181993. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  181994. DeleteObject (clipRgn);
  181995. char rgnData [8192];
  181996. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  181997. if (res > 0 && res <= sizeof (rgnData))
  181998. {
  181999. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182000. if (hdr->iType == RDH_RECTANGLES
  182001. && hdr->rcBound.right - hdr->rcBound.left >= w
  182002. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182003. {
  182004. needToPaintAll = false;
  182005. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182006. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182007. while (--num >= 0)
  182008. {
  182009. // (need to move this one pixel to the left because of a win32 bug)
  182010. const int cx = jmax (x, (int) rects->left - 1);
  182011. const int cy = rects->top;
  182012. const int cw = rects->right - cx;
  182013. const int ch = rects->bottom - rects->top;
  182014. if (cx + cw - x <= w && cy + ch - y <= h)
  182015. {
  182016. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182017. }
  182018. else
  182019. {
  182020. needToPaintAll = true;
  182021. break;
  182022. }
  182023. ++rects;
  182024. }
  182025. }
  182026. }
  182027. }
  182028. if (needToPaintAll)
  182029. {
  182030. contextClip.clear();
  182031. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182032. }
  182033. if (transparent)
  182034. {
  182035. RectangleList::Iterator i (contextClip);
  182036. while (i.next())
  182037. {
  182038. const Rectangle<int>& r = *i.getRectangle();
  182039. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182040. }
  182041. }
  182042. // if the component's not opaque, this won't draw properly unless the platform can support this
  182043. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182044. updateCurrentModifiers();
  182045. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182046. context.clipToRectangleList (contextClip);
  182047. context.setOrigin (-x, -y);
  182048. handlePaint (context);
  182049. if (! dontRepaint)
  182050. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182051. }
  182052. DeleteObject (rgn);
  182053. EndPaint (hwnd, &paintStruct);
  182054. reentrant = false;
  182055. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182056. _fpreset(); // because some graphics cards can unmask FP exceptions
  182057. #endif
  182058. lastPaintTime = Time::getMillisecondCounter();
  182059. }
  182060. void doMouseEvent (const Point<int>& position)
  182061. {
  182062. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182063. }
  182064. void doMouseMove (const Point<int>& position)
  182065. {
  182066. if (! isMouseOver)
  182067. {
  182068. isMouseOver = true;
  182069. updateKeyModifiers();
  182070. TRACKMOUSEEVENT tme;
  182071. tme.cbSize = sizeof (tme);
  182072. tme.dwFlags = TME_LEAVE;
  182073. tme.hwndTrack = hwnd;
  182074. tme.dwHoverTime = 0;
  182075. if (! TrackMouseEvent (&tme))
  182076. jassertfalse;
  182077. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182078. }
  182079. else if (! isDragging)
  182080. {
  182081. if (! contains (position, false))
  182082. return;
  182083. }
  182084. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182085. static uint32 lastMouseTime = 0;
  182086. const uint32 now = Time::getMillisecondCounter();
  182087. const int maxMouseMovesPerSecond = 60;
  182088. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182089. {
  182090. lastMouseTime = now;
  182091. doMouseEvent (position);
  182092. }
  182093. }
  182094. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182095. {
  182096. if (GetCapture() != hwnd)
  182097. SetCapture (hwnd);
  182098. doMouseMove (position);
  182099. updateModifiersFromWParam (wParam);
  182100. isDragging = true;
  182101. doMouseEvent (position);
  182102. }
  182103. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182104. {
  182105. updateModifiersFromWParam (wParam);
  182106. isDragging = false;
  182107. // release the mouse capture if the user has released all buttons
  182108. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182109. ReleaseCapture();
  182110. doMouseEvent (position);
  182111. }
  182112. void doCaptureChanged()
  182113. {
  182114. if (isDragging)
  182115. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182116. }
  182117. void doMouseExit()
  182118. {
  182119. isMouseOver = false;
  182120. doMouseEvent (getCurrentMousePos());
  182121. }
  182122. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182123. {
  182124. updateKeyModifiers();
  182125. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182126. handleMouseWheel (0, position, getMouseEventTime(),
  182127. isVertical ? 0.0f : amount,
  182128. isVertical ? amount : 0.0f);
  182129. }
  182130. void sendModifierKeyChangeIfNeeded()
  182131. {
  182132. if (modifiersAtLastCallback != currentModifiers)
  182133. {
  182134. modifiersAtLastCallback = currentModifiers;
  182135. handleModifierKeysChange();
  182136. }
  182137. }
  182138. bool doKeyUp (const WPARAM key)
  182139. {
  182140. updateKeyModifiers();
  182141. switch (key)
  182142. {
  182143. case VK_SHIFT:
  182144. case VK_CONTROL:
  182145. case VK_MENU:
  182146. case VK_CAPITAL:
  182147. case VK_LWIN:
  182148. case VK_RWIN:
  182149. case VK_APPS:
  182150. case VK_NUMLOCK:
  182151. case VK_SCROLL:
  182152. case VK_LSHIFT:
  182153. case VK_RSHIFT:
  182154. case VK_LCONTROL:
  182155. case VK_LMENU:
  182156. case VK_RCONTROL:
  182157. case VK_RMENU:
  182158. sendModifierKeyChangeIfNeeded();
  182159. }
  182160. return handleKeyUpOrDown (false)
  182161. || Component::getCurrentlyModalComponent() != 0;
  182162. }
  182163. bool doKeyDown (const WPARAM key)
  182164. {
  182165. updateKeyModifiers();
  182166. bool used = false;
  182167. switch (key)
  182168. {
  182169. case VK_SHIFT:
  182170. case VK_LSHIFT:
  182171. case VK_RSHIFT:
  182172. case VK_CONTROL:
  182173. case VK_LCONTROL:
  182174. case VK_RCONTROL:
  182175. case VK_MENU:
  182176. case VK_LMENU:
  182177. case VK_RMENU:
  182178. case VK_LWIN:
  182179. case VK_RWIN:
  182180. case VK_CAPITAL:
  182181. case VK_NUMLOCK:
  182182. case VK_SCROLL:
  182183. case VK_APPS:
  182184. sendModifierKeyChangeIfNeeded();
  182185. break;
  182186. case VK_LEFT:
  182187. case VK_RIGHT:
  182188. case VK_UP:
  182189. case VK_DOWN:
  182190. case VK_PRIOR:
  182191. case VK_NEXT:
  182192. case VK_HOME:
  182193. case VK_END:
  182194. case VK_DELETE:
  182195. case VK_INSERT:
  182196. case VK_F1:
  182197. case VK_F2:
  182198. case VK_F3:
  182199. case VK_F4:
  182200. case VK_F5:
  182201. case VK_F6:
  182202. case VK_F7:
  182203. case VK_F8:
  182204. case VK_F9:
  182205. case VK_F10:
  182206. case VK_F11:
  182207. case VK_F12:
  182208. case VK_F13:
  182209. case VK_F14:
  182210. case VK_F15:
  182211. case VK_F16:
  182212. used = handleKeyUpOrDown (true);
  182213. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182214. break;
  182215. case VK_ADD:
  182216. case VK_SUBTRACT:
  182217. case VK_MULTIPLY:
  182218. case VK_DIVIDE:
  182219. case VK_SEPARATOR:
  182220. case VK_DECIMAL:
  182221. used = handleKeyUpOrDown (true);
  182222. break;
  182223. default:
  182224. used = handleKeyUpOrDown (true);
  182225. {
  182226. MSG msg;
  182227. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182228. {
  182229. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182230. // manually generate the key-press event that matches this key-down.
  182231. const UINT keyChar = MapVirtualKey (key, 2);
  182232. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182233. }
  182234. }
  182235. break;
  182236. }
  182237. if (Component::getCurrentlyModalComponent() != 0)
  182238. used = true;
  182239. return used;
  182240. }
  182241. bool doKeyChar (int key, const LPARAM flags)
  182242. {
  182243. updateKeyModifiers();
  182244. juce_wchar textChar = (juce_wchar) key;
  182245. const int virtualScanCode = (flags >> 16) & 0xff;
  182246. if (key >= '0' && key <= '9')
  182247. {
  182248. switch (virtualScanCode) // check for a numeric keypad scan-code
  182249. {
  182250. case 0x52:
  182251. case 0x4f:
  182252. case 0x50:
  182253. case 0x51:
  182254. case 0x4b:
  182255. case 0x4c:
  182256. case 0x4d:
  182257. case 0x47:
  182258. case 0x48:
  182259. case 0x49:
  182260. key = (key - '0') + KeyPress::numberPad0;
  182261. break;
  182262. default:
  182263. break;
  182264. }
  182265. }
  182266. else
  182267. {
  182268. // convert the scan code to an unmodified character code..
  182269. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182270. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182271. keyChar = LOWORD (keyChar);
  182272. if (keyChar != 0)
  182273. key = (int) keyChar;
  182274. // avoid sending junk text characters for some control-key combinations
  182275. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182276. textChar = 0;
  182277. }
  182278. return handleKeyPress (key, textChar);
  182279. }
  182280. bool doAppCommand (const LPARAM lParam)
  182281. {
  182282. int key = 0;
  182283. switch (GET_APPCOMMAND_LPARAM (lParam))
  182284. {
  182285. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182286. key = KeyPress::playKey;
  182287. break;
  182288. case APPCOMMAND_MEDIA_STOP:
  182289. key = KeyPress::stopKey;
  182290. break;
  182291. case APPCOMMAND_MEDIA_NEXTTRACK:
  182292. key = KeyPress::fastForwardKey;
  182293. break;
  182294. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182295. key = KeyPress::rewindKey;
  182296. break;
  182297. }
  182298. if (key != 0)
  182299. {
  182300. updateKeyModifiers();
  182301. if (hwnd == GetActiveWindow())
  182302. {
  182303. handleKeyPress (key, 0);
  182304. return true;
  182305. }
  182306. }
  182307. return false;
  182308. }
  182309. class JuceDropTarget : public IDropTarget
  182310. {
  182311. public:
  182312. JuceDropTarget (Win32ComponentPeer* const owner_)
  182313. : owner (owner_),
  182314. refCount (1)
  182315. {
  182316. }
  182317. virtual ~JuceDropTarget()
  182318. {
  182319. jassert (refCount == 0);
  182320. }
  182321. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182322. {
  182323. if (id == IID_IUnknown || id == IID_IDropTarget)
  182324. {
  182325. AddRef();
  182326. *result = this;
  182327. return S_OK;
  182328. }
  182329. *result = 0;
  182330. return E_NOINTERFACE;
  182331. }
  182332. ULONG __stdcall AddRef() { return ++refCount; }
  182333. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182334. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182335. {
  182336. updateFileList (pDataObject);
  182337. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182338. *pdwEffect = DROPEFFECT_COPY;
  182339. return S_OK;
  182340. }
  182341. HRESULT __stdcall DragLeave()
  182342. {
  182343. owner->handleFileDragExit (files);
  182344. return S_OK;
  182345. }
  182346. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182347. {
  182348. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182349. *pdwEffect = DROPEFFECT_COPY;
  182350. return S_OK;
  182351. }
  182352. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182353. {
  182354. updateFileList (pDataObject);
  182355. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182356. *pdwEffect = DROPEFFECT_COPY;
  182357. return S_OK;
  182358. }
  182359. private:
  182360. Win32ComponentPeer* const owner;
  182361. int refCount;
  182362. StringArray files;
  182363. void updateFileList (IDataObject* const pDataObject)
  182364. {
  182365. files.clear();
  182366. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182367. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182368. if (pDataObject->GetData (&format, &medium) == S_OK)
  182369. {
  182370. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182371. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182372. unsigned int i = 0;
  182373. if (pDropFiles->fWide)
  182374. {
  182375. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182376. for (;;)
  182377. {
  182378. unsigned int len = 0;
  182379. while (i + len < totalLen && fname [i + len] != 0)
  182380. ++len;
  182381. if (len == 0)
  182382. break;
  182383. files.add (String (fname + i, len));
  182384. i += len + 1;
  182385. }
  182386. }
  182387. else
  182388. {
  182389. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182390. for (;;)
  182391. {
  182392. unsigned int len = 0;
  182393. while (i + len < totalLen && fname [i + len] != 0)
  182394. ++len;
  182395. if (len == 0)
  182396. break;
  182397. files.add (String (fname + i, len));
  182398. i += len + 1;
  182399. }
  182400. }
  182401. GlobalUnlock (medium.hGlobal);
  182402. }
  182403. }
  182404. JuceDropTarget (const JuceDropTarget&);
  182405. JuceDropTarget& operator= (const JuceDropTarget&);
  182406. };
  182407. void doSettingChange()
  182408. {
  182409. Desktop::getInstance().refreshMonitorSizes();
  182410. if (fullScreen && ! isMinimised())
  182411. {
  182412. const Rectangle<int> r (component->getParentMonitorArea());
  182413. SetWindowPos (hwnd, 0,
  182414. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182415. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182416. }
  182417. }
  182418. public:
  182419. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182420. {
  182421. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182422. if (peer != 0)
  182423. return peer->peerWindowProc (h, message, wParam, lParam);
  182424. return DefWindowProcW (h, message, wParam, lParam);
  182425. }
  182426. private:
  182427. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182428. {
  182429. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182430. }
  182431. const Point<int> getCurrentMousePos() throw()
  182432. {
  182433. RECT wr;
  182434. GetWindowRect (hwnd, &wr);
  182435. const DWORD mp = GetMessagePos();
  182436. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182437. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182438. }
  182439. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182440. {
  182441. if (isValidPeer (this))
  182442. {
  182443. switch (message)
  182444. {
  182445. case WM_NCHITTEST:
  182446. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182447. return HTTRANSPARENT;
  182448. if (hasTitleBar())
  182449. break;
  182450. return HTCLIENT;
  182451. case WM_PAINT:
  182452. handlePaintMessage();
  182453. return 0;
  182454. case WM_NCPAINT:
  182455. if (wParam != 1)
  182456. handlePaintMessage();
  182457. if (hasTitleBar())
  182458. break;
  182459. return 0;
  182460. case WM_ERASEBKGND:
  182461. case WM_NCCALCSIZE:
  182462. if (hasTitleBar())
  182463. break;
  182464. return 1;
  182465. case WM_MOUSEMOVE:
  182466. doMouseMove (getPointFromLParam (lParam));
  182467. return 0;
  182468. case WM_MOUSELEAVE:
  182469. doMouseExit();
  182470. return 0;
  182471. case WM_LBUTTONDOWN:
  182472. case WM_MBUTTONDOWN:
  182473. case WM_RBUTTONDOWN:
  182474. doMouseDown (getPointFromLParam (lParam), wParam);
  182475. return 0;
  182476. case WM_LBUTTONUP:
  182477. case WM_MBUTTONUP:
  182478. case WM_RBUTTONUP:
  182479. doMouseUp (getPointFromLParam (lParam), wParam);
  182480. return 0;
  182481. case WM_CAPTURECHANGED:
  182482. doCaptureChanged();
  182483. return 0;
  182484. case WM_NCMOUSEMOVE:
  182485. if (hasTitleBar())
  182486. break;
  182487. return 0;
  182488. case 0x020A: /* WM_MOUSEWHEEL */
  182489. doMouseWheel (getCurrentMousePos(), wParam, true);
  182490. return 0;
  182491. case 0x020E: /* WM_MOUSEHWHEEL */
  182492. doMouseWheel (getCurrentMousePos(), wParam, false);
  182493. return 0;
  182494. case WM_WINDOWPOSCHANGING:
  182495. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182496. {
  182497. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182498. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182499. {
  182500. if (constrainer != 0)
  182501. {
  182502. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182503. component->getY() - windowBorder.getTop(),
  182504. component->getWidth() + windowBorder.getLeftAndRight(),
  182505. component->getHeight() + windowBorder.getTopAndBottom());
  182506. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182507. constrainer->checkBounds (pos, current,
  182508. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182509. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182510. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182511. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182512. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182513. wp->x = pos.getX();
  182514. wp->y = pos.getY();
  182515. wp->cx = pos.getWidth();
  182516. wp->cy = pos.getHeight();
  182517. }
  182518. }
  182519. }
  182520. return 0;
  182521. case WM_WINDOWPOSCHANGED:
  182522. handleMovedOrResized();
  182523. if (dontRepaint)
  182524. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182525. return 0;
  182526. case WM_KEYDOWN:
  182527. case WM_SYSKEYDOWN:
  182528. if (doKeyDown (wParam))
  182529. return 0;
  182530. break;
  182531. case WM_KEYUP:
  182532. case WM_SYSKEYUP:
  182533. if (doKeyUp (wParam))
  182534. return 0;
  182535. break;
  182536. case WM_CHAR:
  182537. if (doKeyChar ((int) wParam, lParam))
  182538. return 0;
  182539. break;
  182540. case WM_APPCOMMAND:
  182541. if (doAppCommand (lParam))
  182542. return TRUE;
  182543. break;
  182544. case WM_SETFOCUS:
  182545. updateKeyModifiers();
  182546. handleFocusGain();
  182547. break;
  182548. case WM_KILLFOCUS:
  182549. if (hasCreatedCaret)
  182550. {
  182551. hasCreatedCaret = false;
  182552. DestroyCaret();
  182553. }
  182554. handleFocusLoss();
  182555. break;
  182556. case WM_ACTIVATEAPP:
  182557. // Windows does weird things to process priority when you swap apps,
  182558. // so this forces an update when the app is brought to the front
  182559. if (wParam != FALSE)
  182560. juce_repeatLastProcessPriority();
  182561. else
  182562. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182563. juce_CheckCurrentlyFocusedTopLevelWindow();
  182564. modifiersAtLastCallback = -1;
  182565. return 0;
  182566. case WM_ACTIVATE:
  182567. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182568. {
  182569. modifiersAtLastCallback = -1;
  182570. updateKeyModifiers();
  182571. if (isMinimised())
  182572. {
  182573. component->repaint();
  182574. handleMovedOrResized();
  182575. if (! ComponentPeer::isValidPeer (this))
  182576. return 0;
  182577. }
  182578. if (LOWORD (wParam) == WA_CLICKACTIVE
  182579. && component->isCurrentlyBlockedByAnotherModalComponent())
  182580. {
  182581. const Point<int> mousePos (component->getMouseXYRelative());
  182582. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182583. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182584. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182585. return 0;
  182586. }
  182587. handleBroughtToFront();
  182588. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182589. Component::getCurrentlyModalComponent()->toFront (true);
  182590. return 0;
  182591. }
  182592. break;
  182593. case WM_NCACTIVATE:
  182594. // while a temporary window is being shown, prevent Windows from deactivating the
  182595. // title bars of our main windows.
  182596. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182597. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182598. break;
  182599. case WM_MOUSEACTIVATE:
  182600. if (! component->getMouseClickGrabsKeyboardFocus())
  182601. return MA_NOACTIVATE;
  182602. break;
  182603. case WM_SHOWWINDOW:
  182604. if (wParam != 0)
  182605. handleBroughtToFront();
  182606. break;
  182607. case WM_CLOSE:
  182608. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182609. handleUserClosingWindow();
  182610. return 0;
  182611. case WM_QUERYENDSESSION:
  182612. if (JUCEApplication::getInstance() != 0)
  182613. {
  182614. JUCEApplication::getInstance()->systemRequestedQuit();
  182615. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182616. }
  182617. return TRUE;
  182618. case WM_TRAYNOTIFY:
  182619. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182620. {
  182621. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182622. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182623. {
  182624. Component* const current = Component::getCurrentlyModalComponent();
  182625. if (current != 0)
  182626. current->inputAttemptWhenModal();
  182627. }
  182628. }
  182629. else
  182630. {
  182631. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182632. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182633. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182634. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182635. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182636. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182637. eventMods = eventMods.withoutMouseButtons();
  182638. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182639. Point<int>(), eventMods, component, getMouseEventTime(),
  182640. Point<int>(), getMouseEventTime(), 1, false);
  182641. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182642. {
  182643. SetFocus (hwnd);
  182644. SetForegroundWindow (hwnd);
  182645. component->mouseDown (e);
  182646. }
  182647. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182648. {
  182649. component->mouseUp (e);
  182650. }
  182651. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182652. {
  182653. component->mouseDoubleClick (e);
  182654. }
  182655. else if (lParam == WM_MOUSEMOVE)
  182656. {
  182657. component->mouseMove (e);
  182658. }
  182659. }
  182660. break;
  182661. case WM_SYNCPAINT:
  182662. return 0;
  182663. case WM_PALETTECHANGED:
  182664. InvalidateRect (h, 0, 0);
  182665. break;
  182666. case WM_DISPLAYCHANGE:
  182667. InvalidateRect (h, 0, 0);
  182668. createPaletteIfNeeded = true;
  182669. // intentional fall-through...
  182670. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182671. doSettingChange();
  182672. break;
  182673. case WM_INITMENU:
  182674. if (! hasTitleBar())
  182675. {
  182676. if (isFullScreen())
  182677. {
  182678. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182679. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182680. }
  182681. else if (! isMinimised())
  182682. {
  182683. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182684. }
  182685. }
  182686. break;
  182687. case WM_SYSCOMMAND:
  182688. switch (wParam & 0xfff0)
  182689. {
  182690. case SC_CLOSE:
  182691. if (sendInputAttemptWhenModalMessage())
  182692. return 0;
  182693. if (hasTitleBar())
  182694. {
  182695. PostMessage (h, WM_CLOSE, 0, 0);
  182696. return 0;
  182697. }
  182698. break;
  182699. case SC_KEYMENU:
  182700. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182701. // obscure situations that can arise if a modal loop is started from an alt-key
  182702. // keypress).
  182703. if (hasTitleBar() && h == GetCapture())
  182704. ReleaseCapture();
  182705. break;
  182706. case SC_MAXIMIZE:
  182707. if (sendInputAttemptWhenModalMessage())
  182708. return 0;
  182709. setFullScreen (true);
  182710. return 0;
  182711. case SC_MINIMIZE:
  182712. if (sendInputAttemptWhenModalMessage())
  182713. return 0;
  182714. if (! hasTitleBar())
  182715. {
  182716. setMinimised (true);
  182717. return 0;
  182718. }
  182719. break;
  182720. case SC_RESTORE:
  182721. if (sendInputAttemptWhenModalMessage())
  182722. return 0;
  182723. if (hasTitleBar())
  182724. {
  182725. if (isFullScreen())
  182726. {
  182727. setFullScreen (false);
  182728. return 0;
  182729. }
  182730. }
  182731. else
  182732. {
  182733. if (isMinimised())
  182734. setMinimised (false);
  182735. else if (isFullScreen())
  182736. setFullScreen (false);
  182737. return 0;
  182738. }
  182739. break;
  182740. }
  182741. break;
  182742. case WM_NCLBUTTONDOWN:
  182743. case WM_NCRBUTTONDOWN:
  182744. case WM_NCMBUTTONDOWN:
  182745. sendInputAttemptWhenModalMessage();
  182746. break;
  182747. //case WM_IME_STARTCOMPOSITION;
  182748. // return 0;
  182749. case WM_GETDLGCODE:
  182750. return DLGC_WANTALLKEYS;
  182751. default:
  182752. break;
  182753. }
  182754. }
  182755. return DefWindowProcW (h, message, wParam, lParam);
  182756. }
  182757. bool sendInputAttemptWhenModalMessage()
  182758. {
  182759. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182760. {
  182761. Component* const current = Component::getCurrentlyModalComponent();
  182762. if (current != 0)
  182763. current->inputAttemptWhenModal();
  182764. return true;
  182765. }
  182766. return false;
  182767. }
  182768. Win32ComponentPeer (const Win32ComponentPeer&);
  182769. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182770. };
  182771. ModifierKeys Win32ComponentPeer::currentModifiers;
  182772. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182773. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182774. {
  182775. return new Win32ComponentPeer (this, styleFlags);
  182776. }
  182777. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182778. void ModifierKeys::updateCurrentModifiers() throw()
  182779. {
  182780. currentModifiers = Win32ComponentPeer::currentModifiers;
  182781. }
  182782. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182783. {
  182784. Win32ComponentPeer::updateKeyModifiers();
  182785. int keyMods = 0;
  182786. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182787. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182788. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182789. Win32ComponentPeer::currentModifiers
  182790. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182791. return Win32ComponentPeer::currentModifiers;
  182792. }
  182793. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182794. {
  182795. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182796. if (wp != 0)
  182797. wp->setTaskBarIcon (&newImage);
  182798. }
  182799. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182800. {
  182801. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182802. if (wp != 0)
  182803. wp->setTaskBarIconToolTip (tooltip);
  182804. }
  182805. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182806. {
  182807. DWORD val = GetWindowLong (h, styleType);
  182808. if (bitIsSet)
  182809. val |= feature;
  182810. else
  182811. val &= ~feature;
  182812. SetWindowLongPtr (h, styleType, val);
  182813. SetWindowPos (h, 0, 0, 0, 0, 0,
  182814. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182815. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182816. }
  182817. bool Process::isForegroundProcess()
  182818. {
  182819. HWND fg = GetForegroundWindow();
  182820. if (fg == 0)
  182821. return true;
  182822. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182823. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182824. // have to see if any of our windows are children of the foreground window
  182825. fg = GetAncestor (fg, GA_ROOT);
  182826. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182827. {
  182828. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182829. if (wp != 0 && wp->isInside (fg))
  182830. return true;
  182831. }
  182832. return false;
  182833. }
  182834. bool AlertWindow::showNativeDialogBox (const String& title,
  182835. const String& bodyText,
  182836. bool isOkCancel)
  182837. {
  182838. return MessageBox (0, bodyText, title,
  182839. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182840. : MB_OK)) == IDOK;
  182841. }
  182842. void Desktop::createMouseInputSources()
  182843. {
  182844. mouseSources.add (new MouseInputSource (0, true));
  182845. }
  182846. const Point<int> Desktop::getMousePosition()
  182847. {
  182848. POINT mousePos;
  182849. GetCursorPos (&mousePos);
  182850. return Point<int> (mousePos.x, mousePos.y);
  182851. }
  182852. void Desktop::setMousePosition (const Point<int>& newPosition)
  182853. {
  182854. SetCursorPos (newPosition.getX(), newPosition.getY());
  182855. }
  182856. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182857. {
  182858. return new Image (format, imageWidth, imageHeight, clearImage);
  182859. }
  182860. class ScreenSaverDefeater : public Timer,
  182861. public DeletedAtShutdown
  182862. {
  182863. public:
  182864. ScreenSaverDefeater() throw()
  182865. {
  182866. startTimer (10000);
  182867. timerCallback();
  182868. }
  182869. ~ScreenSaverDefeater() {}
  182870. void timerCallback()
  182871. {
  182872. if (Process::isForegroundProcess())
  182873. {
  182874. // simulate a shift key getting pressed..
  182875. INPUT input[2];
  182876. input[0].type = INPUT_KEYBOARD;
  182877. input[0].ki.wVk = VK_SHIFT;
  182878. input[0].ki.dwFlags = 0;
  182879. input[0].ki.dwExtraInfo = 0;
  182880. input[1].type = INPUT_KEYBOARD;
  182881. input[1].ki.wVk = VK_SHIFT;
  182882. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182883. input[1].ki.dwExtraInfo = 0;
  182884. SendInput (2, input, sizeof (INPUT));
  182885. }
  182886. }
  182887. };
  182888. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182889. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182890. {
  182891. if (isEnabled)
  182892. {
  182893. deleteAndZero (screenSaverDefeater);
  182894. }
  182895. else if (screenSaverDefeater == 0)
  182896. {
  182897. screenSaverDefeater = new ScreenSaverDefeater();
  182898. }
  182899. }
  182900. bool Desktop::isScreenSaverEnabled() throw()
  182901. {
  182902. return screenSaverDefeater == 0;
  182903. }
  182904. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182905. {
  182906. if (enableOrDisable)
  182907. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182908. }
  182909. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182910. {
  182911. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182912. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182913. return TRUE;
  182914. }
  182915. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182916. {
  182917. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182918. // make sure the first in the list is the main monitor
  182919. for (int i = 1; i < monitorCoords.size(); ++i)
  182920. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182921. monitorCoords.swap (i, 0);
  182922. if (monitorCoords.size() == 0)
  182923. {
  182924. RECT r;
  182925. GetWindowRect (GetDesktopWindow(), &r);
  182926. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182927. }
  182928. if (clipToWorkArea)
  182929. {
  182930. // clip the main monitor to the active non-taskbar area
  182931. RECT r;
  182932. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  182933. Rectangle<int>& screen = monitorCoords.getReference (0);
  182934. screen.setPosition (jmax (screen.getX(), (int) r.left),
  182935. jmax (screen.getY(), (int) r.top));
  182936. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  182937. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  182938. }
  182939. }
  182940. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  182941. {
  182942. Image* im = 0;
  182943. if (bitmap != 0)
  182944. {
  182945. BITMAP bm;
  182946. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  182947. && bm.bmWidth > 0 && bm.bmHeight > 0)
  182948. {
  182949. HDC tempDC = GetDC (0);
  182950. HDC dc = CreateCompatibleDC (tempDC);
  182951. ReleaseDC (0, tempDC);
  182952. SelectObject (dc, bitmap);
  182953. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  182954. for (int y = bm.bmHeight; --y >= 0;)
  182955. {
  182956. for (int x = bm.bmWidth; --x >= 0;)
  182957. {
  182958. COLORREF col = GetPixel (dc, x, y);
  182959. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  182960. (uint8) GetGValue (col),
  182961. (uint8) GetBValue (col)));
  182962. }
  182963. }
  182964. DeleteDC (dc);
  182965. }
  182966. }
  182967. return im;
  182968. }
  182969. static Image* createImageFromHICON (HICON icon) throw()
  182970. {
  182971. ICONINFO info;
  182972. if (GetIconInfo (icon, &info))
  182973. {
  182974. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  182975. if (mask == 0)
  182976. return 0;
  182977. Image* const image = createImageFromHBITMAP (info.hbmColor);
  182978. if (image == 0)
  182979. return mask;
  182980. for (int y = image->getHeight(); --y >= 0;)
  182981. {
  182982. for (int x = image->getWidth(); --x >= 0;)
  182983. {
  182984. const float brightness = mask->getPixelAt (x, y).getBrightness();
  182985. if (brightness > 0.0f)
  182986. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  182987. }
  182988. }
  182989. delete mask;
  182990. return image;
  182991. }
  182992. return 0;
  182993. }
  182994. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  182995. {
  182996. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  182997. ICONINFO info;
  182998. info.fIcon = isIcon;
  182999. info.xHotspot = hotspotX;
  183000. info.yHotspot = hotspotY;
  183001. info.hbmMask = mask;
  183002. HICON hi = 0;
  183003. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183004. {
  183005. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183006. Graphics g (bitmap);
  183007. g.drawImageAt (&image, 0, 0);
  183008. info.hbmColor = bitmap.hBitmap;
  183009. hi = CreateIconIndirect (&info);
  183010. }
  183011. else
  183012. {
  183013. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183014. HDC colDC = CreateCompatibleDC (GetDC (0));
  183015. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183016. SelectObject (colDC, colour);
  183017. SelectObject (alphaDC, mask);
  183018. for (int y = image.getHeight(); --y >= 0;)
  183019. {
  183020. for (int x = image.getWidth(); --x >= 0;)
  183021. {
  183022. const Colour c (image.getPixelAt (x, y));
  183023. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183024. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183025. }
  183026. }
  183027. DeleteDC (colDC);
  183028. DeleteDC (alphaDC);
  183029. info.hbmColor = colour;
  183030. hi = CreateIconIndirect (&info);
  183031. DeleteObject (colour);
  183032. }
  183033. DeleteObject (mask);
  183034. return hi;
  183035. }
  183036. Image* juce_createIconForFile (const File& file)
  183037. {
  183038. Image* image = 0;
  183039. WCHAR filename [1024];
  183040. file.getFullPathName().copyToUnicode (filename, 1023);
  183041. WORD iconNum = 0;
  183042. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183043. filename, &iconNum);
  183044. if (icon != 0)
  183045. {
  183046. image = createImageFromHICON (icon);
  183047. DestroyIcon (icon);
  183048. }
  183049. return image;
  183050. }
  183051. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  183052. {
  183053. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183054. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183055. const Image* im = &image;
  183056. Image* newIm = 0;
  183057. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183058. {
  183059. im = newIm = image.createCopy (maxW, maxH);
  183060. hotspotX = (hotspotX * maxW) / image.getWidth();
  183061. hotspotY = (hotspotY * maxH) / image.getHeight();
  183062. }
  183063. void* cursorH = 0;
  183064. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183065. if (os == SystemStats::WinXP)
  183066. {
  183067. cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183068. }
  183069. else
  183070. {
  183071. const int stride = (maxW + 7) >> 3;
  183072. HeapBlock <uint8> andPlane, xorPlane;
  183073. andPlane.calloc (stride * maxH);
  183074. xorPlane.calloc (stride * maxH);
  183075. int index = 0;
  183076. for (int y = 0; y < maxH; ++y)
  183077. {
  183078. for (int x = 0; x < maxW; ++x)
  183079. {
  183080. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183081. const Colour pixelColour (im->getPixelAt (x, y));
  183082. if (pixelColour.getAlpha() < 127)
  183083. andPlane [index + (x >> 3)] |= bit;
  183084. else if (pixelColour.getBrightness() >= 0.5f)
  183085. xorPlane [index + (x >> 3)] |= bit;
  183086. }
  183087. index += stride;
  183088. }
  183089. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183090. }
  183091. delete newIm;
  183092. return cursorH;
  183093. }
  183094. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  183095. {
  183096. if (cursorHandle != 0 && ! isStandard)
  183097. DestroyCursor ((HCURSOR) cursorHandle);
  183098. }
  183099. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  183100. {
  183101. LPCTSTR cursorName = IDC_ARROW;
  183102. switch (type)
  183103. {
  183104. case MouseCursor::NormalCursor:
  183105. cursorName = IDC_ARROW;
  183106. break;
  183107. case MouseCursor::NoCursor:
  183108. return 0;
  183109. case MouseCursor::DraggingHandCursor:
  183110. {
  183111. static void* dragHandCursor = 0;
  183112. if (dragHandCursor == 0)
  183113. {
  183114. static const unsigned char dragHandData[] =
  183115. { 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,
  183116. 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,
  183117. 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 };
  183118. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183119. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183120. }
  183121. return dragHandCursor;
  183122. }
  183123. case MouseCursor::WaitCursor:
  183124. cursorName = IDC_WAIT;
  183125. break;
  183126. case MouseCursor::IBeamCursor:
  183127. cursorName = IDC_IBEAM;
  183128. break;
  183129. case MouseCursor::PointingHandCursor:
  183130. cursorName = MAKEINTRESOURCE(32649);
  183131. break;
  183132. case MouseCursor::LeftRightResizeCursor:
  183133. case MouseCursor::LeftEdgeResizeCursor:
  183134. case MouseCursor::RightEdgeResizeCursor:
  183135. cursorName = IDC_SIZEWE;
  183136. break;
  183137. case MouseCursor::UpDownResizeCursor:
  183138. case MouseCursor::TopEdgeResizeCursor:
  183139. case MouseCursor::BottomEdgeResizeCursor:
  183140. cursorName = IDC_SIZENS;
  183141. break;
  183142. case MouseCursor::TopLeftCornerResizeCursor:
  183143. case MouseCursor::BottomRightCornerResizeCursor:
  183144. cursorName = IDC_SIZENWSE;
  183145. break;
  183146. case MouseCursor::TopRightCornerResizeCursor:
  183147. case MouseCursor::BottomLeftCornerResizeCursor:
  183148. cursorName = IDC_SIZENESW;
  183149. break;
  183150. case MouseCursor::UpDownLeftRightResizeCursor:
  183151. cursorName = IDC_SIZEALL;
  183152. break;
  183153. case MouseCursor::CrosshairCursor:
  183154. cursorName = IDC_CROSS;
  183155. break;
  183156. case MouseCursor::CopyingCursor:
  183157. // can't seem to find one of these in the win32 list..
  183158. break;
  183159. }
  183160. HCURSOR cursorH = LoadCursor (0, cursorName);
  183161. if (cursorH == 0)
  183162. cursorH = LoadCursor (0, IDC_ARROW);
  183163. return cursorH;
  183164. }
  183165. void MouseCursor::showInWindow (ComponentPeer*) const
  183166. {
  183167. SetCursor ((HCURSOR) getHandle());
  183168. }
  183169. void MouseCursor::showInAllWindows() const
  183170. {
  183171. showInWindow (0);
  183172. }
  183173. class JuceDropSource : public IDropSource
  183174. {
  183175. int refCount;
  183176. public:
  183177. JuceDropSource()
  183178. : refCount (1)
  183179. {
  183180. }
  183181. virtual ~JuceDropSource()
  183182. {
  183183. jassert (refCount == 0);
  183184. }
  183185. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183186. {
  183187. if (id == IID_IUnknown || id == IID_IDropSource)
  183188. {
  183189. AddRef();
  183190. *result = this;
  183191. return S_OK;
  183192. }
  183193. *result = 0;
  183194. return E_NOINTERFACE;
  183195. }
  183196. ULONG __stdcall AddRef() { return ++refCount; }
  183197. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183198. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183199. {
  183200. if (escapePressed)
  183201. return DRAGDROP_S_CANCEL;
  183202. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183203. return DRAGDROP_S_DROP;
  183204. return S_OK;
  183205. }
  183206. HRESULT __stdcall GiveFeedback (DWORD)
  183207. {
  183208. return DRAGDROP_S_USEDEFAULTCURSORS;
  183209. }
  183210. };
  183211. class JuceEnumFormatEtc : public IEnumFORMATETC
  183212. {
  183213. public:
  183214. JuceEnumFormatEtc (const FORMATETC* const format_)
  183215. : refCount (1),
  183216. format (format_),
  183217. index (0)
  183218. {
  183219. }
  183220. virtual ~JuceEnumFormatEtc()
  183221. {
  183222. jassert (refCount == 0);
  183223. }
  183224. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183225. {
  183226. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183227. {
  183228. AddRef();
  183229. *result = this;
  183230. return S_OK;
  183231. }
  183232. *result = 0;
  183233. return E_NOINTERFACE;
  183234. }
  183235. ULONG __stdcall AddRef() { return ++refCount; }
  183236. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183237. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183238. {
  183239. if (result == 0)
  183240. return E_POINTER;
  183241. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183242. newOne->index = index;
  183243. *result = newOne;
  183244. return S_OK;
  183245. }
  183246. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183247. {
  183248. if (pceltFetched != 0)
  183249. *pceltFetched = 0;
  183250. else if (celt != 1)
  183251. return S_FALSE;
  183252. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183253. {
  183254. copyFormatEtc (lpFormatEtc [0], *format);
  183255. ++index;
  183256. if (pceltFetched != 0)
  183257. *pceltFetched = 1;
  183258. return S_OK;
  183259. }
  183260. return S_FALSE;
  183261. }
  183262. HRESULT __stdcall Skip (ULONG celt)
  183263. {
  183264. if (index + (int) celt >= 1)
  183265. return S_FALSE;
  183266. index += celt;
  183267. return S_OK;
  183268. }
  183269. HRESULT __stdcall Reset()
  183270. {
  183271. index = 0;
  183272. return S_OK;
  183273. }
  183274. private:
  183275. int refCount;
  183276. const FORMATETC* const format;
  183277. int index;
  183278. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183279. {
  183280. dest = source;
  183281. if (source.ptd != 0)
  183282. {
  183283. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183284. *(dest.ptd) = *(source.ptd);
  183285. }
  183286. }
  183287. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183288. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183289. };
  183290. class JuceDataObject : public IDataObject
  183291. {
  183292. JuceDropSource* const dropSource;
  183293. const FORMATETC* const format;
  183294. const STGMEDIUM* const medium;
  183295. int refCount;
  183296. JuceDataObject (const JuceDataObject&);
  183297. JuceDataObject& operator= (const JuceDataObject&);
  183298. public:
  183299. JuceDataObject (JuceDropSource* const dropSource_,
  183300. const FORMATETC* const format_,
  183301. const STGMEDIUM* const medium_)
  183302. : dropSource (dropSource_),
  183303. format (format_),
  183304. medium (medium_),
  183305. refCount (1)
  183306. {
  183307. }
  183308. virtual ~JuceDataObject()
  183309. {
  183310. jassert (refCount == 0);
  183311. }
  183312. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183313. {
  183314. if (id == IID_IUnknown || id == IID_IDataObject)
  183315. {
  183316. AddRef();
  183317. *result = this;
  183318. return S_OK;
  183319. }
  183320. *result = 0;
  183321. return E_NOINTERFACE;
  183322. }
  183323. ULONG __stdcall AddRef() { return ++refCount; }
  183324. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183325. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183326. {
  183327. if ((pFormatEtc->tymed & format->tymed) != 0
  183328. && pFormatEtc->cfFormat == format->cfFormat
  183329. && pFormatEtc->dwAspect == format->dwAspect)
  183330. {
  183331. pMedium->tymed = format->tymed;
  183332. pMedium->pUnkForRelease = 0;
  183333. if (format->tymed == TYMED_HGLOBAL)
  183334. {
  183335. const SIZE_T len = GlobalSize (medium->hGlobal);
  183336. void* const src = GlobalLock (medium->hGlobal);
  183337. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183338. memcpy (dst, src, len);
  183339. GlobalUnlock (medium->hGlobal);
  183340. pMedium->hGlobal = dst;
  183341. return S_OK;
  183342. }
  183343. }
  183344. return DV_E_FORMATETC;
  183345. }
  183346. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183347. {
  183348. if (f == 0)
  183349. return E_INVALIDARG;
  183350. if (f->tymed == format->tymed
  183351. && f->cfFormat == format->cfFormat
  183352. && f->dwAspect == format->dwAspect)
  183353. return S_OK;
  183354. return DV_E_FORMATETC;
  183355. }
  183356. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183357. {
  183358. pFormatEtcOut->ptd = 0;
  183359. return E_NOTIMPL;
  183360. }
  183361. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183362. {
  183363. if (result == 0)
  183364. return E_POINTER;
  183365. if (direction == DATADIR_GET)
  183366. {
  183367. *result = new JuceEnumFormatEtc (format);
  183368. return S_OK;
  183369. }
  183370. *result = 0;
  183371. return E_NOTIMPL;
  183372. }
  183373. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183374. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183375. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183376. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183377. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183378. };
  183379. static HDROP createHDrop (const StringArray& fileNames) throw()
  183380. {
  183381. int totalChars = 0;
  183382. for (int i = fileNames.size(); --i >= 0;)
  183383. totalChars += fileNames[i].length() + 1;
  183384. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183385. sizeof (DROPFILES)
  183386. + sizeof (WCHAR) * (totalChars + 2));
  183387. if (hDrop != 0)
  183388. {
  183389. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183390. pDropFiles->pFiles = sizeof (DROPFILES);
  183391. pDropFiles->fWide = true;
  183392. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183393. for (int i = 0; i < fileNames.size(); ++i)
  183394. {
  183395. fileNames[i].copyToUnicode (fname, 2048);
  183396. fname += fileNames[i].length() + 1;
  183397. }
  183398. *fname = 0;
  183399. GlobalUnlock (hDrop);
  183400. }
  183401. return hDrop;
  183402. }
  183403. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183404. {
  183405. JuceDropSource* const source = new JuceDropSource();
  183406. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183407. DWORD effect;
  183408. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183409. data->Release();
  183410. source->Release();
  183411. return res == DRAGDROP_S_DROP;
  183412. }
  183413. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183414. {
  183415. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183416. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183417. medium.hGlobal = createHDrop (files);
  183418. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183419. : DROPEFFECT_COPY);
  183420. }
  183421. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183422. {
  183423. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183424. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183425. const int numChars = text.length();
  183426. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183427. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (medium.hGlobal));
  183428. text.copyToUnicode (data, numChars + 1);
  183429. format.cfFormat = CF_UNICODETEXT;
  183430. GlobalUnlock (medium.hGlobal);
  183431. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183432. }
  183433. #endif
  183434. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183435. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183436. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183437. // compiled on its own).
  183438. #if JUCE_INCLUDED_FILE
  183439. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183440. NEWTEXTMETRICEXW*,
  183441. int type,
  183442. LPARAM lParam)
  183443. {
  183444. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183445. {
  183446. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183447. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183448. }
  183449. return 1;
  183450. }
  183451. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183452. NEWTEXTMETRICEXW*,
  183453. int type,
  183454. LPARAM lParam)
  183455. {
  183456. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183457. {
  183458. LOGFONTW lf;
  183459. zerostruct (lf);
  183460. lf.lfWeight = FW_DONTCARE;
  183461. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183462. lf.lfQuality = DEFAULT_QUALITY;
  183463. lf.lfCharSet = DEFAULT_CHARSET;
  183464. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183465. lf.lfPitchAndFamily = FF_DONTCARE;
  183466. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183467. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183468. HDC dc = CreateCompatibleDC (0);
  183469. EnumFontFamiliesEx (dc, &lf,
  183470. (FONTENUMPROCW) &wfontEnum2,
  183471. lParam, 0);
  183472. DeleteDC (dc);
  183473. }
  183474. return 1;
  183475. }
  183476. const StringArray Font::findAllTypefaceNames()
  183477. {
  183478. StringArray results;
  183479. HDC dc = CreateCompatibleDC (0);
  183480. {
  183481. LOGFONTW lf;
  183482. zerostruct (lf);
  183483. lf.lfWeight = FW_DONTCARE;
  183484. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183485. lf.lfQuality = DEFAULT_QUALITY;
  183486. lf.lfCharSet = DEFAULT_CHARSET;
  183487. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183488. lf.lfPitchAndFamily = FF_DONTCARE;
  183489. lf.lfFaceName[0] = 0;
  183490. EnumFontFamiliesEx (dc, &lf,
  183491. (FONTENUMPROCW) &wfontEnum1,
  183492. (LPARAM) &results, 0);
  183493. }
  183494. DeleteDC (dc);
  183495. results.sort (true);
  183496. return results;
  183497. }
  183498. extern bool juce_IsRunningInWine();
  183499. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183500. {
  183501. if (juce_IsRunningInWine())
  183502. {
  183503. // If we're running in Wine, then use fonts that might be available on Linux..
  183504. defaultSans = "Bitstream Vera Sans";
  183505. defaultSerif = "Bitstream Vera Serif";
  183506. defaultFixed = "Bitstream Vera Sans Mono";
  183507. }
  183508. else
  183509. {
  183510. defaultSans = "Verdana";
  183511. defaultSerif = "Times";
  183512. defaultFixed = "Lucida Console";
  183513. }
  183514. }
  183515. class FontDCHolder : private DeletedAtShutdown
  183516. {
  183517. public:
  183518. FontDCHolder() throw()
  183519. : dc (0), numKPs (0), size (0),
  183520. bold (false), italic (false)
  183521. {
  183522. }
  183523. ~FontDCHolder() throw()
  183524. {
  183525. if (dc != 0)
  183526. {
  183527. DeleteDC (dc);
  183528. DeleteObject (fontH);
  183529. }
  183530. clearSingletonInstance();
  183531. }
  183532. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183533. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183534. {
  183535. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183536. {
  183537. fontName = fontName_;
  183538. bold = bold_;
  183539. italic = italic_;
  183540. size = size_;
  183541. if (dc != 0)
  183542. {
  183543. DeleteDC (dc);
  183544. DeleteObject (fontH);
  183545. kps.free();
  183546. }
  183547. fontH = 0;
  183548. dc = CreateCompatibleDC (0);
  183549. SetMapperFlags (dc, 0);
  183550. SetMapMode (dc, MM_TEXT);
  183551. LOGFONTW lfw;
  183552. zerostruct (lfw);
  183553. lfw.lfCharSet = DEFAULT_CHARSET;
  183554. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183555. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183556. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183557. lfw.lfQuality = PROOF_QUALITY;
  183558. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183559. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183560. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183561. lfw.lfHeight = size > 0 ? size : -256;
  183562. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183563. if (standardSizedFont != 0)
  183564. {
  183565. if (SelectObject (dc, standardSizedFont) != 0)
  183566. {
  183567. fontH = standardSizedFont;
  183568. if (size == 0)
  183569. {
  183570. OUTLINETEXTMETRIC otm;
  183571. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183572. {
  183573. lfw.lfHeight = -(int) otm.otmEMSquare;
  183574. fontH = CreateFontIndirect (&lfw);
  183575. SelectObject (dc, fontH);
  183576. DeleteObject (standardSizedFont);
  183577. }
  183578. }
  183579. }
  183580. else
  183581. {
  183582. jassertfalse
  183583. }
  183584. }
  183585. else
  183586. {
  183587. jassertfalse
  183588. }
  183589. }
  183590. return dc;
  183591. }
  183592. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183593. {
  183594. if (kps == 0)
  183595. {
  183596. numKPs = GetKerningPairs (dc, 0, 0);
  183597. kps.calloc (numKPs);
  183598. GetKerningPairs (dc, numKPs, kps);
  183599. }
  183600. numKPs_ = numKPs;
  183601. return kps;
  183602. }
  183603. private:
  183604. HFONT fontH;
  183605. HDC dc;
  183606. String fontName;
  183607. HeapBlock <KERNINGPAIR> kps;
  183608. int numKPs, size;
  183609. bool bold, italic;
  183610. FontDCHolder (const FontDCHolder&);
  183611. FontDCHolder& operator= (const FontDCHolder&);
  183612. };
  183613. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183614. class WindowsTypeface : public CustomTypeface
  183615. {
  183616. public:
  183617. WindowsTypeface (const Font& font)
  183618. {
  183619. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183620. font.isBold(), font.isItalic(), 0);
  183621. TEXTMETRIC tm;
  183622. tm.tmAscent = tm.tmHeight = 1;
  183623. tm.tmDefaultChar = 0;
  183624. GetTextMetrics (dc, &tm);
  183625. setCharacteristics (font.getTypefaceName(),
  183626. tm.tmAscent / (float) tm.tmHeight,
  183627. font.isBold(), font.isItalic(),
  183628. tm.tmDefaultChar);
  183629. }
  183630. bool loadGlyphIfPossible (juce_wchar character)
  183631. {
  183632. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183633. GLYPHMETRICS gm;
  183634. {
  183635. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183636. WORD index = 0;
  183637. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183638. && index == 0xffff)
  183639. {
  183640. return false;
  183641. }
  183642. }
  183643. Path glyphPath;
  183644. TEXTMETRIC tm;
  183645. if (! GetTextMetrics (dc, &tm))
  183646. {
  183647. addGlyph (character, glyphPath, 0);
  183648. return true;
  183649. }
  183650. const float height = (float) tm.tmHeight;
  183651. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183652. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183653. &gm, 0, 0, &identityMatrix);
  183654. if (bufSize > 0)
  183655. {
  183656. HeapBlock<char> data (bufSize);
  183657. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183658. bufSize, data, &identityMatrix);
  183659. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183660. const float scaleX = 1.0f / height;
  183661. const float scaleY = -1.0f / height;
  183662. while ((char*) pheader < data + bufSize)
  183663. {
  183664. float x = scaleX * pheader->pfxStart.x.value;
  183665. float y = scaleY * pheader->pfxStart.y.value;
  183666. glyphPath.startNewSubPath (x, y);
  183667. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183668. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183669. while ((const char*) curve < curveEnd)
  183670. {
  183671. if (curve->wType == TT_PRIM_LINE)
  183672. {
  183673. for (int i = 0; i < curve->cpfx; ++i)
  183674. {
  183675. x = scaleX * curve->apfx[i].x.value;
  183676. y = scaleY * curve->apfx[i].y.value;
  183677. glyphPath.lineTo (x, y);
  183678. }
  183679. }
  183680. else if (curve->wType == TT_PRIM_QSPLINE)
  183681. {
  183682. for (int i = 0; i < curve->cpfx - 1; ++i)
  183683. {
  183684. const float x2 = scaleX * curve->apfx[i].x.value;
  183685. const float y2 = scaleY * curve->apfx[i].y.value;
  183686. float x3, y3;
  183687. if (i < curve->cpfx - 2)
  183688. {
  183689. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183690. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183691. }
  183692. else
  183693. {
  183694. x3 = scaleX * curve->apfx[i + 1].x.value;
  183695. y3 = scaleY * curve->apfx[i + 1].y.value;
  183696. }
  183697. glyphPath.quadraticTo (x2, y2, x3, y3);
  183698. x = x3;
  183699. y = y3;
  183700. }
  183701. }
  183702. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183703. }
  183704. pheader = (const TTPOLYGONHEADER*) curve;
  183705. glyphPath.closeSubPath();
  183706. }
  183707. }
  183708. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183709. int numKPs;
  183710. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183711. for (int i = 0; i < numKPs; ++i)
  183712. {
  183713. if (kps[i].wFirst == character)
  183714. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183715. kps[i].iKernAmount / height);
  183716. }
  183717. return true;
  183718. }
  183719. };
  183720. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183721. {
  183722. return new WindowsTypeface (font);
  183723. }
  183724. #endif
  183725. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183726. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183727. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183728. // compiled on its own).
  183729. #if JUCE_INCLUDED_FILE
  183730. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183731. namespace FileChooserHelpers
  183732. {
  183733. static const void* defaultDirPath = 0;
  183734. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183735. static Component* currentExtraFileWin = 0;
  183736. static bool areThereAnyAlwaysOnTopWindows()
  183737. {
  183738. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183739. {
  183740. Component* c = Desktop::getInstance().getComponent (i);
  183741. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183742. return true;
  183743. }
  183744. return false;
  183745. }
  183746. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183747. {
  183748. if (msg == BFFM_INITIALIZED)
  183749. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183750. else if (msg == BFFM_VALIDATEFAILEDW)
  183751. returnedString = (LPCWSTR) lParam;
  183752. else if (msg == BFFM_VALIDATEFAILEDA)
  183753. returnedString = (const char*) lParam;
  183754. return 0;
  183755. }
  183756. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183757. {
  183758. if (currentExtraFileWin != 0)
  183759. {
  183760. if (uiMsg == WM_INITDIALOG)
  183761. {
  183762. HWND dialogH = GetParent (hdlg);
  183763. jassert (dialogH != 0);
  183764. if (dialogH == 0)
  183765. dialogH = hdlg;
  183766. RECT r, cr;
  183767. GetWindowRect (dialogH, &r);
  183768. GetClientRect (dialogH, &cr);
  183769. SetWindowPos (dialogH, 0,
  183770. r.left, r.top,
  183771. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183772. jmax (150, (int) (r.bottom - r.top)),
  183773. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183774. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183775. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183776. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183777. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183778. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183779. }
  183780. else if (uiMsg == WM_NOTIFY)
  183781. {
  183782. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183783. if (ofn->hdr.code == CDN_SELCHANGE)
  183784. {
  183785. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183786. if (comp != 0)
  183787. {
  183788. TCHAR path [MAX_PATH * 2];
  183789. path[0] = 0;
  183790. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183791. const String fn ((const WCHAR*) path);
  183792. comp->selectedFileChanged (File (fn));
  183793. }
  183794. }
  183795. }
  183796. }
  183797. return 0;
  183798. }
  183799. class FPComponentHolder : public Component
  183800. {
  183801. public:
  183802. FPComponentHolder()
  183803. {
  183804. setVisible (true);
  183805. setOpaque (true);
  183806. }
  183807. ~FPComponentHolder()
  183808. {
  183809. }
  183810. void paint (Graphics& g)
  183811. {
  183812. g.fillAll (Colours::lightgrey);
  183813. }
  183814. private:
  183815. FPComponentHolder (const FPComponentHolder&);
  183816. FPComponentHolder& operator= (const FPComponentHolder&);
  183817. };
  183818. }
  183819. void FileChooser::showPlatformDialog (Array<File>& results,
  183820. const String& title,
  183821. const File& currentFileOrDirectory,
  183822. const String& filter,
  183823. bool selectsDirectory,
  183824. bool /*selectsFiles*/,
  183825. bool isSaveDialogue,
  183826. bool warnAboutOverwritingExistingFiles,
  183827. bool selectMultipleFiles,
  183828. FilePreviewComponent* extraInfoComponent)
  183829. {
  183830. using namespace FileChooserHelpers;
  183831. const int numCharsAvailable = 32768;
  183832. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183833. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183834. int fnameIdx = 0;
  183835. JUCE_TRY
  183836. {
  183837. // use a modal window as the parent for this dialog box
  183838. // to block input from other app windows
  183839. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183840. Component w (String::empty);
  183841. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183842. mainMon.getY() + mainMon.getHeight() / 4,
  183843. 0, 0);
  183844. w.setOpaque (true);
  183845. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183846. w.addToDesktop (0);
  183847. if (extraInfoComponent == 0)
  183848. w.enterModalState();
  183849. String initialDir;
  183850. if (currentFileOrDirectory.isDirectory())
  183851. {
  183852. initialDir = currentFileOrDirectory.getFullPathName();
  183853. }
  183854. else
  183855. {
  183856. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183857. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183858. }
  183859. if (currentExtraFileWin->isValidComponent())
  183860. {
  183861. jassertfalse
  183862. return;
  183863. }
  183864. if (selectsDirectory)
  183865. {
  183866. LPITEMIDLIST list = 0;
  183867. filenameSpace.fillWith (0);
  183868. {
  183869. BROWSEINFO bi;
  183870. zerostruct (bi);
  183871. bi.hwndOwner = (HWND) w.getWindowHandle();
  183872. bi.pszDisplayName = fname;
  183873. bi.lpszTitle = title;
  183874. bi.lpfn = browseCallbackProc;
  183875. #ifdef BIF_USENEWUI
  183876. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183877. #else
  183878. bi.ulFlags = 0x50;
  183879. #endif
  183880. defaultDirPath = (const WCHAR*) initialDir;
  183881. list = SHBrowseForFolder (&bi);
  183882. if (! SHGetPathFromIDListW (list, fname))
  183883. {
  183884. fname[0] = 0;
  183885. returnedString = String::empty;
  183886. }
  183887. }
  183888. LPMALLOC al;
  183889. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183890. al->Free (list);
  183891. defaultDirPath = 0;
  183892. if (returnedString.isNotEmpty())
  183893. {
  183894. const String stringFName (fname);
  183895. results.add (File (stringFName).getSiblingFile (returnedString));
  183896. returnedString = String::empty;
  183897. return;
  183898. }
  183899. }
  183900. else
  183901. {
  183902. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183903. if (warnAboutOverwritingExistingFiles)
  183904. flags |= OFN_OVERWRITEPROMPT;
  183905. if (selectMultipleFiles)
  183906. flags |= OFN_ALLOWMULTISELECT;
  183907. if (extraInfoComponent != 0)
  183908. {
  183909. flags |= OFN_ENABLEHOOK;
  183910. currentExtraFileWin = new FPComponentHolder();
  183911. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183912. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183913. extraInfoComponent->getHeight());
  183914. currentExtraFileWin->addToDesktop (0);
  183915. currentExtraFileWin->enterModalState();
  183916. }
  183917. {
  183918. WCHAR filters [1024];
  183919. zeromem (filters, sizeof (filters));
  183920. filter.copyToUnicode (filters, 1024);
  183921. filter.copyToUnicode (filters + filter.length() + 1,
  183922. 1022 - filter.length());
  183923. OPENFILENAMEW of;
  183924. zerostruct (of);
  183925. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183926. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183927. #else
  183928. of.lStructSize = sizeof (of);
  183929. #endif
  183930. of.hwndOwner = (HWND) w.getWindowHandle();
  183931. of.lpstrFilter = filters;
  183932. of.nFilterIndex = 1;
  183933. of.lpstrFile = fname;
  183934. of.nMaxFile = numCharsAvailable;
  183935. of.lpstrInitialDir = initialDir;
  183936. of.lpstrTitle = title;
  183937. of.Flags = flags;
  183938. if (extraInfoComponent != 0)
  183939. of.lpfnHook = &openCallback;
  183940. if (isSaveDialogue)
  183941. {
  183942. if (! GetSaveFileName (&of))
  183943. fname[0] = 0;
  183944. else
  183945. fnameIdx = of.nFileOffset;
  183946. }
  183947. else
  183948. {
  183949. if (! GetOpenFileName (&of))
  183950. fname[0] = 0;
  183951. else
  183952. fnameIdx = of.nFileOffset;
  183953. }
  183954. }
  183955. }
  183956. }
  183957. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  183958. catch (...)
  183959. {
  183960. fname[0] = 0;
  183961. }
  183962. #endif
  183963. deleteAndZero (currentExtraFileWin);
  183964. const WCHAR* const files = fname;
  183965. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  183966. {
  183967. const WCHAR* filename = files + fnameIdx;
  183968. while (*filename != 0)
  183969. {
  183970. const String filepath (String (files) + "\\" + String (filename));
  183971. results.add (File (filepath));
  183972. filename += CharacterFunctions::length (filename) + 1;
  183973. }
  183974. }
  183975. else if (files[0] != 0)
  183976. {
  183977. results.add (File (files));
  183978. }
  183979. }
  183980. #endif
  183981. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  183982. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  183983. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183984. // compiled on its own).
  183985. #if JUCE_INCLUDED_FILE
  183986. void SystemClipboard::copyTextToClipboard (const String& text)
  183987. {
  183988. if (OpenClipboard (0) != 0)
  183989. {
  183990. if (EmptyClipboard() != 0)
  183991. {
  183992. const int len = text.length();
  183993. if (len > 0)
  183994. {
  183995. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  183996. (len + 1) * sizeof (wchar_t));
  183997. if (bufH != 0)
  183998. {
  183999. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
  184000. text.copyToUnicode (data, len);
  184001. GlobalUnlock (bufH);
  184002. SetClipboardData (CF_UNICODETEXT, bufH);
  184003. }
  184004. }
  184005. }
  184006. CloseClipboard();
  184007. }
  184008. }
  184009. const String SystemClipboard::getTextFromClipboard()
  184010. {
  184011. String result;
  184012. if (OpenClipboard (0) != 0)
  184013. {
  184014. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184015. if (bufH != 0)
  184016. {
  184017. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184018. if (data != 0)
  184019. {
  184020. result = String (data, (int) (GlobalSize (bufH) / sizeof (wchar_t)));
  184021. GlobalUnlock (bufH);
  184022. }
  184023. }
  184024. CloseClipboard();
  184025. }
  184026. return result;
  184027. }
  184028. #endif
  184029. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184030. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184031. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184032. // compiled on its own).
  184033. #if JUCE_INCLUDED_FILE
  184034. namespace ActiveXHelpers
  184035. {
  184036. class JuceIStorage : public IStorage
  184037. {
  184038. int refCount;
  184039. public:
  184040. JuceIStorage() : refCount (1) {}
  184041. virtual ~JuceIStorage()
  184042. {
  184043. jassert (refCount == 0);
  184044. }
  184045. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184046. {
  184047. if (id == IID_IUnknown || id == IID_IStorage)
  184048. {
  184049. AddRef();
  184050. *result = this;
  184051. return S_OK;
  184052. }
  184053. *result = 0;
  184054. return E_NOINTERFACE;
  184055. }
  184056. ULONG __stdcall AddRef() { return ++refCount; }
  184057. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184058. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184059. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184060. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184061. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184062. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184063. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184064. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184065. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184066. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184067. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184068. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184069. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184070. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184071. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184072. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184073. juce_UseDebuggingNewOperator
  184074. };
  184075. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184076. {
  184077. int refCount;
  184078. HWND window;
  184079. public:
  184080. JuceOleInPlaceFrame (HWND window_)
  184081. : refCount (1),
  184082. window (window_)
  184083. {
  184084. }
  184085. virtual ~JuceOleInPlaceFrame()
  184086. {
  184087. jassert (refCount == 0);
  184088. }
  184089. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184090. {
  184091. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184092. {
  184093. AddRef();
  184094. *result = this;
  184095. return S_OK;
  184096. }
  184097. *result = 0;
  184098. return E_NOINTERFACE;
  184099. }
  184100. ULONG __stdcall AddRef() { return ++refCount; }
  184101. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184102. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184103. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184104. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184105. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184106. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184107. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184108. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184109. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184110. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184111. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184112. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184113. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184114. juce_UseDebuggingNewOperator
  184115. };
  184116. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184117. {
  184118. int refCount;
  184119. HWND window;
  184120. JuceOleInPlaceFrame* frame;
  184121. public:
  184122. JuceIOleInPlaceSite (HWND window_)
  184123. : refCount (1),
  184124. window (window_)
  184125. {
  184126. frame = new JuceOleInPlaceFrame (window);
  184127. }
  184128. virtual ~JuceIOleInPlaceSite()
  184129. {
  184130. jassert (refCount == 0);
  184131. frame->Release();
  184132. }
  184133. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184134. {
  184135. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184136. {
  184137. AddRef();
  184138. *result = this;
  184139. return S_OK;
  184140. }
  184141. *result = 0;
  184142. return E_NOINTERFACE;
  184143. }
  184144. ULONG __stdcall AddRef() { return ++refCount; }
  184145. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184146. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184147. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184148. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184149. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184150. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184151. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184152. {
  184153. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184154. *lplpFrame = frame;
  184155. *lplpDoc = 0;
  184156. lpFrameInfo->fMDIApp = FALSE;
  184157. lpFrameInfo->hwndFrame = window;
  184158. lpFrameInfo->haccel = 0;
  184159. lpFrameInfo->cAccelEntries = 0;
  184160. return S_OK;
  184161. }
  184162. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184163. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184164. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184165. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184166. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184167. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184168. juce_UseDebuggingNewOperator
  184169. };
  184170. class JuceIOleClientSite : public IOleClientSite
  184171. {
  184172. int refCount;
  184173. JuceIOleInPlaceSite* inplaceSite;
  184174. public:
  184175. JuceIOleClientSite (HWND window)
  184176. : refCount (1)
  184177. {
  184178. inplaceSite = new JuceIOleInPlaceSite (window);
  184179. }
  184180. virtual ~JuceIOleClientSite()
  184181. {
  184182. jassert (refCount == 0);
  184183. inplaceSite->Release();
  184184. }
  184185. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184186. {
  184187. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184188. {
  184189. AddRef();
  184190. *result = this;
  184191. return S_OK;
  184192. }
  184193. else if (id == IID_IOleInPlaceSite)
  184194. {
  184195. inplaceSite->AddRef();
  184196. *result = inplaceSite;
  184197. return S_OK;
  184198. }
  184199. *result = 0;
  184200. return E_NOINTERFACE;
  184201. }
  184202. ULONG __stdcall AddRef() { return ++refCount; }
  184203. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184204. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184205. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184206. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184207. HRESULT __stdcall ShowObject() { return S_OK; }
  184208. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184209. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184210. juce_UseDebuggingNewOperator
  184211. };
  184212. static VoidArray activeXComps;
  184213. static HWND getHWND (const ActiveXControlComponent* const component)
  184214. {
  184215. HWND hwnd = 0;
  184216. const IID iid = IID_IOleWindow;
  184217. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184218. if (window != 0)
  184219. {
  184220. window->GetWindow (&hwnd);
  184221. window->Release();
  184222. }
  184223. return hwnd;
  184224. }
  184225. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184226. {
  184227. RECT activeXRect, peerRect;
  184228. GetWindowRect (hwnd, &activeXRect);
  184229. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184230. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184231. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184232. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184233. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184234. switch (message)
  184235. {
  184236. case WM_MOUSEMOVE:
  184237. case WM_LBUTTONDOWN:
  184238. case WM_MBUTTONDOWN:
  184239. case WM_RBUTTONDOWN:
  184240. case WM_LBUTTONUP:
  184241. case WM_MBUTTONUP:
  184242. case WM_RBUTTONUP:
  184243. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184244. break;
  184245. default:
  184246. break;
  184247. }
  184248. }
  184249. }
  184250. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184251. {
  184252. ActiveXControlComponent* const owner;
  184253. bool wasShowing;
  184254. public:
  184255. HWND controlHWND;
  184256. IStorage* storage;
  184257. IOleClientSite* clientSite;
  184258. IOleObject* control;
  184259. ActiveXControlData (HWND hwnd,
  184260. ActiveXControlComponent* const owner_)
  184261. : ComponentMovementWatcher (owner_),
  184262. owner (owner_),
  184263. wasShowing (owner_ != 0 && owner_->isShowing()),
  184264. controlHWND (0),
  184265. storage (new ActiveXHelpers::JuceIStorage()),
  184266. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184267. control (0)
  184268. {
  184269. }
  184270. ~ActiveXControlData()
  184271. {
  184272. if (control != 0)
  184273. {
  184274. control->Close (OLECLOSE_NOSAVE);
  184275. control->Release();
  184276. }
  184277. clientSite->Release();
  184278. storage->Release();
  184279. }
  184280. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184281. {
  184282. Component* const topComp = owner->getTopLevelComponent();
  184283. if (topComp->getPeer() != 0)
  184284. {
  184285. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184286. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184287. }
  184288. }
  184289. void componentPeerChanged()
  184290. {
  184291. const bool isShowingNow = owner->isShowing();
  184292. if (wasShowing != isShowingNow)
  184293. {
  184294. wasShowing = isShowingNow;
  184295. owner->setControlVisible (isShowingNow);
  184296. }
  184297. componentMovedOrResized (true, true);
  184298. }
  184299. void componentVisibilityChanged (Component&)
  184300. {
  184301. componentPeerChanged();
  184302. }
  184303. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184304. {
  184305. return ((ActiveXControlData*) ax->control) != 0
  184306. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184307. }
  184308. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184309. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184310. {
  184311. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184312. {
  184313. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184314. if (doesWindowMatch (ax, hwnd))
  184315. {
  184316. switch (message)
  184317. {
  184318. case WM_MOUSEMOVE:
  184319. case WM_LBUTTONDOWN:
  184320. case WM_MBUTTONDOWN:
  184321. case WM_RBUTTONDOWN:
  184322. case WM_LBUTTONUP:
  184323. case WM_MBUTTONUP:
  184324. case WM_RBUTTONUP:
  184325. case WM_LBUTTONDBLCLK:
  184326. case WM_MBUTTONDBLCLK:
  184327. case WM_RBUTTONDBLCLK:
  184328. if (ax->isShowing())
  184329. {
  184330. ComponentPeer* const peer = ax->getPeer();
  184331. if (peer != 0)
  184332. {
  184333. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184334. if (! ax->areMouseEventsAllowed())
  184335. return 0;
  184336. }
  184337. }
  184338. break;
  184339. default:
  184340. break;
  184341. }
  184342. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184343. }
  184344. }
  184345. return DefWindowProc (hwnd, message, wParam, lParam);
  184346. }
  184347. };
  184348. ActiveXControlComponent::ActiveXControlComponent()
  184349. : originalWndProc (0),
  184350. control (0),
  184351. mouseEventsAllowed (true)
  184352. {
  184353. ActiveXHelpers::activeXComps.add (this);
  184354. }
  184355. ActiveXControlComponent::~ActiveXControlComponent()
  184356. {
  184357. deleteControl();
  184358. ActiveXHelpers::activeXComps.removeValue (this);
  184359. }
  184360. void ActiveXControlComponent::paint (Graphics& g)
  184361. {
  184362. if (control == 0)
  184363. g.fillAll (Colours::lightgrey);
  184364. }
  184365. bool ActiveXControlComponent::createControl (const void* controlIID)
  184366. {
  184367. deleteControl();
  184368. ComponentPeer* const peer = getPeer();
  184369. // the component must have already been added to a real window when you call this!
  184370. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184371. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184372. {
  184373. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184374. HWND hwnd = (HWND) peer->getNativeHandle();
  184375. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184376. HRESULT hr;
  184377. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184378. info->clientSite, info->storage,
  184379. (void**) &(info->control))) == S_OK)
  184380. {
  184381. info->control->SetHostNames (L"Juce", 0);
  184382. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184383. {
  184384. RECT rect;
  184385. rect.left = pos.getX();
  184386. rect.top = pos.getY();
  184387. rect.right = pos.getX() + getWidth();
  184388. rect.bottom = pos.getY() + getHeight();
  184389. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184390. {
  184391. control = info.release();
  184392. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184393. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184394. if (((ActiveXControlData*) control)->controlHWND != 0)
  184395. {
  184396. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184397. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184398. }
  184399. return true;
  184400. }
  184401. }
  184402. }
  184403. }
  184404. return false;
  184405. }
  184406. void ActiveXControlComponent::deleteControl()
  184407. {
  184408. ActiveXControlData* const info = (ActiveXControlData*) control;
  184409. if (info != 0)
  184410. {
  184411. delete info;
  184412. control = 0;
  184413. originalWndProc = 0;
  184414. }
  184415. }
  184416. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184417. {
  184418. ActiveXControlData* const info = (ActiveXControlData*) control;
  184419. void* result = 0;
  184420. if (info != 0 && info->control != 0
  184421. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184422. return result;
  184423. return 0;
  184424. }
  184425. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184426. {
  184427. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184428. if (hwnd != 0)
  184429. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184430. }
  184431. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184432. {
  184433. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184434. if (hwnd != 0)
  184435. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184436. }
  184437. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184438. {
  184439. mouseEventsAllowed = eventsCanReachControl;
  184440. }
  184441. #endif
  184442. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184443. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184444. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184445. // compiled on its own).
  184446. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184447. using namespace QTOLibrary;
  184448. using namespace QTOControlLib;
  184449. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184450. static bool isQTAvailable = false;
  184451. class QuickTimeMovieComponent::Pimpl
  184452. {
  184453. public:
  184454. Pimpl() : dataHandle (0)
  184455. {
  184456. }
  184457. ~Pimpl()
  184458. {
  184459. clearHandle();
  184460. }
  184461. void clearHandle()
  184462. {
  184463. if (dataHandle != 0)
  184464. {
  184465. DisposeHandle (dataHandle);
  184466. dataHandle = 0;
  184467. }
  184468. }
  184469. IQTControlPtr qtControl;
  184470. IQTMoviePtr qtMovie;
  184471. Handle dataHandle;
  184472. };
  184473. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184474. : movieLoaded (false),
  184475. controllerVisible (true)
  184476. {
  184477. pimpl = new Pimpl();
  184478. setMouseEventsAllowed (false);
  184479. }
  184480. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184481. {
  184482. closeMovie();
  184483. pimpl->qtControl = 0;
  184484. deleteControl();
  184485. pimpl = 0;
  184486. }
  184487. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184488. {
  184489. if (! isQTAvailable)
  184490. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184491. return isQTAvailable;
  184492. }
  184493. void QuickTimeMovieComponent::createControlIfNeeded()
  184494. {
  184495. if (isShowing() && ! isControlCreated())
  184496. {
  184497. const IID qtIID = __uuidof (QTControl);
  184498. if (createControl (&qtIID))
  184499. {
  184500. const IID qtInterfaceIID = __uuidof (IQTControl);
  184501. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184502. if (pimpl->qtControl != 0)
  184503. {
  184504. pimpl->qtControl->Release(); // it has one ref too many at this point
  184505. pimpl->qtControl->QuickTimeInitialize();
  184506. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184507. if (movieFile != File::nonexistent)
  184508. loadMovie (movieFile, controllerVisible);
  184509. }
  184510. }
  184511. }
  184512. }
  184513. bool QuickTimeMovieComponent::isControlCreated() const
  184514. {
  184515. return isControlOpen();
  184516. }
  184517. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184518. const bool isControllerVisible)
  184519. {
  184520. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184521. movieFile = File::nonexistent;
  184522. movieLoaded = false;
  184523. pimpl->qtMovie = 0;
  184524. controllerVisible = isControllerVisible;
  184525. createControlIfNeeded();
  184526. if (isControlCreated())
  184527. {
  184528. if (pimpl->qtControl != 0)
  184529. {
  184530. pimpl->qtControl->Put_MovieHandle (0);
  184531. pimpl->clearHandle();
  184532. Movie movie;
  184533. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184534. {
  184535. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184536. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184537. if (pimpl->qtMovie != 0)
  184538. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184539. : qtMovieControllerTypeNone);
  184540. }
  184541. if (movie == 0)
  184542. pimpl->clearHandle();
  184543. }
  184544. movieLoaded = (pimpl->qtMovie != 0);
  184545. }
  184546. else
  184547. {
  184548. // You're trying to open a movie when the control hasn't yet been created, probably because
  184549. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184550. jassertfalse
  184551. }
  184552. return movieLoaded;
  184553. }
  184554. void QuickTimeMovieComponent::closeMovie()
  184555. {
  184556. stop();
  184557. movieFile = File::nonexistent;
  184558. movieLoaded = false;
  184559. pimpl->qtMovie = 0;
  184560. if (pimpl->qtControl != 0)
  184561. pimpl->qtControl->Put_MovieHandle (0);
  184562. pimpl->clearHandle();
  184563. }
  184564. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184565. {
  184566. return movieFile;
  184567. }
  184568. bool QuickTimeMovieComponent::isMovieOpen() const
  184569. {
  184570. return movieLoaded;
  184571. }
  184572. double QuickTimeMovieComponent::getMovieDuration() const
  184573. {
  184574. if (pimpl->qtMovie != 0)
  184575. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184576. return 0.0;
  184577. }
  184578. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184579. {
  184580. if (pimpl->qtMovie != 0)
  184581. {
  184582. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184583. width = r.right - r.left;
  184584. height = r.bottom - r.top;
  184585. }
  184586. else
  184587. {
  184588. width = height = 0;
  184589. }
  184590. }
  184591. void QuickTimeMovieComponent::play()
  184592. {
  184593. if (pimpl->qtMovie != 0)
  184594. pimpl->qtMovie->Play();
  184595. }
  184596. void QuickTimeMovieComponent::stop()
  184597. {
  184598. if (pimpl->qtMovie != 0)
  184599. pimpl->qtMovie->Stop();
  184600. }
  184601. bool QuickTimeMovieComponent::isPlaying() const
  184602. {
  184603. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184604. }
  184605. void QuickTimeMovieComponent::setPosition (const double seconds)
  184606. {
  184607. if (pimpl->qtMovie != 0)
  184608. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184609. }
  184610. double QuickTimeMovieComponent::getPosition() const
  184611. {
  184612. if (pimpl->qtMovie != 0)
  184613. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184614. return 0.0;
  184615. }
  184616. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184617. {
  184618. if (pimpl->qtMovie != 0)
  184619. pimpl->qtMovie->PutRate (newSpeed);
  184620. }
  184621. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184622. {
  184623. if (pimpl->qtMovie != 0)
  184624. {
  184625. pimpl->qtMovie->PutAudioVolume (newVolume);
  184626. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184627. }
  184628. }
  184629. float QuickTimeMovieComponent::getMovieVolume() const
  184630. {
  184631. if (pimpl->qtMovie != 0)
  184632. return pimpl->qtMovie->GetAudioVolume();
  184633. return 0.0f;
  184634. }
  184635. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184636. {
  184637. if (pimpl->qtMovie != 0)
  184638. pimpl->qtMovie->PutLoop (shouldLoop);
  184639. }
  184640. bool QuickTimeMovieComponent::isLooping() const
  184641. {
  184642. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184643. }
  184644. bool QuickTimeMovieComponent::isControllerVisible() const
  184645. {
  184646. return controllerVisible;
  184647. }
  184648. void QuickTimeMovieComponent::parentHierarchyChanged()
  184649. {
  184650. createControlIfNeeded();
  184651. QTCompBaseClass::parentHierarchyChanged();
  184652. }
  184653. void QuickTimeMovieComponent::visibilityChanged()
  184654. {
  184655. createControlIfNeeded();
  184656. QTCompBaseClass::visibilityChanged();
  184657. }
  184658. void QuickTimeMovieComponent::paint (Graphics& g)
  184659. {
  184660. if (! isControlCreated())
  184661. g.fillAll (Colours::black);
  184662. }
  184663. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184664. {
  184665. Handle dataRef = 0;
  184666. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184667. if (err == noErr)
  184668. {
  184669. Str255 suffix;
  184670. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184671. StringPtr name = suffix;
  184672. err = PtrAndHand (name, dataRef, name[0] + 1);
  184673. if (err == noErr)
  184674. {
  184675. long atoms[3];
  184676. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184677. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184678. atoms[2] = EndianU32_NtoB (MovieFileType);
  184679. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184680. if (err == noErr)
  184681. return dataRef;
  184682. }
  184683. DisposeHandle (dataRef);
  184684. }
  184685. return 0;
  184686. }
  184687. static CFStringRef juceStringToCFString (const String& s)
  184688. {
  184689. const int len = s.length();
  184690. const juce_wchar* const t = s;
  184691. HeapBlock <UniChar> temp (len + 2);
  184692. for (int i = 0; i <= len; ++i)
  184693. temp[i] = t[i];
  184694. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184695. }
  184696. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184697. {
  184698. Boolean trueBool = true;
  184699. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184700. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184701. props[prop].propValueSize = sizeof (trueBool);
  184702. props[prop].propValueAddress = &trueBool;
  184703. ++prop;
  184704. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184705. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184706. props[prop].propValueSize = sizeof (trueBool);
  184707. props[prop].propValueAddress = &trueBool;
  184708. ++prop;
  184709. Boolean isActive = true;
  184710. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184711. props[prop].propID = kQTNewMoviePropertyID_Active;
  184712. props[prop].propValueSize = sizeof (isActive);
  184713. props[prop].propValueAddress = &isActive;
  184714. ++prop;
  184715. MacSetPort (0);
  184716. jassert (prop <= 5);
  184717. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184718. return err == noErr;
  184719. }
  184720. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184721. {
  184722. if (input == 0)
  184723. return false;
  184724. dataHandle = 0;
  184725. bool ok = false;
  184726. QTNewMoviePropertyElement props[5];
  184727. zeromem (props, sizeof (props));
  184728. int prop = 0;
  184729. DataReferenceRecord dr;
  184730. props[prop].propClass = kQTPropertyClass_DataLocation;
  184731. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184732. props[prop].propValueSize = sizeof (dr);
  184733. props[prop].propValueAddress = &dr;
  184734. ++prop;
  184735. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184736. if (fin != 0)
  184737. {
  184738. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184739. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184740. &dr.dataRef, &dr.dataRefType);
  184741. ok = openMovie (props, prop, movie);
  184742. DisposeHandle (dr.dataRef);
  184743. CFRelease (filePath);
  184744. }
  184745. else
  184746. {
  184747. // sanity-check because this currently needs to load the whole stream into memory..
  184748. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184749. dataHandle = NewHandle ((Size) input->getTotalLength());
  184750. HLock (dataHandle);
  184751. // read the entire stream into memory - this is a pain, but can't get it to work
  184752. // properly using a custom callback to supply the data.
  184753. input->read (*dataHandle, (int) input->getTotalLength());
  184754. HUnlock (dataHandle);
  184755. // different types to get QT to try. (We should really be a bit smarter here by
  184756. // working out in advance which one the stream contains, rather than just trying
  184757. // each one)
  184758. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184759. "\04.avi", "\04.m4a" };
  184760. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184761. {
  184762. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184763. dr.dataRefType = HandleDataHandlerSubType;
  184764. ok = openMovie (props, prop, movie);
  184765. DisposeHandle (dr.dataRef);
  184766. }
  184767. }
  184768. return ok;
  184769. }
  184770. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184771. const bool isControllerVisible)
  184772. {
  184773. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184774. movieFile = movieFile_;
  184775. return ok;
  184776. }
  184777. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184778. const bool isControllerVisible)
  184779. {
  184780. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184781. }
  184782. void QuickTimeMovieComponent::goToStart()
  184783. {
  184784. setPosition (0.0);
  184785. }
  184786. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184787. const RectanglePlacement& placement)
  184788. {
  184789. int normalWidth, normalHeight;
  184790. getMovieNormalSize (normalWidth, normalHeight);
  184791. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184792. {
  184793. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184794. placement.applyTo (x, y, w, h,
  184795. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184796. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184797. if (w > 0 && h > 0)
  184798. {
  184799. setBounds (roundToInt (x), roundToInt (y),
  184800. roundToInt (w), roundToInt (h));
  184801. }
  184802. }
  184803. else
  184804. {
  184805. setBounds (spaceToFitWithin);
  184806. }
  184807. }
  184808. #endif
  184809. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184810. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184811. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184812. // compiled on its own).
  184813. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184814. class WebBrowserComponentInternal : public ActiveXControlComponent
  184815. {
  184816. public:
  184817. WebBrowserComponentInternal()
  184818. : browser (0),
  184819. connectionPoint (0),
  184820. adviseCookie (0)
  184821. {
  184822. }
  184823. ~WebBrowserComponentInternal()
  184824. {
  184825. if (connectionPoint != 0)
  184826. connectionPoint->Unadvise (adviseCookie);
  184827. if (browser != 0)
  184828. browser->Release();
  184829. }
  184830. void createBrowser()
  184831. {
  184832. createControl (&CLSID_WebBrowser);
  184833. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184834. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184835. if (connectionPointContainer != 0)
  184836. {
  184837. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184838. &connectionPoint);
  184839. if (connectionPoint != 0)
  184840. {
  184841. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184842. jassert (owner != 0);
  184843. EventHandler* handler = new EventHandler (owner);
  184844. connectionPoint->Advise (handler, &adviseCookie);
  184845. }
  184846. }
  184847. }
  184848. void goToURL (const String& url,
  184849. const StringArray* headers,
  184850. const MemoryBlock* postData)
  184851. {
  184852. if (browser != 0)
  184853. {
  184854. LPSAFEARRAY sa = 0;
  184855. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184856. VariantInit (&flags);
  184857. VariantInit (&frame);
  184858. VariantInit (&postDataVar);
  184859. VariantInit (&headersVar);
  184860. if (headers != 0)
  184861. {
  184862. V_VT (&headersVar) = VT_BSTR;
  184863. V_BSTR (&headersVar) = SysAllocString ((const OLECHAR*) headers->joinIntoString ("\r\n"));
  184864. }
  184865. if (postData != 0 && postData->getSize() > 0)
  184866. {
  184867. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184868. if (sa != 0)
  184869. {
  184870. void* data = 0;
  184871. SafeArrayAccessData (sa, &data);
  184872. jassert (data != 0);
  184873. if (data != 0)
  184874. {
  184875. postData->copyTo (data, 0, postData->getSize());
  184876. SafeArrayUnaccessData (sa);
  184877. VARIANT postDataVar2;
  184878. VariantInit (&postDataVar2);
  184879. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184880. V_ARRAY (&postDataVar2) = sa;
  184881. postDataVar = postDataVar2;
  184882. }
  184883. }
  184884. }
  184885. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184886. &flags, &frame,
  184887. &postDataVar, &headersVar);
  184888. if (sa != 0)
  184889. SafeArrayDestroy (sa);
  184890. VariantClear (&flags);
  184891. VariantClear (&frame);
  184892. VariantClear (&postDataVar);
  184893. VariantClear (&headersVar);
  184894. }
  184895. }
  184896. IWebBrowser2* browser;
  184897. juce_UseDebuggingNewOperator
  184898. private:
  184899. IConnectionPoint* connectionPoint;
  184900. DWORD adviseCookie;
  184901. class EventHandler : public IDispatch,
  184902. public ComponentMovementWatcher
  184903. {
  184904. public:
  184905. EventHandler (WebBrowserComponent* owner_)
  184906. : ComponentMovementWatcher (owner_),
  184907. owner (owner_),
  184908. refCount (0)
  184909. {
  184910. }
  184911. ~EventHandler()
  184912. {
  184913. }
  184914. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184915. {
  184916. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184917. {
  184918. AddRef();
  184919. *result = this;
  184920. return S_OK;
  184921. }
  184922. *result = 0;
  184923. return E_NOINTERFACE;
  184924. }
  184925. ULONG __stdcall AddRef() { return ++refCount; }
  184926. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184927. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184928. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184929. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184930. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184931. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  184932. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  184933. UINT __RPC_FAR* /*puArgErr*/)
  184934. {
  184935. switch (dispIdMember)
  184936. {
  184937. case DISPID_BEFORENAVIGATE2:
  184938. {
  184939. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  184940. String url;
  184941. if ((vurl->vt & VT_BYREF) != 0)
  184942. url = *vurl->pbstrVal;
  184943. else
  184944. url = vurl->bstrVal;
  184945. *pDispParams->rgvarg->pboolVal
  184946. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  184947. : VARIANT_TRUE;
  184948. return S_OK;
  184949. }
  184950. default:
  184951. break;
  184952. }
  184953. return E_NOTIMPL;
  184954. }
  184955. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  184956. void componentPeerChanged() {}
  184957. void componentVisibilityChanged (Component&)
  184958. {
  184959. owner->visibilityChanged();
  184960. }
  184961. juce_UseDebuggingNewOperator
  184962. private:
  184963. WebBrowserComponent* const owner;
  184964. int refCount;
  184965. EventHandler (const EventHandler&);
  184966. EventHandler& operator= (const EventHandler&);
  184967. };
  184968. };
  184969. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  184970. : browser (0),
  184971. blankPageShown (false),
  184972. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  184973. {
  184974. setOpaque (true);
  184975. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  184976. }
  184977. WebBrowserComponent::~WebBrowserComponent()
  184978. {
  184979. delete browser;
  184980. }
  184981. void WebBrowserComponent::goToURL (const String& url,
  184982. const StringArray* headers,
  184983. const MemoryBlock* postData)
  184984. {
  184985. lastURL = url;
  184986. lastHeaders.clear();
  184987. if (headers != 0)
  184988. lastHeaders = *headers;
  184989. lastPostData.setSize (0);
  184990. if (postData != 0)
  184991. lastPostData = *postData;
  184992. blankPageShown = false;
  184993. browser->goToURL (url, headers, postData);
  184994. }
  184995. void WebBrowserComponent::stop()
  184996. {
  184997. if (browser->browser != 0)
  184998. browser->browser->Stop();
  184999. }
  185000. void WebBrowserComponent::goBack()
  185001. {
  185002. lastURL = String::empty;
  185003. blankPageShown = false;
  185004. if (browser->browser != 0)
  185005. browser->browser->GoBack();
  185006. }
  185007. void WebBrowserComponent::goForward()
  185008. {
  185009. lastURL = String::empty;
  185010. if (browser->browser != 0)
  185011. browser->browser->GoForward();
  185012. }
  185013. void WebBrowserComponent::refresh()
  185014. {
  185015. if (browser->browser != 0)
  185016. browser->browser->Refresh();
  185017. }
  185018. void WebBrowserComponent::paint (Graphics& g)
  185019. {
  185020. if (browser->browser == 0)
  185021. g.fillAll (Colours::white);
  185022. }
  185023. void WebBrowserComponent::checkWindowAssociation()
  185024. {
  185025. if (isShowing())
  185026. {
  185027. if (browser->browser == 0 && getPeer() != 0)
  185028. {
  185029. browser->createBrowser();
  185030. reloadLastURL();
  185031. }
  185032. else
  185033. {
  185034. if (blankPageShown)
  185035. goBack();
  185036. }
  185037. }
  185038. else
  185039. {
  185040. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185041. {
  185042. // when the component becomes invisible, some stuff like flash
  185043. // carries on playing audio, so we need to force it onto a blank
  185044. // page to avoid this..
  185045. blankPageShown = true;
  185046. browser->goToURL ("about:blank", 0, 0);
  185047. }
  185048. }
  185049. }
  185050. void WebBrowserComponent::reloadLastURL()
  185051. {
  185052. if (lastURL.isNotEmpty())
  185053. {
  185054. goToURL (lastURL, &lastHeaders, &lastPostData);
  185055. lastURL = String::empty;
  185056. }
  185057. }
  185058. void WebBrowserComponent::parentHierarchyChanged()
  185059. {
  185060. checkWindowAssociation();
  185061. }
  185062. void WebBrowserComponent::resized()
  185063. {
  185064. browser->setSize (getWidth(), getHeight());
  185065. }
  185066. void WebBrowserComponent::visibilityChanged()
  185067. {
  185068. checkWindowAssociation();
  185069. }
  185070. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185071. {
  185072. return true;
  185073. }
  185074. #endif
  185075. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185076. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185077. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185078. // compiled on its own).
  185079. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185080. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185081. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185082. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185083. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185084. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185085. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185086. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185087. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185088. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185089. #define WGL_ACCELERATION_ARB 0x2003
  185090. #define WGL_SWAP_METHOD_ARB 0x2007
  185091. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185092. #define WGL_PIXEL_TYPE_ARB 0x2013
  185093. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185094. #define WGL_COLOR_BITS_ARB 0x2014
  185095. #define WGL_RED_BITS_ARB 0x2015
  185096. #define WGL_GREEN_BITS_ARB 0x2017
  185097. #define WGL_BLUE_BITS_ARB 0x2019
  185098. #define WGL_ALPHA_BITS_ARB 0x201B
  185099. #define WGL_DEPTH_BITS_ARB 0x2022
  185100. #define WGL_STENCIL_BITS_ARB 0x2023
  185101. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185102. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185103. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185104. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185105. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185106. #define WGL_STEREO_ARB 0x2012
  185107. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185108. #define WGL_SAMPLES_ARB 0x2042
  185109. #define WGL_TYPE_RGBA_ARB 0x202B
  185110. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185111. {
  185112. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185113. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185114. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185115. else
  185116. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185117. }
  185118. class WindowedGLContext : public OpenGLContext
  185119. {
  185120. public:
  185121. WindowedGLContext (Component* const component_,
  185122. HGLRC contextToShareWith,
  185123. const OpenGLPixelFormat& pixelFormat)
  185124. : renderContext (0),
  185125. nativeWindow (0),
  185126. dc (0),
  185127. component (component_)
  185128. {
  185129. jassert (component != 0);
  185130. createNativeWindow();
  185131. // Use a default pixel format that should be supported everywhere
  185132. PIXELFORMATDESCRIPTOR pfd;
  185133. zerostruct (pfd);
  185134. pfd.nSize = sizeof (pfd);
  185135. pfd.nVersion = 1;
  185136. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185137. pfd.iPixelType = PFD_TYPE_RGBA;
  185138. pfd.cColorBits = 24;
  185139. pfd.cDepthBits = 16;
  185140. const int format = ChoosePixelFormat (dc, &pfd);
  185141. if (format != 0)
  185142. SetPixelFormat (dc, format, &pfd);
  185143. renderContext = wglCreateContext (dc);
  185144. makeActive();
  185145. setPixelFormat (pixelFormat);
  185146. if (contextToShareWith != 0 && renderContext != 0)
  185147. wglShareLists (contextToShareWith, renderContext);
  185148. }
  185149. ~WindowedGLContext()
  185150. {
  185151. makeInactive();
  185152. wglDeleteContext (renderContext);
  185153. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185154. delete nativeWindow;
  185155. }
  185156. bool makeActive() const throw()
  185157. {
  185158. jassert (renderContext != 0);
  185159. return wglMakeCurrent (dc, renderContext) != 0;
  185160. }
  185161. bool makeInactive() const throw()
  185162. {
  185163. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185164. }
  185165. bool isActive() const throw()
  185166. {
  185167. return wglGetCurrentContext() == renderContext;
  185168. }
  185169. const OpenGLPixelFormat getPixelFormat() const
  185170. {
  185171. OpenGLPixelFormat pf;
  185172. makeActive();
  185173. StringArray availableExtensions;
  185174. getWglExtensions (dc, availableExtensions);
  185175. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185176. return pf;
  185177. }
  185178. void* getRawContext() const throw()
  185179. {
  185180. return renderContext;
  185181. }
  185182. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185183. {
  185184. makeActive();
  185185. PIXELFORMATDESCRIPTOR pfd;
  185186. zerostruct (pfd);
  185187. pfd.nSize = sizeof (pfd);
  185188. pfd.nVersion = 1;
  185189. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185190. pfd.iPixelType = PFD_TYPE_RGBA;
  185191. pfd.iLayerType = PFD_MAIN_PLANE;
  185192. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185193. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185194. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185195. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185196. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185197. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185198. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185199. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185200. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185201. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185202. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185203. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185204. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185205. int format = 0;
  185206. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185207. StringArray availableExtensions;
  185208. getWglExtensions (dc, availableExtensions);
  185209. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185210. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185211. {
  185212. int attributes[64];
  185213. int n = 0;
  185214. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185215. attributes[n++] = GL_TRUE;
  185216. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185217. attributes[n++] = GL_TRUE;
  185218. attributes[n++] = WGL_ACCELERATION_ARB;
  185219. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185220. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185221. attributes[n++] = GL_TRUE;
  185222. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185223. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185224. attributes[n++] = WGL_COLOR_BITS_ARB;
  185225. attributes[n++] = pfd.cColorBits;
  185226. attributes[n++] = WGL_RED_BITS_ARB;
  185227. attributes[n++] = pixelFormat.redBits;
  185228. attributes[n++] = WGL_GREEN_BITS_ARB;
  185229. attributes[n++] = pixelFormat.greenBits;
  185230. attributes[n++] = WGL_BLUE_BITS_ARB;
  185231. attributes[n++] = pixelFormat.blueBits;
  185232. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185233. attributes[n++] = pixelFormat.alphaBits;
  185234. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185235. attributes[n++] = pixelFormat.depthBufferBits;
  185236. if (pixelFormat.stencilBufferBits > 0)
  185237. {
  185238. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185239. attributes[n++] = pixelFormat.stencilBufferBits;
  185240. }
  185241. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185242. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185243. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185244. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185245. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185246. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185247. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185248. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185249. if (availableExtensions.contains ("WGL_ARB_multisample")
  185250. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185251. {
  185252. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185253. attributes[n++] = 1;
  185254. attributes[n++] = WGL_SAMPLES_ARB;
  185255. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185256. }
  185257. attributes[n++] = 0;
  185258. UINT formatsCount;
  185259. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185260. (void) ok;
  185261. jassert (ok);
  185262. }
  185263. else
  185264. {
  185265. format = ChoosePixelFormat (dc, &pfd);
  185266. }
  185267. if (format != 0)
  185268. {
  185269. makeInactive();
  185270. // win32 can't change the pixel format of a window, so need to delete the
  185271. // old one and create a new one..
  185272. jassert (nativeWindow != 0);
  185273. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185274. delete nativeWindow;
  185275. createNativeWindow();
  185276. if (SetPixelFormat (dc, format, &pfd))
  185277. {
  185278. wglDeleteContext (renderContext);
  185279. renderContext = wglCreateContext (dc);
  185280. jassert (renderContext != 0);
  185281. return renderContext != 0;
  185282. }
  185283. }
  185284. return false;
  185285. }
  185286. void updateWindowPosition (int x, int y, int w, int h, int)
  185287. {
  185288. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185289. x, y, w, h,
  185290. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185291. }
  185292. void repaint()
  185293. {
  185294. const Rectangle<int> bounds (nativeWindow->getBounds());
  185295. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185296. }
  185297. void swapBuffers()
  185298. {
  185299. SwapBuffers (dc);
  185300. }
  185301. bool setSwapInterval (int numFramesPerSwap)
  185302. {
  185303. makeActive();
  185304. StringArray availableExtensions;
  185305. getWglExtensions (dc, availableExtensions);
  185306. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185307. return availableExtensions.contains ("WGL_EXT_swap_control")
  185308. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185309. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185310. }
  185311. int getSwapInterval() const
  185312. {
  185313. makeActive();
  185314. StringArray availableExtensions;
  185315. getWglExtensions (dc, availableExtensions);
  185316. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185317. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185318. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185319. return wglGetSwapIntervalEXT();
  185320. return 0;
  185321. }
  185322. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185323. {
  185324. jassert (isActive());
  185325. StringArray availableExtensions;
  185326. getWglExtensions (dc, availableExtensions);
  185327. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185328. int numTypes = 0;
  185329. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185330. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185331. {
  185332. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185333. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185334. jassertfalse
  185335. }
  185336. else
  185337. {
  185338. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185339. }
  185340. OpenGLPixelFormat pf;
  185341. for (int i = 0; i < numTypes; ++i)
  185342. {
  185343. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185344. {
  185345. bool alreadyListed = false;
  185346. for (int j = results.size(); --j >= 0;)
  185347. if (pf == *results.getUnchecked(j))
  185348. alreadyListed = true;
  185349. if (! alreadyListed)
  185350. results.add (new OpenGLPixelFormat (pf));
  185351. }
  185352. }
  185353. }
  185354. void* getNativeWindowHandle() const
  185355. {
  185356. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185357. }
  185358. juce_UseDebuggingNewOperator
  185359. HGLRC renderContext;
  185360. private:
  185361. Win32ComponentPeer* nativeWindow;
  185362. Component* const component;
  185363. HDC dc;
  185364. void createNativeWindow()
  185365. {
  185366. nativeWindow = new Win32ComponentPeer (component, 0);
  185367. nativeWindow->dontRepaint = true;
  185368. nativeWindow->setVisible (true);
  185369. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185370. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185371. if (peer != 0)
  185372. {
  185373. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185374. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185375. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185376. }
  185377. dc = GetDC (hwnd);
  185378. }
  185379. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185380. OpenGLPixelFormat& result,
  185381. const StringArray& availableExtensions) const throw()
  185382. {
  185383. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185384. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185385. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185386. {
  185387. int attributes[32];
  185388. int numAttributes = 0;
  185389. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185390. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185391. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185392. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185393. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185394. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185395. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185396. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185397. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185398. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185399. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185400. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185401. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185402. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185403. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185404. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185405. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185406. int values[32];
  185407. zeromem (values, sizeof (values));
  185408. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185409. {
  185410. int n = 0;
  185411. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185412. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185413. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185414. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185415. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185416. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185417. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185418. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185419. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185420. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185421. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185422. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185423. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185424. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185425. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185426. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185427. return isValidFormat;
  185428. }
  185429. else
  185430. {
  185431. jassertfalse
  185432. }
  185433. }
  185434. else
  185435. {
  185436. PIXELFORMATDESCRIPTOR pfd;
  185437. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185438. {
  185439. result.redBits = pfd.cRedBits;
  185440. result.greenBits = pfd.cGreenBits;
  185441. result.blueBits = pfd.cBlueBits;
  185442. result.alphaBits = pfd.cAlphaBits;
  185443. result.depthBufferBits = pfd.cDepthBits;
  185444. result.stencilBufferBits = pfd.cStencilBits;
  185445. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185446. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185447. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185448. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185449. result.fullSceneAntiAliasingNumSamples = 0;
  185450. return true;
  185451. }
  185452. else
  185453. {
  185454. jassertfalse
  185455. }
  185456. }
  185457. return false;
  185458. }
  185459. WindowedGLContext (const WindowedGLContext&);
  185460. WindowedGLContext& operator= (const WindowedGLContext&);
  185461. };
  185462. OpenGLContext* OpenGLComponent::createContext()
  185463. {
  185464. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185465. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185466. preferredPixelFormat));
  185467. return (c->renderContext != 0) ? c.release() : 0;
  185468. }
  185469. void* OpenGLComponent::getNativeWindowHandle() const
  185470. {
  185471. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185472. }
  185473. void juce_glViewport (const int w, const int h)
  185474. {
  185475. glViewport (0, 0, w, h);
  185476. }
  185477. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185478. OwnedArray <OpenGLPixelFormat>& results)
  185479. {
  185480. Component tempComp;
  185481. {
  185482. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185483. wc.makeActive();
  185484. wc.findAlternativeOpenGLPixelFormats (results);
  185485. }
  185486. }
  185487. #endif
  185488. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185489. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185490. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185491. // compiled on its own).
  185492. #if JUCE_INCLUDED_FILE
  185493. #if JUCE_USE_CDREADER
  185494. namespace CDReaderHelpers
  185495. {
  185496. //***************************************************************************
  185497. // %%% TARGET STATUS VALUES %%%
  185498. //***************************************************************************
  185499. #define STATUS_GOOD 0x00 // Status Good
  185500. #define STATUS_CHKCOND 0x02 // Check Condition
  185501. #define STATUS_CONDMET 0x04 // Condition Met
  185502. #define STATUS_BUSY 0x08 // Busy
  185503. #define STATUS_INTERM 0x10 // Intermediate
  185504. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185505. #define STATUS_RESCONF 0x18 // Reservation conflict
  185506. #define STATUS_COMTERM 0x22 // Command Terminated
  185507. #define STATUS_QFULL 0x28 // Queue full
  185508. //***************************************************************************
  185509. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185510. //***************************************************************************
  185511. #define MAXLUN 7 // Maximum Logical Unit Id
  185512. #define MAXTARG 7 // Maximum Target Id
  185513. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185514. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185515. //***************************************************************************
  185516. // %%% Commands for all Device Types %%%
  185517. //***************************************************************************
  185518. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185519. #define SCSI_COMPARE 0x39 // Compare (O)
  185520. #define SCSI_COPY 0x18 // Copy (O)
  185521. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185522. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185523. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185524. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185525. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185526. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185527. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185528. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185529. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185530. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185531. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185532. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185533. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185534. //***************************************************************************
  185535. // %%% Commands Unique to Direct Access Devices %%%
  185536. //***************************************************************************
  185537. #define SCSI_COMPARE 0x39 // Compare (O)
  185538. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185539. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185540. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185541. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185542. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185543. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185544. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185545. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185546. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185547. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185548. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185549. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185550. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185551. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185552. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185553. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185554. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185555. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185556. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185557. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185558. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185559. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185560. #define SCSI_VERIFY 0x2F // Verify (O)
  185561. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185562. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185563. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185564. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185565. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185566. //***************************************************************************
  185567. // %%% Commands Unique to Sequential Access Devices %%%
  185568. //***************************************************************************
  185569. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185570. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185571. #define SCSI_LOCATE 0x2B // Locate (O)
  185572. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185573. #define SCSI_READ_POS 0x34 // Read Position (O)
  185574. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185575. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185576. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185577. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185578. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185579. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185580. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185581. //***************************************************************************
  185582. // %%% Commands Unique to Printer Devices %%%
  185583. //***************************************************************************
  185584. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185585. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185586. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185587. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185588. //***************************************************************************
  185589. // %%% Commands Unique to Processor Devices %%%
  185590. //***************************************************************************
  185591. #define SCSI_RECEIVE 0x08 // Receive (O)
  185592. #define SCSI_SEND 0x0A // Send (O)
  185593. //***************************************************************************
  185594. // %%% Commands Unique to Write-Once Devices %%%
  185595. //***************************************************************************
  185596. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185597. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185598. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185599. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185600. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185601. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185602. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185603. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185604. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185605. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185606. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185607. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185608. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185609. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185610. //***************************************************************************
  185611. // %%% Commands Unique to CD-ROM Devices %%%
  185612. //***************************************************************************
  185613. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185614. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185615. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185616. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185617. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185618. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185619. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185620. #define SCSI_READHEADER 0x44 // Read Header (O)
  185621. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185622. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185623. //***************************************************************************
  185624. // %%% Commands Unique to Scanner Devices %%%
  185625. //***************************************************************************
  185626. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185627. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185628. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185629. #define SCSI_SCAN 0x1B // Scan (O)
  185630. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185631. //***************************************************************************
  185632. // %%% Commands Unique to Optical Memory Devices %%%
  185633. //***************************************************************************
  185634. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185635. //***************************************************************************
  185636. // %%% Commands Unique to Medium Changer Devices %%%
  185637. //***************************************************************************
  185638. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185639. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185640. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185641. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185642. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185643. //***************************************************************************
  185644. // %%% Commands Unique to Communication Devices %%%
  185645. //***************************************************************************
  185646. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185647. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185648. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185649. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185650. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185651. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185652. //***************************************************************************
  185653. // %%% Request Sense Data Format %%%
  185654. //***************************************************************************
  185655. typedef struct {
  185656. BYTE ErrorCode; // Error Code (70H or 71H)
  185657. BYTE SegmentNum; // Number of current segment descriptor
  185658. BYTE SenseKey; // Sense Key(See bit definitions too)
  185659. BYTE InfoByte0; // Information MSB
  185660. BYTE InfoByte1; // Information MID
  185661. BYTE InfoByte2; // Information MID
  185662. BYTE InfoByte3; // Information LSB
  185663. BYTE AddSenLen; // Additional Sense Length
  185664. BYTE ComSpecInf0; // Command Specific Information MSB
  185665. BYTE ComSpecInf1; // Command Specific Information MID
  185666. BYTE ComSpecInf2; // Command Specific Information MID
  185667. BYTE ComSpecInf3; // Command Specific Information LSB
  185668. BYTE AddSenseCode; // Additional Sense Code
  185669. BYTE AddSenQual; // Additional Sense Code Qualifier
  185670. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185671. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185672. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185673. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185674. BYTE AddSenseBytes; // Additional Sense Bytes
  185675. } SENSE_DATA_FMT;
  185676. //***************************************************************************
  185677. // %%% REQUEST SENSE ERROR CODE %%%
  185678. //***************************************************************************
  185679. #define SERROR_CURRENT 0x70 // Current Errors
  185680. #define SERROR_DEFERED 0x71 // Deferred Errors
  185681. //***************************************************************************
  185682. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185683. //***************************************************************************
  185684. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185685. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185686. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185687. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185688. //***************************************************************************
  185689. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185690. //***************************************************************************
  185691. #define KEY_NOSENSE 0x00 // No Sense
  185692. #define KEY_RECERROR 0x01 // Recovered Error
  185693. #define KEY_NOTREADY 0x02 // Not Ready
  185694. #define KEY_MEDIUMERR 0x03 // Medium Error
  185695. #define KEY_HARDERROR 0x04 // Hardware Error
  185696. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185697. #define KEY_UNITATT 0x06 // Unit Attention
  185698. #define KEY_DATAPROT 0x07 // Data Protect
  185699. #define KEY_BLANKCHK 0x08 // Blank Check
  185700. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185701. #define KEY_COPYABORT 0x0A // Copy Abort
  185702. #define KEY_EQUAL 0x0C // Equal (Search)
  185703. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185704. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185705. #define KEY_RESERVED 0x0F // Reserved
  185706. //***************************************************************************
  185707. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185708. //***************************************************************************
  185709. #define DTYPE_DASD 0x00 // Disk Device
  185710. #define DTYPE_SEQD 0x01 // Tape Device
  185711. #define DTYPE_PRNT 0x02 // Printer
  185712. #define DTYPE_PROC 0x03 // Processor
  185713. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185714. #define DTYPE_CROM 0x05 // CD-ROM device
  185715. #define DTYPE_SCAN 0x06 // Scanner device
  185716. #define DTYPE_OPTI 0x07 // Optical memory device
  185717. #define DTYPE_JUKE 0x08 // Medium Changer device
  185718. #define DTYPE_COMM 0x09 // Communications device
  185719. #define DTYPE_RESL 0x0A // Reserved (low)
  185720. #define DTYPE_RESH 0x1E // Reserved (high)
  185721. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185722. //***************************************************************************
  185723. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185724. //***************************************************************************
  185725. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185726. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185727. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185728. #define ANSI_RESLO 0x3 // Reserved (low)
  185729. #define ANSI_RESHI 0x7 // Reserved (high)
  185730. typedef struct
  185731. {
  185732. USHORT Length;
  185733. UCHAR ScsiStatus;
  185734. UCHAR PathId;
  185735. UCHAR TargetId;
  185736. UCHAR Lun;
  185737. UCHAR CdbLength;
  185738. UCHAR SenseInfoLength;
  185739. UCHAR DataIn;
  185740. ULONG DataTransferLength;
  185741. ULONG TimeOutValue;
  185742. ULONG DataBufferOffset;
  185743. ULONG SenseInfoOffset;
  185744. UCHAR Cdb[16];
  185745. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185746. typedef struct
  185747. {
  185748. USHORT Length;
  185749. UCHAR ScsiStatus;
  185750. UCHAR PathId;
  185751. UCHAR TargetId;
  185752. UCHAR Lun;
  185753. UCHAR CdbLength;
  185754. UCHAR SenseInfoLength;
  185755. UCHAR DataIn;
  185756. ULONG DataTransferLength;
  185757. ULONG TimeOutValue;
  185758. PVOID DataBuffer;
  185759. ULONG SenseInfoOffset;
  185760. UCHAR Cdb[16];
  185761. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185762. typedef struct
  185763. {
  185764. SCSI_PASS_THROUGH_DIRECT spt;
  185765. ULONG Filler;
  185766. UCHAR ucSenseBuf[32];
  185767. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185768. typedef struct
  185769. {
  185770. ULONG Length;
  185771. UCHAR PortNumber;
  185772. UCHAR PathId;
  185773. UCHAR TargetId;
  185774. UCHAR Lun;
  185775. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185776. #define METHOD_BUFFERED 0
  185777. #define METHOD_IN_DIRECT 1
  185778. #define METHOD_OUT_DIRECT 2
  185779. #define METHOD_NEITHER 3
  185780. #define FILE_ANY_ACCESS 0
  185781. #ifndef FILE_READ_ACCESS
  185782. #define FILE_READ_ACCESS (0x0001)
  185783. #endif
  185784. #ifndef FILE_WRITE_ACCESS
  185785. #define FILE_WRITE_ACCESS (0x0002)
  185786. #endif
  185787. #define IOCTL_SCSI_BASE 0x00000004
  185788. #define SCSI_IOCTL_DATA_OUT 0
  185789. #define SCSI_IOCTL_DATA_IN 1
  185790. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185791. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185792. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185793. )
  185794. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185795. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185796. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185797. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185798. #define SENSE_LEN 14
  185799. #define SRB_DIR_SCSI 0x00
  185800. #define SRB_POSTING 0x01
  185801. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185802. #define SRB_DIR_IN 0x08
  185803. #define SRB_DIR_OUT 0x10
  185804. #define SRB_EVENT_NOTIFY 0x40
  185805. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185806. #define MAX_SRB_TIMEOUT 1080001u
  185807. #define DEFAULT_SRB_TIMEOUT 1080001u
  185808. #define SC_HA_INQUIRY 0x00
  185809. #define SC_GET_DEV_TYPE 0x01
  185810. #define SC_EXEC_SCSI_CMD 0x02
  185811. #define SC_ABORT_SRB 0x03
  185812. #define SC_RESET_DEV 0x04
  185813. #define SC_SET_HA_PARMS 0x05
  185814. #define SC_GET_DISK_INFO 0x06
  185815. #define SC_RESCAN_SCSI_BUS 0x07
  185816. #define SC_GETSET_TIMEOUTS 0x08
  185817. #define SS_PENDING 0x00
  185818. #define SS_COMP 0x01
  185819. #define SS_ABORTED 0x02
  185820. #define SS_ABORT_FAIL 0x03
  185821. #define SS_ERR 0x04
  185822. #define SS_INVALID_CMD 0x80
  185823. #define SS_INVALID_HA 0x81
  185824. #define SS_NO_DEVICE 0x82
  185825. #define SS_INVALID_SRB 0xE0
  185826. #define SS_OLD_MANAGER 0xE1
  185827. #define SS_BUFFER_ALIGN 0xE1
  185828. #define SS_ILLEGAL_MODE 0xE2
  185829. #define SS_NO_ASPI 0xE3
  185830. #define SS_FAILED_INIT 0xE4
  185831. #define SS_ASPI_IS_BUSY 0xE5
  185832. #define SS_BUFFER_TO_BIG 0xE6
  185833. #define SS_BUFFER_TOO_BIG 0xE6
  185834. #define SS_MISMATCHED_COMPONENTS 0xE7
  185835. #define SS_NO_ADAPTERS 0xE8
  185836. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185837. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185838. #define SS_BAD_INSTALL 0xEB
  185839. #define HASTAT_OK 0x00
  185840. #define HASTAT_SEL_TO 0x11
  185841. #define HASTAT_DO_DU 0x12
  185842. #define HASTAT_BUS_FREE 0x13
  185843. #define HASTAT_PHASE_ERR 0x14
  185844. #define HASTAT_TIMEOUT 0x09
  185845. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185846. #define HASTAT_MESSAGE_REJECT 0x0D
  185847. #define HASTAT_BUS_RESET 0x0E
  185848. #define HASTAT_PARITY_ERROR 0x0F
  185849. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185850. #define PACKED
  185851. #pragma pack(1)
  185852. typedef struct
  185853. {
  185854. BYTE SRB_Cmd;
  185855. BYTE SRB_Status;
  185856. BYTE SRB_HaID;
  185857. BYTE SRB_Flags;
  185858. DWORD SRB_Hdr_Rsvd;
  185859. BYTE HA_Count;
  185860. BYTE HA_SCSI_ID;
  185861. BYTE HA_ManagerId[16];
  185862. BYTE HA_Identifier[16];
  185863. BYTE HA_Unique[16];
  185864. WORD HA_Rsvd1;
  185865. BYTE pad[20];
  185866. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185867. typedef struct
  185868. {
  185869. BYTE SRB_Cmd;
  185870. BYTE SRB_Status;
  185871. BYTE SRB_HaID;
  185872. BYTE SRB_Flags;
  185873. DWORD SRB_Hdr_Rsvd;
  185874. BYTE SRB_Target;
  185875. BYTE SRB_Lun;
  185876. BYTE SRB_DeviceType;
  185877. BYTE SRB_Rsvd1;
  185878. BYTE pad[68];
  185879. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185880. typedef struct
  185881. {
  185882. BYTE SRB_Cmd;
  185883. BYTE SRB_Status;
  185884. BYTE SRB_HaID;
  185885. BYTE SRB_Flags;
  185886. DWORD SRB_Hdr_Rsvd;
  185887. BYTE SRB_Target;
  185888. BYTE SRB_Lun;
  185889. WORD SRB_Rsvd1;
  185890. DWORD SRB_BufLen;
  185891. BYTE FAR *SRB_BufPointer;
  185892. BYTE SRB_SenseLen;
  185893. BYTE SRB_CDBLen;
  185894. BYTE SRB_HaStat;
  185895. BYTE SRB_TargStat;
  185896. VOID FAR *SRB_PostProc;
  185897. BYTE SRB_Rsvd2[20];
  185898. BYTE CDBByte[16];
  185899. BYTE SenseArea[SENSE_LEN+2];
  185900. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185901. typedef struct
  185902. {
  185903. BYTE SRB_Cmd;
  185904. BYTE SRB_Status;
  185905. BYTE SRB_HaId;
  185906. BYTE SRB_Flags;
  185907. DWORD SRB_Hdr_Rsvd;
  185908. } PACKED SRB, *PSRB, FAR *LPSRB;
  185909. #pragma pack()
  185910. struct CDDeviceInfo
  185911. {
  185912. char vendor[9];
  185913. char productId[17];
  185914. char rev[5];
  185915. char vendorSpec[21];
  185916. BYTE ha;
  185917. BYTE tgt;
  185918. BYTE lun;
  185919. char scsiDriveLetter; // will be 0 if not using scsi
  185920. };
  185921. class CDReadBuffer
  185922. {
  185923. public:
  185924. int startFrame;
  185925. int numFrames;
  185926. int dataStartOffset;
  185927. int dataLength;
  185928. BYTE* buffer;
  185929. int bufferSize;
  185930. int index;
  185931. bool wantsIndex;
  185932. CDReadBuffer (const int numberOfFrames)
  185933. : startFrame (0),
  185934. numFrames (0),
  185935. dataStartOffset (0),
  185936. dataLength (0),
  185937. index (0),
  185938. wantsIndex (false)
  185939. {
  185940. bufferSize = 2352 * numberOfFrames;
  185941. buffer = (BYTE*) juce_malloc (bufferSize);
  185942. }
  185943. ~CDReadBuffer()
  185944. {
  185945. juce_free (buffer);
  185946. }
  185947. bool isZero() const
  185948. {
  185949. BYTE* p = buffer + dataStartOffset;
  185950. for (int i = dataLength; --i >= 0;)
  185951. if (*p++ != 0)
  185952. return false;
  185953. return true;
  185954. }
  185955. };
  185956. class CDDeviceHandle;
  185957. class CDController
  185958. {
  185959. public:
  185960. CDController();
  185961. virtual ~CDController();
  185962. virtual bool read (CDReadBuffer* t) = 0;
  185963. virtual void shutDown();
  185964. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  185965. int getLastIndex();
  185966. public:
  185967. bool initialised;
  185968. CDDeviceHandle* deviceInfo;
  185969. int framesToCheck, framesOverlap;
  185970. void prepare (SRB_ExecSCSICmd& s);
  185971. void perform (SRB_ExecSCSICmd& s);
  185972. void setPaused (bool paused);
  185973. };
  185974. #pragma pack(1)
  185975. struct TOCTRACK
  185976. {
  185977. BYTE rsvd;
  185978. BYTE ADR;
  185979. BYTE trackNumber;
  185980. BYTE rsvd2;
  185981. BYTE addr[4];
  185982. };
  185983. struct TOC
  185984. {
  185985. WORD tocLen;
  185986. BYTE firstTrack;
  185987. BYTE lastTrack;
  185988. TOCTRACK tracks[100];
  185989. };
  185990. #pragma pack()
  185991. enum
  185992. {
  185993. READTYPE_ANY = 0,
  185994. READTYPE_ATAPI1 = 1,
  185995. READTYPE_ATAPI2 = 2,
  185996. READTYPE_READ6 = 3,
  185997. READTYPE_READ10 = 4,
  185998. READTYPE_READ_D8 = 5,
  185999. READTYPE_READ_D4 = 6,
  186000. READTYPE_READ_D4_1 = 7,
  186001. READTYPE_READ10_2 = 8
  186002. };
  186003. class CDDeviceHandle
  186004. {
  186005. public:
  186006. CDDeviceHandle (const CDDeviceInfo* const device)
  186007. : scsiHandle (0),
  186008. readType (READTYPE_ANY),
  186009. controller (0)
  186010. {
  186011. memcpy (&info, device, sizeof (info));
  186012. }
  186013. ~CDDeviceHandle()
  186014. {
  186015. if (controller != 0)
  186016. {
  186017. controller->shutDown();
  186018. controller = 0;
  186019. }
  186020. if (scsiHandle != 0)
  186021. CloseHandle (scsiHandle);
  186022. }
  186023. bool readTOC (TOC* lpToc, bool useMSF);
  186024. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186025. void openDrawer (bool shouldBeOpen);
  186026. CDDeviceInfo info;
  186027. HANDLE scsiHandle;
  186028. BYTE readType;
  186029. private:
  186030. ScopedPointer<CDController> controller;
  186031. bool testController (const int readType,
  186032. CDController* const newController,
  186033. CDReadBuffer* const bufferToUse);
  186034. };
  186035. DWORD (*fGetASPI32SupportInfo)(void);
  186036. DWORD (*fSendASPI32Command)(LPSRB);
  186037. static HINSTANCE winAspiLib = 0;
  186038. static bool usingScsi = false;
  186039. static bool initialised = false;
  186040. static bool InitialiseCDRipper()
  186041. {
  186042. if (! initialised)
  186043. {
  186044. initialised = true;
  186045. OSVERSIONINFO info;
  186046. info.dwOSVersionInfoSize = sizeof (info);
  186047. GetVersionEx (&info);
  186048. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186049. if (! usingScsi)
  186050. {
  186051. fGetASPI32SupportInfo = 0;
  186052. fSendASPI32Command = 0;
  186053. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186054. if (winAspiLib != 0)
  186055. {
  186056. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186057. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186058. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186059. return false;
  186060. }
  186061. else
  186062. {
  186063. usingScsi = true;
  186064. }
  186065. }
  186066. }
  186067. return true;
  186068. }
  186069. static void DeinitialiseCDRipper()
  186070. {
  186071. if (winAspiLib != 0)
  186072. {
  186073. fGetASPI32SupportInfo = 0;
  186074. fSendASPI32Command = 0;
  186075. FreeLibrary (winAspiLib);
  186076. winAspiLib = 0;
  186077. }
  186078. initialised = false;
  186079. }
  186080. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186081. {
  186082. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186083. OSVERSIONINFO info;
  186084. info.dwOSVersionInfoSize = sizeof (info);
  186085. GetVersionEx (&info);
  186086. DWORD flags = GENERIC_READ;
  186087. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186088. flags = GENERIC_READ | GENERIC_WRITE;
  186089. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186090. if (h == INVALID_HANDLE_VALUE)
  186091. {
  186092. flags ^= GENERIC_WRITE;
  186093. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186094. }
  186095. return h;
  186096. }
  186097. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186098. const char driveLetter,
  186099. HANDLE& deviceHandle,
  186100. const bool retryOnFailure = true)
  186101. {
  186102. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186103. zerostruct (s);
  186104. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186105. s.spt.CdbLength = srb->SRB_CDBLen;
  186106. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186107. ? SCSI_IOCTL_DATA_IN
  186108. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186109. ? SCSI_IOCTL_DATA_OUT
  186110. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186111. s.spt.DataTransferLength = srb->SRB_BufLen;
  186112. s.spt.TimeOutValue = 5;
  186113. s.spt.DataBuffer = srb->SRB_BufPointer;
  186114. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186115. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186116. srb->SRB_Status = SS_ERR;
  186117. srb->SRB_TargStat = 0x0004;
  186118. DWORD bytesReturned = 0;
  186119. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186120. &s, sizeof (s),
  186121. &s, sizeof (s),
  186122. &bytesReturned, 0) != 0)
  186123. {
  186124. srb->SRB_Status = SS_COMP;
  186125. }
  186126. else if (retryOnFailure)
  186127. {
  186128. const DWORD error = GetLastError();
  186129. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186130. {
  186131. if (error != ERROR_INVALID_HANDLE)
  186132. CloseHandle (deviceHandle);
  186133. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186134. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186135. }
  186136. }
  186137. return srb->SRB_Status;
  186138. }
  186139. // Controller types..
  186140. class ControllerType1 : public CDController
  186141. {
  186142. public:
  186143. ControllerType1() {}
  186144. ~ControllerType1() {}
  186145. bool read (CDReadBuffer* rb)
  186146. {
  186147. if (rb->numFrames * 2352 > rb->bufferSize)
  186148. return false;
  186149. SRB_ExecSCSICmd s;
  186150. prepare (s);
  186151. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186152. s.SRB_BufLen = rb->bufferSize;
  186153. s.SRB_BufPointer = rb->buffer;
  186154. s.SRB_CDBLen = 12;
  186155. s.CDBByte[0] = 0xBE;
  186156. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186157. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186158. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186159. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186160. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186161. perform (s);
  186162. if (s.SRB_Status != SS_COMP)
  186163. return false;
  186164. rb->dataLength = rb->numFrames * 2352;
  186165. rb->dataStartOffset = 0;
  186166. return true;
  186167. }
  186168. };
  186169. class ControllerType2 : public CDController
  186170. {
  186171. public:
  186172. ControllerType2() {}
  186173. ~ControllerType2() {}
  186174. void shutDown()
  186175. {
  186176. if (initialised)
  186177. {
  186178. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186179. SRB_ExecSCSICmd s;
  186180. prepare (s);
  186181. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186182. s.SRB_BufLen = 0x0C;
  186183. s.SRB_BufPointer = bufPointer;
  186184. s.SRB_CDBLen = 6;
  186185. s.CDBByte[0] = 0x15;
  186186. s.CDBByte[4] = 0x0C;
  186187. perform (s);
  186188. }
  186189. }
  186190. bool init()
  186191. {
  186192. SRB_ExecSCSICmd s;
  186193. s.SRB_Status = SS_ERR;
  186194. if (deviceInfo->readType == READTYPE_READ10_2)
  186195. {
  186196. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186197. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186198. for (int i = 0; i < 2; ++i)
  186199. {
  186200. prepare (s);
  186201. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186202. s.SRB_BufLen = 0x14;
  186203. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186204. s.SRB_CDBLen = 6;
  186205. s.CDBByte[0] = 0x15;
  186206. s.CDBByte[1] = 0x10;
  186207. s.CDBByte[4] = 0x14;
  186208. perform (s);
  186209. if (s.SRB_Status != SS_COMP)
  186210. return false;
  186211. }
  186212. }
  186213. else
  186214. {
  186215. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186216. prepare (s);
  186217. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186218. s.SRB_BufLen = 0x0C;
  186219. s.SRB_BufPointer = bufPointer;
  186220. s.SRB_CDBLen = 6;
  186221. s.CDBByte[0] = 0x15;
  186222. s.CDBByte[4] = 0x0C;
  186223. perform (s);
  186224. }
  186225. return s.SRB_Status == SS_COMP;
  186226. }
  186227. bool read (CDReadBuffer* rb)
  186228. {
  186229. if (rb->numFrames * 2352 > rb->bufferSize)
  186230. return false;
  186231. if (!initialised)
  186232. {
  186233. initialised = init();
  186234. if (!initialised)
  186235. return false;
  186236. }
  186237. SRB_ExecSCSICmd s;
  186238. prepare (s);
  186239. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186240. s.SRB_BufLen = rb->bufferSize;
  186241. s.SRB_BufPointer = rb->buffer;
  186242. s.SRB_CDBLen = 10;
  186243. s.CDBByte[0] = 0x28;
  186244. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186245. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186246. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186247. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186248. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186249. perform (s);
  186250. if (s.SRB_Status != SS_COMP)
  186251. return false;
  186252. rb->dataLength = rb->numFrames * 2352;
  186253. rb->dataStartOffset = 0;
  186254. return true;
  186255. }
  186256. };
  186257. class ControllerType3 : public CDController
  186258. {
  186259. public:
  186260. ControllerType3() {}
  186261. ~ControllerType3() {}
  186262. bool read (CDReadBuffer* rb)
  186263. {
  186264. if (rb->numFrames * 2352 > rb->bufferSize)
  186265. return false;
  186266. if (!initialised)
  186267. {
  186268. setPaused (false);
  186269. initialised = true;
  186270. }
  186271. SRB_ExecSCSICmd s;
  186272. prepare (s);
  186273. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186274. s.SRB_BufLen = rb->numFrames * 2352;
  186275. s.SRB_BufPointer = rb->buffer;
  186276. s.SRB_CDBLen = 12;
  186277. s.CDBByte[0] = 0xD8;
  186278. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186279. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186280. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186281. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186282. perform (s);
  186283. if (s.SRB_Status != SS_COMP)
  186284. return false;
  186285. rb->dataLength = rb->numFrames * 2352;
  186286. rb->dataStartOffset = 0;
  186287. return true;
  186288. }
  186289. };
  186290. class ControllerType4 : public CDController
  186291. {
  186292. public:
  186293. ControllerType4() {}
  186294. ~ControllerType4() {}
  186295. bool selectD4Mode()
  186296. {
  186297. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186298. SRB_ExecSCSICmd s;
  186299. prepare (s);
  186300. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186301. s.SRB_CDBLen = 6;
  186302. s.SRB_BufLen = 12;
  186303. s.SRB_BufPointer = bufPointer;
  186304. s.CDBByte[0] = 0x15;
  186305. s.CDBByte[1] = 0x10;
  186306. s.CDBByte[4] = 0x08;
  186307. perform (s);
  186308. return s.SRB_Status == SS_COMP;
  186309. }
  186310. bool read (CDReadBuffer* rb)
  186311. {
  186312. if (rb->numFrames * 2352 > rb->bufferSize)
  186313. return false;
  186314. if (!initialised)
  186315. {
  186316. setPaused (true);
  186317. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186318. selectD4Mode();
  186319. initialised = true;
  186320. }
  186321. SRB_ExecSCSICmd s;
  186322. prepare (s);
  186323. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186324. s.SRB_BufLen = rb->bufferSize;
  186325. s.SRB_BufPointer = rb->buffer;
  186326. s.SRB_CDBLen = 10;
  186327. s.CDBByte[0] = 0xD4;
  186328. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186329. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186330. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186331. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186332. perform (s);
  186333. if (s.SRB_Status != SS_COMP)
  186334. return false;
  186335. rb->dataLength = rb->numFrames * 2352;
  186336. rb->dataStartOffset = 0;
  186337. return true;
  186338. }
  186339. };
  186340. CDController::CDController() : initialised (false)
  186341. {
  186342. }
  186343. CDController::~CDController()
  186344. {
  186345. }
  186346. void CDController::prepare (SRB_ExecSCSICmd& s)
  186347. {
  186348. zerostruct (s);
  186349. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186350. s.SRB_HaID = deviceInfo->info.ha;
  186351. s.SRB_Target = deviceInfo->info.tgt;
  186352. s.SRB_Lun = deviceInfo->info.lun;
  186353. s.SRB_SenseLen = SENSE_LEN;
  186354. }
  186355. void CDController::perform (SRB_ExecSCSICmd& s)
  186356. {
  186357. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186358. s.SRB_PostProc = event;
  186359. ResetEvent (event);
  186360. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186361. deviceInfo->info.scsiDriveLetter,
  186362. deviceInfo->scsiHandle)
  186363. : fSendASPI32Command ((LPSRB)&s);
  186364. if (status == SS_PENDING)
  186365. WaitForSingleObject (event, 4000);
  186366. CloseHandle (event);
  186367. }
  186368. void CDController::setPaused (bool paused)
  186369. {
  186370. SRB_ExecSCSICmd s;
  186371. prepare (s);
  186372. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186373. s.SRB_CDBLen = 10;
  186374. s.CDBByte[0] = 0x4B;
  186375. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186376. perform (s);
  186377. }
  186378. void CDController::shutDown()
  186379. {
  186380. }
  186381. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186382. {
  186383. if (overlapBuffer != 0)
  186384. {
  186385. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186386. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186387. if (doJitter
  186388. && overlapBuffer->startFrame > 0
  186389. && overlapBuffer->numFrames > 0
  186390. && overlapBuffer->dataLength > 0)
  186391. {
  186392. const int numFrames = rb->numFrames;
  186393. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186394. {
  186395. rb->startFrame -= framesOverlap;
  186396. if (framesToCheck < framesOverlap
  186397. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186398. rb->numFrames += framesOverlap;
  186399. }
  186400. else
  186401. {
  186402. overlapBuffer->dataLength = 0;
  186403. overlapBuffer->startFrame = 0;
  186404. overlapBuffer->numFrames = 0;
  186405. }
  186406. }
  186407. if (! read (rb))
  186408. return false;
  186409. if (doJitter)
  186410. {
  186411. const int checkLen = framesToCheck * 2352;
  186412. const int maxToCheck = rb->dataLength - checkLen;
  186413. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186414. return true;
  186415. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186416. bool found = false;
  186417. for (int i = 0; i < maxToCheck; ++i)
  186418. {
  186419. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186420. {
  186421. i += checkLen;
  186422. rb->dataStartOffset = i;
  186423. rb->dataLength -= i;
  186424. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186425. found = true;
  186426. break;
  186427. }
  186428. }
  186429. rb->numFrames = rb->dataLength / 2352;
  186430. rb->dataLength = 2352 * rb->numFrames;
  186431. if (!found)
  186432. return false;
  186433. }
  186434. if (canDoJitter)
  186435. {
  186436. memcpy (overlapBuffer->buffer,
  186437. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186438. 2352 * framesToCheck);
  186439. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186440. overlapBuffer->numFrames = framesToCheck;
  186441. overlapBuffer->dataLength = 2352 * framesToCheck;
  186442. overlapBuffer->dataStartOffset = 0;
  186443. }
  186444. else
  186445. {
  186446. overlapBuffer->startFrame = 0;
  186447. overlapBuffer->numFrames = 0;
  186448. overlapBuffer->dataLength = 0;
  186449. }
  186450. return true;
  186451. }
  186452. else
  186453. {
  186454. return read (rb);
  186455. }
  186456. }
  186457. int CDController::getLastIndex()
  186458. {
  186459. char qdata[100];
  186460. SRB_ExecSCSICmd s;
  186461. prepare (s);
  186462. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186463. s.SRB_BufLen = sizeof (qdata);
  186464. s.SRB_BufPointer = (BYTE*)qdata;
  186465. s.SRB_CDBLen = 12;
  186466. s.CDBByte[0] = 0x42;
  186467. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186468. s.CDBByte[2] = 64;
  186469. s.CDBByte[3] = 1; // get current position
  186470. s.CDBByte[7] = 0;
  186471. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186472. perform (s);
  186473. if (s.SRB_Status == SS_COMP)
  186474. return qdata[7];
  186475. return 0;
  186476. }
  186477. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186478. {
  186479. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186480. SRB_ExecSCSICmd s;
  186481. zerostruct (s);
  186482. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186483. s.SRB_HaID = info.ha;
  186484. s.SRB_Target = info.tgt;
  186485. s.SRB_Lun = info.lun;
  186486. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186487. s.SRB_BufLen = 0x324;
  186488. s.SRB_BufPointer = (BYTE*)lpToc;
  186489. s.SRB_SenseLen = 0x0E;
  186490. s.SRB_CDBLen = 0x0A;
  186491. s.SRB_PostProc = event;
  186492. s.CDBByte[0] = 0x43;
  186493. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186494. s.CDBByte[7] = 0x03;
  186495. s.CDBByte[8] = 0x24;
  186496. ResetEvent (event);
  186497. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186498. : fSendASPI32Command ((LPSRB)&s);
  186499. if (status == SS_PENDING)
  186500. WaitForSingleObject (event, 4000);
  186501. CloseHandle (event);
  186502. return (s.SRB_Status == SS_COMP);
  186503. }
  186504. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186505. CDReadBuffer* const overlapBuffer)
  186506. {
  186507. if (controller == 0)
  186508. {
  186509. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186510. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186511. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186512. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186513. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186514. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186515. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186516. }
  186517. buffer->index = 0;
  186518. if ((controller != 0)
  186519. && controller->readAudio (buffer, overlapBuffer))
  186520. {
  186521. if (buffer->wantsIndex)
  186522. buffer->index = controller->getLastIndex();
  186523. return true;
  186524. }
  186525. return false;
  186526. }
  186527. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186528. {
  186529. if (shouldBeOpen)
  186530. {
  186531. if (controller != 0)
  186532. {
  186533. controller->shutDown();
  186534. controller = 0;
  186535. }
  186536. if (scsiHandle != 0)
  186537. {
  186538. CloseHandle (scsiHandle);
  186539. scsiHandle = 0;
  186540. }
  186541. }
  186542. SRB_ExecSCSICmd s;
  186543. zerostruct (s);
  186544. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186545. s.SRB_HaID = info.ha;
  186546. s.SRB_Target = info.tgt;
  186547. s.SRB_Lun = info.lun;
  186548. s.SRB_SenseLen = SENSE_LEN;
  186549. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186550. s.SRB_BufLen = 0;
  186551. s.SRB_BufPointer = 0;
  186552. s.SRB_CDBLen = 12;
  186553. s.CDBByte[0] = 0x1b;
  186554. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186555. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186556. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186557. s.SRB_PostProc = event;
  186558. ResetEvent (event);
  186559. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186560. : fSendASPI32Command ((LPSRB)&s);
  186561. if (status == SS_PENDING)
  186562. WaitForSingleObject (event, 4000);
  186563. CloseHandle (event);
  186564. }
  186565. bool CDDeviceHandle::testController (const int type,
  186566. CDController* const newController,
  186567. CDReadBuffer* const rb)
  186568. {
  186569. controller = newController;
  186570. readType = (BYTE)type;
  186571. controller->deviceInfo = this;
  186572. controller->framesToCheck = 1;
  186573. controller->framesOverlap = 3;
  186574. bool passed = false;
  186575. memset (rb->buffer, 0xcd, rb->bufferSize);
  186576. if (controller->read (rb))
  186577. {
  186578. passed = true;
  186579. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186580. int wrong = 0;
  186581. for (int i = rb->dataLength / 4; --i >= 0;)
  186582. {
  186583. if (*p++ == (int) 0xcdcdcdcd)
  186584. {
  186585. if (++wrong == 4)
  186586. {
  186587. passed = false;
  186588. break;
  186589. }
  186590. }
  186591. else
  186592. {
  186593. wrong = 0;
  186594. }
  186595. }
  186596. }
  186597. if (! passed)
  186598. {
  186599. controller->shutDown();
  186600. controller = 0;
  186601. }
  186602. return passed;
  186603. }
  186604. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186605. {
  186606. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186607. const int bufSize = 128;
  186608. BYTE buffer[bufSize];
  186609. zeromem (buffer, bufSize);
  186610. SRB_ExecSCSICmd s;
  186611. zerostruct (s);
  186612. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186613. s.SRB_HaID = ha;
  186614. s.SRB_Target = tgt;
  186615. s.SRB_Lun = lun;
  186616. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186617. s.SRB_BufLen = bufSize;
  186618. s.SRB_BufPointer = buffer;
  186619. s.SRB_SenseLen = SENSE_LEN;
  186620. s.SRB_CDBLen = 6;
  186621. s.SRB_PostProc = event;
  186622. s.CDBByte[0] = SCSI_INQUIRY;
  186623. s.CDBByte[4] = 100;
  186624. ResetEvent (event);
  186625. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186626. WaitForSingleObject (event, 4000);
  186627. CloseHandle (event);
  186628. if (s.SRB_Status == SS_COMP)
  186629. {
  186630. memcpy (dev->vendor, &buffer[8], 8);
  186631. memcpy (dev->productId, &buffer[16], 16);
  186632. memcpy (dev->rev, &buffer[32], 4);
  186633. memcpy (dev->vendorSpec, &buffer[36], 20);
  186634. }
  186635. }
  186636. static int FindCDDevices (CDDeviceInfo* const list,
  186637. int maxItems)
  186638. {
  186639. int count = 0;
  186640. if (usingScsi)
  186641. {
  186642. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186643. {
  186644. TCHAR drivePath[8];
  186645. drivePath[0] = driveLetter;
  186646. drivePath[1] = ':';
  186647. drivePath[2] = '\\';
  186648. drivePath[3] = 0;
  186649. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186650. {
  186651. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186652. if (h != INVALID_HANDLE_VALUE)
  186653. {
  186654. BYTE buffer[100], passThroughStruct[1024];
  186655. zeromem (buffer, sizeof (buffer));
  186656. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186657. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186658. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186659. p->spt.CdbLength = 6;
  186660. p->spt.SenseInfoLength = 24;
  186661. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186662. p->spt.DataTransferLength = 100;
  186663. p->spt.TimeOutValue = 2;
  186664. p->spt.DataBuffer = buffer;
  186665. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186666. p->spt.Cdb[0] = 0x12;
  186667. p->spt.Cdb[4] = 100;
  186668. DWORD bytesReturned = 0;
  186669. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186670. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186671. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186672. &bytesReturned, 0) != 0)
  186673. {
  186674. zeromem (&list[count], sizeof (CDDeviceInfo));
  186675. list[count].scsiDriveLetter = driveLetter;
  186676. memcpy (list[count].vendor, &buffer[8], 8);
  186677. memcpy (list[count].productId, &buffer[16], 16);
  186678. memcpy (list[count].rev, &buffer[32], 4);
  186679. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186680. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186681. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186682. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186683. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186684. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186685. &bytesReturned, 0) != 0)
  186686. {
  186687. list[count].ha = scsiAddr->PortNumber;
  186688. list[count].tgt = scsiAddr->TargetId;
  186689. list[count].lun = scsiAddr->Lun;
  186690. ++count;
  186691. }
  186692. }
  186693. CloseHandle (h);
  186694. }
  186695. }
  186696. }
  186697. }
  186698. else
  186699. {
  186700. const DWORD d = fGetASPI32SupportInfo();
  186701. BYTE status = HIBYTE (LOWORD (d));
  186702. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186703. return 0;
  186704. const int numAdapters = LOBYTE (LOWORD (d));
  186705. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186706. {
  186707. SRB_HAInquiry s;
  186708. zerostruct (s);
  186709. s.SRB_Cmd = SC_HA_INQUIRY;
  186710. s.SRB_HaID = ha;
  186711. fSendASPI32Command ((LPSRB)&s);
  186712. if (s.SRB_Status == SS_COMP)
  186713. {
  186714. maxItems = (int)s.HA_Unique[3];
  186715. if (maxItems == 0)
  186716. maxItems = 8;
  186717. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186718. {
  186719. for (BYTE lun = 0; lun < 8; ++lun)
  186720. {
  186721. SRB_GDEVBlock sb;
  186722. zerostruct (sb);
  186723. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186724. sb.SRB_HaID = ha;
  186725. sb.SRB_Target = tgt;
  186726. sb.SRB_Lun = lun;
  186727. fSendASPI32Command ((LPSRB) &sb);
  186728. if (sb.SRB_Status == SS_COMP
  186729. && sb.SRB_DeviceType == DTYPE_CROM)
  186730. {
  186731. zeromem (&list[count], sizeof (CDDeviceInfo));
  186732. list[count].ha = ha;
  186733. list[count].tgt = tgt;
  186734. list[count].lun = lun;
  186735. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186736. ++count;
  186737. }
  186738. }
  186739. }
  186740. }
  186741. }
  186742. }
  186743. return count;
  186744. }
  186745. static int ripperUsers = 0;
  186746. static bool initialisedOk = false;
  186747. class DeinitialiseTimer : private Timer,
  186748. private DeletedAtShutdown
  186749. {
  186750. DeinitialiseTimer (const DeinitialiseTimer&);
  186751. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186752. public:
  186753. DeinitialiseTimer()
  186754. {
  186755. startTimer (4000);
  186756. }
  186757. ~DeinitialiseTimer()
  186758. {
  186759. if (--ripperUsers == 0)
  186760. DeinitialiseCDRipper();
  186761. }
  186762. void timerCallback()
  186763. {
  186764. delete this;
  186765. }
  186766. juce_UseDebuggingNewOperator
  186767. };
  186768. static void incUserCount()
  186769. {
  186770. if (ripperUsers++ == 0)
  186771. initialisedOk = InitialiseCDRipper();
  186772. }
  186773. static void decUserCount()
  186774. {
  186775. new DeinitialiseTimer();
  186776. }
  186777. struct CDDeviceWrapper
  186778. {
  186779. ScopedPointer<CDDeviceHandle> cdH;
  186780. ScopedPointer<CDReadBuffer> overlapBuffer;
  186781. bool jitter;
  186782. };
  186783. static int getAddressOf (const TOCTRACK* const t)
  186784. {
  186785. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186786. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186787. }
  186788. static int getMSFAddressOf (const TOCTRACK* const t)
  186789. {
  186790. return 60 * t->addr[1] + t->addr[2];
  186791. }
  186792. static const int samplesPerFrame = 44100 / 75;
  186793. static const int bytesPerFrame = samplesPerFrame * 4;
  186794. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186795. {
  186796. SRB_GDEVBlock s;
  186797. zerostruct (s);
  186798. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186799. s.SRB_HaID = device->ha;
  186800. s.SRB_Target = device->tgt;
  186801. s.SRB_Lun = device->lun;
  186802. if (usingScsi)
  186803. {
  186804. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186805. if (h != INVALID_HANDLE_VALUE)
  186806. {
  186807. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186808. cdh->scsiHandle = h;
  186809. return cdh;
  186810. }
  186811. }
  186812. else
  186813. {
  186814. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186815. && s.SRB_DeviceType == DTYPE_CROM)
  186816. {
  186817. return new CDDeviceHandle (device);
  186818. }
  186819. }
  186820. return 0;
  186821. }
  186822. }
  186823. const StringArray AudioCDReader::getAvailableCDNames()
  186824. {
  186825. using namespace CDReaderHelpers;
  186826. StringArray results;
  186827. incUserCount();
  186828. if (initialisedOk)
  186829. {
  186830. CDDeviceInfo list[8];
  186831. const int num = FindCDDevices (list, 8);
  186832. decUserCount();
  186833. for (int i = 0; i < num; ++i)
  186834. {
  186835. String s;
  186836. if (list[i].scsiDriveLetter > 0)
  186837. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186838. s << String (list[i].vendor).trim()
  186839. << ' ' << String (list[i].productId).trim()
  186840. << ' ' << String (list[i].rev).trim();
  186841. results.add (s);
  186842. }
  186843. }
  186844. return results;
  186845. }
  186846. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186847. {
  186848. using namespace CDReaderHelpers;
  186849. incUserCount();
  186850. if (initialisedOk)
  186851. {
  186852. CDDeviceInfo list[8];
  186853. const int num = FindCDDevices (list, 8);
  186854. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186855. {
  186856. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186857. if (handle != 0)
  186858. {
  186859. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186860. d->cdH = handle;
  186861. d->overlapBuffer = new CDReadBuffer(3);
  186862. return new AudioCDReader (d);
  186863. }
  186864. }
  186865. }
  186866. decUserCount();
  186867. return 0;
  186868. }
  186869. AudioCDReader::AudioCDReader (void* handle_)
  186870. : AudioFormatReader (0, "CD Audio"),
  186871. handle (handle_),
  186872. indexingEnabled (false),
  186873. lastIndex (0),
  186874. firstFrameInBuffer (0),
  186875. samplesInBuffer (0)
  186876. {
  186877. using namespace CDReaderHelpers;
  186878. jassert (handle_ != 0);
  186879. refreshTrackLengths();
  186880. sampleRate = 44100.0;
  186881. bitsPerSample = 16;
  186882. lengthInSamples = getPositionOfTrackStart (numTracks);
  186883. numChannels = 2;
  186884. usesFloatingPointData = false;
  186885. buffer.setSize (4 * bytesPerFrame, true);
  186886. }
  186887. AudioCDReader::~AudioCDReader()
  186888. {
  186889. using namespace CDReaderHelpers;
  186890. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186891. delete device;
  186892. decUserCount();
  186893. }
  186894. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186895. int64 startSampleInFile, int numSamples)
  186896. {
  186897. using namespace CDReaderHelpers;
  186898. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186899. bool ok = true;
  186900. while (numSamples > 0)
  186901. {
  186902. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186903. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186904. if (startSampleInFile >= bufferStartSample
  186905. && startSampleInFile < bufferEndSample)
  186906. {
  186907. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186908. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186909. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186910. const short* src = (const short*) buffer.getData();
  186911. src += 2 * (startSampleInFile - bufferStartSample);
  186912. for (int i = 0; i < toDo; ++i)
  186913. {
  186914. l[i] = src [i << 1] << 16;
  186915. if (r != 0)
  186916. r[i] = src [(i << 1) + 1] << 16;
  186917. }
  186918. startOffsetInDestBuffer += toDo;
  186919. startSampleInFile += toDo;
  186920. numSamples -= toDo;
  186921. }
  186922. else
  186923. {
  186924. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186925. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186926. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186927. {
  186928. device->overlapBuffer->dataLength = 0;
  186929. device->overlapBuffer->startFrame = 0;
  186930. device->overlapBuffer->numFrames = 0;
  186931. device->jitter = false;
  186932. }
  186933. firstFrameInBuffer = frameNeeded;
  186934. lastIndex = 0;
  186935. CDReadBuffer readBuffer (framesInBuffer + 4);
  186936. readBuffer.wantsIndex = indexingEnabled;
  186937. int i;
  186938. for (i = 5; --i >= 0;)
  186939. {
  186940. readBuffer.startFrame = frameNeeded;
  186941. readBuffer.numFrames = framesInBuffer;
  186942. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  186943. break;
  186944. else
  186945. device->overlapBuffer->dataLength = 0;
  186946. }
  186947. if (i >= 0)
  186948. {
  186949. memcpy ((char*) buffer.getData(),
  186950. readBuffer.buffer + readBuffer.dataStartOffset,
  186951. readBuffer.dataLength);
  186952. samplesInBuffer = readBuffer.dataLength >> 2;
  186953. lastIndex = readBuffer.index;
  186954. }
  186955. else
  186956. {
  186957. int* l = destSamples[0] + startOffsetInDestBuffer;
  186958. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186959. while (--numSamples >= 0)
  186960. {
  186961. *l++ = 0;
  186962. if (r != 0)
  186963. *r++ = 0;
  186964. }
  186965. // sometimes the read fails for just the very last couple of blocks, so
  186966. // we'll ignore and errors in the last half-second of the disk..
  186967. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  186968. break;
  186969. }
  186970. }
  186971. }
  186972. return ok;
  186973. }
  186974. bool AudioCDReader::isCDStillPresent() const
  186975. {
  186976. using namespace CDReaderHelpers;
  186977. TOC toc;
  186978. zerostruct (toc);
  186979. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  186980. }
  186981. int AudioCDReader::getNumTracks() const
  186982. {
  186983. return numTracks;
  186984. }
  186985. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  186986. {
  186987. using namespace CDReaderHelpers;
  186988. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  186989. : 0;
  186990. }
  186991. void AudioCDReader::refreshTrackLengths()
  186992. {
  186993. using namespace CDReaderHelpers;
  186994. zeromem (trackStarts, sizeof (trackStarts));
  186995. zeromem (audioTracks, sizeof (audioTracks));
  186996. TOC toc;
  186997. zerostruct (toc);
  186998. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  186999. {
  187000. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187001. for (int i = 0; i <= numTracks; ++i)
  187002. {
  187003. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187004. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187005. }
  187006. }
  187007. else
  187008. {
  187009. numTracks = 0;
  187010. }
  187011. }
  187012. bool AudioCDReader::isTrackAudio (int trackNum) const
  187013. {
  187014. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187015. : false;
  187016. }
  187017. void AudioCDReader::enableIndexScanning (bool b)
  187018. {
  187019. indexingEnabled = b;
  187020. }
  187021. int AudioCDReader::getLastIndex() const
  187022. {
  187023. return lastIndex;
  187024. }
  187025. const int framesPerIndexRead = 4;
  187026. int AudioCDReader::getIndexAt (int samplePos)
  187027. {
  187028. using namespace CDReaderHelpers;
  187029. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187030. const int frameNeeded = samplePos / samplesPerFrame;
  187031. device->overlapBuffer->dataLength = 0;
  187032. device->overlapBuffer->startFrame = 0;
  187033. device->overlapBuffer->numFrames = 0;
  187034. device->jitter = false;
  187035. firstFrameInBuffer = 0;
  187036. lastIndex = 0;
  187037. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187038. readBuffer.wantsIndex = true;
  187039. int i;
  187040. for (i = 5; --i >= 0;)
  187041. {
  187042. readBuffer.startFrame = frameNeeded;
  187043. readBuffer.numFrames = framesPerIndexRead;
  187044. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187045. break;
  187046. }
  187047. if (i >= 0)
  187048. return readBuffer.index;
  187049. return -1;
  187050. }
  187051. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187052. {
  187053. using namespace CDReaderHelpers;
  187054. Array <int> indexes;
  187055. const int trackStart = getPositionOfTrackStart (trackNumber);
  187056. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187057. bool needToScan = true;
  187058. if (trackEnd - trackStart > 20 * 44100)
  187059. {
  187060. // check the end of the track for indexes before scanning the whole thing
  187061. needToScan = false;
  187062. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187063. bool seenAnIndex = false;
  187064. while (pos <= trackEnd - samplesPerFrame)
  187065. {
  187066. const int index = getIndexAt (pos);
  187067. if (index == 0)
  187068. {
  187069. // lead-out, so skip back a bit if we've not found any indexes yet..
  187070. if (seenAnIndex)
  187071. break;
  187072. pos -= 44100 * 5;
  187073. if (pos < trackStart)
  187074. break;
  187075. }
  187076. else
  187077. {
  187078. if (index > 0)
  187079. seenAnIndex = true;
  187080. if (index > 1)
  187081. {
  187082. needToScan = true;
  187083. break;
  187084. }
  187085. pos += samplesPerFrame * framesPerIndexRead;
  187086. }
  187087. }
  187088. }
  187089. if (needToScan)
  187090. {
  187091. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187092. int pos = trackStart;
  187093. int last = -1;
  187094. while (pos < trackEnd - samplesPerFrame * 10)
  187095. {
  187096. const int frameNeeded = pos / samplesPerFrame;
  187097. device->overlapBuffer->dataLength = 0;
  187098. device->overlapBuffer->startFrame = 0;
  187099. device->overlapBuffer->numFrames = 0;
  187100. device->jitter = false;
  187101. firstFrameInBuffer = 0;
  187102. CDReadBuffer readBuffer (4);
  187103. readBuffer.wantsIndex = true;
  187104. int i;
  187105. for (i = 5; --i >= 0;)
  187106. {
  187107. readBuffer.startFrame = frameNeeded;
  187108. readBuffer.numFrames = framesPerIndexRead;
  187109. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187110. break;
  187111. }
  187112. if (i < 0)
  187113. break;
  187114. if (readBuffer.index > last && readBuffer.index > 1)
  187115. {
  187116. last = readBuffer.index;
  187117. indexes.add (pos);
  187118. }
  187119. pos += samplesPerFrame * framesPerIndexRead;
  187120. }
  187121. indexes.removeValue (trackStart);
  187122. }
  187123. return indexes;
  187124. }
  187125. int AudioCDReader::getCDDBId()
  187126. {
  187127. using namespace CDReaderHelpers;
  187128. refreshTrackLengths();
  187129. if (numTracks > 0)
  187130. {
  187131. TOC toc;
  187132. zerostruct (toc);
  187133. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187134. {
  187135. int n = 0;
  187136. for (int i = numTracks; --i >= 0;)
  187137. {
  187138. int j = getMSFAddressOf (&toc.tracks[i]);
  187139. while (j > 0)
  187140. {
  187141. n += (j % 10);
  187142. j /= 10;
  187143. }
  187144. }
  187145. if (n != 0)
  187146. {
  187147. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187148. - getMSFAddressOf (&toc.tracks[0]);
  187149. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187150. }
  187151. }
  187152. }
  187153. return 0;
  187154. }
  187155. void AudioCDReader::ejectDisk()
  187156. {
  187157. using namespace CDReaderHelpers;
  187158. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187159. }
  187160. #endif
  187161. #if JUCE_USE_CDBURNER
  187162. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187163. {
  187164. CoInitialize (0);
  187165. IDiscMaster* dm;
  187166. IDiscRecorder* result = 0;
  187167. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187168. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187169. IID_IDiscMaster,
  187170. (void**) &dm)))
  187171. {
  187172. if (SUCCEEDED (dm->Open()))
  187173. {
  187174. IEnumDiscRecorders* drEnum = 0;
  187175. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187176. {
  187177. IDiscRecorder* dr = 0;
  187178. DWORD dummy;
  187179. int index = 0;
  187180. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187181. {
  187182. if (indexToOpen == index)
  187183. {
  187184. result = dr;
  187185. break;
  187186. }
  187187. else if (list != 0)
  187188. {
  187189. BSTR path;
  187190. if (SUCCEEDED (dr->GetPath (&path)))
  187191. list->add ((const WCHAR*) path);
  187192. }
  187193. ++index;
  187194. dr->Release();
  187195. }
  187196. drEnum->Release();
  187197. }
  187198. if (master == 0)
  187199. dm->Close();
  187200. }
  187201. if (master != 0)
  187202. *master = dm;
  187203. else
  187204. dm->Release();
  187205. }
  187206. return result;
  187207. }
  187208. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187209. public Timer
  187210. {
  187211. public:
  187212. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187213. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187214. listener (0), progress (0), shouldCancel (false), refCount (1)
  187215. {
  187216. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187217. jassert (SUCCEEDED (hr));
  187218. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187219. //jassert (SUCCEEDED (hr));
  187220. lastState = getDiskState();
  187221. startTimer (2000);
  187222. }
  187223. ~Pimpl() {}
  187224. void releaseObjects()
  187225. {
  187226. discRecorder->Close();
  187227. if (redbook != 0)
  187228. redbook->Release();
  187229. discRecorder->Release();
  187230. discMaster->Release();
  187231. Release();
  187232. }
  187233. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187234. {
  187235. if (result == 0)
  187236. return E_POINTER;
  187237. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187238. {
  187239. AddRef();
  187240. *result = this;
  187241. return S_OK;
  187242. }
  187243. *result = 0;
  187244. return E_NOINTERFACE;
  187245. }
  187246. ULONG __stdcall AddRef() { return ++refCount; }
  187247. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187248. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187249. {
  187250. if (listener != 0 && ! shouldCancel)
  187251. shouldCancel = listener->audioCDBurnProgress (progress);
  187252. *pbCancel = shouldCancel;
  187253. return S_OK;
  187254. }
  187255. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187256. {
  187257. progress = nCompleted / (float) nTotal;
  187258. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187259. return E_NOTIMPL;
  187260. }
  187261. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187262. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187263. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187264. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187265. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187266. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187267. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187268. class ScopedDiscOpener
  187269. {
  187270. public:
  187271. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187272. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187273. private:
  187274. Pimpl& pimpl;
  187275. ScopedDiscOpener (const ScopedDiscOpener&);
  187276. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187277. };
  187278. DiskState getDiskState()
  187279. {
  187280. const ScopedDiscOpener opener (*this);
  187281. long type, flags;
  187282. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187283. if (FAILED (hr))
  187284. return unknown;
  187285. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187286. return writableDiskPresent;
  187287. if (type == 0)
  187288. return noDisc;
  187289. else
  187290. return readOnlyDiskPresent;
  187291. }
  187292. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187293. {
  187294. ComSmartPtr<IPropertyStorage> prop;
  187295. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187296. return defaultReturn;
  187297. PROPSPEC iPropSpec;
  187298. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187299. iPropSpec.lpwstr = name;
  187300. PROPVARIANT iPropVariant;
  187301. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187302. ? defaultReturn : (int) iPropVariant.lVal;
  187303. }
  187304. bool setIntProperty (const LPOLESTR name, const int value) const
  187305. {
  187306. ComSmartPtr<IPropertyStorage> prop;
  187307. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187308. return false;
  187309. PROPSPEC iPropSpec;
  187310. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187311. iPropSpec.lpwstr = name;
  187312. PROPVARIANT iPropVariant;
  187313. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187314. return false;
  187315. iPropVariant.lVal = (long) value;
  187316. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187317. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187318. }
  187319. void timerCallback()
  187320. {
  187321. const DiskState state = getDiskState();
  187322. if (state != lastState)
  187323. {
  187324. lastState = state;
  187325. owner.sendChangeMessage (&owner);
  187326. }
  187327. }
  187328. AudioCDBurner& owner;
  187329. DiskState lastState;
  187330. IDiscMaster* discMaster;
  187331. IDiscRecorder* discRecorder;
  187332. IRedbookDiscMaster* redbook;
  187333. AudioCDBurner::BurnProgressListener* listener;
  187334. float progress;
  187335. bool shouldCancel;
  187336. private:
  187337. int refCount;
  187338. };
  187339. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187340. {
  187341. IDiscMaster* discMaster = 0;
  187342. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187343. if (discRecorder != 0)
  187344. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187345. }
  187346. AudioCDBurner::~AudioCDBurner()
  187347. {
  187348. if (pimpl != 0)
  187349. pimpl.release()->releaseObjects();
  187350. }
  187351. const StringArray AudioCDBurner::findAvailableDevices()
  187352. {
  187353. StringArray devs;
  187354. enumCDBurners (&devs, -1, 0);
  187355. return devs;
  187356. }
  187357. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187358. {
  187359. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187360. if (b->pimpl == 0)
  187361. b = 0;
  187362. return b.release();
  187363. }
  187364. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187365. {
  187366. return pimpl->getDiskState();
  187367. }
  187368. bool AudioCDBurner::isDiskPresent() const
  187369. {
  187370. return getDiskState() == writableDiskPresent;
  187371. }
  187372. bool AudioCDBurner::openTray()
  187373. {
  187374. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187375. return SUCCEEDED (pimpl->discRecorder->Eject());
  187376. }
  187377. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187378. {
  187379. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187380. DiskState oldState = getDiskState();
  187381. DiskState newState = oldState;
  187382. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187383. {
  187384. newState = getDiskState();
  187385. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187386. }
  187387. return newState;
  187388. }
  187389. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187390. {
  187391. Array<int> results;
  187392. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187393. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187394. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187395. if (speeds[i] <= maxSpeed)
  187396. results.add (speeds[i]);
  187397. results.addIfNotAlreadyThere (maxSpeed);
  187398. return results;
  187399. }
  187400. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187401. {
  187402. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187403. return false;
  187404. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187405. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187406. }
  187407. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187408. {
  187409. long blocksFree = 0;
  187410. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187411. return blocksFree;
  187412. }
  187413. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187414. bool performFakeBurnForTesting, int writeSpeed)
  187415. {
  187416. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187417. pimpl->listener = listener;
  187418. pimpl->progress = 0;
  187419. pimpl->shouldCancel = false;
  187420. UINT_PTR cookie;
  187421. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187422. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187423. ejectDiscAfterwards);
  187424. String error;
  187425. if (hr != S_OK)
  187426. {
  187427. const char* e = "Couldn't open or write to the CD device";
  187428. if (hr == IMAPI_E_USERABORT)
  187429. e = "User cancelled the write operation";
  187430. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187431. e = "No Disk present";
  187432. error = e;
  187433. }
  187434. pimpl->discMaster->ProgressUnadvise (cookie);
  187435. pimpl->listener = 0;
  187436. return error;
  187437. }
  187438. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187439. {
  187440. if (audioSource == 0)
  187441. return false;
  187442. ScopedPointer<AudioSource> source (audioSource);
  187443. long bytesPerBlock;
  187444. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187445. const int samplesPerBlock = bytesPerBlock / 4;
  187446. bool ok = true;
  187447. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187448. HeapBlock <byte> buffer (bytesPerBlock);
  187449. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187450. int samplesDone = 0;
  187451. source->prepareToPlay (samplesPerBlock, 44100.0);
  187452. while (ok)
  187453. {
  187454. {
  187455. AudioSourceChannelInfo info;
  187456. info.buffer = &sourceBuffer;
  187457. info.numSamples = samplesPerBlock;
  187458. info.startSample = 0;
  187459. sourceBuffer.clear();
  187460. source->getNextAudioBlock (info);
  187461. }
  187462. zeromem (buffer, bytesPerBlock);
  187463. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187464. buffer, samplesPerBlock, 4);
  187465. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187466. buffer + 2, samplesPerBlock, 4);
  187467. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187468. if (FAILED (hr))
  187469. ok = false;
  187470. samplesDone += samplesPerBlock;
  187471. if (samplesDone >= numSamples)
  187472. break;
  187473. }
  187474. hr = pimpl->redbook->CloseAudioTrack();
  187475. return ok && hr == S_OK;
  187476. }
  187477. #endif
  187478. #endif
  187479. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187480. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187481. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187482. // compiled on its own).
  187483. #if JUCE_INCLUDED_FILE
  187484. using ::free;
  187485. namespace MidiConstants
  187486. {
  187487. static const int midiBufferSize = 1024 * 10;
  187488. static const int numInHeaders = 32;
  187489. static const int inBufferSize = 256;
  187490. }
  187491. class MidiInThread : public Thread
  187492. {
  187493. public:
  187494. MidiInThread (MidiInput* const input_,
  187495. MidiInputCallback* const callback_)
  187496. : Thread ("Juce Midi"),
  187497. hIn (0),
  187498. input (input_),
  187499. callback (callback_),
  187500. isStarted (false),
  187501. startTime (0),
  187502. pendingLength(0)
  187503. {
  187504. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187505. {
  187506. zeromem (&hdr[i], sizeof (MIDIHDR));
  187507. hdr[i].lpData = inData[i];
  187508. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187509. }
  187510. };
  187511. ~MidiInThread()
  187512. {
  187513. stop();
  187514. if (hIn != 0)
  187515. {
  187516. int count = 5;
  187517. while (--count >= 0)
  187518. {
  187519. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187520. break;
  187521. Sleep (20);
  187522. }
  187523. }
  187524. }
  187525. void handle (const uint32 message, const uint32 timeStamp) throw()
  187526. {
  187527. const int byte = message & 0xff;
  187528. if (byte < 0x80)
  187529. return;
  187530. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187531. const double time = timeStampToTime (timeStamp);
  187532. {
  187533. const ScopedLock sl (lock);
  187534. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187535. {
  187536. char* const p = pending + pendingLength;
  187537. *(double*) p = time;
  187538. *(uint32*) (p + 8) = numBytes;
  187539. *(uint32*) (p + 12) = message;
  187540. pendingLength += 12 + numBytes;
  187541. }
  187542. else
  187543. {
  187544. jassertfalse // midi buffer overflow! You might need to increase the size..
  187545. }
  187546. }
  187547. notify();
  187548. }
  187549. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187550. {
  187551. const int num = hdr->dwBytesRecorded;
  187552. if (num > 0)
  187553. {
  187554. const double time = timeStampToTime (timeStamp);
  187555. {
  187556. const ScopedLock sl (lock);
  187557. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187558. {
  187559. char* const p = pending + pendingLength;
  187560. *(double*) p = time;
  187561. *(uint32*) (p + 8) = num;
  187562. memcpy (p + 12, hdr->lpData, num);
  187563. pendingLength += 12 + num;
  187564. }
  187565. else
  187566. {
  187567. jassertfalse // midi buffer overflow! You might need to increase the size..
  187568. }
  187569. }
  187570. notify();
  187571. }
  187572. }
  187573. void writeBlock (const int i) throw()
  187574. {
  187575. hdr[i].dwBytesRecorded = 0;
  187576. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187577. jassert (res == MMSYSERR_NOERROR);
  187578. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187579. jassert (res == MMSYSERR_NOERROR);
  187580. }
  187581. void run()
  187582. {
  187583. MemoryBlock pendingCopy (64);
  187584. while (! threadShouldExit())
  187585. {
  187586. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187587. {
  187588. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187589. {
  187590. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187591. (void) res;
  187592. jassert (res == MMSYSERR_NOERROR);
  187593. writeBlock (i);
  187594. }
  187595. }
  187596. int len;
  187597. {
  187598. const ScopedLock sl (lock);
  187599. len = pendingLength;
  187600. if (len > 0)
  187601. {
  187602. pendingCopy.ensureSize (len);
  187603. pendingCopy.copyFrom (pending, 0, len);
  187604. pendingLength = 0;
  187605. }
  187606. }
  187607. //xxx needs to figure out if blocks are broken up or not
  187608. if (len == 0)
  187609. {
  187610. wait (500);
  187611. }
  187612. else
  187613. {
  187614. const char* p = (const char*) pendingCopy.getData();
  187615. while (len > 0)
  187616. {
  187617. const double time = *(const double*) p;
  187618. const int messageLen = *(const int*) (p + 8);
  187619. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187620. callback->handleIncomingMidiMessage (input, message);
  187621. p += 12 + messageLen;
  187622. len -= 12 + messageLen;
  187623. }
  187624. }
  187625. }
  187626. }
  187627. void start() throw()
  187628. {
  187629. jassert (hIn != 0);
  187630. if (hIn != 0 && ! isStarted)
  187631. {
  187632. stop();
  187633. activeMidiThreads.addIfNotAlreadyThere (this);
  187634. int i;
  187635. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187636. writeBlock (i);
  187637. startTime = Time::getMillisecondCounter();
  187638. MMRESULT res = midiInStart (hIn);
  187639. jassert (res == MMSYSERR_NOERROR);
  187640. if (res == MMSYSERR_NOERROR)
  187641. {
  187642. isStarted = true;
  187643. pendingLength = 0;
  187644. startThread (6);
  187645. }
  187646. }
  187647. }
  187648. void stop() throw()
  187649. {
  187650. if (isStarted)
  187651. {
  187652. stopThread (5000);
  187653. midiInReset (hIn);
  187654. midiInStop (hIn);
  187655. activeMidiThreads.removeValue (this);
  187656. { const ScopedLock sl (lock); }
  187657. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187658. {
  187659. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187660. {
  187661. int c = 10;
  187662. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187663. Sleep (20);
  187664. jassert (c >= 0);
  187665. }
  187666. }
  187667. isStarted = false;
  187668. pendingLength = 0;
  187669. }
  187670. }
  187671. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187672. {
  187673. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187674. if (thread != 0 && activeMidiThreads.contains (thread))
  187675. {
  187676. if (uMsg == MIM_DATA)
  187677. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187678. else if (uMsg == MIM_LONGDATA)
  187679. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187680. }
  187681. }
  187682. juce_UseDebuggingNewOperator
  187683. HMIDIIN hIn;
  187684. private:
  187685. static Array <void*, CriticalSection> activeMidiThreads;
  187686. MidiInput* input;
  187687. MidiInputCallback* callback;
  187688. bool isStarted;
  187689. uint32 startTime;
  187690. CriticalSection lock;
  187691. MIDIHDR hdr [MidiConstants::numInHeaders];
  187692. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187693. int pendingLength;
  187694. char pending [MidiConstants::midiBufferSize];
  187695. double timeStampToTime (uint32 timeStamp) throw()
  187696. {
  187697. timeStamp += startTime;
  187698. const uint32 now = Time::getMillisecondCounter();
  187699. if (timeStamp > now)
  187700. {
  187701. if (timeStamp > now + 2)
  187702. --startTime;
  187703. timeStamp = now;
  187704. }
  187705. return 0.001 * timeStamp;
  187706. }
  187707. MidiInThread (const MidiInThread&);
  187708. MidiInThread& operator= (const MidiInThread&);
  187709. };
  187710. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187711. const StringArray MidiInput::getDevices()
  187712. {
  187713. StringArray s;
  187714. const int num = midiInGetNumDevs();
  187715. for (int i = 0; i < num; ++i)
  187716. {
  187717. MIDIINCAPS mc;
  187718. zerostruct (mc);
  187719. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187720. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187721. }
  187722. return s;
  187723. }
  187724. int MidiInput::getDefaultDeviceIndex()
  187725. {
  187726. return 0;
  187727. }
  187728. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187729. {
  187730. if (callback == 0)
  187731. return 0;
  187732. UINT deviceId = MIDI_MAPPER;
  187733. int n = 0;
  187734. String name;
  187735. const int num = midiInGetNumDevs();
  187736. for (int i = 0; i < num; ++i)
  187737. {
  187738. MIDIINCAPS mc;
  187739. zerostruct (mc);
  187740. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187741. {
  187742. if (index == n)
  187743. {
  187744. deviceId = i;
  187745. name = String (mc.szPname, sizeof (mc.szPname));
  187746. break;
  187747. }
  187748. ++n;
  187749. }
  187750. }
  187751. ScopedPointer <MidiInput> in (new MidiInput (name));
  187752. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187753. HMIDIIN h;
  187754. HRESULT err = midiInOpen (&h, deviceId,
  187755. (DWORD_PTR) &MidiInThread::midiInCallback,
  187756. (DWORD_PTR) (MidiInThread*) thread,
  187757. CALLBACK_FUNCTION);
  187758. if (err == MMSYSERR_NOERROR)
  187759. {
  187760. thread->hIn = h;
  187761. in->internal = thread.release();
  187762. return in.release();
  187763. }
  187764. return 0;
  187765. }
  187766. MidiInput::MidiInput (const String& name_)
  187767. : name (name_),
  187768. internal (0)
  187769. {
  187770. }
  187771. MidiInput::~MidiInput()
  187772. {
  187773. delete static_cast <MidiInThread*> (internal);
  187774. }
  187775. void MidiInput::start()
  187776. {
  187777. static_cast <MidiInThread*> (internal)->start();
  187778. }
  187779. void MidiInput::stop()
  187780. {
  187781. static_cast <MidiInThread*> (internal)->stop();
  187782. }
  187783. struct MidiOutHandle
  187784. {
  187785. int refCount;
  187786. UINT deviceId;
  187787. HMIDIOUT handle;
  187788. static Array<MidiOutHandle*> activeHandles;
  187789. juce_UseDebuggingNewOperator
  187790. };
  187791. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187792. const StringArray MidiOutput::getDevices()
  187793. {
  187794. StringArray s;
  187795. const int num = midiOutGetNumDevs();
  187796. for (int i = 0; i < num; ++i)
  187797. {
  187798. MIDIOUTCAPS mc;
  187799. zerostruct (mc);
  187800. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187801. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187802. }
  187803. return s;
  187804. }
  187805. int MidiOutput::getDefaultDeviceIndex()
  187806. {
  187807. const int num = midiOutGetNumDevs();
  187808. int n = 0;
  187809. for (int i = 0; i < num; ++i)
  187810. {
  187811. MIDIOUTCAPS mc;
  187812. zerostruct (mc);
  187813. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187814. {
  187815. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187816. return n;
  187817. ++n;
  187818. }
  187819. }
  187820. return 0;
  187821. }
  187822. MidiOutput* MidiOutput::openDevice (int index)
  187823. {
  187824. UINT deviceId = MIDI_MAPPER;
  187825. const int num = midiOutGetNumDevs();
  187826. int i, n = 0;
  187827. for (i = 0; i < num; ++i)
  187828. {
  187829. MIDIOUTCAPS mc;
  187830. zerostruct (mc);
  187831. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187832. {
  187833. // use the microsoft sw synth as a default - best not to allow deviceId
  187834. // to be MIDI_MAPPER, or else device sharing breaks
  187835. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187836. deviceId = i;
  187837. if (index == n)
  187838. {
  187839. deviceId = i;
  187840. break;
  187841. }
  187842. ++n;
  187843. }
  187844. }
  187845. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187846. {
  187847. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187848. if (han != 0 && han->deviceId == deviceId)
  187849. {
  187850. han->refCount++;
  187851. MidiOutput* const out = new MidiOutput();
  187852. out->internal = han;
  187853. return out;
  187854. }
  187855. }
  187856. for (i = 4; --i >= 0;)
  187857. {
  187858. HMIDIOUT h = 0;
  187859. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187860. if (res == MMSYSERR_NOERROR)
  187861. {
  187862. MidiOutHandle* const han = new MidiOutHandle();
  187863. han->deviceId = deviceId;
  187864. han->refCount = 1;
  187865. han->handle = h;
  187866. MidiOutHandle::activeHandles.add (han);
  187867. MidiOutput* const out = new MidiOutput();
  187868. out->internal = han;
  187869. return out;
  187870. }
  187871. else if (res == MMSYSERR_ALLOCATED)
  187872. {
  187873. Sleep (100);
  187874. }
  187875. else
  187876. {
  187877. break;
  187878. }
  187879. }
  187880. return 0;
  187881. }
  187882. MidiOutput::~MidiOutput()
  187883. {
  187884. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187885. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187886. {
  187887. midiOutClose (h->handle);
  187888. MidiOutHandle::activeHandles.removeValue (h);
  187889. delete h;
  187890. }
  187891. }
  187892. void MidiOutput::reset()
  187893. {
  187894. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187895. midiOutReset (h->handle);
  187896. }
  187897. bool MidiOutput::getVolume (float& leftVol,
  187898. float& rightVol)
  187899. {
  187900. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187901. DWORD n;
  187902. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187903. {
  187904. const unsigned short* const nn = (const unsigned short*) &n;
  187905. rightVol = nn[0] / (float) 0xffff;
  187906. leftVol = nn[1] / (float) 0xffff;
  187907. return true;
  187908. }
  187909. else
  187910. {
  187911. rightVol = leftVol = 1.0f;
  187912. return false;
  187913. }
  187914. }
  187915. void MidiOutput::setVolume (float leftVol,
  187916. float rightVol)
  187917. {
  187918. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187919. DWORD n;
  187920. unsigned short* const nn = (unsigned short*) &n;
  187921. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187922. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187923. midiOutSetVolume (handle->handle, n);
  187924. }
  187925. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187926. {
  187927. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187928. if (message.getRawDataSize() > 3
  187929. || message.isSysEx())
  187930. {
  187931. MIDIHDR h;
  187932. zerostruct (h);
  187933. h.lpData = (char*) message.getRawData();
  187934. h.dwBufferLength = message.getRawDataSize();
  187935. h.dwBytesRecorded = message.getRawDataSize();
  187936. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  187937. {
  187938. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  187939. if (res == MMSYSERR_NOERROR)
  187940. {
  187941. while ((h.dwFlags & MHDR_DONE) == 0)
  187942. Sleep (1);
  187943. int count = 500; // 1 sec timeout
  187944. while (--count >= 0)
  187945. {
  187946. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  187947. if (res == MIDIERR_STILLPLAYING)
  187948. Sleep (2);
  187949. else
  187950. break;
  187951. }
  187952. }
  187953. }
  187954. }
  187955. else
  187956. {
  187957. midiOutShortMsg (handle->handle,
  187958. *(unsigned int*) message.getRawData());
  187959. }
  187960. }
  187961. #endif
  187962. /*** End of inlined file: juce_win32_Midi.cpp ***/
  187963. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  187964. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187965. // compiled on its own).
  187966. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  187967. #undef WINDOWS
  187968. // #define ASIO_DEBUGGING
  187969. #ifdef ASIO_DEBUGGING
  187970. #define log(a) { Logger::writeToLog (a); DBG (a) }
  187971. #else
  187972. #define log(a) {}
  187973. #endif
  187974. #ifdef ASIO_DEBUGGING
  187975. static void logError (const String& context, long error)
  187976. {
  187977. String err ("unknown error");
  187978. if (error == ASE_NotPresent)
  187979. err = "Not Present";
  187980. else if (error == ASE_HWMalfunction)
  187981. err = "Hardware Malfunction";
  187982. else if (error == ASE_InvalidParameter)
  187983. err = "Invalid Parameter";
  187984. else if (error == ASE_InvalidMode)
  187985. err = "Invalid Mode";
  187986. else if (error == ASE_SPNotAdvancing)
  187987. err = "Sample position not advancing";
  187988. else if (error == ASE_NoClock)
  187989. err = "No Clock";
  187990. else if (error == ASE_NoMemory)
  187991. err = "Out of memory";
  187992. log ("!!error: " + context + " - " + err);
  187993. }
  187994. #else
  187995. #define logError(a, b) {}
  187996. #endif
  187997. class ASIOAudioIODevice;
  187998. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  187999. static const int maxASIOChannels = 160;
  188000. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188001. private Timer
  188002. {
  188003. public:
  188004. Component ourWindow;
  188005. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188006. const String& optionalDllForDirectLoading_)
  188007. : AudioIODevice (name_, "ASIO"),
  188008. asioObject (0),
  188009. classId (classId_),
  188010. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188011. currentBitDepth (16),
  188012. currentSampleRate (0),
  188013. isOpen_ (false),
  188014. isStarted (false),
  188015. postOutput (true),
  188016. insideControlPanelModalLoop (false),
  188017. shouldUsePreferredSize (false)
  188018. {
  188019. name = name_;
  188020. ourWindow.addToDesktop (0);
  188021. windowHandle = ourWindow.getWindowHandle();
  188022. jassert (currentASIODev [slotNumber] == 0);
  188023. currentASIODev [slotNumber] = this;
  188024. openDevice();
  188025. }
  188026. ~ASIOAudioIODevice()
  188027. {
  188028. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188029. if (currentASIODev[i] == this)
  188030. currentASIODev[i] = 0;
  188031. close();
  188032. log ("ASIO - exiting");
  188033. removeCurrentDriver();
  188034. }
  188035. void updateSampleRates()
  188036. {
  188037. // find a list of sample rates..
  188038. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188039. sampleRates.clear();
  188040. if (asioObject != 0)
  188041. {
  188042. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188043. {
  188044. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188045. if (err == 0)
  188046. {
  188047. sampleRates.add ((int) possibleSampleRates[index]);
  188048. log ("rate: " + String ((int) possibleSampleRates[index]));
  188049. }
  188050. else if (err != ASE_NoClock)
  188051. {
  188052. logError ("CanSampleRate", err);
  188053. }
  188054. }
  188055. if (sampleRates.size() == 0)
  188056. {
  188057. double cr = 0;
  188058. const long err = asioObject->getSampleRate (&cr);
  188059. log ("No sample rates supported - current rate: " + String ((int) cr));
  188060. if (err == 0)
  188061. sampleRates.add ((int) cr);
  188062. }
  188063. }
  188064. }
  188065. const StringArray getOutputChannelNames()
  188066. {
  188067. return outputChannelNames;
  188068. }
  188069. const StringArray getInputChannelNames()
  188070. {
  188071. return inputChannelNames;
  188072. }
  188073. int getNumSampleRates()
  188074. {
  188075. return sampleRates.size();
  188076. }
  188077. double getSampleRate (int index)
  188078. {
  188079. return sampleRates [index];
  188080. }
  188081. int getNumBufferSizesAvailable()
  188082. {
  188083. return bufferSizes.size();
  188084. }
  188085. int getBufferSizeSamples (int index)
  188086. {
  188087. return bufferSizes [index];
  188088. }
  188089. int getDefaultBufferSize()
  188090. {
  188091. return preferredSize;
  188092. }
  188093. const String open (const BigInteger& inputChannels,
  188094. const BigInteger& outputChannels,
  188095. double sr,
  188096. int bufferSizeSamples)
  188097. {
  188098. close();
  188099. currentCallback = 0;
  188100. if (bufferSizeSamples <= 0)
  188101. shouldUsePreferredSize = true;
  188102. if (asioObject == 0 || ! isASIOOpen)
  188103. {
  188104. log ("Warning: device not open");
  188105. const String err (openDevice());
  188106. if (asioObject == 0 || ! isASIOOpen)
  188107. return err;
  188108. }
  188109. isStarted = false;
  188110. bufferIndex = -1;
  188111. long err = 0;
  188112. long newPreferredSize = 0;
  188113. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188114. minSize = 0;
  188115. maxSize = 0;
  188116. newPreferredSize = 0;
  188117. granularity = 0;
  188118. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188119. {
  188120. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188121. shouldUsePreferredSize = true;
  188122. preferredSize = newPreferredSize;
  188123. }
  188124. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188125. // dynamic changes to the buffer size...
  188126. shouldUsePreferredSize = shouldUsePreferredSize
  188127. || getName().containsIgnoreCase ("Digidesign");
  188128. if (shouldUsePreferredSize)
  188129. {
  188130. log ("Using preferred size for buffer..");
  188131. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188132. {
  188133. bufferSizeSamples = preferredSize;
  188134. }
  188135. else
  188136. {
  188137. bufferSizeSamples = 1024;
  188138. logError ("GetBufferSize1", err);
  188139. }
  188140. shouldUsePreferredSize = false;
  188141. }
  188142. int sampleRate = roundDoubleToInt (sr);
  188143. currentSampleRate = sampleRate;
  188144. currentBlockSizeSamples = bufferSizeSamples;
  188145. currentChansOut.clear();
  188146. currentChansIn.clear();
  188147. zeromem (inBuffers, sizeof (inBuffers));
  188148. zeromem (outBuffers, sizeof (outBuffers));
  188149. updateSampleRates();
  188150. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188151. sampleRate = sampleRates[0];
  188152. jassert (sampleRate != 0);
  188153. if (sampleRate == 0)
  188154. sampleRate = 44100;
  188155. long numSources = 32;
  188156. ASIOClockSource clocks[32];
  188157. zeromem (clocks, sizeof (clocks));
  188158. asioObject->getClockSources (clocks, &numSources);
  188159. bool isSourceSet = false;
  188160. // careful not to remove this loop because it does more than just logging!
  188161. int i;
  188162. for (i = 0; i < numSources; ++i)
  188163. {
  188164. String s ("clock: ");
  188165. s += clocks[i].name;
  188166. if (clocks[i].isCurrentSource)
  188167. {
  188168. isSourceSet = true;
  188169. s << " (cur)";
  188170. }
  188171. log (s);
  188172. }
  188173. if (numSources > 1 && ! isSourceSet)
  188174. {
  188175. log ("setting clock source");
  188176. asioObject->setClockSource (clocks[0].index);
  188177. Thread::sleep (20);
  188178. }
  188179. else
  188180. {
  188181. if (numSources == 0)
  188182. {
  188183. log ("ASIO - no clock sources!");
  188184. }
  188185. }
  188186. double cr = 0;
  188187. err = asioObject->getSampleRate (&cr);
  188188. if (err == 0)
  188189. {
  188190. currentSampleRate = cr;
  188191. }
  188192. else
  188193. {
  188194. logError ("GetSampleRate", err);
  188195. currentSampleRate = 0;
  188196. }
  188197. error = String::empty;
  188198. needToReset = false;
  188199. isReSync = false;
  188200. err = 0;
  188201. bool buffersCreated = false;
  188202. if (currentSampleRate != sampleRate)
  188203. {
  188204. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188205. err = asioObject->setSampleRate (sampleRate);
  188206. if (err == ASE_NoClock && numSources > 0)
  188207. {
  188208. log ("trying to set a clock source..");
  188209. Thread::sleep (10);
  188210. err = asioObject->setClockSource (clocks[0].index);
  188211. if (err != 0)
  188212. {
  188213. logError ("SetClock", err);
  188214. }
  188215. Thread::sleep (10);
  188216. err = asioObject->setSampleRate (sampleRate);
  188217. }
  188218. }
  188219. if (err == 0)
  188220. {
  188221. currentSampleRate = sampleRate;
  188222. if (needToReset)
  188223. {
  188224. if (isReSync)
  188225. {
  188226. log ("Resync request");
  188227. }
  188228. log ("! Resetting ASIO after sample rate change");
  188229. removeCurrentDriver();
  188230. loadDriver();
  188231. const String error (initDriver());
  188232. if (error.isNotEmpty())
  188233. {
  188234. log ("ASIOInit: " + error);
  188235. }
  188236. needToReset = false;
  188237. isReSync = false;
  188238. }
  188239. numActiveInputChans = 0;
  188240. numActiveOutputChans = 0;
  188241. ASIOBufferInfo* info = bufferInfos;
  188242. int i;
  188243. for (i = 0; i < totalNumInputChans; ++i)
  188244. {
  188245. if (inputChannels[i])
  188246. {
  188247. currentChansIn.setBit (i);
  188248. info->isInput = 1;
  188249. info->channelNum = i;
  188250. info->buffers[0] = info->buffers[1] = 0;
  188251. ++info;
  188252. ++numActiveInputChans;
  188253. }
  188254. }
  188255. for (i = 0; i < totalNumOutputChans; ++i)
  188256. {
  188257. if (outputChannels[i])
  188258. {
  188259. currentChansOut.setBit (i);
  188260. info->isInput = 0;
  188261. info->channelNum = i;
  188262. info->buffers[0] = info->buffers[1] = 0;
  188263. ++info;
  188264. ++numActiveOutputChans;
  188265. }
  188266. }
  188267. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188268. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188269. if (currentASIODev[0] == this)
  188270. {
  188271. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188272. callbacks.asioMessage = &asioMessagesCallback0;
  188273. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188274. }
  188275. else if (currentASIODev[1] == this)
  188276. {
  188277. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188278. callbacks.asioMessage = &asioMessagesCallback1;
  188279. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188280. }
  188281. else if (currentASIODev[2] == this)
  188282. {
  188283. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188284. callbacks.asioMessage = &asioMessagesCallback2;
  188285. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188286. }
  188287. else
  188288. {
  188289. jassertfalse
  188290. }
  188291. log ("disposing buffers");
  188292. err = asioObject->disposeBuffers();
  188293. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188294. err = asioObject->createBuffers (bufferInfos,
  188295. totalBuffers,
  188296. currentBlockSizeSamples,
  188297. &callbacks);
  188298. if (err != 0)
  188299. {
  188300. currentBlockSizeSamples = preferredSize;
  188301. logError ("create buffers 2", err);
  188302. asioObject->disposeBuffers();
  188303. err = asioObject->createBuffers (bufferInfos,
  188304. totalBuffers,
  188305. currentBlockSizeSamples,
  188306. &callbacks);
  188307. }
  188308. if (err == 0)
  188309. {
  188310. buffersCreated = true;
  188311. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188312. int n = 0;
  188313. Array <int> types;
  188314. currentBitDepth = 16;
  188315. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188316. {
  188317. if (inputChannels[i])
  188318. {
  188319. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188320. ASIOChannelInfo channelInfo;
  188321. zerostruct (channelInfo);
  188322. channelInfo.channel = i;
  188323. channelInfo.isInput = 1;
  188324. asioObject->getChannelInfo (&channelInfo);
  188325. types.addIfNotAlreadyThere (channelInfo.type);
  188326. typeToFormatParameters (channelInfo.type,
  188327. inputChannelBitDepths[n],
  188328. inputChannelBytesPerSample[n],
  188329. inputChannelIsFloat[n],
  188330. inputChannelLittleEndian[n]);
  188331. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188332. ++n;
  188333. }
  188334. }
  188335. jassert (numActiveInputChans == n);
  188336. n = 0;
  188337. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188338. {
  188339. if (outputChannels[i])
  188340. {
  188341. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188342. ASIOChannelInfo channelInfo;
  188343. zerostruct (channelInfo);
  188344. channelInfo.channel = i;
  188345. channelInfo.isInput = 0;
  188346. asioObject->getChannelInfo (&channelInfo);
  188347. types.addIfNotAlreadyThere (channelInfo.type);
  188348. typeToFormatParameters (channelInfo.type,
  188349. outputChannelBitDepths[n],
  188350. outputChannelBytesPerSample[n],
  188351. outputChannelIsFloat[n],
  188352. outputChannelLittleEndian[n]);
  188353. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188354. ++n;
  188355. }
  188356. }
  188357. jassert (numActiveOutputChans == n);
  188358. for (i = types.size(); --i >= 0;)
  188359. {
  188360. log ("channel format: " + String (types[i]));
  188361. }
  188362. jassert (n <= totalBuffers);
  188363. for (i = 0; i < numActiveOutputChans; ++i)
  188364. {
  188365. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188366. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188367. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188368. {
  188369. log ("!! Null buffers");
  188370. }
  188371. else
  188372. {
  188373. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188374. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188375. }
  188376. }
  188377. inputLatency = outputLatency = 0;
  188378. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188379. {
  188380. log ("ASIO - no latencies");
  188381. }
  188382. else
  188383. {
  188384. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188385. }
  188386. isOpen_ = true;
  188387. log ("starting ASIO");
  188388. calledback = false;
  188389. err = asioObject->start();
  188390. if (err != 0)
  188391. {
  188392. isOpen_ = false;
  188393. log ("ASIO - stop on failure");
  188394. Thread::sleep (10);
  188395. asioObject->stop();
  188396. error = "Can't start device";
  188397. Thread::sleep (10);
  188398. }
  188399. else
  188400. {
  188401. int count = 300;
  188402. while (--count > 0 && ! calledback)
  188403. Thread::sleep (10);
  188404. isStarted = true;
  188405. if (! calledback)
  188406. {
  188407. error = "Device didn't start correctly";
  188408. log ("ASIO didn't callback - stopping..");
  188409. asioObject->stop();
  188410. }
  188411. }
  188412. }
  188413. else
  188414. {
  188415. error = "Can't create i/o buffers";
  188416. }
  188417. }
  188418. else
  188419. {
  188420. error = "Can't set sample rate: ";
  188421. error << sampleRate;
  188422. }
  188423. if (error.isNotEmpty())
  188424. {
  188425. logError (error, err);
  188426. if (asioObject != 0 && buffersCreated)
  188427. asioObject->disposeBuffers();
  188428. Thread::sleep (20);
  188429. isStarted = false;
  188430. isOpen_ = false;
  188431. close();
  188432. }
  188433. needToReset = false;
  188434. isReSync = false;
  188435. return error;
  188436. }
  188437. void close()
  188438. {
  188439. error = String::empty;
  188440. stopTimer();
  188441. stop();
  188442. if (isASIOOpen && isOpen_)
  188443. {
  188444. const ScopedLock sl (callbackLock);
  188445. isOpen_ = false;
  188446. isStarted = false;
  188447. needToReset = false;
  188448. isReSync = false;
  188449. log ("ASIO - stopping");
  188450. if (asioObject != 0)
  188451. {
  188452. Thread::sleep (20);
  188453. asioObject->stop();
  188454. Thread::sleep (10);
  188455. asioObject->disposeBuffers();
  188456. }
  188457. Thread::sleep (10);
  188458. }
  188459. }
  188460. bool isOpen()
  188461. {
  188462. return isOpen_ || insideControlPanelModalLoop;
  188463. }
  188464. int getCurrentBufferSizeSamples()
  188465. {
  188466. return currentBlockSizeSamples;
  188467. }
  188468. double getCurrentSampleRate()
  188469. {
  188470. return currentSampleRate;
  188471. }
  188472. const BigInteger getActiveOutputChannels() const
  188473. {
  188474. return currentChansOut;
  188475. }
  188476. const BigInteger getActiveInputChannels() const
  188477. {
  188478. return currentChansIn;
  188479. }
  188480. int getCurrentBitDepth()
  188481. {
  188482. return currentBitDepth;
  188483. }
  188484. int getOutputLatencyInSamples()
  188485. {
  188486. return outputLatency + currentBlockSizeSamples / 4;
  188487. }
  188488. int getInputLatencyInSamples()
  188489. {
  188490. return inputLatency + currentBlockSizeSamples / 4;
  188491. }
  188492. void start (AudioIODeviceCallback* callback)
  188493. {
  188494. if (callback != 0)
  188495. {
  188496. callback->audioDeviceAboutToStart (this);
  188497. const ScopedLock sl (callbackLock);
  188498. currentCallback = callback;
  188499. }
  188500. }
  188501. void stop()
  188502. {
  188503. AudioIODeviceCallback* const lastCallback = currentCallback;
  188504. {
  188505. const ScopedLock sl (callbackLock);
  188506. currentCallback = 0;
  188507. }
  188508. if (lastCallback != 0)
  188509. lastCallback->audioDeviceStopped();
  188510. }
  188511. bool isPlaying()
  188512. {
  188513. return isASIOOpen && (currentCallback != 0);
  188514. }
  188515. const String getLastError()
  188516. {
  188517. return error;
  188518. }
  188519. bool hasControlPanel() const
  188520. {
  188521. return true;
  188522. }
  188523. bool showControlPanel()
  188524. {
  188525. log ("ASIO - showing control panel");
  188526. Component modalWindow (String::empty);
  188527. modalWindow.setOpaque (true);
  188528. modalWindow.addToDesktop (0);
  188529. modalWindow.enterModalState();
  188530. bool done = false;
  188531. JUCE_TRY
  188532. {
  188533. // are there are devices that need to be closed before showing their control panel?
  188534. // close();
  188535. insideControlPanelModalLoop = true;
  188536. const uint32 started = Time::getMillisecondCounter();
  188537. if (asioObject != 0)
  188538. {
  188539. asioObject->controlPanel();
  188540. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188541. log ("spent: " + String (spent));
  188542. if (spent > 300)
  188543. {
  188544. shouldUsePreferredSize = true;
  188545. done = true;
  188546. }
  188547. }
  188548. }
  188549. JUCE_CATCH_ALL
  188550. insideControlPanelModalLoop = false;
  188551. return done;
  188552. }
  188553. void resetRequest() throw()
  188554. {
  188555. needToReset = true;
  188556. }
  188557. void resyncRequest() throw()
  188558. {
  188559. needToReset = true;
  188560. isReSync = true;
  188561. }
  188562. void timerCallback()
  188563. {
  188564. if (! insideControlPanelModalLoop)
  188565. {
  188566. stopTimer();
  188567. // used to cause a reset
  188568. log ("! ASIO restart request!");
  188569. if (isOpen_)
  188570. {
  188571. AudioIODeviceCallback* const oldCallback = currentCallback;
  188572. close();
  188573. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188574. currentSampleRate, currentBlockSizeSamples);
  188575. if (oldCallback != 0)
  188576. start (oldCallback);
  188577. }
  188578. }
  188579. else
  188580. {
  188581. startTimer (100);
  188582. }
  188583. }
  188584. juce_UseDebuggingNewOperator
  188585. private:
  188586. IASIO* volatile asioObject;
  188587. ASIOCallbacks callbacks;
  188588. void* windowHandle;
  188589. CLSID classId;
  188590. const String optionalDllForDirectLoading;
  188591. String error;
  188592. long totalNumInputChans, totalNumOutputChans;
  188593. StringArray inputChannelNames, outputChannelNames;
  188594. Array<int> sampleRates, bufferSizes;
  188595. long inputLatency, outputLatency;
  188596. long minSize, maxSize, preferredSize, granularity;
  188597. int volatile currentBlockSizeSamples;
  188598. int volatile currentBitDepth;
  188599. double volatile currentSampleRate;
  188600. BigInteger currentChansOut, currentChansIn;
  188601. AudioIODeviceCallback* volatile currentCallback;
  188602. CriticalSection callbackLock;
  188603. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188604. float* inBuffers [maxASIOChannels];
  188605. float* outBuffers [maxASIOChannels];
  188606. int inputChannelBitDepths [maxASIOChannels];
  188607. int outputChannelBitDepths [maxASIOChannels];
  188608. int inputChannelBytesPerSample [maxASIOChannels];
  188609. int outputChannelBytesPerSample [maxASIOChannels];
  188610. bool inputChannelIsFloat [maxASIOChannels];
  188611. bool outputChannelIsFloat [maxASIOChannels];
  188612. bool inputChannelLittleEndian [maxASIOChannels];
  188613. bool outputChannelLittleEndian [maxASIOChannels];
  188614. WaitableEvent event1;
  188615. HeapBlock <float> tempBuffer;
  188616. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188617. bool isOpen_, isStarted;
  188618. bool volatile isASIOOpen;
  188619. bool volatile calledback;
  188620. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188621. bool volatile insideControlPanelModalLoop;
  188622. bool volatile shouldUsePreferredSize;
  188623. void removeCurrentDriver()
  188624. {
  188625. if (asioObject != 0)
  188626. {
  188627. asioObject->Release();
  188628. asioObject = 0;
  188629. }
  188630. }
  188631. bool loadDriver()
  188632. {
  188633. removeCurrentDriver();
  188634. JUCE_TRY
  188635. {
  188636. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188637. classId, (void**) &asioObject) == S_OK)
  188638. {
  188639. return true;
  188640. }
  188641. // If a class isn't registered but we have a path for it, we can fallback to
  188642. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188643. if (optionalDllForDirectLoading.isNotEmpty())
  188644. {
  188645. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188646. if (h != 0)
  188647. {
  188648. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188649. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188650. if (dllGetClassObject != 0)
  188651. {
  188652. IClassFactory* classFactory = 0;
  188653. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188654. if (classFactory != 0)
  188655. {
  188656. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188657. classFactory->Release();
  188658. }
  188659. return asioObject != 0;
  188660. }
  188661. }
  188662. }
  188663. }
  188664. JUCE_CATCH_ALL
  188665. asioObject = 0;
  188666. return false;
  188667. }
  188668. const String initDriver()
  188669. {
  188670. if (asioObject != 0)
  188671. {
  188672. char buffer [256];
  188673. zeromem (buffer, sizeof (buffer));
  188674. if (! asioObject->init (windowHandle))
  188675. {
  188676. asioObject->getErrorMessage (buffer);
  188677. return String (buffer, sizeof (buffer) - 1);
  188678. }
  188679. // just in case any daft drivers expect this to be called..
  188680. asioObject->getDriverName (buffer);
  188681. return String::empty;
  188682. }
  188683. return "No Driver";
  188684. }
  188685. const String openDevice()
  188686. {
  188687. // use this in case the driver starts opening dialog boxes..
  188688. Component modalWindow (String::empty);
  188689. modalWindow.setOpaque (true);
  188690. modalWindow.addToDesktop (0);
  188691. modalWindow.enterModalState();
  188692. // open the device and get its info..
  188693. log ("opening ASIO device: " + getName());
  188694. needToReset = false;
  188695. isReSync = false;
  188696. outputChannelNames.clear();
  188697. inputChannelNames.clear();
  188698. bufferSizes.clear();
  188699. sampleRates.clear();
  188700. isASIOOpen = false;
  188701. isOpen_ = false;
  188702. totalNumInputChans = 0;
  188703. totalNumOutputChans = 0;
  188704. numActiveInputChans = 0;
  188705. numActiveOutputChans = 0;
  188706. currentCallback = 0;
  188707. error = String::empty;
  188708. if (getName().isEmpty())
  188709. return error;
  188710. long err = 0;
  188711. if (loadDriver())
  188712. {
  188713. if ((error = initDriver()).isEmpty())
  188714. {
  188715. numActiveInputChans = 0;
  188716. numActiveOutputChans = 0;
  188717. totalNumInputChans = 0;
  188718. totalNumOutputChans = 0;
  188719. if (asioObject != 0
  188720. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188721. {
  188722. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188723. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188724. {
  188725. // find a list of buffer sizes..
  188726. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188727. if (granularity >= 0)
  188728. {
  188729. granularity = jmax (1, (int) granularity);
  188730. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188731. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188732. }
  188733. else if (granularity < 0)
  188734. {
  188735. for (int i = 0; i < 18; ++i)
  188736. {
  188737. const int s = (1 << i);
  188738. if (s >= minSize && s <= maxSize)
  188739. bufferSizes.add (s);
  188740. }
  188741. }
  188742. if (! bufferSizes.contains (preferredSize))
  188743. bufferSizes.insert (0, preferredSize);
  188744. double currentRate = 0;
  188745. asioObject->getSampleRate (&currentRate);
  188746. if (currentRate <= 0.0 || currentRate > 192001.0)
  188747. {
  188748. log ("setting sample rate");
  188749. err = asioObject->setSampleRate (44100.0);
  188750. if (err != 0)
  188751. {
  188752. logError ("setting sample rate", err);
  188753. }
  188754. asioObject->getSampleRate (&currentRate);
  188755. }
  188756. currentSampleRate = currentRate;
  188757. postOutput = (asioObject->outputReady() == 0);
  188758. if (postOutput)
  188759. {
  188760. log ("ASIO outputReady = ok");
  188761. }
  188762. updateSampleRates();
  188763. // ..because cubase does it at this point
  188764. inputLatency = outputLatency = 0;
  188765. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188766. {
  188767. log ("ASIO - no latencies");
  188768. }
  188769. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188770. // create some dummy buffers now.. because cubase does..
  188771. numActiveInputChans = 0;
  188772. numActiveOutputChans = 0;
  188773. ASIOBufferInfo* info = bufferInfos;
  188774. int i, numChans = 0;
  188775. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188776. {
  188777. info->isInput = 1;
  188778. info->channelNum = i;
  188779. info->buffers[0] = info->buffers[1] = 0;
  188780. ++info;
  188781. ++numChans;
  188782. }
  188783. const int outputBufferIndex = numChans;
  188784. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188785. {
  188786. info->isInput = 0;
  188787. info->channelNum = i;
  188788. info->buffers[0] = info->buffers[1] = 0;
  188789. ++info;
  188790. ++numChans;
  188791. }
  188792. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188793. if (currentASIODev[0] == this)
  188794. {
  188795. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188796. callbacks.asioMessage = &asioMessagesCallback0;
  188797. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188798. }
  188799. else if (currentASIODev[1] == this)
  188800. {
  188801. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188802. callbacks.asioMessage = &asioMessagesCallback1;
  188803. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188804. }
  188805. else if (currentASIODev[2] == this)
  188806. {
  188807. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188808. callbacks.asioMessage = &asioMessagesCallback2;
  188809. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188810. }
  188811. else
  188812. {
  188813. jassertfalse
  188814. }
  188815. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188816. if (preferredSize > 0)
  188817. {
  188818. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188819. if (err != 0)
  188820. {
  188821. logError ("dummy buffers", err);
  188822. }
  188823. }
  188824. long newInps = 0, newOuts = 0;
  188825. asioObject->getChannels (&newInps, &newOuts);
  188826. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188827. {
  188828. totalNumInputChans = newInps;
  188829. totalNumOutputChans = newOuts;
  188830. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188831. }
  188832. updateSampleRates();
  188833. ASIOChannelInfo channelInfo;
  188834. channelInfo.type = 0;
  188835. for (i = 0; i < totalNumInputChans; ++i)
  188836. {
  188837. zerostruct (channelInfo);
  188838. channelInfo.channel = i;
  188839. channelInfo.isInput = 1;
  188840. asioObject->getChannelInfo (&channelInfo);
  188841. inputChannelNames.add (String (channelInfo.name));
  188842. }
  188843. for (i = 0; i < totalNumOutputChans; ++i)
  188844. {
  188845. zerostruct (channelInfo);
  188846. channelInfo.channel = i;
  188847. channelInfo.isInput = 0;
  188848. asioObject->getChannelInfo (&channelInfo);
  188849. outputChannelNames.add (String (channelInfo.name));
  188850. typeToFormatParameters (channelInfo.type,
  188851. outputChannelBitDepths[i],
  188852. outputChannelBytesPerSample[i],
  188853. outputChannelIsFloat[i],
  188854. outputChannelLittleEndian[i]);
  188855. if (i < 2)
  188856. {
  188857. // clear the channels that are used with the dummy stuff
  188858. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188859. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188860. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188861. }
  188862. }
  188863. outputChannelNames.trim();
  188864. inputChannelNames.trim();
  188865. outputChannelNames.appendNumbersToDuplicates (false, true);
  188866. inputChannelNames.appendNumbersToDuplicates (false, true);
  188867. // start and stop because cubase does it..
  188868. asioObject->getLatencies (&inputLatency, &outputLatency);
  188869. if ((err = asioObject->start()) != 0)
  188870. {
  188871. // ignore an error here, as it might start later after setting other stuff up
  188872. logError ("ASIO start", err);
  188873. }
  188874. Thread::sleep (100);
  188875. asioObject->stop();
  188876. }
  188877. else
  188878. {
  188879. error = "Can't detect buffer sizes";
  188880. }
  188881. }
  188882. else
  188883. {
  188884. error = "Can't detect asio channels";
  188885. }
  188886. }
  188887. }
  188888. else
  188889. {
  188890. error = "No such device";
  188891. }
  188892. if (error.isNotEmpty())
  188893. {
  188894. logError (error, err);
  188895. if (asioObject != 0)
  188896. asioObject->disposeBuffers();
  188897. removeCurrentDriver();
  188898. isASIOOpen = false;
  188899. }
  188900. else
  188901. {
  188902. isASIOOpen = true;
  188903. log ("ASIO device open");
  188904. }
  188905. isOpen_ = false;
  188906. needToReset = false;
  188907. isReSync = false;
  188908. return error;
  188909. }
  188910. void callback (const long index) throw()
  188911. {
  188912. if (isStarted)
  188913. {
  188914. bufferIndex = index;
  188915. processBuffer();
  188916. }
  188917. else
  188918. {
  188919. if (postOutput && (asioObject != 0))
  188920. asioObject->outputReady();
  188921. }
  188922. calledback = true;
  188923. }
  188924. void processBuffer() throw()
  188925. {
  188926. const ASIOBufferInfo* const infos = bufferInfos;
  188927. const int bi = bufferIndex;
  188928. const ScopedLock sl (callbackLock);
  188929. if (needToReset)
  188930. {
  188931. needToReset = false;
  188932. if (isReSync)
  188933. {
  188934. log ("! ASIO resync");
  188935. isReSync = false;
  188936. }
  188937. else
  188938. {
  188939. startTimer (20);
  188940. }
  188941. }
  188942. if (bi >= 0)
  188943. {
  188944. const int samps = currentBlockSizeSamples;
  188945. if (currentCallback != 0)
  188946. {
  188947. int i;
  188948. for (i = 0; i < numActiveInputChans; ++i)
  188949. {
  188950. float* const dst = inBuffers[i];
  188951. jassert (dst != 0);
  188952. const char* const src = (const char*) (infos[i].buffers[bi]);
  188953. if (inputChannelIsFloat[i])
  188954. {
  188955. memcpy (dst, src, samps * sizeof (float));
  188956. }
  188957. else
  188958. {
  188959. jassert (dst == tempBuffer + (samps * i));
  188960. switch (inputChannelBitDepths[i])
  188961. {
  188962. case 16:
  188963. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  188964. samps, inputChannelLittleEndian[i]);
  188965. break;
  188966. case 24:
  188967. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  188968. samps, inputChannelLittleEndian[i]);
  188969. break;
  188970. case 32:
  188971. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  188972. samps, inputChannelLittleEndian[i]);
  188973. break;
  188974. case 64:
  188975. jassertfalse
  188976. break;
  188977. }
  188978. }
  188979. }
  188980. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  188981. numActiveInputChans,
  188982. outBuffers,
  188983. numActiveOutputChans,
  188984. samps);
  188985. for (i = 0; i < numActiveOutputChans; ++i)
  188986. {
  188987. float* const src = outBuffers[i];
  188988. jassert (src != 0);
  188989. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  188990. if (outputChannelIsFloat[i])
  188991. {
  188992. memcpy (dst, src, samps * sizeof (float));
  188993. }
  188994. else
  188995. {
  188996. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  188997. switch (outputChannelBitDepths[i])
  188998. {
  188999. case 16:
  189000. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189001. samps, outputChannelLittleEndian[i]);
  189002. break;
  189003. case 24:
  189004. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189005. samps, outputChannelLittleEndian[i]);
  189006. break;
  189007. case 32:
  189008. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189009. samps, outputChannelLittleEndian[i]);
  189010. break;
  189011. case 64:
  189012. jassertfalse
  189013. break;
  189014. }
  189015. }
  189016. }
  189017. }
  189018. else
  189019. {
  189020. for (int i = 0; i < numActiveOutputChans; ++i)
  189021. {
  189022. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189023. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189024. }
  189025. }
  189026. }
  189027. if (postOutput)
  189028. asioObject->outputReady();
  189029. }
  189030. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189031. {
  189032. if (currentASIODev[0] != 0)
  189033. currentASIODev[0]->callback (index);
  189034. return 0;
  189035. }
  189036. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189037. {
  189038. if (currentASIODev[1] != 0)
  189039. currentASIODev[1]->callback (index);
  189040. return 0;
  189041. }
  189042. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189043. {
  189044. if (currentASIODev[2] != 0)
  189045. currentASIODev[2]->callback (index);
  189046. return 0;
  189047. }
  189048. static void bufferSwitchCallback0 (long index, long) throw()
  189049. {
  189050. if (currentASIODev[0] != 0)
  189051. currentASIODev[0]->callback (index);
  189052. }
  189053. static void bufferSwitchCallback1 (long index, long) throw()
  189054. {
  189055. if (currentASIODev[1] != 0)
  189056. currentASIODev[1]->callback (index);
  189057. }
  189058. static void bufferSwitchCallback2 (long index, long) throw()
  189059. {
  189060. if (currentASIODev[2] != 0)
  189061. currentASIODev[2]->callback (index);
  189062. }
  189063. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189064. {
  189065. return asioMessagesCallback (selector, value, 0);
  189066. }
  189067. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189068. {
  189069. return asioMessagesCallback (selector, value, 1);
  189070. }
  189071. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189072. {
  189073. return asioMessagesCallback (selector, value, 2);
  189074. }
  189075. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189076. {
  189077. switch (selector)
  189078. {
  189079. case kAsioSelectorSupported:
  189080. if (value == kAsioResetRequest
  189081. || value == kAsioEngineVersion
  189082. || value == kAsioResyncRequest
  189083. || value == kAsioLatenciesChanged
  189084. || value == kAsioSupportsInputMonitor)
  189085. return 1;
  189086. break;
  189087. case kAsioBufferSizeChange:
  189088. break;
  189089. case kAsioResetRequest:
  189090. if (currentASIODev[deviceIndex] != 0)
  189091. currentASIODev[deviceIndex]->resetRequest();
  189092. return 1;
  189093. case kAsioResyncRequest:
  189094. if (currentASIODev[deviceIndex] != 0)
  189095. currentASIODev[deviceIndex]->resyncRequest();
  189096. return 1;
  189097. case kAsioLatenciesChanged:
  189098. return 1;
  189099. case kAsioEngineVersion:
  189100. return 2;
  189101. case kAsioSupportsTimeInfo:
  189102. case kAsioSupportsTimeCode:
  189103. return 0;
  189104. }
  189105. return 0;
  189106. }
  189107. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189108. {
  189109. }
  189110. static void convertInt16ToFloat (const char* src,
  189111. float* dest,
  189112. const int srcStrideBytes,
  189113. int numSamples,
  189114. const bool littleEndian) throw()
  189115. {
  189116. const double g = 1.0 / 32768.0;
  189117. if (littleEndian)
  189118. {
  189119. while (--numSamples >= 0)
  189120. {
  189121. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189122. src += srcStrideBytes;
  189123. }
  189124. }
  189125. else
  189126. {
  189127. while (--numSamples >= 0)
  189128. {
  189129. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189130. src += srcStrideBytes;
  189131. }
  189132. }
  189133. }
  189134. static void convertFloatToInt16 (const float* src,
  189135. char* dest,
  189136. const int dstStrideBytes,
  189137. int numSamples,
  189138. const bool littleEndian) throw()
  189139. {
  189140. const double maxVal = (double) 0x7fff;
  189141. if (littleEndian)
  189142. {
  189143. while (--numSamples >= 0)
  189144. {
  189145. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189146. dest += dstStrideBytes;
  189147. }
  189148. }
  189149. else
  189150. {
  189151. while (--numSamples >= 0)
  189152. {
  189153. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189154. dest += dstStrideBytes;
  189155. }
  189156. }
  189157. }
  189158. static void convertInt24ToFloat (const char* src,
  189159. float* dest,
  189160. const int srcStrideBytes,
  189161. int numSamples,
  189162. const bool littleEndian) throw()
  189163. {
  189164. const double g = 1.0 / 0x7fffff;
  189165. if (littleEndian)
  189166. {
  189167. while (--numSamples >= 0)
  189168. {
  189169. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189170. src += srcStrideBytes;
  189171. }
  189172. }
  189173. else
  189174. {
  189175. while (--numSamples >= 0)
  189176. {
  189177. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189178. src += srcStrideBytes;
  189179. }
  189180. }
  189181. }
  189182. static void convertFloatToInt24 (const float* src,
  189183. char* dest,
  189184. const int dstStrideBytes,
  189185. int numSamples,
  189186. const bool littleEndian) throw()
  189187. {
  189188. const double maxVal = (double) 0x7fffff;
  189189. if (littleEndian)
  189190. {
  189191. while (--numSamples >= 0)
  189192. {
  189193. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189194. dest += dstStrideBytes;
  189195. }
  189196. }
  189197. else
  189198. {
  189199. while (--numSamples >= 0)
  189200. {
  189201. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189202. dest += dstStrideBytes;
  189203. }
  189204. }
  189205. }
  189206. static void convertInt32ToFloat (const char* src,
  189207. float* dest,
  189208. const int srcStrideBytes,
  189209. int numSamples,
  189210. const bool littleEndian) throw()
  189211. {
  189212. const double g = 1.0 / 0x7fffffff;
  189213. if (littleEndian)
  189214. {
  189215. while (--numSamples >= 0)
  189216. {
  189217. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189218. src += srcStrideBytes;
  189219. }
  189220. }
  189221. else
  189222. {
  189223. while (--numSamples >= 0)
  189224. {
  189225. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189226. src += srcStrideBytes;
  189227. }
  189228. }
  189229. }
  189230. static void convertFloatToInt32 (const float* src,
  189231. char* dest,
  189232. const int dstStrideBytes,
  189233. int numSamples,
  189234. const bool littleEndian) throw()
  189235. {
  189236. const double maxVal = (double) 0x7fffffff;
  189237. if (littleEndian)
  189238. {
  189239. while (--numSamples >= 0)
  189240. {
  189241. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189242. dest += dstStrideBytes;
  189243. }
  189244. }
  189245. else
  189246. {
  189247. while (--numSamples >= 0)
  189248. {
  189249. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189250. dest += dstStrideBytes;
  189251. }
  189252. }
  189253. }
  189254. static void typeToFormatParameters (const long type,
  189255. int& bitDepth,
  189256. int& byteStride,
  189257. bool& formatIsFloat,
  189258. bool& littleEndian) throw()
  189259. {
  189260. bitDepth = 0;
  189261. littleEndian = false;
  189262. formatIsFloat = false;
  189263. switch (type)
  189264. {
  189265. case ASIOSTInt16MSB:
  189266. case ASIOSTInt16LSB:
  189267. case ASIOSTInt32MSB16:
  189268. case ASIOSTInt32LSB16:
  189269. bitDepth = 16; break;
  189270. case ASIOSTFloat32MSB:
  189271. case ASIOSTFloat32LSB:
  189272. formatIsFloat = true;
  189273. bitDepth = 32; break;
  189274. case ASIOSTInt32MSB:
  189275. case ASIOSTInt32LSB:
  189276. bitDepth = 32; break;
  189277. case ASIOSTInt24MSB:
  189278. case ASIOSTInt24LSB:
  189279. case ASIOSTInt32MSB24:
  189280. case ASIOSTInt32LSB24:
  189281. case ASIOSTInt32MSB18:
  189282. case ASIOSTInt32MSB20:
  189283. case ASIOSTInt32LSB18:
  189284. case ASIOSTInt32LSB20:
  189285. bitDepth = 24; break;
  189286. case ASIOSTFloat64MSB:
  189287. case ASIOSTFloat64LSB:
  189288. default:
  189289. bitDepth = 64;
  189290. break;
  189291. }
  189292. switch (type)
  189293. {
  189294. case ASIOSTInt16MSB:
  189295. case ASIOSTInt32MSB16:
  189296. case ASIOSTFloat32MSB:
  189297. case ASIOSTFloat64MSB:
  189298. case ASIOSTInt32MSB:
  189299. case ASIOSTInt32MSB18:
  189300. case ASIOSTInt32MSB20:
  189301. case ASIOSTInt32MSB24:
  189302. case ASIOSTInt24MSB:
  189303. littleEndian = false; break;
  189304. case ASIOSTInt16LSB:
  189305. case ASIOSTInt32LSB16:
  189306. case ASIOSTFloat32LSB:
  189307. case ASIOSTFloat64LSB:
  189308. case ASIOSTInt32LSB:
  189309. case ASIOSTInt32LSB18:
  189310. case ASIOSTInt32LSB20:
  189311. case ASIOSTInt32LSB24:
  189312. case ASIOSTInt24LSB:
  189313. littleEndian = true; break;
  189314. default:
  189315. break;
  189316. }
  189317. switch (type)
  189318. {
  189319. case ASIOSTInt16LSB:
  189320. case ASIOSTInt16MSB:
  189321. byteStride = 2; break;
  189322. case ASIOSTInt24LSB:
  189323. case ASIOSTInt24MSB:
  189324. byteStride = 3; break;
  189325. case ASIOSTInt32MSB16:
  189326. case ASIOSTInt32LSB16:
  189327. case ASIOSTInt32MSB:
  189328. case ASIOSTInt32MSB18:
  189329. case ASIOSTInt32MSB20:
  189330. case ASIOSTInt32MSB24:
  189331. case ASIOSTInt32LSB:
  189332. case ASIOSTInt32LSB18:
  189333. case ASIOSTInt32LSB20:
  189334. case ASIOSTInt32LSB24:
  189335. case ASIOSTFloat32LSB:
  189336. case ASIOSTFloat32MSB:
  189337. byteStride = 4; break;
  189338. case ASIOSTFloat64MSB:
  189339. case ASIOSTFloat64LSB:
  189340. byteStride = 8; break;
  189341. default:
  189342. break;
  189343. }
  189344. }
  189345. };
  189346. class ASIOAudioIODeviceType : public AudioIODeviceType
  189347. {
  189348. public:
  189349. ASIOAudioIODeviceType()
  189350. : AudioIODeviceType ("ASIO"),
  189351. hasScanned (false)
  189352. {
  189353. CoInitialize (0);
  189354. }
  189355. ~ASIOAudioIODeviceType()
  189356. {
  189357. }
  189358. void scanForDevices()
  189359. {
  189360. hasScanned = true;
  189361. deviceNames.clear();
  189362. classIds.clear();
  189363. HKEY hk = 0;
  189364. int index = 0;
  189365. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189366. {
  189367. for (;;)
  189368. {
  189369. char name [256];
  189370. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189371. {
  189372. addDriverInfo (name, hk);
  189373. }
  189374. else
  189375. {
  189376. break;
  189377. }
  189378. }
  189379. RegCloseKey (hk);
  189380. }
  189381. }
  189382. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189383. {
  189384. jassert (hasScanned); // need to call scanForDevices() before doing this
  189385. return deviceNames;
  189386. }
  189387. int getDefaultDeviceIndex (bool) const
  189388. {
  189389. jassert (hasScanned); // need to call scanForDevices() before doing this
  189390. for (int i = deviceNames.size(); --i >= 0;)
  189391. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189392. return i; // asio4all is a safe choice for a default..
  189393. #if JUCE_DEBUG
  189394. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189395. return 1; // (the digi m-box driver crashes the app when you run
  189396. // it in the debugger, which can be a bit annoying)
  189397. #endif
  189398. return 0;
  189399. }
  189400. static int findFreeSlot()
  189401. {
  189402. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189403. if (currentASIODev[i] == 0)
  189404. return i;
  189405. jassertfalse; // unfortunately you can only have a finite number
  189406. // of ASIO devices open at the same time..
  189407. return -1;
  189408. }
  189409. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189410. {
  189411. jassert (hasScanned); // need to call scanForDevices() before doing this
  189412. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189413. }
  189414. bool hasSeparateInputsAndOutputs() const { return false; }
  189415. AudioIODevice* createDevice (const String& outputDeviceName,
  189416. const String& inputDeviceName)
  189417. {
  189418. // ASIO can't open two different devices for input and output - they must be the same one.
  189419. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189420. jassert (hasScanned); // need to call scanForDevices() before doing this
  189421. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189422. : inputDeviceName);
  189423. if (index >= 0)
  189424. {
  189425. const int freeSlot = findFreeSlot();
  189426. if (freeSlot >= 0)
  189427. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189428. }
  189429. return 0;
  189430. }
  189431. juce_UseDebuggingNewOperator
  189432. private:
  189433. StringArray deviceNames;
  189434. OwnedArray <CLSID> classIds;
  189435. bool hasScanned;
  189436. static bool checkClassIsOk (const String& classId)
  189437. {
  189438. HKEY hk = 0;
  189439. bool ok = false;
  189440. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189441. {
  189442. int index = 0;
  189443. for (;;)
  189444. {
  189445. WCHAR buf [512];
  189446. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189447. {
  189448. if (classId.equalsIgnoreCase (buf))
  189449. {
  189450. HKEY subKey, pathKey;
  189451. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189452. {
  189453. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189454. {
  189455. WCHAR pathName [1024];
  189456. DWORD dtype = REG_SZ;
  189457. DWORD dsize = sizeof (pathName);
  189458. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189459. ok = File (pathName).exists();
  189460. RegCloseKey (pathKey);
  189461. }
  189462. RegCloseKey (subKey);
  189463. }
  189464. break;
  189465. }
  189466. }
  189467. else
  189468. {
  189469. break;
  189470. }
  189471. }
  189472. RegCloseKey (hk);
  189473. }
  189474. return ok;
  189475. }
  189476. void addDriverInfo (const String& keyName, HKEY hk)
  189477. {
  189478. HKEY subKey;
  189479. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189480. {
  189481. WCHAR buf [256];
  189482. zerostruct (buf);
  189483. DWORD dtype = REG_SZ;
  189484. DWORD dsize = sizeof (buf);
  189485. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189486. {
  189487. if (dsize > 0 && checkClassIsOk (buf))
  189488. {
  189489. CLSID classId;
  189490. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189491. {
  189492. dtype = REG_SZ;
  189493. dsize = sizeof (buf);
  189494. String deviceName;
  189495. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189496. deviceName = buf;
  189497. else
  189498. deviceName = keyName;
  189499. log ("found " + deviceName);
  189500. deviceNames.add (deviceName);
  189501. classIds.add (new CLSID (classId));
  189502. }
  189503. }
  189504. RegCloseKey (subKey);
  189505. }
  189506. }
  189507. }
  189508. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189509. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189510. };
  189511. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189512. {
  189513. return new ASIOAudioIODeviceType();
  189514. }
  189515. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189516. void* guid,
  189517. const String& optionalDllForDirectLoading)
  189518. {
  189519. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189520. if (freeSlot < 0)
  189521. return 0;
  189522. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189523. }
  189524. #undef log
  189525. #endif
  189526. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189527. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189528. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189529. // compiled on its own).
  189530. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189531. END_JUCE_NAMESPACE
  189532. extern "C"
  189533. {
  189534. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189535. typedef struct typeDSBUFFERDESC
  189536. {
  189537. DWORD dwSize;
  189538. DWORD dwFlags;
  189539. DWORD dwBufferBytes;
  189540. DWORD dwReserved;
  189541. LPWAVEFORMATEX lpwfxFormat;
  189542. GUID guid3DAlgorithm;
  189543. } DSBUFFERDESC;
  189544. struct IDirectSoundBuffer;
  189545. #undef INTERFACE
  189546. #define INTERFACE IDirectSound
  189547. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189548. {
  189549. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189550. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189551. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189552. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189553. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189554. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189555. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189556. STDMETHOD(Compact) (THIS) PURE;
  189557. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189558. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189559. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189560. };
  189561. #undef INTERFACE
  189562. #define INTERFACE IDirectSoundBuffer
  189563. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189564. {
  189565. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189566. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189567. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189568. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189569. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189570. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189571. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189572. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189573. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189574. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189575. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189576. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189577. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189578. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189579. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189580. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189581. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189582. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189583. STDMETHOD(Stop) (THIS) PURE;
  189584. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189585. STDMETHOD(Restore) (THIS) PURE;
  189586. };
  189587. typedef struct typeDSCBUFFERDESC
  189588. {
  189589. DWORD dwSize;
  189590. DWORD dwFlags;
  189591. DWORD dwBufferBytes;
  189592. DWORD dwReserved;
  189593. LPWAVEFORMATEX lpwfxFormat;
  189594. } DSCBUFFERDESC;
  189595. struct IDirectSoundCaptureBuffer;
  189596. #undef INTERFACE
  189597. #define INTERFACE IDirectSoundCapture
  189598. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189599. {
  189600. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189601. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189602. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189603. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189604. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189605. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189606. };
  189607. #undef INTERFACE
  189608. #define INTERFACE IDirectSoundCaptureBuffer
  189609. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189610. {
  189611. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189612. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189613. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189614. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189615. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189616. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189617. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189618. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189619. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189620. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189621. STDMETHOD(Stop) (THIS) PURE;
  189622. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189623. };
  189624. };
  189625. BEGIN_JUCE_NAMESPACE
  189626. static const String getDSErrorMessage (HRESULT hr)
  189627. {
  189628. const char* result = 0;
  189629. switch (hr)
  189630. {
  189631. case MAKE_HRESULT(1, 0x878, 10):
  189632. result = "Device already allocated";
  189633. break;
  189634. case MAKE_HRESULT(1, 0x878, 30):
  189635. result = "Control unavailable";
  189636. break;
  189637. case E_INVALIDARG:
  189638. result = "Invalid parameter";
  189639. break;
  189640. case MAKE_HRESULT(1, 0x878, 50):
  189641. result = "Invalid call";
  189642. break;
  189643. case E_FAIL:
  189644. result = "Generic error";
  189645. break;
  189646. case MAKE_HRESULT(1, 0x878, 70):
  189647. result = "Priority level error";
  189648. break;
  189649. case E_OUTOFMEMORY:
  189650. result = "Out of memory";
  189651. break;
  189652. case MAKE_HRESULT(1, 0x878, 100):
  189653. result = "Bad format";
  189654. break;
  189655. case E_NOTIMPL:
  189656. result = "Unsupported function";
  189657. break;
  189658. case MAKE_HRESULT(1, 0x878, 120):
  189659. result = "No driver";
  189660. break;
  189661. case MAKE_HRESULT(1, 0x878, 130):
  189662. result = "Already initialised";
  189663. break;
  189664. case CLASS_E_NOAGGREGATION:
  189665. result = "No aggregation";
  189666. break;
  189667. case MAKE_HRESULT(1, 0x878, 150):
  189668. result = "Buffer lost";
  189669. break;
  189670. case MAKE_HRESULT(1, 0x878, 160):
  189671. result = "Another app has priority";
  189672. break;
  189673. case MAKE_HRESULT(1, 0x878, 170):
  189674. result = "Uninitialised";
  189675. break;
  189676. case E_NOINTERFACE:
  189677. result = "No interface";
  189678. break;
  189679. case S_OK:
  189680. result = "No error";
  189681. break;
  189682. default:
  189683. return "Unknown error: " + String ((int) hr);
  189684. }
  189685. return result;
  189686. }
  189687. #define DS_DEBUGGING 1
  189688. #ifdef DS_DEBUGGING
  189689. #define CATCH JUCE_CATCH_EXCEPTION
  189690. #undef log
  189691. #define log(a) Logger::writeToLog(a);
  189692. #undef logError
  189693. #define logError(a) logDSError(a, __LINE__);
  189694. static void logDSError (HRESULT hr, int lineNum)
  189695. {
  189696. if (hr != S_OK)
  189697. {
  189698. String error ("DS error at line ");
  189699. error << lineNum << " - " << getDSErrorMessage (hr);
  189700. log (error);
  189701. }
  189702. }
  189703. #else
  189704. #define CATCH JUCE_CATCH_ALL
  189705. #define log(a)
  189706. #define logError(a)
  189707. #endif
  189708. #define DSOUND_FUNCTION(functionName, params) \
  189709. typedef HRESULT (WINAPI *type##functionName) params; \
  189710. static type##functionName ds##functionName = 0;
  189711. #define DSOUND_FUNCTION_LOAD(functionName) \
  189712. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189713. jassert (ds##functionName != 0);
  189714. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189715. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189716. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189717. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189718. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189719. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189720. static void initialiseDSoundFunctions()
  189721. {
  189722. if (dsDirectSoundCreate == 0)
  189723. {
  189724. HMODULE h = LoadLibraryA ("dsound.dll");
  189725. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189726. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189727. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189728. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189729. }
  189730. }
  189731. class DSoundInternalOutChannel
  189732. {
  189733. String name;
  189734. LPGUID guid;
  189735. int sampleRate, bufferSizeSamples;
  189736. float* leftBuffer;
  189737. float* rightBuffer;
  189738. IDirectSound* pDirectSound;
  189739. IDirectSoundBuffer* pOutputBuffer;
  189740. DWORD writeOffset;
  189741. int totalBytesPerBuffer;
  189742. int bytesPerBuffer;
  189743. unsigned int lastPlayCursor;
  189744. public:
  189745. int bitDepth;
  189746. bool doneFlag;
  189747. DSoundInternalOutChannel (const String& name_,
  189748. LPGUID guid_,
  189749. int rate,
  189750. int bufferSize,
  189751. float* left,
  189752. float* right)
  189753. : name (name_),
  189754. guid (guid_),
  189755. sampleRate (rate),
  189756. bufferSizeSamples (bufferSize),
  189757. leftBuffer (left),
  189758. rightBuffer (right),
  189759. pDirectSound (0),
  189760. pOutputBuffer (0),
  189761. bitDepth (16)
  189762. {
  189763. }
  189764. ~DSoundInternalOutChannel()
  189765. {
  189766. close();
  189767. }
  189768. void close()
  189769. {
  189770. HRESULT hr;
  189771. if (pOutputBuffer != 0)
  189772. {
  189773. JUCE_TRY
  189774. {
  189775. log ("closing dsound out: " + name);
  189776. hr = pOutputBuffer->Stop();
  189777. logError (hr);
  189778. }
  189779. CATCH
  189780. JUCE_TRY
  189781. {
  189782. hr = pOutputBuffer->Release();
  189783. logError (hr);
  189784. }
  189785. CATCH
  189786. pOutputBuffer = 0;
  189787. }
  189788. if (pDirectSound != 0)
  189789. {
  189790. JUCE_TRY
  189791. {
  189792. hr = pDirectSound->Release();
  189793. logError (hr);
  189794. }
  189795. CATCH
  189796. pDirectSound = 0;
  189797. }
  189798. }
  189799. const String open()
  189800. {
  189801. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189802. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189803. pDirectSound = 0;
  189804. pOutputBuffer = 0;
  189805. writeOffset = 0;
  189806. String error;
  189807. HRESULT hr = E_NOINTERFACE;
  189808. if (dsDirectSoundCreate != 0)
  189809. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189810. if (hr == S_OK)
  189811. {
  189812. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189813. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189814. const int numChannels = 2;
  189815. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189816. logError (hr);
  189817. if (hr == S_OK)
  189818. {
  189819. IDirectSoundBuffer* pPrimaryBuffer;
  189820. DSBUFFERDESC primaryDesc;
  189821. zerostruct (primaryDesc);
  189822. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189823. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189824. primaryDesc.dwBufferBytes = 0;
  189825. primaryDesc.lpwfxFormat = 0;
  189826. log ("opening dsound out step 2");
  189827. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189828. logError (hr);
  189829. if (hr == S_OK)
  189830. {
  189831. WAVEFORMATEX wfFormat;
  189832. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189833. wfFormat.nChannels = (unsigned short) numChannels;
  189834. wfFormat.nSamplesPerSec = sampleRate;
  189835. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189836. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189837. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189838. wfFormat.cbSize = 0;
  189839. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189840. logError (hr);
  189841. if (hr == S_OK)
  189842. {
  189843. DSBUFFERDESC secondaryDesc;
  189844. zerostruct (secondaryDesc);
  189845. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189846. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189847. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189848. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189849. secondaryDesc.lpwfxFormat = &wfFormat;
  189850. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189851. logError (hr);
  189852. if (hr == S_OK)
  189853. {
  189854. log ("opening dsound out step 3");
  189855. DWORD dwDataLen;
  189856. unsigned char* pDSBuffData;
  189857. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189858. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189859. logError (hr);
  189860. if (hr == S_OK)
  189861. {
  189862. zeromem (pDSBuffData, dwDataLen);
  189863. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189864. if (hr == S_OK)
  189865. {
  189866. hr = pOutputBuffer->SetCurrentPosition (0);
  189867. if (hr == S_OK)
  189868. {
  189869. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189870. if (hr == S_OK)
  189871. return String::empty;
  189872. }
  189873. }
  189874. }
  189875. }
  189876. }
  189877. }
  189878. }
  189879. }
  189880. error = getDSErrorMessage (hr);
  189881. close();
  189882. return error;
  189883. }
  189884. void synchronisePosition()
  189885. {
  189886. if (pOutputBuffer != 0)
  189887. {
  189888. DWORD playCursor;
  189889. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189890. }
  189891. }
  189892. bool service()
  189893. {
  189894. if (pOutputBuffer == 0)
  189895. return true;
  189896. DWORD playCursor, writeCursor;
  189897. for (;;)
  189898. {
  189899. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189900. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189901. {
  189902. pOutputBuffer->Restore();
  189903. continue;
  189904. }
  189905. if (hr == S_OK)
  189906. break;
  189907. logError (hr);
  189908. jassertfalse
  189909. return true;
  189910. }
  189911. int playWriteGap = writeCursor - playCursor;
  189912. if (playWriteGap < 0)
  189913. playWriteGap += totalBytesPerBuffer;
  189914. int bytesEmpty = playCursor - writeOffset;
  189915. if (bytesEmpty < 0)
  189916. bytesEmpty += totalBytesPerBuffer;
  189917. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189918. {
  189919. writeOffset = writeCursor;
  189920. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189921. }
  189922. if (bytesEmpty >= bytesPerBuffer)
  189923. {
  189924. LPBYTE lpbuf1 = 0;
  189925. LPBYTE lpbuf2 = 0;
  189926. DWORD dwSize1 = 0;
  189927. DWORD dwSize2 = 0;
  189928. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189929. bytesPerBuffer,
  189930. (void**) &lpbuf1, &dwSize1,
  189931. (void**) &lpbuf2, &dwSize2, 0);
  189932. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189933. {
  189934. pOutputBuffer->Restore();
  189935. hr = pOutputBuffer->Lock (writeOffset,
  189936. bytesPerBuffer,
  189937. (void**) &lpbuf1, &dwSize1,
  189938. (void**) &lpbuf2, &dwSize2, 0);
  189939. }
  189940. if (hr == S_OK)
  189941. {
  189942. if (bitDepth == 16)
  189943. {
  189944. const float gainL = 32767.0f;
  189945. const float gainR = 32767.0f;
  189946. int* dest = (int*)lpbuf1;
  189947. const float* left = leftBuffer;
  189948. const float* right = rightBuffer;
  189949. int samples1 = dwSize1 >> 2;
  189950. int samples2 = dwSize2 >> 2;
  189951. if (left == 0)
  189952. {
  189953. while (--samples1 >= 0)
  189954. {
  189955. int r = roundToInt (gainR * *right++);
  189956. if (r < -32768)
  189957. r = -32768;
  189958. else if (r > 32767)
  189959. r = 32767;
  189960. *dest++ = (r << 16);
  189961. }
  189962. dest = (int*)lpbuf2;
  189963. while (--samples2 >= 0)
  189964. {
  189965. int r = roundToInt (gainR * *right++);
  189966. if (r < -32768)
  189967. r = -32768;
  189968. else if (r > 32767)
  189969. r = 32767;
  189970. *dest++ = (r << 16);
  189971. }
  189972. }
  189973. else if (right == 0)
  189974. {
  189975. while (--samples1 >= 0)
  189976. {
  189977. int l = roundToInt (gainL * *left++);
  189978. if (l < -32768)
  189979. l = -32768;
  189980. else if (l > 32767)
  189981. l = 32767;
  189982. l &= 0xffff;
  189983. *dest++ = l;
  189984. }
  189985. dest = (int*)lpbuf2;
  189986. while (--samples2 >= 0)
  189987. {
  189988. int l = roundToInt (gainL * *left++);
  189989. if (l < -32768)
  189990. l = -32768;
  189991. else if (l > 32767)
  189992. l = 32767;
  189993. l &= 0xffff;
  189994. *dest++ = l;
  189995. }
  189996. }
  189997. else
  189998. {
  189999. while (--samples1 >= 0)
  190000. {
  190001. int l = roundToInt (gainL * *left++);
  190002. if (l < -32768)
  190003. l = -32768;
  190004. else if (l > 32767)
  190005. l = 32767;
  190006. l &= 0xffff;
  190007. int r = roundToInt (gainR * *right++);
  190008. if (r < -32768)
  190009. r = -32768;
  190010. else if (r > 32767)
  190011. r = 32767;
  190012. *dest++ = (r << 16) | l;
  190013. }
  190014. dest = (int*)lpbuf2;
  190015. while (--samples2 >= 0)
  190016. {
  190017. int l = roundToInt (gainL * *left++);
  190018. if (l < -32768)
  190019. l = -32768;
  190020. else if (l > 32767)
  190021. l = 32767;
  190022. l &= 0xffff;
  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) | l;
  190029. }
  190030. }
  190031. }
  190032. else
  190033. {
  190034. jassertfalse
  190035. }
  190036. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190037. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190038. }
  190039. else
  190040. {
  190041. jassertfalse
  190042. logError (hr);
  190043. }
  190044. bytesEmpty -= bytesPerBuffer;
  190045. return true;
  190046. }
  190047. else
  190048. {
  190049. return false;
  190050. }
  190051. }
  190052. };
  190053. struct DSoundInternalInChannel
  190054. {
  190055. String name;
  190056. LPGUID guid;
  190057. int sampleRate, bufferSizeSamples;
  190058. float* leftBuffer;
  190059. float* rightBuffer;
  190060. IDirectSound* pDirectSound;
  190061. IDirectSoundCapture* pDirectSoundCapture;
  190062. IDirectSoundCaptureBuffer* pInputBuffer;
  190063. public:
  190064. unsigned int readOffset;
  190065. int bytesPerBuffer, totalBytesPerBuffer;
  190066. int bitDepth;
  190067. bool doneFlag;
  190068. DSoundInternalInChannel (const String& name_,
  190069. LPGUID guid_,
  190070. int rate,
  190071. int bufferSize,
  190072. float* left,
  190073. float* right)
  190074. : name (name_),
  190075. guid (guid_),
  190076. sampleRate (rate),
  190077. bufferSizeSamples (bufferSize),
  190078. leftBuffer (left),
  190079. rightBuffer (right),
  190080. pDirectSound (0),
  190081. pDirectSoundCapture (0),
  190082. pInputBuffer (0),
  190083. bitDepth (16)
  190084. {
  190085. }
  190086. ~DSoundInternalInChannel()
  190087. {
  190088. close();
  190089. }
  190090. void close()
  190091. {
  190092. HRESULT hr;
  190093. if (pInputBuffer != 0)
  190094. {
  190095. JUCE_TRY
  190096. {
  190097. log ("closing dsound in: " + name);
  190098. hr = pInputBuffer->Stop();
  190099. logError (hr);
  190100. }
  190101. CATCH
  190102. JUCE_TRY
  190103. {
  190104. hr = pInputBuffer->Release();
  190105. logError (hr);
  190106. }
  190107. CATCH
  190108. pInputBuffer = 0;
  190109. }
  190110. if (pDirectSoundCapture != 0)
  190111. {
  190112. JUCE_TRY
  190113. {
  190114. hr = pDirectSoundCapture->Release();
  190115. logError (hr);
  190116. }
  190117. CATCH
  190118. pDirectSoundCapture = 0;
  190119. }
  190120. if (pDirectSound != 0)
  190121. {
  190122. JUCE_TRY
  190123. {
  190124. hr = pDirectSound->Release();
  190125. logError (hr);
  190126. }
  190127. CATCH
  190128. pDirectSound = 0;
  190129. }
  190130. }
  190131. const String open()
  190132. {
  190133. log ("opening dsound in device: " + name
  190134. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190135. pDirectSound = 0;
  190136. pDirectSoundCapture = 0;
  190137. pInputBuffer = 0;
  190138. readOffset = 0;
  190139. totalBytesPerBuffer = 0;
  190140. String error;
  190141. HRESULT hr = E_NOINTERFACE;
  190142. if (dsDirectSoundCaptureCreate != 0)
  190143. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190144. logError (hr);
  190145. if (hr == S_OK)
  190146. {
  190147. const int numChannels = 2;
  190148. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190149. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190150. WAVEFORMATEX wfFormat;
  190151. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190152. wfFormat.nChannels = (unsigned short)numChannels;
  190153. wfFormat.nSamplesPerSec = sampleRate;
  190154. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190155. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190156. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190157. wfFormat.cbSize = 0;
  190158. DSCBUFFERDESC captureDesc;
  190159. zerostruct (captureDesc);
  190160. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190161. captureDesc.dwFlags = 0;
  190162. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190163. captureDesc.lpwfxFormat = &wfFormat;
  190164. log ("opening dsound in step 2");
  190165. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190166. logError (hr);
  190167. if (hr == S_OK)
  190168. {
  190169. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190170. logError (hr);
  190171. if (hr == S_OK)
  190172. return String::empty;
  190173. }
  190174. }
  190175. error = getDSErrorMessage (hr);
  190176. close();
  190177. return error;
  190178. }
  190179. void synchronisePosition()
  190180. {
  190181. if (pInputBuffer != 0)
  190182. {
  190183. DWORD capturePos;
  190184. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190185. }
  190186. }
  190187. bool service()
  190188. {
  190189. if (pInputBuffer == 0)
  190190. return true;
  190191. DWORD capturePos, readPos;
  190192. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190193. logError (hr);
  190194. if (hr != S_OK)
  190195. return true;
  190196. int bytesFilled = readPos - readOffset;
  190197. if (bytesFilled < 0)
  190198. bytesFilled += totalBytesPerBuffer;
  190199. if (bytesFilled >= bytesPerBuffer)
  190200. {
  190201. LPBYTE lpbuf1 = 0;
  190202. LPBYTE lpbuf2 = 0;
  190203. DWORD dwsize1 = 0;
  190204. DWORD dwsize2 = 0;
  190205. HRESULT hr = pInputBuffer->Lock (readOffset,
  190206. bytesPerBuffer,
  190207. (void**) &lpbuf1, &dwsize1,
  190208. (void**) &lpbuf2, &dwsize2, 0);
  190209. if (hr == S_OK)
  190210. {
  190211. if (bitDepth == 16)
  190212. {
  190213. const float g = 1.0f / 32768.0f;
  190214. float* destL = leftBuffer;
  190215. float* destR = rightBuffer;
  190216. int samples1 = dwsize1 >> 2;
  190217. int samples2 = dwsize2 >> 2;
  190218. const short* src = (const short*)lpbuf1;
  190219. if (destL == 0)
  190220. {
  190221. while (--samples1 >= 0)
  190222. {
  190223. ++src;
  190224. *destR++ = *src++ * g;
  190225. }
  190226. src = (const short*)lpbuf2;
  190227. while (--samples2 >= 0)
  190228. {
  190229. ++src;
  190230. *destR++ = *src++ * g;
  190231. }
  190232. }
  190233. else if (destR == 0)
  190234. {
  190235. while (--samples1 >= 0)
  190236. {
  190237. *destL++ = *src++ * g;
  190238. ++src;
  190239. }
  190240. src = (const short*)lpbuf2;
  190241. while (--samples2 >= 0)
  190242. {
  190243. *destL++ = *src++ * g;
  190244. ++src;
  190245. }
  190246. }
  190247. else
  190248. {
  190249. while (--samples1 >= 0)
  190250. {
  190251. *destL++ = *src++ * g;
  190252. *destR++ = *src++ * g;
  190253. }
  190254. src = (const short*)lpbuf2;
  190255. while (--samples2 >= 0)
  190256. {
  190257. *destL++ = *src++ * g;
  190258. *destR++ = *src++ * g;
  190259. }
  190260. }
  190261. }
  190262. else
  190263. {
  190264. jassertfalse
  190265. }
  190266. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190267. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190268. }
  190269. else
  190270. {
  190271. logError (hr);
  190272. jassertfalse
  190273. }
  190274. bytesFilled -= bytesPerBuffer;
  190275. return true;
  190276. }
  190277. else
  190278. {
  190279. return false;
  190280. }
  190281. }
  190282. };
  190283. class DSoundAudioIODevice : public AudioIODevice,
  190284. public Thread
  190285. {
  190286. public:
  190287. DSoundAudioIODevice (const String& deviceName,
  190288. const int outputDeviceIndex_,
  190289. const int inputDeviceIndex_)
  190290. : AudioIODevice (deviceName, "DirectSound"),
  190291. Thread ("Juce DSound"),
  190292. isOpen_ (false),
  190293. isStarted (false),
  190294. outputDeviceIndex (outputDeviceIndex_),
  190295. inputDeviceIndex (inputDeviceIndex_),
  190296. numInputBuffers (0),
  190297. numOutputBuffers (0),
  190298. totalSamplesOut (0),
  190299. sampleRate (0.0),
  190300. inputBuffers (0),
  190301. outputBuffers (0),
  190302. callback (0),
  190303. bufferSizeSamples (0)
  190304. {
  190305. if (outputDeviceIndex_ >= 0)
  190306. {
  190307. outChannels.add (TRANS("Left"));
  190308. outChannels.add (TRANS("Right"));
  190309. }
  190310. if (inputDeviceIndex_ >= 0)
  190311. {
  190312. inChannels.add (TRANS("Left"));
  190313. inChannels.add (TRANS("Right"));
  190314. }
  190315. }
  190316. ~DSoundAudioIODevice()
  190317. {
  190318. close();
  190319. }
  190320. const StringArray getOutputChannelNames()
  190321. {
  190322. return outChannels;
  190323. }
  190324. const StringArray getInputChannelNames()
  190325. {
  190326. return inChannels;
  190327. }
  190328. int getNumSampleRates()
  190329. {
  190330. return 4;
  190331. }
  190332. double getSampleRate (int index)
  190333. {
  190334. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190335. return samps [jlimit (0, 3, index)];
  190336. }
  190337. int getNumBufferSizesAvailable()
  190338. {
  190339. return 50;
  190340. }
  190341. int getBufferSizeSamples (int index)
  190342. {
  190343. int n = 64;
  190344. for (int i = 0; i < index; ++i)
  190345. n += (n < 512) ? 32
  190346. : ((n < 1024) ? 64
  190347. : ((n < 2048) ? 128 : 256));
  190348. return n;
  190349. }
  190350. int getDefaultBufferSize()
  190351. {
  190352. return 2560;
  190353. }
  190354. const String open (const BigInteger& inputChannels,
  190355. const BigInteger& outputChannels,
  190356. double sampleRate,
  190357. int bufferSizeSamples)
  190358. {
  190359. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190360. isOpen_ = lastError.isEmpty();
  190361. return lastError;
  190362. }
  190363. void close()
  190364. {
  190365. stop();
  190366. if (isOpen_)
  190367. {
  190368. closeDevice();
  190369. isOpen_ = false;
  190370. }
  190371. }
  190372. bool isOpen()
  190373. {
  190374. return isOpen_ && isThreadRunning();
  190375. }
  190376. int getCurrentBufferSizeSamples()
  190377. {
  190378. return bufferSizeSamples;
  190379. }
  190380. double getCurrentSampleRate()
  190381. {
  190382. return sampleRate;
  190383. }
  190384. int getCurrentBitDepth()
  190385. {
  190386. int i, bits = 256;
  190387. for (i = inChans.size(); --i >= 0;)
  190388. bits = jmin (bits, inChans[i]->bitDepth);
  190389. for (i = outChans.size(); --i >= 0;)
  190390. bits = jmin (bits, outChans[i]->bitDepth);
  190391. if (bits > 32)
  190392. bits = 16;
  190393. return bits;
  190394. }
  190395. const BigInteger getActiveOutputChannels() const
  190396. {
  190397. return enabledOutputs;
  190398. }
  190399. const BigInteger getActiveInputChannels() const
  190400. {
  190401. return enabledInputs;
  190402. }
  190403. int getOutputLatencyInSamples()
  190404. {
  190405. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190406. }
  190407. int getInputLatencyInSamples()
  190408. {
  190409. return getOutputLatencyInSamples();
  190410. }
  190411. void start (AudioIODeviceCallback* call)
  190412. {
  190413. if (isOpen_ && call != 0 && ! isStarted)
  190414. {
  190415. if (! isThreadRunning())
  190416. {
  190417. // something gone wrong and the thread's stopped..
  190418. isOpen_ = false;
  190419. return;
  190420. }
  190421. call->audioDeviceAboutToStart (this);
  190422. const ScopedLock sl (startStopLock);
  190423. callback = call;
  190424. isStarted = true;
  190425. }
  190426. }
  190427. void stop()
  190428. {
  190429. if (isStarted)
  190430. {
  190431. AudioIODeviceCallback* const callbackLocal = callback;
  190432. {
  190433. const ScopedLock sl (startStopLock);
  190434. isStarted = false;
  190435. }
  190436. if (callbackLocal != 0)
  190437. callbackLocal->audioDeviceStopped();
  190438. }
  190439. }
  190440. bool isPlaying()
  190441. {
  190442. return isStarted && isOpen_ && isThreadRunning();
  190443. }
  190444. const String getLastError()
  190445. {
  190446. return lastError;
  190447. }
  190448. juce_UseDebuggingNewOperator
  190449. StringArray inChannels, outChannels;
  190450. int outputDeviceIndex, inputDeviceIndex;
  190451. private:
  190452. bool isOpen_;
  190453. bool isStarted;
  190454. String lastError;
  190455. OwnedArray <DSoundInternalInChannel> inChans;
  190456. OwnedArray <DSoundInternalOutChannel> outChans;
  190457. WaitableEvent startEvent;
  190458. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190459. int volatile totalSamplesOut;
  190460. int64 volatile lastBlockTime;
  190461. double sampleRate;
  190462. BigInteger enabledInputs, enabledOutputs;
  190463. HeapBlock <float*> inputBuffers, outputBuffers;
  190464. AudioIODeviceCallback* callback;
  190465. CriticalSection startStopLock;
  190466. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190467. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190468. const String openDevice (const BigInteger& inputChannels,
  190469. const BigInteger& outputChannels,
  190470. double sampleRate_,
  190471. int bufferSizeSamples_);
  190472. void closeDevice()
  190473. {
  190474. isStarted = false;
  190475. stopThread (5000);
  190476. inChans.clear();
  190477. outChans.clear();
  190478. int i;
  190479. for (i = 0; i < numInputBuffers; ++i)
  190480. juce_free (inputBuffers[i]);
  190481. inputBuffers.free();
  190482. numInputBuffers = 0;
  190483. for (i = 0; i < numOutputBuffers; ++i)
  190484. juce_free (outputBuffers[i]);
  190485. outputBuffers.free();
  190486. numOutputBuffers = 0;
  190487. }
  190488. void resync()
  190489. {
  190490. if (! threadShouldExit())
  190491. {
  190492. sleep (5);
  190493. int i;
  190494. for (i = 0; i < outChans.size(); ++i)
  190495. outChans.getUnchecked(i)->synchronisePosition();
  190496. for (i = 0; i < inChans.size(); ++i)
  190497. inChans.getUnchecked(i)->synchronisePosition();
  190498. }
  190499. }
  190500. public:
  190501. void run()
  190502. {
  190503. while (! threadShouldExit())
  190504. {
  190505. if (wait (100))
  190506. break;
  190507. }
  190508. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190509. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190510. while (! threadShouldExit())
  190511. {
  190512. int numToDo = 0;
  190513. uint32 startTime = Time::getMillisecondCounter();
  190514. int i;
  190515. for (i = inChans.size(); --i >= 0;)
  190516. {
  190517. inChans.getUnchecked(i)->doneFlag = false;
  190518. ++numToDo;
  190519. }
  190520. for (i = outChans.size(); --i >= 0;)
  190521. {
  190522. outChans.getUnchecked(i)->doneFlag = false;
  190523. ++numToDo;
  190524. }
  190525. if (numToDo > 0)
  190526. {
  190527. const int maxCount = 3;
  190528. int count = maxCount;
  190529. for (;;)
  190530. {
  190531. for (i = inChans.size(); --i >= 0;)
  190532. {
  190533. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190534. if ((! in->doneFlag) && in->service())
  190535. {
  190536. in->doneFlag = true;
  190537. --numToDo;
  190538. }
  190539. }
  190540. for (i = outChans.size(); --i >= 0;)
  190541. {
  190542. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190543. if ((! out->doneFlag) && out->service())
  190544. {
  190545. out->doneFlag = true;
  190546. --numToDo;
  190547. }
  190548. }
  190549. if (numToDo <= 0)
  190550. break;
  190551. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190552. {
  190553. resync();
  190554. break;
  190555. }
  190556. if (--count <= 0)
  190557. {
  190558. Sleep (1);
  190559. count = maxCount;
  190560. }
  190561. if (threadShouldExit())
  190562. return;
  190563. }
  190564. }
  190565. else
  190566. {
  190567. sleep (1);
  190568. }
  190569. const ScopedLock sl (startStopLock);
  190570. if (isStarted)
  190571. {
  190572. JUCE_TRY
  190573. {
  190574. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190575. numInputBuffers,
  190576. outputBuffers,
  190577. numOutputBuffers,
  190578. bufferSizeSamples);
  190579. }
  190580. JUCE_CATCH_EXCEPTION
  190581. totalSamplesOut += bufferSizeSamples;
  190582. }
  190583. else
  190584. {
  190585. for (i = 0; i < numOutputBuffers; ++i)
  190586. if (outputBuffers[i] != 0)
  190587. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190588. totalSamplesOut = 0;
  190589. sleep (1);
  190590. }
  190591. }
  190592. }
  190593. };
  190594. class DSoundAudioIODeviceType : public AudioIODeviceType
  190595. {
  190596. public:
  190597. DSoundAudioIODeviceType()
  190598. : AudioIODeviceType ("DirectSound"),
  190599. hasScanned (false)
  190600. {
  190601. initialiseDSoundFunctions();
  190602. }
  190603. ~DSoundAudioIODeviceType()
  190604. {
  190605. }
  190606. void scanForDevices()
  190607. {
  190608. hasScanned = true;
  190609. outputDeviceNames.clear();
  190610. outputGuids.clear();
  190611. inputDeviceNames.clear();
  190612. inputGuids.clear();
  190613. if (dsDirectSoundEnumerateW != 0)
  190614. {
  190615. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190616. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190617. }
  190618. }
  190619. const StringArray getDeviceNames (bool wantInputNames) const
  190620. {
  190621. jassert (hasScanned); // need to call scanForDevices() before doing this
  190622. return wantInputNames ? inputDeviceNames
  190623. : outputDeviceNames;
  190624. }
  190625. int getDefaultDeviceIndex (bool /*forInput*/) const
  190626. {
  190627. jassert (hasScanned); // need to call scanForDevices() before doing this
  190628. return 0;
  190629. }
  190630. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190631. {
  190632. jassert (hasScanned); // need to call scanForDevices() before doing this
  190633. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190634. if (d == 0)
  190635. return -1;
  190636. return asInput ? d->inputDeviceIndex
  190637. : d->outputDeviceIndex;
  190638. }
  190639. bool hasSeparateInputsAndOutputs() const { return true; }
  190640. AudioIODevice* createDevice (const String& outputDeviceName,
  190641. const String& inputDeviceName)
  190642. {
  190643. jassert (hasScanned); // need to call scanForDevices() before doing this
  190644. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190645. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190646. if (outputIndex >= 0 || inputIndex >= 0)
  190647. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190648. : inputDeviceName,
  190649. outputIndex, inputIndex);
  190650. return 0;
  190651. }
  190652. juce_UseDebuggingNewOperator
  190653. StringArray outputDeviceNames;
  190654. OwnedArray <GUID> outputGuids;
  190655. StringArray inputDeviceNames;
  190656. OwnedArray <GUID> inputGuids;
  190657. private:
  190658. bool hasScanned;
  190659. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190660. {
  190661. desc = desc.trim();
  190662. if (desc.isNotEmpty())
  190663. {
  190664. const String origDesc (desc);
  190665. int n = 2;
  190666. while (outputDeviceNames.contains (desc))
  190667. desc = origDesc + " (" + String (n++) + ")";
  190668. outputDeviceNames.add (desc);
  190669. if (lpGUID != 0)
  190670. outputGuids.add (new GUID (*lpGUID));
  190671. else
  190672. outputGuids.add (0);
  190673. }
  190674. return TRUE;
  190675. }
  190676. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190677. {
  190678. return ((DSoundAudioIODeviceType*) object)
  190679. ->outputEnumProc (lpGUID, String (description));
  190680. }
  190681. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190682. {
  190683. return ((DSoundAudioIODeviceType*) object)
  190684. ->outputEnumProc (lpGUID, String (description));
  190685. }
  190686. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190687. {
  190688. desc = desc.trim();
  190689. if (desc.isNotEmpty())
  190690. {
  190691. const String origDesc (desc);
  190692. int n = 2;
  190693. while (inputDeviceNames.contains (desc))
  190694. desc = origDesc + " (" + String (n++) + ")";
  190695. inputDeviceNames.add (desc);
  190696. if (lpGUID != 0)
  190697. inputGuids.add (new GUID (*lpGUID));
  190698. else
  190699. inputGuids.add (0);
  190700. }
  190701. return TRUE;
  190702. }
  190703. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190704. {
  190705. return ((DSoundAudioIODeviceType*) object)
  190706. ->inputEnumProc (lpGUID, String (description));
  190707. }
  190708. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190709. {
  190710. return ((DSoundAudioIODeviceType*) object)
  190711. ->inputEnumProc (lpGUID, String (description));
  190712. }
  190713. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190714. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190715. };
  190716. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190717. const BigInteger& outputChannels,
  190718. double sampleRate_,
  190719. int bufferSizeSamples_)
  190720. {
  190721. closeDevice();
  190722. totalSamplesOut = 0;
  190723. sampleRate = sampleRate_;
  190724. if (bufferSizeSamples_ <= 0)
  190725. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190726. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190727. DSoundAudioIODeviceType dlh;
  190728. dlh.scanForDevices();
  190729. enabledInputs = inputChannels;
  190730. enabledInputs.setRange (inChannels.size(),
  190731. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190732. false);
  190733. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190734. inputBuffers.calloc (numInputBuffers + 2);
  190735. int i, numIns = 0;
  190736. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190737. {
  190738. float* left = 0;
  190739. float* right = 0;
  190740. if (enabledInputs[i])
  190741. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190742. if (enabledInputs[i + 1])
  190743. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190744. if (left != 0 || right != 0)
  190745. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190746. dlh.inputGuids [inputDeviceIndex],
  190747. (int) sampleRate, bufferSizeSamples,
  190748. left, right));
  190749. }
  190750. enabledOutputs = outputChannels;
  190751. enabledOutputs.setRange (outChannels.size(),
  190752. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190753. false);
  190754. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190755. outputBuffers.calloc (numOutputBuffers + 2);
  190756. int numOuts = 0;
  190757. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190758. {
  190759. float* left = 0;
  190760. float* right = 0;
  190761. if (enabledOutputs[i])
  190762. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190763. if (enabledOutputs[i + 1])
  190764. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190765. if (left != 0 || right != 0)
  190766. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190767. dlh.outputGuids [outputDeviceIndex],
  190768. (int) sampleRate, bufferSizeSamples,
  190769. left, right));
  190770. }
  190771. String error;
  190772. // boost our priority while opening the devices to try to get better sync between them
  190773. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190774. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190775. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190776. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190777. for (i = 0; i < outChans.size(); ++i)
  190778. {
  190779. error = outChans[i]->open();
  190780. if (error.isNotEmpty())
  190781. {
  190782. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190783. break;
  190784. }
  190785. }
  190786. if (error.isEmpty())
  190787. {
  190788. for (i = 0; i < inChans.size(); ++i)
  190789. {
  190790. error = inChans[i]->open();
  190791. if (error.isNotEmpty())
  190792. {
  190793. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190794. break;
  190795. }
  190796. }
  190797. }
  190798. if (error.isEmpty())
  190799. {
  190800. totalSamplesOut = 0;
  190801. for (i = 0; i < outChans.size(); ++i)
  190802. outChans.getUnchecked(i)->synchronisePosition();
  190803. for (i = 0; i < inChans.size(); ++i)
  190804. inChans.getUnchecked(i)->synchronisePosition();
  190805. startThread (9);
  190806. sleep (10);
  190807. notify();
  190808. }
  190809. else
  190810. {
  190811. log (error);
  190812. }
  190813. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190814. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190815. return error;
  190816. }
  190817. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190818. {
  190819. return new DSoundAudioIODeviceType();
  190820. }
  190821. #undef log
  190822. #endif
  190823. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190824. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190825. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190826. // compiled on its own).
  190827. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190828. #if 1
  190829. const String getAudioErrorDesc (HRESULT hr)
  190830. {
  190831. const char* e = 0;
  190832. switch (hr)
  190833. {
  190834. case E_POINTER: e = "E_POINTER"; break;
  190835. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190836. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190837. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190838. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190839. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190840. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190841. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190842. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190843. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190844. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190845. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190846. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190847. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190848. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190849. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190850. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190851. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190852. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190853. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190854. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190855. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190856. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190857. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190858. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190859. default: return String::toHexString ((int) hr);
  190860. }
  190861. return e;
  190862. }
  190863. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190864. #define OK(a) wasapi_checkResult(a)
  190865. static bool wasapi_checkResult (HRESULT hr)
  190866. {
  190867. logFailure (hr);
  190868. return SUCCEEDED (hr);
  190869. }
  190870. #else
  190871. #define logFailure(hr) {}
  190872. #define OK(a) SUCCEEDED(a)
  190873. #endif
  190874. static const String wasapi_getDeviceID (IMMDevice* const device)
  190875. {
  190876. String s;
  190877. WCHAR* deviceId = 0;
  190878. if (OK (device->GetId (&deviceId)))
  190879. {
  190880. s = String (deviceId);
  190881. CoTaskMemFree (deviceId);
  190882. }
  190883. return s;
  190884. }
  190885. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190886. {
  190887. EDataFlow flow = eRender;
  190888. ComSmartPtr <IMMEndpoint> endPoint;
  190889. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190890. (void) OK (endPoint->GetDataFlow (&flow));
  190891. return flow;
  190892. }
  190893. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190894. {
  190895. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190896. }
  190897. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190898. {
  190899. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190900. : sizeof (WAVEFORMATEX));
  190901. }
  190902. class WASAPIDeviceBase
  190903. {
  190904. public:
  190905. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190906. : device (device_),
  190907. sampleRate (0),
  190908. numChannels (0),
  190909. actualNumChannels (0),
  190910. defaultSampleRate (0),
  190911. minBufferSize (0),
  190912. defaultBufferSize (0),
  190913. latencySamples (0),
  190914. useExclusiveMode (useExclusiveMode_)
  190915. {
  190916. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190917. ComSmartPtr <IAudioClient> tempClient (createClient());
  190918. if (tempClient == 0)
  190919. return;
  190920. REFERENCE_TIME defaultPeriod, minPeriod;
  190921. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190922. return;
  190923. WAVEFORMATEX* mixFormat = 0;
  190924. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190925. return;
  190926. WAVEFORMATEXTENSIBLE format;
  190927. wasapi_copyWavFormat (format, mixFormat);
  190928. CoTaskMemFree (mixFormat);
  190929. actualNumChannels = numChannels = format.Format.nChannels;
  190930. defaultSampleRate = format.Format.nSamplesPerSec;
  190931. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  190932. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  190933. FloatElementComparator<double> comparator;
  190934. rates.addSorted (comparator, defaultSampleRate);
  190935. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190936. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  190937. {
  190938. if (ratesToTest[i] == defaultSampleRate)
  190939. continue;
  190940. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  190941. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190942. (WAVEFORMATEX*) &format, 0)))
  190943. if (! rates.contains (ratesToTest[i]))
  190944. rates.addSorted (comparator, ratesToTest[i]);
  190945. }
  190946. }
  190947. ~WASAPIDeviceBase()
  190948. {
  190949. device = 0;
  190950. CloseHandle (clientEvent);
  190951. }
  190952. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  190953. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  190954. {
  190955. sampleRate = newSampleRate;
  190956. channels = newChannels;
  190957. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  190958. numChannels = channels.getHighestBit() + 1;
  190959. if (numChannels == 0)
  190960. return true;
  190961. client = createClient();
  190962. if (client != 0
  190963. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  190964. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  190965. {
  190966. channelMaps.clear();
  190967. for (int i = 0; i <= channels.getHighestBit(); ++i)
  190968. if (channels[i])
  190969. channelMaps.add (i);
  190970. REFERENCE_TIME latency;
  190971. if (OK (client->GetStreamLatency (&latency)))
  190972. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  190973. (void) OK (client->GetBufferSize (&actualBufferSize));
  190974. return OK (client->SetEventHandle (clientEvent));
  190975. }
  190976. return false;
  190977. }
  190978. void closeClient()
  190979. {
  190980. if (client != 0)
  190981. client->Stop();
  190982. client = 0;
  190983. ResetEvent (clientEvent);
  190984. }
  190985. ComSmartPtr <IMMDevice> device;
  190986. ComSmartPtr <IAudioClient> client;
  190987. double sampleRate, defaultSampleRate;
  190988. int numChannels, actualNumChannels;
  190989. int minBufferSize, defaultBufferSize, latencySamples;
  190990. const bool useExclusiveMode;
  190991. Array <double> rates;
  190992. HANDLE clientEvent;
  190993. BigInteger channels;
  190994. AudioDataConverters::DataFormat dataFormat;
  190995. Array <int> channelMaps;
  190996. UINT32 actualBufferSize;
  190997. int bytesPerSample;
  190998. private:
  190999. const ComSmartPtr <IAudioClient> createClient()
  191000. {
  191001. ComSmartPtr <IAudioClient> client;
  191002. if (device != 0)
  191003. {
  191004. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191005. logFailure (hr);
  191006. }
  191007. return client;
  191008. }
  191009. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191010. {
  191011. WAVEFORMATEXTENSIBLE format;
  191012. zerostruct (format);
  191013. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191014. {
  191015. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191016. }
  191017. else
  191018. {
  191019. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191020. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191021. }
  191022. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191023. format.Format.nChannels = (WORD) numChannels;
  191024. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191025. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191026. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191027. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191028. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191029. switch (numChannels)
  191030. {
  191031. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191032. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191033. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191034. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191035. 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;
  191036. default: break;
  191037. }
  191038. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191039. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191040. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191041. logFailure (hr);
  191042. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191043. {
  191044. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191045. hr = S_OK;
  191046. }
  191047. CoTaskMemFree (nearestFormat);
  191048. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191049. if (useExclusiveMode)
  191050. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191051. GUID session;
  191052. if (hr == S_OK
  191053. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191054. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191055. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191056. {
  191057. actualNumChannels = format.Format.nChannels;
  191058. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191059. bytesPerSample = format.Format.wBitsPerSample / 8;
  191060. dataFormat = isFloat ? AudioDataConverters::float32LE
  191061. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191062. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191063. : AudioDataConverters::int16LE)));
  191064. return true;
  191065. }
  191066. return false;
  191067. }
  191068. };
  191069. class WASAPIInputDevice : public WASAPIDeviceBase
  191070. {
  191071. public:
  191072. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191073. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191074. reservoir (1, 1)
  191075. {
  191076. }
  191077. ~WASAPIInputDevice()
  191078. {
  191079. close();
  191080. }
  191081. bool open (const double newSampleRate, const BigInteger& newChannels)
  191082. {
  191083. reservoirSize = 0;
  191084. reservoirCapacity = 16384;
  191085. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191086. return openClient (newSampleRate, newChannels)
  191087. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191088. }
  191089. void close()
  191090. {
  191091. closeClient();
  191092. captureClient = 0;
  191093. reservoir.setSize (0);
  191094. }
  191095. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191096. {
  191097. if (numChannels <= 0)
  191098. return;
  191099. int offset = 0;
  191100. while (bufferSize > 0)
  191101. {
  191102. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191103. {
  191104. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191105. for (int i = 0; i < numDestBuffers; ++i)
  191106. {
  191107. float* const dest = destBuffers[i] + offset;
  191108. const int srcChan = channelMaps.getUnchecked(i);
  191109. switch (dataFormat)
  191110. {
  191111. case AudioDataConverters::float32LE:
  191112. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191113. break;
  191114. case AudioDataConverters::int32LE:
  191115. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191116. break;
  191117. case AudioDataConverters::int24LE:
  191118. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191119. break;
  191120. case AudioDataConverters::int16LE:
  191121. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191122. break;
  191123. default: jassertfalse; break;
  191124. }
  191125. }
  191126. bufferSize -= samplesToDo;
  191127. offset += samplesToDo;
  191128. reservoirSize -= samplesToDo;
  191129. }
  191130. else
  191131. {
  191132. UINT32 packetLength = 0;
  191133. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191134. break;
  191135. if (packetLength == 0)
  191136. {
  191137. if (thread.threadShouldExit())
  191138. break;
  191139. Thread::sleep (1);
  191140. continue;
  191141. }
  191142. uint8* inputData = 0;
  191143. UINT32 numSamplesAvailable;
  191144. DWORD flags;
  191145. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191146. {
  191147. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191148. for (int i = 0; i < numDestBuffers; ++i)
  191149. {
  191150. float* const dest = destBuffers[i] + offset;
  191151. const int srcChan = channelMaps.getUnchecked(i);
  191152. switch (dataFormat)
  191153. {
  191154. case AudioDataConverters::float32LE:
  191155. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191156. break;
  191157. case AudioDataConverters::int32LE:
  191158. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191159. break;
  191160. case AudioDataConverters::int24LE:
  191161. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191162. break;
  191163. case AudioDataConverters::int16LE:
  191164. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191165. break;
  191166. default: jassertfalse; break;
  191167. }
  191168. }
  191169. bufferSize -= samplesToDo;
  191170. offset += samplesToDo;
  191171. if (samplesToDo < (int) numSamplesAvailable)
  191172. {
  191173. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191174. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191175. bytesPerSample * actualNumChannels * reservoirSize);
  191176. }
  191177. captureClient->ReleaseBuffer (numSamplesAvailable);
  191178. }
  191179. }
  191180. }
  191181. }
  191182. ComSmartPtr <IAudioCaptureClient> captureClient;
  191183. MemoryBlock reservoir;
  191184. int reservoirSize, reservoirCapacity;
  191185. };
  191186. class WASAPIOutputDevice : public WASAPIDeviceBase
  191187. {
  191188. public:
  191189. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191190. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191191. {
  191192. }
  191193. ~WASAPIOutputDevice()
  191194. {
  191195. close();
  191196. }
  191197. bool open (const double newSampleRate, const BigInteger& newChannels)
  191198. {
  191199. return openClient (newSampleRate, newChannels)
  191200. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191201. }
  191202. void close()
  191203. {
  191204. closeClient();
  191205. renderClient = 0;
  191206. }
  191207. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191208. {
  191209. if (numChannels <= 0)
  191210. return;
  191211. int offset = 0;
  191212. while (bufferSize > 0)
  191213. {
  191214. UINT32 padding = 0;
  191215. if (! OK (client->GetCurrentPadding (&padding)))
  191216. return;
  191217. int samplesToDo = useExclusiveMode ? bufferSize
  191218. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191219. if (samplesToDo <= 0)
  191220. {
  191221. if (thread.threadShouldExit())
  191222. break;
  191223. Thread::sleep (0);
  191224. continue;
  191225. }
  191226. uint8* outputData = 0;
  191227. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191228. {
  191229. for (int i = 0; i < numSrcBuffers; ++i)
  191230. {
  191231. const float* const source = srcBuffers[i] + offset;
  191232. const int destChan = channelMaps.getUnchecked(i);
  191233. switch (dataFormat)
  191234. {
  191235. case AudioDataConverters::float32LE:
  191236. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191237. break;
  191238. case AudioDataConverters::int32LE:
  191239. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191240. break;
  191241. case AudioDataConverters::int24LE:
  191242. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191243. break;
  191244. case AudioDataConverters::int16LE:
  191245. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191246. break;
  191247. default: jassertfalse; break;
  191248. }
  191249. }
  191250. renderClient->ReleaseBuffer (samplesToDo, 0);
  191251. offset += samplesToDo;
  191252. bufferSize -= samplesToDo;
  191253. }
  191254. }
  191255. }
  191256. ComSmartPtr <IAudioRenderClient> renderClient;
  191257. };
  191258. class WASAPIAudioIODevice : public AudioIODevice,
  191259. public Thread
  191260. {
  191261. public:
  191262. WASAPIAudioIODevice (const String& deviceName,
  191263. const String& outputDeviceId_,
  191264. const String& inputDeviceId_,
  191265. const bool useExclusiveMode_)
  191266. : AudioIODevice (deviceName, "Windows Audio"),
  191267. Thread ("Juce WASAPI"),
  191268. isOpen_ (false),
  191269. isStarted (false),
  191270. outputDevice (0),
  191271. outputDeviceId (outputDeviceId_),
  191272. inputDevice (0),
  191273. inputDeviceId (inputDeviceId_),
  191274. useExclusiveMode (useExclusiveMode_),
  191275. currentBufferSizeSamples (0),
  191276. currentSampleRate (0),
  191277. callback (0)
  191278. {
  191279. }
  191280. ~WASAPIAudioIODevice()
  191281. {
  191282. close();
  191283. deleteAndZero (inputDevice);
  191284. deleteAndZero (outputDevice);
  191285. }
  191286. bool initialise()
  191287. {
  191288. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191289. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191290. latencyIn = latencyOut = 0;
  191291. Array <double> ratesIn, ratesOut;
  191292. if (createDevices())
  191293. {
  191294. jassert (inputDevice != 0 || outputDevice != 0);
  191295. if (inputDevice != 0 && outputDevice != 0)
  191296. {
  191297. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191298. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191299. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191300. sampleRates = inputDevice->rates;
  191301. sampleRates.removeValuesNotIn (outputDevice->rates);
  191302. }
  191303. else
  191304. {
  191305. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191306. defaultSampleRate = d->defaultSampleRate;
  191307. minBufferSize = d->minBufferSize;
  191308. defaultBufferSize = d->defaultBufferSize;
  191309. sampleRates = d->rates;
  191310. }
  191311. IntegerElementComparator<int> comparator;
  191312. bufferSizes.addSorted (comparator, defaultBufferSize);
  191313. if (minBufferSize != defaultBufferSize)
  191314. bufferSizes.addSorted (comparator, minBufferSize);
  191315. int n = 64;
  191316. for (int i = 0; i < 40; ++i)
  191317. {
  191318. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191319. bufferSizes.addSorted (comparator, n);
  191320. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191321. }
  191322. return true;
  191323. }
  191324. return false;
  191325. }
  191326. const StringArray getOutputChannelNames()
  191327. {
  191328. StringArray outChannels;
  191329. if (outputDevice != 0)
  191330. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191331. outChannels.add ("Output channel " + String (i));
  191332. return outChannels;
  191333. }
  191334. const StringArray getInputChannelNames()
  191335. {
  191336. StringArray inChannels;
  191337. if (inputDevice != 0)
  191338. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191339. inChannels.add ("Input channel " + String (i));
  191340. return inChannels;
  191341. }
  191342. int getNumSampleRates() { return sampleRates.size(); }
  191343. double getSampleRate (int index) { return sampleRates [index]; }
  191344. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191345. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191346. int getDefaultBufferSize() { return defaultBufferSize; }
  191347. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191348. double getCurrentSampleRate() { return currentSampleRate; }
  191349. int getCurrentBitDepth() { return 32; }
  191350. int getOutputLatencyInSamples() { return latencyOut; }
  191351. int getInputLatencyInSamples() { return latencyIn; }
  191352. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191353. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191354. const String getLastError() { return lastError; }
  191355. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191356. double sampleRate, int bufferSizeSamples)
  191357. {
  191358. close();
  191359. lastError = String::empty;
  191360. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191361. {
  191362. lastError = "The input and output devices don't share a common sample rate!";
  191363. return lastError;
  191364. }
  191365. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191366. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191367. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191368. {
  191369. lastError = "Couldn't open the input device!";
  191370. return lastError;
  191371. }
  191372. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191373. {
  191374. close();
  191375. lastError = "Couldn't open the output device!";
  191376. return lastError;
  191377. }
  191378. if (inputDevice != 0)
  191379. ResetEvent (inputDevice->clientEvent);
  191380. if (outputDevice != 0)
  191381. ResetEvent (outputDevice->clientEvent);
  191382. startThread (8);
  191383. Thread::sleep (5);
  191384. if (inputDevice != 0 && inputDevice->client != 0)
  191385. {
  191386. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191387. HRESULT hr = inputDevice->client->Start();
  191388. logFailure (hr); //xxx handle this
  191389. }
  191390. if (outputDevice != 0 && outputDevice->client != 0)
  191391. {
  191392. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191393. HRESULT hr = outputDevice->client->Start();
  191394. logFailure (hr); //xxx handle this
  191395. }
  191396. isOpen_ = true;
  191397. return lastError;
  191398. }
  191399. void close()
  191400. {
  191401. stop();
  191402. if (inputDevice != 0)
  191403. SetEvent (inputDevice->clientEvent);
  191404. if (outputDevice != 0)
  191405. SetEvent (outputDevice->clientEvent);
  191406. stopThread (5000);
  191407. if (inputDevice != 0)
  191408. inputDevice->close();
  191409. if (outputDevice != 0)
  191410. outputDevice->close();
  191411. isOpen_ = false;
  191412. }
  191413. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191414. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191415. void start (AudioIODeviceCallback* call)
  191416. {
  191417. if (isOpen_ && call != 0 && ! isStarted)
  191418. {
  191419. if (! isThreadRunning())
  191420. {
  191421. // something's gone wrong and the thread's stopped..
  191422. isOpen_ = false;
  191423. return;
  191424. }
  191425. call->audioDeviceAboutToStart (this);
  191426. const ScopedLock sl (startStopLock);
  191427. callback = call;
  191428. isStarted = true;
  191429. }
  191430. }
  191431. void stop()
  191432. {
  191433. if (isStarted)
  191434. {
  191435. AudioIODeviceCallback* const callbackLocal = callback;
  191436. {
  191437. const ScopedLock sl (startStopLock);
  191438. isStarted = false;
  191439. }
  191440. if (callbackLocal != 0)
  191441. callbackLocal->audioDeviceStopped();
  191442. }
  191443. }
  191444. void setMMThreadPriority()
  191445. {
  191446. DynamicLibraryLoader dll ("avrt.dll");
  191447. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191448. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191449. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191450. {
  191451. DWORD dummy = 0;
  191452. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191453. if (h != 0)
  191454. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191455. }
  191456. }
  191457. void run()
  191458. {
  191459. setMMThreadPriority();
  191460. const int bufferSize = currentBufferSizeSamples;
  191461. HANDLE events[2];
  191462. int numEvents = 0;
  191463. if (inputDevice != 0)
  191464. events [numEvents++] = inputDevice->clientEvent;
  191465. if (outputDevice != 0)
  191466. events [numEvents++] = outputDevice->clientEvent;
  191467. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191468. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191469. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191470. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191471. float** const inputBuffers = ins.getArrayOfChannels();
  191472. float** const outputBuffers = outs.getArrayOfChannels();
  191473. ins.clear();
  191474. while (! threadShouldExit())
  191475. {
  191476. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191477. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191478. if (result == WAIT_TIMEOUT)
  191479. continue;
  191480. if (threadShouldExit())
  191481. break;
  191482. if (inputDevice != 0)
  191483. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191484. // Make the callback..
  191485. {
  191486. const ScopedLock sl (startStopLock);
  191487. if (isStarted)
  191488. {
  191489. JUCE_TRY
  191490. {
  191491. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191492. numInputBuffers,
  191493. outputBuffers,
  191494. numOutputBuffers,
  191495. bufferSize);
  191496. }
  191497. JUCE_CATCH_EXCEPTION
  191498. }
  191499. else
  191500. {
  191501. outs.clear();
  191502. }
  191503. }
  191504. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191505. continue;
  191506. if (outputDevice != 0)
  191507. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191508. }
  191509. }
  191510. juce_UseDebuggingNewOperator
  191511. String outputDeviceId, inputDeviceId;
  191512. String lastError;
  191513. private:
  191514. // Device stats...
  191515. WASAPIInputDevice* inputDevice;
  191516. WASAPIOutputDevice* outputDevice;
  191517. const bool useExclusiveMode;
  191518. double defaultSampleRate;
  191519. int minBufferSize, defaultBufferSize;
  191520. int latencyIn, latencyOut;
  191521. Array <double> sampleRates;
  191522. Array <int> bufferSizes;
  191523. // Active state...
  191524. bool isOpen_, isStarted;
  191525. int currentBufferSizeSamples;
  191526. double currentSampleRate;
  191527. AudioIODeviceCallback* callback;
  191528. CriticalSection startStopLock;
  191529. bool createDevices()
  191530. {
  191531. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191532. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191533. return false;
  191534. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191535. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191536. return false;
  191537. UINT32 numDevices = 0;
  191538. if (! OK (deviceCollection->GetCount (&numDevices)))
  191539. return false;
  191540. for (UINT32 i = 0; i < numDevices; ++i)
  191541. {
  191542. ComSmartPtr <IMMDevice> device;
  191543. if (! OK (deviceCollection->Item (i, &device)))
  191544. continue;
  191545. const String deviceId (wasapi_getDeviceID (device));
  191546. if (deviceId.isEmpty())
  191547. continue;
  191548. const EDataFlow flow = wasapi_getDataFlow (device);
  191549. if (deviceId == inputDeviceId && flow == eCapture)
  191550. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191551. else if (deviceId == outputDeviceId && flow == eRender)
  191552. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191553. }
  191554. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191555. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191556. }
  191557. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191558. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191559. };
  191560. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191561. {
  191562. public:
  191563. WASAPIAudioIODeviceType()
  191564. : AudioIODeviceType ("Windows Audio"),
  191565. hasScanned (false)
  191566. {
  191567. }
  191568. ~WASAPIAudioIODeviceType()
  191569. {
  191570. }
  191571. void scanForDevices()
  191572. {
  191573. hasScanned = true;
  191574. outputDeviceNames.clear();
  191575. inputDeviceNames.clear();
  191576. outputDeviceIds.clear();
  191577. inputDeviceIds.clear();
  191578. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191579. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191580. return;
  191581. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191582. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191583. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191584. UINT32 numDevices = 0;
  191585. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191586. && OK (deviceCollection->GetCount (&numDevices))))
  191587. return;
  191588. for (UINT32 i = 0; i < numDevices; ++i)
  191589. {
  191590. ComSmartPtr <IMMDevice> device;
  191591. if (! OK (deviceCollection->Item (i, &device)))
  191592. continue;
  191593. const String deviceId (wasapi_getDeviceID (device));
  191594. DWORD state = 0;
  191595. if (! OK (device->GetState (&state)))
  191596. continue;
  191597. if (state != DEVICE_STATE_ACTIVE)
  191598. continue;
  191599. String name;
  191600. {
  191601. ComSmartPtr <IPropertyStore> properties;
  191602. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191603. continue;
  191604. PROPVARIANT value;
  191605. PropVariantInit (&value);
  191606. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191607. name = value.pwszVal;
  191608. PropVariantClear (&value);
  191609. }
  191610. const EDataFlow flow = wasapi_getDataFlow (device);
  191611. if (flow == eRender)
  191612. {
  191613. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191614. outputDeviceIds.insert (index, deviceId);
  191615. outputDeviceNames.insert (index, name);
  191616. }
  191617. else if (flow == eCapture)
  191618. {
  191619. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191620. inputDeviceIds.insert (index, deviceId);
  191621. inputDeviceNames.insert (index, name);
  191622. }
  191623. }
  191624. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191625. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191626. }
  191627. const StringArray getDeviceNames (bool wantInputNames) const
  191628. {
  191629. jassert (hasScanned); // need to call scanForDevices() before doing this
  191630. return wantInputNames ? inputDeviceNames
  191631. : outputDeviceNames;
  191632. }
  191633. int getDefaultDeviceIndex (bool /*forInput*/) const
  191634. {
  191635. jassert (hasScanned); // need to call scanForDevices() before doing this
  191636. return 0;
  191637. }
  191638. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191639. {
  191640. jassert (hasScanned); // need to call scanForDevices() before doing this
  191641. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191642. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191643. : outputDeviceIds.indexOf (d->outputDeviceId));
  191644. }
  191645. bool hasSeparateInputsAndOutputs() const { return true; }
  191646. AudioIODevice* createDevice (const String& outputDeviceName,
  191647. const String& inputDeviceName)
  191648. {
  191649. jassert (hasScanned); // need to call scanForDevices() before doing this
  191650. const bool useExclusiveMode = false;
  191651. ScopedPointer<WASAPIAudioIODevice> device;
  191652. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191653. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191654. if (outputIndex >= 0 || inputIndex >= 0)
  191655. {
  191656. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191657. : inputDeviceName,
  191658. outputDeviceIds [outputIndex],
  191659. inputDeviceIds [inputIndex],
  191660. useExclusiveMode);
  191661. if (! device->initialise())
  191662. device = 0;
  191663. }
  191664. return device.release();
  191665. }
  191666. juce_UseDebuggingNewOperator
  191667. StringArray outputDeviceNames, outputDeviceIds;
  191668. StringArray inputDeviceNames, inputDeviceIds;
  191669. private:
  191670. bool hasScanned;
  191671. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191672. {
  191673. String s;
  191674. IMMDevice* dev = 0;
  191675. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191676. eMultimedia, &dev)))
  191677. {
  191678. WCHAR* deviceId = 0;
  191679. if (OK (dev->GetId (&deviceId)))
  191680. {
  191681. s = String (deviceId);
  191682. CoTaskMemFree (deviceId);
  191683. }
  191684. dev->Release();
  191685. }
  191686. return s;
  191687. }
  191688. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191689. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191690. };
  191691. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191692. {
  191693. return new WASAPIAudioIODeviceType();
  191694. }
  191695. #undef logFailure
  191696. #undef OK
  191697. #endif
  191698. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191699. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191700. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191701. // compiled on its own).
  191702. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191703. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191704. {
  191705. public:
  191706. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191707. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191708. const ComSmartPtr <IBaseFilter>& filter_,
  191709. int minWidth, int minHeight,
  191710. int maxWidth, int maxHeight)
  191711. : owner (owner_),
  191712. captureGraphBuilder (captureGraphBuilder_),
  191713. filter (filter_),
  191714. ok (false),
  191715. imageNeedsFlipping (false),
  191716. width (0),
  191717. height (0),
  191718. activeUsers (0),
  191719. recordNextFrameTime (false),
  191720. activeImage (0),
  191721. loadingImage (0)
  191722. {
  191723. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191724. if (FAILED (hr))
  191725. return;
  191726. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191727. if (FAILED (hr))
  191728. return;
  191729. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191730. if (FAILED (hr))
  191731. return;
  191732. {
  191733. ComSmartPtr <IAMStreamConfig> streamConfig;
  191734. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191735. IID_IAMStreamConfig, (void**) &streamConfig);
  191736. if (streamConfig != 0)
  191737. {
  191738. getVideoSizes (streamConfig);
  191739. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191740. return;
  191741. }
  191742. }
  191743. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191744. if (FAILED (hr))
  191745. return;
  191746. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191747. if (FAILED (hr))
  191748. return;
  191749. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191750. if (FAILED (hr))
  191751. return;
  191752. if (! connectFilters (filter, smartTee))
  191753. return;
  191754. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191755. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191756. if (FAILED (hr))
  191757. return;
  191758. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191759. if (FAILED (hr))
  191760. return;
  191761. AM_MEDIA_TYPE mt;
  191762. zerostruct (mt);
  191763. mt.majortype = MEDIATYPE_Video;
  191764. mt.subtype = MEDIASUBTYPE_RGB24;
  191765. mt.formattype = FORMAT_VideoInfo;
  191766. sampleGrabber->SetMediaType (&mt);
  191767. callback = new GrabberCallback (*this);
  191768. sampleGrabber->SetCallback (callback, 1);
  191769. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191770. if (FAILED (hr))
  191771. return;
  191772. ComSmartPtr <IPin> grabberInputPin;
  191773. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191774. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191775. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191776. return;
  191777. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191778. if (FAILED (hr))
  191779. return;
  191780. zerostruct (mt);
  191781. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191782. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191783. width = pVih->bmiHeader.biWidth;
  191784. height = pVih->bmiHeader.biHeight;
  191785. ComSmartPtr <IBaseFilter> nullFilter;
  191786. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191787. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191788. if (connectFilters (sampleGrabberBase, nullFilter)
  191789. && addGraphToRot())
  191790. {
  191791. activeImage = new Image (Image::RGB, width, height, true);
  191792. loadingImage = new Image (Image::RGB, width, height, true);
  191793. ok = true;
  191794. }
  191795. }
  191796. ~DShowCameraDeviceInteral()
  191797. {
  191798. if (mediaControl != 0)
  191799. mediaControl->Stop();
  191800. removeGraphFromRot();
  191801. for (int i = viewerComps.size(); --i >= 0;)
  191802. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191803. callback = 0;
  191804. graphBuilder = 0;
  191805. sampleGrabber = 0;
  191806. mediaControl = 0;
  191807. filter = 0;
  191808. captureGraphBuilder = 0;
  191809. smartTee = 0;
  191810. smartTeePreviewOutputPin = 0;
  191811. smartTeeCaptureOutputPin = 0;
  191812. asfWriter = 0;
  191813. delete activeImage;
  191814. delete loadingImage;
  191815. }
  191816. void addUser()
  191817. {
  191818. if (ok && activeUsers++ == 0)
  191819. mediaControl->Run();
  191820. }
  191821. void removeUser()
  191822. {
  191823. if (ok && --activeUsers == 0)
  191824. mediaControl->Stop();
  191825. }
  191826. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191827. {
  191828. if (recordNextFrameTime)
  191829. {
  191830. const double defaultCameraLatency = 0.1;
  191831. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191832. recordNextFrameTime = false;
  191833. ComSmartPtr <IPin> pin;
  191834. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191835. {
  191836. ComSmartPtr <IAMPushSource> pushSource;
  191837. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191838. if (pushSource != 0)
  191839. {
  191840. REFERENCE_TIME latency = 0;
  191841. hr = pushSource->GetLatency (&latency);
  191842. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191843. }
  191844. }
  191845. }
  191846. {
  191847. const int lineStride = width * 3;
  191848. const ScopedLock sl (imageSwapLock);
  191849. {
  191850. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191851. for (int i = 0; i < height; ++i)
  191852. memcpy (destData.getLinePointer ((height - 1) - i),
  191853. buffer + lineStride * i,
  191854. lineStride);
  191855. }
  191856. imageNeedsFlipping = true;
  191857. }
  191858. if (listeners.size() > 0)
  191859. callListeners (*loadingImage);
  191860. sendChangeMessage (this);
  191861. }
  191862. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191863. {
  191864. if (imageNeedsFlipping)
  191865. {
  191866. const ScopedLock sl (imageSwapLock);
  191867. swapVariables (loadingImage, activeImage);
  191868. imageNeedsFlipping = false;
  191869. }
  191870. RectanglePlacement rp (RectanglePlacement::centred);
  191871. double dx = 0, dy = 0, dw = width, dh = height;
  191872. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191873. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191874. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191875. g.saveState();
  191876. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191877. g.fillAll (Colours::black);
  191878. g.restoreState();
  191879. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191880. }
  191881. bool createFileCaptureFilter (const File& file)
  191882. {
  191883. removeFileCaptureFilter();
  191884. file.deleteFile();
  191885. mediaControl->Stop();
  191886. firstRecordedTime = Time();
  191887. recordNextFrameTime = true;
  191888. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191889. if (SUCCEEDED (hr))
  191890. {
  191891. ComSmartPtr <IFileSinkFilter> fileSink;
  191892. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191893. if (SUCCEEDED (hr))
  191894. {
  191895. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191896. if (SUCCEEDED (hr))
  191897. {
  191898. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191899. if (SUCCEEDED (hr))
  191900. {
  191901. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191902. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191903. asfConfig->SetIndexMode (true);
  191904. ComSmartPtr <IWMProfileManager> profileManager;
  191905. hr = WMCreateProfileManager (&profileManager);
  191906. // This gibberish is the DirectShow profile for a video-only wmv file.
  191907. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191908. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191909. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191910. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191911. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191912. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191913. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191914. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191915. prof = prof.replace ("$WIDTH", String (width))
  191916. .replace ("$HEIGHT", String (height));
  191917. ComSmartPtr <IWMProfile> currentProfile;
  191918. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191919. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191920. if (SUCCEEDED (hr))
  191921. {
  191922. ComSmartPtr <IPin> asfWriterInputPin;
  191923. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191924. {
  191925. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191926. if (SUCCEEDED (hr)
  191927. && ok && activeUsers > 0
  191928. && SUCCEEDED (mediaControl->Run()))
  191929. {
  191930. return true;
  191931. }
  191932. }
  191933. }
  191934. }
  191935. }
  191936. }
  191937. }
  191938. removeFileCaptureFilter();
  191939. if (ok && activeUsers > 0)
  191940. mediaControl->Run();
  191941. return false;
  191942. }
  191943. void removeFileCaptureFilter()
  191944. {
  191945. mediaControl->Stop();
  191946. if (asfWriter != 0)
  191947. {
  191948. graphBuilder->RemoveFilter (asfWriter);
  191949. asfWriter = 0;
  191950. }
  191951. if (ok && activeUsers > 0)
  191952. mediaControl->Run();
  191953. }
  191954. void addListener (CameraImageListener* listenerToAdd)
  191955. {
  191956. const ScopedLock sl (listenerLock);
  191957. if (listeners.size() == 0)
  191958. addUser();
  191959. listeners.addIfNotAlreadyThere (listenerToAdd);
  191960. }
  191961. void removeListener (CameraImageListener* listenerToRemove)
  191962. {
  191963. const ScopedLock sl (listenerLock);
  191964. listeners.removeValue (listenerToRemove);
  191965. if (listeners.size() == 0)
  191966. removeUser();
  191967. }
  191968. void callListeners (Image& image)
  191969. {
  191970. const ScopedLock sl (listenerLock);
  191971. for (int i = listeners.size(); --i >= 0;)
  191972. {
  191973. CameraImageListener* l = (CameraImageListener*) listeners[i];
  191974. if (l != 0)
  191975. l->imageReceived (image);
  191976. }
  191977. }
  191978. class DShowCaptureViewerComp : public Component,
  191979. public ChangeListener
  191980. {
  191981. public:
  191982. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  191983. : owner (owner_)
  191984. {
  191985. setOpaque (true);
  191986. owner->addChangeListener (this);
  191987. owner->addUser();
  191988. owner->viewerComps.add (this);
  191989. setSize (owner_->width, owner_->height);
  191990. }
  191991. ~DShowCaptureViewerComp()
  191992. {
  191993. if (owner != 0)
  191994. {
  191995. owner->viewerComps.removeValue (this);
  191996. owner->removeUser();
  191997. owner->removeChangeListener (this);
  191998. }
  191999. }
  192000. void ownerDeleted()
  192001. {
  192002. owner = 0;
  192003. }
  192004. void paint (Graphics& g)
  192005. {
  192006. g.setColour (Colours::black);
  192007. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192008. if (owner != 0)
  192009. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192010. else
  192011. g.fillAll (Colours::black);
  192012. }
  192013. void changeListenerCallback (void*)
  192014. {
  192015. repaint();
  192016. }
  192017. private:
  192018. DShowCameraDeviceInteral* owner;
  192019. };
  192020. bool ok;
  192021. int width, height;
  192022. Time firstRecordedTime;
  192023. VoidArray viewerComps;
  192024. private:
  192025. CameraDevice* const owner;
  192026. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192027. ComSmartPtr <IBaseFilter> filter;
  192028. ComSmartPtr <IBaseFilter> smartTee;
  192029. ComSmartPtr <IGraphBuilder> graphBuilder;
  192030. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192031. ComSmartPtr <IMediaControl> mediaControl;
  192032. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192033. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192034. ComSmartPtr <IBaseFilter> asfWriter;
  192035. int activeUsers;
  192036. Array <int> widths, heights;
  192037. DWORD graphRegistrationID;
  192038. CriticalSection imageSwapLock;
  192039. bool imageNeedsFlipping;
  192040. Image* loadingImage;
  192041. Image* activeImage;
  192042. bool recordNextFrameTime;
  192043. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192044. {
  192045. widths.clear();
  192046. heights.clear();
  192047. int count = 0, size = 0;
  192048. streamConfig->GetNumberOfCapabilities (&count, &size);
  192049. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192050. {
  192051. for (int i = 0; i < count; ++i)
  192052. {
  192053. VIDEO_STREAM_CONFIG_CAPS scc;
  192054. AM_MEDIA_TYPE* config;
  192055. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192056. if (SUCCEEDED (hr))
  192057. {
  192058. const int w = scc.InputSize.cx;
  192059. const int h = scc.InputSize.cy;
  192060. bool duplicate = false;
  192061. for (int j = widths.size(); --j >= 0;)
  192062. {
  192063. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192064. {
  192065. duplicate = true;
  192066. break;
  192067. }
  192068. }
  192069. if (! duplicate)
  192070. {
  192071. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192072. widths.add (w);
  192073. heights.add (h);
  192074. }
  192075. deleteMediaType (config);
  192076. }
  192077. }
  192078. }
  192079. }
  192080. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192081. const int minWidth, const int minHeight,
  192082. const int maxWidth, const int maxHeight)
  192083. {
  192084. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192085. streamConfig->GetNumberOfCapabilities (&count, &size);
  192086. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192087. {
  192088. AM_MEDIA_TYPE* config;
  192089. VIDEO_STREAM_CONFIG_CAPS scc;
  192090. for (int i = 0; i < count; ++i)
  192091. {
  192092. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192093. if (SUCCEEDED (hr))
  192094. {
  192095. if (scc.InputSize.cx >= minWidth
  192096. && scc.InputSize.cy >= minHeight
  192097. && scc.InputSize.cx <= maxWidth
  192098. && scc.InputSize.cy <= maxHeight)
  192099. {
  192100. int area = scc.InputSize.cx * scc.InputSize.cy;
  192101. if (area > bestArea)
  192102. {
  192103. bestIndex = i;
  192104. bestArea = area;
  192105. }
  192106. }
  192107. deleteMediaType (config);
  192108. }
  192109. }
  192110. if (bestIndex >= 0)
  192111. {
  192112. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192113. hr = streamConfig->SetFormat (config);
  192114. deleteMediaType (config);
  192115. return SUCCEEDED (hr);
  192116. }
  192117. }
  192118. return false;
  192119. }
  192120. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192121. {
  192122. ComSmartPtr <IEnumPins> enumerator;
  192123. ComSmartPtr <IPin> pin;
  192124. filter->EnumPins (&enumerator);
  192125. while (enumerator->Next (1, &pin, 0) == S_OK)
  192126. {
  192127. PIN_DIRECTION dir;
  192128. pin->QueryDirection (&dir);
  192129. if (wantedDirection == dir)
  192130. {
  192131. PIN_INFO info;
  192132. zerostruct (info);
  192133. pin->QueryPinInfo (&info);
  192134. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192135. {
  192136. pin.p->AddRef();
  192137. *result = pin;
  192138. return true;
  192139. }
  192140. }
  192141. }
  192142. return false;
  192143. }
  192144. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192145. {
  192146. ComSmartPtr <IPin> in, out;
  192147. return getPin (first, PINDIR_OUTPUT, &out)
  192148. && getPin (second, PINDIR_INPUT, &in)
  192149. && SUCCEEDED (graphBuilder->Connect (out, in));
  192150. }
  192151. bool addGraphToRot()
  192152. {
  192153. ComSmartPtr <IRunningObjectTable> rot;
  192154. if (FAILED (GetRunningObjectTable (0, &rot)))
  192155. return false;
  192156. ComSmartPtr <IMoniker> moniker;
  192157. WCHAR buffer[128];
  192158. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192159. if (FAILED (hr))
  192160. return false;
  192161. graphRegistrationID = 0;
  192162. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192163. }
  192164. void removeGraphFromRot()
  192165. {
  192166. ComSmartPtr <IRunningObjectTable> rot;
  192167. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192168. rot->Revoke (graphRegistrationID);
  192169. }
  192170. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192171. {
  192172. if (pmt->cbFormat != 0)
  192173. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192174. if (pmt->pUnk != 0)
  192175. pmt->pUnk->Release();
  192176. CoTaskMemFree (pmt);
  192177. }
  192178. class GrabberCallback : public ISampleGrabberCB
  192179. {
  192180. public:
  192181. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192182. : owner (owner_)
  192183. {
  192184. }
  192185. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192186. {
  192187. if (id == IID_IUnknown)
  192188. *result = dynamic_cast <IUnknown*> (this);
  192189. else if (id == IID_ISampleGrabberCB)
  192190. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192191. else
  192192. {
  192193. *result = 0;
  192194. return E_NOINTERFACE;
  192195. }
  192196. AddRef();
  192197. return S_OK;
  192198. }
  192199. ULONG __stdcall AddRef() { return ++refCount; }
  192200. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192201. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192202. {
  192203. return E_FAIL;
  192204. }
  192205. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192206. {
  192207. owner.handleFrame (time, buffer, bufferSize);
  192208. return S_OK;
  192209. }
  192210. private:
  192211. int refCount;
  192212. DShowCameraDeviceInteral& owner;
  192213. GrabberCallback (const GrabberCallback&);
  192214. GrabberCallback& operator= (const GrabberCallback&);
  192215. };
  192216. ComSmartPtr <GrabberCallback> callback;
  192217. VoidArray listeners;
  192218. CriticalSection listenerLock;
  192219. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192220. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192221. };
  192222. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192223. : name (name_)
  192224. {
  192225. isRecording = false;
  192226. }
  192227. CameraDevice::~CameraDevice()
  192228. {
  192229. stopRecording();
  192230. delete (DShowCameraDeviceInteral*) internal;
  192231. internal = 0;
  192232. }
  192233. Component* CameraDevice::createViewerComponent()
  192234. {
  192235. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192236. }
  192237. const String CameraDevice::getFileExtension()
  192238. {
  192239. return ".wmv";
  192240. }
  192241. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192242. {
  192243. stopRecording();
  192244. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192245. d->addUser();
  192246. isRecording = d->createFileCaptureFilter (file);
  192247. }
  192248. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192249. {
  192250. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192251. return d->firstRecordedTime;
  192252. }
  192253. void CameraDevice::stopRecording()
  192254. {
  192255. if (isRecording)
  192256. {
  192257. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192258. d->removeFileCaptureFilter();
  192259. d->removeUser();
  192260. isRecording = false;
  192261. }
  192262. }
  192263. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192264. {
  192265. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192266. if (listenerToAdd != 0)
  192267. d->addListener (listenerToAdd);
  192268. }
  192269. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192270. {
  192271. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192272. if (listenerToRemove != 0)
  192273. d->removeListener (listenerToRemove);
  192274. }
  192275. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192276. const int deviceIndexToOpen,
  192277. String& name)
  192278. {
  192279. int index = 0;
  192280. ComSmartPtr <IBaseFilter> result;
  192281. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192282. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192283. if (SUCCEEDED (hr))
  192284. {
  192285. ComSmartPtr <IEnumMoniker> enumerator;
  192286. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192287. if (SUCCEEDED (hr) && enumerator != 0)
  192288. {
  192289. ComSmartPtr <IBaseFilter> captureFilter;
  192290. ComSmartPtr <IMoniker> moniker;
  192291. ULONG fetched;
  192292. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192293. {
  192294. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192295. if (SUCCEEDED (hr))
  192296. {
  192297. ComSmartPtr <IPropertyBag> propertyBag;
  192298. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192299. if (SUCCEEDED (hr))
  192300. {
  192301. VARIANT var;
  192302. var.vt = VT_BSTR;
  192303. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192304. propertyBag = 0;
  192305. if (SUCCEEDED (hr))
  192306. {
  192307. if (names != 0)
  192308. names->add (var.bstrVal);
  192309. if (index == deviceIndexToOpen)
  192310. {
  192311. name = var.bstrVal;
  192312. result = captureFilter;
  192313. captureFilter = 0;
  192314. break;
  192315. }
  192316. ++index;
  192317. }
  192318. moniker = 0;
  192319. }
  192320. captureFilter = 0;
  192321. }
  192322. }
  192323. }
  192324. }
  192325. return result;
  192326. }
  192327. const StringArray CameraDevice::getAvailableDevices()
  192328. {
  192329. StringArray devs;
  192330. String dummy;
  192331. enumerateCameras (&devs, -1, dummy);
  192332. return devs;
  192333. }
  192334. CameraDevice* CameraDevice::openDevice (int index,
  192335. int minWidth, int minHeight,
  192336. int maxWidth, int maxHeight)
  192337. {
  192338. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192339. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192340. if (SUCCEEDED (hr))
  192341. {
  192342. String name;
  192343. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192344. if (filter != 0)
  192345. {
  192346. CameraDevice* const cam = new CameraDevice (name, index);
  192347. DShowCameraDeviceInteral* const intern
  192348. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192349. minWidth, minHeight, maxWidth, maxHeight);
  192350. cam->internal = intern;
  192351. if (intern->ok)
  192352. return cam;
  192353. else
  192354. delete cam;
  192355. }
  192356. }
  192357. return 0;
  192358. }
  192359. #endif
  192360. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192361. #endif
  192362. // Auto-link the other win32 libs that are needed by library calls..
  192363. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192364. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192365. // Auto-links to various win32 libs that are needed by library calls..
  192366. #pragma comment(lib, "kernel32.lib")
  192367. #pragma comment(lib, "user32.lib")
  192368. #pragma comment(lib, "shell32.lib")
  192369. #pragma comment(lib, "gdi32.lib")
  192370. #pragma comment(lib, "vfw32.lib")
  192371. #pragma comment(lib, "comdlg32.lib")
  192372. #pragma comment(lib, "winmm.lib")
  192373. #pragma comment(lib, "wininet.lib")
  192374. #pragma comment(lib, "ole32.lib")
  192375. #pragma comment(lib, "oleaut32.lib")
  192376. #pragma comment(lib, "advapi32.lib")
  192377. #pragma comment(lib, "ws2_32.lib")
  192378. #pragma comment(lib, "comsupp.lib")
  192379. #pragma comment(lib, "version.lib")
  192380. #if JUCE_OPENGL
  192381. #pragma comment(lib, "OpenGL32.Lib")
  192382. #pragma comment(lib, "GlU32.Lib")
  192383. #endif
  192384. #if JUCE_QUICKTIME
  192385. #pragma comment (lib, "QTMLClient.lib")
  192386. #endif
  192387. #if JUCE_USE_CAMERA
  192388. #pragma comment (lib, "Strmiids.lib")
  192389. #pragma comment (lib, "wmvcore.lib")
  192390. #endif
  192391. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192392. #endif
  192393. END_JUCE_NAMESPACE
  192394. #endif
  192395. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192396. #endif
  192397. #if JUCE_LINUX
  192398. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192399. #if JUCE_LINUX
  192400. BEGIN_JUCE_NAMESPACE
  192401. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192402. #define SUPPORT_AFFINITIES 1
  192403. #endif
  192404. #define JUCE_INCLUDED_FILE 1
  192405. // Now include the actual code files..
  192406. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192407. CriticalSection::CriticalSection() throw()
  192408. {
  192409. pthread_mutexattr_t atts;
  192410. pthread_mutexattr_init (&atts);
  192411. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192412. pthread_mutex_init (&internal, &atts);
  192413. }
  192414. CriticalSection::~CriticalSection() throw()
  192415. {
  192416. pthread_mutex_destroy (&internal);
  192417. }
  192418. void CriticalSection::enter() const throw()
  192419. {
  192420. pthread_mutex_lock (&internal);
  192421. }
  192422. bool CriticalSection::tryEnter() const throw()
  192423. {
  192424. return pthread_mutex_trylock (&internal) == 0;
  192425. }
  192426. void CriticalSection::exit() const throw()
  192427. {
  192428. pthread_mutex_unlock (&internal);
  192429. }
  192430. class WaitableEventImpl
  192431. {
  192432. public:
  192433. WaitableEventImpl (const bool manualReset_)
  192434. : triggered (false),
  192435. manualReset (manualReset_)
  192436. {
  192437. pthread_cond_init (&condition, 0);
  192438. pthread_mutex_init (&mutex, 0);
  192439. }
  192440. ~WaitableEventImpl()
  192441. {
  192442. pthread_cond_destroy (&condition);
  192443. pthread_mutex_destroy (&mutex);
  192444. }
  192445. bool wait (const int timeOutMillisecs) throw()
  192446. {
  192447. pthread_mutex_lock (&mutex);
  192448. if (! triggered)
  192449. {
  192450. if (timeOutMillisecs < 0)
  192451. {
  192452. do
  192453. {
  192454. pthread_cond_wait (&condition, &mutex);
  192455. }
  192456. while (! triggered);
  192457. }
  192458. else
  192459. {
  192460. struct timeval now;
  192461. gettimeofday (&now, 0);
  192462. struct timespec time;
  192463. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192464. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192465. if (time.tv_nsec >= 1000000000)
  192466. {
  192467. time.tv_nsec -= 1000000000;
  192468. time.tv_sec++;
  192469. }
  192470. do
  192471. {
  192472. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192473. {
  192474. pthread_mutex_unlock (&mutex);
  192475. return false;
  192476. }
  192477. }
  192478. while (! triggered);
  192479. }
  192480. }
  192481. if (! manualReset)
  192482. triggered = false;
  192483. pthread_mutex_unlock (&mutex);
  192484. return true;
  192485. }
  192486. void signal() throw()
  192487. {
  192488. pthread_mutex_lock (&mutex);
  192489. triggered = true;
  192490. pthread_cond_broadcast (&condition);
  192491. pthread_mutex_unlock (&mutex);
  192492. }
  192493. void reset() throw()
  192494. {
  192495. pthread_mutex_lock (&mutex);
  192496. triggered = false;
  192497. pthread_mutex_unlock (&mutex);
  192498. }
  192499. private:
  192500. pthread_cond_t condition;
  192501. pthread_mutex_t mutex;
  192502. bool triggered;
  192503. const bool manualReset;
  192504. WaitableEventImpl (const WaitableEventImpl&);
  192505. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192506. };
  192507. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  192508. : internal (new WaitableEventImpl (manualReset))
  192509. {
  192510. }
  192511. WaitableEvent::~WaitableEvent() throw()
  192512. {
  192513. delete static_cast <WaitableEventImpl*> (internal);
  192514. }
  192515. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192516. {
  192517. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192518. }
  192519. void WaitableEvent::signal() const throw()
  192520. {
  192521. static_cast <WaitableEventImpl*> (internal)->signal();
  192522. }
  192523. void WaitableEvent::reset() const throw()
  192524. {
  192525. static_cast <WaitableEventImpl*> (internal)->reset();
  192526. }
  192527. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192528. {
  192529. struct timespec time;
  192530. time.tv_sec = millisecs / 1000;
  192531. time.tv_nsec = (millisecs % 1000) * 1000000;
  192532. nanosleep (&time, 0);
  192533. }
  192534. const juce_wchar File::separator = '/';
  192535. const juce_wchar* File::separatorString = L"/";
  192536. const File File::getCurrentWorkingDirectory()
  192537. {
  192538. HeapBlock<char> heapBuffer;
  192539. char localBuffer [1024];
  192540. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192541. int bufferSize = 4096;
  192542. while (cwd == 0 && errno == ERANGE)
  192543. {
  192544. heapBuffer.malloc (bufferSize);
  192545. cwd = getcwd (heapBuffer, bufferSize - 1);
  192546. bufferSize += 1024;
  192547. }
  192548. return File (String::fromUTF8 (cwd));
  192549. }
  192550. bool File::setAsCurrentWorkingDirectory() const
  192551. {
  192552. return chdir (getFullPathName().toUTF8()) == 0;
  192553. }
  192554. bool juce_copyFile (const String& s, const String& d);
  192555. static bool juce_stat (const String& fileName, struct stat& info)
  192556. {
  192557. return fileName.isNotEmpty()
  192558. && (stat (fileName.toUTF8(), &info) == 0);
  192559. }
  192560. bool juce_isDirectory (const String& fileName)
  192561. {
  192562. struct stat info;
  192563. return fileName.isEmpty()
  192564. || (juce_stat (fileName, info)
  192565. && ((info.st_mode & S_IFDIR) != 0));
  192566. }
  192567. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192568. {
  192569. if (fileName.isEmpty())
  192570. return false;
  192571. const char* const fileNameUTF8 = fileName.toUTF8();
  192572. bool exists = access (fileNameUTF8, F_OK) == 0;
  192573. if (exists && dontCountDirectories)
  192574. {
  192575. struct stat info;
  192576. const int res = stat (fileNameUTF8, &info);
  192577. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192578. exists = false;
  192579. }
  192580. return exists;
  192581. }
  192582. int64 juce_getFileSize (const String& fileName)
  192583. {
  192584. struct stat info;
  192585. return juce_stat (fileName, info) ? info.st_size : 0;
  192586. }
  192587. bool juce_canWriteToFile (const String& fileName)
  192588. {
  192589. return access (fileName.toUTF8(), W_OK) == 0;
  192590. }
  192591. bool juce_deleteFile (const String& fileName)
  192592. {
  192593. if (juce_isDirectory (fileName))
  192594. return rmdir (fileName.toUTF8()) == 0;
  192595. else
  192596. return remove (fileName.toUTF8()) == 0;
  192597. }
  192598. bool juce_moveFile (const String& source, const String& dest)
  192599. {
  192600. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192601. return true;
  192602. if (juce_canWriteToFile (source)
  192603. && juce_copyFile (source, dest))
  192604. {
  192605. if (juce_deleteFile (source))
  192606. return true;
  192607. juce_deleteFile (dest);
  192608. }
  192609. return false;
  192610. }
  192611. void juce_createDirectory (const String& fileName)
  192612. {
  192613. mkdir (fileName.toUTF8(), 0777);
  192614. }
  192615. void* juce_fileOpen (const String& fileName, bool forWriting)
  192616. {
  192617. int flags = O_RDONLY;
  192618. if (forWriting)
  192619. {
  192620. if (juce_fileExists (fileName, false))
  192621. {
  192622. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192623. if (f != -1)
  192624. lseek (f, 0, SEEK_END);
  192625. return (void*) f;
  192626. }
  192627. else
  192628. {
  192629. flags = O_RDWR + O_CREAT;
  192630. }
  192631. }
  192632. return (void*) open (fileName.toUTF8(), flags, 00644);
  192633. }
  192634. void juce_fileClose (void* handle)
  192635. {
  192636. if (handle != 0)
  192637. close ((int) (pointer_sized_int) handle);
  192638. }
  192639. int juce_fileRead (void* handle, void* buffer, int size)
  192640. {
  192641. if (handle != 0)
  192642. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192643. return 0;
  192644. }
  192645. int juce_fileWrite (void* handle, const void* buffer, int size)
  192646. {
  192647. if (handle != 0)
  192648. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192649. return 0;
  192650. }
  192651. int64 juce_fileSetPosition (void* handle, int64 pos)
  192652. {
  192653. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192654. return pos;
  192655. return -1;
  192656. }
  192657. int64 juce_fileGetPosition (void* handle)
  192658. {
  192659. if (handle != 0)
  192660. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192661. return -1;
  192662. }
  192663. void juce_fileFlush (void* handle)
  192664. {
  192665. if (handle != 0)
  192666. fsync ((int) (pointer_sized_int) handle);
  192667. }
  192668. const File juce_getExecutableFile()
  192669. {
  192670. Dl_info exeInfo;
  192671. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192672. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192673. }
  192674. // if this file doesn't exist, find a parent of it that does..
  192675. static bool doStatFS (const File* file, struct statfs& result)
  192676. {
  192677. File f (*file);
  192678. for (int i = 5; --i >= 0;)
  192679. {
  192680. if (f.exists())
  192681. break;
  192682. f = f.getParentDirectory();
  192683. }
  192684. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192685. }
  192686. int64 File::getBytesFreeOnVolume() const
  192687. {
  192688. struct statfs buf;
  192689. if (doStatFS (this, buf))
  192690. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192691. return 0;
  192692. }
  192693. int64 File::getVolumeTotalSize() const
  192694. {
  192695. struct statfs buf;
  192696. if (doStatFS (this, buf))
  192697. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192698. return 0;
  192699. }
  192700. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192701. int& volumeSerialNumber)
  192702. {
  192703. volumeSerialNumber = 0;
  192704. #if JUCE_MAC
  192705. struct VolAttrBuf
  192706. {
  192707. u_int32_t length;
  192708. attrreference_t mountPointRef;
  192709. char mountPointSpace [MAXPATHLEN];
  192710. } attrBuf;
  192711. struct attrlist attrList;
  192712. zerostruct (attrList);
  192713. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192714. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192715. File f (filenameOnVolume);
  192716. for (;;)
  192717. {
  192718. if (getattrlist (f.getFullPathName().toUTF8(),
  192719. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192720. {
  192721. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192722. (int) attrBuf.mountPointRef.attr_length);
  192723. }
  192724. const File parent (f.getParentDirectory());
  192725. if (f == parent)
  192726. break;
  192727. f = parent;
  192728. }
  192729. #endif
  192730. return String::empty;
  192731. }
  192732. void juce_runSystemCommand (const String& command)
  192733. {
  192734. int result = system (command.toUTF8());
  192735. (void) result;
  192736. }
  192737. const String juce_getOutputFromCommand (const String& command)
  192738. {
  192739. // slight bodge here, as we just pipe the output into a temp file and read it...
  192740. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192741. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192742. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192743. String result (tempFile.loadFileAsString());
  192744. tempFile.deleteFile();
  192745. return result;
  192746. }
  192747. class InterProcessLock::Pimpl
  192748. {
  192749. public:
  192750. Pimpl (const String& name, const int timeOutMillisecs)
  192751. : handle (0), refCount (1)
  192752. {
  192753. #if JUCE_MAC
  192754. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192755. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192756. #else
  192757. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192758. #endif
  192759. temp.create();
  192760. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192761. if (handle != 0)
  192762. {
  192763. struct flock fl;
  192764. zerostruct (fl);
  192765. fl.l_whence = SEEK_SET;
  192766. fl.l_type = F_WRLCK;
  192767. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192768. for (;;)
  192769. {
  192770. const int result = fcntl (handle, F_SETLK, &fl);
  192771. if (result >= 0)
  192772. return;
  192773. if (errno != EINTR)
  192774. {
  192775. if (timeOutMillisecs == 0
  192776. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192777. break;
  192778. Thread::sleep (10);
  192779. }
  192780. }
  192781. }
  192782. closeFile();
  192783. }
  192784. ~Pimpl()
  192785. {
  192786. closeFile();
  192787. }
  192788. void closeFile()
  192789. {
  192790. if (handle != 0)
  192791. {
  192792. struct flock fl;
  192793. zerostruct (fl);
  192794. fl.l_whence = SEEK_SET;
  192795. fl.l_type = F_UNLCK;
  192796. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  192797. {}
  192798. close (handle);
  192799. handle = 0;
  192800. }
  192801. }
  192802. int handle, refCount;
  192803. };
  192804. InterProcessLock::InterProcessLock (const String& name_)
  192805. : name (name_)
  192806. {
  192807. }
  192808. InterProcessLock::~InterProcessLock()
  192809. {
  192810. }
  192811. bool InterProcessLock::enter (const int timeOutMillisecs)
  192812. {
  192813. const ScopedLock sl (lock);
  192814. if (pimpl == 0)
  192815. {
  192816. pimpl = new Pimpl (name, timeOutMillisecs);
  192817. if (pimpl->handle == 0)
  192818. pimpl = 0;
  192819. }
  192820. else
  192821. {
  192822. pimpl->refCount++;
  192823. }
  192824. return pimpl != 0;
  192825. }
  192826. void InterProcessLock::exit()
  192827. {
  192828. const ScopedLock sl (lock);
  192829. // Trying to release the lock too many times!
  192830. jassert (pimpl != 0);
  192831. if (pimpl != 0 && --(pimpl->refCount) == 0)
  192832. pimpl = 0;
  192833. }
  192834. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192835. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192836. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192837. // compiled on its own).
  192838. #if JUCE_INCLUDED_FILE
  192839. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192840. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192841. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192842. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192843. void juce_getFileTimes (const String& fileName,
  192844. int64& modificationTime,
  192845. int64& accessTime,
  192846. int64& creationTime)
  192847. {
  192848. modificationTime = 0;
  192849. accessTime = 0;
  192850. creationTime = 0;
  192851. struct stat info;
  192852. const int res = stat (fileName.toUTF8(), &info);
  192853. if (res == 0)
  192854. {
  192855. modificationTime = (int64) info.st_mtime * 1000;
  192856. accessTime = (int64) info.st_atime * 1000;
  192857. creationTime = (int64) info.st_ctime * 1000;
  192858. }
  192859. }
  192860. bool juce_setFileTimes (const String& fileName,
  192861. int64 modificationTime,
  192862. int64 accessTime,
  192863. int64 creationTime)
  192864. {
  192865. struct utimbuf times;
  192866. times.actime = (time_t) (accessTime / 1000);
  192867. times.modtime = (time_t) (modificationTime / 1000);
  192868. return utime (fileName.toUTF8(), &times) == 0;
  192869. }
  192870. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192871. {
  192872. struct stat info;
  192873. const int res = stat (fileName.toUTF8(), &info);
  192874. if (res != 0)
  192875. return false;
  192876. info.st_mode &= 0777; // Just permissions
  192877. if( isReadOnly )
  192878. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192879. else
  192880. // Give everybody write permission?
  192881. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192882. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192883. }
  192884. bool juce_copyFile (const String& s, const String& d)
  192885. {
  192886. const File source (s), dest (d);
  192887. FileInputStream* in = source.createInputStream();
  192888. bool ok = false;
  192889. if (in != 0)
  192890. {
  192891. if (dest.deleteFile())
  192892. {
  192893. FileOutputStream* const out = dest.createOutputStream();
  192894. if (out != 0)
  192895. {
  192896. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192897. delete out;
  192898. ok = (bytesCopied == source.getSize());
  192899. if (! ok)
  192900. dest.deleteFile();
  192901. }
  192902. }
  192903. delete in;
  192904. }
  192905. return ok;
  192906. }
  192907. const StringArray juce_getFileSystemRoots()
  192908. {
  192909. StringArray s;
  192910. s.add ("/");
  192911. return s;
  192912. }
  192913. bool File::isOnCDRomDrive() const
  192914. {
  192915. struct statfs buf;
  192916. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192917. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192918. // Assume not if this fails for some reason
  192919. return false;
  192920. }
  192921. bool File::isOnHardDisk() const
  192922. {
  192923. struct statfs buf;
  192924. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192925. {
  192926. switch (buf.f_type)
  192927. {
  192928. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192929. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192930. case U_NFS_SUPER_MAGIC: // Network NFS
  192931. case U_SMB_SUPER_MAGIC: // Network Samba
  192932. return false;
  192933. default:
  192934. // Assume anything else is a hard-disk (but note it could
  192935. // be a RAM disk. There isn't a good way of determining
  192936. // this for sure)
  192937. return true;
  192938. }
  192939. }
  192940. // Assume so if this fails for some reason
  192941. return true;
  192942. }
  192943. bool File::isOnRemovableDrive() const
  192944. {
  192945. jassertfalse // xxx not implemented for linux!
  192946. return false;
  192947. }
  192948. bool File::isHidden() const
  192949. {
  192950. return getFileName().startsWithChar ('.');
  192951. }
  192952. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  192953. const File File::getSpecialLocation (const SpecialLocationType type)
  192954. {
  192955. switch (type)
  192956. {
  192957. case userHomeDirectory:
  192958. {
  192959. const char* homeDir = getenv ("HOME");
  192960. if (homeDir == 0)
  192961. {
  192962. struct passwd* const pw = getpwuid (getuid());
  192963. if (pw != 0)
  192964. homeDir = pw->pw_dir;
  192965. }
  192966. return File (String::fromUTF8 (homeDir));
  192967. }
  192968. case userDocumentsDirectory:
  192969. case userMusicDirectory:
  192970. case userMoviesDirectory:
  192971. case userApplicationDataDirectory:
  192972. return File ("~");
  192973. case userDesktopDirectory:
  192974. return File ("~/Desktop");
  192975. case commonApplicationDataDirectory:
  192976. return File ("/var");
  192977. case globalApplicationsDirectory:
  192978. return File ("/usr");
  192979. case tempDirectory:
  192980. {
  192981. File tmp ("/var/tmp");
  192982. if (! tmp.isDirectory())
  192983. {
  192984. tmp = "/tmp";
  192985. if (! tmp.isDirectory())
  192986. tmp = File::getCurrentWorkingDirectory();
  192987. }
  192988. return tmp;
  192989. }
  192990. case invokedExecutableFile:
  192991. if (juce_Argv0 != 0)
  192992. return File (String::fromUTF8 (juce_Argv0));
  192993. // deliberate fall-through...
  192994. case currentExecutableFile:
  192995. case currentApplicationFile:
  192996. return juce_getExecutableFile();
  192997. default:
  192998. jassertfalse // unknown type?
  192999. break;
  193000. }
  193001. return File::nonexistent;
  193002. }
  193003. const String File::getVersion() const
  193004. {
  193005. return String::empty; // xxx not yet implemented
  193006. }
  193007. const File File::getLinkedTarget() const
  193008. {
  193009. char buffer [4096];
  193010. size_t numChars = readlink (getFullPathName().toUTF8(),
  193011. buffer, sizeof (buffer));
  193012. if (numChars > 0 && numChars <= sizeof (buffer))
  193013. return File (String::fromUTF8 (buffer, (int) numChars));
  193014. return *this;
  193015. }
  193016. bool File::moveToTrash() const
  193017. {
  193018. if (! exists())
  193019. return true;
  193020. File trashCan ("~/.Trash");
  193021. if (! trashCan.isDirectory())
  193022. trashCan = "~/.local/share/Trash/files";
  193023. if (! trashCan.isDirectory())
  193024. return false;
  193025. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193026. getFileExtension()));
  193027. }
  193028. struct FindFileStruct
  193029. {
  193030. String parentDir, wildCard;
  193031. DIR* dir;
  193032. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193033. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193034. {
  193035. const char* const wildcardUTF8 = wildCard.toUTF8();
  193036. for (;;)
  193037. {
  193038. struct dirent* const de = readdir (dir);
  193039. if (de == 0)
  193040. break;
  193041. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193042. {
  193043. result = String::fromUTF8 (de->d_name);
  193044. const String path (parentDir + result);
  193045. if (isDir != 0 || fileSize != 0)
  193046. {
  193047. struct stat info;
  193048. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193049. if (isDir != 0)
  193050. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193051. if (isHidden != 0)
  193052. *isHidden = (de->d_name[0] == '.');
  193053. if (fileSize != 0)
  193054. *fileSize = statOk ? info.st_size : 0;
  193055. }
  193056. if (modTime != 0 || creationTime != 0)
  193057. {
  193058. int64 m, a, c;
  193059. juce_getFileTimes (path, m, a, c);
  193060. if (modTime != 0)
  193061. *modTime = m;
  193062. if (creationTime != 0)
  193063. *creationTime = c;
  193064. }
  193065. if (isReadOnly != 0)
  193066. *isReadOnly = ! juce_canWriteToFile (path);
  193067. return true;
  193068. }
  193069. }
  193070. return false;
  193071. }
  193072. };
  193073. // returns 0 on failure
  193074. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193075. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193076. Time* creationTime, bool* isReadOnly)
  193077. {
  193078. DIR* d = opendir (directory.toUTF8());
  193079. if (d != 0)
  193080. {
  193081. FindFileStruct* ff = new FindFileStruct();
  193082. ff->parentDir = directory;
  193083. if (!ff->parentDir.endsWithChar (File::separator))
  193084. ff->parentDir += File::separator;
  193085. ff->wildCard = wildCard;
  193086. if (wildCard == "*.*")
  193087. ff->wildCard = "*";
  193088. ff->dir = d;
  193089. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193090. {
  193091. return ff;
  193092. }
  193093. else
  193094. {
  193095. firstResultFile = String::empty;
  193096. isDir = false;
  193097. isHidden = false;
  193098. closedir (d);
  193099. delete ff;
  193100. }
  193101. }
  193102. return 0;
  193103. }
  193104. bool juce_findFileNext (void* handle, String& resultFile,
  193105. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193106. {
  193107. FindFileStruct* const ff = (FindFileStruct*) handle;
  193108. if (ff != 0)
  193109. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193110. return false;
  193111. }
  193112. void juce_findFileClose (void* handle)
  193113. {
  193114. FindFileStruct* const ff = (FindFileStruct*) handle;
  193115. if (ff != 0)
  193116. {
  193117. closedir (ff->dir);
  193118. delete ff;
  193119. }
  193120. }
  193121. bool juce_launchFile (const String& fileName,
  193122. const String& parameters)
  193123. {
  193124. String cmdString (fileName.replace (" ", "\\ ",false));
  193125. cmdString << " " << parameters;
  193126. if (URL::isProbablyAWebsiteURL (fileName)
  193127. || cmdString.startsWithIgnoreCase ("file:")
  193128. || URL::isProbablyAnEmailAddress (fileName))
  193129. {
  193130. // create a command that tries to launch a bunch of likely browsers
  193131. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193132. StringArray cmdLines;
  193133. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193134. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193135. cmdString = cmdLines.joinIntoString (" || ");
  193136. }
  193137. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193138. const int cpid = fork();
  193139. if (cpid == 0)
  193140. {
  193141. setsid();
  193142. // Child process
  193143. execve (argv[0], (char**) argv, environ);
  193144. exit (0);
  193145. }
  193146. return cpid >= 0;
  193147. }
  193148. void File::revealToUser() const
  193149. {
  193150. if (isDirectory())
  193151. startAsProcess();
  193152. else if (getParentDirectory().exists())
  193153. getParentDirectory().startAsProcess();
  193154. }
  193155. #endif
  193156. /*** End of inlined file: juce_linux_Files.cpp ***/
  193157. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193158. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193159. // compiled on its own).
  193160. #if JUCE_INCLUDED_FILE
  193161. struct NamedPipeInternal
  193162. {
  193163. String pipeInName, pipeOutName;
  193164. int pipeIn, pipeOut;
  193165. bool volatile createdPipe, blocked, stopReadOperation;
  193166. static void signalHandler (int) {}
  193167. };
  193168. void NamedPipe::cancelPendingReads()
  193169. {
  193170. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193171. {
  193172. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193173. intern->stopReadOperation = true;
  193174. char buffer [1] = { 0 };
  193175. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193176. (void) bytesWritten;
  193177. int timeout = 2000;
  193178. while (intern->blocked && --timeout >= 0)
  193179. Thread::sleep (2);
  193180. intern->stopReadOperation = false;
  193181. }
  193182. }
  193183. void NamedPipe::close()
  193184. {
  193185. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193186. if (intern != 0)
  193187. {
  193188. internal = 0;
  193189. if (intern->pipeIn != -1)
  193190. ::close (intern->pipeIn);
  193191. if (intern->pipeOut != -1)
  193192. ::close (intern->pipeOut);
  193193. if (intern->createdPipe)
  193194. {
  193195. unlink (intern->pipeInName.toUTF8());
  193196. unlink (intern->pipeOutName.toUTF8());
  193197. }
  193198. delete intern;
  193199. }
  193200. }
  193201. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193202. {
  193203. close();
  193204. NamedPipeInternal* const intern = new NamedPipeInternal();
  193205. internal = intern;
  193206. intern->createdPipe = createPipe;
  193207. intern->blocked = false;
  193208. intern->stopReadOperation = false;
  193209. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193210. siginterrupt (SIGPIPE, 1);
  193211. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193212. intern->pipeInName = pipePath + "_in";
  193213. intern->pipeOutName = pipePath + "_out";
  193214. intern->pipeIn = -1;
  193215. intern->pipeOut = -1;
  193216. if (createPipe)
  193217. {
  193218. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193219. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193220. {
  193221. delete intern;
  193222. internal = 0;
  193223. return false;
  193224. }
  193225. }
  193226. return true;
  193227. }
  193228. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193229. {
  193230. int bytesRead = -1;
  193231. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193232. if (intern != 0)
  193233. {
  193234. intern->blocked = true;
  193235. if (intern->pipeIn == -1)
  193236. {
  193237. if (intern->createdPipe)
  193238. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193239. else
  193240. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193241. if (intern->pipeIn == -1)
  193242. {
  193243. intern->blocked = false;
  193244. return -1;
  193245. }
  193246. }
  193247. bytesRead = 0;
  193248. char* p = (char*) destBuffer;
  193249. while (bytesRead < maxBytesToRead)
  193250. {
  193251. const int bytesThisTime = maxBytesToRead - bytesRead;
  193252. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193253. if (numRead <= 0 || intern->stopReadOperation)
  193254. {
  193255. bytesRead = -1;
  193256. break;
  193257. }
  193258. bytesRead += numRead;
  193259. p += bytesRead;
  193260. }
  193261. intern->blocked = false;
  193262. }
  193263. return bytesRead;
  193264. }
  193265. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193266. {
  193267. int bytesWritten = -1;
  193268. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193269. if (intern != 0)
  193270. {
  193271. if (intern->pipeOut == -1)
  193272. {
  193273. if (intern->createdPipe)
  193274. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193275. else
  193276. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193277. if (intern->pipeOut == -1)
  193278. {
  193279. return -1;
  193280. }
  193281. }
  193282. const char* p = (const char*) sourceBuffer;
  193283. bytesWritten = 0;
  193284. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193285. while (bytesWritten < numBytesToWrite
  193286. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193287. {
  193288. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193289. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193290. if (numWritten <= 0)
  193291. {
  193292. bytesWritten = -1;
  193293. break;
  193294. }
  193295. bytesWritten += numWritten;
  193296. p += bytesWritten;
  193297. }
  193298. }
  193299. return bytesWritten;
  193300. }
  193301. #endif
  193302. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193303. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193304. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193305. // compiled on its own).
  193306. #if JUCE_INCLUDED_FILE
  193307. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193308. {
  193309. int numResults = 0;
  193310. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193311. if (s != -1)
  193312. {
  193313. char buf [1024];
  193314. struct ifconf ifc;
  193315. ifc.ifc_len = sizeof (buf);
  193316. ifc.ifc_buf = buf;
  193317. ioctl (s, SIOCGIFCONF, &ifc);
  193318. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193319. {
  193320. struct ifreq ifr;
  193321. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193322. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193323. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193324. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193325. && numResults < maxNum)
  193326. {
  193327. int64 a = 0;
  193328. for (int j = 6; --j >= 0;)
  193329. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193330. *addresses++ = a;
  193331. ++numResults;
  193332. }
  193333. }
  193334. close (s);
  193335. }
  193336. return numResults;
  193337. }
  193338. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193339. const String& emailSubject,
  193340. const String& bodyText,
  193341. const StringArray& filesToAttach)
  193342. {
  193343. jassertfalse // xxx todo
  193344. return false;
  193345. }
  193346. class JUCE_HTTPSocketStream
  193347. {
  193348. public:
  193349. JUCE_HTTPSocketStream()
  193350. : readPosition (0),
  193351. socketHandle (-1),
  193352. levelsOfRedirection (0),
  193353. timeoutSeconds (15)
  193354. {
  193355. }
  193356. ~JUCE_HTTPSocketStream()
  193357. {
  193358. closeSocket();
  193359. }
  193360. bool open (const String& url,
  193361. const String& headers,
  193362. const MemoryBlock& postData,
  193363. const bool isPost,
  193364. URL::OpenStreamProgressCallback* callback,
  193365. void* callbackContext,
  193366. int timeOutMs)
  193367. {
  193368. closeSocket();
  193369. uint32 timeOutTime = Time::getMillisecondCounter();
  193370. if (timeOutMs == 0)
  193371. timeOutTime += 60000;
  193372. else if (timeOutMs < 0)
  193373. timeOutTime = 0xffffffff;
  193374. else
  193375. timeOutTime += timeOutMs;
  193376. String hostName, hostPath;
  193377. int hostPort;
  193378. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193379. return false;
  193380. const struct hostent* host = 0;
  193381. int port = 0;
  193382. String proxyName, proxyPath;
  193383. int proxyPort = 0;
  193384. String proxyURL (getenv ("http_proxy"));
  193385. if (proxyURL.startsWithIgnoreCase ("http://"))
  193386. {
  193387. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193388. return false;
  193389. host = gethostbyname (proxyName.toUTF8());
  193390. port = proxyPort;
  193391. }
  193392. else
  193393. {
  193394. host = gethostbyname (hostName.toUTF8());
  193395. port = hostPort;
  193396. }
  193397. if (host == 0)
  193398. return false;
  193399. struct sockaddr_in address;
  193400. zerostruct (address);
  193401. memcpy (&address.sin_addr, host->h_addr, host->h_length);
  193402. address.sin_family = host->h_addrtype;
  193403. address.sin_port = htons (port);
  193404. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193405. if (socketHandle == -1)
  193406. return false;
  193407. int receiveBufferSize = 16384;
  193408. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193409. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193410. #if JUCE_MAC
  193411. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193412. #endif
  193413. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193414. {
  193415. closeSocket();
  193416. return false;
  193417. }
  193418. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193419. proxyName, proxyPort,
  193420. hostPath, url,
  193421. headers, postData,
  193422. isPost));
  193423. size_t totalHeaderSent = 0;
  193424. while (totalHeaderSent < requestHeader.getSize())
  193425. {
  193426. if (Time::getMillisecondCounter() > timeOutTime)
  193427. {
  193428. closeSocket();
  193429. return false;
  193430. }
  193431. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193432. if (send (socketHandle,
  193433. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193434. numToSend, 0)
  193435. != numToSend)
  193436. {
  193437. closeSocket();
  193438. return false;
  193439. }
  193440. totalHeaderSent += numToSend;
  193441. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193442. {
  193443. closeSocket();
  193444. return false;
  193445. }
  193446. }
  193447. const String responseHeader (readResponse (timeOutTime));
  193448. if (responseHeader.isNotEmpty())
  193449. {
  193450. //DBG (responseHeader);
  193451. StringArray lines;
  193452. lines.addLines (responseHeader);
  193453. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193454. .substring (0, 3).getIntValue();
  193455. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193456. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193457. String location (findHeaderItem (lines, "Location:"));
  193458. if (statusCode >= 300 && statusCode < 400
  193459. && location.isNotEmpty())
  193460. {
  193461. if (! location.startsWithIgnoreCase ("http://"))
  193462. location = "http://" + location;
  193463. if (levelsOfRedirection++ < 3)
  193464. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193465. }
  193466. else
  193467. {
  193468. levelsOfRedirection = 0;
  193469. return true;
  193470. }
  193471. }
  193472. closeSocket();
  193473. return false;
  193474. }
  193475. int read (void* buffer, int bytesToRead)
  193476. {
  193477. fd_set readbits;
  193478. FD_ZERO (&readbits);
  193479. FD_SET (socketHandle, &readbits);
  193480. struct timeval tv;
  193481. tv.tv_sec = timeoutSeconds;
  193482. tv.tv_usec = 0;
  193483. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193484. return 0; // (timeout)
  193485. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193486. readPosition += bytesRead;
  193487. return bytesRead;
  193488. }
  193489. int readPosition;
  193490. juce_UseDebuggingNewOperator
  193491. private:
  193492. int socketHandle, levelsOfRedirection;
  193493. const int timeoutSeconds;
  193494. void closeSocket()
  193495. {
  193496. if (socketHandle >= 0)
  193497. close (socketHandle);
  193498. socketHandle = -1;
  193499. }
  193500. const MemoryBlock createRequestHeader (const String& hostName,
  193501. const int hostPort,
  193502. const String& proxyName,
  193503. const int proxyPort,
  193504. const String& hostPath,
  193505. const String& originalURL,
  193506. const String& headers,
  193507. const MemoryBlock& postData,
  193508. const bool isPost)
  193509. {
  193510. String header (isPost ? "POST " : "GET ");
  193511. if (proxyName.isEmpty())
  193512. {
  193513. header << hostPath << " HTTP/1.0\r\nHost: "
  193514. << hostName << ':' << hostPort;
  193515. }
  193516. else
  193517. {
  193518. header << originalURL << " HTTP/1.0\r\nHost: "
  193519. << proxyName << ':' << proxyPort;
  193520. }
  193521. header << "\r\nUser-Agent: JUCE/"
  193522. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193523. << "\r\nConnection: Close\r\nContent-Length: "
  193524. << postData.getSize() << "\r\n"
  193525. << headers << "\r\n";
  193526. MemoryBlock mb;
  193527. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193528. mb.append (postData.getData(), postData.getSize());
  193529. return mb;
  193530. }
  193531. const String readResponse (const uint32 timeOutTime)
  193532. {
  193533. int bytesRead = 0, numConsecutiveLFs = 0;
  193534. MemoryBlock buffer (1024, true);
  193535. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193536. && Time::getMillisecondCounter() <= timeOutTime)
  193537. {
  193538. fd_set readbits;
  193539. FD_ZERO (&readbits);
  193540. FD_SET (socketHandle, &readbits);
  193541. struct timeval tv;
  193542. tv.tv_sec = timeoutSeconds;
  193543. tv.tv_usec = 0;
  193544. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193545. return String::empty; // (timeout)
  193546. buffer.ensureSize (bytesRead + 8, true);
  193547. char* const dest = (char*) buffer.getData() + bytesRead;
  193548. if (recv (socketHandle, dest, 1, 0) == -1)
  193549. return String::empty;
  193550. const char lastByte = *dest;
  193551. ++bytesRead;
  193552. if (lastByte == '\n')
  193553. ++numConsecutiveLFs;
  193554. else if (lastByte != '\r')
  193555. numConsecutiveLFs = 0;
  193556. }
  193557. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193558. if (header.startsWithIgnoreCase ("HTTP/"))
  193559. return header.trimEnd();
  193560. return String::empty;
  193561. }
  193562. static bool decomposeURL (const String& url,
  193563. String& host, String& path, int& port)
  193564. {
  193565. if (! url.startsWithIgnoreCase ("http://"))
  193566. return false;
  193567. const int nextSlash = url.indexOfChar (7, '/');
  193568. int nextColon = url.indexOfChar (7, ':');
  193569. if (nextColon > nextSlash && nextSlash > 0)
  193570. nextColon = -1;
  193571. if (nextColon >= 0)
  193572. {
  193573. host = url.substring (7, nextColon);
  193574. if (nextSlash >= 0)
  193575. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193576. else
  193577. port = url.substring (nextColon + 1).getIntValue();
  193578. }
  193579. else
  193580. {
  193581. port = 80;
  193582. if (nextSlash >= 0)
  193583. host = url.substring (7, nextSlash);
  193584. else
  193585. host = url.substring (7);
  193586. }
  193587. if (nextSlash >= 0)
  193588. path = url.substring (nextSlash);
  193589. else
  193590. path = "/";
  193591. return true;
  193592. }
  193593. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193594. {
  193595. for (int i = 0; i < lines.size(); ++i)
  193596. if (lines[i].startsWithIgnoreCase (itemName))
  193597. return lines[i].substring (itemName.length()).trim();
  193598. return String::empty;
  193599. }
  193600. };
  193601. bool juce_isOnLine()
  193602. {
  193603. return true;
  193604. }
  193605. void* juce_openInternetFile (const String& url,
  193606. const String& headers,
  193607. const MemoryBlock& postData,
  193608. const bool isPost,
  193609. URL::OpenStreamProgressCallback* callback,
  193610. void* callbackContext,
  193611. int timeOutMs)
  193612. {
  193613. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193614. if (s->open (url, headers, postData, isPost,
  193615. callback, callbackContext, timeOutMs))
  193616. return s;
  193617. delete s;
  193618. return 0;
  193619. }
  193620. void juce_closeInternetFile (void* handle)
  193621. {
  193622. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193623. if (s != 0)
  193624. delete s;
  193625. }
  193626. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193627. {
  193628. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193629. if (s != 0)
  193630. return s->read (buffer, bytesToRead);
  193631. return 0;
  193632. }
  193633. int64 juce_getInternetFileContentLength (void* handle)
  193634. {
  193635. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193636. if (s != 0)
  193637. {
  193638. //xxx todo
  193639. jassertfalse
  193640. }
  193641. return -1;
  193642. }
  193643. int juce_seekInInternetFile (void* handle, int newPosition)
  193644. {
  193645. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193646. if (s != 0)
  193647. return s->readPosition;
  193648. return 0;
  193649. }
  193650. #endif
  193651. /*** End of inlined file: juce_linux_Network.cpp ***/
  193652. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193653. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193654. // compiled on its own).
  193655. #if JUCE_INCLUDED_FILE
  193656. void Logger::outputDebugString (const String& text) throw()
  193657. {
  193658. std::cerr << text << std::endl;
  193659. }
  193660. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193661. {
  193662. return Linux;
  193663. }
  193664. const String SystemStats::getOperatingSystemName() throw()
  193665. {
  193666. return "Linux";
  193667. }
  193668. bool SystemStats::isOperatingSystem64Bit() throw()
  193669. {
  193670. #if JUCE_64BIT
  193671. return true;
  193672. #else
  193673. //xxx not sure how to find this out?..
  193674. return false;
  193675. #endif
  193676. }
  193677. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193678. {
  193679. String info;
  193680. char buf [256];
  193681. FILE* f = fopen ("/proc/cpuinfo", "r");
  193682. while (f != 0 && fgets (buf, sizeof(buf), f))
  193683. {
  193684. if (strncmp (buf, key, strlen (key)) == 0)
  193685. {
  193686. char* p = buf;
  193687. while (*p && *p != '\n')
  193688. ++p;
  193689. if (*p != 0)
  193690. *p = 0;
  193691. p = buf;
  193692. while (*p != 0 && *p != ':')
  193693. ++p;
  193694. if (*p != 0 && *(p + 1) != 0)
  193695. info = p + 2;
  193696. if (! lastOne)
  193697. break;
  193698. }
  193699. }
  193700. fclose (f);
  193701. return info;
  193702. }
  193703. bool SystemStats::hasMMX() throw()
  193704. {
  193705. return getCpuInfo ("flags").contains ("mmx");
  193706. }
  193707. bool SystemStats::hasSSE() throw()
  193708. {
  193709. return getCpuInfo ("flags").contains ("sse");
  193710. }
  193711. bool SystemStats::hasSSE2() throw()
  193712. {
  193713. return getCpuInfo ("flags").contains ("sse2");
  193714. }
  193715. bool SystemStats::has3DNow() throw()
  193716. {
  193717. return getCpuInfo ("flags").contains ("3dnow");
  193718. }
  193719. const String SystemStats::getCpuVendor() throw()
  193720. {
  193721. return getCpuInfo ("vendor_id");
  193722. }
  193723. int SystemStats::getCpuSpeedInMegaherz() throw()
  193724. {
  193725. const String speed (getCpuInfo ("cpu MHz"));
  193726. return (int) (speed.getFloatValue() + 0.5f);
  193727. }
  193728. int SystemStats::getMemorySizeInMegabytes() throw()
  193729. {
  193730. struct sysinfo sysi;
  193731. if (sysinfo (&sysi) == 0)
  193732. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193733. return 0;
  193734. }
  193735. uint32 juce_millisecondsSinceStartup() throw()
  193736. {
  193737. static unsigned int calibrate = 0;
  193738. static bool calibrated = false;
  193739. timeval t;
  193740. unsigned int ret = 0;
  193741. if (! gettimeofday (&t, 0))
  193742. {
  193743. if (! calibrated)
  193744. {
  193745. struct sysinfo sysi;
  193746. if (sysinfo (&sysi) == 0)
  193747. // Safe to assume system was not brought up earlier than 1970!
  193748. calibrate = t.tv_sec - sysi.uptime;
  193749. calibrated = true;
  193750. }
  193751. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193752. }
  193753. return ret;
  193754. }
  193755. double Time::getMillisecondCounterHiRes() throw()
  193756. {
  193757. return getHighResolutionTicks() * 0.001;
  193758. }
  193759. int64 Time::getHighResolutionTicks() throw()
  193760. {
  193761. timeval t;
  193762. if (gettimeofday (&t, 0))
  193763. return 0;
  193764. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193765. }
  193766. int64 Time::getHighResolutionTicksPerSecond() throw()
  193767. {
  193768. // Microseconds
  193769. return 1000000;
  193770. }
  193771. bool Time::setSystemTimeToThisTime() const throw()
  193772. {
  193773. timeval t;
  193774. t.tv_sec = millisSinceEpoch % 1000000;
  193775. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193776. return settimeofday (&t, NULL) ? false : true;
  193777. }
  193778. int SystemStats::getPageSize() throw()
  193779. {
  193780. static int systemPageSize = 0;
  193781. if (systemPageSize == 0)
  193782. systemPageSize = sysconf (_SC_PAGESIZE);
  193783. return systemPageSize;
  193784. }
  193785. int SystemStats::getNumCpus() throw()
  193786. {
  193787. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193788. return lastCpu + 1;
  193789. }
  193790. const String SystemStats::getLogonName()
  193791. {
  193792. const char* user = getenv ("USER");
  193793. if (user == 0)
  193794. {
  193795. struct passwd* const pw = getpwuid (getuid());
  193796. if (pw != 0)
  193797. user = pw->pw_name;
  193798. }
  193799. return String::fromUTF8 (user);
  193800. }
  193801. const String SystemStats::getFullUserName()
  193802. {
  193803. return getLogonName();
  193804. }
  193805. void SystemStats::initialiseStats() throw()
  193806. {
  193807. // Process starts off as root when running suid
  193808. Process::lowerPrivilege();
  193809. String s (SystemStats::getJUCEVersion());
  193810. }
  193811. void PlatformUtilities::fpuReset()
  193812. {
  193813. }
  193814. #endif
  193815. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193816. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193817. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193818. // compiled on its own).
  193819. #if JUCE_INCLUDED_FILE
  193820. void JUCE_API juce_threadEntryPoint (void*);
  193821. void* threadEntryProc (void* value)
  193822. {
  193823. // New threads start off as root when running suid
  193824. Process::lowerPrivilege();
  193825. juce_threadEntryPoint (value);
  193826. return 0;
  193827. }
  193828. void* juce_createThread (void* userData)
  193829. {
  193830. pthread_t handle = 0;
  193831. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193832. {
  193833. pthread_detach (handle);
  193834. return (void*) handle;
  193835. }
  193836. return 0;
  193837. }
  193838. void juce_killThread (void* handle)
  193839. {
  193840. if (handle != 0)
  193841. pthread_cancel ((pthread_t)handle);
  193842. }
  193843. void juce_setCurrentThreadName (const String& /*name*/)
  193844. {
  193845. }
  193846. Thread::ThreadID Thread::getCurrentThreadId()
  193847. {
  193848. return (ThreadID) pthread_self();
  193849. }
  193850. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193851. // priority of the current thread
  193852. bool juce_setThreadPriority (void* handle, int priority)
  193853. {
  193854. struct sched_param param;
  193855. int policy, maxp, minp, pri;
  193856. if (handle == 0)
  193857. handle = (void*) pthread_self();
  193858. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193859. && policy != SCHED_OTHER)
  193860. {
  193861. minp = sched_get_priority_min(policy);
  193862. maxp = sched_get_priority_max(policy);
  193863. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193864. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193865. // Realtime process priority
  193866. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193867. else
  193868. // High process priority
  193869. param.__sched_priority = minp + pri;
  193870. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193871. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193872. }
  193873. return false;
  193874. }
  193875. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193876. {
  193877. #if SUPPORT_AFFINITIES
  193878. cpu_set_t affinity;
  193879. CPU_ZERO (&affinity);
  193880. for (int i = 0; i < 32; ++i)
  193881. if ((affinityMask & (1 << i)) != 0)
  193882. CPU_SET (i, &affinity);
  193883. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193884. sched_yield();
  193885. #else
  193886. /* affinities aren't supported because either the appropriate header files weren't found,
  193887. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193888. */
  193889. jassertfalse
  193890. #endif
  193891. }
  193892. void Thread::yield()
  193893. {
  193894. sched_yield();
  193895. }
  193896. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193897. void Process::setPriority (ProcessPriority prior)
  193898. {
  193899. struct sched_param param;
  193900. int policy, maxp, minp;
  193901. const int p = (int) prior;
  193902. if (p <= 1)
  193903. policy = SCHED_OTHER;
  193904. else
  193905. policy = SCHED_RR;
  193906. minp = sched_get_priority_min (policy);
  193907. maxp = sched_get_priority_max (policy);
  193908. if (p < 2)
  193909. param.__sched_priority = 0;
  193910. else if (p == 2 )
  193911. // Set to middle of lower realtime priority range
  193912. param.__sched_priority = minp + (maxp - minp) / 4;
  193913. else
  193914. // Set to middle of higher realtime priority range
  193915. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193916. pthread_setschedparam (pthread_self(), policy, &param);
  193917. }
  193918. void Process::terminate()
  193919. {
  193920. exit (0);
  193921. }
  193922. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193923. {
  193924. static char testResult = 0;
  193925. if (testResult == 0)
  193926. {
  193927. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193928. if (testResult >= 0)
  193929. {
  193930. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193931. testResult = 1;
  193932. }
  193933. }
  193934. return testResult < 0;
  193935. }
  193936. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193937. {
  193938. return juce_isRunningUnderDebugger();
  193939. }
  193940. void Process::raisePrivilege()
  193941. {
  193942. // If running suid root, change effective user
  193943. // to root
  193944. if (geteuid() != 0 && getuid() == 0)
  193945. {
  193946. setreuid (geteuid(), getuid());
  193947. setregid (getegid(), getgid());
  193948. }
  193949. }
  193950. void Process::lowerPrivilege()
  193951. {
  193952. // If runing suid root, change effective user
  193953. // back to real user
  193954. if (geteuid() == 0 && getuid() != 0)
  193955. {
  193956. setreuid (geteuid(), getuid());
  193957. setregid (getegid(), getgid());
  193958. }
  193959. }
  193960. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193961. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  193962. {
  193963. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  193964. }
  193965. void PlatformUtilities::freeDynamicLibrary (void* handle)
  193966. {
  193967. dlclose(handle);
  193968. }
  193969. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  193970. {
  193971. return dlsym (libraryHandle, procedureName.toCString());
  193972. }
  193973. #endif
  193974. #endif
  193975. /*** End of inlined file: juce_linux_Threads.cpp ***/
  193976. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193977. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  193978. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193979. // compiled on its own).
  193980. #if JUCE_INCLUDED_FILE
  193981. #ifdef JUCE_DEBUG
  193982. #define JUCE_DEBUG_XERRORS 1
  193983. #endif
  193984. extern Display* display;
  193985. extern Window juce_messageWindowHandle;
  193986. static String localClipboardContent;
  193987. static Atom atom_UTF8_STRING;
  193988. static Atom atom_CLIPBOARD;
  193989. static Atom atom_TARGETS;
  193990. static void initSelectionAtoms()
  193991. {
  193992. static bool isInitialised = false;
  193993. if (! isInitialised)
  193994. {
  193995. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  193996. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  193997. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  193998. }
  193999. }
  194000. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194001. // works only for strings shorter than 1000000 bytes
  194002. static String juce_readWindowProperty (Window window, Atom prop,
  194003. Atom fmt, // XA_STRING or UTF8_STRING
  194004. bool deleteAfterReading)
  194005. {
  194006. String returnData;
  194007. char* clipData;
  194008. Atom actualType;
  194009. int actualFormat;
  194010. unsigned long numItems, bytesLeft;
  194011. if (XGetWindowProperty (display, window, prop,
  194012. 0L /* offset */, 1000000 /* length (max) */, False,
  194013. AnyPropertyType /* format */,
  194014. &actualType, &actualFormat, &numItems, &bytesLeft,
  194015. (unsigned char**) &clipData) == Success)
  194016. {
  194017. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194018. {
  194019. returnData = String::fromUTF8 (clipData, numItems);
  194020. }
  194021. else if (actualType == XA_STRING && actualFormat == 8)
  194022. {
  194023. returnData = String (clipData, numItems);
  194024. }
  194025. if (clipData != 0)
  194026. XFree (clipData);
  194027. jassert (bytesLeft == 0 || numItems == 1000000);
  194028. }
  194029. if (deleteAfterReading)
  194030. XDeleteProperty (display, window, prop);
  194031. return returnData;
  194032. }
  194033. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194034. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194035. {
  194036. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194037. // The selection owner will be asked to set the JUCE_SEL property on the
  194038. // juce_messageWindowHandle with the selection content
  194039. XConvertSelection (display, selection, requested_format, property_name,
  194040. juce_messageWindowHandle, CurrentTime);
  194041. int timeoutMs = 200; // will wait at most for 200 ms
  194042. do
  194043. {
  194044. XEvent event;
  194045. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194046. {
  194047. if (event.xselection.property == property_name)
  194048. {
  194049. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194050. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194051. event.xselection.property,
  194052. requested_format, true);
  194053. return true;
  194054. }
  194055. else
  194056. {
  194057. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194058. }
  194059. }
  194060. // not very elegant.. we could do a select() or something like that...
  194061. // however clipboard content requesting is inherently slow on x11, it
  194062. // often takes 50ms or more so...
  194063. Thread::sleep (4);
  194064. timeoutMs -= 4;
  194065. }
  194066. while (timeoutMs > 0);
  194067. DBG("timeout for juce_requestSelectionContent");
  194068. return false;
  194069. }
  194070. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194071. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194072. {
  194073. initSelectionAtoms();
  194074. // the selection content is sent to the target window as a window property
  194075. XSelectionEvent reply;
  194076. reply.type = SelectionNotify;
  194077. reply.display = evt.display;
  194078. reply.requestor = evt.requestor;
  194079. reply.selection = evt.selection;
  194080. reply.target = evt.target;
  194081. reply.property = None; // == "fail"
  194082. reply.time = evt.time;
  194083. HeapBlock <char> data;
  194084. int propertyFormat = 0, numDataItems = 0;
  194085. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194086. {
  194087. if (evt.target == XA_STRING)
  194088. {
  194089. // format data according to system locale
  194090. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194091. data.calloc (numDataItems + 1);
  194092. localClipboardContent.copyToCString (data, numDataItems);
  194093. propertyFormat = 8; // bits/item
  194094. }
  194095. else if (evt.target == atom_UTF8_STRING)
  194096. {
  194097. // translate to utf8
  194098. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194099. data.calloc (numDataItems + 1);
  194100. localClipboardContent.copyToUTF8 (data, numDataItems);
  194101. propertyFormat = 8; // bits/item
  194102. }
  194103. else if (evt.target == atom_TARGETS)
  194104. {
  194105. // another application wants to know what we are able to send
  194106. numDataItems = 2;
  194107. propertyFormat = 32; // atoms are 32-bit
  194108. data.calloc (numDataItems * 4);
  194109. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194110. atoms[0] = atom_UTF8_STRING;
  194111. atoms[1] = XA_STRING;
  194112. }
  194113. }
  194114. else
  194115. {
  194116. DBG ("requested unsupported clipboard");
  194117. }
  194118. if (data != 0)
  194119. {
  194120. const int maxReasonableSelectionSize = 1000000;
  194121. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194122. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194123. {
  194124. XChangeProperty (evt.display, evt.requestor,
  194125. evt.property, evt.target,
  194126. propertyFormat /* 8 or 32 */, PropModeReplace,
  194127. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194128. reply.property = evt.property; // " == success"
  194129. }
  194130. }
  194131. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194132. }
  194133. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194134. {
  194135. initSelectionAtoms();
  194136. localClipboardContent = clipText;
  194137. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194138. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194139. }
  194140. const String SystemClipboard::getTextFromClipboard()
  194141. {
  194142. initSelectionAtoms();
  194143. String content;
  194144. Atom selection = XA_PRIMARY;
  194145. Window selectionOwner = None;
  194146. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194147. {
  194148. selection = atom_CLIPBOARD;
  194149. selectionOwner = XGetSelectionOwner (display, selection);
  194150. }
  194151. if (selectionOwner != None)
  194152. {
  194153. if (selectionOwner == juce_messageWindowHandle)
  194154. {
  194155. content = localClipboardContent;
  194156. }
  194157. else
  194158. {
  194159. // first try: we want an utf8 string
  194160. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194161. if (! ok)
  194162. {
  194163. // second chance, ask for a good old locale-dependent string ..
  194164. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194165. }
  194166. }
  194167. }
  194168. return content;
  194169. }
  194170. #endif
  194171. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194172. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194173. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194174. // compiled on its own).
  194175. #if JUCE_INCLUDED_FILE
  194176. #ifdef JUCE_DEBUG
  194177. #define JUCE_DEBUG_XERRORS 1
  194178. #endif
  194179. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194180. Window juce_messageWindowHandle = None;
  194181. XContext improbableNumber; // This is referenced from Windowing.cpp
  194182. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194183. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194184. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194185. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194186. class InternalMessageQueue
  194187. {
  194188. public:
  194189. InternalMessageQueue()
  194190. : bytesInSocket (0)
  194191. {
  194192. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194193. (void) ret; jassert (ret == 0);
  194194. //setNonBlocking (fd[0]);
  194195. //setNonBlocking (fd[1]);
  194196. }
  194197. ~InternalMessageQueue()
  194198. {
  194199. close (fd[0]);
  194200. close (fd[1]);
  194201. }
  194202. void postMessage (Message* msg)
  194203. {
  194204. const int maxBytesInSocketQueue = 128;
  194205. ScopedLock sl (lock);
  194206. queue.add (msg);
  194207. if (bytesInSocket < maxBytesInSocketQueue)
  194208. {
  194209. ++bytesInSocket;
  194210. ScopedUnlock ul (lock);
  194211. const unsigned char x = 0xff;
  194212. size_t bytesWritten = write (fd[0], &x, 1);
  194213. (void) bytesWritten;
  194214. }
  194215. }
  194216. bool isEmpty() const
  194217. {
  194218. ScopedLock sl (lock);
  194219. return queue.size() == 0;
  194220. }
  194221. Message* popNextMessage()
  194222. {
  194223. ScopedLock sl (lock);
  194224. if (bytesInSocket > 0)
  194225. {
  194226. --bytesInSocket;
  194227. ScopedUnlock ul (lock);
  194228. unsigned char x;
  194229. size_t numBytes = read (fd[1], &x, 1);
  194230. (void) numBytes;
  194231. }
  194232. Message* m = queue[0];
  194233. queue.remove (0, false /* deleteObject */);
  194234. return m;
  194235. }
  194236. int getWaitHandle() const { return fd[1]; }
  194237. private:
  194238. CriticalSection lock;
  194239. OwnedArray <Message> queue;
  194240. int fd[2];
  194241. int bytesInSocket;
  194242. static bool setNonBlocking (int handle)
  194243. {
  194244. int socketFlags = fcntl (handle, F_GETFL, 0);
  194245. if (socketFlags == -1)
  194246. return false;
  194247. socketFlags |= O_NONBLOCK;
  194248. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194249. }
  194250. };
  194251. struct MessageThreadFuncCall
  194252. {
  194253. enum { uniqueID = 0x73774623 };
  194254. MessageCallbackFunction* func;
  194255. void* parameter;
  194256. void* result;
  194257. CriticalSection lock;
  194258. WaitableEvent event;
  194259. };
  194260. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194261. // error handling in X11
  194262. static bool errorOccurred = false;
  194263. static bool keyboardBreakOccurred = false;
  194264. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194265. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194266. // Usually happens when client-server connection is broken
  194267. static int ioErrorHandler (Display* display)
  194268. {
  194269. DBG ("ERROR: connection to X server broken.. terminating.");
  194270. errorOccurred = true;
  194271. if (JUCEApplication::getInstance() != 0)
  194272. Process::terminate();
  194273. return 0;
  194274. }
  194275. // A protocol error has occurred
  194276. static int errorHandler (Display* display, XErrorEvent* event)
  194277. {
  194278. #ifdef JUCE_DEBUG_XERRORS
  194279. char errorStr[64] = { 0 };
  194280. char requestStr[64] = { 0 };
  194281. XGetErrorText (display, event->error_code, errorStr, 64);
  194282. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194283. "Unknown", requestStr, 64);
  194284. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194285. #endif
  194286. return 0;
  194287. }
  194288. // Breakin from keyboard
  194289. static void signalHandler (int sig)
  194290. {
  194291. if (sig == SIGINT)
  194292. {
  194293. keyboardBreakOccurred = true;
  194294. return;
  194295. }
  194296. static bool reentrant = false;
  194297. if (! reentrant)
  194298. {
  194299. reentrant = true;
  194300. // Illegal instruction
  194301. fflush (stdout);
  194302. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194303. errorOccurred = true;
  194304. if (JUCEApplication::getInstance() != 0)
  194305. Process::terminate();
  194306. }
  194307. else
  194308. {
  194309. if (JUCEApplication::getInstance() != 0)
  194310. exit(0);
  194311. }
  194312. }
  194313. void MessageManager::doPlatformSpecificInitialisation()
  194314. {
  194315. // Initialise xlib for multiple thread support
  194316. static bool initThreadCalled = false;
  194317. if (! initThreadCalled)
  194318. {
  194319. if (! XInitThreads())
  194320. {
  194321. // This is fatal! Print error and closedown
  194322. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194323. if (JUCEApplication::getInstance() != 0)
  194324. Process::terminate();
  194325. return;
  194326. }
  194327. initThreadCalled = true;
  194328. }
  194329. // This is called if the client/server connection is broken
  194330. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194331. // This is called if a protocol error occurs
  194332. oldErrorHandler = XSetErrorHandler (errorHandler);
  194333. // Install signal handler for break-in
  194334. struct sigaction saction;
  194335. sigset_t maskSet;
  194336. sigemptyset (&maskSet);
  194337. saction.sa_handler = signalHandler;
  194338. saction.sa_mask = maskSet;
  194339. saction.sa_flags = 0;
  194340. sigaction (SIGINT, &saction, NULL);
  194341. #ifndef _DEBUG
  194342. // Setup signal handlers for various fatal errors
  194343. sigaction (SIGILL, &saction, NULL);
  194344. sigaction (SIGBUS, &saction, NULL);
  194345. sigaction (SIGFPE, &saction, NULL);
  194346. sigaction (SIGSEGV, &saction, NULL);
  194347. sigaction (SIGSYS, &saction, NULL);
  194348. #endif
  194349. // Create the internal message queue
  194350. juce_internalMessageQueue = new InternalMessageQueue();
  194351. // Try to connect to a display
  194352. String displayName (getenv ("DISPLAY"));
  194353. if (displayName.isEmpty())
  194354. displayName = ":0.0";
  194355. display = XOpenDisplay (displayName.toCString());
  194356. if (display == 0)
  194357. {
  194358. // This is not fatal! we can run headless.
  194359. return;
  194360. }
  194361. // Get defaults for various properties
  194362. int screen = DefaultScreen (display);
  194363. Window root = RootWindow (display, screen);
  194364. Visual* visual = DefaultVisual (display, screen);
  194365. // Create a context to store user data associated with Windows we
  194366. // create in WindowDriver
  194367. improbableNumber = XUniqueContext();
  194368. // We're only interested in client messages for this window
  194369. // which are always sent
  194370. XSetWindowAttributes swa;
  194371. swa.event_mask = NoEventMask;
  194372. // Create our message window (this will never be mapped)
  194373. juce_messageWindowHandle = XCreateWindow (display, root,
  194374. 0, 0, 1, 1, 0, 0, InputOnly,
  194375. visual, CWEventMask, &swa);
  194376. }
  194377. void MessageManager::doPlatformSpecificShutdown()
  194378. {
  194379. deleteAndZero (juce_internalMessageQueue);
  194380. if (display != 0 && ! errorOccurred)
  194381. {
  194382. XDestroyWindow (display, juce_messageWindowHandle);
  194383. XCloseDisplay (display);
  194384. // reset pointers
  194385. juce_messageWindowHandle = 0;
  194386. display = 0;
  194387. // Restore original error handlers
  194388. XSetIOErrorHandler (oldIOErrorHandler);
  194389. oldIOErrorHandler = 0;
  194390. XSetErrorHandler (oldErrorHandler);
  194391. oldErrorHandler = 0;
  194392. }
  194393. }
  194394. bool juce_postMessageToSystemQueue (void* message)
  194395. {
  194396. if (errorOccurred)
  194397. return false;
  194398. juce_internalMessageQueue->postMessage ((Message*) message);
  194399. return true;
  194400. }
  194401. void MessageManager::broadcastMessage (const String& value) throw()
  194402. {
  194403. }
  194404. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194405. void* parameter)
  194406. {
  194407. if (errorOccurred)
  194408. return 0;
  194409. if (! isThisTheMessageThread())
  194410. {
  194411. MessageThreadFuncCall messageCallContext;
  194412. messageCallContext.func = func;
  194413. messageCallContext.parameter = parameter;
  194414. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194415. 0, 0, &messageCallContext));
  194416. // Wait for it to complete before continuing
  194417. messageCallContext.event.wait();
  194418. return messageCallContext.result;
  194419. }
  194420. else
  194421. {
  194422. // Just call the function directly
  194423. return func (parameter);
  194424. }
  194425. }
  194426. // Wait for an event (either XEvent, or an internal Message)
  194427. static bool juce_sleepUntilEvent (const int timeoutMs)
  194428. {
  194429. if (! juce_internalMessageQueue->isEmpty())
  194430. return true;
  194431. if (display != 0)
  194432. {
  194433. ScopedXLock xlock;
  194434. if (XPending (display))
  194435. return true;
  194436. }
  194437. struct timeval tv;
  194438. tv.tv_sec = 0;
  194439. tv.tv_usec = timeoutMs * 1000;
  194440. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194441. int fdmax = fd0;
  194442. fd_set readset;
  194443. FD_ZERO (&readset);
  194444. FD_SET (fd0, &readset);
  194445. if (display != 0)
  194446. {
  194447. ScopedXLock xlock;
  194448. int fd1 = XConnectionNumber (display);
  194449. FD_SET (fd1, &readset);
  194450. fdmax = jmax (fd0, fd1);
  194451. }
  194452. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194453. return (ret > 0); // ret <= 0 if error or timeout
  194454. }
  194455. // Handle next XEvent (if any)
  194456. static bool juce_dispatchNextXEvent()
  194457. {
  194458. if (display == 0)
  194459. return false;
  194460. XEvent evt;
  194461. {
  194462. ScopedXLock xlock;
  194463. if (! XPending (display))
  194464. return false;
  194465. XNextEvent (display, &evt);
  194466. }
  194467. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194468. {
  194469. juce_handleSelectionRequest (evt.xselectionrequest);
  194470. }
  194471. else if (evt.xany.window != juce_messageWindowHandle)
  194472. {
  194473. juce_windowMessageReceive (&evt);
  194474. }
  194475. return true;
  194476. }
  194477. // Handle next internal Message (if any)
  194478. static bool juce_dispatchNextInternalMessage()
  194479. {
  194480. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194481. if (msg == 0)
  194482. return false;
  194483. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194484. {
  194485. // Handle callback message
  194486. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194487. call->result = (*(call->func)) (call->parameter);
  194488. call->event.signal();
  194489. }
  194490. else
  194491. {
  194492. // Handle "normal" messages
  194493. MessageManager::getInstance()->deliverMessage (msg.release());
  194494. }
  194495. return true;
  194496. }
  194497. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194498. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194499. {
  194500. for (;;)
  194501. {
  194502. if (errorOccurred)
  194503. break;
  194504. if (keyboardBreakOccurred)
  194505. {
  194506. errorOccurred = true;
  194507. if (JUCEApplication::getInstance() != 0)
  194508. Process::terminate();
  194509. break;
  194510. }
  194511. static int totalEventCount = 0;
  194512. ++totalEventCount;
  194513. // The purpose here is to give either priority to XEvents or
  194514. // to internal messages This is necessary to keep a "good"
  194515. // behaviour when the cpu is overloaded
  194516. if (totalEventCount & 1)
  194517. {
  194518. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194519. return true;
  194520. }
  194521. else
  194522. {
  194523. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194524. return true;
  194525. }
  194526. if (returnIfNoPendingMessages) // early exit
  194527. break;
  194528. // the timeout is to be on the safe side, but it does not seem to be useful
  194529. juce_sleepUntilEvent (2000);
  194530. }
  194531. return false;
  194532. }
  194533. #endif
  194534. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194535. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194536. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194537. // compiled on its own).
  194538. #if JUCE_INCLUDED_FILE
  194539. class FreeTypeFontFace
  194540. {
  194541. public:
  194542. enum FontStyle
  194543. {
  194544. Plain = 0,
  194545. Bold = 1,
  194546. Italic = 2
  194547. };
  194548. struct FontNameIndex
  194549. {
  194550. String fileName;
  194551. int faceIndex;
  194552. };
  194553. FreeTypeFontFace (const String& familyName)
  194554. : hasSerif (false),
  194555. monospaced (false)
  194556. {
  194557. family = familyName;
  194558. }
  194559. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194560. {
  194561. if (names [(int) style].fileName.isEmpty())
  194562. {
  194563. names [(int) style].fileName = name;
  194564. names [(int) style].faceIndex = faceIndex;
  194565. }
  194566. }
  194567. const String& getFamilyName() const throw() { return family; }
  194568. const String& getFileName (const int style, int& faceIndex) const throw()
  194569. {
  194570. faceIndex = names[style].faceIndex;
  194571. return names[style].fileName;
  194572. }
  194573. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194574. bool getMonospaced() const throw() { return monospaced; }
  194575. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194576. bool getSerif() const throw() { return hasSerif; }
  194577. private:
  194578. String family;
  194579. FontNameIndex names[4];
  194580. bool hasSerif, monospaced;
  194581. };
  194582. class FreeTypeInterface : public DeletedAtShutdown
  194583. {
  194584. public:
  194585. FreeTypeInterface()
  194586. : ftLib (0),
  194587. lastFace (0),
  194588. lastBold (false),
  194589. lastItalic (false)
  194590. {
  194591. if (FT_Init_FreeType (&ftLib) != 0)
  194592. {
  194593. ftLib = 0;
  194594. DBG ("Failed to initialize FreeType");
  194595. }
  194596. StringArray fontDirs;
  194597. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194598. fontDirs.removeEmptyStrings (true);
  194599. if (fontDirs.size() == 0)
  194600. {
  194601. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194602. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194603. if (fontsInfo != 0)
  194604. {
  194605. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194606. {
  194607. fontDirs.add (e->getAllSubText().trim());
  194608. }
  194609. delete fontsInfo;
  194610. }
  194611. }
  194612. if (fontDirs.size() == 0)
  194613. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194614. for (int i = 0; i < fontDirs.size(); ++i)
  194615. enumerateFaces (fontDirs[i]);
  194616. }
  194617. ~FreeTypeInterface()
  194618. {
  194619. if (lastFace != 0)
  194620. FT_Done_Face (lastFace);
  194621. if (ftLib != 0)
  194622. FT_Done_FreeType (ftLib);
  194623. clearSingletonInstance();
  194624. }
  194625. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194626. {
  194627. for (int i = 0; i < faces.size(); i++)
  194628. if (faces[i]->getFamilyName() == familyName)
  194629. return faces[i];
  194630. if (! create)
  194631. return NULL;
  194632. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194633. faces.add (newFace);
  194634. return newFace;
  194635. }
  194636. // Enumerate all font faces available in a given directory
  194637. void enumerateFaces (const String& path)
  194638. {
  194639. File dirPath (path);
  194640. if (path.isEmpty() || ! dirPath.isDirectory())
  194641. return;
  194642. DirectoryIterator di (dirPath, true);
  194643. while (di.next())
  194644. {
  194645. File possible (di.getFile());
  194646. if (possible.hasFileExtension ("ttf")
  194647. || possible.hasFileExtension ("pfb")
  194648. || possible.hasFileExtension ("pcf"))
  194649. {
  194650. FT_Face face;
  194651. int faceIndex = 0;
  194652. int numFaces = 0;
  194653. do
  194654. {
  194655. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194656. faceIndex, &face) == 0)
  194657. {
  194658. if (faceIndex == 0)
  194659. numFaces = face->num_faces;
  194660. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194661. {
  194662. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194663. int style = (int) FreeTypeFontFace::Plain;
  194664. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194665. style |= (int) FreeTypeFontFace::Bold;
  194666. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194667. style |= (int) FreeTypeFontFace::Italic;
  194668. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194669. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194670. // Surely there must be a better way to do this?
  194671. const String name (face->family_name);
  194672. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194673. || name.containsIgnoreCase ("Verdana")
  194674. || name.containsIgnoreCase ("Arial")));
  194675. }
  194676. FT_Done_Face (face);
  194677. }
  194678. ++faceIndex;
  194679. }
  194680. while (faceIndex < numFaces);
  194681. }
  194682. }
  194683. }
  194684. // Create a FreeType face object for a given font
  194685. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194686. {
  194687. FT_Face face = 0;
  194688. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194689. {
  194690. face = lastFace;
  194691. }
  194692. else
  194693. {
  194694. if (lastFace != 0)
  194695. {
  194696. FT_Done_Face (lastFace);
  194697. lastFace = 0;
  194698. }
  194699. lastFontName = fontName;
  194700. lastBold = bold;
  194701. lastItalic = italic;
  194702. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194703. if (ftFace != 0)
  194704. {
  194705. int style = (int) FreeTypeFontFace::Plain;
  194706. if (bold)
  194707. style |= (int) FreeTypeFontFace::Bold;
  194708. if (italic)
  194709. style |= (int) FreeTypeFontFace::Italic;
  194710. int faceIndex;
  194711. String fileName (ftFace->getFileName (style, faceIndex));
  194712. if (fileName.isEmpty())
  194713. {
  194714. style ^= (int) FreeTypeFontFace::Bold;
  194715. fileName = ftFace->getFileName (style, faceIndex);
  194716. if (fileName.isEmpty())
  194717. {
  194718. style ^= (int) FreeTypeFontFace::Bold;
  194719. style ^= (int) FreeTypeFontFace::Italic;
  194720. fileName = ftFace->getFileName (style, faceIndex);
  194721. if (! fileName.length())
  194722. {
  194723. style ^= (int) FreeTypeFontFace::Bold;
  194724. fileName = ftFace->getFileName (style, faceIndex);
  194725. }
  194726. }
  194727. }
  194728. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194729. {
  194730. face = lastFace;
  194731. // If there isn't a unicode charmap then select the first one.
  194732. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194733. FT_Set_Charmap (face, face->charmaps[0]);
  194734. }
  194735. }
  194736. }
  194737. return face;
  194738. }
  194739. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194740. {
  194741. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194742. const float height = (float) (face->ascender - face->descender);
  194743. const float scaleX = 1.0f / height;
  194744. const float scaleY = -1.0f / height;
  194745. Path destShape;
  194746. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194747. || face->glyph->format != ft_glyph_format_outline)
  194748. {
  194749. return false;
  194750. }
  194751. const FT_Outline* const outline = &face->glyph->outline;
  194752. const short* const contours = outline->contours;
  194753. const char* const tags = outline->tags;
  194754. FT_Vector* const points = outline->points;
  194755. for (int c = 0; c < outline->n_contours; c++)
  194756. {
  194757. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194758. const int endPoint = contours[c];
  194759. for (int p = startPoint; p <= endPoint; p++)
  194760. {
  194761. const float x = scaleX * points[p].x;
  194762. const float y = scaleY * points[p].y;
  194763. if (p == startPoint)
  194764. {
  194765. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194766. {
  194767. float x2 = scaleX * points [endPoint].x;
  194768. float y2 = scaleY * points [endPoint].y;
  194769. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194770. {
  194771. x2 = (x + x2) * 0.5f;
  194772. y2 = (y + y2) * 0.5f;
  194773. }
  194774. destShape.startNewSubPath (x2, y2);
  194775. }
  194776. else
  194777. {
  194778. destShape.startNewSubPath (x, y);
  194779. }
  194780. }
  194781. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194782. {
  194783. if (p != startPoint)
  194784. destShape.lineTo (x, y);
  194785. }
  194786. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194787. {
  194788. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194789. float x2 = scaleX * points [nextIndex].x;
  194790. float y2 = scaleY * points [nextIndex].y;
  194791. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194792. {
  194793. x2 = (x + x2) * 0.5f;
  194794. y2 = (y + y2) * 0.5f;
  194795. }
  194796. else
  194797. {
  194798. ++p;
  194799. }
  194800. destShape.quadraticTo (x, y, x2, y2);
  194801. }
  194802. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194803. {
  194804. if (p >= endPoint)
  194805. return false;
  194806. const int next1 = p + 1;
  194807. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194808. const float x2 = scaleX * points [next1].x;
  194809. const float y2 = scaleY * points [next1].y;
  194810. const float x3 = scaleX * points [next2].x;
  194811. const float y3 = scaleY * points [next2].y;
  194812. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194813. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194814. return false;
  194815. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194816. p += 2;
  194817. }
  194818. }
  194819. destShape.closeSubPath();
  194820. }
  194821. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194822. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194823. addKerning (face, dest, character, glyphIndex);
  194824. return true;
  194825. }
  194826. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194827. {
  194828. const float height = (float) (face->ascender - face->descender);
  194829. uint32 rightGlyphIndex;
  194830. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194831. while (rightGlyphIndex != 0)
  194832. {
  194833. FT_Vector kerning;
  194834. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194835. {
  194836. if (kerning.x != 0)
  194837. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194838. }
  194839. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194840. }
  194841. }
  194842. // Add a glyph to a font
  194843. bool addGlyphToFont (const uint32 character, const String& fontName,
  194844. bool bold, bool italic, CustomTypeface& dest)
  194845. {
  194846. FT_Face face = createFT_Face (fontName, bold, italic);
  194847. return face != 0 && addGlyph (face, dest, character);
  194848. }
  194849. void getFamilyNames (StringArray& familyNames) const
  194850. {
  194851. for (int i = 0; i < faces.size(); i++)
  194852. familyNames.add (faces[i]->getFamilyName());
  194853. }
  194854. void getMonospacedNames (StringArray& monoSpaced) const
  194855. {
  194856. for (int i = 0; i < faces.size(); i++)
  194857. if (faces[i]->getMonospaced())
  194858. monoSpaced.add (faces[i]->getFamilyName());
  194859. }
  194860. void getSerifNames (StringArray& serif) const
  194861. {
  194862. for (int i = 0; i < faces.size(); i++)
  194863. if (faces[i]->getSerif())
  194864. serif.add (faces[i]->getFamilyName());
  194865. }
  194866. void getSansSerifNames (StringArray& sansSerif) const
  194867. {
  194868. for (int i = 0; i < faces.size(); i++)
  194869. if (! faces[i]->getSerif())
  194870. sansSerif.add (faces[i]->getFamilyName());
  194871. }
  194872. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194873. private:
  194874. FT_Library ftLib;
  194875. FT_Face lastFace;
  194876. String lastFontName;
  194877. bool lastBold, lastItalic;
  194878. OwnedArray<FreeTypeFontFace> faces;
  194879. };
  194880. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194881. class FreetypeTypeface : public CustomTypeface
  194882. {
  194883. public:
  194884. FreetypeTypeface (const Font& font)
  194885. {
  194886. FT_Face face = FreeTypeInterface::getInstance()
  194887. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194888. if (face == 0)
  194889. {
  194890. #ifdef JUCE_DEBUG
  194891. String msg ("Failed to create typeface: ");
  194892. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194893. DBG (msg);
  194894. #endif
  194895. }
  194896. else
  194897. {
  194898. setCharacteristics (font.getTypefaceName(),
  194899. face->ascender / (float) (face->ascender - face->descender),
  194900. font.isBold(), font.isItalic(),
  194901. L' ');
  194902. }
  194903. }
  194904. bool loadGlyphIfPossible (juce_wchar character)
  194905. {
  194906. return FreeTypeInterface::getInstance()
  194907. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194908. }
  194909. };
  194910. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194911. {
  194912. return new FreetypeTypeface (font);
  194913. }
  194914. const StringArray Font::findAllTypefaceNames()
  194915. {
  194916. StringArray s;
  194917. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194918. s.sort (true);
  194919. return s;
  194920. }
  194921. static const String pickBestFont (const StringArray& names,
  194922. const char* const choicesString)
  194923. {
  194924. StringArray choices;
  194925. choices.addTokens (String (choicesString), ",", String::empty);
  194926. choices.trim();
  194927. choices.removeEmptyStrings();
  194928. int i, j;
  194929. for (j = 0; j < choices.size(); ++j)
  194930. if (names.contains (choices[j], true))
  194931. return choices[j];
  194932. for (j = 0; j < choices.size(); ++j)
  194933. for (i = 0; i < names.size(); i++)
  194934. if (names[i].startsWithIgnoreCase (choices[j]))
  194935. return names[i];
  194936. for (j = 0; j < choices.size(); ++j)
  194937. for (i = 0; i < names.size(); i++)
  194938. if (names[i].containsIgnoreCase (choices[j]))
  194939. return names[i];
  194940. return names[0];
  194941. }
  194942. static const String linux_getDefaultSansSerifFontName()
  194943. {
  194944. StringArray allFonts;
  194945. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  194946. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  194947. }
  194948. static const String linux_getDefaultSerifFontName()
  194949. {
  194950. StringArray allFonts;
  194951. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  194952. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  194953. }
  194954. static const String linux_getDefaultMonospacedFontName()
  194955. {
  194956. StringArray allFonts;
  194957. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  194958. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  194959. }
  194960. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  194961. {
  194962. defaultSans = linux_getDefaultSansSerifFontName();
  194963. defaultSerif = linux_getDefaultSerifFontName();
  194964. defaultFixed = linux_getDefaultMonospacedFontName();
  194965. }
  194966. #endif
  194967. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  194968. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  194969. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194970. // compiled on its own).
  194971. #if JUCE_INCLUDED_FILE
  194972. // These are defined in juce_linux_Messaging.cpp
  194973. extern Display* display;
  194974. extern XContext improbableNumber;
  194975. namespace Atoms
  194976. {
  194977. enum ProtocolItems
  194978. {
  194979. TAKE_FOCUS = 0,
  194980. DELETE_WINDOW = 1,
  194981. PING = 2
  194982. };
  194983. static Atom Protocols, ProtocolList[3], ChangeState, State,
  194984. ActiveWin, Pid, WindowType, WindowState,
  194985. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  194986. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  194987. XdndActionDescription, XdndActionCopy,
  194988. allowedActions[5],
  194989. allowedMimeTypes[2];
  194990. const unsigned long DndVersion = 3;
  194991. static void initialiseAtoms()
  194992. {
  194993. static bool atomsInitialised = false;
  194994. if (! atomsInitialised)
  194995. {
  194996. atomsInitialised = true;
  194997. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  194998. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  194999. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195000. ProtocolList [PING] = XInternAtom (display, "_NET_WM_PING", True);
  195001. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195002. State = XInternAtom (display, "WM_STATE", True);
  195003. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195004. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195005. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195006. WindowState = XInternAtom (display, "_NET_WM_STATE", True);
  195007. XdndAware = XInternAtom (display, "XdndAware", False);
  195008. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195009. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195010. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195011. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195012. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195013. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195014. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195015. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195016. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195017. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195018. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195019. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  195020. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  195021. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  195022. allowedActions[1] = XdndActionCopy;
  195023. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  195024. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  195025. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  195026. }
  195027. }
  195028. }
  195029. namespace Keys
  195030. {
  195031. enum MouseButtons
  195032. {
  195033. NoButton = 0,
  195034. LeftButton = 1,
  195035. MiddleButton = 2,
  195036. RightButton = 3,
  195037. WheelUp = 4,
  195038. WheelDown = 5
  195039. };
  195040. static int AltMask = 0;
  195041. static int NumLockMask = 0;
  195042. static bool numLock = false;
  195043. static bool capsLock = false;
  195044. static char keyStates [32];
  195045. static const int extendedKeyModifier = 0x10000000;
  195046. }
  195047. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  195048. {
  195049. int keysym;
  195050. if (keyCode & Keys::extendedKeyModifier)
  195051. {
  195052. keysym = 0xff00 | (keyCode & 0xff);
  195053. }
  195054. else
  195055. {
  195056. keysym = keyCode;
  195057. if (keysym == (XK_Tab & 0xff)
  195058. || keysym == (XK_Return & 0xff)
  195059. || keysym == (XK_Escape & 0xff)
  195060. || keysym == (XK_BackSpace & 0xff))
  195061. {
  195062. keysym |= 0xff00;
  195063. }
  195064. }
  195065. ScopedXLock xlock;
  195066. const int keycode = XKeysymToKeycode (display, keysym);
  195067. const int keybyte = keycode >> 3;
  195068. const int keybit = (1 << (keycode & 7));
  195069. return (Keys::keyStates [keybyte] & keybit) != 0;
  195070. }
  195071. #if JUCE_USE_XSHM
  195072. namespace XSHMHelpers
  195073. {
  195074. static int trappedErrorCode = 0;
  195075. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  195076. {
  195077. trappedErrorCode = err->error_code;
  195078. return 0;
  195079. }
  195080. static bool isShmAvailable() throw()
  195081. {
  195082. static bool isChecked = false;
  195083. static bool isAvailable = false;
  195084. if (! isChecked)
  195085. {
  195086. isChecked = true;
  195087. int major, minor;
  195088. Bool pixmaps;
  195089. ScopedXLock xlock;
  195090. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195091. {
  195092. trappedErrorCode = 0;
  195093. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  195094. XShmSegmentInfo segmentInfo;
  195095. zerostruct (segmentInfo);
  195096. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195097. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195098. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195099. xImage->bytes_per_line * xImage->height,
  195100. IPC_CREAT | 0777)) >= 0)
  195101. {
  195102. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195103. if (segmentInfo.shmaddr != (void*) -1)
  195104. {
  195105. segmentInfo.readOnly = False;
  195106. xImage->data = segmentInfo.shmaddr;
  195107. XSync (display, False);
  195108. if (XShmAttach (display, &segmentInfo) != 0)
  195109. {
  195110. XSync (display, False);
  195111. XShmDetach (display, &segmentInfo);
  195112. isAvailable = true;
  195113. }
  195114. }
  195115. XFlush (display);
  195116. XDestroyImage (xImage);
  195117. shmdt (segmentInfo.shmaddr);
  195118. }
  195119. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195120. XSetErrorHandler (oldHandler);
  195121. if (trappedErrorCode != 0)
  195122. isAvailable = false;
  195123. }
  195124. }
  195125. return isAvailable;
  195126. }
  195127. }
  195128. #endif
  195129. #if JUCE_USE_XRENDER
  195130. namespace XRender
  195131. {
  195132. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195133. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195134. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195135. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195136. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195137. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195138. static tXRenderFindFormat xRenderFindFormat = 0;
  195139. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195140. static bool isAvailable()
  195141. {
  195142. static bool hasLoaded = false;
  195143. if (! hasLoaded)
  195144. {
  195145. ScopedXLock xlock;
  195146. hasLoaded = true;
  195147. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195148. if (h != 0)
  195149. {
  195150. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195151. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195152. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195153. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195154. }
  195155. if (xRenderQueryVersion != 0
  195156. && xRenderFindStandardFormat != 0
  195157. && xRenderFindFormat != 0
  195158. && xRenderFindVisualFormat != 0)
  195159. {
  195160. int major, minor;
  195161. if (xRenderQueryVersion (display, &major, &minor))
  195162. return true;
  195163. }
  195164. xRenderQueryVersion = 0;
  195165. }
  195166. return xRenderQueryVersion != 0;
  195167. }
  195168. static XRenderPictFormat* findPictureFormat()
  195169. {
  195170. ScopedXLock xlock;
  195171. XRenderPictFormat* pictFormat = 0;
  195172. if (isAvailable())
  195173. {
  195174. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195175. if (pictFormat == 0)
  195176. {
  195177. XRenderPictFormat desiredFormat;
  195178. desiredFormat.type = PictTypeDirect;
  195179. desiredFormat.depth = 32;
  195180. desiredFormat.direct.alphaMask = 0xff;
  195181. desiredFormat.direct.redMask = 0xff;
  195182. desiredFormat.direct.greenMask = 0xff;
  195183. desiredFormat.direct.blueMask = 0xff;
  195184. desiredFormat.direct.alpha = 24;
  195185. desiredFormat.direct.red = 16;
  195186. desiredFormat.direct.green = 8;
  195187. desiredFormat.direct.blue = 0;
  195188. pictFormat = xRenderFindFormat (display,
  195189. PictFormatType | PictFormatDepth
  195190. | PictFormatRedMask | PictFormatRed
  195191. | PictFormatGreenMask | PictFormatGreen
  195192. | PictFormatBlueMask | PictFormatBlue
  195193. | PictFormatAlphaMask | PictFormatAlpha,
  195194. &desiredFormat,
  195195. 0);
  195196. }
  195197. }
  195198. return pictFormat;
  195199. }
  195200. }
  195201. #endif
  195202. namespace Visuals
  195203. {
  195204. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195205. {
  195206. ScopedXLock xlock;
  195207. Visual* visual = 0;
  195208. int numVisuals = 0;
  195209. long desiredMask = VisualNoMask;
  195210. XVisualInfo desiredVisual;
  195211. desiredVisual.screen = DefaultScreen (display);
  195212. desiredVisual.depth = desiredDepth;
  195213. desiredMask = VisualScreenMask | VisualDepthMask;
  195214. if (desiredDepth == 32)
  195215. {
  195216. desiredVisual.c_class = TrueColor;
  195217. desiredVisual.red_mask = 0x00FF0000;
  195218. desiredVisual.green_mask = 0x0000FF00;
  195219. desiredVisual.blue_mask = 0x000000FF;
  195220. desiredVisual.bits_per_rgb = 8;
  195221. desiredMask |= VisualClassMask;
  195222. desiredMask |= VisualRedMaskMask;
  195223. desiredMask |= VisualGreenMaskMask;
  195224. desiredMask |= VisualBlueMaskMask;
  195225. desiredMask |= VisualBitsPerRGBMask;
  195226. }
  195227. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195228. desiredMask,
  195229. &desiredVisual,
  195230. &numVisuals);
  195231. if (xvinfos != 0)
  195232. {
  195233. for (int i = 0; i < numVisuals; i++)
  195234. {
  195235. if (xvinfos[i].depth == desiredDepth)
  195236. {
  195237. visual = xvinfos[i].visual;
  195238. break;
  195239. }
  195240. }
  195241. XFree (xvinfos);
  195242. }
  195243. return visual;
  195244. }
  195245. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195246. {
  195247. Visual* visual = 0;
  195248. if (desiredDepth == 32)
  195249. {
  195250. #if JUCE_USE_XSHM
  195251. if (XSHMHelpers::isShmAvailable())
  195252. {
  195253. #if JUCE_USE_XRENDER
  195254. if (XRender::isAvailable())
  195255. {
  195256. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195257. if (pictFormat != 0)
  195258. {
  195259. int numVisuals = 0;
  195260. XVisualInfo desiredVisual;
  195261. desiredVisual.screen = DefaultScreen (display);
  195262. desiredVisual.depth = 32;
  195263. desiredVisual.bits_per_rgb = 8;
  195264. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195265. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195266. &desiredVisual, &numVisuals);
  195267. if (xvinfos != 0)
  195268. {
  195269. for (int i = 0; i < numVisuals; ++i)
  195270. {
  195271. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195272. if (pictVisualFormat != 0
  195273. && pictVisualFormat->type == PictTypeDirect
  195274. && pictVisualFormat->direct.alphaMask)
  195275. {
  195276. visual = xvinfos[i].visual;
  195277. matchedDepth = 32;
  195278. break;
  195279. }
  195280. }
  195281. XFree (xvinfos);
  195282. }
  195283. }
  195284. }
  195285. #endif
  195286. if (visual == 0)
  195287. {
  195288. visual = findVisualWithDepth (32);
  195289. if (visual != 0)
  195290. matchedDepth = 32;
  195291. }
  195292. }
  195293. #endif
  195294. }
  195295. if (visual == 0 && desiredDepth >= 24)
  195296. {
  195297. visual = findVisualWithDepth (24);
  195298. if (visual != 0)
  195299. matchedDepth = 24;
  195300. }
  195301. if (visual == 0 && desiredDepth >= 16)
  195302. {
  195303. visual = findVisualWithDepth (16);
  195304. if (visual != 0)
  195305. matchedDepth = 16;
  195306. }
  195307. return visual;
  195308. }
  195309. }
  195310. class XBitmapImage : public Image
  195311. {
  195312. public:
  195313. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195314. const bool clearImage, const int imageDepth_, Visual* visual)
  195315. : Image (format_, w, h),
  195316. imageDepth (imageDepth_),
  195317. gc (None)
  195318. {
  195319. jassert (format_ == RGB || format_ == ARGB);
  195320. pixelStride = (format_ == RGB) ? 3 : 4;
  195321. lineStride = ((w * pixelStride + 3) & ~3);
  195322. ScopedXLock xlock;
  195323. #if JUCE_USE_XSHM
  195324. usingXShm = false;
  195325. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  195326. {
  195327. zerostruct (segmentInfo);
  195328. segmentInfo.shmid = -1;
  195329. segmentInfo.shmaddr = (char *) -1;
  195330. segmentInfo.readOnly = False;
  195331. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195332. if (xImage != 0)
  195333. {
  195334. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195335. xImage->bytes_per_line * xImage->height,
  195336. IPC_CREAT | 0777)) >= 0)
  195337. {
  195338. if (segmentInfo.shmid != -1)
  195339. {
  195340. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195341. if (segmentInfo.shmaddr != (void*) -1)
  195342. {
  195343. segmentInfo.readOnly = False;
  195344. xImage->data = segmentInfo.shmaddr;
  195345. imageData = (uint8*) segmentInfo.shmaddr;
  195346. if (XShmAttach (display, &segmentInfo) != 0)
  195347. {
  195348. usingXShm = true;
  195349. }
  195350. else
  195351. {
  195352. jassertfalse
  195353. }
  195354. }
  195355. else
  195356. {
  195357. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195358. }
  195359. }
  195360. }
  195361. }
  195362. }
  195363. if (! usingXShm)
  195364. #endif
  195365. {
  195366. imageDataAllocated.malloc (lineStride * h);
  195367. imageData = imageDataAllocated;
  195368. if (format_ == ARGB && clearImage)
  195369. zeromem (imageData, h * lineStride);
  195370. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195371. xImage->width = w;
  195372. xImage->height = h;
  195373. xImage->xoffset = 0;
  195374. xImage->format = ZPixmap;
  195375. xImage->data = (char*) imageData;
  195376. xImage->byte_order = ImageByteOrder (display);
  195377. xImage->bitmap_unit = BitmapUnit (display);
  195378. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195379. xImage->bitmap_pad = 32;
  195380. xImage->depth = pixelStride * 8;
  195381. xImage->bytes_per_line = lineStride;
  195382. xImage->bits_per_pixel = pixelStride * 8;
  195383. xImage->red_mask = 0x00FF0000;
  195384. xImage->green_mask = 0x0000FF00;
  195385. xImage->blue_mask = 0x000000FF;
  195386. if (imageDepth == 16)
  195387. {
  195388. const int pixelStride = 2;
  195389. const int lineStride = ((w * pixelStride + 3) & ~3);
  195390. imageData16Bit.malloc (lineStride * h);
  195391. xImage->data = imageData16Bit;
  195392. xImage->bitmap_pad = 16;
  195393. xImage->depth = pixelStride * 8;
  195394. xImage->bytes_per_line = lineStride;
  195395. xImage->bits_per_pixel = pixelStride * 8;
  195396. xImage->red_mask = visual->red_mask;
  195397. xImage->green_mask = visual->green_mask;
  195398. xImage->blue_mask = visual->blue_mask;
  195399. }
  195400. if (! XInitImage (xImage))
  195401. {
  195402. jassertfalse
  195403. }
  195404. }
  195405. }
  195406. ~XBitmapImage()
  195407. {
  195408. ScopedXLock xlock;
  195409. if (gc != None)
  195410. XFreeGC (display, gc);
  195411. #if JUCE_USE_XSHM
  195412. if (usingXShm)
  195413. {
  195414. XShmDetach (display, &segmentInfo);
  195415. XFlush (display);
  195416. XDestroyImage (xImage);
  195417. shmdt (segmentInfo.shmaddr);
  195418. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195419. }
  195420. else
  195421. #endif
  195422. {
  195423. xImage->data = 0;
  195424. XDestroyImage (xImage);
  195425. }
  195426. }
  195427. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195428. {
  195429. ScopedXLock xlock;
  195430. if (gc == None)
  195431. {
  195432. XGCValues gcvalues;
  195433. gcvalues.foreground = None;
  195434. gcvalues.background = None;
  195435. gcvalues.function = GXcopy;
  195436. gcvalues.plane_mask = AllPlanes;
  195437. gcvalues.clip_mask = None;
  195438. gcvalues.graphics_exposures = False;
  195439. gc = XCreateGC (display, window,
  195440. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195441. &gcvalues);
  195442. }
  195443. if (imageDepth == 16)
  195444. {
  195445. const uint32 rMask = xImage->red_mask;
  195446. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195447. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195448. const uint32 gMask = xImage->green_mask;
  195449. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195450. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195451. const uint32 bMask = xImage->blue_mask;
  195452. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195453. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195454. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195455. for (int y = sy; y < sy + dh; ++y)
  195456. {
  195457. const uint8* p = srcData.getPixelPointer (sx, y);
  195458. for (int x = sx; x < sx + dw; ++x)
  195459. {
  195460. const PixelRGB* const pixel = (const PixelRGB*) p;
  195461. p += srcData.pixelStride;
  195462. XPutPixel (xImage, x, y,
  195463. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195464. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195465. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195466. }
  195467. }
  195468. }
  195469. // blit results to screen.
  195470. #if JUCE_USE_XSHM
  195471. if (usingXShm)
  195472. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195473. else
  195474. #endif
  195475. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195476. }
  195477. juce_UseDebuggingNewOperator
  195478. private:
  195479. XImage* xImage;
  195480. const int imageDepth;
  195481. HeapBlock <char> imageData16Bit;
  195482. GC gc;
  195483. #if JUCE_USE_XSHM
  195484. XShmSegmentInfo segmentInfo;
  195485. bool usingXShm;
  195486. #endif
  195487. static int getShiftNeeded (const uint32 mask) throw()
  195488. {
  195489. for (int i = 32; --i >= 0;)
  195490. if (((mask >> i) & 1) != 0)
  195491. return i - 7;
  195492. jassertfalse
  195493. return 0;
  195494. }
  195495. };
  195496. class LinuxComponentPeer : public ComponentPeer
  195497. {
  195498. public:
  195499. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195500. : ComponentPeer (component, windowStyleFlags),
  195501. windowH (0),
  195502. parentWindow (0),
  195503. wx (0),
  195504. wy (0),
  195505. ww (0),
  195506. wh (0),
  195507. fullScreen (false),
  195508. mapped (false),
  195509. visual (0),
  195510. depth (0)
  195511. {
  195512. // it's dangerous to create a window on a thread other than the message thread..
  195513. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195514. repainter = new LinuxRepaintManager (this);
  195515. createWindow();
  195516. setTitle (component->getName());
  195517. }
  195518. ~LinuxComponentPeer()
  195519. {
  195520. // it's dangerous to delete a window on a thread other than the message thread..
  195521. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195522. deleteIconPixmaps();
  195523. destroyWindow();
  195524. windowH = 0;
  195525. }
  195526. void* getNativeHandle() const
  195527. {
  195528. return (void*) windowH;
  195529. }
  195530. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195531. {
  195532. XPointer peer = 0;
  195533. ScopedXLock xlock;
  195534. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195535. {
  195536. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195537. peer = 0;
  195538. }
  195539. return (LinuxComponentPeer*) peer;
  195540. }
  195541. void setVisible (bool shouldBeVisible)
  195542. {
  195543. ScopedXLock xlock;
  195544. if (shouldBeVisible)
  195545. XMapWindow (display, windowH);
  195546. else
  195547. XUnmapWindow (display, windowH);
  195548. }
  195549. void setTitle (const String& title)
  195550. {
  195551. setWindowTitle (windowH, title);
  195552. }
  195553. void setPosition (int x, int y)
  195554. {
  195555. setBounds (x, y, ww, wh, false);
  195556. }
  195557. void setSize (int w, int h)
  195558. {
  195559. setBounds (wx, wy, w, h, false);
  195560. }
  195561. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195562. {
  195563. fullScreen = isNowFullScreen;
  195564. if (windowH != 0)
  195565. {
  195566. Component::SafePointer<Component> deletionChecker (component);
  195567. wx = x;
  195568. wy = y;
  195569. ww = jmax (1, w);
  195570. wh = jmax (1, h);
  195571. ScopedXLock xlock;
  195572. // Make sure the Window manager does what we want
  195573. XSizeHints* hints = XAllocSizeHints();
  195574. hints->flags = USSize | USPosition;
  195575. hints->width = ww;
  195576. hints->height = wh;
  195577. hints->x = wx;
  195578. hints->y = wy;
  195579. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195580. {
  195581. hints->min_width = hints->max_width = hints->width;
  195582. hints->min_height = hints->max_height = hints->height;
  195583. hints->flags |= PMinSize | PMaxSize;
  195584. }
  195585. XSetWMNormalHints (display, windowH, hints);
  195586. XFree (hints);
  195587. XMoveResizeWindow (display, windowH,
  195588. wx - windowBorder.getLeft(),
  195589. wy - windowBorder.getTop(), ww, wh);
  195590. if (deletionChecker != 0)
  195591. {
  195592. updateBorderSize();
  195593. handleMovedOrResized();
  195594. }
  195595. }
  195596. }
  195597. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195598. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195599. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195600. {
  195601. return relativePosition + getScreenPosition();
  195602. }
  195603. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195604. {
  195605. return screenPosition - getScreenPosition();
  195606. }
  195607. void setMinimised (bool shouldBeMinimised)
  195608. {
  195609. if (shouldBeMinimised)
  195610. {
  195611. Window root = RootWindow (display, DefaultScreen (display));
  195612. XClientMessageEvent clientMsg;
  195613. clientMsg.display = display;
  195614. clientMsg.window = windowH;
  195615. clientMsg.type = ClientMessage;
  195616. clientMsg.format = 32;
  195617. clientMsg.message_type = Atoms::ChangeState;
  195618. clientMsg.data.l[0] = IconicState;
  195619. ScopedXLock xlock;
  195620. XSendEvent (display, root, false,
  195621. SubstructureRedirectMask | SubstructureNotifyMask,
  195622. (XEvent*) &clientMsg);
  195623. }
  195624. else
  195625. {
  195626. setVisible (true);
  195627. }
  195628. }
  195629. bool isMinimised() const
  195630. {
  195631. bool minimised = false;
  195632. unsigned char* stateProp;
  195633. unsigned long nitems, bytesLeft;
  195634. Atom actualType;
  195635. int actualFormat;
  195636. ScopedXLock xlock;
  195637. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195638. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195639. &stateProp) == Success
  195640. && actualType == Atoms::State
  195641. && actualFormat == 32
  195642. && nitems > 0)
  195643. {
  195644. if (((unsigned long*) stateProp)[0] == IconicState)
  195645. minimised = true;
  195646. XFree (stateProp);
  195647. }
  195648. return minimised;
  195649. }
  195650. void setFullScreen (const bool shouldBeFullScreen)
  195651. {
  195652. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195653. setMinimised (false);
  195654. if (fullScreen != shouldBeFullScreen)
  195655. {
  195656. if (shouldBeFullScreen)
  195657. r = Desktop::getInstance().getMainMonitorArea();
  195658. if (! r.isEmpty())
  195659. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195660. getComponent()->repaint();
  195661. }
  195662. }
  195663. bool isFullScreen() const
  195664. {
  195665. return fullScreen;
  195666. }
  195667. bool isChildWindowOf (Window possibleParent) const
  195668. {
  195669. Window* windowList = 0;
  195670. uint32 windowListSize = 0;
  195671. Window parent, root;
  195672. ScopedXLock xlock;
  195673. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195674. {
  195675. if (windowList != 0)
  195676. XFree (windowList);
  195677. return parent == possibleParent;
  195678. }
  195679. return false;
  195680. }
  195681. bool isFrontWindow() const
  195682. {
  195683. Window* windowList = 0;
  195684. uint32 windowListSize = 0;
  195685. bool result = false;
  195686. ScopedXLock xlock;
  195687. Window parent, root = RootWindow (display, DefaultScreen (display));
  195688. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195689. {
  195690. for (int i = windowListSize; --i >= 0;)
  195691. {
  195692. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195693. if (peer != 0)
  195694. {
  195695. result = (peer == this);
  195696. break;
  195697. }
  195698. }
  195699. }
  195700. if (windowList != 0)
  195701. XFree (windowList);
  195702. return result;
  195703. }
  195704. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195705. {
  195706. int x = position.getX();
  195707. int y = position.getY();
  195708. if (((unsigned int) x) >= (unsigned int) ww
  195709. || ((unsigned int) y) >= (unsigned int) wh)
  195710. return false;
  195711. bool inFront = false;
  195712. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195713. {
  195714. Component* const c = Desktop::getInstance().getComponent (i);
  195715. if (inFront)
  195716. {
  195717. if (c->contains (x + wx - c->getScreenX(),
  195718. y + wy - c->getScreenY()))
  195719. {
  195720. return false;
  195721. }
  195722. }
  195723. else if (c == getComponent())
  195724. {
  195725. inFront = true;
  195726. }
  195727. }
  195728. if (trueIfInAChildWindow)
  195729. return true;
  195730. ::Window root, child;
  195731. unsigned int bw, depth;
  195732. int wx, wy, w, h;
  195733. ScopedXLock xlock;
  195734. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195735. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195736. &bw, &depth))
  195737. {
  195738. return false;
  195739. }
  195740. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195741. return false;
  195742. return child == None;
  195743. }
  195744. const BorderSize getFrameSize() const
  195745. {
  195746. return BorderSize();
  195747. }
  195748. bool setAlwaysOnTop (bool alwaysOnTop)
  195749. {
  195750. if (windowH != 0)
  195751. {
  195752. const bool wasVisible = component->isVisible();
  195753. if (wasVisible)
  195754. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195755. {
  195756. ScopedXLock xlock;
  195757. XSetWindowAttributes swa;
  195758. swa.override_redirect = alwaysOnTop ? True : False;
  195759. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195760. }
  195761. if (wasVisible)
  195762. setVisible (true);
  195763. }
  195764. return true;
  195765. }
  195766. void toFront (bool makeActive)
  195767. {
  195768. if (makeActive)
  195769. {
  195770. setVisible (true);
  195771. grabFocus();
  195772. }
  195773. XEvent ev;
  195774. ev.xclient.type = ClientMessage;
  195775. ev.xclient.serial = 0;
  195776. ev.xclient.send_event = True;
  195777. ev.xclient.message_type = Atoms::ActiveWin;
  195778. ev.xclient.window = windowH;
  195779. ev.xclient.format = 32;
  195780. ev.xclient.data.l[0] = 2;
  195781. ev.xclient.data.l[1] = CurrentTime;
  195782. ev.xclient.data.l[2] = 0;
  195783. ev.xclient.data.l[3] = 0;
  195784. ev.xclient.data.l[4] = 0;
  195785. {
  195786. ScopedXLock xlock;
  195787. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195788. False,
  195789. SubstructureRedirectMask | SubstructureNotifyMask,
  195790. &ev);
  195791. XWindowAttributes attr;
  195792. XGetWindowAttributes (display, windowH, &attr);
  195793. if (attr.override_redirect)
  195794. XRaiseWindow (display, windowH);
  195795. XSync (display, False);
  195796. }
  195797. handleBroughtToFront();
  195798. }
  195799. void toBehind (ComponentPeer* other)
  195800. {
  195801. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195802. jassert (otherPeer != 0); // wrong type of window?
  195803. if (otherPeer != 0)
  195804. {
  195805. setMinimised (false);
  195806. Window newStack[] = { otherPeer->windowH, windowH };
  195807. ScopedXLock xlock;
  195808. XRestackWindows (display, newStack, 2);
  195809. }
  195810. }
  195811. bool isFocused() const
  195812. {
  195813. int revert;
  195814. Window focusedWindow = 0;
  195815. ScopedXLock xlock;
  195816. XGetInputFocus (display, &focusedWindow, &revert);
  195817. return focusedWindow == windowH;
  195818. }
  195819. void grabFocus()
  195820. {
  195821. XWindowAttributes atts;
  195822. ScopedXLock xlock;
  195823. if (windowH != 0
  195824. && XGetWindowAttributes (display, windowH, &atts)
  195825. && atts.map_state == IsViewable
  195826. && ! isFocused())
  195827. {
  195828. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195829. isActiveApplication = true;
  195830. }
  195831. }
  195832. void textInputRequired (const Point<int>&)
  195833. {
  195834. }
  195835. void repaint (int x, int y, int w, int h)
  195836. {
  195837. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195838. 0, 0,
  195839. getComponent()->getWidth(),
  195840. getComponent()->getHeight()))
  195841. {
  195842. repainter->repaint (x, y, w, h);
  195843. }
  195844. }
  195845. void performAnyPendingRepaintsNow()
  195846. {
  195847. repainter->performAnyPendingRepaintsNow();
  195848. }
  195849. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195850. {
  195851. ScopedXLock xlock;
  195852. const int width = image.getWidth();
  195853. const int height = image.getHeight();
  195854. HeapBlock <char> colour (width * height);
  195855. int index = 0;
  195856. for (int y = 0; y < height; ++y)
  195857. for (int x = 0; x < width; ++x)
  195858. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195859. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195860. 0, colour.getData(),
  195861. width, height, 32, 0);
  195862. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195863. width, height, 24);
  195864. GC gc = XCreateGC (display, pixmap, 0, 0);
  195865. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195866. XFreeGC (display, gc);
  195867. return pixmap;
  195868. }
  195869. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195870. {
  195871. ScopedXLock xlock;
  195872. const int width = image.getWidth();
  195873. const int height = image.getHeight();
  195874. const int stride = (width + 7) >> 3;
  195875. HeapBlock <char> mask;
  195876. mask.calloc (stride * height);
  195877. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195878. for (int y = 0; y < height; ++y)
  195879. {
  195880. for (int x = 0; x < width; ++x)
  195881. {
  195882. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195883. const int offset = y * stride + (x >> 3);
  195884. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195885. mask[offset] |= bit;
  195886. }
  195887. }
  195888. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195889. mask.getData(), width, height, 1, 0, 1);
  195890. }
  195891. void setIcon (const Image& newIcon)
  195892. {
  195893. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195894. HeapBlock <unsigned long> data (dataSize);
  195895. int index = 0;
  195896. data[index++] = newIcon.getWidth();
  195897. data[index++] = newIcon.getHeight();
  195898. for (int y = 0; y < newIcon.getHeight(); ++y)
  195899. for (int x = 0; x < newIcon.getWidth(); ++x)
  195900. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195901. ScopedXLock xlock;
  195902. XChangeProperty (display, windowH,
  195903. XInternAtom (display, "_NET_WM_ICON", False),
  195904. XA_CARDINAL, 32, PropModeReplace,
  195905. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195906. deleteIconPixmaps();
  195907. XWMHints* wmHints = XGetWMHints (display, windowH);
  195908. if (wmHints == 0)
  195909. wmHints = XAllocWMHints();
  195910. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195911. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195912. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195913. XSetWMHints (display, windowH, wmHints);
  195914. XFree (wmHints);
  195915. XSync (display, False);
  195916. }
  195917. void deleteIconPixmaps()
  195918. {
  195919. ScopedXLock xlock;
  195920. XWMHints* wmHints = XGetWMHints (display, windowH);
  195921. if (wmHints != 0)
  195922. {
  195923. if ((wmHints->flags & IconPixmapHint) != 0)
  195924. {
  195925. wmHints->flags &= ~IconPixmapHint;
  195926. XFreePixmap (display, wmHints->icon_pixmap);
  195927. }
  195928. if ((wmHints->flags & IconMaskHint) != 0)
  195929. {
  195930. wmHints->flags &= ~IconMaskHint;
  195931. XFreePixmap (display, wmHints->icon_mask);
  195932. }
  195933. XSetWMHints (display, windowH, wmHints);
  195934. XFree (wmHints);
  195935. }
  195936. }
  195937. void handleWindowMessage (XEvent* event)
  195938. {
  195939. switch (event->xany.type)
  195940. {
  195941. case 2: // 'KeyPress'
  195942. {
  195943. ScopedXLock xlock;
  195944. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  195945. updateKeyStates (keyEvent->keycode, true);
  195946. char utf8 [64];
  195947. zeromem (utf8, sizeof (utf8));
  195948. KeySym sym;
  195949. {
  195950. const char* oldLocale = ::setlocale (LC_ALL, 0);
  195951. ::setlocale (LC_ALL, "");
  195952. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  195953. ::setlocale (LC_ALL, oldLocale);
  195954. }
  195955. const juce_wchar unicodeChar = String::fromUTF8 (utf8, sizeof (utf8) - 1) [0];
  195956. int keyCode = (int) unicodeChar;
  195957. if (keyCode < 0x20)
  195958. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  195959. const ModifierKeys oldMods (currentModifiers);
  195960. bool keyPressed = false;
  195961. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  195962. if ((sym & 0xff00) == 0xff00)
  195963. {
  195964. // Translate keypad
  195965. if (sym == XK_KP_Divide)
  195966. keyCode = XK_slash;
  195967. else if (sym == XK_KP_Multiply)
  195968. keyCode = XK_asterisk;
  195969. else if (sym == XK_KP_Subtract)
  195970. keyCode = XK_hyphen;
  195971. else if (sym == XK_KP_Add)
  195972. keyCode = XK_plus;
  195973. else if (sym == XK_KP_Enter)
  195974. keyCode = XK_Return;
  195975. else if (sym == XK_KP_Decimal)
  195976. keyCode = Keys::numLock ? XK_period : XK_Delete;
  195977. else if (sym == XK_KP_0)
  195978. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  195979. else if (sym == XK_KP_1)
  195980. keyCode = Keys::numLock ? XK_1 : XK_End;
  195981. else if (sym == XK_KP_2)
  195982. keyCode = Keys::numLock ? XK_2 : XK_Down;
  195983. else if (sym == XK_KP_3)
  195984. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  195985. else if (sym == XK_KP_4)
  195986. keyCode = Keys::numLock ? XK_4 : XK_Left;
  195987. else if (sym == XK_KP_5)
  195988. keyCode = XK_5;
  195989. else if (sym == XK_KP_6)
  195990. keyCode = Keys::numLock ? XK_6 : XK_Right;
  195991. else if (sym == XK_KP_7)
  195992. keyCode = Keys::numLock ? XK_7 : XK_Home;
  195993. else if (sym == XK_KP_8)
  195994. keyCode = Keys::numLock ? XK_8 : XK_Up;
  195995. else if (sym == XK_KP_9)
  195996. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  195997. switch (sym)
  195998. {
  195999. case XK_Left:
  196000. case XK_Right:
  196001. case XK_Up:
  196002. case XK_Down:
  196003. case XK_Page_Up:
  196004. case XK_Page_Down:
  196005. case XK_End:
  196006. case XK_Home:
  196007. case XK_Delete:
  196008. case XK_Insert:
  196009. keyPressed = true;
  196010. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196011. break;
  196012. case XK_Tab:
  196013. case XK_Return:
  196014. case XK_Escape:
  196015. case XK_BackSpace:
  196016. keyPressed = true;
  196017. keyCode &= 0xff;
  196018. break;
  196019. default:
  196020. {
  196021. if (sym >= XK_F1 && sym <= XK_F16)
  196022. {
  196023. keyPressed = true;
  196024. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196025. }
  196026. break;
  196027. }
  196028. }
  196029. }
  196030. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196031. keyPressed = true;
  196032. if (oldMods != currentModifiers)
  196033. handleModifierKeysChange();
  196034. if (keyDownChange)
  196035. handleKeyUpOrDown (true);
  196036. if (keyPressed)
  196037. handleKeyPress (keyCode, unicodeChar);
  196038. break;
  196039. }
  196040. case KeyRelease:
  196041. {
  196042. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196043. updateKeyStates (keyEvent->keycode, false);
  196044. ScopedXLock xlock;
  196045. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196046. const ModifierKeys oldMods (currentModifiers);
  196047. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196048. if (oldMods != currentModifiers)
  196049. handleModifierKeysChange();
  196050. if (keyDownChange)
  196051. handleKeyUpOrDown (false);
  196052. break;
  196053. }
  196054. case ButtonPress:
  196055. {
  196056. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196057. updateKeyModifiers (buttonPressEvent->state);
  196058. bool buttonMsg = false;
  196059. const int map = pointerMap [buttonPressEvent->button - Button1];
  196060. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196061. {
  196062. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196063. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196064. }
  196065. if (map == Keys::LeftButton)
  196066. {
  196067. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196068. buttonMsg = true;
  196069. }
  196070. else if (map == Keys::RightButton)
  196071. {
  196072. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196073. buttonMsg = true;
  196074. }
  196075. else if (map == Keys::MiddleButton)
  196076. {
  196077. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196078. buttonMsg = true;
  196079. }
  196080. if (buttonMsg)
  196081. {
  196082. toFront (true);
  196083. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196084. getEventTime (buttonPressEvent->time));
  196085. }
  196086. clearLastMousePos();
  196087. break;
  196088. }
  196089. case ButtonRelease:
  196090. {
  196091. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196092. updateKeyModifiers (buttonRelEvent->state);
  196093. const int map = pointerMap [buttonRelEvent->button - Button1];
  196094. if (map == Keys::LeftButton)
  196095. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196096. else if (map == Keys::RightButton)
  196097. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196098. else if (map == Keys::MiddleButton)
  196099. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196100. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196101. getEventTime (buttonRelEvent->time));
  196102. clearLastMousePos();
  196103. break;
  196104. }
  196105. case MotionNotify:
  196106. {
  196107. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196108. updateKeyModifiers (movedEvent->state);
  196109. const Point<int> mousePos (Desktop::getMousePosition());
  196110. if (lastMousePos != mousePos)
  196111. {
  196112. lastMousePos = mousePos;
  196113. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196114. {
  196115. Window wRoot = 0, wParent = 0;
  196116. {
  196117. ScopedXLock xlock;
  196118. unsigned int numChildren;
  196119. Window* wChild = 0;
  196120. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196121. }
  196122. if (wParent != 0
  196123. && wParent != windowH
  196124. && wParent != wRoot)
  196125. {
  196126. parentWindow = wParent;
  196127. updateBounds();
  196128. }
  196129. else
  196130. {
  196131. parentWindow = 0;
  196132. }
  196133. }
  196134. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196135. }
  196136. break;
  196137. }
  196138. case EnterNotify:
  196139. {
  196140. clearLastMousePos();
  196141. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196142. if (! currentModifiers.isAnyMouseButtonDown())
  196143. {
  196144. updateKeyModifiers (enterEvent->state);
  196145. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196146. }
  196147. break;
  196148. }
  196149. case LeaveNotify:
  196150. {
  196151. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196152. // Suppress the normal leave if we've got a pointer grab, or if
  196153. // it's a bogus one caused by clicking a mouse button when running
  196154. // in a Window manager
  196155. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196156. || leaveEvent->mode == NotifyUngrab)
  196157. {
  196158. updateKeyModifiers (leaveEvent->state);
  196159. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196160. }
  196161. break;
  196162. }
  196163. case FocusIn:
  196164. {
  196165. isActiveApplication = true;
  196166. if (isFocused())
  196167. handleFocusGain();
  196168. break;
  196169. }
  196170. case FocusOut:
  196171. {
  196172. isActiveApplication = false;
  196173. if (! isFocused())
  196174. handleFocusLoss();
  196175. break;
  196176. }
  196177. case Expose:
  196178. {
  196179. // Batch together all pending expose events
  196180. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196181. XEvent nextEvent;
  196182. ScopedXLock xlock;
  196183. if (exposeEvent->window != windowH)
  196184. {
  196185. Window child;
  196186. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196187. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196188. &child);
  196189. }
  196190. repaint (exposeEvent->x, exposeEvent->y,
  196191. exposeEvent->width, exposeEvent->height);
  196192. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196193. {
  196194. XPeekEvent (display, (XEvent*) &nextEvent);
  196195. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196196. break;
  196197. XNextEvent (display, (XEvent*) &nextEvent);
  196198. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196199. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196200. nextExposeEvent->width, nextExposeEvent->height);
  196201. }
  196202. break;
  196203. }
  196204. case CirculateNotify:
  196205. case CreateNotify:
  196206. case DestroyNotify:
  196207. // Think we can ignore these
  196208. break;
  196209. case ConfigureNotify:
  196210. {
  196211. updateBounds();
  196212. updateBorderSize();
  196213. handleMovedOrResized();
  196214. // if the native title bar is dragged, need to tell any active menus, etc.
  196215. if ((styleFlags & windowHasTitleBar) != 0
  196216. && component->isCurrentlyBlockedByAnotherModalComponent())
  196217. {
  196218. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196219. if (currentModalComp != 0)
  196220. currentModalComp->inputAttemptWhenModal();
  196221. }
  196222. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196223. if (confEvent->window == windowH
  196224. && confEvent->above != 0
  196225. && isFrontWindow())
  196226. {
  196227. handleBroughtToFront();
  196228. }
  196229. break;
  196230. }
  196231. case ReparentNotify:
  196232. {
  196233. parentWindow = 0;
  196234. Window wRoot = 0;
  196235. Window* wChild = 0;
  196236. unsigned int numChildren;
  196237. {
  196238. ScopedXLock xlock;
  196239. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196240. }
  196241. if (parentWindow == windowH || parentWindow == wRoot)
  196242. parentWindow = 0;
  196243. updateBounds();
  196244. updateBorderSize();
  196245. handleMovedOrResized();
  196246. break;
  196247. }
  196248. case GravityNotify:
  196249. {
  196250. updateBounds();
  196251. updateBorderSize();
  196252. handleMovedOrResized();
  196253. break;
  196254. }
  196255. case MapNotify:
  196256. mapped = true;
  196257. handleBroughtToFront();
  196258. break;
  196259. case UnmapNotify:
  196260. mapped = false;
  196261. break;
  196262. case MappingNotify:
  196263. {
  196264. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196265. if (mappingEvent->request != MappingPointer)
  196266. {
  196267. // Deal with modifier/keyboard mapping
  196268. ScopedXLock xlock;
  196269. XRefreshKeyboardMapping (mappingEvent);
  196270. updateModifierMappings();
  196271. }
  196272. break;
  196273. }
  196274. case ClientMessage:
  196275. {
  196276. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196277. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196278. {
  196279. const Atom atom = (Atom) clientMsg->data.l[0];
  196280. if (atom == Atoms::ProtocolList [Atoms::PING])
  196281. {
  196282. Window root = RootWindow (display, DefaultScreen (display));
  196283. event->xclient.window = root;
  196284. XSendEvent (display, root, False, NoEventMask, event);
  196285. XFlush (display);
  196286. }
  196287. else if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196288. {
  196289. XWindowAttributes atts;
  196290. ScopedXLock xlock;
  196291. if (clientMsg->window != 0
  196292. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196293. {
  196294. if (atts.map_state == IsViewable)
  196295. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196296. }
  196297. }
  196298. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196299. {
  196300. handleUserClosingWindow();
  196301. }
  196302. }
  196303. else if (clientMsg->message_type == Atoms::XdndEnter)
  196304. {
  196305. handleDragAndDropEnter (clientMsg);
  196306. }
  196307. else if (clientMsg->message_type == Atoms::XdndLeave)
  196308. {
  196309. resetDragAndDrop();
  196310. }
  196311. else if (clientMsg->message_type == Atoms::XdndPosition)
  196312. {
  196313. handleDragAndDropPosition (clientMsg);
  196314. }
  196315. else if (clientMsg->message_type == Atoms::XdndDrop)
  196316. {
  196317. handleDragAndDropDrop (clientMsg);
  196318. }
  196319. else if (clientMsg->message_type == Atoms::XdndStatus)
  196320. {
  196321. handleDragAndDropStatus (clientMsg);
  196322. }
  196323. else if (clientMsg->message_type == Atoms::XdndFinished)
  196324. {
  196325. resetDragAndDrop();
  196326. }
  196327. break;
  196328. }
  196329. case SelectionNotify:
  196330. handleDragAndDropSelection (event);
  196331. break;
  196332. case SelectionClear:
  196333. case SelectionRequest:
  196334. break;
  196335. default:
  196336. #if JUCE_USE_XSHM
  196337. {
  196338. ScopedXLock xlock;
  196339. if (event->xany.type == XShmGetEventBase (display))
  196340. repainter->notifyPaintCompleted();
  196341. }
  196342. #endif
  196343. break;
  196344. }
  196345. }
  196346. void showMouseCursor (Cursor cursor) throw()
  196347. {
  196348. ScopedXLock xlock;
  196349. XDefineCursor (display, windowH, cursor);
  196350. }
  196351. void setTaskBarIcon (const Image& image)
  196352. {
  196353. ScopedXLock xlock;
  196354. taskbarImage = image.createCopy();
  196355. Screen* const screen = XDefaultScreenOfDisplay (display);
  196356. const int screenNumber = XScreenNumberOfScreen (screen);
  196357. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196358. screenAtom << screenNumber;
  196359. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196360. XGrabServer (display);
  196361. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196362. if (managerWin != None)
  196363. XSelectInput (display, managerWin, StructureNotifyMask);
  196364. XUngrabServer (display);
  196365. XFlush (display);
  196366. if (managerWin != None)
  196367. {
  196368. XEvent ev;
  196369. zerostruct (ev);
  196370. ev.xclient.type = ClientMessage;
  196371. ev.xclient.window = managerWin;
  196372. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196373. ev.xclient.format = 32;
  196374. ev.xclient.data.l[0] = CurrentTime;
  196375. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  196376. ev.xclient.data.l[2] = windowH;
  196377. ev.xclient.data.l[3] = 0;
  196378. ev.xclient.data.l[4] = 0;
  196379. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196380. XSync (display, False);
  196381. }
  196382. // For older KDE's ...
  196383. long atomData = 1;
  196384. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196385. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196386. // For more recent KDE's...
  196387. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196388. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196389. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196390. XSizeHints* hints = XAllocSizeHints();
  196391. hints->flags = PMinSize;
  196392. hints->min_width = 22;
  196393. hints->min_height = 22;
  196394. XSetWMNormalHints (display, windowH, hints);
  196395. XFree (hints);
  196396. }
  196397. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196398. juce_UseDebuggingNewOperator
  196399. bool dontRepaint;
  196400. static ModifierKeys currentModifiers;
  196401. static bool isActiveApplication;
  196402. private:
  196403. class LinuxRepaintManager : public Timer
  196404. {
  196405. public:
  196406. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196407. : peer (peer_),
  196408. lastTimeImageUsed (0)
  196409. {
  196410. #if JUCE_USE_XSHM
  196411. shmCompletedDrawing = true;
  196412. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196413. if (useARGBImagesForRendering)
  196414. {
  196415. ScopedXLock xlock;
  196416. XShmSegmentInfo segmentinfo;
  196417. XImage* const testImage
  196418. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196419. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196420. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196421. XDestroyImage (testImage);
  196422. }
  196423. #endif
  196424. }
  196425. ~LinuxRepaintManager()
  196426. {
  196427. }
  196428. void timerCallback()
  196429. {
  196430. #if JUCE_USE_XSHM
  196431. if (! shmCompletedDrawing)
  196432. return;
  196433. #endif
  196434. if (! regionsNeedingRepaint.isEmpty())
  196435. {
  196436. stopTimer();
  196437. performAnyPendingRepaintsNow();
  196438. }
  196439. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196440. {
  196441. stopTimer();
  196442. image = 0;
  196443. }
  196444. }
  196445. void repaint (int x, int y, int w, int h)
  196446. {
  196447. if (! isTimerRunning())
  196448. startTimer (repaintTimerPeriod);
  196449. regionsNeedingRepaint.add (x, y, w, h);
  196450. }
  196451. void performAnyPendingRepaintsNow()
  196452. {
  196453. #if JUCE_USE_XSHM
  196454. if (! shmCompletedDrawing)
  196455. {
  196456. startTimer (repaintTimerPeriod);
  196457. return;
  196458. }
  196459. #endif
  196460. peer->clearMaskedRegion();
  196461. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196462. regionsNeedingRepaint.clear();
  196463. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196464. if (! totalArea.isEmpty())
  196465. {
  196466. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196467. || image->getHeight() < totalArea.getHeight())
  196468. {
  196469. #if JUCE_USE_XSHM
  196470. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196471. : Image::RGB,
  196472. #else
  196473. image = new XBitmapImage (Image::RGB,
  196474. #endif
  196475. (totalArea.getWidth() + 31) & ~31,
  196476. (totalArea.getHeight() + 31) & ~31,
  196477. false,
  196478. peer->depth,
  196479. peer->visual);
  196480. }
  196481. startTimer (repaintTimerPeriod);
  196482. LowLevelGraphicsSoftwareRenderer context (*image);
  196483. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196484. if (context.clipToRectangleList (originalRepaintRegion))
  196485. {
  196486. if (peer->depth == 32)
  196487. {
  196488. RectangleList::Iterator i (originalRepaintRegion);
  196489. while (i.next())
  196490. {
  196491. const Rectangle<int>& r = *i.getRectangle();
  196492. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196493. }
  196494. }
  196495. peer->handlePaint (context);
  196496. }
  196497. if (! peer->maskedRegion.isEmpty())
  196498. originalRepaintRegion.subtract (peer->maskedRegion);
  196499. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196500. {
  196501. #if JUCE_USE_XSHM
  196502. shmCompletedDrawing = false;
  196503. #endif
  196504. const Rectangle<int>& r = *i.getRectangle();
  196505. image->blitToWindow (peer->windowH,
  196506. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196507. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196508. }
  196509. }
  196510. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196511. startTimer (repaintTimerPeriod);
  196512. }
  196513. #if JUCE_USE_XSHM
  196514. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196515. #endif
  196516. private:
  196517. enum { repaintTimerPeriod = 1000 / 100 };
  196518. LinuxComponentPeer* const peer;
  196519. ScopedPointer <XBitmapImage> image;
  196520. uint32 lastTimeImageUsed;
  196521. RectangleList regionsNeedingRepaint;
  196522. #if JUCE_USE_XSHM
  196523. bool useARGBImagesForRendering, shmCompletedDrawing;
  196524. #endif
  196525. LinuxRepaintManager (const LinuxRepaintManager&);
  196526. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196527. };
  196528. ScopedPointer <LinuxRepaintManager> repainter;
  196529. friend class LinuxRepaintManager;
  196530. Window windowH, parentWindow;
  196531. int wx, wy, ww, wh;
  196532. ScopedPointer<Image> taskbarImage;
  196533. bool fullScreen, mapped;
  196534. Visual* visual;
  196535. int depth;
  196536. BorderSize windowBorder;
  196537. struct MotifWmHints
  196538. {
  196539. unsigned long flags;
  196540. unsigned long functions;
  196541. unsigned long decorations;
  196542. long input_mode;
  196543. unsigned long status;
  196544. };
  196545. static void updateKeyStates (const int keycode, const bool press) throw()
  196546. {
  196547. const int keybyte = keycode >> 3;
  196548. const int keybit = (1 << (keycode & 7));
  196549. if (press)
  196550. Keys::keyStates [keybyte] |= keybit;
  196551. else
  196552. Keys::keyStates [keybyte] &= ~keybit;
  196553. }
  196554. static void updateKeyModifiers (const int status) throw()
  196555. {
  196556. int keyMods = 0;
  196557. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196558. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196559. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196560. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196561. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196562. Keys::capsLock = ((status & LockMask) != 0);
  196563. }
  196564. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196565. {
  196566. int modifier = 0;
  196567. bool isModifier = true;
  196568. switch (sym)
  196569. {
  196570. case XK_Shift_L:
  196571. case XK_Shift_R:
  196572. modifier = ModifierKeys::shiftModifier;
  196573. break;
  196574. case XK_Control_L:
  196575. case XK_Control_R:
  196576. modifier = ModifierKeys::ctrlModifier;
  196577. break;
  196578. case XK_Alt_L:
  196579. case XK_Alt_R:
  196580. modifier = ModifierKeys::altModifier;
  196581. break;
  196582. case XK_Num_Lock:
  196583. if (press)
  196584. Keys::numLock = ! Keys::numLock;
  196585. break;
  196586. case XK_Caps_Lock:
  196587. if (press)
  196588. Keys::capsLock = ! Keys::capsLock;
  196589. break;
  196590. case XK_Scroll_Lock:
  196591. break;
  196592. default:
  196593. isModifier = false;
  196594. break;
  196595. }
  196596. if (modifier != 0)
  196597. {
  196598. if (press)
  196599. currentModifiers = currentModifiers.withFlags (modifier);
  196600. else
  196601. currentModifiers = currentModifiers.withoutFlags (modifier);
  196602. }
  196603. return isModifier;
  196604. }
  196605. // Alt and Num lock are not defined by standard X
  196606. // modifier constants: check what they're mapped to
  196607. static void updateModifierMappings() throw()
  196608. {
  196609. ScopedXLock xlock;
  196610. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196611. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196612. Keys::AltMask = 0;
  196613. Keys::NumLockMask = 0;
  196614. XModifierKeymap* mapping = XGetModifierMapping (display);
  196615. if (mapping)
  196616. {
  196617. for (int i = 0; i < 8; i++)
  196618. {
  196619. if (mapping->modifiermap [i << 1] == altLeftCode)
  196620. Keys::AltMask = 1 << i;
  196621. else if (mapping->modifiermap [i << 1] == numLockCode)
  196622. Keys::NumLockMask = 1 << i;
  196623. }
  196624. XFreeModifiermap (mapping);
  196625. }
  196626. }
  196627. void removeWindowDecorations (Window wndH)
  196628. {
  196629. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196630. if (hints != None)
  196631. {
  196632. MotifWmHints motifHints;
  196633. zerostruct (motifHints);
  196634. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196635. motifHints.decorations = 0;
  196636. ScopedXLock xlock;
  196637. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196638. (unsigned char*) &motifHints, 4);
  196639. }
  196640. hints = XInternAtom (display, "_WIN_HINTS", True);
  196641. if (hints != None)
  196642. {
  196643. long gnomeHints = 0;
  196644. ScopedXLock xlock;
  196645. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196646. (unsigned char*) &gnomeHints, 1);
  196647. }
  196648. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196649. if (hints != None)
  196650. {
  196651. long kwmHints = 2; /*KDE_tinyDecoration*/
  196652. ScopedXLock xlock;
  196653. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196654. (unsigned char*) &kwmHints, 1);
  196655. }
  196656. }
  196657. void addWindowButtons (Window wndH)
  196658. {
  196659. ScopedXLock xlock;
  196660. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196661. if (hints != None)
  196662. {
  196663. MotifWmHints motifHints;
  196664. zerostruct (motifHints);
  196665. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196666. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196667. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196668. if ((styleFlags & windowHasCloseButton) != 0)
  196669. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196670. if ((styleFlags & windowHasMinimiseButton) != 0)
  196671. {
  196672. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196673. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196674. }
  196675. if ((styleFlags & windowHasMaximiseButton) != 0)
  196676. {
  196677. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196678. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196679. }
  196680. if ((styleFlags & windowIsResizable) != 0)
  196681. {
  196682. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196683. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196684. }
  196685. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196686. }
  196687. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196688. if (hints != None)
  196689. {
  196690. int netHints [6];
  196691. int num = 0;
  196692. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196693. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196694. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196695. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196696. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196697. (unsigned char*) &netHints, num);
  196698. }
  196699. }
  196700. void setWindowType (Window wndH)
  196701. {
  196702. int netHints [2];
  196703. int numHints = 0;
  196704. if ((styleFlags & windowIsTemporary) != 0
  196705. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196706. {
  196707. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196708. }
  196709. else
  196710. {
  196711. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196712. }
  196713. if (netHints [numHints] != 0)
  196714. ++numHints;
  196715. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196716. if (netHints [numHints] != 0)
  196717. ++numHints;
  196718. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196719. (unsigned char*) &netHints, numHints);
  196720. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196721. {
  196722. Atom skipTaskbar = XInternAtom (display, "_NET_WM_STATE_SKIP_TASKBAR", False);
  196723. XChangeProperty (display, wndH, Atoms::WindowState, XA_ATOM, 32, PropModeReplace,
  196724. (unsigned char*) &skipTaskbar, 1);
  196725. }
  196726. }
  196727. void createWindow()
  196728. {
  196729. ScopedXLock xlock;
  196730. Atoms::initialiseAtoms();
  196731. resetDragAndDrop();
  196732. // Get defaults for various properties
  196733. const int screen = DefaultScreen (display);
  196734. Window root = RootWindow (display, screen);
  196735. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196736. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196737. if (visual == 0)
  196738. {
  196739. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196740. Process::terminate();
  196741. }
  196742. // Create and install a colormap suitable fr our visual
  196743. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196744. XInstallColormap (display, colormap);
  196745. // Set up the window attributes
  196746. XSetWindowAttributes swa;
  196747. swa.border_pixel = 0;
  196748. swa.background_pixmap = None;
  196749. swa.colormap = colormap;
  196750. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196751. swa.event_mask = getAllEventsMask();
  196752. Window wndH = XCreateWindow (display, root,
  196753. 0, 0, 1, 1,
  196754. 0, depth, InputOutput, visual,
  196755. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196756. &swa);
  196757. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196758. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196759. GrabModeAsync, GrabModeAsync, None, None);
  196760. // Set the window context to identify the window handle object
  196761. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196762. {
  196763. // Failed
  196764. jassertfalse
  196765. Logger::outputDebugString ("Failed to create context information for window.\n");
  196766. XDestroyWindow (display, wndH);
  196767. wndH = 0;
  196768. }
  196769. // Set window manager hints
  196770. XWMHints* wmHints = XAllocWMHints();
  196771. wmHints->flags = InputHint | StateHint;
  196772. wmHints->input = True; // Locally active input model
  196773. wmHints->initial_state = NormalState;
  196774. XSetWMHints (display, wndH, wmHints);
  196775. XFree (wmHints);
  196776. // Set the window type
  196777. setWindowType (wndH);
  196778. // Define decoration
  196779. if ((styleFlags & windowHasTitleBar) == 0)
  196780. removeWindowDecorations (wndH);
  196781. else
  196782. addWindowButtons (wndH);
  196783. // Set window name
  196784. setWindowTitle (wndH, getComponent()->getName());
  196785. // Associate the PID, allowing to be shut down when something goes wrong
  196786. unsigned long pid = getpid();
  196787. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196788. (unsigned char*) &pid, 1);
  196789. // Set window manager protocols
  196790. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196791. (unsigned char*) Atoms::ProtocolList, 2);
  196792. // Set drag and drop flags
  196793. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196794. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196795. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196796. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196797. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196798. (const unsigned char*) "", 0);
  196799. unsigned long dndVersion = Atoms::DndVersion;
  196800. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196801. (const unsigned char*) &dndVersion, 1);
  196802. // Initialise the pointer and keyboard mapping
  196803. // This is not the same as the logical pointer mapping the X server uses:
  196804. // we don't mess with this.
  196805. static bool mappingInitialised = false;
  196806. if (! mappingInitialised)
  196807. {
  196808. mappingInitialised = true;
  196809. const int numButtons = XGetPointerMapping (display, 0, 0);
  196810. if (numButtons == 2)
  196811. {
  196812. pointerMap[0] = Keys::LeftButton;
  196813. pointerMap[1] = Keys::RightButton;
  196814. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196815. }
  196816. else if (numButtons >= 3)
  196817. {
  196818. pointerMap[0] = Keys::LeftButton;
  196819. pointerMap[1] = Keys::MiddleButton;
  196820. pointerMap[2] = Keys::RightButton;
  196821. if (numButtons >= 5)
  196822. {
  196823. pointerMap[3] = Keys::WheelUp;
  196824. pointerMap[4] = Keys::WheelDown;
  196825. }
  196826. }
  196827. updateModifierMappings();
  196828. }
  196829. windowH = wndH;
  196830. }
  196831. void destroyWindow()
  196832. {
  196833. ScopedXLock xlock;
  196834. XPointer handlePointer;
  196835. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196836. XDeleteContext (display, (XID) windowH, improbableNumber);
  196837. XDestroyWindow (display, windowH);
  196838. // Wait for it to complete and then remove any events for this
  196839. // window from the event queue.
  196840. XSync (display, false);
  196841. XEvent event;
  196842. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196843. {}
  196844. }
  196845. static int getAllEventsMask() throw()
  196846. {
  196847. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196848. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196849. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196850. }
  196851. static int64 getEventTime (::Time t)
  196852. {
  196853. static int64 eventTimeOffset = 0x12345678;
  196854. const int64 thisMessageTime = t;
  196855. if (eventTimeOffset == 0x12345678)
  196856. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196857. return eventTimeOffset + thisMessageTime;
  196858. }
  196859. static void setWindowTitle (Window xwin, const String& title)
  196860. {
  196861. XTextProperty nameProperty;
  196862. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196863. ScopedXLock xlock;
  196864. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196865. {
  196866. XSetWMName (display, xwin, &nameProperty);
  196867. XSetWMIconName (display, xwin, &nameProperty);
  196868. XFree (nameProperty.value);
  196869. }
  196870. }
  196871. void updateBorderSize()
  196872. {
  196873. if ((styleFlags & windowHasTitleBar) == 0)
  196874. {
  196875. windowBorder = BorderSize (0);
  196876. }
  196877. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196878. {
  196879. ScopedXLock xlock;
  196880. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196881. if (hints != None)
  196882. {
  196883. unsigned char* data = 0;
  196884. unsigned long nitems, bytesLeft;
  196885. Atom actualType;
  196886. int actualFormat;
  196887. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196888. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196889. &data) == Success)
  196890. {
  196891. const unsigned long* const sizes = (const unsigned long*) data;
  196892. if (actualFormat == 32)
  196893. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196894. (int) sizes[3], (int) sizes[1]);
  196895. XFree (data);
  196896. }
  196897. }
  196898. }
  196899. }
  196900. void updateBounds()
  196901. {
  196902. jassert (windowH != 0);
  196903. if (windowH != 0)
  196904. {
  196905. Window root, child;
  196906. unsigned int bw, depth;
  196907. ScopedXLock xlock;
  196908. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196909. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196910. &bw, &depth))
  196911. {
  196912. wx = wy = ww = wh = 0;
  196913. }
  196914. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196915. {
  196916. wx = wy = 0;
  196917. }
  196918. }
  196919. }
  196920. void resetDragAndDrop()
  196921. {
  196922. dragAndDropFiles.clear();
  196923. lastDropPos = Point<int> (-1, -1);
  196924. dragAndDropCurrentMimeType = 0;
  196925. dragAndDropSourceWindow = 0;
  196926. srcMimeTypeAtomList.clear();
  196927. }
  196928. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196929. {
  196930. msg.type = ClientMessage;
  196931. msg.display = display;
  196932. msg.window = dragAndDropSourceWindow;
  196933. msg.format = 32;
  196934. msg.data.l[0] = windowH;
  196935. ScopedXLock xlock;
  196936. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196937. }
  196938. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196939. {
  196940. XClientMessageEvent msg;
  196941. zerostruct (msg);
  196942. msg.message_type = Atoms::XdndStatus;
  196943. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196944. msg.data.l[4] = dropAction;
  196945. sendDragAndDropMessage (msg);
  196946. }
  196947. void sendDragAndDropLeave()
  196948. {
  196949. XClientMessageEvent msg;
  196950. zerostruct (msg);
  196951. msg.message_type = Atoms::XdndLeave;
  196952. sendDragAndDropMessage (msg);
  196953. }
  196954. void sendDragAndDropFinish()
  196955. {
  196956. XClientMessageEvent msg;
  196957. zerostruct (msg);
  196958. msg.message_type = Atoms::XdndFinished;
  196959. sendDragAndDropMessage (msg);
  196960. }
  196961. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  196962. {
  196963. if ((clientMsg->data.l[1] & 1) == 0)
  196964. {
  196965. sendDragAndDropLeave();
  196966. if (dragAndDropFiles.size() > 0)
  196967. handleFileDragExit (dragAndDropFiles);
  196968. dragAndDropFiles.clear();
  196969. }
  196970. }
  196971. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  196972. {
  196973. if (dragAndDropSourceWindow == 0)
  196974. return;
  196975. dragAndDropSourceWindow = clientMsg->data.l[0];
  196976. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  196977. (int) clientMsg->data.l[2] & 0xffff);
  196978. dropPos -= getScreenPosition();
  196979. if (lastDropPos != dropPos)
  196980. {
  196981. lastDropPos = dropPos;
  196982. dragAndDropTimestamp = clientMsg->data.l[3];
  196983. Atom targetAction = Atoms::XdndActionCopy;
  196984. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  196985. {
  196986. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  196987. {
  196988. targetAction = Atoms::allowedActions[i];
  196989. break;
  196990. }
  196991. }
  196992. sendDragAndDropStatus (true, targetAction);
  196993. if (dragAndDropFiles.size() == 0)
  196994. updateDraggedFileList (clientMsg);
  196995. if (dragAndDropFiles.size() > 0)
  196996. handleFileDragMove (dragAndDropFiles, dropPos);
  196997. }
  196998. }
  196999. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197000. {
  197001. if (dragAndDropFiles.size() == 0)
  197002. updateDraggedFileList (clientMsg);
  197003. const StringArray files (dragAndDropFiles);
  197004. const Point<int> lastPos (lastDropPos);
  197005. sendDragAndDropFinish();
  197006. resetDragAndDrop();
  197007. if (files.size() > 0)
  197008. handleFileDragDrop (files, lastPos);
  197009. }
  197010. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197011. {
  197012. dragAndDropFiles.clear();
  197013. srcMimeTypeAtomList.clear();
  197014. dragAndDropCurrentMimeType = 0;
  197015. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197016. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197017. {
  197018. dragAndDropSourceWindow = 0;
  197019. return;
  197020. }
  197021. dragAndDropSourceWindow = clientMsg->data.l[0];
  197022. if ((clientMsg->data.l[1] & 1) != 0)
  197023. {
  197024. Atom actual;
  197025. int format;
  197026. unsigned long count = 0, remaining = 0;
  197027. unsigned char* data = 0;
  197028. ScopedXLock xlock;
  197029. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197030. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197031. &count, &remaining, &data);
  197032. if (data != 0)
  197033. {
  197034. if (actual == XA_ATOM && format == 32 && count != 0)
  197035. {
  197036. const unsigned long* const types = (const unsigned long*) data;
  197037. for (unsigned int i = 0; i < count; ++i)
  197038. if (types[i] != None)
  197039. srcMimeTypeAtomList.add (types[i]);
  197040. }
  197041. XFree (data);
  197042. }
  197043. }
  197044. if (srcMimeTypeAtomList.size() == 0)
  197045. {
  197046. for (int i = 2; i < 5; ++i)
  197047. if (clientMsg->data.l[i] != None)
  197048. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197049. if (srcMimeTypeAtomList.size() == 0)
  197050. {
  197051. dragAndDropSourceWindow = 0;
  197052. return;
  197053. }
  197054. }
  197055. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197056. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197057. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197058. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197059. handleDragAndDropPosition (clientMsg);
  197060. }
  197061. void handleDragAndDropSelection (const XEvent* const evt)
  197062. {
  197063. dragAndDropFiles.clear();
  197064. if (evt->xselection.property != 0)
  197065. {
  197066. StringArray lines;
  197067. {
  197068. MemoryBlock dropData;
  197069. for (;;)
  197070. {
  197071. Atom actual;
  197072. uint8* data = 0;
  197073. unsigned long count = 0, remaining = 0;
  197074. int format = 0;
  197075. ScopedXLock xlock;
  197076. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197077. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197078. &format, &count, &remaining, &data) == Success)
  197079. {
  197080. dropData.append (data, count * format / 8);
  197081. XFree (data);
  197082. if (remaining == 0)
  197083. break;
  197084. }
  197085. else
  197086. {
  197087. XFree (data);
  197088. break;
  197089. }
  197090. }
  197091. lines.addLines (dropData.toString());
  197092. }
  197093. for (int i = 0; i < lines.size(); ++i)
  197094. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  197095. dragAndDropFiles.trim();
  197096. dragAndDropFiles.removeEmptyStrings();
  197097. }
  197098. }
  197099. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197100. {
  197101. dragAndDropFiles.clear();
  197102. if (dragAndDropSourceWindow != None
  197103. && dragAndDropCurrentMimeType != 0)
  197104. {
  197105. dragAndDropTimestamp = clientMsg->data.l[2];
  197106. ScopedXLock xlock;
  197107. XConvertSelection (display,
  197108. Atoms::XdndSelection,
  197109. dragAndDropCurrentMimeType,
  197110. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197111. windowH,
  197112. dragAndDropTimestamp);
  197113. }
  197114. }
  197115. StringArray dragAndDropFiles;
  197116. int dragAndDropTimestamp;
  197117. Point<int> lastDropPos;
  197118. Atom dragAndDropCurrentMimeType;
  197119. Window dragAndDropSourceWindow;
  197120. Array <Atom> srcMimeTypeAtomList;
  197121. static int pointerMap[5];
  197122. static Point<int> lastMousePos;
  197123. static void clearLastMousePos() throw()
  197124. {
  197125. lastMousePos = Point<int> (0x100000, 0x100000);
  197126. }
  197127. };
  197128. ModifierKeys LinuxComponentPeer::currentModifiers;
  197129. bool LinuxComponentPeer::isActiveApplication = false;
  197130. int LinuxComponentPeer::pointerMap[5];
  197131. Point<int> LinuxComponentPeer::lastMousePos;
  197132. bool Process::isForegroundProcess()
  197133. {
  197134. return LinuxComponentPeer::isActiveApplication;
  197135. }
  197136. void ModifierKeys::updateCurrentModifiers() throw()
  197137. {
  197138. currentModifiers = LinuxComponentPeer::currentModifiers;
  197139. }
  197140. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197141. {
  197142. Window root, child;
  197143. int x, y, winx, winy;
  197144. unsigned int mask;
  197145. int mouseMods = 0;
  197146. ScopedXLock xlock;
  197147. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197148. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197149. {
  197150. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197151. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197152. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197153. }
  197154. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197155. return LinuxComponentPeer::currentModifiers;
  197156. }
  197157. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197158. {
  197159. if (enableOrDisable)
  197160. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197161. }
  197162. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197163. {
  197164. return new LinuxComponentPeer (this, styleFlags);
  197165. }
  197166. // (this callback is hooked up in the messaging code)
  197167. void juce_windowMessageReceive (XEvent* event)
  197168. {
  197169. if (event->xany.window != None)
  197170. {
  197171. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197172. if (ComponentPeer::isValidPeer (peer))
  197173. peer->handleWindowMessage (event);
  197174. }
  197175. else
  197176. {
  197177. switch (event->xany.type)
  197178. {
  197179. case KeymapNotify:
  197180. {
  197181. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197182. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197183. break;
  197184. }
  197185. default:
  197186. break;
  197187. }
  197188. }
  197189. }
  197190. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197191. {
  197192. if (display == 0)
  197193. return;
  197194. #if JUCE_USE_XINERAMA
  197195. int major_opcode, first_event, first_error;
  197196. ScopedXLock xlock;
  197197. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197198. {
  197199. typedef Bool (*tXineramaIsActive) (Display*);
  197200. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197201. static tXineramaIsActive xXineramaIsActive = 0;
  197202. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197203. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197204. {
  197205. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197206. if (h != 0)
  197207. {
  197208. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197209. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197210. }
  197211. }
  197212. if (xXineramaIsActive != 0
  197213. && xXineramaQueryScreens != 0
  197214. && xXineramaIsActive (display))
  197215. {
  197216. int numMonitors = 0;
  197217. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197218. if (screens != 0)
  197219. {
  197220. for (int i = numMonitors; --i >= 0;)
  197221. {
  197222. int index = screens[i].screen_number;
  197223. if (index >= 0)
  197224. {
  197225. while (monitorCoords.size() < index)
  197226. monitorCoords.add (Rectangle<int>());
  197227. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197228. screens[i].y_org,
  197229. screens[i].width,
  197230. screens[i].height));
  197231. }
  197232. }
  197233. XFree (screens);
  197234. }
  197235. }
  197236. }
  197237. if (monitorCoords.size() == 0)
  197238. #endif
  197239. {
  197240. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197241. if (hints != None)
  197242. {
  197243. const int numMonitors = ScreenCount (display);
  197244. for (int i = 0; i < numMonitors; ++i)
  197245. {
  197246. Window root = RootWindow (display, i);
  197247. unsigned long nitems, bytesLeft;
  197248. Atom actualType;
  197249. int actualFormat;
  197250. unsigned char* data = 0;
  197251. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197252. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197253. &data) == Success)
  197254. {
  197255. const long* const position = (const long*) data;
  197256. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197257. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197258. position[2], position[3]));
  197259. XFree (data);
  197260. }
  197261. }
  197262. }
  197263. if (monitorCoords.size() == 0)
  197264. {
  197265. monitorCoords.add (Rectangle<int> (0, 0,
  197266. DisplayWidth (display, DefaultScreen (display)),
  197267. DisplayHeight (display, DefaultScreen (display))));
  197268. }
  197269. }
  197270. }
  197271. void Desktop::createMouseInputSources()
  197272. {
  197273. mouseSources.add (new MouseInputSource (0, true));
  197274. }
  197275. bool Desktop::canUseSemiTransparentWindows() throw()
  197276. {
  197277. int matchedDepth = 0;
  197278. const int desiredDepth = 32;
  197279. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197280. && (matchedDepth == desiredDepth);
  197281. }
  197282. const Point<int> Desktop::getMousePosition()
  197283. {
  197284. Window root, child;
  197285. int x, y, winx, winy;
  197286. unsigned int mask;
  197287. ScopedXLock xlock;
  197288. if (XQueryPointer (display,
  197289. RootWindow (display, DefaultScreen (display)),
  197290. &root, &child,
  197291. &x, &y, &winx, &winy, &mask) == False)
  197292. {
  197293. // Pointer not on the default screen
  197294. x = y = -1;
  197295. }
  197296. return Point<int> (x, y);
  197297. }
  197298. void Desktop::setMousePosition (const Point<int>& newPosition)
  197299. {
  197300. ScopedXLock xlock;
  197301. Window root = RootWindow (display, DefaultScreen (display));
  197302. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197303. }
  197304. static bool screenSaverAllowed = true;
  197305. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197306. {
  197307. if (screenSaverAllowed != isEnabled)
  197308. {
  197309. screenSaverAllowed = isEnabled;
  197310. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197311. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197312. if (xScreenSaverSuspend == 0)
  197313. {
  197314. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197315. if (h != 0)
  197316. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197317. }
  197318. ScopedXLock xlock;
  197319. if (xScreenSaverSuspend != 0)
  197320. xScreenSaverSuspend (display, ! isEnabled);
  197321. }
  197322. }
  197323. bool Desktop::isScreenSaverEnabled() throw()
  197324. {
  197325. return screenSaverAllowed;
  197326. }
  197327. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  197328. {
  197329. ScopedXLock xlock;
  197330. const unsigned int imageW = image.getWidth();
  197331. const unsigned int imageH = image.getHeight();
  197332. #if JUCE_USE_XCURSOR
  197333. {
  197334. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  197335. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  197336. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  197337. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  197338. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  197339. static tXcursorImageCreate xXcursorImageCreate = 0;
  197340. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  197341. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  197342. static bool hasBeenLoaded = false;
  197343. if (! hasBeenLoaded)
  197344. {
  197345. hasBeenLoaded = true;
  197346. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  197347. if (h != 0)
  197348. {
  197349. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  197350. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  197351. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  197352. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  197353. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  197354. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  197355. || ! xXcursorSupportsARGB (display))
  197356. xXcursorSupportsARGB = 0;
  197357. }
  197358. }
  197359. if (xXcursorSupportsARGB != 0)
  197360. {
  197361. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  197362. if (xcImage != 0)
  197363. {
  197364. xcImage->xhot = hotspotX;
  197365. xcImage->yhot = hotspotY;
  197366. XcursorPixel* dest = xcImage->pixels;
  197367. for (int y = 0; y < (int) imageH; ++y)
  197368. for (int x = 0; x < (int) imageW; ++x)
  197369. *dest++ = image.getPixelAt (x, y).getARGB();
  197370. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  197371. xXcursorImageDestroy (xcImage);
  197372. if (result != 0)
  197373. return result;
  197374. }
  197375. }
  197376. }
  197377. #endif
  197378. Window root = RootWindow (display, DefaultScreen (display));
  197379. unsigned int cursorW, cursorH;
  197380. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197381. return 0;
  197382. Image im (Image::ARGB, cursorW, cursorH, true);
  197383. {
  197384. Graphics g (im);
  197385. if (imageW > cursorW || imageH > cursorH)
  197386. {
  197387. hotspotX = (hotspotX * cursorW) / imageW;
  197388. hotspotY = (hotspotY * cursorH) / imageH;
  197389. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197390. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197391. false);
  197392. }
  197393. else
  197394. {
  197395. g.drawImageAt (&image, 0, 0);
  197396. }
  197397. }
  197398. const int stride = (cursorW + 7) >> 3;
  197399. HeapBlock <char> maskPlane, sourcePlane;
  197400. maskPlane.calloc (stride * cursorH);
  197401. sourcePlane.calloc (stride * cursorH);
  197402. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197403. for (int y = cursorH; --y >= 0;)
  197404. {
  197405. for (int x = cursorW; --x >= 0;)
  197406. {
  197407. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197408. const int offset = y * stride + (x >> 3);
  197409. const Colour c (im.getPixelAt (x, y));
  197410. if (c.getAlpha() >= 128)
  197411. maskPlane[offset] |= mask;
  197412. if (c.getBrightness() >= 0.5f)
  197413. sourcePlane[offset] |= mask;
  197414. }
  197415. }
  197416. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197417. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197418. XColor white, black;
  197419. black.red = black.green = black.blue = 0;
  197420. white.red = white.green = white.blue = 0xffff;
  197421. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197422. XFreePixmap (display, sourcePixmap);
  197423. XFreePixmap (display, maskPixmap);
  197424. return result;
  197425. }
  197426. void juce_deleteMouseCursor (void* const cursorHandle, const bool)
  197427. {
  197428. ScopedXLock xlock;
  197429. if (cursorHandle != 0)
  197430. XFreeCursor (display, (Cursor) cursorHandle);
  197431. }
  197432. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  197433. {
  197434. unsigned int shape;
  197435. switch (type)
  197436. {
  197437. case MouseCursor::NoCursor:
  197438. {
  197439. const Image im (Image::ARGB, 16, 16, true);
  197440. return juce_createMouseCursorFromImage (im, 0, 0);
  197441. }
  197442. case MouseCursor::NormalCursor:
  197443. return (void*) None; // Use parent cursor
  197444. case MouseCursor::DraggingHandCursor:
  197445. {
  197446. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197447. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197448. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197449. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197450. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197451. const int dragHandDataSize = 99;
  197452. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197453. return juce_createMouseCursorFromImage (*im, 8, 7);
  197454. }
  197455. case MouseCursor::CopyingCursor:
  197456. {
  197457. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197458. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197459. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197460. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197461. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197462. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197463. const int copyCursorSize = 119;
  197464. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197465. return juce_createMouseCursorFromImage (*im, 1, 3);
  197466. }
  197467. case MouseCursor::WaitCursor:
  197468. shape = XC_watch;
  197469. break;
  197470. case MouseCursor::IBeamCursor:
  197471. shape = XC_xterm;
  197472. break;
  197473. case MouseCursor::PointingHandCursor:
  197474. shape = XC_hand2;
  197475. break;
  197476. case MouseCursor::LeftRightResizeCursor:
  197477. shape = XC_sb_h_double_arrow;
  197478. break;
  197479. case MouseCursor::UpDownResizeCursor:
  197480. shape = XC_sb_v_double_arrow;
  197481. break;
  197482. case MouseCursor::UpDownLeftRightResizeCursor:
  197483. shape = XC_fleur;
  197484. break;
  197485. case MouseCursor::TopEdgeResizeCursor:
  197486. shape = XC_top_side;
  197487. break;
  197488. case MouseCursor::BottomEdgeResizeCursor:
  197489. shape = XC_bottom_side;
  197490. break;
  197491. case MouseCursor::LeftEdgeResizeCursor:
  197492. shape = XC_left_side;
  197493. break;
  197494. case MouseCursor::RightEdgeResizeCursor:
  197495. shape = XC_right_side;
  197496. break;
  197497. case MouseCursor::TopLeftCornerResizeCursor:
  197498. shape = XC_top_left_corner;
  197499. break;
  197500. case MouseCursor::TopRightCornerResizeCursor:
  197501. shape = XC_top_right_corner;
  197502. break;
  197503. case MouseCursor::BottomLeftCornerResizeCursor:
  197504. shape = XC_bottom_left_corner;
  197505. break;
  197506. case MouseCursor::BottomRightCornerResizeCursor:
  197507. shape = XC_bottom_right_corner;
  197508. break;
  197509. case MouseCursor::CrosshairCursor:
  197510. shape = XC_crosshair;
  197511. break;
  197512. default:
  197513. return (void*) None; // Use parent cursor
  197514. }
  197515. ScopedXLock xlock;
  197516. return (void*) XCreateFontCursor (display, shape);
  197517. }
  197518. void MouseCursor::showInWindow (ComponentPeer* peer) const
  197519. {
  197520. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197521. if (lp != 0)
  197522. lp->showMouseCursor ((Cursor) getHandle());
  197523. }
  197524. void MouseCursor::showInAllWindows() const
  197525. {
  197526. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197527. showInWindow (ComponentPeer::getPeer (i));
  197528. }
  197529. Image* juce_createIconForFile (const File& file)
  197530. {
  197531. return 0;
  197532. }
  197533. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197534. {
  197535. return new Image (format, imageWidth, imageHeight, clearImage);
  197536. }
  197537. #if JUCE_OPENGL
  197538. class WindowedGLContext : public OpenGLContext
  197539. {
  197540. public:
  197541. WindowedGLContext (Component* const component,
  197542. const OpenGLPixelFormat& pixelFormat_,
  197543. GLXContext sharedContext)
  197544. : renderContext (0),
  197545. embeddedWindow (0),
  197546. pixelFormat (pixelFormat_)
  197547. {
  197548. jassert (component != 0);
  197549. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197550. if (peer == 0)
  197551. return;
  197552. ScopedXLock xlock;
  197553. XSync (display, False);
  197554. GLint attribs [64];
  197555. int n = 0;
  197556. attribs[n++] = GLX_RGBA;
  197557. attribs[n++] = GLX_DOUBLEBUFFER;
  197558. attribs[n++] = GLX_RED_SIZE;
  197559. attribs[n++] = pixelFormat.redBits;
  197560. attribs[n++] = GLX_GREEN_SIZE;
  197561. attribs[n++] = pixelFormat.greenBits;
  197562. attribs[n++] = GLX_BLUE_SIZE;
  197563. attribs[n++] = pixelFormat.blueBits;
  197564. attribs[n++] = GLX_ALPHA_SIZE;
  197565. attribs[n++] = pixelFormat.alphaBits;
  197566. attribs[n++] = GLX_DEPTH_SIZE;
  197567. attribs[n++] = pixelFormat.depthBufferBits;
  197568. attribs[n++] = GLX_STENCIL_SIZE;
  197569. attribs[n++] = pixelFormat.stencilBufferBits;
  197570. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197571. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197572. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197573. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197574. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197575. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197576. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197577. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197578. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197579. attribs[n++] = None;
  197580. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197581. if (bestVisual == 0)
  197582. return;
  197583. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197584. Window windowH = (Window) peer->getNativeHandle();
  197585. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197586. XSetWindowAttributes swa;
  197587. swa.colormap = colourMap;
  197588. swa.border_pixel = 0;
  197589. swa.event_mask = ExposureMask | StructureNotifyMask;
  197590. embeddedWindow = XCreateWindow (display, windowH,
  197591. 0, 0, 1, 1, 0,
  197592. bestVisual->depth,
  197593. InputOutput,
  197594. bestVisual->visual,
  197595. CWBorderPixel | CWColormap | CWEventMask,
  197596. &swa);
  197597. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197598. XMapWindow (display, embeddedWindow);
  197599. XFreeColormap (display, colourMap);
  197600. XFree (bestVisual);
  197601. XSync (display, False);
  197602. }
  197603. ~WindowedGLContext()
  197604. {
  197605. makeInactive();
  197606. ScopedXLock xlock;
  197607. glXDestroyContext (display, renderContext);
  197608. XUnmapWindow (display, embeddedWindow);
  197609. XDestroyWindow (display, embeddedWindow);
  197610. }
  197611. bool makeActive() const throw()
  197612. {
  197613. jassert (renderContext != 0);
  197614. ScopedXLock xlock;
  197615. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197616. && XSync (display, False);
  197617. }
  197618. bool makeInactive() const throw()
  197619. {
  197620. ScopedXLock xlock;
  197621. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197622. }
  197623. bool isActive() const throw()
  197624. {
  197625. ScopedXLock xlock;
  197626. return glXGetCurrentContext() == renderContext;
  197627. }
  197628. const OpenGLPixelFormat getPixelFormat() const
  197629. {
  197630. return pixelFormat;
  197631. }
  197632. void* getRawContext() const throw()
  197633. {
  197634. return renderContext;
  197635. }
  197636. void updateWindowPosition (int x, int y, int w, int h, int)
  197637. {
  197638. ScopedXLock xlock;
  197639. XMoveResizeWindow (display, embeddedWindow,
  197640. x, y, jmax (1, w), jmax (1, h));
  197641. }
  197642. void swapBuffers()
  197643. {
  197644. ScopedXLock xlock;
  197645. glXSwapBuffers (display, embeddedWindow);
  197646. }
  197647. bool setSwapInterval (const int numFramesPerSwap)
  197648. {
  197649. // xxx needs doing..
  197650. return false;
  197651. }
  197652. int getSwapInterval() const
  197653. {
  197654. // xxx needs doing..
  197655. return 0;
  197656. }
  197657. void repaint()
  197658. {
  197659. }
  197660. juce_UseDebuggingNewOperator
  197661. GLXContext renderContext;
  197662. private:
  197663. Window embeddedWindow;
  197664. OpenGLPixelFormat pixelFormat;
  197665. WindowedGLContext (const WindowedGLContext&);
  197666. WindowedGLContext& operator= (const WindowedGLContext&);
  197667. };
  197668. OpenGLContext* OpenGLComponent::createContext()
  197669. {
  197670. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197671. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197672. return (c->renderContext != 0) ? c.release() : 0;
  197673. }
  197674. void juce_glViewport (const int w, const int h)
  197675. {
  197676. glViewport (0, 0, w, h);
  197677. }
  197678. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197679. OwnedArray <OpenGLPixelFormat>& results)
  197680. {
  197681. results.add (new OpenGLPixelFormat()); // xxx
  197682. }
  197683. #endif
  197684. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197685. {
  197686. jassertfalse // not implemented!
  197687. return false;
  197688. }
  197689. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197690. {
  197691. jassertfalse // not implemented!
  197692. return false;
  197693. }
  197694. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197695. {
  197696. if (! isOnDesktop ())
  197697. addToDesktop (0);
  197698. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197699. if (wp != 0)
  197700. {
  197701. wp->setTaskBarIcon (newImage);
  197702. setVisible (true);
  197703. toFront (false);
  197704. repaint();
  197705. }
  197706. }
  197707. void SystemTrayIconComponent::paint (Graphics& g)
  197708. {
  197709. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197710. if (wp != 0)
  197711. {
  197712. const Image* const image = wp->getTaskbarIcon();
  197713. if (image != 0)
  197714. {
  197715. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197716. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197717. false);
  197718. }
  197719. }
  197720. }
  197721. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197722. {
  197723. // xxx not yet implemented!
  197724. }
  197725. void PlatformUtilities::beep()
  197726. {
  197727. std::cout << "\a" << std::flush;
  197728. }
  197729. bool AlertWindow::showNativeDialogBox (const String& title,
  197730. const String& bodyText,
  197731. bool isOkCancel)
  197732. {
  197733. // use a non-native one for the time being..
  197734. if (isOkCancel)
  197735. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197736. else
  197737. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197738. return true;
  197739. }
  197740. const int KeyPress::spaceKey = XK_space & 0xff;
  197741. const int KeyPress::returnKey = XK_Return & 0xff;
  197742. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197743. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197744. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197745. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197746. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197747. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197748. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197749. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197750. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197751. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197752. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197753. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197754. const int KeyPress::tabKey = XK_Tab & 0xff;
  197755. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197756. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197757. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197758. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197759. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197760. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197761. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197762. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197763. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197764. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197765. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197766. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197767. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197768. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197769. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197770. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197771. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197772. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197773. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197774. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197775. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197776. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197777. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197778. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197779. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197780. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197781. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197782. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197783. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197784. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197785. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197786. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197787. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197788. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197789. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197790. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197791. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197792. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197793. #endif
  197794. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197795. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197796. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197797. // compiled on its own).
  197798. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197799. static const int maxNumChans = 64;
  197800. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197801. {
  197802. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197803. snd_pcm_hw_params_t* hwParams;
  197804. snd_pcm_hw_params_alloca (&hwParams);
  197805. for (int i = 0; ratesToTry[i] != 0; ++i)
  197806. {
  197807. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197808. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197809. {
  197810. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197811. }
  197812. }
  197813. }
  197814. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197815. {
  197816. snd_pcm_hw_params_t *params;
  197817. snd_pcm_hw_params_alloca (&params);
  197818. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197819. {
  197820. snd_pcm_hw_params_get_channels_min (params, minChans);
  197821. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197822. }
  197823. }
  197824. static void getDeviceProperties (const String& deviceID,
  197825. unsigned int& minChansOut,
  197826. unsigned int& maxChansOut,
  197827. unsigned int& minChansIn,
  197828. unsigned int& maxChansIn,
  197829. Array <int>& rates)
  197830. {
  197831. if (deviceID.isEmpty())
  197832. return;
  197833. snd_ctl_t* handle;
  197834. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197835. {
  197836. snd_pcm_info_t* info;
  197837. snd_pcm_info_alloca (&info);
  197838. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197839. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197840. snd_pcm_info_set_subdevice (info, 0);
  197841. if (snd_ctl_pcm_info (handle, info) >= 0)
  197842. {
  197843. snd_pcm_t* pcmHandle;
  197844. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197845. {
  197846. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197847. getDeviceSampleRates (pcmHandle, rates);
  197848. snd_pcm_close (pcmHandle);
  197849. }
  197850. }
  197851. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197852. if (snd_ctl_pcm_info (handle, info) >= 0)
  197853. {
  197854. snd_pcm_t* pcmHandle;
  197855. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197856. {
  197857. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197858. if (rates.size() == 0)
  197859. getDeviceSampleRates (pcmHandle, rates);
  197860. snd_pcm_close (pcmHandle);
  197861. }
  197862. }
  197863. snd_ctl_close (handle);
  197864. }
  197865. }
  197866. class ALSADevice
  197867. {
  197868. public:
  197869. ALSADevice (const String& deviceID,
  197870. const bool forInput)
  197871. : handle (0),
  197872. bitDepth (16),
  197873. numChannelsRunning (0),
  197874. isInput (forInput),
  197875. sampleFormat (AudioDataConverters::int16LE)
  197876. {
  197877. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197878. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197879. SND_PCM_ASYNC));
  197880. }
  197881. ~ALSADevice()
  197882. {
  197883. if (handle != 0)
  197884. snd_pcm_close (handle);
  197885. }
  197886. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197887. {
  197888. if (handle == 0)
  197889. return false;
  197890. snd_pcm_hw_params_t* hwParams;
  197891. snd_pcm_hw_params_alloca (&hwParams);
  197892. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197893. return false;
  197894. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197895. isInterleaved = false;
  197896. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197897. isInterleaved = true;
  197898. else
  197899. {
  197900. jassertfalse
  197901. return false;
  197902. }
  197903. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197904. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197905. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197906. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197907. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197908. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197909. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197910. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197911. bitDepth = 0;
  197912. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197913. {
  197914. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197915. {
  197916. bitDepth = formatsToTry [i + 1];
  197917. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197918. break;
  197919. }
  197920. }
  197921. if (bitDepth == 0)
  197922. {
  197923. error = "device doesn't support a compatible PCM format";
  197924. DBG ("ALSA error: " + error + "\n");
  197925. return false;
  197926. }
  197927. int dir = 0;
  197928. unsigned int periods = 4;
  197929. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197930. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197931. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197932. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197933. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197934. || failed (snd_pcm_hw_params (handle, hwParams)))
  197935. {
  197936. return false;
  197937. }
  197938. snd_pcm_sw_params_t* swParams;
  197939. snd_pcm_sw_params_alloca (&swParams);
  197940. snd_pcm_uframes_t boundary;
  197941. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197942. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197943. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197944. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197945. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197946. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197947. || failed (snd_pcm_sw_params (handle, swParams)))
  197948. {
  197949. return false;
  197950. }
  197951. numChannelsRunning = numChannels;
  197952. return true;
  197953. }
  197954. bool write (float** const data, const int numSamples)
  197955. {
  197956. if (isInterleaved)
  197957. {
  197958. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197959. float* interleaved = static_cast <float*> (scratch.getData());
  197960. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197961. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197962. snd_pcm_sframes_t num = snd_pcm_writei (handle, interleaved, numSamples);
  197963. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197964. return false;
  197965. }
  197966. else
  197967. {
  197968. for (int i = 0; i < numChannelsRunning; ++i)
  197969. if (data[i] != 0)
  197970. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197971. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197972. if (failed (num))
  197973. {
  197974. if (num == -EPIPE)
  197975. {
  197976. if (failed (snd_pcm_prepare (handle)))
  197977. return false;
  197978. }
  197979. else if (num != -ESTRPIPE)
  197980. return false;
  197981. }
  197982. }
  197983. return true;
  197984. }
  197985. bool read (float** const data, const int numSamples)
  197986. {
  197987. if (isInterleaved)
  197988. {
  197989. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197990. float* interleaved = static_cast <float*> (scratch.getData());
  197991. snd_pcm_sframes_t num = snd_pcm_readi (handle, interleaved, numSamples);
  197992. if (failed (num))
  197993. {
  197994. if (num == -EPIPE)
  197995. {
  197996. if (failed (snd_pcm_prepare (handle)))
  197997. return false;
  197998. }
  197999. else if (num != -ESTRPIPE)
  198000. return false;
  198001. }
  198002. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198003. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198004. }
  198005. else
  198006. {
  198007. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198008. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198009. return false;
  198010. for (int i = 0; i < numChannelsRunning; ++i)
  198011. if (data[i] != 0)
  198012. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198013. }
  198014. return true;
  198015. }
  198016. juce_UseDebuggingNewOperator
  198017. snd_pcm_t* handle;
  198018. String error;
  198019. int bitDepth, numChannelsRunning;
  198020. private:
  198021. const bool isInput;
  198022. bool isInterleaved;
  198023. MemoryBlock scratch;
  198024. AudioDataConverters::DataFormat sampleFormat;
  198025. bool failed (const int errorNum)
  198026. {
  198027. if (errorNum >= 0)
  198028. return false;
  198029. error = snd_strerror (errorNum);
  198030. DBG ("ALSA error: " + error + "\n");
  198031. return true;
  198032. }
  198033. };
  198034. class ALSAThread : public Thread
  198035. {
  198036. public:
  198037. ALSAThread (const String& inputId_,
  198038. const String& outputId_)
  198039. : Thread ("Juce ALSA"),
  198040. sampleRate (0),
  198041. bufferSize (0),
  198042. callback (0),
  198043. inputId (inputId_),
  198044. outputId (outputId_),
  198045. outputDevice (0),
  198046. inputDevice (0),
  198047. numCallbacks (0),
  198048. totalNumInputChannels (0),
  198049. totalNumOutputChannels (0)
  198050. {
  198051. zeromem (outputChannelData, sizeof (outputChannelData));
  198052. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198053. zeromem (inputChannelData, sizeof (inputChannelData));
  198054. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198055. initialiseRatesAndChannels();
  198056. }
  198057. ~ALSAThread()
  198058. {
  198059. close();
  198060. }
  198061. void open (BigInteger inputChannels,
  198062. BigInteger outputChannels,
  198063. const double sampleRate_,
  198064. const int bufferSize_)
  198065. {
  198066. close();
  198067. error = String::empty;
  198068. sampleRate = sampleRate_;
  198069. bufferSize = bufferSize_;
  198070. currentInputChans.clear();
  198071. currentOutputChans.clear();
  198072. if (inputChannels.getHighestBit() >= 0)
  198073. {
  198074. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198075. {
  198076. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198077. if (inputChannels[i])
  198078. {
  198079. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198080. currentInputChans.setBit (i);
  198081. }
  198082. }
  198083. }
  198084. if (outputChannels.getHighestBit() >= 0)
  198085. {
  198086. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198087. {
  198088. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198089. if (outputChannels[i])
  198090. {
  198091. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198092. currentOutputChans.setBit (i);
  198093. }
  198094. }
  198095. }
  198096. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198097. {
  198098. outputDevice = new ALSADevice (outputId, false);
  198099. if (outputDevice->error.isNotEmpty())
  198100. {
  198101. error = outputDevice->error;
  198102. deleteAndZero (outputDevice);
  198103. return;
  198104. }
  198105. currentOutputChans.setRange (0, minChansOut, true);
  198106. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198107. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198108. bufferSize))
  198109. {
  198110. error = outputDevice->error;
  198111. deleteAndZero (outputDevice);
  198112. return;
  198113. }
  198114. }
  198115. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198116. {
  198117. inputDevice = new ALSADevice (inputId, true);
  198118. if (inputDevice->error.isNotEmpty())
  198119. {
  198120. error = inputDevice->error;
  198121. deleteAndZero (inputDevice);
  198122. return;
  198123. }
  198124. currentInputChans.setRange (0, minChansIn, true);
  198125. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198126. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198127. bufferSize))
  198128. {
  198129. error = inputDevice->error;
  198130. deleteAndZero (inputDevice);
  198131. return;
  198132. }
  198133. }
  198134. if (outputDevice == 0 && inputDevice == 0)
  198135. {
  198136. error = "no channels";
  198137. return;
  198138. }
  198139. if (outputDevice != 0 && inputDevice != 0)
  198140. {
  198141. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198142. }
  198143. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198144. return;
  198145. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198146. return;
  198147. startThread (9);
  198148. int count = 1000;
  198149. while (numCallbacks == 0)
  198150. {
  198151. sleep (5);
  198152. if (--count < 0 || ! isThreadRunning())
  198153. {
  198154. error = "device didn't start";
  198155. break;
  198156. }
  198157. }
  198158. }
  198159. void close()
  198160. {
  198161. stopThread (6000);
  198162. deleteAndZero (inputDevice);
  198163. deleteAndZero (outputDevice);
  198164. for (int i = 0; i < maxNumChans; ++i)
  198165. {
  198166. juce_free (inputChannelData [i]);
  198167. juce_free (outputChannelData [i]);
  198168. }
  198169. zeromem (outputChannelData, sizeof (outputChannelData));
  198170. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198171. zeromem (inputChannelData, sizeof (inputChannelData));
  198172. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198173. totalNumOutputChannels = 0;
  198174. totalNumInputChannels = 0;
  198175. numCallbacks = 0;
  198176. }
  198177. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198178. {
  198179. const ScopedLock sl (callbackLock);
  198180. callback = newCallback;
  198181. }
  198182. void run()
  198183. {
  198184. while (! threadShouldExit())
  198185. {
  198186. if (inputDevice != 0)
  198187. {
  198188. if (! inputDevice->read (inputChannelData, bufferSize))
  198189. {
  198190. DBG ("ALSA: read failure");
  198191. break;
  198192. }
  198193. }
  198194. if (threadShouldExit())
  198195. break;
  198196. {
  198197. const ScopedLock sl (callbackLock);
  198198. ++numCallbacks;
  198199. if (callback != 0)
  198200. {
  198201. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198202. totalNumInputChannels,
  198203. outputChannelDataForCallback,
  198204. totalNumOutputChannels,
  198205. bufferSize);
  198206. }
  198207. else
  198208. {
  198209. for (int i = 0; i < totalNumOutputChannels; ++i)
  198210. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198211. }
  198212. }
  198213. if (outputDevice != 0)
  198214. {
  198215. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198216. if (threadShouldExit())
  198217. break;
  198218. failed (snd_pcm_avail_update (outputDevice->handle));
  198219. if (! outputDevice->write (outputChannelData, bufferSize))
  198220. {
  198221. DBG ("ALSA: write failure");
  198222. break;
  198223. }
  198224. }
  198225. }
  198226. }
  198227. int getBitDepth() const throw()
  198228. {
  198229. if (outputDevice != 0)
  198230. return outputDevice->bitDepth;
  198231. if (inputDevice != 0)
  198232. return inputDevice->bitDepth;
  198233. return 16;
  198234. }
  198235. juce_UseDebuggingNewOperator
  198236. String error;
  198237. double sampleRate;
  198238. int bufferSize;
  198239. BigInteger currentInputChans, currentOutputChans;
  198240. Array <int> sampleRates;
  198241. StringArray channelNamesOut, channelNamesIn;
  198242. AudioIODeviceCallback* callback;
  198243. private:
  198244. const String inputId, outputId;
  198245. ALSADevice* outputDevice;
  198246. ALSADevice* inputDevice;
  198247. int numCallbacks;
  198248. CriticalSection callbackLock;
  198249. float* outputChannelData [maxNumChans];
  198250. float* outputChannelDataForCallback [maxNumChans];
  198251. int totalNumInputChannels;
  198252. float* inputChannelData [maxNumChans];
  198253. float* inputChannelDataForCallback [maxNumChans];
  198254. int totalNumOutputChannels;
  198255. unsigned int minChansOut, maxChansOut;
  198256. unsigned int minChansIn, maxChansIn;
  198257. bool failed (const int errorNum) throw()
  198258. {
  198259. if (errorNum >= 0)
  198260. return false;
  198261. error = snd_strerror (errorNum);
  198262. DBG ("ALSA error: " + error + "\n");
  198263. return true;
  198264. }
  198265. void initialiseRatesAndChannels() throw()
  198266. {
  198267. sampleRates.clear();
  198268. channelNamesOut.clear();
  198269. channelNamesIn.clear();
  198270. minChansOut = 0;
  198271. maxChansOut = 0;
  198272. minChansIn = 0;
  198273. maxChansIn = 0;
  198274. unsigned int dummy = 0;
  198275. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198276. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198277. unsigned int i;
  198278. for (i = 0; i < maxChansOut; ++i)
  198279. channelNamesOut.add ("channel " + String ((int) i + 1));
  198280. for (i = 0; i < maxChansIn; ++i)
  198281. channelNamesIn.add ("channel " + String ((int) i + 1));
  198282. }
  198283. };
  198284. class ALSAAudioIODevice : public AudioIODevice
  198285. {
  198286. public:
  198287. ALSAAudioIODevice (const String& deviceName,
  198288. const String& inputId_,
  198289. const String& outputId_)
  198290. : AudioIODevice (deviceName, "ALSA"),
  198291. inputId (inputId_),
  198292. outputId (outputId_),
  198293. isOpen_ (false),
  198294. isStarted (false),
  198295. internal (0)
  198296. {
  198297. internal = new ALSAThread (inputId, outputId);
  198298. }
  198299. ~ALSAAudioIODevice()
  198300. {
  198301. delete internal;
  198302. }
  198303. const StringArray getOutputChannelNames()
  198304. {
  198305. return internal->channelNamesOut;
  198306. }
  198307. const StringArray getInputChannelNames()
  198308. {
  198309. return internal->channelNamesIn;
  198310. }
  198311. int getNumSampleRates()
  198312. {
  198313. return internal->sampleRates.size();
  198314. }
  198315. double getSampleRate (int index)
  198316. {
  198317. return internal->sampleRates [index];
  198318. }
  198319. int getNumBufferSizesAvailable()
  198320. {
  198321. return 50;
  198322. }
  198323. int getBufferSizeSamples (int index)
  198324. {
  198325. int n = 16;
  198326. for (int i = 0; i < index; ++i)
  198327. n += n < 64 ? 16
  198328. : (n < 512 ? 32
  198329. : (n < 1024 ? 64
  198330. : (n < 2048 ? 128 : 256)));
  198331. return n;
  198332. }
  198333. int getDefaultBufferSize()
  198334. {
  198335. return 512;
  198336. }
  198337. const String open (const BigInteger& inputChannels,
  198338. const BigInteger& outputChannels,
  198339. double sampleRate,
  198340. int bufferSizeSamples)
  198341. {
  198342. close();
  198343. if (bufferSizeSamples <= 0)
  198344. bufferSizeSamples = getDefaultBufferSize();
  198345. if (sampleRate <= 0)
  198346. {
  198347. for (int i = 0; i < getNumSampleRates(); ++i)
  198348. {
  198349. if (getSampleRate (i) >= 44100)
  198350. {
  198351. sampleRate = getSampleRate (i);
  198352. break;
  198353. }
  198354. }
  198355. }
  198356. internal->open (inputChannels, outputChannels,
  198357. sampleRate, bufferSizeSamples);
  198358. isOpen_ = internal->error.isEmpty();
  198359. return internal->error;
  198360. }
  198361. void close()
  198362. {
  198363. stop();
  198364. internal->close();
  198365. isOpen_ = false;
  198366. }
  198367. bool isOpen()
  198368. {
  198369. return isOpen_;
  198370. }
  198371. int getCurrentBufferSizeSamples()
  198372. {
  198373. return internal->bufferSize;
  198374. }
  198375. double getCurrentSampleRate()
  198376. {
  198377. return internal->sampleRate;
  198378. }
  198379. int getCurrentBitDepth()
  198380. {
  198381. return internal->getBitDepth();
  198382. }
  198383. const BigInteger getActiveOutputChannels() const
  198384. {
  198385. return internal->currentOutputChans;
  198386. }
  198387. const BigInteger getActiveInputChannels() const
  198388. {
  198389. return internal->currentInputChans;
  198390. }
  198391. int getOutputLatencyInSamples()
  198392. {
  198393. return 0;
  198394. }
  198395. int getInputLatencyInSamples()
  198396. {
  198397. return 0;
  198398. }
  198399. void start (AudioIODeviceCallback* callback)
  198400. {
  198401. if (! isOpen_)
  198402. callback = 0;
  198403. internal->setCallback (callback);
  198404. if (callback != 0)
  198405. callback->audioDeviceAboutToStart (this);
  198406. isStarted = (callback != 0);
  198407. }
  198408. void stop()
  198409. {
  198410. AudioIODeviceCallback* const oldCallback = internal->callback;
  198411. start (0);
  198412. if (oldCallback != 0)
  198413. oldCallback->audioDeviceStopped();
  198414. }
  198415. bool isPlaying()
  198416. {
  198417. return isStarted && internal->error.isEmpty();
  198418. }
  198419. const String getLastError()
  198420. {
  198421. return internal->error;
  198422. }
  198423. String inputId, outputId;
  198424. private:
  198425. bool isOpen_, isStarted;
  198426. ALSAThread* internal;
  198427. };
  198428. class ALSAAudioIODeviceType : public AudioIODeviceType
  198429. {
  198430. public:
  198431. ALSAAudioIODeviceType()
  198432. : AudioIODeviceType ("ALSA"),
  198433. hasScanned (false)
  198434. {
  198435. }
  198436. ~ALSAAudioIODeviceType()
  198437. {
  198438. }
  198439. void scanForDevices()
  198440. {
  198441. if (hasScanned)
  198442. return;
  198443. hasScanned = true;
  198444. inputNames.clear();
  198445. inputIds.clear();
  198446. outputNames.clear();
  198447. outputIds.clear();
  198448. snd_ctl_t* handle;
  198449. snd_ctl_card_info_t* info;
  198450. snd_ctl_card_info_alloca (&info);
  198451. int cardNum = -1;
  198452. while (outputIds.size() + inputIds.size() <= 32)
  198453. {
  198454. snd_card_next (&cardNum);
  198455. if (cardNum < 0)
  198456. break;
  198457. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198458. {
  198459. if (snd_ctl_card_info (handle, info) >= 0)
  198460. {
  198461. String cardId (snd_ctl_card_info_get_id (info));
  198462. if (cardId.removeCharacters ("0123456789").isEmpty())
  198463. cardId = String (cardNum);
  198464. int device = -1;
  198465. for (;;)
  198466. {
  198467. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198468. break;
  198469. String id, name;
  198470. id << "hw:" << cardId << ',' << device;
  198471. bool isInput, isOutput;
  198472. if (testDevice (id, isInput, isOutput))
  198473. {
  198474. name << snd_ctl_card_info_get_name (info);
  198475. if (name.isEmpty())
  198476. name = id;
  198477. if (isInput)
  198478. {
  198479. inputNames.add (name);
  198480. inputIds.add (id);
  198481. }
  198482. if (isOutput)
  198483. {
  198484. outputNames.add (name);
  198485. outputIds.add (id);
  198486. }
  198487. }
  198488. }
  198489. }
  198490. snd_ctl_close (handle);
  198491. }
  198492. }
  198493. inputNames.appendNumbersToDuplicates (false, true);
  198494. outputNames.appendNumbersToDuplicates (false, true);
  198495. }
  198496. const StringArray getDeviceNames (bool wantInputNames) const
  198497. {
  198498. jassert (hasScanned); // need to call scanForDevices() before doing this
  198499. return wantInputNames ? inputNames : outputNames;
  198500. }
  198501. int getDefaultDeviceIndex (bool forInput) const
  198502. {
  198503. jassert (hasScanned); // need to call scanForDevices() before doing this
  198504. return 0;
  198505. }
  198506. bool hasSeparateInputsAndOutputs() const { return true; }
  198507. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198508. {
  198509. jassert (hasScanned); // need to call scanForDevices() before doing this
  198510. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198511. if (d == 0)
  198512. return -1;
  198513. return asInput ? inputIds.indexOf (d->inputId)
  198514. : outputIds.indexOf (d->outputId);
  198515. }
  198516. AudioIODevice* createDevice (const String& outputDeviceName,
  198517. const String& inputDeviceName)
  198518. {
  198519. jassert (hasScanned); // need to call scanForDevices() before doing this
  198520. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198521. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198522. String deviceName (outputIndex >= 0 ? outputDeviceName
  198523. : inputDeviceName);
  198524. if (inputIndex >= 0 || outputIndex >= 0)
  198525. return new ALSAAudioIODevice (deviceName,
  198526. inputIds [inputIndex],
  198527. outputIds [outputIndex]);
  198528. return 0;
  198529. }
  198530. juce_UseDebuggingNewOperator
  198531. private:
  198532. StringArray inputNames, outputNames, inputIds, outputIds;
  198533. bool hasScanned;
  198534. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198535. {
  198536. unsigned int minChansOut = 0, maxChansOut = 0;
  198537. unsigned int minChansIn = 0, maxChansIn = 0;
  198538. Array <int> rates;
  198539. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198540. DBG ("ALSA device: " + id
  198541. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198542. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198543. + " rates=" + String (rates.size()));
  198544. isInput = maxChansIn > 0;
  198545. isOutput = maxChansOut > 0;
  198546. return (isInput || isOutput) && rates.size() > 0;
  198547. }
  198548. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198549. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198550. };
  198551. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198552. {
  198553. return new ALSAAudioIODeviceType();
  198554. }
  198555. #endif
  198556. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198557. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198558. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198559. // compiled on its own).
  198560. #ifdef JUCE_INCLUDED_FILE
  198561. #if JUCE_JACK
  198562. static void* juce_libjack_handle = 0;
  198563. void* juce_load_jack_function (const char* const name)
  198564. {
  198565. if (juce_libjack_handle == 0)
  198566. return 0;
  198567. return dlsym (juce_libjack_handle, name);
  198568. }
  198569. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198570. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198571. return_type fn_name argument_types { \
  198572. static fn_name##_ptr_t fn = 0; \
  198573. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198574. if (fn) return (*fn)arguments; \
  198575. else return 0; \
  198576. }
  198577. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198578. typedef void (*fn_name##_ptr_t)argument_types; \
  198579. void fn_name argument_types { \
  198580. static fn_name##_ptr_t fn = 0; \
  198581. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198582. if (fn) (*fn)arguments; \
  198583. }
  198584. 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));
  198585. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198586. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198587. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198588. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198589. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198590. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198591. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198592. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198593. 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));
  198594. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198595. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198596. 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));
  198597. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198598. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198599. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198600. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198601. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198602. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198603. #if JUCE_DEBUG
  198604. #define JACK_LOGGING_ENABLED 1
  198605. #endif
  198606. #if JACK_LOGGING_ENABLED
  198607. static void jack_Log (const String& s)
  198608. {
  198609. std::cerr << s << std::endl;
  198610. }
  198611. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198612. {
  198613. if (status & JackServerFailed || status & JackServerError)
  198614. jack_Log ("Unable to connect to JACK server");
  198615. if (status & JackVersionError)
  198616. jack_Log ("Client's protocol version does not match");
  198617. if (status & JackInvalidOption)
  198618. jack_Log ("The operation contained an invalid or unsupported option");
  198619. if (status & JackNameNotUnique)
  198620. jack_Log ("The desired client name was not unique");
  198621. if (status & JackNoSuchClient)
  198622. jack_Log ("Requested client does not exist");
  198623. if (status & JackInitFailure)
  198624. jack_Log ("Unable to initialize client");
  198625. }
  198626. #else
  198627. #define dumpJackErrorMessage(a) {}
  198628. #define jack_Log(...) {}
  198629. #endif
  198630. #ifndef JUCE_JACK_CLIENT_NAME
  198631. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198632. #endif
  198633. class JackAudioIODevice : public AudioIODevice
  198634. {
  198635. public:
  198636. JackAudioIODevice (const String& deviceName,
  198637. const String& inputId_,
  198638. const String& outputId_)
  198639. : AudioIODevice (deviceName, "JACK"),
  198640. inputId (inputId_),
  198641. outputId (outputId_),
  198642. isOpen_ (false),
  198643. callback (0),
  198644. totalNumberOfInputChannels (0),
  198645. totalNumberOfOutputChannels (0)
  198646. {
  198647. jassert (deviceName.isNotEmpty());
  198648. jack_status_t status;
  198649. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198650. if (client == 0)
  198651. {
  198652. dumpJackErrorMessage (status);
  198653. }
  198654. else
  198655. {
  198656. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198657. // open input ports
  198658. const StringArray inputChannels (getInputChannelNames());
  198659. for (int i = 0; i < inputChannels.size(); i++)
  198660. {
  198661. String inputName;
  198662. inputName << "in_" << ++totalNumberOfInputChannels;
  198663. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198664. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198665. }
  198666. // open output ports
  198667. const StringArray outputChannels (getOutputChannelNames());
  198668. for (int i = 0; i < outputChannels.size (); i++)
  198669. {
  198670. String outputName;
  198671. outputName << "out_" << ++totalNumberOfOutputChannels;
  198672. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198673. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198674. }
  198675. inChans.calloc (totalNumberOfInputChannels + 2);
  198676. outChans.calloc (totalNumberOfOutputChannels + 2);
  198677. }
  198678. }
  198679. ~JackAudioIODevice()
  198680. {
  198681. close();
  198682. if (client != 0)
  198683. {
  198684. JUCE_NAMESPACE::jack_client_close (client);
  198685. client = 0;
  198686. }
  198687. }
  198688. const StringArray getChannelNames (bool forInput) const
  198689. {
  198690. StringArray names;
  198691. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198692. forInput ? JackPortIsInput : JackPortIsOutput);
  198693. if (ports != 0)
  198694. {
  198695. int j = 0;
  198696. while (ports[j] != 0)
  198697. {
  198698. const String portName (ports [j++]);
  198699. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198700. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198701. }
  198702. free (ports);
  198703. }
  198704. return names;
  198705. }
  198706. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198707. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198708. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198709. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198710. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198711. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198712. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198713. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198714. double sampleRate, int bufferSizeSamples)
  198715. {
  198716. if (client == 0)
  198717. {
  198718. lastError = "No JACK client running";
  198719. return lastError;
  198720. }
  198721. lastError = String::empty;
  198722. close();
  198723. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198724. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198725. JUCE_NAMESPACE::jack_activate (client);
  198726. isOpen_ = true;
  198727. if (! inputChannels.isZero())
  198728. {
  198729. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198730. if (ports != 0)
  198731. {
  198732. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198733. for (int i = 0; i < numInputChannels; ++i)
  198734. {
  198735. const String portName (ports[i]);
  198736. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198737. {
  198738. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198739. if (error != 0)
  198740. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198741. }
  198742. }
  198743. free (ports);
  198744. }
  198745. }
  198746. if (! outputChannels.isZero())
  198747. {
  198748. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198749. if (ports != 0)
  198750. {
  198751. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198752. for (int i = 0; i < numOutputChannels; ++i)
  198753. {
  198754. const String portName (ports[i]);
  198755. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198756. {
  198757. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198758. if (error != 0)
  198759. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198760. }
  198761. }
  198762. free (ports);
  198763. }
  198764. }
  198765. return lastError;
  198766. }
  198767. void close()
  198768. {
  198769. stop();
  198770. if (client != 0)
  198771. {
  198772. JUCE_NAMESPACE::jack_deactivate (client);
  198773. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198774. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198775. }
  198776. isOpen_ = false;
  198777. }
  198778. void start (AudioIODeviceCallback* newCallback)
  198779. {
  198780. if (isOpen_ && newCallback != callback)
  198781. {
  198782. if (newCallback != 0)
  198783. newCallback->audioDeviceAboutToStart (this);
  198784. AudioIODeviceCallback* const oldCallback = callback;
  198785. {
  198786. const ScopedLock sl (callbackLock);
  198787. callback = newCallback;
  198788. }
  198789. if (oldCallback != 0)
  198790. oldCallback->audioDeviceStopped();
  198791. }
  198792. }
  198793. void stop()
  198794. {
  198795. start (0);
  198796. }
  198797. bool isOpen() { return isOpen_; }
  198798. bool isPlaying() { return callback != 0; }
  198799. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198800. double getCurrentSampleRate() { return getSampleRate (0); }
  198801. int getCurrentBitDepth() { return 32; }
  198802. const String getLastError() { return lastError; }
  198803. const BigInteger getActiveOutputChannels() const
  198804. {
  198805. BigInteger outputBits;
  198806. for (int i = 0; i < outputPorts.size(); i++)
  198807. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198808. outputBits.setBit (i);
  198809. return outputBits;
  198810. }
  198811. const BigInteger getActiveInputChannels() const
  198812. {
  198813. BigInteger inputBits;
  198814. for (int i = 0; i < inputPorts.size(); i++)
  198815. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198816. inputBits.setBit (i);
  198817. return inputBits;
  198818. }
  198819. int getOutputLatencyInSamples()
  198820. {
  198821. int latency = 0;
  198822. for (int i = 0; i < outputPorts.size(); i++)
  198823. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198824. return latency;
  198825. }
  198826. int getInputLatencyInSamples()
  198827. {
  198828. int latency = 0;
  198829. for (int i = 0; i < inputPorts.size(); i++)
  198830. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198831. return latency;
  198832. }
  198833. String inputId, outputId;
  198834. private:
  198835. void process (const int numSamples)
  198836. {
  198837. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198838. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198839. {
  198840. jack_default_audio_sample_t* in
  198841. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198842. if (in != 0)
  198843. inChans [numActiveInChans++] = (float*) in;
  198844. }
  198845. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198846. {
  198847. jack_default_audio_sample_t* out
  198848. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198849. if (out != 0)
  198850. outChans [numActiveOutChans++] = (float*) out;
  198851. }
  198852. const ScopedLock sl (callbackLock);
  198853. if (callback != 0)
  198854. {
  198855. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198856. outChans, numActiveOutChans, numSamples);
  198857. }
  198858. else
  198859. {
  198860. for (i = 0; i < numActiveOutChans; ++i)
  198861. zeromem (outChans[i], sizeof (float) * numSamples);
  198862. }
  198863. }
  198864. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198865. {
  198866. if (callbackArgument != 0)
  198867. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198868. return 0;
  198869. }
  198870. static void threadInitCallback (void* callbackArgument)
  198871. {
  198872. jack_Log ("JackAudioIODevice::initialise");
  198873. }
  198874. static void shutdownCallback (void* callbackArgument)
  198875. {
  198876. jack_Log ("JackAudioIODevice::shutdown");
  198877. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198878. if (device != 0)
  198879. {
  198880. device->client = 0;
  198881. device->close();
  198882. }
  198883. }
  198884. static void errorCallback (const char* msg)
  198885. {
  198886. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198887. }
  198888. bool isOpen_;
  198889. jack_client_t* client;
  198890. String lastError;
  198891. AudioIODeviceCallback* callback;
  198892. CriticalSection callbackLock;
  198893. HeapBlock <float*> inChans, outChans;
  198894. int totalNumberOfInputChannels;
  198895. int totalNumberOfOutputChannels;
  198896. VoidArray inputPorts, outputPorts;
  198897. };
  198898. class JackAudioIODeviceType : public AudioIODeviceType
  198899. {
  198900. public:
  198901. JackAudioIODeviceType()
  198902. : AudioIODeviceType ("JACK"),
  198903. hasScanned (false)
  198904. {
  198905. }
  198906. ~JackAudioIODeviceType()
  198907. {
  198908. }
  198909. void scanForDevices()
  198910. {
  198911. hasScanned = true;
  198912. inputNames.clear();
  198913. inputIds.clear();
  198914. outputNames.clear();
  198915. outputIds.clear();
  198916. if (juce_libjack_handle == 0)
  198917. {
  198918. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198919. if (juce_libjack_handle == 0)
  198920. return;
  198921. }
  198922. // open a dummy client
  198923. jack_status_t status;
  198924. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198925. if (client == 0)
  198926. {
  198927. dumpJackErrorMessage (status);
  198928. }
  198929. else
  198930. {
  198931. // scan for output devices
  198932. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198933. if (ports != 0)
  198934. {
  198935. int j = 0;
  198936. while (ports[j] != 0)
  198937. {
  198938. String clientName (ports[j]);
  198939. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198940. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198941. && ! inputNames.contains (clientName))
  198942. {
  198943. inputNames.add (clientName);
  198944. inputIds.add (ports [j]);
  198945. }
  198946. ++j;
  198947. }
  198948. free (ports);
  198949. }
  198950. // scan for input devices
  198951. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198952. if (ports != 0)
  198953. {
  198954. int j = 0;
  198955. while (ports[j] != 0)
  198956. {
  198957. String clientName (ports[j]);
  198958. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198959. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198960. && ! outputNames.contains (clientName))
  198961. {
  198962. outputNames.add (clientName);
  198963. outputIds.add (ports [j]);
  198964. }
  198965. ++j;
  198966. }
  198967. free (ports);
  198968. }
  198969. JUCE_NAMESPACE::jack_client_close (client);
  198970. }
  198971. }
  198972. const StringArray getDeviceNames (bool wantInputNames) const
  198973. {
  198974. jassert (hasScanned); // need to call scanForDevices() before doing this
  198975. return wantInputNames ? inputNames : outputNames;
  198976. }
  198977. int getDefaultDeviceIndex (bool forInput) const
  198978. {
  198979. jassert (hasScanned); // need to call scanForDevices() before doing this
  198980. return 0;
  198981. }
  198982. bool hasSeparateInputsAndOutputs() const { return true; }
  198983. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198984. {
  198985. jassert (hasScanned); // need to call scanForDevices() before doing this
  198986. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  198987. if (d == 0)
  198988. return -1;
  198989. return asInput ? inputIds.indexOf (d->inputId)
  198990. : outputIds.indexOf (d->outputId);
  198991. }
  198992. AudioIODevice* createDevice (const String& outputDeviceName,
  198993. const String& inputDeviceName)
  198994. {
  198995. jassert (hasScanned); // need to call scanForDevices() before doing this
  198996. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198997. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198998. if (inputIndex >= 0 || outputIndex >= 0)
  198999. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199000. : inputDeviceName,
  199001. inputIds [inputIndex],
  199002. outputIds [outputIndex]);
  199003. return 0;
  199004. }
  199005. juce_UseDebuggingNewOperator
  199006. private:
  199007. StringArray inputNames, outputNames, inputIds, outputIds;
  199008. bool hasScanned;
  199009. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199010. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199011. };
  199012. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199013. {
  199014. return new JackAudioIODeviceType();
  199015. }
  199016. #else // if JACK is turned off..
  199017. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199018. #endif
  199019. #endif
  199020. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199021. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199022. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199023. // compiled on its own).
  199024. #if JUCE_INCLUDED_FILE
  199025. #if JUCE_ALSA
  199026. static snd_seq_t* iterateDevices (const bool forInput,
  199027. StringArray& deviceNamesFound,
  199028. const int deviceIndexToOpen)
  199029. {
  199030. snd_seq_t* returnedHandle = 0;
  199031. snd_seq_t* seqHandle;
  199032. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199033. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199034. {
  199035. snd_seq_system_info_t* systemInfo;
  199036. snd_seq_client_info_t* clientInfo;
  199037. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199038. {
  199039. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199040. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199041. {
  199042. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199043. while (--numClients >= 0 && returnedHandle == 0)
  199044. {
  199045. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199046. {
  199047. snd_seq_port_info_t* portInfo;
  199048. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199049. {
  199050. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199051. const int client = snd_seq_client_info_get_client (clientInfo);
  199052. snd_seq_port_info_set_client (portInfo, client);
  199053. snd_seq_port_info_set_port (portInfo, -1);
  199054. while (--numPorts >= 0)
  199055. {
  199056. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199057. && (snd_seq_port_info_get_capability (portInfo)
  199058. & (forInput ? SND_SEQ_PORT_CAP_READ
  199059. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199060. {
  199061. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199062. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199063. {
  199064. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199065. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199066. if (sourcePort != -1)
  199067. {
  199068. snd_seq_set_client_name (seqHandle,
  199069. forInput ? "Juce Midi Input"
  199070. : "Juce Midi Output");
  199071. const int portId
  199072. = snd_seq_create_simple_port (seqHandle,
  199073. forInput ? "Juce Midi In Port"
  199074. : "Juce Midi Out Port",
  199075. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199076. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199077. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199078. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199079. returnedHandle = seqHandle;
  199080. }
  199081. }
  199082. }
  199083. }
  199084. snd_seq_port_info_free (portInfo);
  199085. }
  199086. }
  199087. }
  199088. snd_seq_client_info_free (clientInfo);
  199089. }
  199090. snd_seq_system_info_free (systemInfo);
  199091. }
  199092. if (returnedHandle == 0)
  199093. snd_seq_close (seqHandle);
  199094. }
  199095. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199096. return returnedHandle;
  199097. }
  199098. static snd_seq_t* createDevice (const bool forInput,
  199099. const String& deviceNameToOpen)
  199100. {
  199101. snd_seq_t* seqHandle = 0;
  199102. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199103. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199104. {
  199105. snd_seq_set_client_name (seqHandle,
  199106. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199107. const int portId
  199108. = snd_seq_create_simple_port (seqHandle,
  199109. forInput ? "in"
  199110. : "out",
  199111. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199112. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199113. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199114. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199115. if (portId < 0)
  199116. {
  199117. snd_seq_close (seqHandle);
  199118. seqHandle = 0;
  199119. }
  199120. }
  199121. return seqHandle;
  199122. }
  199123. class MidiOutputDevice
  199124. {
  199125. public:
  199126. MidiOutputDevice (MidiOutput* const midiOutput_,
  199127. snd_seq_t* const seqHandle_)
  199128. :
  199129. midiOutput (midiOutput_),
  199130. seqHandle (seqHandle_),
  199131. maxEventSize (16 * 1024)
  199132. {
  199133. jassert (seqHandle != 0 && midiOutput != 0);
  199134. snd_midi_event_new (maxEventSize, &midiParser);
  199135. }
  199136. ~MidiOutputDevice()
  199137. {
  199138. snd_midi_event_free (midiParser);
  199139. snd_seq_close (seqHandle);
  199140. }
  199141. void sendMessageNow (const MidiMessage& message)
  199142. {
  199143. if (message.getRawDataSize() > maxEventSize)
  199144. {
  199145. maxEventSize = message.getRawDataSize();
  199146. snd_midi_event_free (midiParser);
  199147. snd_midi_event_new (maxEventSize, &midiParser);
  199148. }
  199149. snd_seq_event_t event;
  199150. snd_seq_ev_clear (&event);
  199151. snd_midi_event_encode (midiParser,
  199152. message.getRawData(),
  199153. message.getRawDataSize(),
  199154. &event);
  199155. snd_midi_event_reset_encode (midiParser);
  199156. snd_seq_ev_set_source (&event, 0);
  199157. snd_seq_ev_set_subs (&event);
  199158. snd_seq_ev_set_direct (&event);
  199159. snd_seq_event_output (seqHandle, &event);
  199160. snd_seq_drain_output (seqHandle);
  199161. }
  199162. juce_UseDebuggingNewOperator
  199163. private:
  199164. MidiOutput* const midiOutput;
  199165. snd_seq_t* const seqHandle;
  199166. snd_midi_event_t* midiParser;
  199167. int maxEventSize;
  199168. };
  199169. const StringArray MidiOutput::getDevices()
  199170. {
  199171. StringArray devices;
  199172. iterateDevices (false, devices, -1);
  199173. return devices;
  199174. }
  199175. int MidiOutput::getDefaultDeviceIndex()
  199176. {
  199177. return 0;
  199178. }
  199179. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199180. {
  199181. MidiOutput* newDevice = 0;
  199182. StringArray devices;
  199183. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199184. if (handle != 0)
  199185. {
  199186. newDevice = new MidiOutput();
  199187. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199188. }
  199189. return newDevice;
  199190. }
  199191. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199192. {
  199193. MidiOutput* newDevice = 0;
  199194. snd_seq_t* const handle = createDevice (false, deviceName);
  199195. if (handle != 0)
  199196. {
  199197. newDevice = new MidiOutput();
  199198. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199199. }
  199200. return newDevice;
  199201. }
  199202. MidiOutput::~MidiOutput()
  199203. {
  199204. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199205. delete device;
  199206. }
  199207. void MidiOutput::reset()
  199208. {
  199209. }
  199210. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199211. {
  199212. return false;
  199213. }
  199214. void MidiOutput::setVolume (float leftVol, float rightVol)
  199215. {
  199216. }
  199217. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199218. {
  199219. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199220. }
  199221. class MidiInputThread : public Thread
  199222. {
  199223. public:
  199224. MidiInputThread (MidiInput* const midiInput_,
  199225. snd_seq_t* const seqHandle_,
  199226. MidiInputCallback* const callback_)
  199227. : Thread ("Juce MIDI Input"),
  199228. midiInput (midiInput_),
  199229. seqHandle (seqHandle_),
  199230. callback (callback_)
  199231. {
  199232. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199233. }
  199234. ~MidiInputThread()
  199235. {
  199236. snd_seq_close (seqHandle);
  199237. }
  199238. void run()
  199239. {
  199240. const int maxEventSize = 16 * 1024;
  199241. snd_midi_event_t* midiParser;
  199242. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199243. {
  199244. HeapBlock <uint8> buffer (maxEventSize);
  199245. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199246. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199247. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199248. while (! threadShouldExit())
  199249. {
  199250. if (poll (pfd, numPfds, 500) > 0)
  199251. {
  199252. snd_seq_event_t* inputEvent = 0;
  199253. snd_seq_nonblock (seqHandle, 1);
  199254. do
  199255. {
  199256. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199257. {
  199258. // xxx what about SYSEXes that are too big for the buffer?
  199259. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199260. snd_midi_event_reset_decode (midiParser);
  199261. if (numBytes > 0)
  199262. {
  199263. const MidiMessage message ((const uint8*) buffer,
  199264. numBytes,
  199265. Time::getMillisecondCounter() * 0.001);
  199266. callback->handleIncomingMidiMessage (midiInput, message);
  199267. }
  199268. snd_seq_free_event (inputEvent);
  199269. }
  199270. }
  199271. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199272. snd_seq_free_event (inputEvent);
  199273. }
  199274. }
  199275. snd_midi_event_free (midiParser);
  199276. }
  199277. };
  199278. juce_UseDebuggingNewOperator
  199279. private:
  199280. MidiInput* const midiInput;
  199281. snd_seq_t* const seqHandle;
  199282. MidiInputCallback* const callback;
  199283. };
  199284. MidiInput::MidiInput (const String& name_)
  199285. : name (name_),
  199286. internal (0)
  199287. {
  199288. }
  199289. MidiInput::~MidiInput()
  199290. {
  199291. stop();
  199292. MidiInputThread* const thread = (MidiInputThread*) internal;
  199293. delete thread;
  199294. }
  199295. void MidiInput::start()
  199296. {
  199297. ((MidiInputThread*) internal)->startThread();
  199298. }
  199299. void MidiInput::stop()
  199300. {
  199301. ((MidiInputThread*) internal)->stopThread (3000);
  199302. }
  199303. int MidiInput::getDefaultDeviceIndex()
  199304. {
  199305. return 0;
  199306. }
  199307. const StringArray MidiInput::getDevices()
  199308. {
  199309. StringArray devices;
  199310. iterateDevices (true, devices, -1);
  199311. return devices;
  199312. }
  199313. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199314. {
  199315. MidiInput* newDevice = 0;
  199316. StringArray devices;
  199317. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199318. if (handle != 0)
  199319. {
  199320. newDevice = new MidiInput (devices [deviceIndex]);
  199321. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199322. }
  199323. return newDevice;
  199324. }
  199325. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199326. {
  199327. MidiInput* newDevice = 0;
  199328. snd_seq_t* const handle = createDevice (true, deviceName);
  199329. if (handle != 0)
  199330. {
  199331. newDevice = new MidiInput (deviceName);
  199332. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199333. }
  199334. return newDevice;
  199335. }
  199336. #else
  199337. // (These are just stub functions if ALSA is unavailable...)
  199338. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199339. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199340. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199341. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199342. MidiOutput::~MidiOutput() {}
  199343. void MidiOutput::reset() {}
  199344. bool MidiOutput::getVolume (float&, float&) { return false; }
  199345. void MidiOutput::setVolume (float, float) {}
  199346. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199347. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199348. MidiInput::~MidiInput() {}
  199349. void MidiInput::start() {}
  199350. void MidiInput::stop() {}
  199351. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199352. const StringArray MidiInput::getDevices() { return StringArray(); }
  199353. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199354. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199355. #endif
  199356. #endif
  199357. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199358. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199359. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199360. // compiled on its own).
  199361. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199362. AudioCDReader::AudioCDReader()
  199363. : AudioFormatReader (0, "CD Audio")
  199364. {
  199365. }
  199366. const StringArray AudioCDReader::getAvailableCDNames()
  199367. {
  199368. StringArray names;
  199369. return names;
  199370. }
  199371. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199372. {
  199373. return 0;
  199374. }
  199375. AudioCDReader::~AudioCDReader()
  199376. {
  199377. }
  199378. void AudioCDReader::refreshTrackLengths()
  199379. {
  199380. }
  199381. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199382. int64 startSampleInFile, int numSamples)
  199383. {
  199384. return false;
  199385. }
  199386. bool AudioCDReader::isCDStillPresent() const
  199387. {
  199388. return false;
  199389. }
  199390. int AudioCDReader::getNumTracks() const
  199391. {
  199392. return 0;
  199393. }
  199394. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199395. {
  199396. return 0;
  199397. }
  199398. bool AudioCDReader::isTrackAudio (int trackNum) const
  199399. {
  199400. return false;
  199401. }
  199402. void AudioCDReader::enableIndexScanning (bool b)
  199403. {
  199404. }
  199405. int AudioCDReader::getLastIndex() const
  199406. {
  199407. return 0;
  199408. }
  199409. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199410. {
  199411. return Array<int>();
  199412. }
  199413. int AudioCDReader::getCDDBId()
  199414. {
  199415. return 0;
  199416. }
  199417. #endif
  199418. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199419. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199420. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199421. // compiled on its own).
  199422. #if JUCE_INCLUDED_FILE
  199423. void FileChooser::showPlatformDialog (Array<File>& results,
  199424. const String& title,
  199425. const File& file,
  199426. const String& filters,
  199427. bool isDirectory,
  199428. bool selectsFiles,
  199429. bool isSave,
  199430. bool warnAboutOverwritingExistingFiles,
  199431. bool selectMultipleFiles,
  199432. FilePreviewComponent* previewComponent)
  199433. {
  199434. const String separator (":");
  199435. String command ("zenity --file-selection");
  199436. if (title.isNotEmpty())
  199437. command << " --title=\"" << title << "\"";
  199438. if (file != File::nonexistent)
  199439. command << " --filename=\"" << file.getFullPathName () << "\"";
  199440. if (isDirectory)
  199441. command << " --directory";
  199442. if (isSave)
  199443. command << " --save";
  199444. if (selectMultipleFiles)
  199445. command << " --multiple --separator=\"" << separator << "\"";
  199446. command << " 2>&1";
  199447. MemoryOutputStream result;
  199448. int status = -1;
  199449. FILE* stream = popen (command.toUTF8(), "r");
  199450. if (stream != 0)
  199451. {
  199452. for (;;)
  199453. {
  199454. char buffer [1024];
  199455. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199456. if (bytesRead <= 0)
  199457. break;
  199458. result.write (buffer, bytesRead);
  199459. }
  199460. status = pclose (stream);
  199461. }
  199462. if (status == 0)
  199463. {
  199464. StringArray tokens;
  199465. if (selectMultipleFiles)
  199466. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199467. else
  199468. tokens.add (result.toUTF8());
  199469. for (int i = 0; i < tokens.size(); i++)
  199470. results.add (File (tokens[i]));
  199471. return;
  199472. }
  199473. //xxx ain't got one!
  199474. jassertfalse
  199475. }
  199476. #endif
  199477. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199478. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199479. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199480. // compiled on its own).
  199481. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199482. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199483. : browser (0),
  199484. blankPageShown (false),
  199485. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199486. {
  199487. setOpaque (true);
  199488. }
  199489. WebBrowserComponent::~WebBrowserComponent()
  199490. {
  199491. }
  199492. void WebBrowserComponent::goToURL (const String& url,
  199493. const StringArray* headers,
  199494. const MemoryBlock* postData)
  199495. {
  199496. lastURL = url;
  199497. lastHeaders.clear();
  199498. if (headers != 0)
  199499. lastHeaders = *headers;
  199500. lastPostData.setSize (0);
  199501. if (postData != 0)
  199502. lastPostData = *postData;
  199503. blankPageShown = false;
  199504. }
  199505. void WebBrowserComponent::stop()
  199506. {
  199507. }
  199508. void WebBrowserComponent::goBack()
  199509. {
  199510. lastURL = String::empty;
  199511. blankPageShown = false;
  199512. }
  199513. void WebBrowserComponent::goForward()
  199514. {
  199515. lastURL = String::empty;
  199516. }
  199517. void WebBrowserComponent::refresh()
  199518. {
  199519. }
  199520. void WebBrowserComponent::paint (Graphics& g)
  199521. {
  199522. g.fillAll (Colours::white);
  199523. }
  199524. void WebBrowserComponent::checkWindowAssociation()
  199525. {
  199526. }
  199527. void WebBrowserComponent::reloadLastURL()
  199528. {
  199529. if (lastURL.isNotEmpty())
  199530. {
  199531. goToURL (lastURL, &lastHeaders, &lastPostData);
  199532. lastURL = String::empty;
  199533. }
  199534. }
  199535. void WebBrowserComponent::parentHierarchyChanged()
  199536. {
  199537. checkWindowAssociation();
  199538. }
  199539. void WebBrowserComponent::resized()
  199540. {
  199541. }
  199542. void WebBrowserComponent::visibilityChanged()
  199543. {
  199544. checkWindowAssociation();
  199545. }
  199546. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199547. {
  199548. return true;
  199549. }
  199550. #endif
  199551. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199552. #endif
  199553. END_JUCE_NAMESPACE
  199554. #endif
  199555. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199556. #endif
  199557. #if JUCE_MAC || JUCE_IPHONE
  199558. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199559. #if JUCE_MAC || JUCE_IPHONE
  199560. BEGIN_JUCE_NAMESPACE
  199561. #undef Point
  199562. #define JUCE_INCLUDED_FILE 1
  199563. // Now include the actual code files..
  199564. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199565. #ifndef JUCE_ObjCExtraSuffix
  199566. #define JUCE_ObjCExtraSuffix 3
  199567. #endif
  199568. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199569. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199570. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199571. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199572. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199573. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199574. // compiled on its own).
  199575. #if JUCE_INCLUDED_FILE
  199576. static const String nsStringToJuce (NSString* s)
  199577. {
  199578. return String::fromUTF8 ([s UTF8String]);
  199579. }
  199580. static NSString* juceStringToNS (const String& s)
  199581. {
  199582. return [NSString stringWithUTF8String: s.toUTF8()];
  199583. }
  199584. static const String convertUTF16ToString (const UniChar* utf16)
  199585. {
  199586. String s;
  199587. while (*utf16 != 0)
  199588. s += (juce_wchar) *utf16++;
  199589. return s;
  199590. }
  199591. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199592. {
  199593. String result;
  199594. if (cfString != 0)
  199595. {
  199596. CFRange range = { 0, CFStringGetLength (cfString) };
  199597. HeapBlock <UniChar> u (range.length + 1);
  199598. CFStringGetCharacters (cfString, range, u);
  199599. u[range.length] = 0;
  199600. result = convertUTF16ToString (u);
  199601. }
  199602. return result;
  199603. }
  199604. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199605. {
  199606. const int len = s.length();
  199607. HeapBlock <UniChar> temp (len + 2);
  199608. for (int i = 0; i <= len; ++i)
  199609. temp[i] = s[i];
  199610. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199611. }
  199612. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199613. {
  199614. #if JUCE_IPHONE
  199615. const ScopedAutoReleasePool pool;
  199616. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199617. #else
  199618. UnicodeMapping map;
  199619. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199620. kUnicodeNoSubset,
  199621. kTextEncodingDefaultFormat);
  199622. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199623. kUnicodeCanonicalCompVariant,
  199624. kTextEncodingDefaultFormat);
  199625. map.mappingVersion = kUnicodeUseLatestMapping;
  199626. UnicodeToTextInfo conversionInfo = 0;
  199627. String result;
  199628. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199629. {
  199630. const int len = s.length();
  199631. HeapBlock <UniChar> tempIn, tempOut;
  199632. tempIn.calloc (len + 2);
  199633. tempOut.calloc (len + 2);
  199634. for (int i = 0; i <= len; ++i)
  199635. tempIn[i] = s[i];
  199636. ByteCount bytesRead = 0;
  199637. ByteCount outputBufferSize = 0;
  199638. if (ConvertFromUnicodeToText (conversionInfo,
  199639. len * sizeof (UniChar), tempIn,
  199640. kUnicodeDefaultDirectionMask,
  199641. 0, 0, 0, 0,
  199642. len * sizeof (UniChar), &bytesRead,
  199643. &outputBufferSize, tempOut) == noErr)
  199644. {
  199645. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199646. juce_wchar* t = result;
  199647. unsigned int i;
  199648. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199649. t[i] = (juce_wchar) tempOut[i];
  199650. t[i] = 0;
  199651. }
  199652. DisposeUnicodeToTextInfo (&conversionInfo);
  199653. }
  199654. return result;
  199655. #endif
  199656. }
  199657. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199658. void SystemClipboard::copyTextToClipboard (const String& text)
  199659. {
  199660. #if JUCE_IPHONE
  199661. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199662. forPasteboardType: @"public.text"];
  199663. #else
  199664. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199665. owner: nil];
  199666. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199667. forType: NSStringPboardType];
  199668. #endif
  199669. }
  199670. const String SystemClipboard::getTextFromClipboard()
  199671. {
  199672. #if JUCE_IPHONE
  199673. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199674. #else
  199675. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199676. #endif
  199677. return text == 0 ? String::empty
  199678. : nsStringToJuce (text);
  199679. }
  199680. #endif
  199681. #endif
  199682. /*** End of inlined file: juce_mac_Strings.mm ***/
  199683. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199684. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199685. // compiled on its own).
  199686. #if JUCE_INCLUDED_FILE
  199687. namespace SystemStatsHelpers
  199688. {
  199689. static int64 highResTimerFrequency = 0;
  199690. static double highResTimerToMillisecRatio = 0;
  199691. #if JUCE_INTEL
  199692. static void juce_getCpuVendor (char* const v) throw()
  199693. {
  199694. int vendor[4];
  199695. zerostruct (vendor);
  199696. int dummy = 0;
  199697. asm ("mov %%ebx, %%esi \n\t"
  199698. "cpuid \n\t"
  199699. "xchg %%esi, %%ebx"
  199700. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199701. memcpy (v, vendor, 16);
  199702. }
  199703. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199704. {
  199705. unsigned int cpu = 0;
  199706. unsigned int ext = 0;
  199707. unsigned int family = 0;
  199708. unsigned int dummy = 0;
  199709. asm ("mov %%ebx, %%esi \n\t"
  199710. "cpuid \n\t"
  199711. "xchg %%esi, %%ebx"
  199712. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199713. familyModel = family;
  199714. extFeatures = ext;
  199715. return cpu;
  199716. }
  199717. struct CPUFlags
  199718. {
  199719. bool hasMMX : 1;
  199720. bool hasSSE : 1;
  199721. bool hasSSE2 : 1;
  199722. bool has3DNow : 1;
  199723. };
  199724. static CPUFlags cpuFlags;
  199725. #endif
  199726. }
  199727. void SystemStats::initialiseStats() throw()
  199728. {
  199729. using namespace SystemStatsHelpers;
  199730. static bool initialised = false;
  199731. if (! initialised)
  199732. {
  199733. initialised = true;
  199734. #if JUCE_MAC
  199735. // extremely annoying: adding this line stops the apple menu items from working. Of
  199736. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199737. // any events.
  199738. //NSApplicationLoad();
  199739. [NSApplication sharedApplication];
  199740. #endif
  199741. #if JUCE_INTEL
  199742. {
  199743. unsigned int familyModel, extFeatures;
  199744. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199745. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199746. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199747. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199748. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199749. }
  199750. #endif
  199751. mach_timebase_info_data_t timebase;
  199752. (void) mach_timebase_info (&timebase);
  199753. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199754. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199755. String s (SystemStats::getJUCEVersion());
  199756. rlimit lim;
  199757. getrlimit (RLIMIT_NOFILE, &lim);
  199758. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199759. setrlimit (RLIMIT_NOFILE, &lim);
  199760. }
  199761. }
  199762. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199763. {
  199764. return MacOSX;
  199765. }
  199766. const String SystemStats::getOperatingSystemName() throw()
  199767. {
  199768. return "Mac OS X";
  199769. }
  199770. bool SystemStats::isOperatingSystem64Bit() throw()
  199771. {
  199772. #if JUCE_64BIT
  199773. return true;
  199774. #else
  199775. //xxx not sure how to find this out?..
  199776. return false;
  199777. #endif
  199778. }
  199779. int SystemStats::getMemorySizeInMegabytes() throw()
  199780. {
  199781. uint64 mem = 0;
  199782. size_t memSize = sizeof (mem);
  199783. int mib[] = { CTL_HW, HW_MEMSIZE };
  199784. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199785. return (int) (mem / (1024 * 1024));
  199786. }
  199787. bool SystemStats::hasMMX() throw()
  199788. {
  199789. #if JUCE_INTEL
  199790. return SystemStatsHelpers::cpuFlags.hasMMX;
  199791. #else
  199792. return false;
  199793. #endif
  199794. }
  199795. bool SystemStats::hasSSE() throw()
  199796. {
  199797. #if JUCE_INTEL
  199798. return SystemStatsHelpers::cpuFlags.hasSSE;
  199799. #else
  199800. return false;
  199801. #endif
  199802. }
  199803. bool SystemStats::hasSSE2() throw()
  199804. {
  199805. #if JUCE_INTEL
  199806. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199807. #else
  199808. return false;
  199809. #endif
  199810. }
  199811. bool SystemStats::has3DNow() throw()
  199812. {
  199813. #if JUCE_INTEL
  199814. return SystemStatsHelpers::cpuFlags.has3DNow;
  199815. #else
  199816. return false;
  199817. #endif
  199818. }
  199819. const String SystemStats::getCpuVendor() throw()
  199820. {
  199821. #if JUCE_INTEL
  199822. char v [16];
  199823. SystemStatsHelpers::juce_getCpuVendor (v);
  199824. return String (v, 16);
  199825. #else
  199826. return String::empty;
  199827. #endif
  199828. }
  199829. int SystemStats::getCpuSpeedInMegaherz() throw()
  199830. {
  199831. uint64 speedHz = 0;
  199832. size_t speedSize = sizeof (speedHz);
  199833. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199834. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199835. #if JUCE_BIG_ENDIAN
  199836. if (speedSize == 4)
  199837. speedHz >>= 32;
  199838. #endif
  199839. return (int) (speedHz / 1000000);
  199840. }
  199841. int SystemStats::getNumCpus() throw()
  199842. {
  199843. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199844. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199845. #else
  199846. return MPProcessors();
  199847. #endif
  199848. }
  199849. const String SystemStats::getLogonName()
  199850. {
  199851. return nsStringToJuce (NSUserName());
  199852. }
  199853. const String SystemStats::getFullUserName()
  199854. {
  199855. return nsStringToJuce (NSFullUserName());
  199856. }
  199857. uint32 juce_millisecondsSinceStartup() throw()
  199858. {
  199859. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199860. }
  199861. double Time::getMillisecondCounterHiRes() throw()
  199862. {
  199863. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199864. }
  199865. int64 Time::getHighResolutionTicks() throw()
  199866. {
  199867. return (int64) mach_absolute_time();
  199868. }
  199869. int64 Time::getHighResolutionTicksPerSecond() throw()
  199870. {
  199871. return SystemStatsHelpers::highResTimerFrequency;
  199872. }
  199873. int64 SystemStats::getClockCycleCounter() throw()
  199874. {
  199875. return (int64) mach_absolute_time();
  199876. }
  199877. bool Time::setSystemTimeToThisTime() const throw()
  199878. {
  199879. jassertfalse
  199880. return false;
  199881. }
  199882. int SystemStats::getPageSize() throw()
  199883. {
  199884. return (int) NSPageSize();
  199885. }
  199886. void PlatformUtilities::fpuReset()
  199887. {
  199888. }
  199889. #endif
  199890. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199891. /*** Start of inlined file: juce_mac_Network.mm ***/
  199892. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199893. // compiled on its own).
  199894. #if JUCE_INCLUDED_FILE
  199895. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199896. {
  199897. #ifndef IFT_ETHER
  199898. #define IFT_ETHER 6
  199899. #endif
  199900. ifaddrs* addrs = 0;
  199901. int numResults = 0;
  199902. if (getifaddrs (&addrs) == 0)
  199903. {
  199904. const ifaddrs* cursor = addrs;
  199905. while (cursor != 0 && numResults < maxNum)
  199906. {
  199907. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199908. if (sto->ss_family == AF_LINK)
  199909. {
  199910. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199911. if (sadd->sdl_type == IFT_ETHER)
  199912. {
  199913. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199914. uint64 a = 0;
  199915. for (int i = 6; --i >= 0;)
  199916. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199917. *addresses++ = (int64) a;
  199918. ++numResults;
  199919. }
  199920. }
  199921. cursor = cursor->ifa_next;
  199922. }
  199923. freeifaddrs (addrs);
  199924. }
  199925. return numResults;
  199926. }
  199927. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199928. const String& emailSubject,
  199929. const String& bodyText,
  199930. const StringArray& filesToAttach)
  199931. {
  199932. #if JUCE_IPHONE
  199933. //xxx probably need to use MFMailComposeViewController
  199934. jassertfalse
  199935. return false;
  199936. #else
  199937. const ScopedAutoReleasePool pool;
  199938. String script;
  199939. script << "tell application \"Mail\"\r\n"
  199940. "set newMessage to make new outgoing message with properties {subject:\""
  199941. << emailSubject.replace ("\"", "\\\"")
  199942. << "\", content:\""
  199943. << bodyText.replace ("\"", "\\\"")
  199944. << "\" & return & return}\r\n"
  199945. "tell newMessage\r\n"
  199946. "set visible to true\r\n"
  199947. "set sender to \"sdfsdfsdfewf\"\r\n"
  199948. "make new to recipient at end of to recipients with properties {address:\""
  199949. << targetEmailAddress
  199950. << "\"}\r\n";
  199951. for (int i = 0; i < filesToAttach.size(); ++i)
  199952. {
  199953. script << "tell content\r\n"
  199954. "make new attachment with properties {file name:\""
  199955. << filesToAttach[i].replace ("\"", "\\\"")
  199956. << "\"} at after the last paragraph\r\n"
  199957. "end tell\r\n";
  199958. }
  199959. script << "end tell\r\n"
  199960. "end tell\r\n";
  199961. NSAppleScript* s = [[NSAppleScript alloc]
  199962. initWithSource: juceStringToNS (script)];
  199963. NSDictionary* error = 0;
  199964. const bool ok = [s executeAndReturnError: &error] != nil;
  199965. [s release];
  199966. return ok;
  199967. #endif
  199968. }
  199969. END_JUCE_NAMESPACE
  199970. using namespace JUCE_NAMESPACE;
  199971. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199972. @interface JuceURLConnection : NSObject
  199973. {
  199974. @public
  199975. NSURLRequest* request;
  199976. NSURLConnection* connection;
  199977. NSMutableData* data;
  199978. Thread* runLoopThread;
  199979. bool initialised, hasFailed, hasFinished;
  199980. int position;
  199981. int64 contentLength;
  199982. NSLock* dataLock;
  199983. }
  199984. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  199985. - (void) dealloc;
  199986. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  199987. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  199988. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  199989. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  199990. - (BOOL) isOpen;
  199991. - (int) read: (char*) dest numBytes: (int) num;
  199992. - (int) readPosition;
  199993. - (void) stop;
  199994. - (void) createConnection;
  199995. @end
  199996. class JuceURLConnectionMessageThread : public Thread
  199997. {
  199998. JuceURLConnection* owner;
  199999. public:
  200000. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200001. : Thread ("http connection"),
  200002. owner (owner_)
  200003. {
  200004. }
  200005. ~JuceURLConnectionMessageThread()
  200006. {
  200007. stopThread (10000);
  200008. }
  200009. void run()
  200010. {
  200011. [owner createConnection];
  200012. while (! threadShouldExit())
  200013. {
  200014. const ScopedAutoReleasePool pool;
  200015. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200016. }
  200017. }
  200018. };
  200019. @implementation JuceURLConnection
  200020. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200021. withCallback: (URL::OpenStreamProgressCallback*) callback
  200022. withContext: (void*) context;
  200023. {
  200024. [super init];
  200025. request = req;
  200026. [request retain];
  200027. data = [[NSMutableData data] retain];
  200028. dataLock = [[NSLock alloc] init];
  200029. connection = 0;
  200030. initialised = false;
  200031. hasFailed = false;
  200032. hasFinished = false;
  200033. contentLength = -1;
  200034. runLoopThread = new JuceURLConnectionMessageThread (self);
  200035. runLoopThread->startThread();
  200036. while (runLoopThread->isThreadRunning() && ! initialised)
  200037. {
  200038. if (callback != 0)
  200039. callback (context, -1, (int) [[request HTTPBody] length]);
  200040. Thread::sleep (1);
  200041. }
  200042. return self;
  200043. }
  200044. - (void) dealloc
  200045. {
  200046. [self stop];
  200047. deleteAndZero (runLoopThread);
  200048. [connection release];
  200049. [data release];
  200050. [dataLock release];
  200051. [request release];
  200052. [super dealloc];
  200053. }
  200054. - (void) createConnection
  200055. {
  200056. connection = [[NSURLConnection alloc] initWithRequest: request
  200057. delegate: [self retain]];
  200058. if (connection == nil)
  200059. runLoopThread->signalThreadShouldExit();
  200060. }
  200061. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200062. {
  200063. [dataLock lock];
  200064. [data setLength: 0];
  200065. [dataLock unlock];
  200066. initialised = true;
  200067. contentLength = [response expectedContentLength];
  200068. }
  200069. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200070. {
  200071. DBG (nsStringToJuce ([error description]));
  200072. hasFailed = true;
  200073. initialised = true;
  200074. if (runLoopThread != 0)
  200075. runLoopThread->signalThreadShouldExit();
  200076. }
  200077. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200078. {
  200079. [dataLock lock];
  200080. [data appendData: newData];
  200081. [dataLock unlock];
  200082. initialised = true;
  200083. }
  200084. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200085. {
  200086. hasFinished = true;
  200087. initialised = true;
  200088. if (runLoopThread != 0)
  200089. runLoopThread->signalThreadShouldExit();
  200090. }
  200091. - (BOOL) isOpen
  200092. {
  200093. return connection != 0 && ! hasFailed;
  200094. }
  200095. - (int) readPosition
  200096. {
  200097. return position;
  200098. }
  200099. - (int) read: (char*) dest numBytes: (int) numNeeded
  200100. {
  200101. int numDone = 0;
  200102. while (numNeeded > 0)
  200103. {
  200104. int available = jmin (numNeeded, (int) [data length]);
  200105. if (available > 0)
  200106. {
  200107. [dataLock lock];
  200108. [data getBytes: dest length: available];
  200109. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200110. [dataLock unlock];
  200111. numDone += available;
  200112. numNeeded -= available;
  200113. dest += available;
  200114. }
  200115. else
  200116. {
  200117. if (hasFailed || hasFinished)
  200118. break;
  200119. Thread::sleep (1);
  200120. }
  200121. }
  200122. position += numDone;
  200123. return numDone;
  200124. }
  200125. - (void) stop
  200126. {
  200127. [connection cancel];
  200128. if (runLoopThread != 0)
  200129. runLoopThread->stopThread (10000);
  200130. }
  200131. @end
  200132. BEGIN_JUCE_NAMESPACE
  200133. bool juce_isOnLine()
  200134. {
  200135. return true;
  200136. }
  200137. void* juce_openInternetFile (const String& url,
  200138. const String& headers,
  200139. const MemoryBlock& postData,
  200140. const bool isPost,
  200141. URL::OpenStreamProgressCallback* callback,
  200142. void* callbackContext,
  200143. int timeOutMs)
  200144. {
  200145. const ScopedAutoReleasePool pool;
  200146. NSMutableURLRequest* req = [NSMutableURLRequest
  200147. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200148. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200149. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200150. if (req == nil)
  200151. return 0;
  200152. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200153. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200154. StringArray headerLines;
  200155. headerLines.addLines (headers);
  200156. headerLines.removeEmptyStrings (true);
  200157. for (int i = 0; i < headerLines.size(); ++i)
  200158. {
  200159. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  200160. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  200161. if (key.isNotEmpty() && value.isNotEmpty())
  200162. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200163. }
  200164. if (isPost && postData.getSize() > 0)
  200165. {
  200166. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200167. length: postData.getSize()]];
  200168. }
  200169. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200170. withCallback: callback
  200171. withContext: callbackContext];
  200172. if ([s isOpen])
  200173. return s;
  200174. [s release];
  200175. return 0;
  200176. }
  200177. void juce_closeInternetFile (void* handle)
  200178. {
  200179. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200180. if (s != 0)
  200181. {
  200182. const ScopedAutoReleasePool pool;
  200183. [s stop];
  200184. [s release];
  200185. }
  200186. }
  200187. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200188. {
  200189. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200190. if (s != 0)
  200191. {
  200192. const ScopedAutoReleasePool pool;
  200193. return [s read: (char*) buffer numBytes: bytesToRead];
  200194. }
  200195. return 0;
  200196. }
  200197. int64 juce_getInternetFileContentLength (void* handle)
  200198. {
  200199. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200200. if (s != 0)
  200201. return s->contentLength;
  200202. return -1;
  200203. }
  200204. int juce_seekInInternetFile (void* handle, int newPosition)
  200205. {
  200206. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200207. if (s != 0)
  200208. return [s readPosition];
  200209. return 0;
  200210. }
  200211. #endif
  200212. /*** End of inlined file: juce_mac_Network.mm ***/
  200213. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200214. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200215. // compiled on its own).
  200216. #if JUCE_INCLUDED_FILE
  200217. struct NamedPipeInternal
  200218. {
  200219. String pipeInName, pipeOutName;
  200220. int pipeIn, pipeOut;
  200221. bool volatile createdPipe, blocked, stopReadOperation;
  200222. static void signalHandler (int) {}
  200223. };
  200224. void NamedPipe::cancelPendingReads()
  200225. {
  200226. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200227. {
  200228. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200229. intern->stopReadOperation = true;
  200230. char buffer [1] = { 0 };
  200231. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200232. (void) bytesWritten;
  200233. int timeout = 2000;
  200234. while (intern->blocked && --timeout >= 0)
  200235. Thread::sleep (2);
  200236. intern->stopReadOperation = false;
  200237. }
  200238. }
  200239. void NamedPipe::close()
  200240. {
  200241. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200242. if (intern != 0)
  200243. {
  200244. internal = 0;
  200245. if (intern->pipeIn != -1)
  200246. ::close (intern->pipeIn);
  200247. if (intern->pipeOut != -1)
  200248. ::close (intern->pipeOut);
  200249. if (intern->createdPipe)
  200250. {
  200251. unlink (intern->pipeInName.toUTF8());
  200252. unlink (intern->pipeOutName.toUTF8());
  200253. }
  200254. delete intern;
  200255. }
  200256. }
  200257. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200258. {
  200259. close();
  200260. NamedPipeInternal* const intern = new NamedPipeInternal();
  200261. internal = intern;
  200262. intern->createdPipe = createPipe;
  200263. intern->blocked = false;
  200264. intern->stopReadOperation = false;
  200265. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200266. siginterrupt (SIGPIPE, 1);
  200267. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200268. intern->pipeInName = pipePath + "_in";
  200269. intern->pipeOutName = pipePath + "_out";
  200270. intern->pipeIn = -1;
  200271. intern->pipeOut = -1;
  200272. if (createPipe)
  200273. {
  200274. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200275. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200276. {
  200277. delete intern;
  200278. internal = 0;
  200279. return false;
  200280. }
  200281. }
  200282. return true;
  200283. }
  200284. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200285. {
  200286. int bytesRead = -1;
  200287. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200288. if (intern != 0)
  200289. {
  200290. intern->blocked = true;
  200291. if (intern->pipeIn == -1)
  200292. {
  200293. if (intern->createdPipe)
  200294. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200295. else
  200296. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200297. if (intern->pipeIn == -1)
  200298. {
  200299. intern->blocked = false;
  200300. return -1;
  200301. }
  200302. }
  200303. bytesRead = 0;
  200304. char* p = (char*) destBuffer;
  200305. while (bytesRead < maxBytesToRead)
  200306. {
  200307. const int bytesThisTime = maxBytesToRead - bytesRead;
  200308. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200309. if (numRead <= 0 || intern->stopReadOperation)
  200310. {
  200311. bytesRead = -1;
  200312. break;
  200313. }
  200314. bytesRead += numRead;
  200315. p += bytesRead;
  200316. }
  200317. intern->blocked = false;
  200318. }
  200319. return bytesRead;
  200320. }
  200321. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200322. {
  200323. int bytesWritten = -1;
  200324. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200325. if (intern != 0)
  200326. {
  200327. if (intern->pipeOut == -1)
  200328. {
  200329. if (intern->createdPipe)
  200330. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200331. else
  200332. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200333. if (intern->pipeOut == -1)
  200334. {
  200335. return -1;
  200336. }
  200337. }
  200338. const char* p = (const char*) sourceBuffer;
  200339. bytesWritten = 0;
  200340. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200341. while (bytesWritten < numBytesToWrite
  200342. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200343. {
  200344. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200345. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200346. if (numWritten <= 0)
  200347. {
  200348. bytesWritten = -1;
  200349. break;
  200350. }
  200351. bytesWritten += numWritten;
  200352. p += bytesWritten;
  200353. }
  200354. }
  200355. return bytesWritten;
  200356. }
  200357. #endif
  200358. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200359. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200360. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200361. // compiled on its own).
  200362. #if JUCE_INCLUDED_FILE
  200363. void JUCE_API juce_threadEntryPoint (void*);
  200364. void* threadEntryProc (void* userData)
  200365. {
  200366. const ScopedAutoReleasePool pool;
  200367. juce_threadEntryPoint (userData);
  200368. return 0;
  200369. }
  200370. void* juce_createThread (void* userData)
  200371. {
  200372. pthread_t handle = 0;
  200373. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200374. {
  200375. pthread_detach (handle);
  200376. return (void*) handle;
  200377. }
  200378. return 0;
  200379. }
  200380. void juce_killThread (void* handle)
  200381. {
  200382. if (handle != 0)
  200383. pthread_cancel ((pthread_t) handle);
  200384. }
  200385. void juce_setCurrentThreadName (const String& /*name*/)
  200386. {
  200387. }
  200388. bool juce_setThreadPriority (void* handle, int priority)
  200389. {
  200390. if (handle == 0)
  200391. handle = (void*) pthread_self();
  200392. struct sched_param param;
  200393. int policy;
  200394. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200395. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200396. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200397. }
  200398. Thread::ThreadID Thread::getCurrentThreadId()
  200399. {
  200400. return static_cast <ThreadID> (pthread_self());
  200401. }
  200402. void Thread::yield()
  200403. {
  200404. sched_yield();
  200405. }
  200406. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200407. {
  200408. // xxx
  200409. jassertfalse
  200410. }
  200411. bool Process::isForegroundProcess()
  200412. {
  200413. #if JUCE_MAC
  200414. return [NSApp isActive];
  200415. #else
  200416. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200417. #endif
  200418. }
  200419. void Process::raisePrivilege()
  200420. {
  200421. jassertfalse
  200422. }
  200423. void Process::lowerPrivilege()
  200424. {
  200425. jassertfalse
  200426. }
  200427. void Process::terminate()
  200428. {
  200429. exit (0);
  200430. }
  200431. void Process::setPriority (ProcessPriority p)
  200432. {
  200433. // xxx
  200434. }
  200435. #endif
  200436. /*** End of inlined file: juce_mac_Threads.mm ***/
  200437. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200438. CriticalSection::CriticalSection() throw()
  200439. {
  200440. pthread_mutexattr_t atts;
  200441. pthread_mutexattr_init (&atts);
  200442. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200443. pthread_mutex_init (&internal, &atts);
  200444. }
  200445. CriticalSection::~CriticalSection() throw()
  200446. {
  200447. pthread_mutex_destroy (&internal);
  200448. }
  200449. void CriticalSection::enter() const throw()
  200450. {
  200451. pthread_mutex_lock (&internal);
  200452. }
  200453. bool CriticalSection::tryEnter() const throw()
  200454. {
  200455. return pthread_mutex_trylock (&internal) == 0;
  200456. }
  200457. void CriticalSection::exit() const throw()
  200458. {
  200459. pthread_mutex_unlock (&internal);
  200460. }
  200461. class WaitableEventImpl
  200462. {
  200463. public:
  200464. WaitableEventImpl (const bool manualReset_)
  200465. : triggered (false),
  200466. manualReset (manualReset_)
  200467. {
  200468. pthread_cond_init (&condition, 0);
  200469. pthread_mutex_init (&mutex, 0);
  200470. }
  200471. ~WaitableEventImpl()
  200472. {
  200473. pthread_cond_destroy (&condition);
  200474. pthread_mutex_destroy (&mutex);
  200475. }
  200476. bool wait (const int timeOutMillisecs) throw()
  200477. {
  200478. pthread_mutex_lock (&mutex);
  200479. if (! triggered)
  200480. {
  200481. if (timeOutMillisecs < 0)
  200482. {
  200483. do
  200484. {
  200485. pthread_cond_wait (&condition, &mutex);
  200486. }
  200487. while (! triggered);
  200488. }
  200489. else
  200490. {
  200491. struct timeval now;
  200492. gettimeofday (&now, 0);
  200493. struct timespec time;
  200494. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200495. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200496. if (time.tv_nsec >= 1000000000)
  200497. {
  200498. time.tv_nsec -= 1000000000;
  200499. time.tv_sec++;
  200500. }
  200501. do
  200502. {
  200503. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200504. {
  200505. pthread_mutex_unlock (&mutex);
  200506. return false;
  200507. }
  200508. }
  200509. while (! triggered);
  200510. }
  200511. }
  200512. if (! manualReset)
  200513. triggered = false;
  200514. pthread_mutex_unlock (&mutex);
  200515. return true;
  200516. }
  200517. void signal() throw()
  200518. {
  200519. pthread_mutex_lock (&mutex);
  200520. triggered = true;
  200521. pthread_cond_broadcast (&condition);
  200522. pthread_mutex_unlock (&mutex);
  200523. }
  200524. void reset() throw()
  200525. {
  200526. pthread_mutex_lock (&mutex);
  200527. triggered = false;
  200528. pthread_mutex_unlock (&mutex);
  200529. }
  200530. private:
  200531. pthread_cond_t condition;
  200532. pthread_mutex_t mutex;
  200533. bool triggered;
  200534. const bool manualReset;
  200535. WaitableEventImpl (const WaitableEventImpl&);
  200536. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200537. };
  200538. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  200539. : internal (new WaitableEventImpl (manualReset))
  200540. {
  200541. }
  200542. WaitableEvent::~WaitableEvent() throw()
  200543. {
  200544. delete static_cast <WaitableEventImpl*> (internal);
  200545. }
  200546. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200547. {
  200548. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200549. }
  200550. void WaitableEvent::signal() const throw()
  200551. {
  200552. static_cast <WaitableEventImpl*> (internal)->signal();
  200553. }
  200554. void WaitableEvent::reset() const throw()
  200555. {
  200556. static_cast <WaitableEventImpl*> (internal)->reset();
  200557. }
  200558. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200559. {
  200560. struct timespec time;
  200561. time.tv_sec = millisecs / 1000;
  200562. time.tv_nsec = (millisecs % 1000) * 1000000;
  200563. nanosleep (&time, 0);
  200564. }
  200565. const juce_wchar File::separator = '/';
  200566. const juce_wchar* File::separatorString = L"/";
  200567. const File File::getCurrentWorkingDirectory()
  200568. {
  200569. HeapBlock<char> heapBuffer;
  200570. char localBuffer [1024];
  200571. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200572. int bufferSize = 4096;
  200573. while (cwd == 0 && errno == ERANGE)
  200574. {
  200575. heapBuffer.malloc (bufferSize);
  200576. cwd = getcwd (heapBuffer, bufferSize - 1);
  200577. bufferSize += 1024;
  200578. }
  200579. return File (String::fromUTF8 (cwd));
  200580. }
  200581. bool File::setAsCurrentWorkingDirectory() const
  200582. {
  200583. return chdir (getFullPathName().toUTF8()) == 0;
  200584. }
  200585. bool juce_copyFile (const String& s, const String& d);
  200586. static bool juce_stat (const String& fileName, struct stat& info)
  200587. {
  200588. return fileName.isNotEmpty()
  200589. && (stat (fileName.toUTF8(), &info) == 0);
  200590. }
  200591. bool juce_isDirectory (const String& fileName)
  200592. {
  200593. struct stat info;
  200594. return fileName.isEmpty()
  200595. || (juce_stat (fileName, info)
  200596. && ((info.st_mode & S_IFDIR) != 0));
  200597. }
  200598. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200599. {
  200600. if (fileName.isEmpty())
  200601. return false;
  200602. const char* const fileNameUTF8 = fileName.toUTF8();
  200603. bool exists = access (fileNameUTF8, F_OK) == 0;
  200604. if (exists && dontCountDirectories)
  200605. {
  200606. struct stat info;
  200607. const int res = stat (fileNameUTF8, &info);
  200608. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200609. exists = false;
  200610. }
  200611. return exists;
  200612. }
  200613. int64 juce_getFileSize (const String& fileName)
  200614. {
  200615. struct stat info;
  200616. return juce_stat (fileName, info) ? info.st_size : 0;
  200617. }
  200618. bool juce_canWriteToFile (const String& fileName)
  200619. {
  200620. return access (fileName.toUTF8(), W_OK) == 0;
  200621. }
  200622. bool juce_deleteFile (const String& fileName)
  200623. {
  200624. if (juce_isDirectory (fileName))
  200625. return rmdir (fileName.toUTF8()) == 0;
  200626. else
  200627. return remove (fileName.toUTF8()) == 0;
  200628. }
  200629. bool juce_moveFile (const String& source, const String& dest)
  200630. {
  200631. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200632. return true;
  200633. if (juce_canWriteToFile (source)
  200634. && juce_copyFile (source, dest))
  200635. {
  200636. if (juce_deleteFile (source))
  200637. return true;
  200638. juce_deleteFile (dest);
  200639. }
  200640. return false;
  200641. }
  200642. void juce_createDirectory (const String& fileName)
  200643. {
  200644. mkdir (fileName.toUTF8(), 0777);
  200645. }
  200646. void* juce_fileOpen (const String& fileName, bool forWriting)
  200647. {
  200648. int flags = O_RDONLY;
  200649. if (forWriting)
  200650. {
  200651. if (juce_fileExists (fileName, false))
  200652. {
  200653. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200654. if (f != -1)
  200655. lseek (f, 0, SEEK_END);
  200656. return (void*) f;
  200657. }
  200658. else
  200659. {
  200660. flags = O_RDWR + O_CREAT;
  200661. }
  200662. }
  200663. return (void*) open (fileName.toUTF8(), flags, 00644);
  200664. }
  200665. void juce_fileClose (void* handle)
  200666. {
  200667. if (handle != 0)
  200668. close ((int) (pointer_sized_int) handle);
  200669. }
  200670. int juce_fileRead (void* handle, void* buffer, int size)
  200671. {
  200672. if (handle != 0)
  200673. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200674. return 0;
  200675. }
  200676. int juce_fileWrite (void* handle, const void* buffer, int size)
  200677. {
  200678. if (handle != 0)
  200679. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200680. return 0;
  200681. }
  200682. int64 juce_fileSetPosition (void* handle, int64 pos)
  200683. {
  200684. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200685. return pos;
  200686. return -1;
  200687. }
  200688. int64 juce_fileGetPosition (void* handle)
  200689. {
  200690. if (handle != 0)
  200691. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200692. return -1;
  200693. }
  200694. void juce_fileFlush (void* handle)
  200695. {
  200696. if (handle != 0)
  200697. fsync ((int) (pointer_sized_int) handle);
  200698. }
  200699. const File juce_getExecutableFile()
  200700. {
  200701. Dl_info exeInfo;
  200702. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200703. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200704. }
  200705. // if this file doesn't exist, find a parent of it that does..
  200706. static bool doStatFS (const File* file, struct statfs& result)
  200707. {
  200708. File f (*file);
  200709. for (int i = 5; --i >= 0;)
  200710. {
  200711. if (f.exists())
  200712. break;
  200713. f = f.getParentDirectory();
  200714. }
  200715. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200716. }
  200717. int64 File::getBytesFreeOnVolume() const
  200718. {
  200719. struct statfs buf;
  200720. if (doStatFS (this, buf))
  200721. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200722. return 0;
  200723. }
  200724. int64 File::getVolumeTotalSize() const
  200725. {
  200726. struct statfs buf;
  200727. if (doStatFS (this, buf))
  200728. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200729. return 0;
  200730. }
  200731. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200732. int& volumeSerialNumber)
  200733. {
  200734. volumeSerialNumber = 0;
  200735. #if JUCE_MAC
  200736. struct VolAttrBuf
  200737. {
  200738. u_int32_t length;
  200739. attrreference_t mountPointRef;
  200740. char mountPointSpace [MAXPATHLEN];
  200741. } attrBuf;
  200742. struct attrlist attrList;
  200743. zerostruct (attrList);
  200744. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200745. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200746. File f (filenameOnVolume);
  200747. for (;;)
  200748. {
  200749. if (getattrlist (f.getFullPathName().toUTF8(),
  200750. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200751. {
  200752. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200753. (int) attrBuf.mountPointRef.attr_length);
  200754. }
  200755. const File parent (f.getParentDirectory());
  200756. if (f == parent)
  200757. break;
  200758. f = parent;
  200759. }
  200760. #endif
  200761. return String::empty;
  200762. }
  200763. void juce_runSystemCommand (const String& command)
  200764. {
  200765. int result = system (command.toUTF8());
  200766. (void) result;
  200767. }
  200768. const String juce_getOutputFromCommand (const String& command)
  200769. {
  200770. // slight bodge here, as we just pipe the output into a temp file and read it...
  200771. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200772. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200773. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200774. String result (tempFile.loadFileAsString());
  200775. tempFile.deleteFile();
  200776. return result;
  200777. }
  200778. class InterProcessLock::Pimpl
  200779. {
  200780. public:
  200781. Pimpl (const String& name, const int timeOutMillisecs)
  200782. : handle (0), refCount (1)
  200783. {
  200784. #if JUCE_MAC
  200785. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200786. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200787. #else
  200788. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200789. #endif
  200790. temp.create();
  200791. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200792. if (handle != 0)
  200793. {
  200794. struct flock fl;
  200795. zerostruct (fl);
  200796. fl.l_whence = SEEK_SET;
  200797. fl.l_type = F_WRLCK;
  200798. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200799. for (;;)
  200800. {
  200801. const int result = fcntl (handle, F_SETLK, &fl);
  200802. if (result >= 0)
  200803. return;
  200804. if (errno != EINTR)
  200805. {
  200806. if (timeOutMillisecs == 0
  200807. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200808. break;
  200809. Thread::sleep (10);
  200810. }
  200811. }
  200812. }
  200813. closeFile();
  200814. }
  200815. ~Pimpl()
  200816. {
  200817. closeFile();
  200818. }
  200819. void closeFile()
  200820. {
  200821. if (handle != 0)
  200822. {
  200823. struct flock fl;
  200824. zerostruct (fl);
  200825. fl.l_whence = SEEK_SET;
  200826. fl.l_type = F_UNLCK;
  200827. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  200828. {}
  200829. close (handle);
  200830. handle = 0;
  200831. }
  200832. }
  200833. int handle, refCount;
  200834. };
  200835. InterProcessLock::InterProcessLock (const String& name_)
  200836. : name (name_)
  200837. {
  200838. }
  200839. InterProcessLock::~InterProcessLock()
  200840. {
  200841. }
  200842. bool InterProcessLock::enter (const int timeOutMillisecs)
  200843. {
  200844. const ScopedLock sl (lock);
  200845. if (pimpl == 0)
  200846. {
  200847. pimpl = new Pimpl (name, timeOutMillisecs);
  200848. if (pimpl->handle == 0)
  200849. pimpl = 0;
  200850. }
  200851. else
  200852. {
  200853. pimpl->refCount++;
  200854. }
  200855. return pimpl != 0;
  200856. }
  200857. void InterProcessLock::exit()
  200858. {
  200859. const ScopedLock sl (lock);
  200860. // Trying to release the lock too many times!
  200861. jassert (pimpl != 0);
  200862. if (pimpl != 0 && --(pimpl->refCount) == 0)
  200863. pimpl = 0;
  200864. }
  200865. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200866. /*** Start of inlined file: juce_mac_Files.mm ***/
  200867. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200868. // compiled on its own).
  200869. #if JUCE_INCLUDED_FILE
  200870. void juce_getFileTimes (const String& fileName,
  200871. int64& modificationTime,
  200872. int64& accessTime,
  200873. int64& creationTime)
  200874. {
  200875. modificationTime = 0;
  200876. accessTime = 0;
  200877. creationTime = 0;
  200878. struct stat info;
  200879. const int res = stat (fileName.toUTF8(), &info);
  200880. if (res == 0)
  200881. {
  200882. modificationTime = (int64) info.st_mtime * 1000;
  200883. accessTime = (int64) info.st_atime * 1000;
  200884. creationTime = (int64) info.st_ctime * 1000;
  200885. }
  200886. }
  200887. bool juce_setFileTimes (const String& fileName,
  200888. int64 modificationTime,
  200889. int64 accessTime,
  200890. int64 creationTime)
  200891. {
  200892. struct utimbuf times;
  200893. times.actime = (time_t) (accessTime / 1000);
  200894. times.modtime = (time_t) (modificationTime / 1000);
  200895. return utime (fileName.toUTF8(), &times) == 0;
  200896. }
  200897. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200898. {
  200899. struct stat info;
  200900. const int res = stat (fileName.toUTF8(), &info);
  200901. if (res != 0)
  200902. return false;
  200903. info.st_mode &= 0777; // Just permissions
  200904. if (isReadOnly)
  200905. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200906. else
  200907. // Give everybody write permission?
  200908. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200909. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200910. }
  200911. bool juce_copyFile (const String& src, const String& dst)
  200912. {
  200913. const ScopedAutoReleasePool pool;
  200914. NSFileManager* fm = [NSFileManager defaultManager];
  200915. return [fm fileExistsAtPath: juceStringToNS (src)]
  200916. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200917. && [fm copyItemAtPath: juceStringToNS (src)
  200918. toPath: juceStringToNS (dst)
  200919. error: nil];
  200920. #else
  200921. && [fm copyPath: juceStringToNS (src)
  200922. toPath: juceStringToNS (dst)
  200923. handler: nil];
  200924. #endif
  200925. }
  200926. const StringArray juce_getFileSystemRoots()
  200927. {
  200928. StringArray s;
  200929. s.add ("/");
  200930. return s;
  200931. }
  200932. static bool isFileOnDriveType (const File* const f, const char** types)
  200933. {
  200934. struct statfs buf;
  200935. if (doStatFS (f, buf))
  200936. {
  200937. const String type (buf.f_fstypename);
  200938. while (*types != 0)
  200939. if (type.equalsIgnoreCase (*types++))
  200940. return true;
  200941. }
  200942. return false;
  200943. }
  200944. bool File::isOnCDRomDrive() const
  200945. {
  200946. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200947. return isFileOnDriveType (this, (const char**) cdTypes);
  200948. }
  200949. bool File::isOnHardDisk() const
  200950. {
  200951. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200952. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  200953. }
  200954. bool File::isOnRemovableDrive() const
  200955. {
  200956. #if JUCE_IPHONE
  200957. return false; // xxx is this possible?
  200958. #else
  200959. const ScopedAutoReleasePool pool;
  200960. BOOL removable = false;
  200961. [[NSWorkspace sharedWorkspace]
  200962. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200963. isRemovable: &removable
  200964. isWritable: nil
  200965. isUnmountable: nil
  200966. description: nil
  200967. type: nil];
  200968. return removable;
  200969. #endif
  200970. }
  200971. static bool juce_isHiddenFile (const String& path)
  200972. {
  200973. #if JUCE_IPHONE
  200974. return File (path).getFileName().startsWithChar ('.');
  200975. #else
  200976. FSRef ref;
  200977. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200978. return false;
  200979. FSCatalogInfo info;
  200980. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200981. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200982. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200983. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200984. #endif
  200985. }
  200986. bool File::isHidden() const
  200987. {
  200988. return juce_isHiddenFile (getFullPathName());
  200989. }
  200990. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200991. const File File::getSpecialLocation (const SpecialLocationType type)
  200992. {
  200993. const ScopedAutoReleasePool pool;
  200994. String resultPath;
  200995. switch (type)
  200996. {
  200997. case userHomeDirectory:
  200998. resultPath = nsStringToJuce (NSHomeDirectory());
  200999. break;
  201000. case userDocumentsDirectory:
  201001. resultPath = "~/Documents";
  201002. break;
  201003. case userDesktopDirectory:
  201004. resultPath = "~/Desktop";
  201005. break;
  201006. case userApplicationDataDirectory:
  201007. resultPath = "~/Library";
  201008. break;
  201009. case commonApplicationDataDirectory:
  201010. resultPath = "/Library";
  201011. break;
  201012. case globalApplicationsDirectory:
  201013. resultPath = "/Applications";
  201014. break;
  201015. case userMusicDirectory:
  201016. resultPath = "~/Music";
  201017. break;
  201018. case userMoviesDirectory:
  201019. resultPath = "~/Movies";
  201020. break;
  201021. case tempDirectory:
  201022. {
  201023. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  201024. tmp.createDirectory();
  201025. return tmp.getFullPathName();
  201026. }
  201027. case invokedExecutableFile:
  201028. if (juce_Argv0 != 0)
  201029. return File (String::fromUTF8 (juce_Argv0));
  201030. // deliberate fall-through...
  201031. case currentExecutableFile:
  201032. return juce_getExecutableFile();
  201033. case currentApplicationFile:
  201034. {
  201035. const File exe (juce_getExecutableFile());
  201036. const File parent (exe.getParentDirectory());
  201037. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  201038. ? parent.getParentDirectory().getParentDirectory()
  201039. : exe;
  201040. }
  201041. default:
  201042. jassertfalse // unknown type?
  201043. break;
  201044. }
  201045. if (resultPath.isNotEmpty())
  201046. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201047. return File::nonexistent;
  201048. }
  201049. const String File::getVersion() const
  201050. {
  201051. const ScopedAutoReleasePool pool;
  201052. String result;
  201053. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201054. if (bundle != 0)
  201055. {
  201056. NSDictionary* info = [bundle infoDictionary];
  201057. if (info != 0)
  201058. {
  201059. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201060. if (name != nil)
  201061. result = nsStringToJuce (name);
  201062. }
  201063. }
  201064. return result;
  201065. }
  201066. const File File::getLinkedTarget() const
  201067. {
  201068. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201069. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201070. #else
  201071. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201072. #endif
  201073. if (dest != nil)
  201074. return File (nsStringToJuce (dest));
  201075. return *this;
  201076. }
  201077. bool File::moveToTrash() const
  201078. {
  201079. if (! exists())
  201080. return true;
  201081. #if JUCE_IPHONE
  201082. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201083. #else
  201084. const ScopedAutoReleasePool pool;
  201085. NSString* p = juceStringToNS (getFullPathName());
  201086. return [[NSWorkspace sharedWorkspace]
  201087. performFileOperation: NSWorkspaceRecycleOperation
  201088. source: [p stringByDeletingLastPathComponent]
  201089. destination: @""
  201090. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201091. tag: nil ];
  201092. #endif
  201093. }
  201094. struct FindFileStruct
  201095. {
  201096. NSDirectoryEnumerator* enumerator;
  201097. String parentDir, wildCard;
  201098. };
  201099. bool juce_findFileNext (void* handle, String& resultFile,
  201100. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201101. {
  201102. ScopedAutoReleasePool pool;
  201103. FindFileStruct* ff = (FindFileStruct*) handle;
  201104. NSString* file;
  201105. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201106. for (;;)
  201107. {
  201108. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201109. return false;
  201110. [ff->enumerator skipDescendents];
  201111. resultFile = nsStringToJuce (file);
  201112. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201113. continue;
  201114. const String path (ff->parentDir + resultFile);
  201115. if (isDir != 0 || fileSize != 0)
  201116. {
  201117. struct stat info;
  201118. const bool statOk = juce_stat (path, info);
  201119. if (isDir != 0)
  201120. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201121. if (isHidden != 0)
  201122. *isHidden = juce_isHiddenFile (path);
  201123. if (fileSize != 0)
  201124. *fileSize = statOk ? info.st_size : 0;
  201125. }
  201126. if (modTime != 0 || creationTime != 0)
  201127. {
  201128. int64 m, a, c;
  201129. juce_getFileTimes (path, m, a, c);
  201130. if (modTime != 0)
  201131. *modTime = m;
  201132. if (creationTime != 0)
  201133. *creationTime = c;
  201134. }
  201135. if (isReadOnly != 0)
  201136. *isReadOnly = ! juce_canWriteToFile (path);
  201137. return true;
  201138. }
  201139. }
  201140. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201141. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201142. Time* creationTime, bool* isReadOnly)
  201143. {
  201144. ScopedAutoReleasePool pool;
  201145. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201146. if (e != 0)
  201147. {
  201148. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201149. ff->enumerator = [e retain];
  201150. ff->parentDir = directory;
  201151. ff->wildCard = wildCard;
  201152. if (! ff->parentDir.endsWithChar (File::separator))
  201153. ff->parentDir += File::separator;
  201154. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201155. return ff.release();
  201156. [e release];
  201157. }
  201158. return 0;
  201159. }
  201160. void juce_findFileClose (void* handle)
  201161. {
  201162. ScopedAutoReleasePool pool;
  201163. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201164. [ff->enumerator release];
  201165. }
  201166. bool juce_launchExecutable (const String& pathAndArguments)
  201167. {
  201168. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201169. const int cpid = fork();
  201170. if (cpid == 0)
  201171. {
  201172. // Child process
  201173. if (execve (argv[0], (char**) argv, 0) < 0)
  201174. exit (0);
  201175. }
  201176. else
  201177. {
  201178. if (cpid < 0)
  201179. return false;
  201180. }
  201181. return true;
  201182. }
  201183. bool juce_launchFile (const String& fileName, const String& parameters)
  201184. {
  201185. #if JUCE_IPHONE
  201186. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201187. #else
  201188. const ScopedAutoReleasePool pool;
  201189. if (parameters.isEmpty())
  201190. {
  201191. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201192. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201193. }
  201194. bool ok = false;
  201195. FSRef ref;
  201196. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201197. {
  201198. if (PlatformUtilities::isBundle (fileName))
  201199. {
  201200. NSMutableArray* urls = [NSMutableArray array];
  201201. StringArray docs;
  201202. docs.addTokens (parameters, true);
  201203. for (int i = 0; i < docs.size(); ++i)
  201204. [urls addObject: juceStringToNS (docs[i])];
  201205. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201206. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201207. options: 0
  201208. additionalEventParamDescriptor: nil
  201209. launchIdentifiers: nil];
  201210. }
  201211. else
  201212. {
  201213. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201214. }
  201215. }
  201216. return ok;
  201217. #endif
  201218. }
  201219. void File::revealToUser() const
  201220. {
  201221. #if ! JUCE_IPHONE
  201222. if (exists())
  201223. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201224. else if (getParentDirectory().exists())
  201225. getParentDirectory().revealToUser();
  201226. #endif
  201227. }
  201228. #if ! JUCE_IPHONE
  201229. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201230. {
  201231. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201232. }
  201233. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201234. {
  201235. char path [2048];
  201236. zerostruct (path);
  201237. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201238. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201239. return String::empty;
  201240. }
  201241. #endif
  201242. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201243. {
  201244. const ScopedAutoReleasePool pool;
  201245. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201246. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201247. #else
  201248. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201249. #endif
  201250. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201251. return [fileDict fileHFSTypeCode];
  201252. }
  201253. bool PlatformUtilities::isBundle (const String& filename)
  201254. {
  201255. #if JUCE_IPHONE
  201256. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201257. #else
  201258. const ScopedAutoReleasePool pool;
  201259. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201260. #endif
  201261. }
  201262. #endif
  201263. /*** End of inlined file: juce_mac_Files.mm ***/
  201264. #if JUCE_IPHONE
  201265. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201266. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201267. // compiled on its own).
  201268. #if JUCE_INCLUDED_FILE
  201269. static JUCEApplication* juce_intialisingApp;
  201270. END_JUCE_NAMESPACE
  201271. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201272. {
  201273. }
  201274. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201275. - (void) applicationWillResignActive: (UIApplication*) application;
  201276. @end
  201277. @implementation JuceAppStartupDelegate
  201278. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201279. {
  201280. String dummy;
  201281. if (! juce_intialisingApp->initialiseApp (dummy))
  201282. exit (0);
  201283. }
  201284. - (void) applicationWillResignActive: (UIApplication*) application
  201285. {
  201286. JUCEApplication::shutdownAppAndClearUp();
  201287. }
  201288. @end
  201289. BEGIN_JUCE_NAMESPACE
  201290. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201291. {
  201292. juce_intialisingApp = app;
  201293. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201294. }
  201295. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201296. {
  201297. pool = [[NSAutoreleasePool alloc] init];
  201298. }
  201299. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201300. {
  201301. [((NSAutoreleasePool*) pool) release];
  201302. }
  201303. void PlatformUtilities::beep()
  201304. {
  201305. //xxx
  201306. //AudioServicesPlaySystemSound ();
  201307. }
  201308. void PlatformUtilities::addItemToDock (const File& file)
  201309. {
  201310. }
  201311. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201312. END_JUCE_NAMESPACE
  201313. @interface JuceAlertBoxDelegate : NSObject
  201314. {
  201315. @public
  201316. bool clickedOk;
  201317. }
  201318. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201319. @end
  201320. @implementation JuceAlertBoxDelegate
  201321. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201322. {
  201323. clickedOk = (buttonIndex == 0);
  201324. alertView.hidden = true;
  201325. }
  201326. @end
  201327. BEGIN_JUCE_NAMESPACE
  201328. // (This function is used directly by other bits of code)
  201329. bool juce_iPhoneShowModalAlert (const String& title,
  201330. const String& bodyText,
  201331. NSString* okButtonText,
  201332. NSString* cancelButtonText)
  201333. {
  201334. const ScopedAutoReleasePool pool;
  201335. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201336. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201337. message: juceStringToNS (bodyText)
  201338. delegate: callback
  201339. cancelButtonTitle: okButtonText
  201340. otherButtonTitles: cancelButtonText, nil];
  201341. [alert retain];
  201342. [alert show];
  201343. while (! alert.hidden && alert.superview != nil)
  201344. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201345. const bool result = callback->clickedOk;
  201346. [alert release];
  201347. [callback release];
  201348. return result;
  201349. }
  201350. bool AlertWindow::showNativeDialogBox (const String& title,
  201351. const String& bodyText,
  201352. bool isOkCancel)
  201353. {
  201354. return juce_iPhoneShowModalAlert (title, bodyText,
  201355. @"OK",
  201356. isOkCancel ? @"Cancel" : nil);
  201357. }
  201358. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201359. {
  201360. jassertfalse // no such thing on the iphone!
  201361. return false;
  201362. }
  201363. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201364. {
  201365. jassertfalse // no such thing on the iphone!
  201366. return false;
  201367. }
  201368. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201369. {
  201370. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201371. }
  201372. bool Desktop::isScreenSaverEnabled() throw()
  201373. {
  201374. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201375. }
  201376. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201377. {
  201378. const ScopedAutoReleasePool pool;
  201379. monitorCoords.clear();
  201380. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201381. : [[UIScreen mainScreen] bounds];
  201382. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201383. (int) r.origin.y,
  201384. (int) r.size.width,
  201385. (int) r.size.height));
  201386. }
  201387. #endif
  201388. #endif
  201389. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201390. #else
  201391. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201392. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201393. // compiled on its own).
  201394. #if JUCE_INCLUDED_FILE
  201395. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201396. {
  201397. pool = [[NSAutoreleasePool alloc] init];
  201398. }
  201399. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201400. {
  201401. [((NSAutoreleasePool*) pool) release];
  201402. }
  201403. void PlatformUtilities::beep()
  201404. {
  201405. NSBeep();
  201406. }
  201407. void PlatformUtilities::addItemToDock (const File& file)
  201408. {
  201409. // check that it's not already there...
  201410. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201411. .containsIgnoreCase (file.getFullPathName()))
  201412. {
  201413. 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>"
  201414. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201415. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201416. }
  201417. }
  201418. int PlatformUtilities::getOSXMinorVersionNumber()
  201419. {
  201420. SInt32 versionMinor = 0;
  201421. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201422. (void) err;
  201423. jassert (err == noErr);
  201424. return (int) versionMinor;
  201425. }
  201426. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201427. bool AlertWindow::showNativeDialogBox (const String& title,
  201428. const String& bodyText,
  201429. bool isOkCancel)
  201430. {
  201431. const ScopedAutoReleasePool pool;
  201432. return NSRunAlertPanel (juceStringToNS (title),
  201433. juceStringToNS (bodyText),
  201434. @"Ok",
  201435. isOkCancel ? @"Cancel" : nil,
  201436. nil) == NSAlertDefaultReturn;
  201437. }
  201438. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201439. {
  201440. if (files.size() == 0)
  201441. return false;
  201442. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201443. if (draggingSource == 0)
  201444. {
  201445. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201446. return false;
  201447. }
  201448. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201449. if (sourceComp == 0)
  201450. {
  201451. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201452. return false;
  201453. }
  201454. const ScopedAutoReleasePool pool;
  201455. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201456. if (view == 0)
  201457. return false;
  201458. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201459. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201460. owner: nil];
  201461. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201462. for (int i = 0; i < files.size(); ++i)
  201463. [filesArray addObject: juceStringToNS (files[i])];
  201464. [pboard setPropertyList: filesArray
  201465. forType: NSFilenamesPboardType];
  201466. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201467. fromView: nil];
  201468. dragPosition.x -= 16;
  201469. dragPosition.y -= 16;
  201470. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201471. at: dragPosition
  201472. offset: NSMakeSize (0, 0)
  201473. event: [[view window] currentEvent]
  201474. pasteboard: pboard
  201475. source: view
  201476. slideBack: YES];
  201477. return true;
  201478. }
  201479. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201480. {
  201481. jassertfalse // not implemented!
  201482. return false;
  201483. }
  201484. bool Desktop::canUseSemiTransparentWindows() throw()
  201485. {
  201486. return true;
  201487. }
  201488. const Point<int> Desktop::getMousePosition()
  201489. {
  201490. const ScopedAutoReleasePool pool;
  201491. const NSPoint p ([NSEvent mouseLocation]);
  201492. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201493. }
  201494. void Desktop::setMousePosition (const Point<int>& newPosition)
  201495. {
  201496. // this rubbish needs to be done around the warp call, to avoid causing a
  201497. // bizarre glitch..
  201498. CGAssociateMouseAndMouseCursorPosition (false);
  201499. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201500. CGAssociateMouseAndMouseCursorPosition (true);
  201501. }
  201502. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201503. class ScreenSaverDefeater : public Timer,
  201504. public DeletedAtShutdown
  201505. {
  201506. public:
  201507. ScreenSaverDefeater() throw()
  201508. {
  201509. startTimer (10000);
  201510. timerCallback();
  201511. }
  201512. ~ScreenSaverDefeater() {}
  201513. void timerCallback()
  201514. {
  201515. if (Process::isForegroundProcess())
  201516. UpdateSystemActivity (UsrActivity);
  201517. }
  201518. };
  201519. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201520. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201521. {
  201522. if (isEnabled)
  201523. {
  201524. deleteAndZero (screenSaverDefeater);
  201525. }
  201526. else if (screenSaverDefeater == 0)
  201527. {
  201528. screenSaverDefeater = new ScreenSaverDefeater();
  201529. }
  201530. }
  201531. bool Desktop::isScreenSaverEnabled() throw()
  201532. {
  201533. return screenSaverDefeater == 0;
  201534. }
  201535. #else
  201536. static IOPMAssertionID screenSaverDisablerID = 0;
  201537. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201538. {
  201539. if (isEnabled)
  201540. {
  201541. if (screenSaverDisablerID != 0)
  201542. {
  201543. IOPMAssertionRelease (screenSaverDisablerID);
  201544. screenSaverDisablerID = 0;
  201545. }
  201546. }
  201547. else
  201548. {
  201549. if (screenSaverDisablerID == 0)
  201550. {
  201551. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201552. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201553. CFSTR ("Juce"), &screenSaverDisablerID);
  201554. #else
  201555. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201556. &screenSaverDisablerID);
  201557. #endif
  201558. }
  201559. }
  201560. }
  201561. bool Desktop::isScreenSaverEnabled() throw()
  201562. {
  201563. return screenSaverDisablerID == 0;
  201564. }
  201565. #endif
  201566. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201567. {
  201568. const ScopedAutoReleasePool pool;
  201569. monitorCoords.clear();
  201570. NSArray* screens = [NSScreen screens];
  201571. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201572. for (unsigned int i = 0; i < [screens count]; ++i)
  201573. {
  201574. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201575. NSRect r = clipToWorkArea ? [s visibleFrame]
  201576. : [s frame];
  201577. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201578. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201579. (int) r.size.width,
  201580. (int) r.size.height));
  201581. }
  201582. jassert (monitorCoords.size() > 0);
  201583. }
  201584. #endif
  201585. #endif
  201586. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201587. #endif
  201588. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201589. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201590. // compiled on its own).
  201591. #if JUCE_INCLUDED_FILE
  201592. void Logger::outputDebugString (const String& text) throw()
  201593. {
  201594. std::cerr << text << std::endl;
  201595. }
  201596. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201597. {
  201598. static char testResult = 0;
  201599. if (testResult == 0)
  201600. {
  201601. struct kinfo_proc info;
  201602. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201603. size_t sz = sizeof (info);
  201604. sysctl (m, 4, &info, &sz, 0, 0);
  201605. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201606. }
  201607. return testResult > 0;
  201608. }
  201609. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201610. {
  201611. return juce_isRunningUnderDebugger();
  201612. }
  201613. #endif
  201614. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201615. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201616. #if JUCE_IPHONE
  201617. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201618. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201619. // compiled on its own).
  201620. #if JUCE_INCLUDED_FILE
  201621. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201622. #define SUPPORT_10_4_FONTS 1
  201623. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201624. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201625. #define SUPPORT_ONLY_10_4_FONTS 1
  201626. #endif
  201627. END_JUCE_NAMESPACE
  201628. @interface NSFont (PrivateHack)
  201629. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201630. @end
  201631. BEGIN_JUCE_NAMESPACE
  201632. #endif
  201633. class MacTypeface : public Typeface
  201634. {
  201635. public:
  201636. MacTypeface (const Font& font)
  201637. : Typeface (font.getTypefaceName())
  201638. {
  201639. const ScopedAutoReleasePool pool;
  201640. renderingTransform = CGAffineTransformIdentity;
  201641. bool needsItalicTransform = false;
  201642. #if JUCE_IPHONE
  201643. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201644. if (font.isItalic() || font.isBold())
  201645. {
  201646. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201647. for (NSString* i in familyFonts)
  201648. {
  201649. const String fn (nsStringToJuce (i));
  201650. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201651. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201652. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201653. || afterDash.containsIgnoreCase ("italic")
  201654. || fn.endsWithIgnoreCase ("oblique")
  201655. || fn.endsWithIgnoreCase ("italic");
  201656. if (probablyBold == font.isBold()
  201657. && probablyItalic == font.isItalic())
  201658. {
  201659. fontName = i;
  201660. needsItalicTransform = false;
  201661. break;
  201662. }
  201663. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201664. {
  201665. fontName = i;
  201666. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201667. }
  201668. }
  201669. if (needsItalicTransform)
  201670. renderingTransform.c = 0.15f;
  201671. }
  201672. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201673. const int ascender = abs (CGFontGetAscent (fontRef));
  201674. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201675. ascent = ascender / totalHeight;
  201676. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201677. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201678. #else
  201679. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201680. if (font.isItalic())
  201681. {
  201682. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201683. toHaveTrait: NSItalicFontMask];
  201684. if (newFont == nsFont)
  201685. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201686. nsFont = newFont;
  201687. }
  201688. if (font.isBold())
  201689. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201690. [nsFont retain];
  201691. ascent = fabsf ((float) [nsFont ascender]);
  201692. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201693. ascent /= totalSize;
  201694. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201695. if (needsItalicTransform)
  201696. {
  201697. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201698. renderingTransform.c = 0.15f;
  201699. }
  201700. #if SUPPORT_ONLY_10_4_FONTS
  201701. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201702. if (atsFont == 0)
  201703. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201704. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201705. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201706. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201707. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201708. #else
  201709. #if SUPPORT_10_4_FONTS
  201710. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201711. {
  201712. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201713. if (atsFont == 0)
  201714. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201715. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201716. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201717. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201718. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201719. }
  201720. else
  201721. #endif
  201722. {
  201723. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201724. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201725. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201726. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201727. }
  201728. #endif
  201729. #endif
  201730. }
  201731. ~MacTypeface()
  201732. {
  201733. #if ! JUCE_IPHONE
  201734. [nsFont release];
  201735. #endif
  201736. if (fontRef != 0)
  201737. CGFontRelease (fontRef);
  201738. }
  201739. float getAscent() const
  201740. {
  201741. return ascent;
  201742. }
  201743. float getDescent() const
  201744. {
  201745. return 1.0f - ascent;
  201746. }
  201747. float getStringWidth (const String& text)
  201748. {
  201749. if (fontRef == 0 || text.isEmpty())
  201750. return 0;
  201751. const int length = text.length();
  201752. HeapBlock <CGGlyph> glyphs;
  201753. createGlyphsForString (text, length, glyphs);
  201754. float x = 0;
  201755. #if SUPPORT_ONLY_10_4_FONTS
  201756. HeapBlock <NSSize> advances (length);
  201757. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201758. for (int i = 0; i < length; ++i)
  201759. x += advances[i].width;
  201760. #else
  201761. #if SUPPORT_10_4_FONTS
  201762. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201763. {
  201764. HeapBlock <NSSize> advances (length);
  201765. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201766. for (int i = 0; i < length; ++i)
  201767. x += advances[i].width;
  201768. }
  201769. else
  201770. #endif
  201771. {
  201772. HeapBlock <int> advances (length);
  201773. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201774. for (int i = 0; i < length; ++i)
  201775. x += advances[i];
  201776. }
  201777. #endif
  201778. return x * unitsToHeightScaleFactor;
  201779. }
  201780. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201781. {
  201782. xOffsets.add (0);
  201783. if (fontRef == 0 || text.isEmpty())
  201784. return;
  201785. const int length = text.length();
  201786. HeapBlock <CGGlyph> glyphs;
  201787. createGlyphsForString (text, length, glyphs);
  201788. #if SUPPORT_ONLY_10_4_FONTS
  201789. HeapBlock <NSSize> advances (length);
  201790. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201791. int x = 0;
  201792. for (int i = 0; i < length; ++i)
  201793. {
  201794. x += advances[i].width;
  201795. xOffsets.add (x * unitsToHeightScaleFactor);
  201796. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201797. }
  201798. #else
  201799. #if SUPPORT_10_4_FONTS
  201800. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201801. {
  201802. HeapBlock <NSSize> advances (length);
  201803. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201804. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201805. float x = 0;
  201806. for (int i = 0; i < length; ++i)
  201807. {
  201808. x += advances[i].width;
  201809. xOffsets.add (x * unitsToHeightScaleFactor);
  201810. resultGlyphs.add (nsGlyphs[i]);
  201811. }
  201812. }
  201813. else
  201814. #endif
  201815. {
  201816. HeapBlock <int> advances (length);
  201817. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201818. {
  201819. int x = 0;
  201820. for (int i = 0; i < length; ++i)
  201821. {
  201822. x += advances [i];
  201823. xOffsets.add (x * unitsToHeightScaleFactor);
  201824. resultGlyphs.add (glyphs[i]);
  201825. }
  201826. }
  201827. }
  201828. #endif
  201829. }
  201830. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201831. {
  201832. #if JUCE_IPHONE
  201833. return false;
  201834. #else
  201835. if (nsFont == 0)
  201836. return false;
  201837. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201838. jassert (path.isEmpty());
  201839. const ScopedAutoReleasePool pool;
  201840. NSBezierPath* bez = [NSBezierPath bezierPath];
  201841. [bez moveToPoint: NSMakePoint (0, 0)];
  201842. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201843. inFont: nsFont];
  201844. for (int i = 0; i < [bez elementCount]; ++i)
  201845. {
  201846. NSPoint p[3];
  201847. switch ([bez elementAtIndex: i associatedPoints: p])
  201848. {
  201849. case NSMoveToBezierPathElement:
  201850. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201851. break;
  201852. case NSLineToBezierPathElement:
  201853. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201854. break;
  201855. case NSCurveToBezierPathElement:
  201856. 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);
  201857. break;
  201858. case NSClosePathBezierPathElement:
  201859. path.closeSubPath();
  201860. break;
  201861. default:
  201862. jassertfalse
  201863. break;
  201864. }
  201865. }
  201866. path.applyTransform (pathTransform);
  201867. return true;
  201868. #endif
  201869. }
  201870. juce_UseDebuggingNewOperator
  201871. CGFontRef fontRef;
  201872. float fontHeightToCGSizeFactor;
  201873. CGAffineTransform renderingTransform;
  201874. private:
  201875. float ascent, unitsToHeightScaleFactor;
  201876. #if JUCE_IPHONE
  201877. #else
  201878. NSFont* nsFont;
  201879. AffineTransform pathTransform;
  201880. #endif
  201881. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201882. {
  201883. #if SUPPORT_10_4_FONTS
  201884. #if ! SUPPORT_ONLY_10_4_FONTS
  201885. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201886. #endif
  201887. {
  201888. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201889. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201890. for (int i = 0; i < length; ++i)
  201891. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201892. return;
  201893. }
  201894. #endif
  201895. #if ! SUPPORT_ONLY_10_4_FONTS
  201896. if (charToGlyphMapper == 0)
  201897. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201898. glyphs.malloc (length);
  201899. for (int i = 0; i < length; ++i)
  201900. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201901. #endif
  201902. }
  201903. #if ! SUPPORT_ONLY_10_4_FONTS
  201904. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201905. class CharToGlyphMapper
  201906. {
  201907. public:
  201908. CharToGlyphMapper (CGFontRef fontRef)
  201909. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201910. idRangeOffset (0), glyphIndexes (0)
  201911. {
  201912. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201913. if (cmapTable != 0)
  201914. {
  201915. const int numSubtables = getValue16 (cmapTable, 2);
  201916. for (int i = 0; i < numSubtables; ++i)
  201917. {
  201918. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201919. {
  201920. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201921. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201922. {
  201923. const int length = getValue16 (cmapTable, offset + 2);
  201924. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201925. segCount = segCountX2 / 2;
  201926. const int endCodeOffset = offset + 14;
  201927. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201928. const int idDeltaOffset = startCodeOffset + segCountX2;
  201929. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201930. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201931. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201932. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201933. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201934. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201935. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201936. }
  201937. break;
  201938. }
  201939. }
  201940. CFRelease (cmapTable);
  201941. }
  201942. }
  201943. ~CharToGlyphMapper()
  201944. {
  201945. if (endCode != 0)
  201946. {
  201947. CFRelease (endCode);
  201948. CFRelease (startCode);
  201949. CFRelease (idDelta);
  201950. CFRelease (idRangeOffset);
  201951. CFRelease (glyphIndexes);
  201952. }
  201953. }
  201954. int getGlyphForCharacter (const juce_wchar c) const
  201955. {
  201956. for (int i = 0; i < segCount; ++i)
  201957. {
  201958. if (getValue16 (endCode, i * 2) >= c)
  201959. {
  201960. const int start = getValue16 (startCode, i * 2);
  201961. if (start > c)
  201962. break;
  201963. const int delta = getValue16 (idDelta, i * 2);
  201964. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201965. if (rangeOffset == 0)
  201966. return delta + c;
  201967. else
  201968. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201969. }
  201970. }
  201971. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201972. return jmax (-1, c - 29);
  201973. }
  201974. private:
  201975. int segCount;
  201976. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201977. static uint16 getValue16 (CFDataRef data, const int index)
  201978. {
  201979. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201980. }
  201981. static uint32 getValue32 (CFDataRef data, const int index)
  201982. {
  201983. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201984. }
  201985. };
  201986. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201987. #endif
  201988. MacTypeface (const MacTypeface&);
  201989. MacTypeface& operator= (const MacTypeface&);
  201990. };
  201991. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201992. {
  201993. return new MacTypeface (font);
  201994. }
  201995. const StringArray Font::findAllTypefaceNames()
  201996. {
  201997. StringArray names;
  201998. const ScopedAutoReleasePool pool;
  201999. #if JUCE_IPHONE
  202000. NSArray* fonts = [UIFont familyNames];
  202001. #else
  202002. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202003. #endif
  202004. for (unsigned int i = 0; i < [fonts count]; ++i)
  202005. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202006. names.sort (true);
  202007. return names;
  202008. }
  202009. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  202010. {
  202011. #if JUCE_IPHONE
  202012. defaultSans = "Helvetica";
  202013. defaultSerif = "Times New Roman";
  202014. defaultFixed = "Courier New";
  202015. #else
  202016. defaultSans = "Lucida Grande";
  202017. defaultSerif = "Times New Roman";
  202018. defaultFixed = "Monaco";
  202019. #endif
  202020. }
  202021. #endif
  202022. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202023. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202024. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202025. // compiled on its own).
  202026. #if JUCE_INCLUDED_FILE
  202027. class CoreGraphicsImage : public Image
  202028. {
  202029. public:
  202030. CoreGraphicsImage (const PixelFormat format_,
  202031. const int imageWidth_,
  202032. const int imageHeight_,
  202033. const bool clearImage)
  202034. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202035. {
  202036. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202037. : CGColorSpaceCreateDeviceRGB();
  202038. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202039. colourSpace, getCGImageFlags (*this));
  202040. CGColorSpaceRelease (colourSpace);
  202041. }
  202042. ~CoreGraphicsImage()
  202043. {
  202044. CGContextRelease (context);
  202045. }
  202046. LowLevelGraphicsContext* createLowLevelContext();
  202047. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202048. {
  202049. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202050. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202051. {
  202052. return CGBitmapContextCreateImage (nativeImage->context);
  202053. }
  202054. else
  202055. {
  202056. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202057. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202058. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202059. 8, srcData.pixelStride * 8, srcData.lineStride,
  202060. colourSpace, getCGImageFlags (juceImage), provider,
  202061. 0, true, kCGRenderingIntentDefault);
  202062. CGDataProviderRelease (provider);
  202063. return imageRef;
  202064. }
  202065. }
  202066. #if JUCE_MAC
  202067. static NSImage* createNSImage (const Image& image)
  202068. {
  202069. const ScopedAutoReleasePool pool;
  202070. NSImage* im = [[NSImage alloc] init];
  202071. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202072. [im lockFocus];
  202073. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202074. CGImageRef imageRef = createImage (image, false, colourSpace);
  202075. CGColorSpaceRelease (colourSpace);
  202076. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202077. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202078. CGImageRelease (imageRef);
  202079. [im unlockFocus];
  202080. return im;
  202081. }
  202082. #endif
  202083. CGContextRef context;
  202084. private:
  202085. static CGBitmapInfo getCGImageFlags (const Image& image)
  202086. {
  202087. #if JUCE_BIG_ENDIAN
  202088. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202089. #else
  202090. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202091. #endif
  202092. }
  202093. };
  202094. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202095. {
  202096. #if USE_COREGRAPHICS_RENDERING
  202097. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202098. #else
  202099. return new Image (format, imageWidth, imageHeight, clearImage);
  202100. #endif
  202101. }
  202102. class CoreGraphicsContext : public LowLevelGraphicsContext
  202103. {
  202104. public:
  202105. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202106. : context (context_),
  202107. flipHeight (flipHeight_),
  202108. state (new SavedState()),
  202109. numGradientLookupEntries (0)
  202110. {
  202111. CGContextRetain (context);
  202112. CGContextSaveGState(context);
  202113. CGContextSetShouldSmoothFonts (context, true);
  202114. CGContextSetShouldAntialias (context, true);
  202115. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202116. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202117. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202118. gradientCallbacks.version = 0;
  202119. gradientCallbacks.evaluate = gradientCallback;
  202120. gradientCallbacks.releaseInfo = 0;
  202121. setFont (Font());
  202122. }
  202123. ~CoreGraphicsContext()
  202124. {
  202125. CGContextRestoreGState (context);
  202126. CGContextRelease (context);
  202127. CGColorSpaceRelease (rgbColourSpace);
  202128. CGColorSpaceRelease (greyColourSpace);
  202129. }
  202130. bool isVectorDevice() const { return false; }
  202131. void setOrigin (int x, int y)
  202132. {
  202133. CGContextTranslateCTM (context, x, -y);
  202134. }
  202135. bool clipToRectangle (const Rectangle<int>& r)
  202136. {
  202137. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202138. return ! isClipEmpty();
  202139. }
  202140. bool clipToRectangleList (const RectangleList& clipRegion)
  202141. {
  202142. if (clipRegion.isEmpty())
  202143. {
  202144. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202145. return false;
  202146. }
  202147. else
  202148. {
  202149. const int numRects = clipRegion.getNumRectangles();
  202150. HeapBlock <CGRect> rects (numRects);
  202151. for (int i = 0; i < numRects; ++i)
  202152. {
  202153. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202154. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202155. }
  202156. CGContextClipToRects (context, rects, numRects);
  202157. return ! isClipEmpty();
  202158. }
  202159. }
  202160. void excludeClipRectangle (const Rectangle<int>& r)
  202161. {
  202162. RectangleList remaining (getClipBounds());
  202163. remaining.subtract (r);
  202164. clipToRectangleList (remaining);
  202165. }
  202166. void clipToPath (const Path& path, const AffineTransform& transform)
  202167. {
  202168. createPath (path, transform);
  202169. CGContextClip (context);
  202170. }
  202171. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202172. {
  202173. if (! transform.isSingularity())
  202174. {
  202175. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202176. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202177. flip();
  202178. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202179. applyTransform (t);
  202180. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202181. CGContextClipToMask (context, r, image);
  202182. applyTransform (t.inverted());
  202183. flip();
  202184. CGImageRelease (image);
  202185. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202186. }
  202187. }
  202188. bool clipRegionIntersects (const Rectangle<int>& r)
  202189. {
  202190. return getClipBounds().intersects (r);
  202191. }
  202192. const Rectangle<int> getClipBounds() const
  202193. {
  202194. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202195. return Rectangle<int> (roundToInt (bounds.origin.x),
  202196. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202197. roundToInt (bounds.size.width),
  202198. roundToInt (bounds.size.height));
  202199. }
  202200. bool isClipEmpty() const
  202201. {
  202202. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202203. }
  202204. void saveState()
  202205. {
  202206. CGContextSaveGState (context);
  202207. stateStack.add (new SavedState (*state));
  202208. }
  202209. void restoreState()
  202210. {
  202211. CGContextRestoreGState (context);
  202212. SavedState* const top = stateStack.getLast();
  202213. if (top != 0)
  202214. {
  202215. state = top;
  202216. stateStack.removeLast (1, false);
  202217. }
  202218. else
  202219. {
  202220. jassertfalse // trying to pop with an empty stack!
  202221. }
  202222. }
  202223. void setFill (const FillType& fillType)
  202224. {
  202225. state->fillType = fillType;
  202226. if (fillType.isColour())
  202227. {
  202228. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202229. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202230. CGContextSetAlpha (context, 1.0f);
  202231. }
  202232. }
  202233. void setOpacity (float newOpacity)
  202234. {
  202235. state->fillType.setOpacity (newOpacity);
  202236. setFill (state->fillType);
  202237. }
  202238. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202239. {
  202240. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202241. ? kCGInterpolationLow
  202242. : kCGInterpolationHigh);
  202243. }
  202244. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202245. {
  202246. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202247. if (replaceExistingContents)
  202248. {
  202249. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202250. CGContextClearRect (context, cgRect);
  202251. #else
  202252. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202253. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202254. CGContextClearRect (context, cgRect);
  202255. else
  202256. #endif
  202257. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202258. #endif
  202259. fillRect (r, false);
  202260. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202261. }
  202262. else
  202263. {
  202264. if (state->fillType.isColour())
  202265. {
  202266. CGContextFillRect (context, cgRect);
  202267. }
  202268. else if (state->fillType.isGradient())
  202269. {
  202270. CGContextSaveGState (context);
  202271. CGContextClipToRect (context, cgRect);
  202272. drawGradient();
  202273. CGContextRestoreGState (context);
  202274. }
  202275. else
  202276. {
  202277. CGContextSaveGState (context);
  202278. CGContextClipToRect (context, cgRect);
  202279. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202280. CGContextRestoreGState (context);
  202281. }
  202282. }
  202283. }
  202284. void fillPath (const Path& path, const AffineTransform& transform)
  202285. {
  202286. CGContextSaveGState (context);
  202287. if (state->fillType.isColour())
  202288. {
  202289. flip();
  202290. applyTransform (transform);
  202291. createPath (path);
  202292. if (path.isUsingNonZeroWinding())
  202293. CGContextFillPath (context);
  202294. else
  202295. CGContextEOFillPath (context);
  202296. }
  202297. else
  202298. {
  202299. createPath (path, transform);
  202300. if (path.isUsingNonZeroWinding())
  202301. CGContextClip (context);
  202302. else
  202303. CGContextEOClip (context);
  202304. if (state->fillType.isGradient())
  202305. drawGradient();
  202306. else
  202307. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202308. }
  202309. CGContextRestoreGState (context);
  202310. }
  202311. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202312. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202313. {
  202314. jassert (sourceImage.getBounds().contains (srcClip));
  202315. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202316. CGImageRef image = fullImage;
  202317. if (srcClip != sourceImage.getBounds())
  202318. {
  202319. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202320. srcClip.getWidth(), srcClip.getHeight()));
  202321. CGImageRelease (fullImage);
  202322. }
  202323. CGContextSaveGState (context);
  202324. CGContextSetAlpha (context, state->fillType.getOpacity());
  202325. flip();
  202326. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202327. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202328. if (fillEntireClipAsTiles)
  202329. {
  202330. #if JUCE_IPHONE
  202331. CGContextDrawTiledImage (context, imageRect, image);
  202332. #else
  202333. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202334. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202335. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202336. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202337. CGContextDrawTiledImage (context, imageRect, image);
  202338. else
  202339. #endif
  202340. {
  202341. // Fallback to manually doing a tiled fill on 10.4
  202342. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202343. const int iw = srcClip.getWidth();
  202344. const int ih = srcClip.getHeight();
  202345. int x = 0, y = 0;
  202346. while (x > clip.origin.x) x -= iw;
  202347. while (y > clip.origin.y) y -= ih;
  202348. const int right = (int) (clip.origin.x + clip.size.width);
  202349. const int bottom = (int) (clip.origin.y + clip.size.height);
  202350. while (y < bottom)
  202351. {
  202352. for (int x2 = x; x2 < right; x2 += iw)
  202353. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202354. y += ih;
  202355. }
  202356. }
  202357. #endif
  202358. }
  202359. else
  202360. {
  202361. CGContextDrawImage (context, imageRect, image);
  202362. }
  202363. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202364. CGContextRestoreGState (context);
  202365. }
  202366. void drawLine (double x1, double y1, double x2, double y2)
  202367. {
  202368. CGContextSetLineCap (context, kCGLineCapSquare);
  202369. CGContextSetLineWidth (context, 1.0f);
  202370. CGContextSetRGBStrokeColor (context,
  202371. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202372. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202373. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202374. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202375. CGContextStrokeLineSegments (context, line, 1);
  202376. }
  202377. void drawVerticalLine (const int x, double top, double bottom)
  202378. {
  202379. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202380. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202381. #else
  202382. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202383. // the x co-ord slightly to trick it..
  202384. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202385. #endif
  202386. }
  202387. void drawHorizontalLine (const int y, double left, double right)
  202388. {
  202389. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202390. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202391. #else
  202392. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202393. // the x co-ord slightly to trick it..
  202394. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202395. #endif
  202396. }
  202397. void setFont (const Font& newFont)
  202398. {
  202399. if (state->font != newFont)
  202400. {
  202401. state->fontRef = 0;
  202402. state->font = newFont;
  202403. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  202404. if (mf != 0)
  202405. {
  202406. state->fontRef = mf->fontRef;
  202407. CGContextSetFont (context, state->fontRef);
  202408. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202409. state->fontTransform = mf->renderingTransform;
  202410. state->fontTransform.a *= state->font.getHorizontalScale();
  202411. CGContextSetTextMatrix (context, state->fontTransform);
  202412. }
  202413. }
  202414. }
  202415. const Font getFont()
  202416. {
  202417. return state->font;
  202418. }
  202419. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202420. {
  202421. if (state->fontRef != 0 && state->fillType.isColour())
  202422. {
  202423. if (transform.isOnlyTranslation())
  202424. {
  202425. CGGlyph g = glyphNumber;
  202426. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202427. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202428. }
  202429. else
  202430. {
  202431. CGContextSaveGState (context);
  202432. flip();
  202433. applyTransform (transform);
  202434. CGAffineTransform t = state->fontTransform;
  202435. t.d = -t.d;
  202436. CGContextSetTextMatrix (context, t);
  202437. CGGlyph g = glyphNumber;
  202438. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202439. CGContextSetTextMatrix (context, state->fontTransform);
  202440. CGContextRestoreGState (context);
  202441. }
  202442. }
  202443. else
  202444. {
  202445. Path p;
  202446. Font& f = state->font;
  202447. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202448. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202449. .followedBy (transform));
  202450. }
  202451. }
  202452. private:
  202453. CGContextRef context;
  202454. const CGFloat flipHeight;
  202455. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202456. CGFunctionCallbacks gradientCallbacks;
  202457. struct SavedState
  202458. {
  202459. SavedState()
  202460. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202461. {
  202462. }
  202463. SavedState (const SavedState& other)
  202464. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202465. fontTransform (other.fontTransform)
  202466. {
  202467. }
  202468. ~SavedState()
  202469. {
  202470. }
  202471. FillType fillType;
  202472. Font font;
  202473. CGFontRef fontRef;
  202474. CGAffineTransform fontTransform;
  202475. };
  202476. ScopedPointer <SavedState> state;
  202477. OwnedArray <SavedState> stateStack;
  202478. HeapBlock <PixelARGB> gradientLookupTable;
  202479. int numGradientLookupEntries;
  202480. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202481. {
  202482. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  202483. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202484. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202485. colour.unpremultiply();
  202486. outData[0] = colour.getRed() / 255.0f;
  202487. outData[1] = colour.getGreen() / 255.0f;
  202488. outData[2] = colour.getBlue() / 255.0f;
  202489. outData[3] = colour.getAlpha() / 255.0f;
  202490. }
  202491. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202492. {
  202493. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202494. --numGradientLookupEntries;
  202495. CGShadingRef result = 0;
  202496. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  202497. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202498. if (gradient.isRadial)
  202499. {
  202500. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202501. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202502. function, true, true);
  202503. }
  202504. else
  202505. {
  202506. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202507. CGPointMake (gradient.x2, gradient.y2),
  202508. function, true, true);
  202509. }
  202510. CGFunctionRelease (function);
  202511. return result;
  202512. }
  202513. void drawGradient()
  202514. {
  202515. flip();
  202516. applyTransform (state->fillType.transform);
  202517. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202518. // you draw a gradient with high quality interp enabled).
  202519. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202520. CGContextSetAlpha (context, state->fillType.getOpacity());
  202521. CGContextDrawShading (context, shading);
  202522. CGShadingRelease (shading);
  202523. }
  202524. void createPath (const Path& path) const
  202525. {
  202526. CGContextBeginPath (context);
  202527. Path::Iterator i (path);
  202528. while (i.next())
  202529. {
  202530. switch (i.elementType)
  202531. {
  202532. case Path::Iterator::startNewSubPath:
  202533. CGContextMoveToPoint (context, i.x1, i.y1);
  202534. break;
  202535. case Path::Iterator::lineTo:
  202536. CGContextAddLineToPoint (context, i.x1, i.y1);
  202537. break;
  202538. case Path::Iterator::quadraticTo:
  202539. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202540. break;
  202541. case Path::Iterator::cubicTo:
  202542. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202543. break;
  202544. case Path::Iterator::closePath:
  202545. CGContextClosePath (context); break;
  202546. default:
  202547. jassertfalse
  202548. break;
  202549. }
  202550. }
  202551. }
  202552. void createPath (const Path& path, const AffineTransform& transform) const
  202553. {
  202554. CGContextBeginPath (context);
  202555. Path::Iterator i (path);
  202556. while (i.next())
  202557. {
  202558. switch (i.elementType)
  202559. {
  202560. case Path::Iterator::startNewSubPath:
  202561. transform.transformPoint (i.x1, i.y1);
  202562. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202563. break;
  202564. case Path::Iterator::lineTo:
  202565. transform.transformPoint (i.x1, i.y1);
  202566. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202567. break;
  202568. case Path::Iterator::quadraticTo:
  202569. transform.transformPoint (i.x1, i.y1);
  202570. transform.transformPoint (i.x2, i.y2);
  202571. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202572. break;
  202573. case Path::Iterator::cubicTo:
  202574. transform.transformPoint (i.x1, i.y1);
  202575. transform.transformPoint (i.x2, i.y2);
  202576. transform.transformPoint (i.x3, i.y3);
  202577. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202578. break;
  202579. case Path::Iterator::closePath:
  202580. CGContextClosePath (context); break;
  202581. default:
  202582. jassertfalse
  202583. break;
  202584. }
  202585. }
  202586. }
  202587. static Image* createAlphaChannelImage (const Image& im)
  202588. {
  202589. if (im.getFormat() == Image::SingleChannel)
  202590. return const_cast <Image*> (&im);
  202591. return im.createCopyOfAlphaChannel();
  202592. }
  202593. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202594. {
  202595. if (im.getFormat() != Image::SingleChannel)
  202596. delete alphaIm;
  202597. }
  202598. void flip() const
  202599. {
  202600. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202601. }
  202602. void applyTransform (const AffineTransform& transform) const
  202603. {
  202604. CGAffineTransform t;
  202605. t.a = transform.mat00;
  202606. t.b = transform.mat10;
  202607. t.c = transform.mat01;
  202608. t.d = transform.mat11;
  202609. t.tx = transform.mat02;
  202610. t.ty = transform.mat12;
  202611. CGContextConcatCTM (context, t);
  202612. }
  202613. CoreGraphicsContext (const CoreGraphicsContext&);
  202614. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202615. };
  202616. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202617. {
  202618. return new CoreGraphicsContext (context, imageHeight);
  202619. }
  202620. #endif
  202621. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202622. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202623. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202624. // compiled on its own).
  202625. #if JUCE_INCLUDED_FILE
  202626. class UIViewComponentPeer;
  202627. END_JUCE_NAMESPACE
  202628. #define JuceUIView MakeObjCClassName(JuceUIView)
  202629. @interface JuceUIView : UIView <UITextFieldDelegate>
  202630. {
  202631. @public
  202632. UIViewComponentPeer* owner;
  202633. UITextField *hiddenTextField;
  202634. }
  202635. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202636. - (void) dealloc;
  202637. - (void) drawRect: (CGRect) r;
  202638. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202639. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202640. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202641. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202642. - (BOOL) becomeFirstResponder;
  202643. - (BOOL) resignFirstResponder;
  202644. - (BOOL) canBecomeFirstResponder;
  202645. - (void) asyncRepaint: (id) rect;
  202646. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202647. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202648. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202649. @end
  202650. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202651. @interface JuceUIWindow : UIWindow
  202652. {
  202653. @private
  202654. UIViewComponentPeer* owner;
  202655. bool isZooming;
  202656. }
  202657. - (void) setOwner: (UIViewComponentPeer*) owner;
  202658. - (void) becomeKeyWindow;
  202659. @end
  202660. BEGIN_JUCE_NAMESPACE
  202661. class UIViewComponentPeer : public ComponentPeer,
  202662. public FocusChangeListener
  202663. {
  202664. public:
  202665. UIViewComponentPeer (Component* const component,
  202666. const int windowStyleFlags,
  202667. UIView* viewToAttachTo);
  202668. ~UIViewComponentPeer();
  202669. void* getNativeHandle() const;
  202670. void setVisible (bool shouldBeVisible);
  202671. void setTitle (const String& title);
  202672. void setPosition (int x, int y);
  202673. void setSize (int w, int h);
  202674. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202675. const Rectangle<int> getBounds() const;
  202676. const Rectangle<int> getBounds (const bool global) const;
  202677. const Point<int> getScreenPosition() const;
  202678. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202679. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202680. void setMinimised (bool shouldBeMinimised);
  202681. bool isMinimised() const;
  202682. void setFullScreen (bool shouldBeFullScreen);
  202683. bool isFullScreen() const;
  202684. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202685. const BorderSize getFrameSize() const;
  202686. bool setAlwaysOnTop (bool alwaysOnTop);
  202687. void toFront (bool makeActiveWindow);
  202688. void toBehind (ComponentPeer* other);
  202689. void setIcon (const Image& newIcon);
  202690. virtual void drawRect (CGRect r);
  202691. virtual bool canBecomeKeyWindow();
  202692. virtual bool windowShouldClose();
  202693. virtual void redirectMovedOrResized();
  202694. virtual CGRect constrainRect (CGRect r);
  202695. virtual void viewFocusGain();
  202696. virtual void viewFocusLoss();
  202697. bool isFocused() const;
  202698. void grabFocus();
  202699. void textInputRequired (const Point<int>& position);
  202700. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202701. virtual BOOL textFieldShouldClear();
  202702. virtual BOOL textFieldShouldReturn();
  202703. void updateHiddenTextContent (TextInputTarget* target);
  202704. void globalFocusChanged (Component*);
  202705. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202706. void repaint (int x, int y, int w, int h);
  202707. void performAnyPendingRepaintsNow();
  202708. juce_UseDebuggingNewOperator
  202709. UIWindow* window;
  202710. JuceUIView* view;
  202711. bool isSharedWindow, fullScreen, insideDrawRect;
  202712. static ModifierKeys currentModifiers;
  202713. static int64 getMouseTime (UIEvent* e)
  202714. {
  202715. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202716. + (int64) ([e timestamp] * 1000.0);
  202717. }
  202718. Array <UITouch*> currentTouches;
  202719. };
  202720. END_JUCE_NAMESPACE
  202721. @implementation JuceUIView
  202722. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202723. withFrame: (CGRect) frame
  202724. {
  202725. [super initWithFrame: frame];
  202726. owner = owner_;
  202727. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202728. [self addSubview: hiddenTextField];
  202729. hiddenTextField.delegate = self;
  202730. return self;
  202731. }
  202732. - (void) dealloc
  202733. {
  202734. [hiddenTextField removeFromSuperview];
  202735. [hiddenTextField release];
  202736. [super dealloc];
  202737. }
  202738. - (void) drawRect: (CGRect) r
  202739. {
  202740. if (owner != 0)
  202741. owner->drawRect (r);
  202742. }
  202743. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  202744. {
  202745. return false;
  202746. }
  202747. ModifierKeys UIViewComponentPeer::currentModifiers;
  202748. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202749. {
  202750. return UIViewComponentPeer::currentModifiers;
  202751. }
  202752. void ModifierKeys::updateCurrentModifiers() throw()
  202753. {
  202754. currentModifiers = UIViewComponentPeer::currentModifiers;
  202755. }
  202756. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202757. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202758. {
  202759. if (owner != 0)
  202760. owner->handleTouches (event, true, false, false);
  202761. }
  202762. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202763. {
  202764. if (owner != 0)
  202765. owner->handleTouches (event, false, false, false);
  202766. }
  202767. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202768. {
  202769. if (owner != 0)
  202770. owner->handleTouches (event, false, true, false);
  202771. }
  202772. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202773. {
  202774. if (owner != 0)
  202775. owner->handleTouches (event, false, true, true);
  202776. [self touchesEnded: touches withEvent: event];
  202777. }
  202778. - (BOOL) becomeFirstResponder
  202779. {
  202780. if (owner != 0)
  202781. owner->viewFocusGain();
  202782. return true;
  202783. }
  202784. - (BOOL) resignFirstResponder
  202785. {
  202786. if (owner != 0)
  202787. owner->viewFocusLoss();
  202788. return true;
  202789. }
  202790. - (BOOL) canBecomeFirstResponder
  202791. {
  202792. return owner != 0 && owner->canBecomeKeyWindow();
  202793. }
  202794. - (void) asyncRepaint: (id) rect
  202795. {
  202796. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202797. [self setNeedsDisplayInRect: *r];
  202798. }
  202799. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202800. {
  202801. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202802. nsStringToJuce (text));
  202803. }
  202804. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202805. {
  202806. return owner->textFieldShouldClear();
  202807. }
  202808. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202809. {
  202810. return owner->textFieldShouldReturn();
  202811. }
  202812. @end
  202813. @implementation JuceUIWindow
  202814. - (void) setOwner: (UIViewComponentPeer*) owner_
  202815. {
  202816. owner = owner_;
  202817. isZooming = false;
  202818. }
  202819. - (void) becomeKeyWindow
  202820. {
  202821. [super becomeKeyWindow];
  202822. if (owner != 0)
  202823. owner->grabFocus();
  202824. }
  202825. @end
  202826. BEGIN_JUCE_NAMESPACE
  202827. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202828. const int windowStyleFlags,
  202829. UIView* viewToAttachTo)
  202830. : ComponentPeer (component, windowStyleFlags),
  202831. window (0),
  202832. view (0),
  202833. isSharedWindow (viewToAttachTo != 0),
  202834. fullScreen (false),
  202835. insideDrawRect (false)
  202836. {
  202837. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202838. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202839. if (isSharedWindow)
  202840. {
  202841. window = [viewToAttachTo window];
  202842. [viewToAttachTo addSubview: view];
  202843. setVisible (component->isVisible());
  202844. }
  202845. else
  202846. {
  202847. r.origin.x = (float) component->getX();
  202848. r.origin.y = (float) component->getY();
  202849. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202850. window = [[JuceUIWindow alloc] init];
  202851. window.frame = r;
  202852. window.opaque = component->isOpaque();
  202853. view.opaque = component->isOpaque();
  202854. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202855. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202856. [((JuceUIWindow*) window) setOwner: this];
  202857. if (component->isAlwaysOnTop())
  202858. window.windowLevel = UIWindowLevelAlert;
  202859. [window addSubview: view];
  202860. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202861. view.hidden = ! component->isVisible();
  202862. window.hidden = ! component->isVisible();
  202863. view.multipleTouchEnabled = YES;
  202864. }
  202865. setTitle (component->getName());
  202866. Desktop::getInstance().addFocusChangeListener (this);
  202867. }
  202868. UIViewComponentPeer::~UIViewComponentPeer()
  202869. {
  202870. Desktop::getInstance().removeFocusChangeListener (this);
  202871. view->owner = 0;
  202872. [view removeFromSuperview];
  202873. [view release];
  202874. if (! isSharedWindow)
  202875. {
  202876. [((JuceUIWindow*) window) setOwner: 0];
  202877. [window release];
  202878. }
  202879. }
  202880. void* UIViewComponentPeer::getNativeHandle() const
  202881. {
  202882. return view;
  202883. }
  202884. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202885. {
  202886. view.hidden = ! shouldBeVisible;
  202887. if (! isSharedWindow)
  202888. window.hidden = ! shouldBeVisible;
  202889. }
  202890. void UIViewComponentPeer::setTitle (const String& title)
  202891. {
  202892. // xxx is this possible?
  202893. }
  202894. void UIViewComponentPeer::setPosition (int x, int y)
  202895. {
  202896. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202897. }
  202898. void UIViewComponentPeer::setSize (int w, int h)
  202899. {
  202900. setBounds (component->getX(), component->getY(), w, h, false);
  202901. }
  202902. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202903. {
  202904. fullScreen = isNowFullScreen;
  202905. w = jmax (0, w);
  202906. h = jmax (0, h);
  202907. CGRect r;
  202908. r.origin.x = (float) x;
  202909. r.origin.y = (float) y;
  202910. r.size.width = (float) w;
  202911. r.size.height = (float) h;
  202912. if (isSharedWindow)
  202913. {
  202914. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202915. if ([view frame].size.width != r.size.width
  202916. || [view frame].size.height != r.size.height)
  202917. [view setNeedsDisplay];
  202918. view.frame = r;
  202919. }
  202920. else
  202921. {
  202922. window.frame = r;
  202923. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202924. }
  202925. }
  202926. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202927. {
  202928. CGRect r = [view frame];
  202929. if (global && [view window] != 0)
  202930. {
  202931. r = [view convertRect: r toView: nil];
  202932. CGRect wr = [[view window] frame];
  202933. r.origin.x += wr.origin.x;
  202934. r.origin.y += wr.origin.y;
  202935. }
  202936. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202937. (int) r.size.width, (int) r.size.height);
  202938. }
  202939. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202940. {
  202941. return getBounds (! isSharedWindow);
  202942. }
  202943. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202944. {
  202945. return getBounds (true).getPosition();
  202946. }
  202947. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202948. {
  202949. return relativePosition + getScreenPosition();
  202950. }
  202951. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202952. {
  202953. return screenPosition - getScreenPosition();
  202954. }
  202955. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202956. {
  202957. if (constrainer != 0)
  202958. {
  202959. CGRect current = [window frame];
  202960. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202961. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202962. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202963. (int) r.size.width, (int) r.size.height);
  202964. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202965. (int) current.size.width, (int) current.size.height);
  202966. constrainer->checkBounds (pos, original,
  202967. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202968. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202969. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202970. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202971. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202972. r.origin.x = pos.getX();
  202973. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202974. r.size.width = pos.getWidth();
  202975. r.size.height = pos.getHeight();
  202976. }
  202977. return r;
  202978. }
  202979. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202980. {
  202981. // xxx
  202982. }
  202983. bool UIViewComponentPeer::isMinimised() const
  202984. {
  202985. return false;
  202986. }
  202987. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202988. {
  202989. if (! isSharedWindow)
  202990. {
  202991. Rectangle<int> r (lastNonFullscreenBounds);
  202992. setMinimised (false);
  202993. if (fullScreen != shouldBeFullScreen)
  202994. {
  202995. if (shouldBeFullScreen)
  202996. r = Desktop::getInstance().getMainMonitorArea();
  202997. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202998. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202999. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203000. }
  203001. }
  203002. }
  203003. bool UIViewComponentPeer::isFullScreen() const
  203004. {
  203005. return fullScreen;
  203006. }
  203007. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203008. {
  203009. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203010. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203011. return false;
  203012. CGPoint p;
  203013. p.x = (float) position.getX();
  203014. p.y = (float) position.getY();
  203015. UIView* v = [view hitTest: p withEvent: nil];
  203016. if (trueIfInAChildWindow)
  203017. return v != nil;
  203018. return v == view;
  203019. }
  203020. const BorderSize UIViewComponentPeer::getFrameSize() const
  203021. {
  203022. BorderSize b;
  203023. if (! isSharedWindow)
  203024. {
  203025. CGRect v = [view convertRect: [view frame] toView: nil];
  203026. CGRect w = [window frame];
  203027. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203028. b.setBottom ((int) v.origin.y);
  203029. b.setLeft ((int) v.origin.x);
  203030. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203031. }
  203032. return b;
  203033. }
  203034. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203035. {
  203036. if (! isSharedWindow)
  203037. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203038. return true;
  203039. }
  203040. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203041. {
  203042. if (isSharedWindow)
  203043. [[view superview] bringSubviewToFront: view];
  203044. if (window != 0 && component->isVisible())
  203045. [window makeKeyAndVisible];
  203046. }
  203047. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203048. {
  203049. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203050. if (isSharedWindow)
  203051. {
  203052. [[view superview] insertSubview: view belowSubview: o->view];
  203053. }
  203054. else
  203055. {
  203056. jassertfalse // don't know how to do this
  203057. }
  203058. }
  203059. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203060. {
  203061. // to do..
  203062. }
  203063. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203064. {
  203065. NSArray* touches = [[event touchesForView: view] allObjects];
  203066. for (unsigned int i = 0; i < [touches count]; ++i)
  203067. {
  203068. UITouch* touch = [touches objectAtIndex: i];
  203069. CGPoint p = [touch locationInView: view];
  203070. const Point<int> pos ((int) p.x, (int) p.y);
  203071. juce_lastMousePos = pos + getScreenPosition();
  203072. const int64 time = getMouseTime (event);
  203073. int touchIndex = currentTouches.indexOf (touch);
  203074. if (touchIndex < 0)
  203075. {
  203076. touchIndex = currentTouches.size();
  203077. currentTouches.add (touch);
  203078. }
  203079. if (isDown)
  203080. {
  203081. currentModifiers = currentModifiers.withoutMouseButtons();
  203082. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203083. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203084. }
  203085. else if (isUp)
  203086. {
  203087. currentModifiers = currentModifiers.withoutMouseButtons();
  203088. currentTouches.remove (touchIndex);
  203089. }
  203090. if (isCancel)
  203091. currentTouches.clear();
  203092. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203093. }
  203094. }
  203095. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203096. void UIViewComponentPeer::viewFocusGain()
  203097. {
  203098. if (currentlyFocusedPeer != this)
  203099. {
  203100. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203101. currentlyFocusedPeer->handleFocusLoss();
  203102. currentlyFocusedPeer = this;
  203103. handleFocusGain();
  203104. }
  203105. }
  203106. void UIViewComponentPeer::viewFocusLoss()
  203107. {
  203108. if (currentlyFocusedPeer == this)
  203109. {
  203110. currentlyFocusedPeer = 0;
  203111. handleFocusLoss();
  203112. }
  203113. }
  203114. void juce_HandleProcessFocusChange()
  203115. {
  203116. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203117. {
  203118. if (Process::isForegroundProcess())
  203119. {
  203120. currentlyFocusedPeer->handleFocusGain();
  203121. ComponentPeer::bringModalComponentToFront();
  203122. }
  203123. else
  203124. {
  203125. currentlyFocusedPeer->handleFocusLoss();
  203126. // turn kiosk mode off if we lose focus..
  203127. Desktop::getInstance().setKioskModeComponent (0);
  203128. }
  203129. }
  203130. }
  203131. bool UIViewComponentPeer::isFocused() const
  203132. {
  203133. return isSharedWindow ? this == currentlyFocusedPeer
  203134. : (window != 0 && [window isKeyWindow]);
  203135. }
  203136. void UIViewComponentPeer::grabFocus()
  203137. {
  203138. if (window != 0)
  203139. {
  203140. [window makeKeyWindow];
  203141. viewFocusGain();
  203142. }
  203143. }
  203144. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203145. {
  203146. }
  203147. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203148. {
  203149. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203150. }
  203151. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203152. {
  203153. TextInputTarget* const target = findCurrentTextInputTarget();
  203154. if (target != 0)
  203155. {
  203156. const Range<int> currentSelection (target->getHighlightedRegion());
  203157. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203158. if (currentSelection.isEmpty())
  203159. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203160. target->insertTextAtCaret (text);
  203161. updateHiddenTextContent (target);
  203162. }
  203163. return NO;
  203164. }
  203165. BOOL UIViewComponentPeer::textFieldShouldClear()
  203166. {
  203167. TextInputTarget* const target = findCurrentTextInputTarget();
  203168. if (target != 0)
  203169. {
  203170. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203171. target->insertTextAtCaret (String::empty);
  203172. updateHiddenTextContent (target);
  203173. }
  203174. return YES;
  203175. }
  203176. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203177. {
  203178. TextInputTarget* const target = findCurrentTextInputTarget();
  203179. if (target != 0)
  203180. {
  203181. target->insertTextAtCaret ("\n");
  203182. updateHiddenTextContent (target);
  203183. }
  203184. return YES;
  203185. }
  203186. void UIViewComponentPeer::globalFocusChanged (Component*)
  203187. {
  203188. TextInputTarget* const target = findCurrentTextInputTarget();
  203189. if (target != 0)
  203190. {
  203191. Component* comp = dynamic_cast<Component*> (target);
  203192. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203193. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203194. updateHiddenTextContent (target);
  203195. [view->hiddenTextField becomeFirstResponder];
  203196. }
  203197. else
  203198. {
  203199. [view->hiddenTextField resignFirstResponder];
  203200. }
  203201. }
  203202. void UIViewComponentPeer::drawRect (CGRect r)
  203203. {
  203204. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203205. return;
  203206. CGContextRef cg = UIGraphicsGetCurrentContext();
  203207. if (! component->isOpaque())
  203208. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203209. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203210. CoreGraphicsContext g (cg, view.bounds.size.height);
  203211. insideDrawRect = true;
  203212. handlePaint (g);
  203213. insideDrawRect = false;
  203214. }
  203215. bool UIViewComponentPeer::canBecomeKeyWindow()
  203216. {
  203217. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203218. }
  203219. bool UIViewComponentPeer::windowShouldClose()
  203220. {
  203221. if (! isValidPeer (this))
  203222. return YES;
  203223. handleUserClosingWindow();
  203224. return NO;
  203225. }
  203226. void UIViewComponentPeer::redirectMovedOrResized()
  203227. {
  203228. handleMovedOrResized();
  203229. }
  203230. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203231. {
  203232. }
  203233. class AsyncRepaintMessage : public CallbackMessage
  203234. {
  203235. public:
  203236. UIViewComponentPeer* const peer;
  203237. const Rectangle<int> rect;
  203238. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203239. : peer (peer_), rect (rect_)
  203240. {
  203241. }
  203242. void messageCallback()
  203243. {
  203244. if (ComponentPeer::isValidPeer (peer))
  203245. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203246. }
  203247. };
  203248. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203249. {
  203250. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203251. {
  203252. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203253. }
  203254. else
  203255. {
  203256. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203257. }
  203258. }
  203259. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203260. {
  203261. }
  203262. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203263. {
  203264. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203265. }
  203266. Image* juce_createIconForFile (const File& file)
  203267. {
  203268. return 0;
  203269. }
  203270. void Desktop::createMouseInputSources()
  203271. {
  203272. for (int i = 0; i < 10; ++i)
  203273. mouseSources.add (new MouseInputSource (i, false));
  203274. }
  203275. bool Desktop::canUseSemiTransparentWindows() throw()
  203276. {
  203277. return true;
  203278. }
  203279. const Point<int> Desktop::getMousePosition()
  203280. {
  203281. return juce_lastMousePos;
  203282. }
  203283. void Desktop::setMousePosition (const Point<int>&)
  203284. {
  203285. }
  203286. const int KeyPress::spaceKey = ' ';
  203287. const int KeyPress::returnKey = 0x0d;
  203288. const int KeyPress::escapeKey = 0x1b;
  203289. const int KeyPress::backspaceKey = 0x7f;
  203290. const int KeyPress::leftKey = 0x1000;
  203291. const int KeyPress::rightKey = 0x1001;
  203292. const int KeyPress::upKey = 0x1002;
  203293. const int KeyPress::downKey = 0x1003;
  203294. const int KeyPress::pageUpKey = 0x1004;
  203295. const int KeyPress::pageDownKey = 0x1005;
  203296. const int KeyPress::endKey = 0x1006;
  203297. const int KeyPress::homeKey = 0x1007;
  203298. const int KeyPress::deleteKey = 0x1008;
  203299. const int KeyPress::insertKey = -1;
  203300. const int KeyPress::tabKey = 9;
  203301. const int KeyPress::F1Key = 0x2001;
  203302. const int KeyPress::F2Key = 0x2002;
  203303. const int KeyPress::F3Key = 0x2003;
  203304. const int KeyPress::F4Key = 0x2004;
  203305. const int KeyPress::F5Key = 0x2005;
  203306. const int KeyPress::F6Key = 0x2006;
  203307. const int KeyPress::F7Key = 0x2007;
  203308. const int KeyPress::F8Key = 0x2008;
  203309. const int KeyPress::F9Key = 0x2009;
  203310. const int KeyPress::F10Key = 0x200a;
  203311. const int KeyPress::F11Key = 0x200b;
  203312. const int KeyPress::F12Key = 0x200c;
  203313. const int KeyPress::F13Key = 0x200d;
  203314. const int KeyPress::F14Key = 0x200e;
  203315. const int KeyPress::F15Key = 0x200f;
  203316. const int KeyPress::F16Key = 0x2010;
  203317. const int KeyPress::numberPad0 = 0x30020;
  203318. const int KeyPress::numberPad1 = 0x30021;
  203319. const int KeyPress::numberPad2 = 0x30022;
  203320. const int KeyPress::numberPad3 = 0x30023;
  203321. const int KeyPress::numberPad4 = 0x30024;
  203322. const int KeyPress::numberPad5 = 0x30025;
  203323. const int KeyPress::numberPad6 = 0x30026;
  203324. const int KeyPress::numberPad7 = 0x30027;
  203325. const int KeyPress::numberPad8 = 0x30028;
  203326. const int KeyPress::numberPad9 = 0x30029;
  203327. const int KeyPress::numberPadAdd = 0x3002a;
  203328. const int KeyPress::numberPadSubtract = 0x3002b;
  203329. const int KeyPress::numberPadMultiply = 0x3002c;
  203330. const int KeyPress::numberPadDivide = 0x3002d;
  203331. const int KeyPress::numberPadSeparator = 0x3002e;
  203332. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203333. const int KeyPress::numberPadEquals = 0x30030;
  203334. const int KeyPress::numberPadDelete = 0x30031;
  203335. const int KeyPress::playKey = 0x30000;
  203336. const int KeyPress::stopKey = 0x30001;
  203337. const int KeyPress::fastForwardKey = 0x30002;
  203338. const int KeyPress::rewindKey = 0x30003;
  203339. #endif
  203340. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203341. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203342. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203343. // compiled on its own).
  203344. #if JUCE_INCLUDED_FILE
  203345. struct CallbackMessagePayload
  203346. {
  203347. MessageCallbackFunction* function;
  203348. void* parameter;
  203349. void* volatile result;
  203350. bool volatile hasBeenExecuted;
  203351. };
  203352. END_JUCE_NAMESPACE
  203353. using namespace JUCE_NAMESPACE;
  203354. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203355. {
  203356. }
  203357. - (JuceAppDelegate*) init;
  203358. - (void) dealloc;
  203359. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203360. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203361. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203362. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203363. - (void) customEvent: (id) data;
  203364. - (void) performCallback: (id) info;
  203365. @end
  203366. @implementation JuceAppDelegate
  203367. - (JuceAppDelegate*) init
  203368. {
  203369. [super init];
  203370. [[UIApplication sharedApplication] setDelegate: self];
  203371. return self;
  203372. }
  203373. - (void) dealloc
  203374. {
  203375. [[UIApplication sharedApplication] setDelegate: nil];
  203376. [super dealloc];
  203377. }
  203378. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203379. {
  203380. if (JUCEApplication::getInstance() != 0)
  203381. {
  203382. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203383. return YES;
  203384. }
  203385. return NO;
  203386. }
  203387. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203388. {
  203389. juce_HandleProcessFocusChange();
  203390. }
  203391. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203392. {
  203393. juce_HandleProcessFocusChange();
  203394. }
  203395. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203396. {
  203397. juce_HandleProcessFocusChange();
  203398. }
  203399. - (void) customEvent: (id) n
  203400. {
  203401. NSData* data = (NSData*) n;
  203402. void* message = 0;
  203403. [data getBytes: &message length: sizeof (message)];
  203404. [data release];
  203405. if (message != 0)
  203406. MessageManager::getInstance()->deliverMessage (message);
  203407. }
  203408. - (void) performCallback: (id) info
  203409. {
  203410. if ([info isKindOfClass: [NSData class]])
  203411. {
  203412. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203413. if (pl != 0)
  203414. {
  203415. pl->result = (*pl->function) (pl->parameter);
  203416. pl->hasBeenExecuted = true;
  203417. }
  203418. }
  203419. else
  203420. {
  203421. jassertfalse // should never get here!
  203422. }
  203423. }
  203424. @end
  203425. BEGIN_JUCE_NAMESPACE
  203426. static JuceAppDelegate* juceAppDelegate = 0;
  203427. void MessageManager::runDispatchLoop()
  203428. {
  203429. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203430. runDispatchLoopUntil (-1);
  203431. }
  203432. void MessageManager::stopDispatchLoop()
  203433. {
  203434. exit (0); // iPhone apps get no mercy..
  203435. }
  203436. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203437. {
  203438. const ScopedAutoReleasePool pool;
  203439. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203440. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203441. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203442. while (! quitMessagePosted)
  203443. {
  203444. const ScopedAutoReleasePool pool;
  203445. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203446. beforeDate: endDate];
  203447. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203448. break;
  203449. }
  203450. return ! quitMessagePosted;
  203451. }
  203452. static CFRunLoopRef runLoop = 0;
  203453. static CFRunLoopSourceRef runLoopSource = 0;
  203454. static Array <void*, CriticalSection>* pendingMessages = 0;
  203455. static void runLoopSourceCallback (void*)
  203456. {
  203457. if (pendingMessages != 0)
  203458. {
  203459. int numDispatched = 0;
  203460. do
  203461. {
  203462. void* const nextMessage = pendingMessages->remove (0);
  203463. if (nextMessage == 0)
  203464. return;
  203465. const ScopedAutoReleasePool pool;
  203466. MessageManager::getInstance()->deliverMessage (nextMessage);
  203467. } while (++numDispatched <= 4);
  203468. CFRunLoopSourceSignal (runLoopSource);
  203469. CFRunLoopWakeUp (runLoop);
  203470. }
  203471. }
  203472. void MessageManager::doPlatformSpecificInitialisation()
  203473. {
  203474. pendingMessages = new Array <void*, CriticalSection>();
  203475. runLoop = CFRunLoopGetCurrent();
  203476. CFRunLoopSourceContext sourceContext;
  203477. zerostruct (sourceContext);
  203478. sourceContext.perform = runLoopSourceCallback;
  203479. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203480. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203481. if (juceAppDelegate == 0)
  203482. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203483. }
  203484. void MessageManager::doPlatformSpecificShutdown()
  203485. {
  203486. CFRunLoopSourceInvalidate (runLoopSource);
  203487. CFRelease (runLoopSource);
  203488. runLoopSource = 0;
  203489. if (pendingMessages != 0)
  203490. {
  203491. while (pendingMessages->size() > 0)
  203492. delete ((Message*) pendingMessages->remove(0));
  203493. deleteAndZero (pendingMessages);
  203494. }
  203495. if (juceAppDelegate != 0)
  203496. {
  203497. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203498. [juceAppDelegate release];
  203499. juceAppDelegate = 0;
  203500. }
  203501. }
  203502. bool juce_postMessageToSystemQueue (void* message)
  203503. {
  203504. if (pendingMessages != 0)
  203505. {
  203506. pendingMessages->add (message);
  203507. CFRunLoopSourceSignal (runLoopSource);
  203508. CFRunLoopWakeUp (runLoop);
  203509. }
  203510. return true;
  203511. }
  203512. void MessageManager::broadcastMessage (const String& value) throw()
  203513. {
  203514. }
  203515. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203516. void* data)
  203517. {
  203518. if (isThisTheMessageThread())
  203519. {
  203520. return (*callback) (data);
  203521. }
  203522. else
  203523. {
  203524. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203525. // deadlock because the message manager is blocked from running, so can never
  203526. // call your function..
  203527. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203528. const ScopedAutoReleasePool pool;
  203529. CallbackMessagePayload cmp;
  203530. cmp.function = callback;
  203531. cmp.parameter = data;
  203532. cmp.result = 0;
  203533. cmp.hasBeenExecuted = false;
  203534. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203535. withObject: [NSData dataWithBytesNoCopy: &cmp
  203536. length: sizeof (cmp)
  203537. freeWhenDone: NO]
  203538. waitUntilDone: YES];
  203539. return cmp.result;
  203540. }
  203541. }
  203542. #endif
  203543. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203544. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203545. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203546. // compiled on its own).
  203547. #if JUCE_INCLUDED_FILE
  203548. #if JUCE_MAC
  203549. END_JUCE_NAMESPACE
  203550. using namespace JUCE_NAMESPACE;
  203551. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203552. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203553. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203554. #else
  203555. @interface JuceFileChooserDelegate : NSObject
  203556. #endif
  203557. {
  203558. StringArray* filters;
  203559. }
  203560. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203561. - (void) dealloc;
  203562. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203563. @end
  203564. @implementation JuceFileChooserDelegate
  203565. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203566. {
  203567. [super init];
  203568. filters = filters_;
  203569. return self;
  203570. }
  203571. - (void) dealloc
  203572. {
  203573. delete filters;
  203574. [super dealloc];
  203575. }
  203576. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203577. {
  203578. const File f (nsStringToJuce (filename));
  203579. for (int i = filters->size(); --i >= 0;)
  203580. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203581. return true;
  203582. return f.isDirectory();
  203583. }
  203584. @end
  203585. BEGIN_JUCE_NAMESPACE
  203586. void FileChooser::showPlatformDialog (Array<File>& results,
  203587. const String& title,
  203588. const File& currentFileOrDirectory,
  203589. const String& filter,
  203590. bool selectsDirectory,
  203591. bool selectsFiles,
  203592. bool isSaveDialogue,
  203593. bool warnAboutOverwritingExistingFiles,
  203594. bool selectMultipleFiles,
  203595. FilePreviewComponent* extraInfoComponent)
  203596. {
  203597. const ScopedAutoReleasePool pool;
  203598. StringArray* filters = new StringArray();
  203599. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203600. filters->trim();
  203601. filters->removeEmptyStrings();
  203602. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203603. [delegate autorelease];
  203604. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203605. : [NSOpenPanel openPanel];
  203606. [panel setTitle: juceStringToNS (title)];
  203607. if (! isSaveDialogue)
  203608. {
  203609. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203610. [openPanel setCanChooseDirectories: selectsDirectory];
  203611. [openPanel setCanChooseFiles: selectsFiles];
  203612. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203613. }
  203614. [panel setDelegate: delegate];
  203615. if (isSaveDialogue || selectsDirectory)
  203616. [panel setCanCreateDirectories: YES];
  203617. String directory, filename;
  203618. if (currentFileOrDirectory.isDirectory())
  203619. {
  203620. directory = currentFileOrDirectory.getFullPathName();
  203621. }
  203622. else
  203623. {
  203624. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203625. filename = currentFileOrDirectory.getFileName();
  203626. }
  203627. if ([panel runModalForDirectory: juceStringToNS (directory)
  203628. file: juceStringToNS (filename)]
  203629. == NSOKButton)
  203630. {
  203631. if (isSaveDialogue)
  203632. {
  203633. results.add (File (nsStringToJuce ([panel filename])));
  203634. }
  203635. else
  203636. {
  203637. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203638. NSArray* urls = [openPanel filenames];
  203639. for (unsigned int i = 0; i < [urls count]; ++i)
  203640. {
  203641. NSString* f = [urls objectAtIndex: i];
  203642. results.add (File (nsStringToJuce (f)));
  203643. }
  203644. }
  203645. }
  203646. [panel setDelegate: nil];
  203647. }
  203648. #else
  203649. void FileChooser::showPlatformDialog (Array<File>& results,
  203650. const String& title,
  203651. const File& currentFileOrDirectory,
  203652. const String& filter,
  203653. bool selectsDirectory,
  203654. bool selectsFiles,
  203655. bool isSaveDialogue,
  203656. bool warnAboutOverwritingExistingFiles,
  203657. bool selectMultipleFiles,
  203658. FilePreviewComponent* extraInfoComponent)
  203659. {
  203660. const ScopedAutoReleasePool pool;
  203661. jassertfalse //xxx to do
  203662. }
  203663. #endif
  203664. #endif
  203665. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203666. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203667. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203668. // compiled on its own).
  203669. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203670. #if JUCE_MAC
  203671. END_JUCE_NAMESPACE
  203672. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203673. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203674. {
  203675. CriticalSection* contextLock;
  203676. bool needsUpdate;
  203677. }
  203678. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203679. - (bool) makeActive;
  203680. - (void) makeInactive;
  203681. - (void) reshape;
  203682. @end
  203683. @implementation ThreadSafeNSOpenGLView
  203684. - (id) initWithFrame: (NSRect) frameRect
  203685. pixelFormat: (NSOpenGLPixelFormat*) format
  203686. {
  203687. contextLock = new CriticalSection();
  203688. self = [super initWithFrame: frameRect pixelFormat: format];
  203689. if (self != nil)
  203690. [[NSNotificationCenter defaultCenter] addObserver: self
  203691. selector: @selector (_surfaceNeedsUpdate:)
  203692. name: NSViewGlobalFrameDidChangeNotification
  203693. object: self];
  203694. return self;
  203695. }
  203696. - (void) dealloc
  203697. {
  203698. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203699. delete contextLock;
  203700. [super dealloc];
  203701. }
  203702. - (bool) makeActive
  203703. {
  203704. const ScopedLock sl (*contextLock);
  203705. if ([self openGLContext] == 0)
  203706. return false;
  203707. [[self openGLContext] makeCurrentContext];
  203708. if (needsUpdate)
  203709. {
  203710. [super update];
  203711. needsUpdate = false;
  203712. }
  203713. return true;
  203714. }
  203715. - (void) makeInactive
  203716. {
  203717. const ScopedLock sl (*contextLock);
  203718. [NSOpenGLContext clearCurrentContext];
  203719. }
  203720. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203721. {
  203722. const ScopedLock sl (*contextLock);
  203723. needsUpdate = true;
  203724. }
  203725. - (void) update
  203726. {
  203727. const ScopedLock sl (*contextLock);
  203728. needsUpdate = true;
  203729. }
  203730. - (void) reshape
  203731. {
  203732. const ScopedLock sl (*contextLock);
  203733. needsUpdate = true;
  203734. }
  203735. @end
  203736. BEGIN_JUCE_NAMESPACE
  203737. class WindowedGLContext : public OpenGLContext
  203738. {
  203739. public:
  203740. WindowedGLContext (Component* const component,
  203741. const OpenGLPixelFormat& pixelFormat_,
  203742. NSOpenGLContext* sharedContext)
  203743. : renderContext (0),
  203744. pixelFormat (pixelFormat_)
  203745. {
  203746. jassert (component != 0);
  203747. NSOpenGLPixelFormatAttribute attribs [64];
  203748. int n = 0;
  203749. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203750. attribs[n++] = NSOpenGLPFAAccelerated;
  203751. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203752. attribs[n++] = NSOpenGLPFAColorSize;
  203753. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203754. pixelFormat.greenBits,
  203755. pixelFormat.blueBits);
  203756. attribs[n++] = NSOpenGLPFAAlphaSize;
  203757. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203758. attribs[n++] = NSOpenGLPFADepthSize;
  203759. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203760. attribs[n++] = NSOpenGLPFAStencilSize;
  203761. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203762. attribs[n++] = NSOpenGLPFAAccumSize;
  203763. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203764. pixelFormat.accumulationBufferGreenBits,
  203765. pixelFormat.accumulationBufferBlueBits,
  203766. pixelFormat.accumulationBufferAlphaBits);
  203767. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203768. attribs[n++] = NSOpenGLPFASampleBuffers;
  203769. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203770. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203771. attribs[n++] = NSOpenGLPFANoRecovery;
  203772. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203773. NSOpenGLPixelFormat* format
  203774. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203775. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203776. pixelFormat: format];
  203777. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203778. shareContext: sharedContext] autorelease];
  203779. const GLint swapInterval = 1;
  203780. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203781. [view setOpenGLContext: renderContext];
  203782. [renderContext setView: view];
  203783. [format release];
  203784. viewHolder = new NSViewComponentInternal (view, component);
  203785. }
  203786. ~WindowedGLContext()
  203787. {
  203788. makeInactive();
  203789. [renderContext clearDrawable];
  203790. viewHolder = 0;
  203791. }
  203792. bool makeActive() const throw()
  203793. {
  203794. jassert (renderContext != 0);
  203795. [view makeActive];
  203796. return isActive();
  203797. }
  203798. bool makeInactive() const throw()
  203799. {
  203800. [view makeInactive];
  203801. return true;
  203802. }
  203803. bool isActive() const throw()
  203804. {
  203805. return [NSOpenGLContext currentContext] == renderContext;
  203806. }
  203807. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203808. void* getRawContext() const throw() { return renderContext; }
  203809. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203810. {
  203811. }
  203812. void swapBuffers()
  203813. {
  203814. [renderContext flushBuffer];
  203815. }
  203816. bool setSwapInterval (const int numFramesPerSwap)
  203817. {
  203818. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203819. forParameter: NSOpenGLCPSwapInterval];
  203820. return true;
  203821. }
  203822. int getSwapInterval() const
  203823. {
  203824. GLint numFrames = 0;
  203825. [renderContext getValues: &numFrames
  203826. forParameter: NSOpenGLCPSwapInterval];
  203827. return numFrames;
  203828. }
  203829. void repaint()
  203830. {
  203831. // we need to invalidate the juce view that holds this gl view, to make it
  203832. // cause a repaint callback
  203833. NSView* v = (NSView*) viewHolder->view;
  203834. NSRect r = [v frame];
  203835. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203836. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203837. // repaint message, thus never causing our paint() callback, and never repainting
  203838. // the comp. So invalidating just a little bit around the edge helps..
  203839. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203840. }
  203841. void* getNativeWindowHandle() const { return viewHolder->view; }
  203842. juce_UseDebuggingNewOperator
  203843. NSOpenGLContext* renderContext;
  203844. ThreadSafeNSOpenGLView* view;
  203845. private:
  203846. OpenGLPixelFormat pixelFormat;
  203847. ScopedPointer <NSViewComponentInternal> viewHolder;
  203848. WindowedGLContext (const WindowedGLContext&);
  203849. WindowedGLContext& operator= (const WindowedGLContext&);
  203850. };
  203851. OpenGLContext* OpenGLComponent::createContext()
  203852. {
  203853. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203854. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203855. return (c->renderContext != 0) ? c.release() : 0;
  203856. }
  203857. void* OpenGLComponent::getNativeWindowHandle() const
  203858. {
  203859. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203860. : 0;
  203861. }
  203862. void juce_glViewport (const int w, const int h)
  203863. {
  203864. glViewport (0, 0, w, h);
  203865. }
  203866. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203867. OwnedArray <OpenGLPixelFormat>& results)
  203868. {
  203869. /* GLint attribs [64];
  203870. int n = 0;
  203871. attribs[n++] = AGL_RGBA;
  203872. attribs[n++] = AGL_DOUBLEBUFFER;
  203873. attribs[n++] = AGL_ACCELERATED;
  203874. attribs[n++] = AGL_NO_RECOVERY;
  203875. attribs[n++] = AGL_NONE;
  203876. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203877. while (p != 0)
  203878. {
  203879. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203880. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203881. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203882. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203883. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203884. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203885. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203886. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203887. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203888. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203889. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203890. results.add (pf);
  203891. p = aglNextPixelFormat (p);
  203892. }*/
  203893. //jassertfalse //xxx can't see how you do this in cocoa!
  203894. }
  203895. #else
  203896. END_JUCE_NAMESPACE
  203897. @interface JuceGLView : UIView
  203898. {
  203899. }
  203900. + (Class) layerClass;
  203901. @end
  203902. @implementation JuceGLView
  203903. + (Class) layerClass
  203904. {
  203905. return [CAEAGLLayer class];
  203906. }
  203907. @end
  203908. BEGIN_JUCE_NAMESPACE
  203909. class GLESContext : public OpenGLContext
  203910. {
  203911. public:
  203912. GLESContext (UIViewComponentPeer* peer,
  203913. Component* const component_,
  203914. const OpenGLPixelFormat& pixelFormat_,
  203915. const GLESContext* const sharedContext,
  203916. NSUInteger apiType)
  203917. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203918. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203919. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203920. {
  203921. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203922. view.opaque = YES;
  203923. view.hidden = NO;
  203924. view.backgroundColor = [UIColor blackColor];
  203925. view.userInteractionEnabled = NO;
  203926. glLayer = (CAEAGLLayer*) [view layer];
  203927. [peer->view addSubview: view];
  203928. if (sharedContext != 0)
  203929. context = [[EAGLContext alloc] initWithAPI: apiType
  203930. sharegroup: [sharedContext->context sharegroup]];
  203931. else
  203932. context = [[EAGLContext alloc] initWithAPI: apiType];
  203933. createGLBuffers();
  203934. }
  203935. ~GLESContext()
  203936. {
  203937. makeInactive();
  203938. [context release];
  203939. [view removeFromSuperview];
  203940. [view release];
  203941. freeGLBuffers();
  203942. }
  203943. bool makeActive() const throw()
  203944. {
  203945. jassert (context != 0);
  203946. [EAGLContext setCurrentContext: context];
  203947. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203948. return true;
  203949. }
  203950. void swapBuffers()
  203951. {
  203952. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203953. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203954. }
  203955. bool makeInactive() const throw()
  203956. {
  203957. return [EAGLContext setCurrentContext: nil];
  203958. }
  203959. bool isActive() const throw()
  203960. {
  203961. return [EAGLContext currentContext] == context;
  203962. }
  203963. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203964. void* getRawContext() const throw() { return glLayer; }
  203965. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203966. {
  203967. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203968. if (lastWidth != w || lastHeight != h)
  203969. {
  203970. lastWidth = w;
  203971. lastHeight = h;
  203972. freeGLBuffers();
  203973. createGLBuffers();
  203974. }
  203975. }
  203976. bool setSwapInterval (const int numFramesPerSwap)
  203977. {
  203978. numFrames = numFramesPerSwap;
  203979. return true;
  203980. }
  203981. int getSwapInterval() const
  203982. {
  203983. return numFrames;
  203984. }
  203985. void repaint()
  203986. {
  203987. }
  203988. void createGLBuffers()
  203989. {
  203990. makeActive();
  203991. glGenFramebuffersOES (1, &frameBufferHandle);
  203992. glGenRenderbuffersOES (1, &colorBufferHandle);
  203993. glGenRenderbuffersOES (1, &depthBufferHandle);
  203994. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203995. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203996. GLint width, height;
  203997. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203998. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203999. if (useDepthBuffer)
  204000. {
  204001. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  204002. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  204003. }
  204004. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204005. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  204006. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  204007. if (useDepthBuffer)
  204008. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  204009. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  204010. }
  204011. void freeGLBuffers()
  204012. {
  204013. if (frameBufferHandle != 0)
  204014. {
  204015. glDeleteFramebuffersOES (1, &frameBufferHandle);
  204016. frameBufferHandle = 0;
  204017. }
  204018. if (colorBufferHandle != 0)
  204019. {
  204020. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204021. colorBufferHandle = 0;
  204022. }
  204023. if (depthBufferHandle != 0)
  204024. {
  204025. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204026. depthBufferHandle = 0;
  204027. }
  204028. }
  204029. juce_UseDebuggingNewOperator
  204030. private:
  204031. Component::SafePointer<Component> component;
  204032. OpenGLPixelFormat pixelFormat;
  204033. JuceGLView* view;
  204034. CAEAGLLayer* glLayer;
  204035. EAGLContext* context;
  204036. bool useDepthBuffer;
  204037. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204038. int numFrames;
  204039. int lastWidth, lastHeight;
  204040. GLESContext (const GLESContext&);
  204041. GLESContext& operator= (const GLESContext&);
  204042. };
  204043. OpenGLContext* OpenGLComponent::createContext()
  204044. {
  204045. ScopedAutoReleasePool pool;
  204046. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204047. if (peer != 0)
  204048. return new GLESContext (peer, this, preferredPixelFormat,
  204049. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204050. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204051. return 0;
  204052. }
  204053. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204054. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204055. {
  204056. }
  204057. void juce_glViewport (const int w, const int h)
  204058. {
  204059. glViewport (0, 0, w, h);
  204060. }
  204061. #endif
  204062. #endif
  204063. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204064. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204065. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204066. // compiled on its own).
  204067. #if JUCE_INCLUDED_FILE
  204068. #if JUCE_MAC
  204069. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204070. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  204071. {
  204072. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204073. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204074. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204075. [im release];
  204076. return c;
  204077. }
  204078. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  204079. {
  204080. MemoryInputStream stream (data, false);
  204081. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204082. jassert (im != 0);
  204083. if (im == 0)
  204084. return 0;
  204085. return juce_createMouseCursorFromImage (*im,
  204086. (int) (hx * im->getWidth()),
  204087. (int) (hy * im->getHeight()));
  204088. }
  204089. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204090. {
  204091. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204092. MemoryBlock mb;
  204093. if (f.getChildFile (filename).loadFileAsData (mb))
  204094. return juce_cursorFromData (mb, hx, hy);
  204095. return 0;
  204096. }
  204097. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  204098. {
  204099. const ScopedAutoReleasePool pool;
  204100. NSCursor* c = 0;
  204101. switch (type)
  204102. {
  204103. case MouseCursor::NormalCursor:
  204104. c = [NSCursor arrowCursor];
  204105. break;
  204106. case MouseCursor::NoCursor:
  204107. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204108. case MouseCursor::DraggingHandCursor:
  204109. c = [NSCursor openHandCursor];
  204110. break;
  204111. case MouseCursor::CopyingCursor:
  204112. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204113. case MouseCursor::WaitCursor:
  204114. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204115. break;
  204116. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204117. case MouseCursor::IBeamCursor:
  204118. c = [NSCursor IBeamCursor];
  204119. break;
  204120. case MouseCursor::PointingHandCursor:
  204121. c = [NSCursor pointingHandCursor];
  204122. break;
  204123. case MouseCursor::LeftRightResizeCursor:
  204124. c = [NSCursor resizeLeftRightCursor];
  204125. break;
  204126. case MouseCursor::LeftEdgeResizeCursor:
  204127. c = [NSCursor resizeLeftCursor];
  204128. break;
  204129. case MouseCursor::RightEdgeResizeCursor:
  204130. c = [NSCursor resizeRightCursor];
  204131. break;
  204132. case MouseCursor::UpDownResizeCursor:
  204133. case MouseCursor::TopEdgeResizeCursor:
  204134. case MouseCursor::BottomEdgeResizeCursor:
  204135. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204136. case MouseCursor::TopLeftCornerResizeCursor:
  204137. case MouseCursor::BottomRightCornerResizeCursor:
  204138. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204139. case MouseCursor::TopRightCornerResizeCursor:
  204140. case MouseCursor::BottomLeftCornerResizeCursor:
  204141. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204142. case MouseCursor::UpDownLeftRightResizeCursor:
  204143. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204144. case MouseCursor::CrosshairCursor:
  204145. c = [NSCursor crosshairCursor];
  204146. break;
  204147. }
  204148. [c retain];
  204149. return c;
  204150. }
  204151. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  204152. {
  204153. NSCursor* c = (NSCursor*) cursorHandle;
  204154. [c release];
  204155. }
  204156. void MouseCursor::showInAllWindows() const
  204157. {
  204158. showInWindow (0);
  204159. }
  204160. void MouseCursor::showInWindow (ComponentPeer*) const
  204161. {
  204162. NSCursor* const c = (NSCursor*) getHandle();
  204163. [c set];
  204164. }
  204165. #else
  204166. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  204167. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  204168. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  204169. void MouseCursor::showInAllWindows() const {}
  204170. void MouseCursor::showInWindow (ComponentPeer*) const {}
  204171. #endif
  204172. #endif
  204173. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204174. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204175. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204176. // compiled on its own).
  204177. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204178. #if JUCE_MAC
  204179. END_JUCE_NAMESPACE
  204180. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204181. @interface DownloadClickDetector : NSObject
  204182. {
  204183. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204184. }
  204185. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204186. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204187. request: (NSURLRequest*) request
  204188. frame: (WebFrame*) frame
  204189. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204190. @end
  204191. @implementation DownloadClickDetector
  204192. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204193. {
  204194. [super init];
  204195. ownerComponent = ownerComponent_;
  204196. return self;
  204197. }
  204198. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204199. request: (NSURLRequest*) request
  204200. frame: (WebFrame*) frame
  204201. decisionListener: (id <WebPolicyDecisionListener>) listener
  204202. {
  204203. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204204. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204205. [listener use];
  204206. else
  204207. [listener ignore];
  204208. }
  204209. @end
  204210. BEGIN_JUCE_NAMESPACE
  204211. class WebBrowserComponentInternal : public NSViewComponent
  204212. {
  204213. public:
  204214. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204215. {
  204216. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204217. frameName: @""
  204218. groupName: @""];
  204219. setView (webView);
  204220. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204221. [webView setPolicyDelegate: clickListener];
  204222. }
  204223. ~WebBrowserComponentInternal()
  204224. {
  204225. [webView setPolicyDelegate: nil];
  204226. [clickListener release];
  204227. setView (0);
  204228. }
  204229. void goToURL (const String& url,
  204230. const StringArray* headers,
  204231. const MemoryBlock* postData)
  204232. {
  204233. NSMutableURLRequest* r
  204234. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204235. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204236. timeoutInterval: 30.0];
  204237. if (postData != 0 && postData->getSize() > 0)
  204238. {
  204239. [r setHTTPMethod: @"POST"];
  204240. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204241. length: postData->getSize()]];
  204242. }
  204243. if (headers != 0)
  204244. {
  204245. for (int i = 0; i < headers->size(); ++i)
  204246. {
  204247. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  204248. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  204249. [r setValue: juceStringToNS (headerValue)
  204250. forHTTPHeaderField: juceStringToNS (headerName)];
  204251. }
  204252. }
  204253. stop();
  204254. [[webView mainFrame] loadRequest: r];
  204255. }
  204256. void goBack()
  204257. {
  204258. [webView goBack];
  204259. }
  204260. void goForward()
  204261. {
  204262. [webView goForward];
  204263. }
  204264. void stop()
  204265. {
  204266. [webView stopLoading: nil];
  204267. }
  204268. void refresh()
  204269. {
  204270. [webView reload: nil];
  204271. }
  204272. private:
  204273. WebView* webView;
  204274. DownloadClickDetector* clickListener;
  204275. };
  204276. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204277. : browser (0),
  204278. blankPageShown (false),
  204279. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204280. {
  204281. setOpaque (true);
  204282. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204283. }
  204284. WebBrowserComponent::~WebBrowserComponent()
  204285. {
  204286. deleteAndZero (browser);
  204287. }
  204288. void WebBrowserComponent::goToURL (const String& url,
  204289. const StringArray* headers,
  204290. const MemoryBlock* postData)
  204291. {
  204292. lastURL = url;
  204293. lastHeaders.clear();
  204294. if (headers != 0)
  204295. lastHeaders = *headers;
  204296. lastPostData.setSize (0);
  204297. if (postData != 0)
  204298. lastPostData = *postData;
  204299. blankPageShown = false;
  204300. browser->goToURL (url, headers, postData);
  204301. }
  204302. void WebBrowserComponent::stop()
  204303. {
  204304. browser->stop();
  204305. }
  204306. void WebBrowserComponent::goBack()
  204307. {
  204308. lastURL = String::empty;
  204309. blankPageShown = false;
  204310. browser->goBack();
  204311. }
  204312. void WebBrowserComponent::goForward()
  204313. {
  204314. lastURL = String::empty;
  204315. browser->goForward();
  204316. }
  204317. void WebBrowserComponent::refresh()
  204318. {
  204319. browser->refresh();
  204320. }
  204321. void WebBrowserComponent::paint (Graphics& g)
  204322. {
  204323. }
  204324. void WebBrowserComponent::checkWindowAssociation()
  204325. {
  204326. if (isShowing())
  204327. {
  204328. if (blankPageShown)
  204329. goBack();
  204330. }
  204331. else
  204332. {
  204333. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204334. {
  204335. // when the component becomes invisible, some stuff like flash
  204336. // carries on playing audio, so we need to force it onto a blank
  204337. // page to avoid this, (and send it back when it's made visible again).
  204338. blankPageShown = true;
  204339. browser->goToURL ("about:blank", 0, 0);
  204340. }
  204341. }
  204342. }
  204343. void WebBrowserComponent::reloadLastURL()
  204344. {
  204345. if (lastURL.isNotEmpty())
  204346. {
  204347. goToURL (lastURL, &lastHeaders, &lastPostData);
  204348. lastURL = String::empty;
  204349. }
  204350. }
  204351. void WebBrowserComponent::parentHierarchyChanged()
  204352. {
  204353. checkWindowAssociation();
  204354. }
  204355. void WebBrowserComponent::resized()
  204356. {
  204357. browser->setSize (getWidth(), getHeight());
  204358. }
  204359. void WebBrowserComponent::visibilityChanged()
  204360. {
  204361. checkWindowAssociation();
  204362. }
  204363. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204364. {
  204365. return true;
  204366. }
  204367. #else
  204368. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204369. {
  204370. }
  204371. WebBrowserComponent::~WebBrowserComponent()
  204372. {
  204373. }
  204374. void WebBrowserComponent::goToURL (const String& url,
  204375. const StringArray* headers,
  204376. const MemoryBlock* postData)
  204377. {
  204378. }
  204379. void WebBrowserComponent::stop()
  204380. {
  204381. }
  204382. void WebBrowserComponent::goBack()
  204383. {
  204384. }
  204385. void WebBrowserComponent::goForward()
  204386. {
  204387. }
  204388. void WebBrowserComponent::refresh()
  204389. {
  204390. }
  204391. void WebBrowserComponent::paint (Graphics& g)
  204392. {
  204393. }
  204394. void WebBrowserComponent::checkWindowAssociation()
  204395. {
  204396. }
  204397. void WebBrowserComponent::reloadLastURL()
  204398. {
  204399. }
  204400. void WebBrowserComponent::parentHierarchyChanged()
  204401. {
  204402. }
  204403. void WebBrowserComponent::resized()
  204404. {
  204405. }
  204406. void WebBrowserComponent::visibilityChanged()
  204407. {
  204408. }
  204409. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204410. {
  204411. return true;
  204412. }
  204413. #endif
  204414. #endif
  204415. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204416. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204417. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204418. // compiled on its own).
  204419. #if JUCE_INCLUDED_FILE
  204420. class IPhoneAudioIODevice : public AudioIODevice
  204421. {
  204422. public:
  204423. IPhoneAudioIODevice (const String& deviceName)
  204424. : AudioIODevice (deviceName, "Audio"),
  204425. audioUnit (0),
  204426. isRunning (false),
  204427. callback (0),
  204428. actualBufferSize (0),
  204429. floatData (1, 2)
  204430. {
  204431. numInputChannels = 2;
  204432. numOutputChannels = 2;
  204433. preferredBufferSize = 0;
  204434. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204435. updateDeviceInfo();
  204436. }
  204437. ~IPhoneAudioIODevice()
  204438. {
  204439. close();
  204440. }
  204441. const StringArray getOutputChannelNames()
  204442. {
  204443. StringArray s;
  204444. s.add ("Left");
  204445. s.add ("Right");
  204446. return s;
  204447. }
  204448. const StringArray getInputChannelNames()
  204449. {
  204450. StringArray s;
  204451. if (audioInputIsAvailable)
  204452. {
  204453. s.add ("Left");
  204454. s.add ("Right");
  204455. }
  204456. return s;
  204457. }
  204458. int getNumSampleRates()
  204459. {
  204460. return 1;
  204461. }
  204462. double getSampleRate (int index)
  204463. {
  204464. return sampleRate;
  204465. }
  204466. int getNumBufferSizesAvailable()
  204467. {
  204468. return 1;
  204469. }
  204470. int getBufferSizeSamples (int index)
  204471. {
  204472. return getDefaultBufferSize();
  204473. }
  204474. int getDefaultBufferSize()
  204475. {
  204476. return 1024;
  204477. }
  204478. const String open (const BigInteger& inputChannels,
  204479. const BigInteger& outputChannels,
  204480. double sampleRate,
  204481. int bufferSize)
  204482. {
  204483. close();
  204484. lastError = String::empty;
  204485. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204486. // xxx set up channel mapping
  204487. activeOutputChans = outputChannels;
  204488. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204489. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204490. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204491. activeInputChans = inputChannels;
  204492. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204493. numInputChannels = activeInputChans.countNumberOfSetBits();
  204494. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204495. AudioSessionSetActive (true);
  204496. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204497. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204498. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204499. fixAudioRouteIfSetToReceiver();
  204500. updateDeviceInfo();
  204501. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204502. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204503. actualBufferSize = preferredBufferSize;
  204504. prepareFloatBuffers();
  204505. isRunning = true;
  204506. propertyChanged (0, 0, 0); // creates and starts the AU
  204507. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204508. return lastError;
  204509. }
  204510. void close()
  204511. {
  204512. if (isRunning)
  204513. {
  204514. isRunning = false;
  204515. AudioSessionSetActive (false);
  204516. if (audioUnit != 0)
  204517. {
  204518. AudioComponentInstanceDispose (audioUnit);
  204519. audioUnit = 0;
  204520. }
  204521. }
  204522. }
  204523. bool isOpen()
  204524. {
  204525. return isRunning;
  204526. }
  204527. int getCurrentBufferSizeSamples()
  204528. {
  204529. return actualBufferSize;
  204530. }
  204531. double getCurrentSampleRate()
  204532. {
  204533. return sampleRate;
  204534. }
  204535. int getCurrentBitDepth()
  204536. {
  204537. return 16;
  204538. }
  204539. const BigInteger getActiveOutputChannels() const
  204540. {
  204541. return activeOutputChans;
  204542. }
  204543. const BigInteger getActiveInputChannels() const
  204544. {
  204545. return activeInputChans;
  204546. }
  204547. int getOutputLatencyInSamples()
  204548. {
  204549. return 0; //xxx
  204550. }
  204551. int getInputLatencyInSamples()
  204552. {
  204553. return 0; //xxx
  204554. }
  204555. void start (AudioIODeviceCallback* callback_)
  204556. {
  204557. if (isRunning && callback != callback_)
  204558. {
  204559. if (callback_ != 0)
  204560. callback_->audioDeviceAboutToStart (this);
  204561. const ScopedLock sl (callbackLock);
  204562. callback = callback_;
  204563. }
  204564. }
  204565. void stop()
  204566. {
  204567. if (isRunning)
  204568. {
  204569. AudioIODeviceCallback* lastCallback;
  204570. {
  204571. const ScopedLock sl (callbackLock);
  204572. lastCallback = callback;
  204573. callback = 0;
  204574. }
  204575. if (lastCallback != 0)
  204576. lastCallback->audioDeviceStopped();
  204577. }
  204578. }
  204579. bool isPlaying()
  204580. {
  204581. return isRunning && callback != 0;
  204582. }
  204583. const String getLastError()
  204584. {
  204585. return lastError;
  204586. }
  204587. private:
  204588. CriticalSection callbackLock;
  204589. Float64 sampleRate;
  204590. int numInputChannels, numOutputChannels;
  204591. int preferredBufferSize;
  204592. int actualBufferSize;
  204593. bool isRunning;
  204594. String lastError;
  204595. AudioStreamBasicDescription format;
  204596. AudioUnit audioUnit;
  204597. UInt32 audioInputIsAvailable;
  204598. AudioIODeviceCallback* callback;
  204599. BigInteger activeOutputChans, activeInputChans;
  204600. AudioSampleBuffer floatData;
  204601. float* inputChannels[3];
  204602. float* outputChannels[3];
  204603. bool monoInputChannelNumber, monoOutputChannelNumber;
  204604. void prepareFloatBuffers()
  204605. {
  204606. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204607. zerostruct (inputChannels);
  204608. zerostruct (outputChannels);
  204609. for (int i = 0; i < numInputChannels; ++i)
  204610. inputChannels[i] = floatData.getSampleData (i);
  204611. for (int i = 0; i < numOutputChannels; ++i)
  204612. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204613. }
  204614. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204615. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204616. {
  204617. OSStatus err = noErr;
  204618. if (audioInputIsAvailable)
  204619. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204620. const ScopedLock sl (callbackLock);
  204621. if (callback != 0)
  204622. {
  204623. if (audioInputIsAvailable && numInputChannels > 0)
  204624. {
  204625. short* shortData = (short*) ioData->mBuffers[0].mData;
  204626. if (numInputChannels >= 2)
  204627. {
  204628. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204629. {
  204630. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204631. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204632. }
  204633. }
  204634. else
  204635. {
  204636. if (monoInputChannelNumber > 0)
  204637. ++shortData;
  204638. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204639. {
  204640. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204641. ++shortData;
  204642. }
  204643. }
  204644. }
  204645. else
  204646. {
  204647. for (int i = numInputChannels; --i >= 0;)
  204648. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204649. }
  204650. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204651. outputChannels, numOutputChannels,
  204652. (int) inNumberFrames);
  204653. short* shortData = (short*) ioData->mBuffers[0].mData;
  204654. int n = 0;
  204655. if (numOutputChannels >= 2)
  204656. {
  204657. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204658. {
  204659. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204660. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204661. }
  204662. }
  204663. else if (numOutputChannels == 1)
  204664. {
  204665. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204666. {
  204667. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204668. shortData [n++] = s;
  204669. shortData [n++] = s;
  204670. }
  204671. }
  204672. else
  204673. {
  204674. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204675. }
  204676. }
  204677. else
  204678. {
  204679. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204680. }
  204681. return err;
  204682. }
  204683. void updateDeviceInfo()
  204684. {
  204685. UInt32 size = sizeof (sampleRate);
  204686. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204687. size = sizeof (audioInputIsAvailable);
  204688. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204689. }
  204690. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204691. {
  204692. if (! isRunning)
  204693. return;
  204694. if (inPropertyValue != 0)
  204695. {
  204696. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204697. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204698. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204699. SInt32 routeChangeReason;
  204700. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204701. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204702. fixAudioRouteIfSetToReceiver();
  204703. }
  204704. updateDeviceInfo();
  204705. createAudioUnit();
  204706. AudioSessionSetActive (true);
  204707. if (audioUnit != 0)
  204708. {
  204709. UInt32 formatSize = sizeof (format);
  204710. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204711. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204712. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204713. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204714. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204715. AudioOutputUnitStart (audioUnit);
  204716. }
  204717. }
  204718. void interruptionListener (UInt32 inInterruption)
  204719. {
  204720. if (inInterruption == kAudioSessionEndInterruption)
  204721. {
  204722. isRunning = true;
  204723. AudioSessionSetActive (true);
  204724. AudioOutputUnitStart (audioUnit);
  204725. }
  204726. }
  204727. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204728. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204729. {
  204730. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204731. }
  204732. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204733. {
  204734. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204735. }
  204736. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204737. {
  204738. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204739. }
  204740. void resetFormat (const int numChannels)
  204741. {
  204742. memset (&format, 0, sizeof (format));
  204743. format.mFormatID = kAudioFormatLinearPCM;
  204744. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204745. format.mBitsPerChannel = 8 * sizeof (short);
  204746. format.mChannelsPerFrame = 2;
  204747. format.mFramesPerPacket = 1;
  204748. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204749. }
  204750. bool createAudioUnit()
  204751. {
  204752. if (audioUnit != 0)
  204753. {
  204754. AudioComponentInstanceDispose (audioUnit);
  204755. audioUnit = 0;
  204756. }
  204757. resetFormat (2);
  204758. AudioComponentDescription desc;
  204759. desc.componentType = kAudioUnitType_Output;
  204760. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204761. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204762. desc.componentFlags = 0;
  204763. desc.componentFlagsMask = 0;
  204764. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204765. AudioComponentInstanceNew (comp, &audioUnit);
  204766. if (audioUnit == 0)
  204767. return false;
  204768. const UInt32 one = 1;
  204769. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204770. AudioChannelLayout layout;
  204771. layout.mChannelBitmap = 0;
  204772. layout.mNumberChannelDescriptions = 0;
  204773. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204774. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204775. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204776. AURenderCallbackStruct inputProc;
  204777. inputProc.inputProc = processStatic;
  204778. inputProc.inputProcRefCon = this;
  204779. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204780. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204781. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204782. AudioUnitInitialize (audioUnit);
  204783. return true;
  204784. }
  204785. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204786. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204787. static void fixAudioRouteIfSetToReceiver()
  204788. {
  204789. CFStringRef audioRoute = 0;
  204790. UInt32 propertySize = sizeof (audioRoute);
  204791. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204792. {
  204793. NSString* route = (NSString*) audioRoute;
  204794. //DBG ("audio route: " + nsStringToJuce (route));
  204795. if ([route hasPrefix: @"Receiver"])
  204796. {
  204797. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204798. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204799. }
  204800. CFRelease (audioRoute);
  204801. }
  204802. }
  204803. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204804. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204805. };
  204806. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204807. {
  204808. public:
  204809. IPhoneAudioIODeviceType()
  204810. : AudioIODeviceType ("iPhone Audio")
  204811. {
  204812. }
  204813. ~IPhoneAudioIODeviceType()
  204814. {
  204815. }
  204816. void scanForDevices()
  204817. {
  204818. }
  204819. const StringArray getDeviceNames (bool wantInputNames) const
  204820. {
  204821. StringArray s;
  204822. s.add ("iPhone Audio");
  204823. return s;
  204824. }
  204825. int getDefaultDeviceIndex (bool forInput) const
  204826. {
  204827. return 0;
  204828. }
  204829. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204830. {
  204831. return device != 0 ? 0 : -1;
  204832. }
  204833. bool hasSeparateInputsAndOutputs() const { return false; }
  204834. AudioIODevice* createDevice (const String& outputDeviceName,
  204835. const String& inputDeviceName)
  204836. {
  204837. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204838. {
  204839. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204840. : inputDeviceName);
  204841. }
  204842. return 0;
  204843. }
  204844. juce_UseDebuggingNewOperator
  204845. private:
  204846. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204847. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204848. };
  204849. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204850. {
  204851. return new IPhoneAudioIODeviceType();
  204852. }
  204853. #endif
  204854. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204855. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204856. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204857. // compiled on its own).
  204858. #if JUCE_INCLUDED_FILE
  204859. #if JUCE_MAC
  204860. #undef log
  204861. #define log(a) Logger::writeToLog(a)
  204862. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204863. {
  204864. if (err == noErr)
  204865. return true;
  204866. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204867. jassertfalse
  204868. return false;
  204869. }
  204870. #undef OK
  204871. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204872. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204873. {
  204874. String result;
  204875. CFStringRef str = 0;
  204876. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204877. if (str != 0)
  204878. {
  204879. result = PlatformUtilities::cfStringToJuceString (str);
  204880. CFRelease (str);
  204881. str = 0;
  204882. }
  204883. MIDIEntityRef entity = 0;
  204884. MIDIEndpointGetEntity (endpoint, &entity);
  204885. if (entity == 0)
  204886. return result; // probably virtual
  204887. if (result.isEmpty())
  204888. {
  204889. // endpoint name has zero length - try the entity
  204890. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204891. if (str != 0)
  204892. {
  204893. result += PlatformUtilities::cfStringToJuceString (str);
  204894. CFRelease (str);
  204895. str = 0;
  204896. }
  204897. }
  204898. // now consider the device's name
  204899. MIDIDeviceRef device = 0;
  204900. MIDIEntityGetDevice (entity, &device);
  204901. if (device == 0)
  204902. return result;
  204903. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204904. if (str != 0)
  204905. {
  204906. const String s (PlatformUtilities::cfStringToJuceString (str));
  204907. CFRelease (str);
  204908. // if an external device has only one entity, throw away
  204909. // the endpoint name and just use the device name
  204910. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204911. {
  204912. result = s;
  204913. }
  204914. else if (! result.startsWithIgnoreCase (s))
  204915. {
  204916. // prepend the device name to the entity name
  204917. result = (s + " " + result).trimEnd();
  204918. }
  204919. }
  204920. return result;
  204921. }
  204922. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204923. {
  204924. String result;
  204925. // Does the endpoint have connections?
  204926. CFDataRef connections = 0;
  204927. int numConnections = 0;
  204928. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204929. if (connections != 0)
  204930. {
  204931. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204932. if (numConnections > 0)
  204933. {
  204934. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204935. for (int i = 0; i < numConnections; ++i, ++pid)
  204936. {
  204937. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204938. MIDIObjectRef connObject;
  204939. MIDIObjectType connObjectType;
  204940. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204941. if (err == noErr)
  204942. {
  204943. String s;
  204944. if (connObjectType == kMIDIObjectType_ExternalSource
  204945. || connObjectType == kMIDIObjectType_ExternalDestination)
  204946. {
  204947. // Connected to an external device's endpoint (10.3 and later).
  204948. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204949. }
  204950. else
  204951. {
  204952. // Connected to an external device (10.2) (or something else, catch-all)
  204953. CFStringRef str = 0;
  204954. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204955. if (str != 0)
  204956. {
  204957. s = PlatformUtilities::cfStringToJuceString (str);
  204958. CFRelease (str);
  204959. }
  204960. }
  204961. if (s.isNotEmpty())
  204962. {
  204963. if (result.isNotEmpty())
  204964. result += ", ";
  204965. result += s;
  204966. }
  204967. }
  204968. }
  204969. }
  204970. CFRelease (connections);
  204971. }
  204972. if (result.isNotEmpty())
  204973. return result;
  204974. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204975. return getEndpointName (endpoint, false);
  204976. }
  204977. const StringArray MidiOutput::getDevices()
  204978. {
  204979. StringArray s;
  204980. const ItemCount num = MIDIGetNumberOfDestinations();
  204981. for (ItemCount i = 0; i < num; ++i)
  204982. {
  204983. MIDIEndpointRef dest = MIDIGetDestination (i);
  204984. if (dest != 0)
  204985. {
  204986. String name (getConnectedEndpointName (dest));
  204987. if (name.isEmpty())
  204988. name = "<error>";
  204989. s.add (name);
  204990. }
  204991. else
  204992. {
  204993. s.add ("<error>");
  204994. }
  204995. }
  204996. return s;
  204997. }
  204998. int MidiOutput::getDefaultDeviceIndex()
  204999. {
  205000. return 0;
  205001. }
  205002. static MIDIClientRef globalMidiClient;
  205003. static bool hasGlobalClientBeenCreated = false;
  205004. static bool makeSureClientExists()
  205005. {
  205006. if (! hasGlobalClientBeenCreated)
  205007. {
  205008. String name ("JUCE");
  205009. if (JUCEApplication::getInstance() != 0)
  205010. name = JUCEApplication::getInstance()->getApplicationName();
  205011. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205012. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205013. CFRelease (appName);
  205014. }
  205015. return hasGlobalClientBeenCreated;
  205016. }
  205017. class MidiPortAndEndpoint
  205018. {
  205019. public:
  205020. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205021. : port (port_), endPoint (endPoint_)
  205022. {
  205023. }
  205024. ~MidiPortAndEndpoint()
  205025. {
  205026. if (port != 0)
  205027. MIDIPortDispose (port);
  205028. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205029. MIDIEndpointDispose (endPoint);
  205030. }
  205031. MIDIPortRef port;
  205032. MIDIEndpointRef endPoint;
  205033. };
  205034. MidiOutput* MidiOutput::openDevice (int index)
  205035. {
  205036. MidiOutput* mo = 0;
  205037. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205038. {
  205039. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205040. CFStringRef pname;
  205041. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205042. {
  205043. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  205044. if (makeSureClientExists())
  205045. {
  205046. MIDIPortRef port;
  205047. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205048. {
  205049. mo = new MidiOutput();
  205050. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  205051. }
  205052. }
  205053. CFRelease (pname);
  205054. }
  205055. }
  205056. return mo;
  205057. }
  205058. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205059. {
  205060. MidiOutput* mo = 0;
  205061. if (makeSureClientExists())
  205062. {
  205063. MIDIEndpointRef endPoint;
  205064. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205065. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205066. {
  205067. mo = new MidiOutput();
  205068. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  205069. }
  205070. CFRelease (name);
  205071. }
  205072. return mo;
  205073. }
  205074. MidiOutput::~MidiOutput()
  205075. {
  205076. delete (MidiPortAndEndpoint*) internal;
  205077. }
  205078. void MidiOutput::reset()
  205079. {
  205080. }
  205081. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205082. {
  205083. return false;
  205084. }
  205085. void MidiOutput::setVolume (float leftVol, float rightVol)
  205086. {
  205087. }
  205088. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205089. {
  205090. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205091. if (message.isSysEx())
  205092. {
  205093. const int maxPacketSize = 256;
  205094. int pos = 0, bytesLeft = message.getRawDataSize();
  205095. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205096. HeapBlock <MIDIPacketList> packets;
  205097. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205098. packets->numPackets = numPackets;
  205099. MIDIPacket* p = packets->packet;
  205100. for (int i = 0; i < numPackets; ++i)
  205101. {
  205102. p->timeStamp = 0;
  205103. p->length = jmin (maxPacketSize, bytesLeft);
  205104. memcpy (p->data, message.getRawData() + pos, p->length);
  205105. pos += p->length;
  205106. bytesLeft -= p->length;
  205107. p = MIDIPacketNext (p);
  205108. }
  205109. if (mpe->port != 0)
  205110. MIDISend (mpe->port, mpe->endPoint, packets);
  205111. else
  205112. MIDIReceived (mpe->endPoint, packets);
  205113. }
  205114. else
  205115. {
  205116. MIDIPacketList packets;
  205117. packets.numPackets = 1;
  205118. packets.packet[0].timeStamp = 0;
  205119. packets.packet[0].length = message.getRawDataSize();
  205120. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205121. if (mpe->port != 0)
  205122. MIDISend (mpe->port, mpe->endPoint, &packets);
  205123. else
  205124. MIDIReceived (mpe->endPoint, &packets);
  205125. }
  205126. }
  205127. const StringArray MidiInput::getDevices()
  205128. {
  205129. StringArray s;
  205130. const ItemCount num = MIDIGetNumberOfSources();
  205131. for (ItemCount i = 0; i < num; ++i)
  205132. {
  205133. MIDIEndpointRef source = MIDIGetSource (i);
  205134. if (source != 0)
  205135. {
  205136. String name (getConnectedEndpointName (source));
  205137. if (name.isEmpty())
  205138. name = "<error>";
  205139. s.add (name);
  205140. }
  205141. else
  205142. {
  205143. s.add ("<error>");
  205144. }
  205145. }
  205146. return s;
  205147. }
  205148. int MidiInput::getDefaultDeviceIndex()
  205149. {
  205150. return 0;
  205151. }
  205152. struct MidiPortAndCallback
  205153. {
  205154. MidiInput* input;
  205155. MidiPortAndEndpoint* portAndEndpoint;
  205156. MidiInputCallback* callback;
  205157. MemoryBlock pendingData;
  205158. int pendingBytes;
  205159. double pendingDataTime;
  205160. bool active;
  205161. void processSysex (const uint8*& d, int& size, const double time)
  205162. {
  205163. if (*d == 0xf0)
  205164. {
  205165. pendingBytes = 0;
  205166. pendingDataTime = time;
  205167. }
  205168. pendingData.ensureSize (pendingBytes + size, false);
  205169. uint8* totalMessage = (uint8*) pendingData.getData();
  205170. uint8* dest = totalMessage + pendingBytes;
  205171. while (size > 0)
  205172. {
  205173. if (pendingBytes > 0 && *d >= 0x80)
  205174. {
  205175. if (*d >= 0xfa || *d == 0xf8)
  205176. {
  205177. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205178. ++d;
  205179. --size;
  205180. }
  205181. else
  205182. {
  205183. if (*d == 0xf7)
  205184. {
  205185. *dest++ = *d++;
  205186. pendingBytes++;
  205187. --size;
  205188. }
  205189. break;
  205190. }
  205191. }
  205192. else
  205193. {
  205194. *dest++ = *d++;
  205195. pendingBytes++;
  205196. --size;
  205197. }
  205198. }
  205199. if (totalMessage [pendingBytes - 1] == 0xf7)
  205200. {
  205201. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205202. pendingBytes = 0;
  205203. }
  205204. else
  205205. {
  205206. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205207. }
  205208. }
  205209. };
  205210. namespace CoreMidiCallbacks
  205211. {
  205212. static CriticalSection callbackLock;
  205213. static VoidArray activeCallbacks;
  205214. }
  205215. static void midiInputProc (const MIDIPacketList* pktlist,
  205216. void* readProcRefCon,
  205217. void* srcConnRefCon)
  205218. {
  205219. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205220. const double originalTime = time;
  205221. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205222. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205223. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205224. {
  205225. const MIDIPacket* packet = &pktlist->packet[0];
  205226. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205227. {
  205228. const uint8* d = (const uint8*) (packet->data);
  205229. int size = packet->length;
  205230. while (size > 0)
  205231. {
  205232. time = originalTime;
  205233. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205234. {
  205235. mpc->processSysex (d, size, time);
  205236. }
  205237. else
  205238. {
  205239. int used = 0;
  205240. const MidiMessage m (d, size, used, 0, time);
  205241. if (used <= 0)
  205242. {
  205243. jassertfalse // malformed midi message
  205244. break;
  205245. }
  205246. else
  205247. {
  205248. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205249. }
  205250. size -= used;
  205251. d += used;
  205252. }
  205253. }
  205254. packet = MIDIPacketNext (packet);
  205255. }
  205256. }
  205257. }
  205258. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205259. {
  205260. MidiInput* mi = 0;
  205261. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205262. {
  205263. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205264. if (endPoint != 0)
  205265. {
  205266. CFStringRef pname;
  205267. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205268. {
  205269. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205270. if (makeSureClientExists())
  205271. {
  205272. MIDIPortRef port;
  205273. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205274. mpc->active = false;
  205275. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205276. {
  205277. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205278. {
  205279. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205280. mpc->callback = callback;
  205281. mpc->pendingBytes = 0;
  205282. mpc->pendingData.ensureSize (128);
  205283. mi = new MidiInput (getDevices() [index]);
  205284. mpc->input = mi;
  205285. mi->internal = mpc;
  205286. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205287. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205288. }
  205289. else
  205290. {
  205291. OK (MIDIPortDispose (port));
  205292. }
  205293. }
  205294. }
  205295. }
  205296. CFRelease (pname);
  205297. }
  205298. }
  205299. return mi;
  205300. }
  205301. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205302. {
  205303. MidiInput* mi = 0;
  205304. if (makeSureClientExists())
  205305. {
  205306. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205307. mpc->active = false;
  205308. MIDIEndpointRef endPoint;
  205309. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205310. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205311. {
  205312. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205313. mpc->callback = callback;
  205314. mpc->pendingBytes = 0;
  205315. mpc->pendingData.ensureSize (128);
  205316. mi = new MidiInput (deviceName);
  205317. mpc->input = mi;
  205318. mi->internal = mpc;
  205319. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205320. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205321. }
  205322. CFRelease (name);
  205323. }
  205324. return mi;
  205325. }
  205326. MidiInput::MidiInput (const String& name_)
  205327. : name (name_)
  205328. {
  205329. }
  205330. MidiInput::~MidiInput()
  205331. {
  205332. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205333. mpc->active = false;
  205334. {
  205335. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205336. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205337. }
  205338. if (mpc->portAndEndpoint->port != 0)
  205339. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205340. delete mpc->portAndEndpoint;
  205341. delete mpc;
  205342. }
  205343. void MidiInput::start()
  205344. {
  205345. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205346. ((MidiPortAndCallback*) internal)->active = true;
  205347. }
  205348. void MidiInput::stop()
  205349. {
  205350. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205351. ((MidiPortAndCallback*) internal)->active = false;
  205352. }
  205353. #undef log
  205354. #else
  205355. MidiOutput::~MidiOutput()
  205356. {
  205357. }
  205358. void MidiOutput::reset()
  205359. {
  205360. }
  205361. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205362. {
  205363. return false;
  205364. }
  205365. void MidiOutput::setVolume (float leftVol, float rightVol)
  205366. {
  205367. }
  205368. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205369. {
  205370. }
  205371. const StringArray MidiOutput::getDevices()
  205372. {
  205373. return StringArray();
  205374. }
  205375. MidiOutput* MidiOutput::openDevice (int index)
  205376. {
  205377. return 0;
  205378. }
  205379. const StringArray MidiInput::getDevices()
  205380. {
  205381. return StringArray();
  205382. }
  205383. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205384. {
  205385. return 0;
  205386. }
  205387. #endif
  205388. #endif
  205389. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205390. #else
  205391. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205392. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205393. // compiled on its own).
  205394. #if JUCE_INCLUDED_FILE
  205395. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205396. #define SUPPORT_10_4_FONTS 1
  205397. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205398. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205399. #define SUPPORT_ONLY_10_4_FONTS 1
  205400. #endif
  205401. END_JUCE_NAMESPACE
  205402. @interface NSFont (PrivateHack)
  205403. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205404. @end
  205405. BEGIN_JUCE_NAMESPACE
  205406. #endif
  205407. class MacTypeface : public Typeface
  205408. {
  205409. public:
  205410. MacTypeface (const Font& font)
  205411. : Typeface (font.getTypefaceName())
  205412. {
  205413. const ScopedAutoReleasePool pool;
  205414. renderingTransform = CGAffineTransformIdentity;
  205415. bool needsItalicTransform = false;
  205416. #if JUCE_IPHONE
  205417. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205418. if (font.isItalic() || font.isBold())
  205419. {
  205420. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205421. for (NSString* i in familyFonts)
  205422. {
  205423. const String fn (nsStringToJuce (i));
  205424. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205425. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205426. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205427. || afterDash.containsIgnoreCase ("italic")
  205428. || fn.endsWithIgnoreCase ("oblique")
  205429. || fn.endsWithIgnoreCase ("italic");
  205430. if (probablyBold == font.isBold()
  205431. && probablyItalic == font.isItalic())
  205432. {
  205433. fontName = i;
  205434. needsItalicTransform = false;
  205435. break;
  205436. }
  205437. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205438. {
  205439. fontName = i;
  205440. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205441. }
  205442. }
  205443. if (needsItalicTransform)
  205444. renderingTransform.c = 0.15f;
  205445. }
  205446. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205447. const int ascender = abs (CGFontGetAscent (fontRef));
  205448. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205449. ascent = ascender / totalHeight;
  205450. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205451. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205452. #else
  205453. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205454. if (font.isItalic())
  205455. {
  205456. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205457. toHaveTrait: NSItalicFontMask];
  205458. if (newFont == nsFont)
  205459. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205460. nsFont = newFont;
  205461. }
  205462. if (font.isBold())
  205463. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205464. [nsFont retain];
  205465. ascent = fabsf ((float) [nsFont ascender]);
  205466. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205467. ascent /= totalSize;
  205468. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205469. if (needsItalicTransform)
  205470. {
  205471. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205472. renderingTransform.c = 0.15f;
  205473. }
  205474. #if SUPPORT_ONLY_10_4_FONTS
  205475. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205476. if (atsFont == 0)
  205477. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205478. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205479. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205480. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205481. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205482. #else
  205483. #if SUPPORT_10_4_FONTS
  205484. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205485. {
  205486. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205487. if (atsFont == 0)
  205488. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205489. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205490. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205491. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205492. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205493. }
  205494. else
  205495. #endif
  205496. {
  205497. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205498. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205499. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205500. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205501. }
  205502. #endif
  205503. #endif
  205504. }
  205505. ~MacTypeface()
  205506. {
  205507. #if ! JUCE_IPHONE
  205508. [nsFont release];
  205509. #endif
  205510. if (fontRef != 0)
  205511. CGFontRelease (fontRef);
  205512. }
  205513. float getAscent() const
  205514. {
  205515. return ascent;
  205516. }
  205517. float getDescent() const
  205518. {
  205519. return 1.0f - ascent;
  205520. }
  205521. float getStringWidth (const String& text)
  205522. {
  205523. if (fontRef == 0 || text.isEmpty())
  205524. return 0;
  205525. const int length = text.length();
  205526. HeapBlock <CGGlyph> glyphs;
  205527. createGlyphsForString (text, length, glyphs);
  205528. float x = 0;
  205529. #if SUPPORT_ONLY_10_4_FONTS
  205530. HeapBlock <NSSize> advances (length);
  205531. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205532. for (int i = 0; i < length; ++i)
  205533. x += advances[i].width;
  205534. #else
  205535. #if SUPPORT_10_4_FONTS
  205536. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205537. {
  205538. HeapBlock <NSSize> advances (length);
  205539. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205540. for (int i = 0; i < length; ++i)
  205541. x += advances[i].width;
  205542. }
  205543. else
  205544. #endif
  205545. {
  205546. HeapBlock <int> advances (length);
  205547. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205548. for (int i = 0; i < length; ++i)
  205549. x += advances[i];
  205550. }
  205551. #endif
  205552. return x * unitsToHeightScaleFactor;
  205553. }
  205554. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205555. {
  205556. xOffsets.add (0);
  205557. if (fontRef == 0 || text.isEmpty())
  205558. return;
  205559. const int length = text.length();
  205560. HeapBlock <CGGlyph> glyphs;
  205561. createGlyphsForString (text, length, glyphs);
  205562. #if SUPPORT_ONLY_10_4_FONTS
  205563. HeapBlock <NSSize> advances (length);
  205564. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205565. int x = 0;
  205566. for (int i = 0; i < length; ++i)
  205567. {
  205568. x += advances[i].width;
  205569. xOffsets.add (x * unitsToHeightScaleFactor);
  205570. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205571. }
  205572. #else
  205573. #if SUPPORT_10_4_FONTS
  205574. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205575. {
  205576. HeapBlock <NSSize> advances (length);
  205577. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205578. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205579. float x = 0;
  205580. for (int i = 0; i < length; ++i)
  205581. {
  205582. x += advances[i].width;
  205583. xOffsets.add (x * unitsToHeightScaleFactor);
  205584. resultGlyphs.add (nsGlyphs[i]);
  205585. }
  205586. }
  205587. else
  205588. #endif
  205589. {
  205590. HeapBlock <int> advances (length);
  205591. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205592. {
  205593. int x = 0;
  205594. for (int i = 0; i < length; ++i)
  205595. {
  205596. x += advances [i];
  205597. xOffsets.add (x * unitsToHeightScaleFactor);
  205598. resultGlyphs.add (glyphs[i]);
  205599. }
  205600. }
  205601. }
  205602. #endif
  205603. }
  205604. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205605. {
  205606. #if JUCE_IPHONE
  205607. return false;
  205608. #else
  205609. if (nsFont == 0)
  205610. return false;
  205611. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205612. jassert (path.isEmpty());
  205613. const ScopedAutoReleasePool pool;
  205614. NSBezierPath* bez = [NSBezierPath bezierPath];
  205615. [bez moveToPoint: NSMakePoint (0, 0)];
  205616. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205617. inFont: nsFont];
  205618. for (int i = 0; i < [bez elementCount]; ++i)
  205619. {
  205620. NSPoint p[3];
  205621. switch ([bez elementAtIndex: i associatedPoints: p])
  205622. {
  205623. case NSMoveToBezierPathElement:
  205624. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205625. break;
  205626. case NSLineToBezierPathElement:
  205627. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205628. break;
  205629. case NSCurveToBezierPathElement:
  205630. 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);
  205631. break;
  205632. case NSClosePathBezierPathElement:
  205633. path.closeSubPath();
  205634. break;
  205635. default:
  205636. jassertfalse
  205637. break;
  205638. }
  205639. }
  205640. path.applyTransform (pathTransform);
  205641. return true;
  205642. #endif
  205643. }
  205644. juce_UseDebuggingNewOperator
  205645. CGFontRef fontRef;
  205646. float fontHeightToCGSizeFactor;
  205647. CGAffineTransform renderingTransform;
  205648. private:
  205649. float ascent, unitsToHeightScaleFactor;
  205650. #if JUCE_IPHONE
  205651. #else
  205652. NSFont* nsFont;
  205653. AffineTransform pathTransform;
  205654. #endif
  205655. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205656. {
  205657. #if SUPPORT_10_4_FONTS
  205658. #if ! SUPPORT_ONLY_10_4_FONTS
  205659. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205660. #endif
  205661. {
  205662. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205663. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205664. for (int i = 0; i < length; ++i)
  205665. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205666. return;
  205667. }
  205668. #endif
  205669. #if ! SUPPORT_ONLY_10_4_FONTS
  205670. if (charToGlyphMapper == 0)
  205671. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205672. glyphs.malloc (length);
  205673. for (int i = 0; i < length; ++i)
  205674. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205675. #endif
  205676. }
  205677. #if ! SUPPORT_ONLY_10_4_FONTS
  205678. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205679. class CharToGlyphMapper
  205680. {
  205681. public:
  205682. CharToGlyphMapper (CGFontRef fontRef)
  205683. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205684. idRangeOffset (0), glyphIndexes (0)
  205685. {
  205686. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205687. if (cmapTable != 0)
  205688. {
  205689. const int numSubtables = getValue16 (cmapTable, 2);
  205690. for (int i = 0; i < numSubtables; ++i)
  205691. {
  205692. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205693. {
  205694. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205695. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205696. {
  205697. const int length = getValue16 (cmapTable, offset + 2);
  205698. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205699. segCount = segCountX2 / 2;
  205700. const int endCodeOffset = offset + 14;
  205701. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205702. const int idDeltaOffset = startCodeOffset + segCountX2;
  205703. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205704. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205705. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205706. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205707. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205708. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205709. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205710. }
  205711. break;
  205712. }
  205713. }
  205714. CFRelease (cmapTable);
  205715. }
  205716. }
  205717. ~CharToGlyphMapper()
  205718. {
  205719. if (endCode != 0)
  205720. {
  205721. CFRelease (endCode);
  205722. CFRelease (startCode);
  205723. CFRelease (idDelta);
  205724. CFRelease (idRangeOffset);
  205725. CFRelease (glyphIndexes);
  205726. }
  205727. }
  205728. int getGlyphForCharacter (const juce_wchar c) const
  205729. {
  205730. for (int i = 0; i < segCount; ++i)
  205731. {
  205732. if (getValue16 (endCode, i * 2) >= c)
  205733. {
  205734. const int start = getValue16 (startCode, i * 2);
  205735. if (start > c)
  205736. break;
  205737. const int delta = getValue16 (idDelta, i * 2);
  205738. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205739. if (rangeOffset == 0)
  205740. return delta + c;
  205741. else
  205742. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205743. }
  205744. }
  205745. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205746. return jmax (-1, c - 29);
  205747. }
  205748. private:
  205749. int segCount;
  205750. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205751. static uint16 getValue16 (CFDataRef data, const int index)
  205752. {
  205753. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205754. }
  205755. static uint32 getValue32 (CFDataRef data, const int index)
  205756. {
  205757. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205758. }
  205759. };
  205760. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205761. #endif
  205762. MacTypeface (const MacTypeface&);
  205763. MacTypeface& operator= (const MacTypeface&);
  205764. };
  205765. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205766. {
  205767. return new MacTypeface (font);
  205768. }
  205769. const StringArray Font::findAllTypefaceNames()
  205770. {
  205771. StringArray names;
  205772. const ScopedAutoReleasePool pool;
  205773. #if JUCE_IPHONE
  205774. NSArray* fonts = [UIFont familyNames];
  205775. #else
  205776. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205777. #endif
  205778. for (unsigned int i = 0; i < [fonts count]; ++i)
  205779. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205780. names.sort (true);
  205781. return names;
  205782. }
  205783. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205784. {
  205785. #if JUCE_IPHONE
  205786. defaultSans = "Helvetica";
  205787. defaultSerif = "Times New Roman";
  205788. defaultFixed = "Courier New";
  205789. #else
  205790. defaultSans = "Lucida Grande";
  205791. defaultSerif = "Times New Roman";
  205792. defaultFixed = "Monaco";
  205793. #endif
  205794. }
  205795. #endif
  205796. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205797. // (must go before juce_mac_CoreGraphicsContext.mm)
  205798. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205799. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205800. // compiled on its own).
  205801. #if JUCE_INCLUDED_FILE
  205802. class CoreGraphicsImage : public Image
  205803. {
  205804. public:
  205805. CoreGraphicsImage (const PixelFormat format_,
  205806. const int imageWidth_,
  205807. const int imageHeight_,
  205808. const bool clearImage)
  205809. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205810. {
  205811. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205812. : CGColorSpaceCreateDeviceRGB();
  205813. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205814. colourSpace, getCGImageFlags (*this));
  205815. CGColorSpaceRelease (colourSpace);
  205816. }
  205817. ~CoreGraphicsImage()
  205818. {
  205819. CGContextRelease (context);
  205820. }
  205821. LowLevelGraphicsContext* createLowLevelContext();
  205822. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205823. {
  205824. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205825. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205826. {
  205827. return CGBitmapContextCreateImage (nativeImage->context);
  205828. }
  205829. else
  205830. {
  205831. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205832. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205833. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205834. 8, srcData.pixelStride * 8, srcData.lineStride,
  205835. colourSpace, getCGImageFlags (juceImage), provider,
  205836. 0, true, kCGRenderingIntentDefault);
  205837. CGDataProviderRelease (provider);
  205838. return imageRef;
  205839. }
  205840. }
  205841. #if JUCE_MAC
  205842. static NSImage* createNSImage (const Image& image)
  205843. {
  205844. const ScopedAutoReleasePool pool;
  205845. NSImage* im = [[NSImage alloc] init];
  205846. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205847. [im lockFocus];
  205848. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205849. CGImageRef imageRef = createImage (image, false, colourSpace);
  205850. CGColorSpaceRelease (colourSpace);
  205851. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205852. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205853. CGImageRelease (imageRef);
  205854. [im unlockFocus];
  205855. return im;
  205856. }
  205857. #endif
  205858. CGContextRef context;
  205859. private:
  205860. static CGBitmapInfo getCGImageFlags (const Image& image)
  205861. {
  205862. #if JUCE_BIG_ENDIAN
  205863. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205864. #else
  205865. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205866. #endif
  205867. }
  205868. };
  205869. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205870. {
  205871. #if USE_COREGRAPHICS_RENDERING
  205872. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205873. #else
  205874. return new Image (format, imageWidth, imageHeight, clearImage);
  205875. #endif
  205876. }
  205877. class CoreGraphicsContext : public LowLevelGraphicsContext
  205878. {
  205879. public:
  205880. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205881. : context (context_),
  205882. flipHeight (flipHeight_),
  205883. state (new SavedState()),
  205884. numGradientLookupEntries (0)
  205885. {
  205886. CGContextRetain (context);
  205887. CGContextSaveGState(context);
  205888. CGContextSetShouldSmoothFonts (context, true);
  205889. CGContextSetShouldAntialias (context, true);
  205890. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205891. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205892. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205893. gradientCallbacks.version = 0;
  205894. gradientCallbacks.evaluate = gradientCallback;
  205895. gradientCallbacks.releaseInfo = 0;
  205896. setFont (Font());
  205897. }
  205898. ~CoreGraphicsContext()
  205899. {
  205900. CGContextRestoreGState (context);
  205901. CGContextRelease (context);
  205902. CGColorSpaceRelease (rgbColourSpace);
  205903. CGColorSpaceRelease (greyColourSpace);
  205904. }
  205905. bool isVectorDevice() const { return false; }
  205906. void setOrigin (int x, int y)
  205907. {
  205908. CGContextTranslateCTM (context, x, -y);
  205909. }
  205910. bool clipToRectangle (const Rectangle<int>& r)
  205911. {
  205912. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205913. return ! isClipEmpty();
  205914. }
  205915. bool clipToRectangleList (const RectangleList& clipRegion)
  205916. {
  205917. if (clipRegion.isEmpty())
  205918. {
  205919. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205920. return false;
  205921. }
  205922. else
  205923. {
  205924. const int numRects = clipRegion.getNumRectangles();
  205925. HeapBlock <CGRect> rects (numRects);
  205926. for (int i = 0; i < numRects; ++i)
  205927. {
  205928. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205929. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205930. }
  205931. CGContextClipToRects (context, rects, numRects);
  205932. return ! isClipEmpty();
  205933. }
  205934. }
  205935. void excludeClipRectangle (const Rectangle<int>& r)
  205936. {
  205937. RectangleList remaining (getClipBounds());
  205938. remaining.subtract (r);
  205939. clipToRectangleList (remaining);
  205940. }
  205941. void clipToPath (const Path& path, const AffineTransform& transform)
  205942. {
  205943. createPath (path, transform);
  205944. CGContextClip (context);
  205945. }
  205946. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205947. {
  205948. if (! transform.isSingularity())
  205949. {
  205950. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205951. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205952. flip();
  205953. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205954. applyTransform (t);
  205955. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205956. CGContextClipToMask (context, r, image);
  205957. applyTransform (t.inverted());
  205958. flip();
  205959. CGImageRelease (image);
  205960. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205961. }
  205962. }
  205963. bool clipRegionIntersects (const Rectangle<int>& r)
  205964. {
  205965. return getClipBounds().intersects (r);
  205966. }
  205967. const Rectangle<int> getClipBounds() const
  205968. {
  205969. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205970. return Rectangle<int> (roundToInt (bounds.origin.x),
  205971. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205972. roundToInt (bounds.size.width),
  205973. roundToInt (bounds.size.height));
  205974. }
  205975. bool isClipEmpty() const
  205976. {
  205977. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205978. }
  205979. void saveState()
  205980. {
  205981. CGContextSaveGState (context);
  205982. stateStack.add (new SavedState (*state));
  205983. }
  205984. void restoreState()
  205985. {
  205986. CGContextRestoreGState (context);
  205987. SavedState* const top = stateStack.getLast();
  205988. if (top != 0)
  205989. {
  205990. state = top;
  205991. stateStack.removeLast (1, false);
  205992. }
  205993. else
  205994. {
  205995. jassertfalse // trying to pop with an empty stack!
  205996. }
  205997. }
  205998. void setFill (const FillType& fillType)
  205999. {
  206000. state->fillType = fillType;
  206001. if (fillType.isColour())
  206002. {
  206003. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206004. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206005. CGContextSetAlpha (context, 1.0f);
  206006. }
  206007. }
  206008. void setOpacity (float newOpacity)
  206009. {
  206010. state->fillType.setOpacity (newOpacity);
  206011. setFill (state->fillType);
  206012. }
  206013. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206014. {
  206015. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206016. ? kCGInterpolationLow
  206017. : kCGInterpolationHigh);
  206018. }
  206019. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206020. {
  206021. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206022. if (replaceExistingContents)
  206023. {
  206024. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206025. CGContextClearRect (context, cgRect);
  206026. #else
  206027. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206028. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206029. CGContextClearRect (context, cgRect);
  206030. else
  206031. #endif
  206032. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206033. #endif
  206034. fillRect (r, false);
  206035. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206036. }
  206037. else
  206038. {
  206039. if (state->fillType.isColour())
  206040. {
  206041. CGContextFillRect (context, cgRect);
  206042. }
  206043. else if (state->fillType.isGradient())
  206044. {
  206045. CGContextSaveGState (context);
  206046. CGContextClipToRect (context, cgRect);
  206047. drawGradient();
  206048. CGContextRestoreGState (context);
  206049. }
  206050. else
  206051. {
  206052. CGContextSaveGState (context);
  206053. CGContextClipToRect (context, cgRect);
  206054. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206055. CGContextRestoreGState (context);
  206056. }
  206057. }
  206058. }
  206059. void fillPath (const Path& path, const AffineTransform& transform)
  206060. {
  206061. CGContextSaveGState (context);
  206062. if (state->fillType.isColour())
  206063. {
  206064. flip();
  206065. applyTransform (transform);
  206066. createPath (path);
  206067. if (path.isUsingNonZeroWinding())
  206068. CGContextFillPath (context);
  206069. else
  206070. CGContextEOFillPath (context);
  206071. }
  206072. else
  206073. {
  206074. createPath (path, transform);
  206075. if (path.isUsingNonZeroWinding())
  206076. CGContextClip (context);
  206077. else
  206078. CGContextEOClip (context);
  206079. if (state->fillType.isGradient())
  206080. drawGradient();
  206081. else
  206082. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206083. }
  206084. CGContextRestoreGState (context);
  206085. }
  206086. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206087. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206088. {
  206089. jassert (sourceImage.getBounds().contains (srcClip));
  206090. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206091. CGImageRef image = fullImage;
  206092. if (srcClip != sourceImage.getBounds())
  206093. {
  206094. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206095. srcClip.getWidth(), srcClip.getHeight()));
  206096. CGImageRelease (fullImage);
  206097. }
  206098. CGContextSaveGState (context);
  206099. CGContextSetAlpha (context, state->fillType.getOpacity());
  206100. flip();
  206101. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206102. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206103. if (fillEntireClipAsTiles)
  206104. {
  206105. #if JUCE_IPHONE
  206106. CGContextDrawTiledImage (context, imageRect, image);
  206107. #else
  206108. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206109. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206110. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206111. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206112. CGContextDrawTiledImage (context, imageRect, image);
  206113. else
  206114. #endif
  206115. {
  206116. // Fallback to manually doing a tiled fill on 10.4
  206117. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206118. const int iw = srcClip.getWidth();
  206119. const int ih = srcClip.getHeight();
  206120. int x = 0, y = 0;
  206121. while (x > clip.origin.x) x -= iw;
  206122. while (y > clip.origin.y) y -= ih;
  206123. const int right = (int) (clip.origin.x + clip.size.width);
  206124. const int bottom = (int) (clip.origin.y + clip.size.height);
  206125. while (y < bottom)
  206126. {
  206127. for (int x2 = x; x2 < right; x2 += iw)
  206128. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206129. y += ih;
  206130. }
  206131. }
  206132. #endif
  206133. }
  206134. else
  206135. {
  206136. CGContextDrawImage (context, imageRect, image);
  206137. }
  206138. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206139. CGContextRestoreGState (context);
  206140. }
  206141. void drawLine (double x1, double y1, double x2, double y2)
  206142. {
  206143. CGContextSetLineCap (context, kCGLineCapSquare);
  206144. CGContextSetLineWidth (context, 1.0f);
  206145. CGContextSetRGBStrokeColor (context,
  206146. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206147. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206148. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206149. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206150. CGContextStrokeLineSegments (context, line, 1);
  206151. }
  206152. void drawVerticalLine (const int x, double top, double bottom)
  206153. {
  206154. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206155. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206156. #else
  206157. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206158. // the x co-ord slightly to trick it..
  206159. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206160. #endif
  206161. }
  206162. void drawHorizontalLine (const int y, double left, double right)
  206163. {
  206164. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206165. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206166. #else
  206167. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206168. // the x co-ord slightly to trick it..
  206169. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206170. #endif
  206171. }
  206172. void setFont (const Font& newFont)
  206173. {
  206174. if (state->font != newFont)
  206175. {
  206176. state->fontRef = 0;
  206177. state->font = newFont;
  206178. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  206179. if (mf != 0)
  206180. {
  206181. state->fontRef = mf->fontRef;
  206182. CGContextSetFont (context, state->fontRef);
  206183. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206184. state->fontTransform = mf->renderingTransform;
  206185. state->fontTransform.a *= state->font.getHorizontalScale();
  206186. CGContextSetTextMatrix (context, state->fontTransform);
  206187. }
  206188. }
  206189. }
  206190. const Font getFont()
  206191. {
  206192. return state->font;
  206193. }
  206194. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206195. {
  206196. if (state->fontRef != 0 && state->fillType.isColour())
  206197. {
  206198. if (transform.isOnlyTranslation())
  206199. {
  206200. CGGlyph g = glyphNumber;
  206201. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206202. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206203. }
  206204. else
  206205. {
  206206. CGContextSaveGState (context);
  206207. flip();
  206208. applyTransform (transform);
  206209. CGAffineTransform t = state->fontTransform;
  206210. t.d = -t.d;
  206211. CGContextSetTextMatrix (context, t);
  206212. CGGlyph g = glyphNumber;
  206213. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206214. CGContextSetTextMatrix (context, state->fontTransform);
  206215. CGContextRestoreGState (context);
  206216. }
  206217. }
  206218. else
  206219. {
  206220. Path p;
  206221. Font& f = state->font;
  206222. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206223. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206224. .followedBy (transform));
  206225. }
  206226. }
  206227. private:
  206228. CGContextRef context;
  206229. const CGFloat flipHeight;
  206230. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206231. CGFunctionCallbacks gradientCallbacks;
  206232. struct SavedState
  206233. {
  206234. SavedState()
  206235. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206236. {
  206237. }
  206238. SavedState (const SavedState& other)
  206239. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206240. fontTransform (other.fontTransform)
  206241. {
  206242. }
  206243. ~SavedState()
  206244. {
  206245. }
  206246. FillType fillType;
  206247. Font font;
  206248. CGFontRef fontRef;
  206249. CGAffineTransform fontTransform;
  206250. };
  206251. ScopedPointer <SavedState> state;
  206252. OwnedArray <SavedState> stateStack;
  206253. HeapBlock <PixelARGB> gradientLookupTable;
  206254. int numGradientLookupEntries;
  206255. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206256. {
  206257. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  206258. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206259. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206260. colour.unpremultiply();
  206261. outData[0] = colour.getRed() / 255.0f;
  206262. outData[1] = colour.getGreen() / 255.0f;
  206263. outData[2] = colour.getBlue() / 255.0f;
  206264. outData[3] = colour.getAlpha() / 255.0f;
  206265. }
  206266. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206267. {
  206268. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206269. --numGradientLookupEntries;
  206270. CGShadingRef result = 0;
  206271. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  206272. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206273. if (gradient.isRadial)
  206274. {
  206275. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206276. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206277. function, true, true);
  206278. }
  206279. else
  206280. {
  206281. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206282. CGPointMake (gradient.x2, gradient.y2),
  206283. function, true, true);
  206284. }
  206285. CGFunctionRelease (function);
  206286. return result;
  206287. }
  206288. void drawGradient()
  206289. {
  206290. flip();
  206291. applyTransform (state->fillType.transform);
  206292. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206293. // you draw a gradient with high quality interp enabled).
  206294. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206295. CGContextSetAlpha (context, state->fillType.getOpacity());
  206296. CGContextDrawShading (context, shading);
  206297. CGShadingRelease (shading);
  206298. }
  206299. void createPath (const Path& path) const
  206300. {
  206301. CGContextBeginPath (context);
  206302. Path::Iterator i (path);
  206303. while (i.next())
  206304. {
  206305. switch (i.elementType)
  206306. {
  206307. case Path::Iterator::startNewSubPath:
  206308. CGContextMoveToPoint (context, i.x1, i.y1);
  206309. break;
  206310. case Path::Iterator::lineTo:
  206311. CGContextAddLineToPoint (context, i.x1, i.y1);
  206312. break;
  206313. case Path::Iterator::quadraticTo:
  206314. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206315. break;
  206316. case Path::Iterator::cubicTo:
  206317. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206318. break;
  206319. case Path::Iterator::closePath:
  206320. CGContextClosePath (context); break;
  206321. default:
  206322. jassertfalse
  206323. break;
  206324. }
  206325. }
  206326. }
  206327. void createPath (const Path& path, const AffineTransform& transform) const
  206328. {
  206329. CGContextBeginPath (context);
  206330. Path::Iterator i (path);
  206331. while (i.next())
  206332. {
  206333. switch (i.elementType)
  206334. {
  206335. case Path::Iterator::startNewSubPath:
  206336. transform.transformPoint (i.x1, i.y1);
  206337. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206338. break;
  206339. case Path::Iterator::lineTo:
  206340. transform.transformPoint (i.x1, i.y1);
  206341. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206342. break;
  206343. case Path::Iterator::quadraticTo:
  206344. transform.transformPoint (i.x1, i.y1);
  206345. transform.transformPoint (i.x2, i.y2);
  206346. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206347. break;
  206348. case Path::Iterator::cubicTo:
  206349. transform.transformPoint (i.x1, i.y1);
  206350. transform.transformPoint (i.x2, i.y2);
  206351. transform.transformPoint (i.x3, i.y3);
  206352. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206353. break;
  206354. case Path::Iterator::closePath:
  206355. CGContextClosePath (context); break;
  206356. default:
  206357. jassertfalse
  206358. break;
  206359. }
  206360. }
  206361. }
  206362. static Image* createAlphaChannelImage (const Image& im)
  206363. {
  206364. if (im.getFormat() == Image::SingleChannel)
  206365. return const_cast <Image*> (&im);
  206366. return im.createCopyOfAlphaChannel();
  206367. }
  206368. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206369. {
  206370. if (im.getFormat() != Image::SingleChannel)
  206371. delete alphaIm;
  206372. }
  206373. void flip() const
  206374. {
  206375. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206376. }
  206377. void applyTransform (const AffineTransform& transform) const
  206378. {
  206379. CGAffineTransform t;
  206380. t.a = transform.mat00;
  206381. t.b = transform.mat10;
  206382. t.c = transform.mat01;
  206383. t.d = transform.mat11;
  206384. t.tx = transform.mat02;
  206385. t.ty = transform.mat12;
  206386. CGContextConcatCTM (context, t);
  206387. }
  206388. CoreGraphicsContext (const CoreGraphicsContext&);
  206389. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206390. };
  206391. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206392. {
  206393. return new CoreGraphicsContext (context, imageHeight);
  206394. }
  206395. #endif
  206396. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206397. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206398. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206399. // compiled on its own).
  206400. #if JUCE_INCLUDED_FILE
  206401. class NSViewComponentPeer;
  206402. END_JUCE_NAMESPACE
  206403. #define JuceNSView MakeObjCClassName(JuceNSView)
  206404. @interface JuceNSView : NSView<NSTextInput>
  206405. {
  206406. @public
  206407. NSViewComponentPeer* owner;
  206408. NSNotificationCenter* notificationCenter;
  206409. String* stringBeingComposed;
  206410. bool textWasInserted;
  206411. }
  206412. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206413. - (void) dealloc;
  206414. - (BOOL) isOpaque;
  206415. - (void) drawRect: (NSRect) r;
  206416. - (void) mouseDown: (NSEvent*) ev;
  206417. - (void) asyncMouseDown: (NSEvent*) ev;
  206418. - (void) mouseUp: (NSEvent*) ev;
  206419. - (void) asyncMouseUp: (NSEvent*) ev;
  206420. - (void) mouseDragged: (NSEvent*) ev;
  206421. - (void) mouseMoved: (NSEvent*) ev;
  206422. - (void) mouseEntered: (NSEvent*) ev;
  206423. - (void) mouseExited: (NSEvent*) ev;
  206424. - (void) rightMouseDown: (NSEvent*) ev;
  206425. - (void) rightMouseDragged: (NSEvent*) ev;
  206426. - (void) rightMouseUp: (NSEvent*) ev;
  206427. - (void) otherMouseDown: (NSEvent*) ev;
  206428. - (void) otherMouseDragged: (NSEvent*) ev;
  206429. - (void) otherMouseUp: (NSEvent*) ev;
  206430. - (void) scrollWheel: (NSEvent*) ev;
  206431. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206432. - (void) frameChanged: (NSNotification*) n;
  206433. - (void) viewDidMoveToWindow;
  206434. - (void) keyDown: (NSEvent*) ev;
  206435. - (void) keyUp: (NSEvent*) ev;
  206436. // NSTextInput Methods
  206437. - (void) insertText: (id) aString;
  206438. - (void) doCommandBySelector: (SEL) aSelector;
  206439. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206440. - (void) unmarkText;
  206441. - (BOOL) hasMarkedText;
  206442. - (long) conversationIdentifier;
  206443. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206444. - (NSRange) markedRange;
  206445. - (NSRange) selectedRange;
  206446. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206447. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206448. - (NSArray*) validAttributesForMarkedText;
  206449. - (void) flagsChanged: (NSEvent*) ev;
  206450. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206451. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206452. #endif
  206453. - (BOOL) becomeFirstResponder;
  206454. - (BOOL) resignFirstResponder;
  206455. - (BOOL) acceptsFirstResponder;
  206456. - (void) asyncRepaint: (id) rect;
  206457. - (NSArray*) getSupportedDragTypes;
  206458. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206459. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206460. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206461. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206462. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206463. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206464. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206465. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206466. @end
  206467. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206468. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206469. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206470. #else
  206471. @interface JuceNSWindow : NSWindow
  206472. #endif
  206473. {
  206474. @private
  206475. NSViewComponentPeer* owner;
  206476. bool isZooming;
  206477. }
  206478. - (void) setOwner: (NSViewComponentPeer*) owner;
  206479. - (BOOL) canBecomeKeyWindow;
  206480. - (void) becomeKeyWindow;
  206481. - (BOOL) windowShouldClose: (id) window;
  206482. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206483. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206484. - (void) zoom: (id) sender;
  206485. @end
  206486. BEGIN_JUCE_NAMESPACE
  206487. class NSViewComponentPeer : public ComponentPeer
  206488. {
  206489. public:
  206490. NSViewComponentPeer (Component* const component,
  206491. const int windowStyleFlags,
  206492. NSView* viewToAttachTo);
  206493. ~NSViewComponentPeer();
  206494. void* getNativeHandle() const;
  206495. void setVisible (bool shouldBeVisible);
  206496. void setTitle (const String& title);
  206497. void setPosition (int x, int y);
  206498. void setSize (int w, int h);
  206499. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206500. const Rectangle<int> getBounds (const bool global) const;
  206501. const Rectangle<int> getBounds() const;
  206502. const Point<int> getScreenPosition() const;
  206503. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206504. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206505. void setMinimised (bool shouldBeMinimised);
  206506. bool isMinimised() const;
  206507. void setFullScreen (bool shouldBeFullScreen);
  206508. bool isFullScreen() const;
  206509. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206510. const BorderSize getFrameSize() const;
  206511. bool setAlwaysOnTop (bool alwaysOnTop);
  206512. void toFront (bool makeActiveWindow);
  206513. void toBehind (ComponentPeer* other);
  206514. void setIcon (const Image& newIcon);
  206515. const StringArray getAvailableRenderingEngines() throw();
  206516. int getCurrentRenderingEngine() throw();
  206517. void setCurrentRenderingEngine (int index) throw();
  206518. virtual void redirectMouseDown (NSEvent* ev);
  206519. virtual void redirectMouseUp (NSEvent* ev);
  206520. virtual void redirectMouseDrag (NSEvent* ev);
  206521. virtual void redirectMouseMove (NSEvent* ev);
  206522. virtual void redirectMouseEnter (NSEvent* ev);
  206523. virtual void redirectMouseExit (NSEvent* ev);
  206524. virtual void redirectMouseWheel (NSEvent* ev);
  206525. void sendMouseEvent (NSEvent* ev);
  206526. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206527. virtual bool redirectKeyDown (NSEvent* ev);
  206528. virtual bool redirectKeyUp (NSEvent* ev);
  206529. virtual void redirectModKeyChange (NSEvent* ev);
  206530. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206531. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206532. #endif
  206533. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206534. virtual bool isOpaque();
  206535. virtual void drawRect (NSRect r);
  206536. virtual bool canBecomeKeyWindow();
  206537. virtual bool windowShouldClose();
  206538. virtual void redirectMovedOrResized();
  206539. virtual void viewMovedToWindow();
  206540. virtual NSRect constrainRect (NSRect r);
  206541. static void showArrowCursorIfNeeded();
  206542. static void updateModifiers (NSEvent* e);
  206543. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206544. static int getKeyCodeFromEvent (NSEvent* ev)
  206545. {
  206546. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206547. int keyCode = unmodified[0];
  206548. if (keyCode == 0x19) // (backwards-tab)
  206549. keyCode = '\t';
  206550. else if (keyCode == 0x03) // (enter)
  206551. keyCode = '\r';
  206552. return keyCode;
  206553. }
  206554. static int64 getMouseTime (NSEvent* e)
  206555. {
  206556. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206557. + (int64) ([e timestamp] * 1000.0);
  206558. }
  206559. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206560. {
  206561. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206562. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206563. }
  206564. static int getModifierForButtonNumber (const NSInteger num)
  206565. {
  206566. return num == 0 ? ModifierKeys::leftButtonModifier
  206567. : (num == 1 ? ModifierKeys::rightButtonModifier
  206568. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206569. }
  206570. virtual void viewFocusGain();
  206571. virtual void viewFocusLoss();
  206572. bool isFocused() const;
  206573. void grabFocus();
  206574. void textInputRequired (const Point<int>& position);
  206575. void repaint (int x, int y, int w, int h);
  206576. void performAnyPendingRepaintsNow();
  206577. juce_UseDebuggingNewOperator
  206578. NSWindow* window;
  206579. JuceNSView* view;
  206580. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206581. static ModifierKeys currentModifiers;
  206582. static ComponentPeer* currentlyFocusedPeer;
  206583. static Array<int> keysCurrentlyDown;
  206584. };
  206585. END_JUCE_NAMESPACE
  206586. @implementation JuceNSView
  206587. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206588. withFrame: (NSRect) frame
  206589. {
  206590. [super initWithFrame: frame];
  206591. owner = owner_;
  206592. stringBeingComposed = 0;
  206593. textWasInserted = false;
  206594. notificationCenter = [NSNotificationCenter defaultCenter];
  206595. [notificationCenter addObserver: self
  206596. selector: @selector (frameChanged:)
  206597. name: NSViewFrameDidChangeNotification
  206598. object: self];
  206599. if (! owner_->isSharedWindow)
  206600. {
  206601. [notificationCenter addObserver: self
  206602. selector: @selector (frameChanged:)
  206603. name: NSWindowDidMoveNotification
  206604. object: owner_->window];
  206605. }
  206606. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206607. return self;
  206608. }
  206609. - (void) dealloc
  206610. {
  206611. [notificationCenter removeObserver: self];
  206612. delete stringBeingComposed;
  206613. [super dealloc];
  206614. }
  206615. - (void) drawRect: (NSRect) r
  206616. {
  206617. if (owner != 0)
  206618. owner->drawRect (r);
  206619. }
  206620. - (BOOL) isOpaque
  206621. {
  206622. return owner == 0 || owner->isOpaque();
  206623. }
  206624. - (void) mouseDown: (NSEvent*) ev
  206625. {
  206626. // In some host situations, the host will stop modal loops from working
  206627. // correctly if they're called from a mouse event, so we'll trigger
  206628. // the event asynchronously..
  206629. if (JUCEApplication::getInstance() == 0)
  206630. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206631. withObject: ev
  206632. waitUntilDone: NO];
  206633. else
  206634. [self asyncMouseDown: ev];
  206635. }
  206636. - (void) asyncMouseDown: (NSEvent*) ev
  206637. {
  206638. if (owner != 0)
  206639. owner->redirectMouseDown (ev);
  206640. }
  206641. - (void) mouseUp: (NSEvent*) ev
  206642. {
  206643. // In some host situations, the host will stop modal loops from working
  206644. // correctly if they're called from a mouse event, so we'll trigger
  206645. // the event asynchronously..
  206646. if (JUCEApplication::getInstance() == 0)
  206647. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206648. withObject: ev
  206649. waitUntilDone: NO];
  206650. else
  206651. [self asyncMouseUp: ev];
  206652. }
  206653. - (void) asyncMouseUp: (NSEvent*) ev
  206654. {
  206655. if (owner != 0)
  206656. owner->redirectMouseUp (ev);
  206657. }
  206658. - (void) mouseDragged: (NSEvent*) ev
  206659. {
  206660. if (owner != 0)
  206661. owner->redirectMouseDrag (ev);
  206662. }
  206663. - (void) mouseMoved: (NSEvent*) ev
  206664. {
  206665. if (owner != 0)
  206666. owner->redirectMouseMove (ev);
  206667. }
  206668. - (void) mouseEntered: (NSEvent*) ev
  206669. {
  206670. if (owner != 0)
  206671. owner->redirectMouseEnter (ev);
  206672. }
  206673. - (void) mouseExited: (NSEvent*) ev
  206674. {
  206675. if (owner != 0)
  206676. owner->redirectMouseExit (ev);
  206677. }
  206678. - (void) rightMouseDown: (NSEvent*) ev
  206679. {
  206680. [self mouseDown: ev];
  206681. }
  206682. - (void) rightMouseDragged: (NSEvent*) ev
  206683. {
  206684. [self mouseDragged: ev];
  206685. }
  206686. - (void) rightMouseUp: (NSEvent*) ev
  206687. {
  206688. [self mouseUp: ev];
  206689. }
  206690. - (void) otherMouseDown: (NSEvent*) ev
  206691. {
  206692. [self mouseDown: ev];
  206693. }
  206694. - (void) otherMouseDragged: (NSEvent*) ev
  206695. {
  206696. [self mouseDragged: ev];
  206697. }
  206698. - (void) otherMouseUp: (NSEvent*) ev
  206699. {
  206700. [self mouseUp: ev];
  206701. }
  206702. - (void) scrollWheel: (NSEvent*) ev
  206703. {
  206704. if (owner != 0)
  206705. owner->redirectMouseWheel (ev);
  206706. }
  206707. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206708. {
  206709. return YES;
  206710. }
  206711. - (void) frameChanged: (NSNotification*) n
  206712. {
  206713. if (owner != 0)
  206714. owner->redirectMovedOrResized();
  206715. }
  206716. - (void) viewDidMoveToWindow
  206717. {
  206718. if (owner != 0)
  206719. owner->viewMovedToWindow();
  206720. }
  206721. - (void) asyncRepaint: (id) rect
  206722. {
  206723. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206724. [self setNeedsDisplayInRect: *r];
  206725. }
  206726. - (void) keyDown: (NSEvent*) ev
  206727. {
  206728. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206729. textWasInserted = false;
  206730. if (target != 0)
  206731. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206732. else
  206733. deleteAndZero (stringBeingComposed);
  206734. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206735. [super keyDown: ev];
  206736. }
  206737. - (void) keyUp: (NSEvent*) ev
  206738. {
  206739. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206740. [super keyUp: ev];
  206741. }
  206742. - (void) insertText: (id) aString
  206743. {
  206744. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206745. if ([aString length] > 0)
  206746. {
  206747. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206748. if (target != 0)
  206749. {
  206750. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206751. textWasInserted = true;
  206752. }
  206753. }
  206754. deleteAndZero (stringBeingComposed);
  206755. }
  206756. - (void) doCommandBySelector: (SEL) aSelector
  206757. {
  206758. }
  206759. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206760. {
  206761. if (stringBeingComposed == 0)
  206762. stringBeingComposed = new String();
  206763. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206764. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206765. if (target != 0)
  206766. {
  206767. const Range<int> currentHighlight (target->getHighlightedRegion());
  206768. target->insertTextAtCaret (*stringBeingComposed);
  206769. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206770. textWasInserted = true;
  206771. }
  206772. }
  206773. - (void) unmarkText
  206774. {
  206775. if (stringBeingComposed != 0)
  206776. {
  206777. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206778. if (target != 0)
  206779. {
  206780. target->insertTextAtCaret (*stringBeingComposed);
  206781. textWasInserted = true;
  206782. }
  206783. }
  206784. deleteAndZero (stringBeingComposed);
  206785. }
  206786. - (BOOL) hasMarkedText
  206787. {
  206788. return stringBeingComposed != 0;
  206789. }
  206790. - (long) conversationIdentifier
  206791. {
  206792. return (long) (pointer_sized_int) self;
  206793. }
  206794. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206795. {
  206796. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206797. if (target != 0)
  206798. {
  206799. const Range<int> r ((int) theRange.location,
  206800. (int) (theRange.location + theRange.length));
  206801. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206802. }
  206803. return nil;
  206804. }
  206805. - (NSRange) markedRange
  206806. {
  206807. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206808. : NSMakeRange (NSNotFound, 0);
  206809. }
  206810. - (NSRange) selectedRange
  206811. {
  206812. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206813. if (target != 0)
  206814. {
  206815. const Range<int> highlight (target->getHighlightedRegion());
  206816. if (! highlight.isEmpty())
  206817. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206818. }
  206819. return NSMakeRange (NSNotFound, 0);
  206820. }
  206821. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206822. {
  206823. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206824. if (comp == 0)
  206825. return NSMakeRect (0, 0, 0, 0);
  206826. const Rectangle<int> bounds (comp->getScreenBounds());
  206827. return NSMakeRect (bounds.getX(),
  206828. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206829. bounds.getWidth(),
  206830. bounds.getHeight());
  206831. }
  206832. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206833. {
  206834. return NSNotFound;
  206835. }
  206836. - (NSArray*) validAttributesForMarkedText
  206837. {
  206838. return [NSArray array];
  206839. }
  206840. - (void) flagsChanged: (NSEvent*) ev
  206841. {
  206842. if (owner != 0)
  206843. owner->redirectModKeyChange (ev);
  206844. }
  206845. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206846. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206847. {
  206848. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206849. return true;
  206850. return [super performKeyEquivalent: ev];
  206851. }
  206852. #endif
  206853. - (BOOL) becomeFirstResponder
  206854. {
  206855. if (owner != 0)
  206856. owner->viewFocusGain();
  206857. return true;
  206858. }
  206859. - (BOOL) resignFirstResponder
  206860. {
  206861. if (owner != 0)
  206862. owner->viewFocusLoss();
  206863. return true;
  206864. }
  206865. - (BOOL) acceptsFirstResponder
  206866. {
  206867. return owner != 0 && owner->canBecomeKeyWindow();
  206868. }
  206869. - (NSArray*) getSupportedDragTypes
  206870. {
  206871. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206872. }
  206873. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206874. {
  206875. return owner != 0 && owner->sendDragCallback (type, sender);
  206876. }
  206877. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206878. {
  206879. if ([self sendDragCallback: 0 sender: sender])
  206880. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206881. else
  206882. return NSDragOperationNone;
  206883. }
  206884. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206885. {
  206886. if ([self sendDragCallback: 0 sender: sender])
  206887. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206888. else
  206889. return NSDragOperationNone;
  206890. }
  206891. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206892. {
  206893. [self sendDragCallback: 1 sender: sender];
  206894. }
  206895. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206896. {
  206897. [self sendDragCallback: 1 sender: sender];
  206898. }
  206899. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206900. {
  206901. return YES;
  206902. }
  206903. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206904. {
  206905. return [self sendDragCallback: 2 sender: sender];
  206906. }
  206907. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206908. {
  206909. }
  206910. @end
  206911. @implementation JuceNSWindow
  206912. - (void) setOwner: (NSViewComponentPeer*) owner_
  206913. {
  206914. owner = owner_;
  206915. isZooming = false;
  206916. }
  206917. - (BOOL) canBecomeKeyWindow
  206918. {
  206919. return owner != 0 && owner->canBecomeKeyWindow();
  206920. }
  206921. - (void) becomeKeyWindow
  206922. {
  206923. [super becomeKeyWindow];
  206924. if (owner != 0)
  206925. owner->grabFocus();
  206926. }
  206927. - (BOOL) windowShouldClose: (id) window
  206928. {
  206929. return owner == 0 || owner->windowShouldClose();
  206930. }
  206931. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206932. {
  206933. if (owner != 0)
  206934. frameRect = owner->constrainRect (frameRect);
  206935. return frameRect;
  206936. }
  206937. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206938. {
  206939. if (isZooming)
  206940. return proposedFrameSize;
  206941. NSRect frameRect = [self frame];
  206942. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206943. frameRect.size = proposedFrameSize;
  206944. if (owner != 0)
  206945. frameRect = owner->constrainRect (frameRect);
  206946. return frameRect.size;
  206947. }
  206948. - (void) zoom: (id) sender
  206949. {
  206950. isZooming = true;
  206951. [super zoom: sender];
  206952. isZooming = false;
  206953. }
  206954. - (void) windowWillMove: (NSNotification*) notification
  206955. {
  206956. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206957. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206958. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206959. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206960. }
  206961. @end
  206962. BEGIN_JUCE_NAMESPACE
  206963. ModifierKeys NSViewComponentPeer::currentModifiers;
  206964. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206965. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  206966. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  206967. {
  206968. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  206969. return true;
  206970. if (keyCode >= 'A' && keyCode <= 'Z'
  206971. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  206972. return true;
  206973. if (keyCode >= 'a' && keyCode <= 'z'
  206974. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  206975. return true;
  206976. return false;
  206977. }
  206978. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206979. {
  206980. int m = 0;
  206981. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206982. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206983. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206984. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206985. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206986. }
  206987. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206988. {
  206989. updateModifiers (ev);
  206990. int keyCode = getKeyCodeFromEvent (ev);
  206991. if (keyCode != 0)
  206992. {
  206993. if (isKeyDown)
  206994. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  206995. else
  206996. keysCurrentlyDown.removeValue (keyCode);
  206997. }
  206998. }
  206999. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207000. {
  207001. return NSViewComponentPeer::currentModifiers;
  207002. }
  207003. void ModifierKeys::updateCurrentModifiers() throw()
  207004. {
  207005. currentModifiers = NSViewComponentPeer::currentModifiers;
  207006. }
  207007. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207008. const int windowStyleFlags,
  207009. NSView* viewToAttachTo)
  207010. : ComponentPeer (component_, windowStyleFlags),
  207011. window (0),
  207012. view (0),
  207013. isSharedWindow (viewToAttachTo != 0),
  207014. fullScreen (false),
  207015. insideDrawRect (false),
  207016. #if USE_COREGRAPHICS_RENDERING
  207017. usingCoreGraphics (true),
  207018. #else
  207019. usingCoreGraphics (false),
  207020. #endif
  207021. recursiveToFrontCall (false)
  207022. {
  207023. NSRect r;
  207024. r.origin.x = 0;
  207025. r.origin.y = 0;
  207026. r.size.width = (float) component->getWidth();
  207027. r.size.height = (float) component->getHeight();
  207028. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207029. [view setPostsFrameChangedNotifications: YES];
  207030. if (isSharedWindow)
  207031. {
  207032. window = [viewToAttachTo window];
  207033. [viewToAttachTo addSubview: view];
  207034. setVisible (component->isVisible());
  207035. }
  207036. else
  207037. {
  207038. r.origin.x = (float) component->getX();
  207039. r.origin.y = (float) component->getY();
  207040. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207041. unsigned int style = 0;
  207042. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207043. style = NSBorderlessWindowMask;
  207044. else
  207045. style = NSTitledWindowMask;
  207046. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207047. style |= NSMiniaturizableWindowMask;
  207048. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207049. style |= NSClosableWindowMask;
  207050. if ((windowStyleFlags & windowIsResizable) != 0)
  207051. style |= NSResizableWindowMask;
  207052. window = [[JuceNSWindow alloc] initWithContentRect: r
  207053. styleMask: style
  207054. backing: NSBackingStoreBuffered
  207055. defer: YES];
  207056. [((JuceNSWindow*) window) setOwner: this];
  207057. [window orderOut: nil];
  207058. [window setDelegate: (JuceNSWindow*) window];
  207059. [window setOpaque: component->isOpaque()];
  207060. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207061. if (component->isAlwaysOnTop())
  207062. [window setLevel: NSFloatingWindowLevel];
  207063. [window setContentView: view];
  207064. [window setAutodisplay: YES];
  207065. [window setAcceptsMouseMovedEvents: YES];
  207066. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207067. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207068. [window setReleasedWhenClosed: YES];
  207069. [window retain];
  207070. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207071. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207072. }
  207073. setTitle (component->getName());
  207074. }
  207075. NSViewComponentPeer::~NSViewComponentPeer()
  207076. {
  207077. view->owner = 0;
  207078. [view removeFromSuperview];
  207079. [view release];
  207080. if (! isSharedWindow)
  207081. {
  207082. [((JuceNSWindow*) window) setOwner: 0];
  207083. [window close];
  207084. [window release];
  207085. }
  207086. }
  207087. void* NSViewComponentPeer::getNativeHandle() const
  207088. {
  207089. return view;
  207090. }
  207091. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207092. {
  207093. if (isSharedWindow)
  207094. {
  207095. [view setHidden: ! shouldBeVisible];
  207096. }
  207097. else
  207098. {
  207099. if (shouldBeVisible)
  207100. {
  207101. [window orderFront: nil];
  207102. handleBroughtToFront();
  207103. }
  207104. else
  207105. {
  207106. [window orderOut: nil];
  207107. }
  207108. }
  207109. }
  207110. void NSViewComponentPeer::setTitle (const String& title)
  207111. {
  207112. const ScopedAutoReleasePool pool;
  207113. if (! isSharedWindow)
  207114. [window setTitle: juceStringToNS (title)];
  207115. }
  207116. void NSViewComponentPeer::setPosition (int x, int y)
  207117. {
  207118. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207119. }
  207120. void NSViewComponentPeer::setSize (int w, int h)
  207121. {
  207122. setBounds (component->getX(), component->getY(), w, h, false);
  207123. }
  207124. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207125. {
  207126. fullScreen = isNowFullScreen;
  207127. w = jmax (0, w);
  207128. h = jmax (0, h);
  207129. NSRect r;
  207130. r.origin.x = (float) x;
  207131. r.origin.y = (float) y;
  207132. r.size.width = (float) w;
  207133. r.size.height = (float) h;
  207134. if (isSharedWindow)
  207135. {
  207136. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207137. if ([view frame].size.width != r.size.width
  207138. || [view frame].size.height != r.size.height)
  207139. [view setNeedsDisplay: true];
  207140. [view setFrame: r];
  207141. }
  207142. else
  207143. {
  207144. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207145. [window setFrame: [window frameRectForContentRect: r]
  207146. display: true];
  207147. }
  207148. }
  207149. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207150. {
  207151. NSRect r = [view frame];
  207152. if (global && [view window] != 0)
  207153. {
  207154. r = [view convertRect: r toView: nil];
  207155. NSRect wr = [[view window] frame];
  207156. r.origin.x += wr.origin.x;
  207157. r.origin.y += wr.origin.y;
  207158. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207159. }
  207160. else
  207161. {
  207162. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207163. }
  207164. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207165. }
  207166. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207167. {
  207168. return getBounds (! isSharedWindow);
  207169. }
  207170. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207171. {
  207172. return getBounds (true).getPosition();
  207173. }
  207174. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207175. {
  207176. return relativePosition + getScreenPosition();
  207177. }
  207178. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207179. {
  207180. return screenPosition - getScreenPosition();
  207181. }
  207182. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207183. {
  207184. if (constrainer != 0)
  207185. {
  207186. NSRect current = [window frame];
  207187. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207188. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207189. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207190. (int) r.size.width, (int) r.size.height);
  207191. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207192. (int) current.size.width, (int) current.size.height);
  207193. constrainer->checkBounds (pos, original,
  207194. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207195. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207196. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207197. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207198. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207199. r.origin.x = pos.getX();
  207200. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207201. r.size.width = pos.getWidth();
  207202. r.size.height = pos.getHeight();
  207203. }
  207204. return r;
  207205. }
  207206. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207207. {
  207208. if (! isSharedWindow)
  207209. {
  207210. if (shouldBeMinimised)
  207211. [window miniaturize: nil];
  207212. else
  207213. [window deminiaturize: nil];
  207214. }
  207215. }
  207216. bool NSViewComponentPeer::isMinimised() const
  207217. {
  207218. return window != 0 && [window isMiniaturized];
  207219. }
  207220. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207221. {
  207222. if (! isSharedWindow)
  207223. {
  207224. Rectangle<int> r (lastNonFullscreenBounds);
  207225. setMinimised (false);
  207226. if (fullScreen != shouldBeFullScreen)
  207227. {
  207228. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207229. {
  207230. fullScreen = true;
  207231. [window performZoom: nil];
  207232. }
  207233. else
  207234. {
  207235. if (shouldBeFullScreen)
  207236. r = Desktop::getInstance().getMainMonitorArea();
  207237. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207238. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207239. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207240. }
  207241. }
  207242. }
  207243. }
  207244. bool NSViewComponentPeer::isFullScreen() const
  207245. {
  207246. return fullScreen;
  207247. }
  207248. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207249. {
  207250. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207251. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207252. return false;
  207253. NSPoint p;
  207254. p.x = (float) position.getX();
  207255. p.y = (float) position.getY();
  207256. NSView* v = [view hitTest: p];
  207257. if (trueIfInAChildWindow)
  207258. return v != nil;
  207259. return v == view;
  207260. }
  207261. const BorderSize NSViewComponentPeer::getFrameSize() const
  207262. {
  207263. BorderSize b;
  207264. if (! isSharedWindow)
  207265. {
  207266. NSRect v = [view convertRect: [view frame] toView: nil];
  207267. NSRect w = [window frame];
  207268. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207269. b.setBottom ((int) v.origin.y);
  207270. b.setLeft ((int) v.origin.x);
  207271. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207272. }
  207273. return b;
  207274. }
  207275. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207276. {
  207277. if (! isSharedWindow)
  207278. {
  207279. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207280. : NSNormalWindowLevel];
  207281. }
  207282. return true;
  207283. }
  207284. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207285. {
  207286. if (isSharedWindow)
  207287. {
  207288. [[view superview] addSubview: view
  207289. positioned: NSWindowAbove
  207290. relativeTo: nil];
  207291. }
  207292. if (window != 0 && component->isVisible())
  207293. {
  207294. if (makeActiveWindow)
  207295. [window makeKeyAndOrderFront: nil];
  207296. else
  207297. [window orderFront: nil];
  207298. if (! recursiveToFrontCall)
  207299. {
  207300. recursiveToFrontCall = true;
  207301. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207302. handleBroughtToFront();
  207303. recursiveToFrontCall = false;
  207304. }
  207305. }
  207306. }
  207307. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207308. {
  207309. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207310. if (isSharedWindow)
  207311. {
  207312. [[view superview] addSubview: view
  207313. positioned: NSWindowBelow
  207314. relativeTo: o->view];
  207315. }
  207316. else
  207317. {
  207318. [window orderWindow: NSWindowBelow
  207319. relativeTo: o->window != 0 ? [o->window windowNumber]
  207320. : nil ];
  207321. }
  207322. }
  207323. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207324. {
  207325. // to do..
  207326. }
  207327. void NSViewComponentPeer::viewFocusGain()
  207328. {
  207329. if (currentlyFocusedPeer != this)
  207330. {
  207331. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207332. currentlyFocusedPeer->handleFocusLoss();
  207333. currentlyFocusedPeer = this;
  207334. handleFocusGain();
  207335. }
  207336. }
  207337. void NSViewComponentPeer::viewFocusLoss()
  207338. {
  207339. if (currentlyFocusedPeer == this)
  207340. {
  207341. currentlyFocusedPeer = 0;
  207342. handleFocusLoss();
  207343. }
  207344. }
  207345. void juce_HandleProcessFocusChange()
  207346. {
  207347. NSViewComponentPeer::keysCurrentlyDown.clear();
  207348. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207349. {
  207350. if (Process::isForegroundProcess())
  207351. {
  207352. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207353. ComponentPeer::bringModalComponentToFront();
  207354. }
  207355. else
  207356. {
  207357. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207358. // turn kiosk mode off if we lose focus..
  207359. Desktop::getInstance().setKioskModeComponent (0);
  207360. }
  207361. }
  207362. }
  207363. bool NSViewComponentPeer::isFocused() const
  207364. {
  207365. return isSharedWindow ? this == currentlyFocusedPeer
  207366. : (window != 0 && [window isKeyWindow]);
  207367. }
  207368. void NSViewComponentPeer::grabFocus()
  207369. {
  207370. if (window != 0)
  207371. {
  207372. [window makeKeyWindow];
  207373. [window makeFirstResponder: view];
  207374. viewFocusGain();
  207375. }
  207376. }
  207377. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207378. {
  207379. }
  207380. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207381. {
  207382. String unicode (nsStringToJuce ([ev characters]));
  207383. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207384. int keyCode = getKeyCodeFromEvent (ev);
  207385. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207386. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207387. if (unicode.isNotEmpty() || keyCode != 0)
  207388. {
  207389. if (isKeyDown)
  207390. {
  207391. bool used = false;
  207392. while (unicode.length() > 0)
  207393. {
  207394. juce_wchar textCharacter = unicode[0];
  207395. unicode = unicode.substring (1);
  207396. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207397. textCharacter = 0;
  207398. used = handleKeyUpOrDown (true) || used;
  207399. used = handleKeyPress (keyCode, textCharacter) || used;
  207400. }
  207401. return used;
  207402. }
  207403. else
  207404. {
  207405. if (handleKeyUpOrDown (false))
  207406. return true;
  207407. }
  207408. }
  207409. return false;
  207410. }
  207411. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207412. {
  207413. updateKeysDown (ev, true);
  207414. bool used = handleKeyEvent (ev, true);
  207415. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207416. {
  207417. // for command keys, the key-up event is thrown away, so simulate one..
  207418. updateKeysDown (ev, false);
  207419. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207420. }
  207421. // (If we're running modally, don't allow unused keystrokes to be passed
  207422. // along to other blocked views..)
  207423. if (Component::getCurrentlyModalComponent() != 0)
  207424. used = true;
  207425. return used;
  207426. }
  207427. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207428. {
  207429. updateKeysDown (ev, false);
  207430. return handleKeyEvent (ev, false)
  207431. || Component::getCurrentlyModalComponent() != 0;
  207432. }
  207433. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207434. {
  207435. keysCurrentlyDown.clear();
  207436. handleKeyUpOrDown (true);
  207437. updateModifiers (ev);
  207438. handleModifierKeysChange();
  207439. }
  207440. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207441. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207442. {
  207443. if ([ev type] == NSKeyDown)
  207444. return redirectKeyDown (ev);
  207445. else if ([ev type] == NSKeyUp)
  207446. return redirectKeyUp (ev);
  207447. return false;
  207448. }
  207449. #endif
  207450. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207451. {
  207452. updateModifiers (ev);
  207453. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207454. }
  207455. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207456. {
  207457. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207458. sendMouseEvent (ev);
  207459. }
  207460. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207461. {
  207462. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207463. sendMouseEvent (ev);
  207464. showArrowCursorIfNeeded();
  207465. }
  207466. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207467. {
  207468. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207469. sendMouseEvent (ev);
  207470. }
  207471. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207472. {
  207473. currentModifiers = currentModifiers.withoutMouseButtons();
  207474. sendMouseEvent (ev);
  207475. showArrowCursorIfNeeded();
  207476. }
  207477. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207478. {
  207479. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207480. currentModifiers = currentModifiers.withoutMouseButtons();
  207481. sendMouseEvent (ev);
  207482. }
  207483. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207484. {
  207485. currentModifiers = currentModifiers.withoutMouseButtons();
  207486. sendMouseEvent (ev);
  207487. }
  207488. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207489. {
  207490. updateModifiers (ev);
  207491. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207492. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207493. }
  207494. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207495. {
  207496. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207497. if (mouse.getComponentUnderMouse() == 0
  207498. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207499. {
  207500. [[NSCursor arrowCursor] set];
  207501. }
  207502. }
  207503. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207504. {
  207505. NSString* bestType
  207506. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207507. if (bestType == nil)
  207508. return false;
  207509. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207510. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207511. StringArray files;
  207512. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207513. if (list == nil)
  207514. return false;
  207515. if ([list isKindOfClass: [NSArray class]])
  207516. {
  207517. NSArray* items = (NSArray*) list;
  207518. for (unsigned int i = 0; i < [items count]; ++i)
  207519. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207520. }
  207521. if (files.size() == 0)
  207522. return false;
  207523. if (type == 0)
  207524. handleFileDragMove (files, pos);
  207525. else if (type == 1)
  207526. handleFileDragExit (files);
  207527. else if (type == 2)
  207528. handleFileDragDrop (files, pos);
  207529. return true;
  207530. }
  207531. bool NSViewComponentPeer::isOpaque()
  207532. {
  207533. return component == 0 || component->isOpaque();
  207534. }
  207535. void NSViewComponentPeer::drawRect (NSRect r)
  207536. {
  207537. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207538. return;
  207539. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207540. if (! component->isOpaque())
  207541. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207542. #if USE_COREGRAPHICS_RENDERING
  207543. if (usingCoreGraphics)
  207544. {
  207545. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207546. insideDrawRect = true;
  207547. handlePaint (context);
  207548. insideDrawRect = false;
  207549. }
  207550. else
  207551. #endif
  207552. {
  207553. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207554. (int) (r.size.width + 0.5f),
  207555. (int) (r.size.height + 0.5f),
  207556. ! getComponent()->isOpaque());
  207557. LowLevelGraphicsSoftwareRenderer context (temp);
  207558. context.setOrigin (-roundToInt (r.origin.x),
  207559. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207560. const NSRect* rects = 0;
  207561. NSInteger numRects = 0;
  207562. [view getRectsBeingDrawn: &rects count: &numRects];
  207563. RectangleList clip;
  207564. for (int i = 0; i < numRects; ++i)
  207565. {
  207566. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207567. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207568. roundToInt (rects[i].size.width),
  207569. roundToInt (rects[i].size.height)));
  207570. }
  207571. if (context.clipToRectangleList (clip))
  207572. {
  207573. insideDrawRect = true;
  207574. handlePaint (context);
  207575. insideDrawRect = false;
  207576. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207577. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207578. CGColorSpaceRelease (colourSpace);
  207579. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207580. CGImageRelease (image);
  207581. }
  207582. }
  207583. }
  207584. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207585. {
  207586. StringArray s;
  207587. s.add ("Software Renderer");
  207588. #if USE_COREGRAPHICS_RENDERING
  207589. s.add ("CoreGraphics Renderer");
  207590. #endif
  207591. return s;
  207592. }
  207593. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207594. {
  207595. return usingCoreGraphics ? 1 : 0;
  207596. }
  207597. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207598. {
  207599. #if USE_COREGRAPHICS_RENDERING
  207600. if (usingCoreGraphics != (index > 0))
  207601. {
  207602. usingCoreGraphics = index > 0;
  207603. [view setNeedsDisplay: true];
  207604. }
  207605. #endif
  207606. }
  207607. bool NSViewComponentPeer::canBecomeKeyWindow()
  207608. {
  207609. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207610. }
  207611. bool NSViewComponentPeer::windowShouldClose()
  207612. {
  207613. if (! isValidPeer (this))
  207614. return YES;
  207615. handleUserClosingWindow();
  207616. return NO;
  207617. }
  207618. void NSViewComponentPeer::redirectMovedOrResized()
  207619. {
  207620. handleMovedOrResized();
  207621. }
  207622. void NSViewComponentPeer::viewMovedToWindow()
  207623. {
  207624. if (isSharedWindow)
  207625. window = [view window];
  207626. }
  207627. void Desktop::createMouseInputSources()
  207628. {
  207629. mouseSources.add (new MouseInputSource (0, true));
  207630. }
  207631. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207632. {
  207633. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207634. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207635. // is apparently still available in 64-bit apps..
  207636. if (enableOrDisable)
  207637. {
  207638. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207639. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207640. }
  207641. else
  207642. {
  207643. SetSystemUIMode (kUIModeNormal, 0);
  207644. }
  207645. }
  207646. class AsyncRepaintMessage : public CallbackMessage
  207647. {
  207648. public:
  207649. NSViewComponentPeer* const peer;
  207650. const Rectangle<int> rect;
  207651. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207652. : peer (peer_), rect (rect_)
  207653. {
  207654. }
  207655. void messageCallback()
  207656. {
  207657. if (ComponentPeer::isValidPeer (peer))
  207658. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207659. }
  207660. };
  207661. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207662. {
  207663. if (insideDrawRect)
  207664. {
  207665. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207666. }
  207667. else
  207668. {
  207669. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207670. (float) w, (float) h)];
  207671. }
  207672. }
  207673. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207674. {
  207675. [view displayIfNeeded];
  207676. }
  207677. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207678. {
  207679. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207680. }
  207681. Image* juce_createIconForFile (const File& file)
  207682. {
  207683. const ScopedAutoReleasePool pool;
  207684. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207685. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207686. [NSGraphicsContext saveGraphicsState];
  207687. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207688. [image drawAtPoint: NSMakePoint (0, 0)
  207689. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207690. operation: NSCompositeSourceOver fraction: 1.0f];
  207691. [[NSGraphicsContext currentContext] flushGraphics];
  207692. [NSGraphicsContext restoreGraphicsState];
  207693. return result;
  207694. }
  207695. const int KeyPress::spaceKey = ' ';
  207696. const int KeyPress::returnKey = 0x0d;
  207697. const int KeyPress::escapeKey = 0x1b;
  207698. const int KeyPress::backspaceKey = 0x7f;
  207699. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207700. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207701. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207702. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207703. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207704. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207705. const int KeyPress::endKey = NSEndFunctionKey;
  207706. const int KeyPress::homeKey = NSHomeFunctionKey;
  207707. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207708. const int KeyPress::insertKey = -1;
  207709. const int KeyPress::tabKey = 9;
  207710. const int KeyPress::F1Key = NSF1FunctionKey;
  207711. const int KeyPress::F2Key = NSF2FunctionKey;
  207712. const int KeyPress::F3Key = NSF3FunctionKey;
  207713. const int KeyPress::F4Key = NSF4FunctionKey;
  207714. const int KeyPress::F5Key = NSF5FunctionKey;
  207715. const int KeyPress::F6Key = NSF6FunctionKey;
  207716. const int KeyPress::F7Key = NSF7FunctionKey;
  207717. const int KeyPress::F8Key = NSF8FunctionKey;
  207718. const int KeyPress::F9Key = NSF9FunctionKey;
  207719. const int KeyPress::F10Key = NSF10FunctionKey;
  207720. const int KeyPress::F11Key = NSF1FunctionKey;
  207721. const int KeyPress::F12Key = NSF12FunctionKey;
  207722. const int KeyPress::F13Key = NSF13FunctionKey;
  207723. const int KeyPress::F14Key = NSF14FunctionKey;
  207724. const int KeyPress::F15Key = NSF15FunctionKey;
  207725. const int KeyPress::F16Key = NSF16FunctionKey;
  207726. const int KeyPress::numberPad0 = 0x30020;
  207727. const int KeyPress::numberPad1 = 0x30021;
  207728. const int KeyPress::numberPad2 = 0x30022;
  207729. const int KeyPress::numberPad3 = 0x30023;
  207730. const int KeyPress::numberPad4 = 0x30024;
  207731. const int KeyPress::numberPad5 = 0x30025;
  207732. const int KeyPress::numberPad6 = 0x30026;
  207733. const int KeyPress::numberPad7 = 0x30027;
  207734. const int KeyPress::numberPad8 = 0x30028;
  207735. const int KeyPress::numberPad9 = 0x30029;
  207736. const int KeyPress::numberPadAdd = 0x3002a;
  207737. const int KeyPress::numberPadSubtract = 0x3002b;
  207738. const int KeyPress::numberPadMultiply = 0x3002c;
  207739. const int KeyPress::numberPadDivide = 0x3002d;
  207740. const int KeyPress::numberPadSeparator = 0x3002e;
  207741. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207742. const int KeyPress::numberPadEquals = 0x30030;
  207743. const int KeyPress::numberPadDelete = 0x30031;
  207744. const int KeyPress::playKey = 0x30000;
  207745. const int KeyPress::stopKey = 0x30001;
  207746. const int KeyPress::fastForwardKey = 0x30002;
  207747. const int KeyPress::rewindKey = 0x30003;
  207748. #endif
  207749. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207750. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207751. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207752. // compiled on its own).
  207753. #if JUCE_INCLUDED_FILE
  207754. #if JUCE_MAC
  207755. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207756. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  207757. {
  207758. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207759. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207760. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207761. [im release];
  207762. return c;
  207763. }
  207764. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  207765. {
  207766. MemoryInputStream stream (data, false);
  207767. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207768. jassert (im != 0);
  207769. if (im == 0)
  207770. return 0;
  207771. return juce_createMouseCursorFromImage (*im,
  207772. (int) (hx * im->getWidth()),
  207773. (int) (hy * im->getHeight()));
  207774. }
  207775. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207776. {
  207777. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207778. MemoryBlock mb;
  207779. if (f.getChildFile (filename).loadFileAsData (mb))
  207780. return juce_cursorFromData (mb, hx, hy);
  207781. return 0;
  207782. }
  207783. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  207784. {
  207785. const ScopedAutoReleasePool pool;
  207786. NSCursor* c = 0;
  207787. switch (type)
  207788. {
  207789. case MouseCursor::NormalCursor:
  207790. c = [NSCursor arrowCursor];
  207791. break;
  207792. case MouseCursor::NoCursor:
  207793. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207794. case MouseCursor::DraggingHandCursor:
  207795. c = [NSCursor openHandCursor];
  207796. break;
  207797. case MouseCursor::CopyingCursor:
  207798. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207799. case MouseCursor::WaitCursor:
  207800. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207801. break;
  207802. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207803. case MouseCursor::IBeamCursor:
  207804. c = [NSCursor IBeamCursor];
  207805. break;
  207806. case MouseCursor::PointingHandCursor:
  207807. c = [NSCursor pointingHandCursor];
  207808. break;
  207809. case MouseCursor::LeftRightResizeCursor:
  207810. c = [NSCursor resizeLeftRightCursor];
  207811. break;
  207812. case MouseCursor::LeftEdgeResizeCursor:
  207813. c = [NSCursor resizeLeftCursor];
  207814. break;
  207815. case MouseCursor::RightEdgeResizeCursor:
  207816. c = [NSCursor resizeRightCursor];
  207817. break;
  207818. case MouseCursor::UpDownResizeCursor:
  207819. case MouseCursor::TopEdgeResizeCursor:
  207820. case MouseCursor::BottomEdgeResizeCursor:
  207821. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207822. case MouseCursor::TopLeftCornerResizeCursor:
  207823. case MouseCursor::BottomRightCornerResizeCursor:
  207824. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207825. case MouseCursor::TopRightCornerResizeCursor:
  207826. case MouseCursor::BottomLeftCornerResizeCursor:
  207827. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207828. case MouseCursor::UpDownLeftRightResizeCursor:
  207829. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207830. case MouseCursor::CrosshairCursor:
  207831. c = [NSCursor crosshairCursor];
  207832. break;
  207833. }
  207834. [c retain];
  207835. return c;
  207836. }
  207837. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  207838. {
  207839. NSCursor* c = (NSCursor*) cursorHandle;
  207840. [c release];
  207841. }
  207842. void MouseCursor::showInAllWindows() const
  207843. {
  207844. showInWindow (0);
  207845. }
  207846. void MouseCursor::showInWindow (ComponentPeer*) const
  207847. {
  207848. NSCursor* const c = (NSCursor*) getHandle();
  207849. [c set];
  207850. }
  207851. #else
  207852. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  207853. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  207854. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  207855. void MouseCursor::showInAllWindows() const {}
  207856. void MouseCursor::showInWindow (ComponentPeer*) const {}
  207857. #endif
  207858. #endif
  207859. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207860. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207861. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207862. // compiled on its own).
  207863. #if JUCE_INCLUDED_FILE
  207864. class NSViewComponentInternal : public ComponentMovementWatcher
  207865. {
  207866. Component* const owner;
  207867. NSViewComponentPeer* currentPeer;
  207868. bool wasShowing;
  207869. public:
  207870. NSView* const view;
  207871. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207872. : ComponentMovementWatcher (owner_),
  207873. owner (owner_),
  207874. currentPeer (0),
  207875. wasShowing (false),
  207876. view (view_)
  207877. {
  207878. [view_ retain];
  207879. if (owner_->isShowing())
  207880. componentPeerChanged();
  207881. }
  207882. ~NSViewComponentInternal()
  207883. {
  207884. [view removeFromSuperview];
  207885. [view release];
  207886. }
  207887. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207888. {
  207889. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207890. // The ComponentMovementWatcher version of this method avoids calling
  207891. // us when the top-level comp is resized, but for an NSView we need to know this
  207892. // because with inverted co-ords, we need to update the position even if the
  207893. // top-left pos hasn't changed
  207894. if (comp.isOnDesktop() && wasResized)
  207895. componentMovedOrResized (wasMoved, wasResized);
  207896. }
  207897. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207898. {
  207899. Component* const topComp = owner->getTopLevelComponent();
  207900. if (topComp->getPeer() != 0)
  207901. {
  207902. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207903. NSRect r;
  207904. r.origin.x = (float) pos.getX();
  207905. r.origin.y = (float) pos.getY();
  207906. r.size.width = (float) owner->getWidth();
  207907. r.size.height = (float) owner->getHeight();
  207908. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207909. [view setFrame: r];
  207910. }
  207911. }
  207912. void componentPeerChanged()
  207913. {
  207914. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207915. if (currentPeer != peer)
  207916. {
  207917. [view removeFromSuperview];
  207918. currentPeer = peer;
  207919. if (peer != 0)
  207920. {
  207921. [peer->view addSubview: view];
  207922. componentMovedOrResized (false, false);
  207923. }
  207924. }
  207925. [view setHidden: ! owner->isShowing()];
  207926. }
  207927. void componentVisibilityChanged (Component&)
  207928. {
  207929. componentPeerChanged();
  207930. }
  207931. juce_UseDebuggingNewOperator
  207932. private:
  207933. NSViewComponentInternal (const NSViewComponentInternal&);
  207934. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207935. };
  207936. NSViewComponent::NSViewComponent()
  207937. {
  207938. }
  207939. NSViewComponent::~NSViewComponent()
  207940. {
  207941. }
  207942. void NSViewComponent::setView (void* view)
  207943. {
  207944. if (view != getView())
  207945. {
  207946. if (view != 0)
  207947. info = new NSViewComponentInternal ((NSView*) view, this);
  207948. else
  207949. info = 0;
  207950. }
  207951. }
  207952. void* NSViewComponent::getView() const
  207953. {
  207954. return info == 0 ? 0 : info->view;
  207955. }
  207956. void NSViewComponent::paint (Graphics& g)
  207957. {
  207958. }
  207959. #endif
  207960. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207961. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207962. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207963. // compiled on its own).
  207964. #if JUCE_INCLUDED_FILE
  207965. AppleRemoteDevice::AppleRemoteDevice()
  207966. : device (0),
  207967. queue (0),
  207968. remoteId (0)
  207969. {
  207970. }
  207971. AppleRemoteDevice::~AppleRemoteDevice()
  207972. {
  207973. stop();
  207974. }
  207975. static io_object_t getAppleRemoteDevice()
  207976. {
  207977. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207978. io_iterator_t iter = 0;
  207979. io_object_t iod = 0;
  207980. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207981. && iter != 0)
  207982. {
  207983. iod = IOIteratorNext (iter);
  207984. }
  207985. IOObjectRelease (iter);
  207986. return iod;
  207987. }
  207988. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207989. {
  207990. jassert (*device == 0);
  207991. io_name_t classname;
  207992. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207993. {
  207994. IOCFPlugInInterface** cfPlugInInterface = 0;
  207995. SInt32 score = 0;
  207996. if (IOCreatePlugInInterfaceForService (iod,
  207997. kIOHIDDeviceUserClientTypeID,
  207998. kIOCFPlugInInterfaceID,
  207999. &cfPlugInInterface,
  208000. &score) == kIOReturnSuccess)
  208001. {
  208002. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208003. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208004. device);
  208005. (void) hr;
  208006. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208007. }
  208008. }
  208009. return *device != 0;
  208010. }
  208011. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208012. {
  208013. if (queue != 0)
  208014. return true;
  208015. stop();
  208016. bool result = false;
  208017. io_object_t iod = getAppleRemoteDevice();
  208018. if (iod != 0)
  208019. {
  208020. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208021. result = true;
  208022. else
  208023. stop();
  208024. IOObjectRelease (iod);
  208025. }
  208026. return result;
  208027. }
  208028. void AppleRemoteDevice::stop()
  208029. {
  208030. if (queue != 0)
  208031. {
  208032. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208033. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208034. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208035. queue = 0;
  208036. }
  208037. if (device != 0)
  208038. {
  208039. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208040. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208041. device = 0;
  208042. }
  208043. }
  208044. bool AppleRemoteDevice::isActive() const
  208045. {
  208046. return queue != 0;
  208047. }
  208048. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208049. {
  208050. if (result == kIOReturnSuccess)
  208051. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208052. }
  208053. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208054. {
  208055. Array <int> cookies;
  208056. CFArrayRef elements;
  208057. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208058. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208059. return false;
  208060. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208061. {
  208062. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208063. // get the cookie
  208064. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208065. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208066. continue;
  208067. long number;
  208068. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208069. continue;
  208070. cookies.add ((int) number);
  208071. }
  208072. CFRelease (elements);
  208073. if ((*(IOHIDDeviceInterface**) device)
  208074. ->open ((IOHIDDeviceInterface**) device,
  208075. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208076. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208077. {
  208078. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208079. if (queue != 0)
  208080. {
  208081. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208082. for (int i = 0; i < cookies.size(); ++i)
  208083. {
  208084. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208085. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208086. }
  208087. CFRunLoopSourceRef eventSource;
  208088. if ((*(IOHIDQueueInterface**) queue)
  208089. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208090. {
  208091. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208092. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208093. {
  208094. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208095. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208096. return true;
  208097. }
  208098. }
  208099. }
  208100. }
  208101. return false;
  208102. }
  208103. void AppleRemoteDevice::handleCallbackInternal()
  208104. {
  208105. int totalValues = 0;
  208106. AbsoluteTime nullTime = { 0, 0 };
  208107. char cookies [12];
  208108. int numCookies = 0;
  208109. while (numCookies < numElementsInArray (cookies))
  208110. {
  208111. IOHIDEventStruct e;
  208112. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208113. break;
  208114. if ((int) e.elementCookie == 19)
  208115. {
  208116. remoteId = e.value;
  208117. buttonPressed (switched, false);
  208118. }
  208119. else
  208120. {
  208121. totalValues += e.value;
  208122. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208123. }
  208124. }
  208125. cookies [numCookies++] = 0;
  208126. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208127. static const char buttonPatterns[] =
  208128. {
  208129. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208130. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208131. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208132. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208133. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208134. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208135. 0x1f, 0x12, 0x04, 0x02, 0,
  208136. 0x1f, 0x12, 0x03, 0x02, 0,
  208137. 0x1f, 0x12, 0x1f, 0x12, 0,
  208138. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208139. 19, 0
  208140. };
  208141. int buttonNum = (int) menuButton;
  208142. int i = 0;
  208143. while (i < numElementsInArray (buttonPatterns))
  208144. {
  208145. if (strcmp (cookies, buttonPatterns + i) == 0)
  208146. {
  208147. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208148. break;
  208149. }
  208150. i += (int) strlen (buttonPatterns + i) + 1;
  208151. ++buttonNum;
  208152. }
  208153. }
  208154. #endif
  208155. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208156. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208157. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208158. // compiled on its own).
  208159. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208160. #if JUCE_MAC
  208161. END_JUCE_NAMESPACE
  208162. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208163. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208164. {
  208165. CriticalSection* contextLock;
  208166. bool needsUpdate;
  208167. }
  208168. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208169. - (bool) makeActive;
  208170. - (void) makeInactive;
  208171. - (void) reshape;
  208172. @end
  208173. @implementation ThreadSafeNSOpenGLView
  208174. - (id) initWithFrame: (NSRect) frameRect
  208175. pixelFormat: (NSOpenGLPixelFormat*) format
  208176. {
  208177. contextLock = new CriticalSection();
  208178. self = [super initWithFrame: frameRect pixelFormat: format];
  208179. if (self != nil)
  208180. [[NSNotificationCenter defaultCenter] addObserver: self
  208181. selector: @selector (_surfaceNeedsUpdate:)
  208182. name: NSViewGlobalFrameDidChangeNotification
  208183. object: self];
  208184. return self;
  208185. }
  208186. - (void) dealloc
  208187. {
  208188. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208189. delete contextLock;
  208190. [super dealloc];
  208191. }
  208192. - (bool) makeActive
  208193. {
  208194. const ScopedLock sl (*contextLock);
  208195. if ([self openGLContext] == 0)
  208196. return false;
  208197. [[self openGLContext] makeCurrentContext];
  208198. if (needsUpdate)
  208199. {
  208200. [super update];
  208201. needsUpdate = false;
  208202. }
  208203. return true;
  208204. }
  208205. - (void) makeInactive
  208206. {
  208207. const ScopedLock sl (*contextLock);
  208208. [NSOpenGLContext clearCurrentContext];
  208209. }
  208210. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208211. {
  208212. const ScopedLock sl (*contextLock);
  208213. needsUpdate = true;
  208214. }
  208215. - (void) update
  208216. {
  208217. const ScopedLock sl (*contextLock);
  208218. needsUpdate = true;
  208219. }
  208220. - (void) reshape
  208221. {
  208222. const ScopedLock sl (*contextLock);
  208223. needsUpdate = true;
  208224. }
  208225. @end
  208226. BEGIN_JUCE_NAMESPACE
  208227. class WindowedGLContext : public OpenGLContext
  208228. {
  208229. public:
  208230. WindowedGLContext (Component* const component,
  208231. const OpenGLPixelFormat& pixelFormat_,
  208232. NSOpenGLContext* sharedContext)
  208233. : renderContext (0),
  208234. pixelFormat (pixelFormat_)
  208235. {
  208236. jassert (component != 0);
  208237. NSOpenGLPixelFormatAttribute attribs [64];
  208238. int n = 0;
  208239. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208240. attribs[n++] = NSOpenGLPFAAccelerated;
  208241. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208242. attribs[n++] = NSOpenGLPFAColorSize;
  208243. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208244. pixelFormat.greenBits,
  208245. pixelFormat.blueBits);
  208246. attribs[n++] = NSOpenGLPFAAlphaSize;
  208247. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208248. attribs[n++] = NSOpenGLPFADepthSize;
  208249. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208250. attribs[n++] = NSOpenGLPFAStencilSize;
  208251. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208252. attribs[n++] = NSOpenGLPFAAccumSize;
  208253. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208254. pixelFormat.accumulationBufferGreenBits,
  208255. pixelFormat.accumulationBufferBlueBits,
  208256. pixelFormat.accumulationBufferAlphaBits);
  208257. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208258. attribs[n++] = NSOpenGLPFASampleBuffers;
  208259. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208260. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208261. attribs[n++] = NSOpenGLPFANoRecovery;
  208262. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208263. NSOpenGLPixelFormat* format
  208264. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208265. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208266. pixelFormat: format];
  208267. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208268. shareContext: sharedContext] autorelease];
  208269. const GLint swapInterval = 1;
  208270. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208271. [view setOpenGLContext: renderContext];
  208272. [renderContext setView: view];
  208273. [format release];
  208274. viewHolder = new NSViewComponentInternal (view, component);
  208275. }
  208276. ~WindowedGLContext()
  208277. {
  208278. makeInactive();
  208279. [renderContext clearDrawable];
  208280. viewHolder = 0;
  208281. }
  208282. bool makeActive() const throw()
  208283. {
  208284. jassert (renderContext != 0);
  208285. [view makeActive];
  208286. return isActive();
  208287. }
  208288. bool makeInactive() const throw()
  208289. {
  208290. [view makeInactive];
  208291. return true;
  208292. }
  208293. bool isActive() const throw()
  208294. {
  208295. return [NSOpenGLContext currentContext] == renderContext;
  208296. }
  208297. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208298. void* getRawContext() const throw() { return renderContext; }
  208299. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208300. {
  208301. }
  208302. void swapBuffers()
  208303. {
  208304. [renderContext flushBuffer];
  208305. }
  208306. bool setSwapInterval (const int numFramesPerSwap)
  208307. {
  208308. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208309. forParameter: NSOpenGLCPSwapInterval];
  208310. return true;
  208311. }
  208312. int getSwapInterval() const
  208313. {
  208314. GLint numFrames = 0;
  208315. [renderContext getValues: &numFrames
  208316. forParameter: NSOpenGLCPSwapInterval];
  208317. return numFrames;
  208318. }
  208319. void repaint()
  208320. {
  208321. // we need to invalidate the juce view that holds this gl view, to make it
  208322. // cause a repaint callback
  208323. NSView* v = (NSView*) viewHolder->view;
  208324. NSRect r = [v frame];
  208325. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208326. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208327. // repaint message, thus never causing our paint() callback, and never repainting
  208328. // the comp. So invalidating just a little bit around the edge helps..
  208329. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208330. }
  208331. void* getNativeWindowHandle() const { return viewHolder->view; }
  208332. juce_UseDebuggingNewOperator
  208333. NSOpenGLContext* renderContext;
  208334. ThreadSafeNSOpenGLView* view;
  208335. private:
  208336. OpenGLPixelFormat pixelFormat;
  208337. ScopedPointer <NSViewComponentInternal> viewHolder;
  208338. WindowedGLContext (const WindowedGLContext&);
  208339. WindowedGLContext& operator= (const WindowedGLContext&);
  208340. };
  208341. OpenGLContext* OpenGLComponent::createContext()
  208342. {
  208343. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208344. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208345. return (c->renderContext != 0) ? c.release() : 0;
  208346. }
  208347. void* OpenGLComponent::getNativeWindowHandle() const
  208348. {
  208349. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208350. : 0;
  208351. }
  208352. void juce_glViewport (const int w, const int h)
  208353. {
  208354. glViewport (0, 0, w, h);
  208355. }
  208356. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208357. OwnedArray <OpenGLPixelFormat>& results)
  208358. {
  208359. /* GLint attribs [64];
  208360. int n = 0;
  208361. attribs[n++] = AGL_RGBA;
  208362. attribs[n++] = AGL_DOUBLEBUFFER;
  208363. attribs[n++] = AGL_ACCELERATED;
  208364. attribs[n++] = AGL_NO_RECOVERY;
  208365. attribs[n++] = AGL_NONE;
  208366. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208367. while (p != 0)
  208368. {
  208369. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208370. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208371. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208372. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208373. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208374. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208375. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208376. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208377. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208378. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208379. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208380. results.add (pf);
  208381. p = aglNextPixelFormat (p);
  208382. }*/
  208383. //jassertfalse //xxx can't see how you do this in cocoa!
  208384. }
  208385. #else
  208386. END_JUCE_NAMESPACE
  208387. @interface JuceGLView : UIView
  208388. {
  208389. }
  208390. + (Class) layerClass;
  208391. @end
  208392. @implementation JuceGLView
  208393. + (Class) layerClass
  208394. {
  208395. return [CAEAGLLayer class];
  208396. }
  208397. @end
  208398. BEGIN_JUCE_NAMESPACE
  208399. class GLESContext : public OpenGLContext
  208400. {
  208401. public:
  208402. GLESContext (UIViewComponentPeer* peer,
  208403. Component* const component_,
  208404. const OpenGLPixelFormat& pixelFormat_,
  208405. const GLESContext* const sharedContext,
  208406. NSUInteger apiType)
  208407. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208408. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208409. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208410. {
  208411. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208412. view.opaque = YES;
  208413. view.hidden = NO;
  208414. view.backgroundColor = [UIColor blackColor];
  208415. view.userInteractionEnabled = NO;
  208416. glLayer = (CAEAGLLayer*) [view layer];
  208417. [peer->view addSubview: view];
  208418. if (sharedContext != 0)
  208419. context = [[EAGLContext alloc] initWithAPI: apiType
  208420. sharegroup: [sharedContext->context sharegroup]];
  208421. else
  208422. context = [[EAGLContext alloc] initWithAPI: apiType];
  208423. createGLBuffers();
  208424. }
  208425. ~GLESContext()
  208426. {
  208427. makeInactive();
  208428. [context release];
  208429. [view removeFromSuperview];
  208430. [view release];
  208431. freeGLBuffers();
  208432. }
  208433. bool makeActive() const throw()
  208434. {
  208435. jassert (context != 0);
  208436. [EAGLContext setCurrentContext: context];
  208437. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208438. return true;
  208439. }
  208440. void swapBuffers()
  208441. {
  208442. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208443. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208444. }
  208445. bool makeInactive() const throw()
  208446. {
  208447. return [EAGLContext setCurrentContext: nil];
  208448. }
  208449. bool isActive() const throw()
  208450. {
  208451. return [EAGLContext currentContext] == context;
  208452. }
  208453. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208454. void* getRawContext() const throw() { return glLayer; }
  208455. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208456. {
  208457. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208458. if (lastWidth != w || lastHeight != h)
  208459. {
  208460. lastWidth = w;
  208461. lastHeight = h;
  208462. freeGLBuffers();
  208463. createGLBuffers();
  208464. }
  208465. }
  208466. bool setSwapInterval (const int numFramesPerSwap)
  208467. {
  208468. numFrames = numFramesPerSwap;
  208469. return true;
  208470. }
  208471. int getSwapInterval() const
  208472. {
  208473. return numFrames;
  208474. }
  208475. void repaint()
  208476. {
  208477. }
  208478. void createGLBuffers()
  208479. {
  208480. makeActive();
  208481. glGenFramebuffersOES (1, &frameBufferHandle);
  208482. glGenRenderbuffersOES (1, &colorBufferHandle);
  208483. glGenRenderbuffersOES (1, &depthBufferHandle);
  208484. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208485. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208486. GLint width, height;
  208487. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208488. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208489. if (useDepthBuffer)
  208490. {
  208491. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208492. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208493. }
  208494. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208495. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208496. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208497. if (useDepthBuffer)
  208498. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208499. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208500. }
  208501. void freeGLBuffers()
  208502. {
  208503. if (frameBufferHandle != 0)
  208504. {
  208505. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208506. frameBufferHandle = 0;
  208507. }
  208508. if (colorBufferHandle != 0)
  208509. {
  208510. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208511. colorBufferHandle = 0;
  208512. }
  208513. if (depthBufferHandle != 0)
  208514. {
  208515. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208516. depthBufferHandle = 0;
  208517. }
  208518. }
  208519. juce_UseDebuggingNewOperator
  208520. private:
  208521. Component::SafePointer<Component> component;
  208522. OpenGLPixelFormat pixelFormat;
  208523. JuceGLView* view;
  208524. CAEAGLLayer* glLayer;
  208525. EAGLContext* context;
  208526. bool useDepthBuffer;
  208527. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208528. int numFrames;
  208529. int lastWidth, lastHeight;
  208530. GLESContext (const GLESContext&);
  208531. GLESContext& operator= (const GLESContext&);
  208532. };
  208533. OpenGLContext* OpenGLComponent::createContext()
  208534. {
  208535. ScopedAutoReleasePool pool;
  208536. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208537. if (peer != 0)
  208538. return new GLESContext (peer, this, preferredPixelFormat,
  208539. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208540. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208541. return 0;
  208542. }
  208543. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208544. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208545. {
  208546. }
  208547. void juce_glViewport (const int w, const int h)
  208548. {
  208549. glViewport (0, 0, w, h);
  208550. }
  208551. #endif
  208552. #endif
  208553. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208554. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208555. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208556. // compiled on its own).
  208557. #if JUCE_INCLUDED_FILE
  208558. class JuceMainMenuHandler;
  208559. END_JUCE_NAMESPACE
  208560. using namespace JUCE_NAMESPACE;
  208561. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208562. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208563. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208564. #else
  208565. @interface JuceMenuCallback : NSObject
  208566. #endif
  208567. {
  208568. JuceMainMenuHandler* owner;
  208569. }
  208570. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208571. - (void) dealloc;
  208572. - (void) menuItemInvoked: (id) menu;
  208573. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208574. @end
  208575. BEGIN_JUCE_NAMESPACE
  208576. class JuceMainMenuHandler : private MenuBarModelListener,
  208577. private DeletedAtShutdown
  208578. {
  208579. public:
  208580. static JuceMainMenuHandler* instance;
  208581. JuceMainMenuHandler()
  208582. : currentModel (0),
  208583. lastUpdateTime (0)
  208584. {
  208585. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208586. }
  208587. ~JuceMainMenuHandler()
  208588. {
  208589. setMenu (0);
  208590. jassert (instance == this);
  208591. instance = 0;
  208592. [callback release];
  208593. }
  208594. void setMenu (MenuBarModel* const newMenuBarModel)
  208595. {
  208596. if (currentModel != newMenuBarModel)
  208597. {
  208598. if (currentModel != 0)
  208599. currentModel->removeListener (this);
  208600. currentModel = newMenuBarModel;
  208601. if (currentModel != 0)
  208602. currentModel->addListener (this);
  208603. menuBarItemsChanged (0);
  208604. }
  208605. }
  208606. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208607. const String& name, const int menuId, const int tag)
  208608. {
  208609. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208610. action: nil
  208611. keyEquivalent: @""];
  208612. [item setTag: tag];
  208613. NSMenu* sub = createMenu (child, name, menuId, tag);
  208614. [parent setSubmenu: sub forItem: item];
  208615. [sub setAutoenablesItems: false];
  208616. [sub release];
  208617. }
  208618. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208619. const String& name, const int menuId, const int tag)
  208620. {
  208621. [parentItem setTag: tag];
  208622. NSMenu* menu = [parentItem submenu];
  208623. [menu setTitle: juceStringToNS (name)];
  208624. while ([menu numberOfItems] > 0)
  208625. [menu removeItemAtIndex: 0];
  208626. PopupMenu::MenuItemIterator iter (menuToCopy);
  208627. while (iter.next())
  208628. addMenuItem (iter, menu, menuId, tag);
  208629. [menu setAutoenablesItems: false];
  208630. [menu update];
  208631. }
  208632. void menuBarItemsChanged (MenuBarModel*)
  208633. {
  208634. lastUpdateTime = Time::getMillisecondCounter();
  208635. StringArray menuNames;
  208636. if (currentModel != 0)
  208637. menuNames = currentModel->getMenuBarNames();
  208638. NSMenu* menuBar = [NSApp mainMenu];
  208639. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208640. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208641. int menuId = 1;
  208642. for (int i = 0; i < menuNames.size(); ++i)
  208643. {
  208644. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208645. if (i >= [menuBar numberOfItems] - 1)
  208646. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208647. else
  208648. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208649. }
  208650. }
  208651. static void flashMenuBar (NSMenu* menu)
  208652. {
  208653. if ([[menu title] isEqualToString: @"Apple"])
  208654. return;
  208655. [menu retain];
  208656. const unichar f35Key = NSF35FunctionKey;
  208657. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208658. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208659. action: nil
  208660. keyEquivalent: f35String];
  208661. [item setTarget: nil];
  208662. [menu insertItem: item atIndex: [menu numberOfItems]];
  208663. [item release];
  208664. if ([menu indexOfItem: item] >= 0)
  208665. {
  208666. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208667. location: NSZeroPoint
  208668. modifierFlags: NSCommandKeyMask
  208669. timestamp: 0
  208670. windowNumber: 0
  208671. context: [NSGraphicsContext currentContext]
  208672. characters: f35String
  208673. charactersIgnoringModifiers: f35String
  208674. isARepeat: NO
  208675. keyCode: 0];
  208676. [menu performKeyEquivalent: f35Event];
  208677. if ([menu indexOfItem: item] >= 0)
  208678. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208679. }
  208680. [menu release];
  208681. }
  208682. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208683. {
  208684. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208685. {
  208686. NSMenuItem* m = [menu itemAtIndex: i];
  208687. if ([m tag] == info.commandID)
  208688. return m;
  208689. if ([m submenu] != 0)
  208690. {
  208691. NSMenuItem* found = findMenuItem ([m submenu], info);
  208692. if (found != 0)
  208693. return found;
  208694. }
  208695. }
  208696. return 0;
  208697. }
  208698. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208699. {
  208700. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208701. if (item != 0)
  208702. flashMenuBar ([item menu]);
  208703. }
  208704. void updateMenus()
  208705. {
  208706. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208707. menuBarItemsChanged (0);
  208708. }
  208709. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208710. {
  208711. if (currentModel != 0)
  208712. {
  208713. if (commandManager != 0)
  208714. {
  208715. ApplicationCommandTarget::InvocationInfo info (commandId);
  208716. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208717. commandManager->invoke (info, true);
  208718. }
  208719. currentModel->menuItemSelected (commandId, topLevelIndex);
  208720. }
  208721. }
  208722. MenuBarModel* currentModel;
  208723. uint32 lastUpdateTime;
  208724. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208725. const int topLevelMenuId, const int topLevelIndex)
  208726. {
  208727. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208728. if (text == 0)
  208729. text = @"";
  208730. if (iter.isSeparator)
  208731. {
  208732. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208733. }
  208734. else if (iter.isSectionHeader)
  208735. {
  208736. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208737. action: nil
  208738. keyEquivalent: @""];
  208739. [item setEnabled: false];
  208740. }
  208741. else if (iter.subMenu != 0)
  208742. {
  208743. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208744. action: nil
  208745. keyEquivalent: @""];
  208746. [item setTag: iter.itemId];
  208747. [item setEnabled: iter.isEnabled];
  208748. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208749. [sub setDelegate: nil];
  208750. [menuToAddTo setSubmenu: sub forItem: item];
  208751. [sub release];
  208752. }
  208753. else
  208754. {
  208755. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208756. action: @selector (menuItemInvoked:)
  208757. keyEquivalent: @""];
  208758. [item setTag: iter.itemId];
  208759. [item setEnabled: iter.isEnabled];
  208760. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208761. [item setTarget: (id) callback];
  208762. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208763. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208764. [item setRepresentedObject: info];
  208765. if (iter.commandManager != 0)
  208766. {
  208767. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208768. ->getKeyPressesAssignedToCommand (iter.itemId));
  208769. if (keyPresses.size() > 0)
  208770. {
  208771. const KeyPress& kp = keyPresses.getReference(0);
  208772. juce_wchar key = kp.getTextCharacter();
  208773. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208774. key = NSBackspaceCharacter;
  208775. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208776. key = NSDeleteCharacter;
  208777. else if (key == 0)
  208778. key = (juce_wchar) kp.getKeyCode();
  208779. unsigned int mods = 0;
  208780. if (kp.getModifiers().isShiftDown())
  208781. mods |= NSShiftKeyMask;
  208782. if (kp.getModifiers().isCtrlDown())
  208783. mods |= NSControlKeyMask;
  208784. if (kp.getModifiers().isAltDown())
  208785. mods |= NSAlternateKeyMask;
  208786. if (kp.getModifiers().isCommandDown())
  208787. mods |= NSCommandKeyMask;
  208788. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208789. [item setKeyEquivalentModifierMask: mods];
  208790. }
  208791. }
  208792. }
  208793. }
  208794. JuceMenuCallback* callback;
  208795. private:
  208796. NSMenu* createMenu (const PopupMenu menu,
  208797. const String& menuName,
  208798. const int topLevelMenuId,
  208799. const int topLevelIndex)
  208800. {
  208801. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208802. [m setAutoenablesItems: false];
  208803. [m setDelegate: callback];
  208804. PopupMenu::MenuItemIterator iter (menu);
  208805. while (iter.next())
  208806. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208807. [m update];
  208808. return m;
  208809. }
  208810. };
  208811. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208812. END_JUCE_NAMESPACE
  208813. @implementation JuceMenuCallback
  208814. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208815. {
  208816. [super init];
  208817. owner = owner_;
  208818. return self;
  208819. }
  208820. - (void) dealloc
  208821. {
  208822. [super dealloc];
  208823. }
  208824. - (void) menuItemInvoked: (id) menu
  208825. {
  208826. NSMenuItem* item = (NSMenuItem*) menu;
  208827. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208828. {
  208829. // 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
  208830. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208831. // into the focused component and let it trigger the menu item indirectly.
  208832. NSEvent* e = [NSApp currentEvent];
  208833. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208834. {
  208835. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208836. {
  208837. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208838. if (peer != 0)
  208839. {
  208840. if ([e type] == NSKeyDown)
  208841. peer->redirectKeyDown (e);
  208842. else
  208843. peer->redirectKeyUp (e);
  208844. return;
  208845. }
  208846. }
  208847. }
  208848. NSArray* info = (NSArray*) [item representedObject];
  208849. owner->invoke ((int) [item tag],
  208850. (ApplicationCommandManager*) (pointer_sized_int)
  208851. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208852. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208853. }
  208854. }
  208855. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208856. {
  208857. if (JuceMainMenuHandler::instance != 0)
  208858. JuceMainMenuHandler::instance->updateMenus();
  208859. }
  208860. @end
  208861. BEGIN_JUCE_NAMESPACE
  208862. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208863. const PopupMenu* extraItems)
  208864. {
  208865. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208866. {
  208867. PopupMenu::MenuItemIterator iter (*extraItems);
  208868. while (iter.next())
  208869. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208870. [menu addItem: [NSMenuItem separatorItem]];
  208871. }
  208872. NSMenuItem* item;
  208873. // Services...
  208874. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208875. action: nil keyEquivalent: @""];
  208876. [menu addItem: item];
  208877. [item release];
  208878. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208879. [menu setSubmenu: servicesMenu forItem: item];
  208880. [NSApp setServicesMenu: servicesMenu];
  208881. [servicesMenu release];
  208882. [menu addItem: [NSMenuItem separatorItem]];
  208883. // Hide + Show stuff...
  208884. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208885. action: @selector (hide:) keyEquivalent: @"h"];
  208886. [item setTarget: NSApp];
  208887. [menu addItem: item];
  208888. [item release];
  208889. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208890. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208891. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208892. [item setTarget: NSApp];
  208893. [menu addItem: item];
  208894. [item release];
  208895. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208896. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208897. [item setTarget: NSApp];
  208898. [menu addItem: item];
  208899. [item release];
  208900. [menu addItem: [NSMenuItem separatorItem]];
  208901. // Quit item....
  208902. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208903. action: @selector (terminate:) keyEquivalent: @"q"];
  208904. [item setTarget: NSApp];
  208905. [menu addItem: item];
  208906. [item release];
  208907. return menu;
  208908. }
  208909. // Since our app has no NIB, this initialises a standard app menu...
  208910. static void rebuildMainMenu (const PopupMenu* extraItems)
  208911. {
  208912. // this can't be used in a plugin!
  208913. jassert (JUCEApplication::getInstance() != 0);
  208914. if (JUCEApplication::getInstance() != 0)
  208915. {
  208916. const ScopedAutoReleasePool pool;
  208917. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208918. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208919. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208920. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208921. [mainMenu setSubmenu: appMenu forItem: item];
  208922. [NSApp setMainMenu: mainMenu];
  208923. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208924. [appMenu release];
  208925. [mainMenu release];
  208926. }
  208927. }
  208928. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208929. const PopupMenu* extraAppleMenuItems)
  208930. {
  208931. if (getMacMainMenu() != newMenuBarModel)
  208932. {
  208933. const ScopedAutoReleasePool pool;
  208934. if (newMenuBarModel == 0)
  208935. {
  208936. delete JuceMainMenuHandler::instance;
  208937. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208938. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208939. extraAppleMenuItems = 0;
  208940. }
  208941. else
  208942. {
  208943. if (JuceMainMenuHandler::instance == 0)
  208944. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208945. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208946. }
  208947. }
  208948. rebuildMainMenu (extraAppleMenuItems);
  208949. if (newMenuBarModel != 0)
  208950. newMenuBarModel->menuItemsChanged();
  208951. }
  208952. MenuBarModel* MenuBarModel::getMacMainMenu()
  208953. {
  208954. return JuceMainMenuHandler::instance != 0
  208955. ? JuceMainMenuHandler::instance->currentModel : 0;
  208956. }
  208957. void initialiseMainMenu()
  208958. {
  208959. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208960. rebuildMainMenu (0);
  208961. }
  208962. #endif
  208963. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208964. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208965. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208966. // compiled on its own).
  208967. #if JUCE_INCLUDED_FILE
  208968. #if JUCE_MAC
  208969. END_JUCE_NAMESPACE
  208970. using namespace JUCE_NAMESPACE;
  208971. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208972. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208973. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208974. #else
  208975. @interface JuceFileChooserDelegate : NSObject
  208976. #endif
  208977. {
  208978. StringArray* filters;
  208979. }
  208980. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208981. - (void) dealloc;
  208982. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208983. @end
  208984. @implementation JuceFileChooserDelegate
  208985. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208986. {
  208987. [super init];
  208988. filters = filters_;
  208989. return self;
  208990. }
  208991. - (void) dealloc
  208992. {
  208993. delete filters;
  208994. [super dealloc];
  208995. }
  208996. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208997. {
  208998. const File f (nsStringToJuce (filename));
  208999. for (int i = filters->size(); --i >= 0;)
  209000. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  209001. return true;
  209002. return f.isDirectory();
  209003. }
  209004. @end
  209005. BEGIN_JUCE_NAMESPACE
  209006. void FileChooser::showPlatformDialog (Array<File>& results,
  209007. const String& title,
  209008. const File& currentFileOrDirectory,
  209009. const String& filter,
  209010. bool selectsDirectory,
  209011. bool selectsFiles,
  209012. bool isSaveDialogue,
  209013. bool warnAboutOverwritingExistingFiles,
  209014. bool selectMultipleFiles,
  209015. FilePreviewComponent* extraInfoComponent)
  209016. {
  209017. const ScopedAutoReleasePool pool;
  209018. StringArray* filters = new StringArray();
  209019. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  209020. filters->trim();
  209021. filters->removeEmptyStrings();
  209022. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209023. [delegate autorelease];
  209024. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209025. : [NSOpenPanel openPanel];
  209026. [panel setTitle: juceStringToNS (title)];
  209027. if (! isSaveDialogue)
  209028. {
  209029. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209030. [openPanel setCanChooseDirectories: selectsDirectory];
  209031. [openPanel setCanChooseFiles: selectsFiles];
  209032. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209033. }
  209034. [panel setDelegate: delegate];
  209035. if (isSaveDialogue || selectsDirectory)
  209036. [panel setCanCreateDirectories: YES];
  209037. String directory, filename;
  209038. if (currentFileOrDirectory.isDirectory())
  209039. {
  209040. directory = currentFileOrDirectory.getFullPathName();
  209041. }
  209042. else
  209043. {
  209044. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209045. filename = currentFileOrDirectory.getFileName();
  209046. }
  209047. if ([panel runModalForDirectory: juceStringToNS (directory)
  209048. file: juceStringToNS (filename)]
  209049. == NSOKButton)
  209050. {
  209051. if (isSaveDialogue)
  209052. {
  209053. results.add (File (nsStringToJuce ([panel filename])));
  209054. }
  209055. else
  209056. {
  209057. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209058. NSArray* urls = [openPanel filenames];
  209059. for (unsigned int i = 0; i < [urls count]; ++i)
  209060. {
  209061. NSString* f = [urls objectAtIndex: i];
  209062. results.add (File (nsStringToJuce (f)));
  209063. }
  209064. }
  209065. }
  209066. [panel setDelegate: nil];
  209067. }
  209068. #else
  209069. void FileChooser::showPlatformDialog (Array<File>& results,
  209070. const String& title,
  209071. const File& currentFileOrDirectory,
  209072. const String& filter,
  209073. bool selectsDirectory,
  209074. bool selectsFiles,
  209075. bool isSaveDialogue,
  209076. bool warnAboutOverwritingExistingFiles,
  209077. bool selectMultipleFiles,
  209078. FilePreviewComponent* extraInfoComponent)
  209079. {
  209080. const ScopedAutoReleasePool pool;
  209081. jassertfalse //xxx to do
  209082. }
  209083. #endif
  209084. #endif
  209085. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209086. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209087. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209088. // compiled on its own).
  209089. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209090. END_JUCE_NAMESPACE
  209091. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209092. @interface NonInterceptingQTMovieView : QTMovieView
  209093. {
  209094. }
  209095. - (id) initWithFrame: (NSRect) frame;
  209096. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209097. - (NSView*) hitTest: (NSPoint) p;
  209098. @end
  209099. @implementation NonInterceptingQTMovieView
  209100. - (id) initWithFrame: (NSRect) frame
  209101. {
  209102. self = [super initWithFrame: frame];
  209103. [self setNextResponder: [self superview]];
  209104. return self;
  209105. }
  209106. - (void) dealloc
  209107. {
  209108. [super dealloc];
  209109. }
  209110. - (NSView*) hitTest: (NSPoint) point
  209111. {
  209112. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209113. }
  209114. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209115. {
  209116. return YES;
  209117. }
  209118. @end
  209119. BEGIN_JUCE_NAMESPACE
  209120. #define theMovie (static_cast <QTMovie*> (movie))
  209121. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209122. : movie (0)
  209123. {
  209124. setOpaque (true);
  209125. setVisible (true);
  209126. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209127. setView (view);
  209128. [view release];
  209129. }
  209130. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209131. {
  209132. closeMovie();
  209133. setView (0);
  209134. }
  209135. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209136. {
  209137. return true;
  209138. }
  209139. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209140. {
  209141. // unfortunately, QTMovie objects can only be created on the main thread..
  209142. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209143. QTMovie* movie = 0;
  209144. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209145. if (fin != 0)
  209146. {
  209147. movieFile = fin->getFile();
  209148. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209149. error: nil];
  209150. }
  209151. else
  209152. {
  209153. MemoryBlock temp;
  209154. movieStream->readIntoMemoryBlock (temp);
  209155. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209156. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209157. {
  209158. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209159. length: temp.getSize()]
  209160. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209161. MIMEType: @""]
  209162. error: nil];
  209163. if (movie != 0)
  209164. break;
  209165. }
  209166. }
  209167. return movie;
  209168. }
  209169. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209170. const bool isControllerVisible_)
  209171. {
  209172. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209173. }
  209174. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209175. const bool controllerVisible_)
  209176. {
  209177. closeMovie();
  209178. if (getPeer() == 0)
  209179. {
  209180. // To open a movie, this component must be visible inside a functioning window, so that
  209181. // the QT control can be assigned to the window.
  209182. jassertfalse
  209183. return false;
  209184. }
  209185. movie = openMovieFromStream (movieStream, movieFile);
  209186. [theMovie retain];
  209187. QTMovieView* view = (QTMovieView*) getView();
  209188. [view setMovie: theMovie];
  209189. [view setControllerVisible: controllerVisible_];
  209190. setLooping (looping);
  209191. return movie != nil;
  209192. }
  209193. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209194. const bool isControllerVisible_)
  209195. {
  209196. // unfortunately, QTMovie objects can only be created on the main thread..
  209197. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209198. closeMovie();
  209199. if (getPeer() == 0)
  209200. {
  209201. // To open a movie, this component must be visible inside a functioning window, so that
  209202. // the QT control can be assigned to the window.
  209203. jassertfalse
  209204. return false;
  209205. }
  209206. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209207. NSError* err;
  209208. if ([QTMovie canInitWithURL: url])
  209209. movie = [QTMovie movieWithURL: url error: &err];
  209210. [theMovie retain];
  209211. QTMovieView* view = (QTMovieView*) getView();
  209212. [view setMovie: theMovie];
  209213. [view setControllerVisible: controllerVisible];
  209214. setLooping (looping);
  209215. return movie != nil;
  209216. }
  209217. void QuickTimeMovieComponent::closeMovie()
  209218. {
  209219. stop();
  209220. QTMovieView* view = (QTMovieView*) getView();
  209221. [view setMovie: nil];
  209222. [theMovie release];
  209223. movie = 0;
  209224. movieFile = File::nonexistent;
  209225. }
  209226. bool QuickTimeMovieComponent::isMovieOpen() const
  209227. {
  209228. return movie != nil;
  209229. }
  209230. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209231. {
  209232. return movieFile;
  209233. }
  209234. void QuickTimeMovieComponent::play()
  209235. {
  209236. [theMovie play];
  209237. }
  209238. void QuickTimeMovieComponent::stop()
  209239. {
  209240. [theMovie stop];
  209241. }
  209242. bool QuickTimeMovieComponent::isPlaying() const
  209243. {
  209244. return movie != 0 && [theMovie rate] != 0;
  209245. }
  209246. void QuickTimeMovieComponent::setPosition (const double seconds)
  209247. {
  209248. if (movie != 0)
  209249. {
  209250. QTTime t;
  209251. t.timeValue = (uint64) (100000.0 * seconds);
  209252. t.timeScale = 100000;
  209253. t.flags = 0;
  209254. [theMovie setCurrentTime: t];
  209255. }
  209256. }
  209257. double QuickTimeMovieComponent::getPosition() const
  209258. {
  209259. if (movie == 0)
  209260. return 0.0;
  209261. QTTime t = [theMovie currentTime];
  209262. return t.timeValue / (double) t.timeScale;
  209263. }
  209264. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209265. {
  209266. [theMovie setRate: newSpeed];
  209267. }
  209268. double QuickTimeMovieComponent::getMovieDuration() const
  209269. {
  209270. if (movie == 0)
  209271. return 0.0;
  209272. QTTime t = [theMovie duration];
  209273. return t.timeValue / (double) t.timeScale;
  209274. }
  209275. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209276. {
  209277. looping = shouldLoop;
  209278. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209279. forKey: QTMovieLoopsAttribute];
  209280. }
  209281. bool QuickTimeMovieComponent::isLooping() const
  209282. {
  209283. return looping;
  209284. }
  209285. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209286. {
  209287. [theMovie setVolume: newVolume];
  209288. }
  209289. float QuickTimeMovieComponent::getMovieVolume() const
  209290. {
  209291. return movie != 0 ? [theMovie volume] : 0.0f;
  209292. }
  209293. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209294. {
  209295. width = 0;
  209296. height = 0;
  209297. if (movie != 0)
  209298. {
  209299. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209300. width = (int) s.width;
  209301. height = (int) s.height;
  209302. }
  209303. }
  209304. void QuickTimeMovieComponent::paint (Graphics& g)
  209305. {
  209306. if (movie == 0)
  209307. g.fillAll (Colours::black);
  209308. }
  209309. bool QuickTimeMovieComponent::isControllerVisible() const
  209310. {
  209311. return controllerVisible;
  209312. }
  209313. void QuickTimeMovieComponent::goToStart()
  209314. {
  209315. setPosition (0.0);
  209316. }
  209317. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209318. const RectanglePlacement& placement)
  209319. {
  209320. int normalWidth, normalHeight;
  209321. getMovieNormalSize (normalWidth, normalHeight);
  209322. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209323. {
  209324. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209325. placement.applyTo (x, y, w, h,
  209326. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209327. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209328. if (w > 0 && h > 0)
  209329. {
  209330. setBounds (roundToInt (x), roundToInt (y),
  209331. roundToInt (w), roundToInt (h));
  209332. }
  209333. }
  209334. else
  209335. {
  209336. setBounds (spaceToFitWithin);
  209337. }
  209338. }
  209339. #if ! (JUCE_MAC && JUCE_64BIT)
  209340. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209341. {
  209342. if (movieStream == 0)
  209343. return false;
  209344. File file;
  209345. QTMovie* movie = openMovieFromStream (movieStream, file);
  209346. if (movie != nil)
  209347. result = [movie quickTimeMovie];
  209348. return movie != nil;
  209349. }
  209350. #endif
  209351. #endif
  209352. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209353. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209354. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209355. // compiled on its own).
  209356. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209357. const int kilobytesPerSecond1x = 176;
  209358. END_JUCE_NAMESPACE
  209359. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209360. @interface OpenDiskDevice : NSObject
  209361. {
  209362. @public
  209363. DRDevice* device;
  209364. NSMutableArray* tracks;
  209365. bool underrunProtection;
  209366. }
  209367. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209368. - (void) dealloc;
  209369. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209370. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209371. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209372. @end
  209373. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209374. @interface AudioTrackProducer : NSObject
  209375. {
  209376. JUCE_NAMESPACE::AudioSource* source;
  209377. int readPosition, lengthInFrames;
  209378. }
  209379. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209380. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209381. - (void) dealloc;
  209382. - (void) setupTrackProperties: (DRTrack*) track;
  209383. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209384. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209385. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209386. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209387. toMedia:(NSDictionary*)mediaInfo;
  209388. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209389. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209390. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209391. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209392. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209393. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209394. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209395. ioFlags:(uint32_t*)flags;
  209396. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209397. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209398. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209399. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209400. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209401. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209402. ioFlags:(uint32_t*)flags;
  209403. @end
  209404. @implementation OpenDiskDevice
  209405. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209406. {
  209407. [super init];
  209408. device = device_;
  209409. tracks = [[NSMutableArray alloc] init];
  209410. underrunProtection = true;
  209411. return self;
  209412. }
  209413. - (void) dealloc
  209414. {
  209415. [tracks release];
  209416. [super dealloc];
  209417. }
  209418. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209419. {
  209420. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209421. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209422. [p setupTrackProperties: t];
  209423. [tracks addObject: t];
  209424. [t release];
  209425. [p release];
  209426. }
  209427. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209428. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209429. {
  209430. DRBurn* burn = [DRBurn burnForDevice: device];
  209431. if (! [device acquireExclusiveAccess])
  209432. {
  209433. *error = "Couldn't open or write to the CD device";
  209434. return;
  209435. }
  209436. [device acquireMediaReservation];
  209437. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209438. [d autorelease];
  209439. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209440. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209441. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209442. if (burnSpeed > 0)
  209443. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209444. if (! underrunProtection)
  209445. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209446. [burn setProperties: d];
  209447. [burn writeLayout: tracks];
  209448. for (;;)
  209449. {
  209450. JUCE_NAMESPACE::Thread::sleep (300);
  209451. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209452. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209453. {
  209454. [burn abort];
  209455. *error = "User cancelled the write operation";
  209456. break;
  209457. }
  209458. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209459. {
  209460. *error = "Write operation failed";
  209461. break;
  209462. }
  209463. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209464. {
  209465. break;
  209466. }
  209467. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209468. objectForKey: DRErrorStatusErrorStringKey];
  209469. if ([err length] > 0)
  209470. {
  209471. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209472. break;
  209473. }
  209474. }
  209475. [device releaseMediaReservation];
  209476. [device releaseExclusiveAccess];
  209477. }
  209478. @end
  209479. @implementation AudioTrackProducer
  209480. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209481. {
  209482. lengthInFrames = lengthInFrames_;
  209483. readPosition = 0;
  209484. return self;
  209485. }
  209486. - (void) setupTrackProperties: (DRTrack*) track
  209487. {
  209488. NSMutableDictionary* p = [[track properties] mutableCopy];
  209489. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209490. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209491. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209492. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209493. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209494. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209495. [track setProperties: p];
  209496. [p release];
  209497. }
  209498. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209499. {
  209500. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209501. if (s != nil)
  209502. s->source = source_;
  209503. return s;
  209504. }
  209505. - (void) dealloc
  209506. {
  209507. if (source != 0)
  209508. {
  209509. source->releaseResources();
  209510. delete source;
  209511. }
  209512. [super dealloc];
  209513. }
  209514. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209515. {
  209516. }
  209517. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209518. {
  209519. return true;
  209520. }
  209521. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209522. {
  209523. return lengthInFrames;
  209524. }
  209525. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209526. toMedia: (NSDictionary*) mediaInfo
  209527. {
  209528. if (source != 0)
  209529. source->prepareToPlay (44100 / 75, 44100);
  209530. readPosition = 0;
  209531. return true;
  209532. }
  209533. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209534. {
  209535. if (source != 0)
  209536. source->prepareToPlay (44100 / 75, 44100);
  209537. return true;
  209538. }
  209539. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209540. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209541. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209542. {
  209543. if (source != 0)
  209544. {
  209545. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209546. if (numSamples > 0)
  209547. {
  209548. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209549. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209550. info.buffer = &tempBuffer;
  209551. info.startSample = 0;
  209552. info.numSamples = numSamples;
  209553. source->getNextAudioBlock (info);
  209554. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209555. buffer, numSamples, 4);
  209556. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209557. buffer + 2, numSamples, 4);
  209558. readPosition += numSamples;
  209559. }
  209560. return numSamples * 4;
  209561. }
  209562. return 0;
  209563. }
  209564. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209565. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209566. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209567. ioFlags: (uint32_t*) flags
  209568. {
  209569. zeromem (buffer, bufferLength);
  209570. return bufferLength;
  209571. }
  209572. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209573. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209574. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209575. {
  209576. return true;
  209577. }
  209578. @end
  209579. BEGIN_JUCE_NAMESPACE
  209580. class AudioCDBurner::Pimpl : public Timer
  209581. {
  209582. public:
  209583. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209584. : device (0), owner (owner_)
  209585. {
  209586. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209587. if (dev != 0)
  209588. {
  209589. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209590. lastState = getDiskState();
  209591. startTimer (1000);
  209592. }
  209593. }
  209594. ~Pimpl()
  209595. {
  209596. stopTimer();
  209597. [device release];
  209598. }
  209599. void timerCallback()
  209600. {
  209601. const DiskState state = getDiskState();
  209602. if (state != lastState)
  209603. {
  209604. lastState = state;
  209605. owner.sendChangeMessage (&owner);
  209606. }
  209607. }
  209608. DiskState getDiskState() const
  209609. {
  209610. if ([device->device isValid])
  209611. {
  209612. NSDictionary* status = [device->device status];
  209613. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209614. if ([state isEqualTo: DRDeviceMediaStateNone])
  209615. {
  209616. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209617. return trayOpen;
  209618. return noDisc;
  209619. }
  209620. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209621. {
  209622. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209623. return writableDiskPresent;
  209624. else
  209625. return readOnlyDiskPresent;
  209626. }
  209627. }
  209628. return unknown;
  209629. }
  209630. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209631. const Array<int> getAvailableWriteSpeeds() const
  209632. {
  209633. Array<int> results;
  209634. if ([device->device isValid])
  209635. {
  209636. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209637. for (unsigned int i = 0; i < [speeds count]; ++i)
  209638. {
  209639. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209640. results.add (kbPerSec / kilobytesPerSecond1x);
  209641. }
  209642. }
  209643. return results;
  209644. }
  209645. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209646. {
  209647. if ([device->device isValid])
  209648. {
  209649. device->underrunProtection = shouldBeEnabled;
  209650. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209651. }
  209652. return false;
  209653. }
  209654. int getNumAvailableAudioBlocks() const
  209655. {
  209656. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209657. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209658. }
  209659. OpenDiskDevice* device;
  209660. private:
  209661. DiskState lastState;
  209662. AudioCDBurner& owner;
  209663. };
  209664. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209665. {
  209666. pimpl = new Pimpl (*this, deviceIndex);
  209667. }
  209668. AudioCDBurner::~AudioCDBurner()
  209669. {
  209670. }
  209671. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209672. {
  209673. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209674. if (b->pimpl->device == 0)
  209675. b = 0;
  209676. return b.release();
  209677. }
  209678. static NSArray* findDiskBurnerDevices()
  209679. {
  209680. NSMutableArray* results = [NSMutableArray array];
  209681. NSArray* devs = [DRDevice devices];
  209682. if (devs != 0)
  209683. {
  209684. int num = [devs count];
  209685. int i;
  209686. for (i = 0; i < num; ++i)
  209687. {
  209688. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209689. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209690. if (name != nil)
  209691. [results addObject: name];
  209692. }
  209693. }
  209694. return results;
  209695. }
  209696. const StringArray AudioCDBurner::findAvailableDevices()
  209697. {
  209698. NSArray* names = findDiskBurnerDevices();
  209699. StringArray s;
  209700. for (unsigned int i = 0; i < [names count]; ++i)
  209701. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209702. return s;
  209703. }
  209704. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209705. {
  209706. return pimpl->getDiskState();
  209707. }
  209708. bool AudioCDBurner::isDiskPresent() const
  209709. {
  209710. return getDiskState() == writableDiskPresent;
  209711. }
  209712. bool AudioCDBurner::openTray()
  209713. {
  209714. return pimpl->openTray();
  209715. }
  209716. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209717. {
  209718. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209719. DiskState oldState = getDiskState();
  209720. DiskState newState = oldState;
  209721. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209722. {
  209723. newState = getDiskState();
  209724. Thread::sleep (100);
  209725. }
  209726. return newState;
  209727. }
  209728. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209729. {
  209730. return pimpl->getAvailableWriteSpeeds();
  209731. }
  209732. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209733. {
  209734. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209735. }
  209736. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209737. {
  209738. return pimpl->getNumAvailableAudioBlocks();
  209739. }
  209740. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209741. {
  209742. if ([pimpl->device->device isValid])
  209743. {
  209744. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209745. return true;
  209746. }
  209747. return false;
  209748. }
  209749. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209750. bool ejectDiscAfterwards,
  209751. bool performFakeBurnForTesting,
  209752. int writeSpeed)
  209753. {
  209754. String error ("Couldn't open or write to the CD device");
  209755. if ([pimpl->device->device isValid])
  209756. {
  209757. error = String::empty;
  209758. [pimpl->device burn: listener
  209759. errorString: &error
  209760. ejectAfterwards: ejectDiscAfterwards
  209761. isFake: performFakeBurnForTesting
  209762. speed: writeSpeed];
  209763. }
  209764. return error;
  209765. }
  209766. #endif
  209767. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209768. void AudioCDReader::ejectDisk()
  209769. {
  209770. const ScopedAutoReleasePool p;
  209771. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209772. }
  209773. #endif
  209774. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209775. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209776. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209777. // compiled on its own).
  209778. #if JUCE_INCLUDED_FILE
  209779. class AppDelegateRedirector
  209780. {
  209781. public:
  209782. AppDelegateRedirector()
  209783. {
  209784. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209785. runLoop = CFRunLoopGetMain();
  209786. #else
  209787. runLoop = CFRunLoopGetCurrent();
  209788. #endif
  209789. CFRunLoopSourceContext sourceContext;
  209790. zerostruct (sourceContext);
  209791. sourceContext.info = this;
  209792. sourceContext.perform = runLoopSourceCallback;
  209793. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209794. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209795. }
  209796. virtual ~AppDelegateRedirector()
  209797. {
  209798. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209799. CFRunLoopSourceInvalidate (runLoopSource);
  209800. CFRelease (runLoopSource);
  209801. while (messages.size() > 0)
  209802. delete static_cast <Message*> (messages.remove(0));
  209803. }
  209804. virtual NSApplicationTerminateReply shouldTerminate()
  209805. {
  209806. if (JUCEApplication::getInstance() != 0)
  209807. {
  209808. JUCEApplication::getInstance()->systemRequestedQuit();
  209809. return NSTerminateCancel;
  209810. }
  209811. return NSTerminateNow;
  209812. }
  209813. virtual BOOL openFile (const NSString* filename)
  209814. {
  209815. if (JUCEApplication::getInstance() != 0)
  209816. {
  209817. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209818. return YES;
  209819. }
  209820. return NO;
  209821. }
  209822. virtual void openFiles (NSArray* filenames)
  209823. {
  209824. StringArray files;
  209825. for (unsigned int i = 0; i < [filenames count]; ++i)
  209826. {
  209827. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209828. if (filename.containsChar (' '))
  209829. filename = filename.quoted('"');
  209830. files.add (filename);
  209831. }
  209832. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209833. {
  209834. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209835. }
  209836. }
  209837. virtual void focusChanged()
  209838. {
  209839. juce_HandleProcessFocusChange();
  209840. }
  209841. struct CallbackMessagePayload
  209842. {
  209843. MessageCallbackFunction* function;
  209844. void* parameter;
  209845. void* volatile result;
  209846. bool volatile hasBeenExecuted;
  209847. };
  209848. virtual void performCallback (CallbackMessagePayload* pl)
  209849. {
  209850. pl->result = (*pl->function) (pl->parameter);
  209851. pl->hasBeenExecuted = true;
  209852. }
  209853. virtual void deleteSelf()
  209854. {
  209855. delete this;
  209856. }
  209857. void postMessage (void* m)
  209858. {
  209859. messages.add (m);
  209860. CFRunLoopSourceSignal (runLoopSource);
  209861. CFRunLoopWakeUp (runLoop);
  209862. }
  209863. private:
  209864. CFRunLoopRef runLoop;
  209865. CFRunLoopSourceRef runLoopSource;
  209866. Array <void*, CriticalSection> messages;
  209867. void runLoopCallback()
  209868. {
  209869. int numDispatched = 0;
  209870. do
  209871. {
  209872. void* const nextMessage = messages.remove (0);
  209873. if (nextMessage == 0)
  209874. return;
  209875. const ScopedAutoReleasePool pool;
  209876. MessageManager::getInstance()->deliverMessage (nextMessage);
  209877. } while (++numDispatched <= 4);
  209878. CFRunLoopSourceSignal (runLoopSource);
  209879. CFRunLoopWakeUp (runLoop);
  209880. }
  209881. static void runLoopSourceCallback (void* info)
  209882. {
  209883. static_cast <AppDelegateRedirector*> (info)->runLoopCallback();
  209884. }
  209885. };
  209886. END_JUCE_NAMESPACE
  209887. using namespace JUCE_NAMESPACE;
  209888. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209889. @interface JuceAppDelegate : NSObject
  209890. {
  209891. @private
  209892. id oldDelegate;
  209893. @public
  209894. AppDelegateRedirector* redirector;
  209895. }
  209896. - (JuceAppDelegate*) init;
  209897. - (void) dealloc;
  209898. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209899. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209900. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209901. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209902. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209903. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209904. - (void) performCallback: (id) info;
  209905. - (void) dummyMethod;
  209906. @end
  209907. @implementation JuceAppDelegate
  209908. - (JuceAppDelegate*) init
  209909. {
  209910. [super init];
  209911. redirector = new AppDelegateRedirector();
  209912. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209913. if (JUCEApplication::getInstance() != 0)
  209914. {
  209915. oldDelegate = [NSApp delegate];
  209916. [NSApp setDelegate: self];
  209917. }
  209918. else
  209919. {
  209920. oldDelegate = 0;
  209921. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209922. name: NSApplicationDidResignActiveNotification object: NSApp];
  209923. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209924. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209925. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209926. name: NSApplicationWillUnhideNotification object: NSApp];
  209927. }
  209928. return self;
  209929. }
  209930. - (void) dealloc
  209931. {
  209932. if (oldDelegate != 0)
  209933. [NSApp setDelegate: oldDelegate];
  209934. redirector->deleteSelf();
  209935. [super dealloc];
  209936. }
  209937. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209938. {
  209939. return redirector->shouldTerminate();
  209940. }
  209941. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209942. {
  209943. return redirector->openFile (filename);
  209944. }
  209945. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209946. {
  209947. return redirector->openFiles (filenames);
  209948. }
  209949. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209950. {
  209951. redirector->focusChanged();
  209952. }
  209953. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209954. {
  209955. redirector->focusChanged();
  209956. }
  209957. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209958. {
  209959. redirector->focusChanged();
  209960. }
  209961. - (void) performCallback: (id) info
  209962. {
  209963. if ([info isKindOfClass: [NSData class]])
  209964. {
  209965. AppDelegateRedirector::CallbackMessagePayload* pl
  209966. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209967. if (pl != 0)
  209968. redirector->performCallback (pl);
  209969. }
  209970. else
  209971. {
  209972. jassertfalse // should never get here!
  209973. }
  209974. }
  209975. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209976. @end
  209977. BEGIN_JUCE_NAMESPACE
  209978. static JuceAppDelegate* juceAppDelegate = 0;
  209979. void MessageManager::runDispatchLoop()
  209980. {
  209981. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209982. {
  209983. const ScopedAutoReleasePool pool;
  209984. // must only be called by the message thread!
  209985. jassert (isThisTheMessageThread());
  209986. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209987. @try
  209988. {
  209989. [NSApp run];
  209990. }
  209991. @catch (NSException* e)
  209992. {
  209993. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209994. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209995. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209996. }
  209997. @finally
  209998. {
  209999. }
  210000. #else
  210001. [NSApp run];
  210002. #endif
  210003. }
  210004. }
  210005. void MessageManager::stopDispatchLoop()
  210006. {
  210007. quitMessagePosted = true;
  210008. [NSApp stop: nil];
  210009. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210010. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210011. }
  210012. static bool isEventBlockedByModalComps (NSEvent* e)
  210013. {
  210014. if (Component::getNumCurrentlyModalComponents() == 0)
  210015. return false;
  210016. NSWindow* const w = [e window];
  210017. if (w == 0 || [w worksWhenModal])
  210018. return false;
  210019. bool isKey = false, isInputAttempt = false;
  210020. switch ([e type])
  210021. {
  210022. case NSKeyDown:
  210023. case NSKeyUp:
  210024. isKey = isInputAttempt = true;
  210025. break;
  210026. case NSLeftMouseDown:
  210027. case NSRightMouseDown:
  210028. case NSOtherMouseDown:
  210029. isInputAttempt = true;
  210030. break;
  210031. case NSLeftMouseDragged:
  210032. case NSRightMouseDragged:
  210033. case NSLeftMouseUp:
  210034. case NSRightMouseUp:
  210035. case NSOtherMouseUp:
  210036. case NSOtherMouseDragged:
  210037. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210038. return false;
  210039. break;
  210040. case NSMouseMoved:
  210041. case NSMouseEntered:
  210042. case NSMouseExited:
  210043. case NSCursorUpdate:
  210044. case NSScrollWheel:
  210045. case NSTabletPoint:
  210046. case NSTabletProximity:
  210047. break;
  210048. default:
  210049. return false;
  210050. }
  210051. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210052. {
  210053. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210054. NSView* const compView = (NSView*) peer->getNativeHandle();
  210055. if ([compView window] == w)
  210056. {
  210057. if (isKey)
  210058. {
  210059. if (compView == [w firstResponder])
  210060. return false;
  210061. }
  210062. else
  210063. {
  210064. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210065. [compView bounds]))
  210066. return false;
  210067. }
  210068. }
  210069. }
  210070. if (isInputAttempt)
  210071. {
  210072. if (! [NSApp isActive])
  210073. [NSApp activateIgnoringOtherApps: YES];
  210074. Component* const modal = Component::getCurrentlyModalComponent (0);
  210075. if (modal != 0)
  210076. modal->inputAttemptWhenModal();
  210077. }
  210078. return true;
  210079. }
  210080. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210081. {
  210082. const ScopedAutoReleasePool pool;
  210083. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210084. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210085. while (! quitMessagePosted)
  210086. {
  210087. const ScopedAutoReleasePool pool2;
  210088. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210089. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210090. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210091. inMode: NSDefaultRunLoopMode
  210092. dequeue: YES];
  210093. if (e != 0 && ! isEventBlockedByModalComps (e))
  210094. [NSApp sendEvent: e];
  210095. if (Time::getMillisecondCounter() >= endTime)
  210096. break;
  210097. }
  210098. return ! quitMessagePosted;
  210099. }
  210100. void MessageManager::doPlatformSpecificInitialisation()
  210101. {
  210102. if (juceAppDelegate == 0)
  210103. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210104. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210105. // correctly (needed prior to 10.5)
  210106. if (! [NSThread isMultiThreaded])
  210107. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210108. toTarget: juceAppDelegate
  210109. withObject: nil];
  210110. initialiseMainMenu();
  210111. }
  210112. void MessageManager::doPlatformSpecificShutdown()
  210113. {
  210114. if (juceAppDelegate != 0)
  210115. {
  210116. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210117. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210118. [juceAppDelegate release];
  210119. juceAppDelegate = 0;
  210120. }
  210121. }
  210122. bool juce_postMessageToSystemQueue (void* message)
  210123. {
  210124. juceAppDelegate->redirector->postMessage (message);
  210125. return true;
  210126. }
  210127. void MessageManager::broadcastMessage (const String& value) throw()
  210128. {
  210129. }
  210130. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210131. void* data)
  210132. {
  210133. if (isThisTheMessageThread())
  210134. {
  210135. return (*callback) (data);
  210136. }
  210137. else
  210138. {
  210139. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210140. // deadlock because the message manager is blocked from running, so can never
  210141. // call your function..
  210142. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210143. const ScopedAutoReleasePool pool;
  210144. AppDelegateRedirector::CallbackMessagePayload cmp;
  210145. cmp.function = callback;
  210146. cmp.parameter = data;
  210147. cmp.result = 0;
  210148. cmp.hasBeenExecuted = false;
  210149. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210150. withObject: [NSData dataWithBytesNoCopy: &cmp
  210151. length: sizeof (cmp)
  210152. freeWhenDone: NO]
  210153. waitUntilDone: YES];
  210154. return cmp.result;
  210155. }
  210156. }
  210157. #endif
  210158. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210159. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210160. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210161. // compiled on its own).
  210162. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210163. #if JUCE_MAC
  210164. END_JUCE_NAMESPACE
  210165. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210166. @interface DownloadClickDetector : NSObject
  210167. {
  210168. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210169. }
  210170. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210171. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210172. request: (NSURLRequest*) request
  210173. frame: (WebFrame*) frame
  210174. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210175. @end
  210176. @implementation DownloadClickDetector
  210177. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210178. {
  210179. [super init];
  210180. ownerComponent = ownerComponent_;
  210181. return self;
  210182. }
  210183. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210184. request: (NSURLRequest*) request
  210185. frame: (WebFrame*) frame
  210186. decisionListener: (id <WebPolicyDecisionListener>) listener
  210187. {
  210188. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210189. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210190. [listener use];
  210191. else
  210192. [listener ignore];
  210193. }
  210194. @end
  210195. BEGIN_JUCE_NAMESPACE
  210196. class WebBrowserComponentInternal : public NSViewComponent
  210197. {
  210198. public:
  210199. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210200. {
  210201. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210202. frameName: @""
  210203. groupName: @""];
  210204. setView (webView);
  210205. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210206. [webView setPolicyDelegate: clickListener];
  210207. }
  210208. ~WebBrowserComponentInternal()
  210209. {
  210210. [webView setPolicyDelegate: nil];
  210211. [clickListener release];
  210212. setView (0);
  210213. }
  210214. void goToURL (const String& url,
  210215. const StringArray* headers,
  210216. const MemoryBlock* postData)
  210217. {
  210218. NSMutableURLRequest* r
  210219. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210220. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210221. timeoutInterval: 30.0];
  210222. if (postData != 0 && postData->getSize() > 0)
  210223. {
  210224. [r setHTTPMethod: @"POST"];
  210225. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210226. length: postData->getSize()]];
  210227. }
  210228. if (headers != 0)
  210229. {
  210230. for (int i = 0; i < headers->size(); ++i)
  210231. {
  210232. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  210233. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  210234. [r setValue: juceStringToNS (headerValue)
  210235. forHTTPHeaderField: juceStringToNS (headerName)];
  210236. }
  210237. }
  210238. stop();
  210239. [[webView mainFrame] loadRequest: r];
  210240. }
  210241. void goBack()
  210242. {
  210243. [webView goBack];
  210244. }
  210245. void goForward()
  210246. {
  210247. [webView goForward];
  210248. }
  210249. void stop()
  210250. {
  210251. [webView stopLoading: nil];
  210252. }
  210253. void refresh()
  210254. {
  210255. [webView reload: nil];
  210256. }
  210257. private:
  210258. WebView* webView;
  210259. DownloadClickDetector* clickListener;
  210260. };
  210261. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210262. : browser (0),
  210263. blankPageShown (false),
  210264. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210265. {
  210266. setOpaque (true);
  210267. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210268. }
  210269. WebBrowserComponent::~WebBrowserComponent()
  210270. {
  210271. deleteAndZero (browser);
  210272. }
  210273. void WebBrowserComponent::goToURL (const String& url,
  210274. const StringArray* headers,
  210275. const MemoryBlock* postData)
  210276. {
  210277. lastURL = url;
  210278. lastHeaders.clear();
  210279. if (headers != 0)
  210280. lastHeaders = *headers;
  210281. lastPostData.setSize (0);
  210282. if (postData != 0)
  210283. lastPostData = *postData;
  210284. blankPageShown = false;
  210285. browser->goToURL (url, headers, postData);
  210286. }
  210287. void WebBrowserComponent::stop()
  210288. {
  210289. browser->stop();
  210290. }
  210291. void WebBrowserComponent::goBack()
  210292. {
  210293. lastURL = String::empty;
  210294. blankPageShown = false;
  210295. browser->goBack();
  210296. }
  210297. void WebBrowserComponent::goForward()
  210298. {
  210299. lastURL = String::empty;
  210300. browser->goForward();
  210301. }
  210302. void WebBrowserComponent::refresh()
  210303. {
  210304. browser->refresh();
  210305. }
  210306. void WebBrowserComponent::paint (Graphics& g)
  210307. {
  210308. }
  210309. void WebBrowserComponent::checkWindowAssociation()
  210310. {
  210311. if (isShowing())
  210312. {
  210313. if (blankPageShown)
  210314. goBack();
  210315. }
  210316. else
  210317. {
  210318. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210319. {
  210320. // when the component becomes invisible, some stuff like flash
  210321. // carries on playing audio, so we need to force it onto a blank
  210322. // page to avoid this, (and send it back when it's made visible again).
  210323. blankPageShown = true;
  210324. browser->goToURL ("about:blank", 0, 0);
  210325. }
  210326. }
  210327. }
  210328. void WebBrowserComponent::reloadLastURL()
  210329. {
  210330. if (lastURL.isNotEmpty())
  210331. {
  210332. goToURL (lastURL, &lastHeaders, &lastPostData);
  210333. lastURL = String::empty;
  210334. }
  210335. }
  210336. void WebBrowserComponent::parentHierarchyChanged()
  210337. {
  210338. checkWindowAssociation();
  210339. }
  210340. void WebBrowserComponent::resized()
  210341. {
  210342. browser->setSize (getWidth(), getHeight());
  210343. }
  210344. void WebBrowserComponent::visibilityChanged()
  210345. {
  210346. checkWindowAssociation();
  210347. }
  210348. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210349. {
  210350. return true;
  210351. }
  210352. #else
  210353. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210354. {
  210355. }
  210356. WebBrowserComponent::~WebBrowserComponent()
  210357. {
  210358. }
  210359. void WebBrowserComponent::goToURL (const String& url,
  210360. const StringArray* headers,
  210361. const MemoryBlock* postData)
  210362. {
  210363. }
  210364. void WebBrowserComponent::stop()
  210365. {
  210366. }
  210367. void WebBrowserComponent::goBack()
  210368. {
  210369. }
  210370. void WebBrowserComponent::goForward()
  210371. {
  210372. }
  210373. void WebBrowserComponent::refresh()
  210374. {
  210375. }
  210376. void WebBrowserComponent::paint (Graphics& g)
  210377. {
  210378. }
  210379. void WebBrowserComponent::checkWindowAssociation()
  210380. {
  210381. }
  210382. void WebBrowserComponent::reloadLastURL()
  210383. {
  210384. }
  210385. void WebBrowserComponent::parentHierarchyChanged()
  210386. {
  210387. }
  210388. void WebBrowserComponent::resized()
  210389. {
  210390. }
  210391. void WebBrowserComponent::visibilityChanged()
  210392. {
  210393. }
  210394. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210395. {
  210396. return true;
  210397. }
  210398. #endif
  210399. #endif
  210400. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210401. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210402. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210403. // compiled on its own).
  210404. #if JUCE_INCLUDED_FILE
  210405. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210406. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210407. #endif
  210408. #undef log
  210409. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210410. #define log(a) Logger::writeToLog (a)
  210411. #else
  210412. #define log(a)
  210413. #endif
  210414. #undef OK
  210415. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210416. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210417. {
  210418. if (err == noErr)
  210419. return true;
  210420. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210421. jassertfalse
  210422. return false;
  210423. }
  210424. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210425. #else
  210426. #define OK(a) (a == noErr)
  210427. #endif
  210428. class CoreAudioInternal : public Timer
  210429. {
  210430. public:
  210431. CoreAudioInternal (AudioDeviceID id)
  210432. : inputLatency (0),
  210433. outputLatency (0),
  210434. callback (0),
  210435. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210436. audioProcID (0),
  210437. #endif
  210438. inputDevice (0),
  210439. isSlaveDevice (false),
  210440. deviceID (id),
  210441. started (false),
  210442. sampleRate (0),
  210443. bufferSize (512),
  210444. numInputChans (0),
  210445. numOutputChans (0),
  210446. callbacksAllowed (true),
  210447. numInputChannelInfos (0),
  210448. numOutputChannelInfos (0)
  210449. {
  210450. jassert (deviceID != 0);
  210451. updateDetailsFromDevice();
  210452. AudioObjectPropertyAddress pa;
  210453. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210454. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210455. pa.mElement = kAudioObjectPropertyElementWildcard;
  210456. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210457. }
  210458. ~CoreAudioInternal()
  210459. {
  210460. AudioObjectPropertyAddress pa;
  210461. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210462. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210463. pa.mElement = kAudioObjectPropertyElementWildcard;
  210464. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210465. stop (false);
  210466. delete inputDevice;
  210467. }
  210468. void allocateTempBuffers()
  210469. {
  210470. const int tempBufSize = bufferSize + 4;
  210471. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210472. tempInputBuffers.calloc (numInputChans + 2);
  210473. tempOutputBuffers.calloc (numOutputChans + 2);
  210474. int i, count = 0;
  210475. for (i = 0; i < numInputChans; ++i)
  210476. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210477. for (i = 0; i < numOutputChans; ++i)
  210478. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210479. }
  210480. // returns the number of actual available channels
  210481. void fillInChannelInfo (const bool input)
  210482. {
  210483. int chanNum = 0;
  210484. UInt32 size;
  210485. AudioObjectPropertyAddress pa;
  210486. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210487. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210488. pa.mElement = kAudioObjectPropertyElementMaster;
  210489. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210490. {
  210491. HeapBlock <AudioBufferList> bufList;
  210492. bufList.calloc (size, 1);
  210493. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210494. {
  210495. const int numStreams = bufList->mNumberBuffers;
  210496. for (int i = 0; i < numStreams; ++i)
  210497. {
  210498. const AudioBuffer& b = bufList->mBuffers[i];
  210499. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210500. {
  210501. String name;
  210502. {
  210503. char channelName [256];
  210504. zerostruct (channelName);
  210505. UInt32 nameSize = sizeof (channelName);
  210506. UInt32 channelNum = chanNum + 1;
  210507. pa.mSelector = kAudioDevicePropertyChannelName;
  210508. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210509. name = String::fromUTF8 (channelName, nameSize);
  210510. }
  210511. if (input)
  210512. {
  210513. if (activeInputChans[chanNum])
  210514. {
  210515. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210516. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210517. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210518. ++numInputChannelInfos;
  210519. }
  210520. if (name.isEmpty())
  210521. name << "Input " << (chanNum + 1);
  210522. inChanNames.add (name);
  210523. }
  210524. else
  210525. {
  210526. if (activeOutputChans[chanNum])
  210527. {
  210528. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210529. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210530. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210531. ++numOutputChannelInfos;
  210532. }
  210533. if (name.isEmpty())
  210534. name << "Output " << (chanNum + 1);
  210535. outChanNames.add (name);
  210536. }
  210537. ++chanNum;
  210538. }
  210539. }
  210540. }
  210541. }
  210542. }
  210543. void updateDetailsFromDevice()
  210544. {
  210545. stopTimer();
  210546. if (deviceID == 0)
  210547. return;
  210548. const ScopedLock sl (callbackLock);
  210549. Float64 sr;
  210550. UInt32 size = sizeof (Float64);
  210551. AudioObjectPropertyAddress pa;
  210552. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210553. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210554. pa.mElement = kAudioObjectPropertyElementMaster;
  210555. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210556. sampleRate = sr;
  210557. UInt32 framesPerBuf;
  210558. size = sizeof (framesPerBuf);
  210559. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210560. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210561. {
  210562. bufferSize = framesPerBuf;
  210563. allocateTempBuffers();
  210564. }
  210565. bufferSizes.clear();
  210566. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210567. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210568. {
  210569. HeapBlock <AudioValueRange> ranges;
  210570. ranges.calloc (size, 1);
  210571. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210572. {
  210573. bufferSizes.add ((int) ranges[0].mMinimum);
  210574. for (int i = 32; i < 2048; i += 32)
  210575. {
  210576. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210577. {
  210578. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210579. {
  210580. bufferSizes.addIfNotAlreadyThere (i);
  210581. break;
  210582. }
  210583. }
  210584. }
  210585. if (bufferSize > 0)
  210586. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210587. }
  210588. }
  210589. if (bufferSizes.size() == 0 && bufferSize > 0)
  210590. bufferSizes.add (bufferSize);
  210591. sampleRates.clear();
  210592. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210593. String rates;
  210594. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210595. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210596. {
  210597. HeapBlock <AudioValueRange> ranges;
  210598. ranges.calloc (size, 1);
  210599. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210600. {
  210601. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210602. {
  210603. bool ok = false;
  210604. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210605. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210606. ok = true;
  210607. if (ok)
  210608. {
  210609. sampleRates.add (possibleRates[i]);
  210610. rates << possibleRates[i] << ' ';
  210611. }
  210612. }
  210613. }
  210614. }
  210615. if (sampleRates.size() == 0 && sampleRate > 0)
  210616. {
  210617. sampleRates.add (sampleRate);
  210618. rates << sampleRate;
  210619. }
  210620. log ("sr: " + rates);
  210621. inputLatency = 0;
  210622. outputLatency = 0;
  210623. UInt32 lat;
  210624. size = sizeof (lat);
  210625. pa.mSelector = kAudioDevicePropertyLatency;
  210626. pa.mScope = kAudioDevicePropertyScopeInput;
  210627. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210628. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210629. inputLatency = (int) lat;
  210630. pa.mScope = kAudioDevicePropertyScopeOutput;
  210631. size = sizeof (lat);
  210632. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210633. outputLatency = (int) lat;
  210634. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210635. inChanNames.clear();
  210636. outChanNames.clear();
  210637. inputChannelInfo.calloc (numInputChans + 2);
  210638. numInputChannelInfos = 0;
  210639. outputChannelInfo.calloc (numOutputChans + 2);
  210640. numOutputChannelInfos = 0;
  210641. fillInChannelInfo (true);
  210642. fillInChannelInfo (false);
  210643. }
  210644. const StringArray getSources (bool input)
  210645. {
  210646. StringArray s;
  210647. HeapBlock <OSType> types;
  210648. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210649. for (int i = 0; i < num; ++i)
  210650. {
  210651. AudioValueTranslation avt;
  210652. char buffer[256];
  210653. avt.mInputData = &(types[i]);
  210654. avt.mInputDataSize = sizeof (UInt32);
  210655. avt.mOutputData = buffer;
  210656. avt.mOutputDataSize = 256;
  210657. UInt32 transSize = sizeof (avt);
  210658. AudioObjectPropertyAddress pa;
  210659. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210660. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210661. pa.mElement = kAudioObjectPropertyElementMaster;
  210662. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210663. {
  210664. DBG (buffer);
  210665. s.add (buffer);
  210666. }
  210667. }
  210668. return s;
  210669. }
  210670. int getCurrentSourceIndex (bool input) const
  210671. {
  210672. OSType currentSourceID = 0;
  210673. UInt32 size = sizeof (currentSourceID);
  210674. int result = -1;
  210675. AudioObjectPropertyAddress pa;
  210676. pa.mSelector = kAudioDevicePropertyDataSource;
  210677. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210678. pa.mElement = kAudioObjectPropertyElementMaster;
  210679. if (deviceID != 0)
  210680. {
  210681. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210682. {
  210683. HeapBlock <OSType> types;
  210684. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210685. for (int i = 0; i < num; ++i)
  210686. {
  210687. if (types[num] == currentSourceID)
  210688. {
  210689. result = i;
  210690. break;
  210691. }
  210692. }
  210693. }
  210694. }
  210695. return result;
  210696. }
  210697. void setCurrentSourceIndex (int index, bool input)
  210698. {
  210699. if (deviceID != 0)
  210700. {
  210701. HeapBlock <OSType> types;
  210702. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210703. if (((unsigned int) index) < (unsigned int) num)
  210704. {
  210705. AudioObjectPropertyAddress pa;
  210706. pa.mSelector = kAudioDevicePropertyDataSource;
  210707. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210708. pa.mElement = kAudioObjectPropertyElementMaster;
  210709. OSType typeId = types[index];
  210710. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210711. }
  210712. }
  210713. }
  210714. const String reopen (const BigInteger& inputChannels,
  210715. const BigInteger& outputChannels,
  210716. double newSampleRate,
  210717. int bufferSizeSamples)
  210718. {
  210719. String error;
  210720. log ("CoreAudio reopen");
  210721. callbacksAllowed = false;
  210722. stopTimer();
  210723. stop (false);
  210724. activeInputChans = inputChannels;
  210725. activeInputChans.setRange (inChanNames.size(),
  210726. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210727. false);
  210728. activeOutputChans = outputChannels;
  210729. activeOutputChans.setRange (outChanNames.size(),
  210730. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210731. false);
  210732. numInputChans = activeInputChans.countNumberOfSetBits();
  210733. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210734. // set sample rate
  210735. AudioObjectPropertyAddress pa;
  210736. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210737. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210738. pa.mElement = kAudioObjectPropertyElementMaster;
  210739. Float64 sr = newSampleRate;
  210740. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210741. {
  210742. error = "Couldn't change sample rate";
  210743. }
  210744. else
  210745. {
  210746. // change buffer size
  210747. UInt32 framesPerBuf = bufferSizeSamples;
  210748. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210749. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210750. {
  210751. error = "Couldn't change buffer size";
  210752. }
  210753. else
  210754. {
  210755. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210756. // correctly report their new settings until some random time in the future, so
  210757. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210758. // to make sure we're using the correct numbers..
  210759. updateDetailsFromDevice();
  210760. sampleRate = newSampleRate;
  210761. bufferSize = bufferSizeSamples;
  210762. if (sampleRates.size() == 0)
  210763. error = "Device has no available sample-rates";
  210764. else if (bufferSizes.size() == 0)
  210765. error = "Device has no available buffer-sizes";
  210766. else if (inputDevice != 0)
  210767. error = inputDevice->reopen (inputChannels,
  210768. outputChannels,
  210769. newSampleRate,
  210770. bufferSizeSamples);
  210771. }
  210772. }
  210773. callbacksAllowed = true;
  210774. return error;
  210775. }
  210776. bool start (AudioIODeviceCallback* cb)
  210777. {
  210778. if (! started)
  210779. {
  210780. callback = 0;
  210781. if (deviceID != 0)
  210782. {
  210783. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210784. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, this)))
  210785. #else
  210786. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, this, &audioProcID)))
  210787. #endif
  210788. {
  210789. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210790. {
  210791. started = true;
  210792. }
  210793. else
  210794. {
  210795. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210796. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210797. #else
  210798. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210799. audioProcID = 0;
  210800. #endif
  210801. }
  210802. }
  210803. }
  210804. }
  210805. if (started)
  210806. {
  210807. const ScopedLock sl (callbackLock);
  210808. callback = cb;
  210809. }
  210810. if (inputDevice != 0)
  210811. return started && inputDevice->start (cb);
  210812. else
  210813. return started;
  210814. }
  210815. void stop (bool leaveInterruptRunning)
  210816. {
  210817. {
  210818. const ScopedLock sl (callbackLock);
  210819. callback = 0;
  210820. }
  210821. if (started
  210822. && (deviceID != 0)
  210823. && ! leaveInterruptRunning)
  210824. {
  210825. OK (AudioDeviceStop (deviceID, audioIOProc));
  210826. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210827. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210828. #else
  210829. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210830. audioProcID = 0;
  210831. #endif
  210832. started = false;
  210833. { const ScopedLock sl (callbackLock); }
  210834. // wait until it's definately stopped calling back..
  210835. for (int i = 40; --i >= 0;)
  210836. {
  210837. Thread::sleep (50);
  210838. UInt32 running = 0;
  210839. UInt32 size = sizeof (running);
  210840. AudioObjectPropertyAddress pa;
  210841. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210842. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210843. pa.mElement = kAudioObjectPropertyElementMaster;
  210844. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210845. if (running == 0)
  210846. break;
  210847. }
  210848. const ScopedLock sl (callbackLock);
  210849. }
  210850. if (inputDevice != 0)
  210851. inputDevice->stop (leaveInterruptRunning);
  210852. }
  210853. double getSampleRate() const
  210854. {
  210855. return sampleRate;
  210856. }
  210857. int getBufferSize() const
  210858. {
  210859. return bufferSize;
  210860. }
  210861. void audioCallback (const AudioBufferList* inInputData,
  210862. AudioBufferList* outOutputData)
  210863. {
  210864. int i;
  210865. const ScopedLock sl (callbackLock);
  210866. if (callback != 0)
  210867. {
  210868. if (inputDevice == 0)
  210869. {
  210870. for (i = numInputChans; --i >= 0;)
  210871. {
  210872. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210873. float* dest = tempInputBuffers [i];
  210874. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210875. + info.dataOffsetSamples;
  210876. const int stride = info.dataStrideSamples;
  210877. if (stride != 0) // if this is zero, info is invalid
  210878. {
  210879. for (int j = bufferSize; --j >= 0;)
  210880. {
  210881. *dest++ = *src;
  210882. src += stride;
  210883. }
  210884. }
  210885. }
  210886. }
  210887. if (! isSlaveDevice)
  210888. {
  210889. if (inputDevice == 0)
  210890. {
  210891. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210892. numInputChans,
  210893. tempOutputBuffers,
  210894. numOutputChans,
  210895. bufferSize);
  210896. }
  210897. else
  210898. {
  210899. jassert (inputDevice->bufferSize == bufferSize);
  210900. // Sometimes the two linked devices seem to get their callbacks in
  210901. // parallel, so we need to lock both devices to stop the input data being
  210902. // changed while inside our callback..
  210903. const ScopedLock sl2 (inputDevice->callbackLock);
  210904. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210905. inputDevice->numInputChans,
  210906. tempOutputBuffers,
  210907. numOutputChans,
  210908. bufferSize);
  210909. }
  210910. for (i = numOutputChans; --i >= 0;)
  210911. {
  210912. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210913. const float* src = tempOutputBuffers [i];
  210914. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210915. + info.dataOffsetSamples;
  210916. const int stride = info.dataStrideSamples;
  210917. if (stride != 0) // if this is zero, info is invalid
  210918. {
  210919. for (int j = bufferSize; --j >= 0;)
  210920. {
  210921. *dest = *src++;
  210922. dest += stride;
  210923. }
  210924. }
  210925. }
  210926. }
  210927. }
  210928. else
  210929. {
  210930. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210931. {
  210932. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210933. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210934. + info.dataOffsetSamples;
  210935. const int stride = info.dataStrideSamples;
  210936. if (stride != 0) // if this is zero, info is invalid
  210937. {
  210938. for (int j = bufferSize; --j >= 0;)
  210939. {
  210940. *dest = 0.0f;
  210941. dest += stride;
  210942. }
  210943. }
  210944. }
  210945. }
  210946. }
  210947. // called by callbacks
  210948. void deviceDetailsChanged()
  210949. {
  210950. if (callbacksAllowed)
  210951. startTimer (100);
  210952. }
  210953. void timerCallback()
  210954. {
  210955. stopTimer();
  210956. log ("CoreAudio device changed callback");
  210957. const double oldSampleRate = sampleRate;
  210958. const int oldBufferSize = bufferSize;
  210959. updateDetailsFromDevice();
  210960. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210961. {
  210962. callbacksAllowed = false;
  210963. stop (false);
  210964. updateDetailsFromDevice();
  210965. callbacksAllowed = true;
  210966. }
  210967. }
  210968. CoreAudioInternal* getRelatedDevice() const
  210969. {
  210970. UInt32 size = 0;
  210971. ScopedPointer <CoreAudioInternal> result;
  210972. AudioObjectPropertyAddress pa;
  210973. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210974. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210975. pa.mElement = kAudioObjectPropertyElementMaster;
  210976. if (deviceID != 0
  210977. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210978. && size > 0)
  210979. {
  210980. HeapBlock <AudioDeviceID> devs;
  210981. devs.calloc (size, 1);
  210982. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210983. {
  210984. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210985. {
  210986. if (devs[i] != deviceID && devs[i] != 0)
  210987. {
  210988. result = new CoreAudioInternal (devs[i]);
  210989. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210990. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210991. if (thisIsInput != otherIsInput
  210992. || (inChanNames.size() + outChanNames.size() == 0)
  210993. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210994. break;
  210995. result = 0;
  210996. }
  210997. }
  210998. }
  210999. }
  211000. return result.release();
  211001. }
  211002. juce_UseDebuggingNewOperator
  211003. int inputLatency, outputLatency;
  211004. BigInteger activeInputChans, activeOutputChans;
  211005. StringArray inChanNames, outChanNames;
  211006. Array <double> sampleRates;
  211007. Array <int> bufferSizes;
  211008. AudioIODeviceCallback* callback;
  211009. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211010. AudioDeviceIOProcID audioProcID;
  211011. #endif
  211012. CoreAudioInternal* inputDevice;
  211013. bool isSlaveDevice;
  211014. private:
  211015. CriticalSection callbackLock;
  211016. AudioDeviceID deviceID;
  211017. bool started;
  211018. double sampleRate;
  211019. int bufferSize;
  211020. HeapBlock <float> audioBuffer;
  211021. int numInputChans, numOutputChans;
  211022. bool callbacksAllowed;
  211023. struct CallbackDetailsForChannel
  211024. {
  211025. int streamNum;
  211026. int dataOffsetSamples;
  211027. int dataStrideSamples;
  211028. };
  211029. int numInputChannelInfos, numOutputChannelInfos;
  211030. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211031. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211032. CoreAudioInternal (const CoreAudioInternal&);
  211033. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211034. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211035. const AudioTimeStamp* inNow,
  211036. const AudioBufferList* inInputData,
  211037. const AudioTimeStamp* inInputTime,
  211038. AudioBufferList* outOutputData,
  211039. const AudioTimeStamp* inOutputTime,
  211040. void* device)
  211041. {
  211042. static_cast <CoreAudioInternal*> (device)->audioCallback (inInputData, outOutputData);
  211043. return noErr;
  211044. }
  211045. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211046. {
  211047. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211048. switch (pa->mSelector)
  211049. {
  211050. case kAudioDevicePropertyBufferSize:
  211051. case kAudioDevicePropertyBufferFrameSize:
  211052. case kAudioDevicePropertyNominalSampleRate:
  211053. case kAudioDevicePropertyStreamFormat:
  211054. case kAudioDevicePropertyDeviceIsAlive:
  211055. intern->deviceDetailsChanged();
  211056. break;
  211057. case kAudioDevicePropertyBufferSizeRange:
  211058. case kAudioDevicePropertyVolumeScalar:
  211059. case kAudioDevicePropertyMute:
  211060. case kAudioDevicePropertyPlayThru:
  211061. case kAudioDevicePropertyDataSource:
  211062. case kAudioDevicePropertyDeviceIsRunning:
  211063. break;
  211064. }
  211065. return noErr;
  211066. }
  211067. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211068. {
  211069. AudioObjectPropertyAddress pa;
  211070. pa.mSelector = kAudioDevicePropertyDataSources;
  211071. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211072. pa.mElement = kAudioObjectPropertyElementMaster;
  211073. UInt32 size = 0;
  211074. if (deviceID != 0
  211075. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211076. {
  211077. types.calloc (size, 1);
  211078. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211079. return size / (int) sizeof (OSType);
  211080. }
  211081. return 0;
  211082. }
  211083. };
  211084. class CoreAudioIODevice : public AudioIODevice
  211085. {
  211086. public:
  211087. CoreAudioIODevice (const String& deviceName,
  211088. AudioDeviceID inputDeviceId,
  211089. const int inputIndex_,
  211090. AudioDeviceID outputDeviceId,
  211091. const int outputIndex_)
  211092. : AudioIODevice (deviceName, "CoreAudio"),
  211093. inputIndex (inputIndex_),
  211094. outputIndex (outputIndex_),
  211095. isOpen_ (false),
  211096. isStarted (false)
  211097. {
  211098. internal = 0;
  211099. CoreAudioInternal* device = 0;
  211100. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211101. {
  211102. jassert (inputDeviceId != 0);
  211103. device = new CoreAudioInternal (inputDeviceId);
  211104. }
  211105. else
  211106. {
  211107. device = new CoreAudioInternal (outputDeviceId);
  211108. if (inputDeviceId != 0)
  211109. {
  211110. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211111. device->inputDevice = secondDevice;
  211112. secondDevice->isSlaveDevice = true;
  211113. }
  211114. }
  211115. internal = device;
  211116. AudioObjectPropertyAddress pa;
  211117. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211118. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211119. pa.mElement = kAudioObjectPropertyElementWildcard;
  211120. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211121. }
  211122. ~CoreAudioIODevice()
  211123. {
  211124. AudioObjectPropertyAddress pa;
  211125. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211126. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211127. pa.mElement = kAudioObjectPropertyElementWildcard;
  211128. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211129. delete internal;
  211130. }
  211131. const StringArray getOutputChannelNames()
  211132. {
  211133. return internal->outChanNames;
  211134. }
  211135. const StringArray getInputChannelNames()
  211136. {
  211137. if (internal->inputDevice != 0)
  211138. return internal->inputDevice->inChanNames;
  211139. else
  211140. return internal->inChanNames;
  211141. }
  211142. int getNumSampleRates()
  211143. {
  211144. return internal->sampleRates.size();
  211145. }
  211146. double getSampleRate (int index)
  211147. {
  211148. return internal->sampleRates [index];
  211149. }
  211150. int getNumBufferSizesAvailable()
  211151. {
  211152. return internal->bufferSizes.size();
  211153. }
  211154. int getBufferSizeSamples (int index)
  211155. {
  211156. return internal->bufferSizes [index];
  211157. }
  211158. int getDefaultBufferSize()
  211159. {
  211160. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211161. if (getBufferSizeSamples(i) >= 512)
  211162. return getBufferSizeSamples(i);
  211163. return 512;
  211164. }
  211165. const String open (const BigInteger& inputChannels,
  211166. const BigInteger& outputChannels,
  211167. double sampleRate,
  211168. int bufferSizeSamples)
  211169. {
  211170. isOpen_ = true;
  211171. if (bufferSizeSamples <= 0)
  211172. bufferSizeSamples = getDefaultBufferSize();
  211173. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211174. isOpen_ = lastError.isEmpty();
  211175. return lastError;
  211176. }
  211177. void close()
  211178. {
  211179. isOpen_ = false;
  211180. internal->stop (false);
  211181. }
  211182. bool isOpen()
  211183. {
  211184. return isOpen_;
  211185. }
  211186. int getCurrentBufferSizeSamples()
  211187. {
  211188. return internal != 0 ? internal->getBufferSize() : 512;
  211189. }
  211190. double getCurrentSampleRate()
  211191. {
  211192. return internal != 0 ? internal->getSampleRate() : 0;
  211193. }
  211194. int getCurrentBitDepth()
  211195. {
  211196. return 32; // no way to find out, so just assume it's high..
  211197. }
  211198. const BigInteger getActiveOutputChannels() const
  211199. {
  211200. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211201. }
  211202. const BigInteger getActiveInputChannels() const
  211203. {
  211204. BigInteger chans;
  211205. if (internal != 0)
  211206. {
  211207. chans = internal->activeInputChans;
  211208. if (internal->inputDevice != 0)
  211209. chans |= internal->inputDevice->activeInputChans;
  211210. }
  211211. return chans;
  211212. }
  211213. int getOutputLatencyInSamples()
  211214. {
  211215. if (internal == 0)
  211216. return 0;
  211217. // this seems like a good guess at getting the latency right - comparing
  211218. // this with a round-trip measurement, it gets it to within a few millisecs
  211219. // for the built-in mac soundcard
  211220. return internal->outputLatency + internal->getBufferSize() * 2;
  211221. }
  211222. int getInputLatencyInSamples()
  211223. {
  211224. if (internal == 0)
  211225. return 0;
  211226. return internal->inputLatency + internal->getBufferSize() * 2;
  211227. }
  211228. void start (AudioIODeviceCallback* callback)
  211229. {
  211230. if (internal != 0 && ! isStarted)
  211231. {
  211232. if (callback != 0)
  211233. callback->audioDeviceAboutToStart (this);
  211234. isStarted = true;
  211235. internal->start (callback);
  211236. }
  211237. }
  211238. void stop()
  211239. {
  211240. if (isStarted && internal != 0)
  211241. {
  211242. AudioIODeviceCallback* const lastCallback = internal->callback;
  211243. isStarted = false;
  211244. internal->stop (true);
  211245. if (lastCallback != 0)
  211246. lastCallback->audioDeviceStopped();
  211247. }
  211248. }
  211249. bool isPlaying()
  211250. {
  211251. if (internal->callback == 0)
  211252. isStarted = false;
  211253. return isStarted;
  211254. }
  211255. const String getLastError()
  211256. {
  211257. return lastError;
  211258. }
  211259. int inputIndex, outputIndex;
  211260. juce_UseDebuggingNewOperator
  211261. private:
  211262. CoreAudioInternal* internal;
  211263. bool isOpen_, isStarted;
  211264. String lastError;
  211265. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211266. {
  211267. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211268. switch (pa->mSelector)
  211269. {
  211270. case kAudioHardwarePropertyDevices:
  211271. intern->deviceDetailsChanged();
  211272. break;
  211273. case kAudioHardwarePropertyDefaultOutputDevice:
  211274. case kAudioHardwarePropertyDefaultInputDevice:
  211275. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211276. break;
  211277. }
  211278. return noErr;
  211279. }
  211280. CoreAudioIODevice (const CoreAudioIODevice&);
  211281. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211282. };
  211283. class CoreAudioIODeviceType : public AudioIODeviceType
  211284. {
  211285. public:
  211286. CoreAudioIODeviceType()
  211287. : AudioIODeviceType ("CoreAudio"),
  211288. hasScanned (false)
  211289. {
  211290. }
  211291. ~CoreAudioIODeviceType()
  211292. {
  211293. }
  211294. void scanForDevices()
  211295. {
  211296. hasScanned = true;
  211297. inputDeviceNames.clear();
  211298. outputDeviceNames.clear();
  211299. inputIds.clear();
  211300. outputIds.clear();
  211301. UInt32 size;
  211302. AudioObjectPropertyAddress pa;
  211303. pa.mSelector = kAudioHardwarePropertyDevices;
  211304. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211305. pa.mElement = kAudioObjectPropertyElementMaster;
  211306. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211307. {
  211308. HeapBlock <AudioDeviceID> devs;
  211309. devs.calloc (size, 1);
  211310. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211311. {
  211312. static bool alreadyLogged = false;
  211313. const int num = size / (int) sizeof (AudioDeviceID);
  211314. for (int i = 0; i < num; ++i)
  211315. {
  211316. char name [1024];
  211317. size = sizeof (name);
  211318. pa.mSelector = kAudioDevicePropertyDeviceName;
  211319. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211320. {
  211321. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211322. if (! alreadyLogged)
  211323. log ("CoreAudio device: " + nameString);
  211324. const int numIns = getNumChannels (devs[i], true);
  211325. const int numOuts = getNumChannels (devs[i], false);
  211326. if (numIns > 0)
  211327. {
  211328. inputDeviceNames.add (nameString);
  211329. inputIds.add (devs[i]);
  211330. }
  211331. if (numOuts > 0)
  211332. {
  211333. outputDeviceNames.add (nameString);
  211334. outputIds.add (devs[i]);
  211335. }
  211336. }
  211337. }
  211338. alreadyLogged = true;
  211339. }
  211340. }
  211341. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211342. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211343. }
  211344. const StringArray getDeviceNames (bool wantInputNames) const
  211345. {
  211346. jassert (hasScanned); // need to call scanForDevices() before doing this
  211347. if (wantInputNames)
  211348. return inputDeviceNames;
  211349. else
  211350. return outputDeviceNames;
  211351. }
  211352. int getDefaultDeviceIndex (bool forInput) const
  211353. {
  211354. jassert (hasScanned); // need to call scanForDevices() before doing this
  211355. AudioDeviceID deviceID;
  211356. UInt32 size = sizeof (deviceID);
  211357. // if they're asking for any input channels at all, use the default input, so we
  211358. // get the built-in mic rather than the built-in output with no inputs..
  211359. AudioObjectPropertyAddress pa;
  211360. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211361. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211362. pa.mElement = kAudioObjectPropertyElementMaster;
  211363. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211364. {
  211365. if (forInput)
  211366. {
  211367. for (int i = inputIds.size(); --i >= 0;)
  211368. if (inputIds[i] == deviceID)
  211369. return i;
  211370. }
  211371. else
  211372. {
  211373. for (int i = outputIds.size(); --i >= 0;)
  211374. if (outputIds[i] == deviceID)
  211375. return i;
  211376. }
  211377. }
  211378. return 0;
  211379. }
  211380. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  211381. {
  211382. jassert (hasScanned); // need to call scanForDevices() before doing this
  211383. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211384. if (d == 0)
  211385. return -1;
  211386. return asInput ? d->inputIndex
  211387. : d->outputIndex;
  211388. }
  211389. bool hasSeparateInputsAndOutputs() const { return true; }
  211390. AudioIODevice* createDevice (const String& outputDeviceName,
  211391. const String& inputDeviceName)
  211392. {
  211393. jassert (hasScanned); // need to call scanForDevices() before doing this
  211394. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211395. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211396. String deviceName (outputDeviceName);
  211397. if (deviceName.isEmpty())
  211398. deviceName = inputDeviceName;
  211399. if (index >= 0)
  211400. return new CoreAudioIODevice (deviceName,
  211401. inputIds [inputIndex],
  211402. inputIndex,
  211403. outputIds [outputIndex],
  211404. outputIndex);
  211405. return 0;
  211406. }
  211407. juce_UseDebuggingNewOperator
  211408. private:
  211409. StringArray inputDeviceNames, outputDeviceNames;
  211410. Array <AudioDeviceID> inputIds, outputIds;
  211411. bool hasScanned;
  211412. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211413. {
  211414. int total = 0;
  211415. UInt32 size;
  211416. AudioObjectPropertyAddress pa;
  211417. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211418. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211419. pa.mElement = kAudioObjectPropertyElementMaster;
  211420. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211421. {
  211422. HeapBlock <AudioBufferList> bufList;
  211423. bufList.calloc (size, 1);
  211424. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211425. {
  211426. const int numStreams = bufList->mNumberBuffers;
  211427. for (int i = 0; i < numStreams; ++i)
  211428. {
  211429. const AudioBuffer& b = bufList->mBuffers[i];
  211430. total += b.mNumberChannels;
  211431. }
  211432. }
  211433. }
  211434. return total;
  211435. }
  211436. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211437. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211438. };
  211439. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211440. {
  211441. return new CoreAudioIODeviceType();
  211442. }
  211443. #undef log
  211444. #endif
  211445. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211446. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211447. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211448. // compiled on its own).
  211449. #if JUCE_INCLUDED_FILE
  211450. #if JUCE_MAC
  211451. #undef log
  211452. #define log(a) Logger::writeToLog(a)
  211453. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211454. {
  211455. if (err == noErr)
  211456. return true;
  211457. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211458. jassertfalse
  211459. return false;
  211460. }
  211461. #undef OK
  211462. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211463. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211464. {
  211465. String result;
  211466. CFStringRef str = 0;
  211467. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211468. if (str != 0)
  211469. {
  211470. result = PlatformUtilities::cfStringToJuceString (str);
  211471. CFRelease (str);
  211472. str = 0;
  211473. }
  211474. MIDIEntityRef entity = 0;
  211475. MIDIEndpointGetEntity (endpoint, &entity);
  211476. if (entity == 0)
  211477. return result; // probably virtual
  211478. if (result.isEmpty())
  211479. {
  211480. // endpoint name has zero length - try the entity
  211481. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211482. if (str != 0)
  211483. {
  211484. result += PlatformUtilities::cfStringToJuceString (str);
  211485. CFRelease (str);
  211486. str = 0;
  211487. }
  211488. }
  211489. // now consider the device's name
  211490. MIDIDeviceRef device = 0;
  211491. MIDIEntityGetDevice (entity, &device);
  211492. if (device == 0)
  211493. return result;
  211494. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211495. if (str != 0)
  211496. {
  211497. const String s (PlatformUtilities::cfStringToJuceString (str));
  211498. CFRelease (str);
  211499. // if an external device has only one entity, throw away
  211500. // the endpoint name and just use the device name
  211501. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211502. {
  211503. result = s;
  211504. }
  211505. else if (! result.startsWithIgnoreCase (s))
  211506. {
  211507. // prepend the device name to the entity name
  211508. result = (s + " " + result).trimEnd();
  211509. }
  211510. }
  211511. return result;
  211512. }
  211513. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211514. {
  211515. String result;
  211516. // Does the endpoint have connections?
  211517. CFDataRef connections = 0;
  211518. int numConnections = 0;
  211519. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211520. if (connections != 0)
  211521. {
  211522. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211523. if (numConnections > 0)
  211524. {
  211525. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211526. for (int i = 0; i < numConnections; ++i, ++pid)
  211527. {
  211528. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211529. MIDIObjectRef connObject;
  211530. MIDIObjectType connObjectType;
  211531. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211532. if (err == noErr)
  211533. {
  211534. String s;
  211535. if (connObjectType == kMIDIObjectType_ExternalSource
  211536. || connObjectType == kMIDIObjectType_ExternalDestination)
  211537. {
  211538. // Connected to an external device's endpoint (10.3 and later).
  211539. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211540. }
  211541. else
  211542. {
  211543. // Connected to an external device (10.2) (or something else, catch-all)
  211544. CFStringRef str = 0;
  211545. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211546. if (str != 0)
  211547. {
  211548. s = PlatformUtilities::cfStringToJuceString (str);
  211549. CFRelease (str);
  211550. }
  211551. }
  211552. if (s.isNotEmpty())
  211553. {
  211554. if (result.isNotEmpty())
  211555. result += ", ";
  211556. result += s;
  211557. }
  211558. }
  211559. }
  211560. }
  211561. CFRelease (connections);
  211562. }
  211563. if (result.isNotEmpty())
  211564. return result;
  211565. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211566. return getEndpointName (endpoint, false);
  211567. }
  211568. const StringArray MidiOutput::getDevices()
  211569. {
  211570. StringArray s;
  211571. const ItemCount num = MIDIGetNumberOfDestinations();
  211572. for (ItemCount i = 0; i < num; ++i)
  211573. {
  211574. MIDIEndpointRef dest = MIDIGetDestination (i);
  211575. if (dest != 0)
  211576. {
  211577. String name (getConnectedEndpointName (dest));
  211578. if (name.isEmpty())
  211579. name = "<error>";
  211580. s.add (name);
  211581. }
  211582. else
  211583. {
  211584. s.add ("<error>");
  211585. }
  211586. }
  211587. return s;
  211588. }
  211589. int MidiOutput::getDefaultDeviceIndex()
  211590. {
  211591. return 0;
  211592. }
  211593. static MIDIClientRef globalMidiClient;
  211594. static bool hasGlobalClientBeenCreated = false;
  211595. static bool makeSureClientExists()
  211596. {
  211597. if (! hasGlobalClientBeenCreated)
  211598. {
  211599. String name ("JUCE");
  211600. if (JUCEApplication::getInstance() != 0)
  211601. name = JUCEApplication::getInstance()->getApplicationName();
  211602. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211603. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211604. CFRelease (appName);
  211605. }
  211606. return hasGlobalClientBeenCreated;
  211607. }
  211608. class MidiPortAndEndpoint
  211609. {
  211610. public:
  211611. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211612. : port (port_), endPoint (endPoint_)
  211613. {
  211614. }
  211615. ~MidiPortAndEndpoint()
  211616. {
  211617. if (port != 0)
  211618. MIDIPortDispose (port);
  211619. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211620. MIDIEndpointDispose (endPoint);
  211621. }
  211622. MIDIPortRef port;
  211623. MIDIEndpointRef endPoint;
  211624. };
  211625. MidiOutput* MidiOutput::openDevice (int index)
  211626. {
  211627. MidiOutput* mo = 0;
  211628. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211629. {
  211630. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211631. CFStringRef pname;
  211632. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211633. {
  211634. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211635. if (makeSureClientExists())
  211636. {
  211637. MIDIPortRef port;
  211638. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211639. {
  211640. mo = new MidiOutput();
  211641. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  211642. }
  211643. }
  211644. CFRelease (pname);
  211645. }
  211646. }
  211647. return mo;
  211648. }
  211649. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211650. {
  211651. MidiOutput* mo = 0;
  211652. if (makeSureClientExists())
  211653. {
  211654. MIDIEndpointRef endPoint;
  211655. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211656. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211657. {
  211658. mo = new MidiOutput();
  211659. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  211660. }
  211661. CFRelease (name);
  211662. }
  211663. return mo;
  211664. }
  211665. MidiOutput::~MidiOutput()
  211666. {
  211667. delete (MidiPortAndEndpoint*) internal;
  211668. }
  211669. void MidiOutput::reset()
  211670. {
  211671. }
  211672. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211673. {
  211674. return false;
  211675. }
  211676. void MidiOutput::setVolume (float leftVol, float rightVol)
  211677. {
  211678. }
  211679. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211680. {
  211681. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211682. if (message.isSysEx())
  211683. {
  211684. const int maxPacketSize = 256;
  211685. int pos = 0, bytesLeft = message.getRawDataSize();
  211686. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211687. HeapBlock <MIDIPacketList> packets;
  211688. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211689. packets->numPackets = numPackets;
  211690. MIDIPacket* p = packets->packet;
  211691. for (int i = 0; i < numPackets; ++i)
  211692. {
  211693. p->timeStamp = 0;
  211694. p->length = jmin (maxPacketSize, bytesLeft);
  211695. memcpy (p->data, message.getRawData() + pos, p->length);
  211696. pos += p->length;
  211697. bytesLeft -= p->length;
  211698. p = MIDIPacketNext (p);
  211699. }
  211700. if (mpe->port != 0)
  211701. MIDISend (mpe->port, mpe->endPoint, packets);
  211702. else
  211703. MIDIReceived (mpe->endPoint, packets);
  211704. }
  211705. else
  211706. {
  211707. MIDIPacketList packets;
  211708. packets.numPackets = 1;
  211709. packets.packet[0].timeStamp = 0;
  211710. packets.packet[0].length = message.getRawDataSize();
  211711. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211712. if (mpe->port != 0)
  211713. MIDISend (mpe->port, mpe->endPoint, &packets);
  211714. else
  211715. MIDIReceived (mpe->endPoint, &packets);
  211716. }
  211717. }
  211718. const StringArray MidiInput::getDevices()
  211719. {
  211720. StringArray s;
  211721. const ItemCount num = MIDIGetNumberOfSources();
  211722. for (ItemCount i = 0; i < num; ++i)
  211723. {
  211724. MIDIEndpointRef source = MIDIGetSource (i);
  211725. if (source != 0)
  211726. {
  211727. String name (getConnectedEndpointName (source));
  211728. if (name.isEmpty())
  211729. name = "<error>";
  211730. s.add (name);
  211731. }
  211732. else
  211733. {
  211734. s.add ("<error>");
  211735. }
  211736. }
  211737. return s;
  211738. }
  211739. int MidiInput::getDefaultDeviceIndex()
  211740. {
  211741. return 0;
  211742. }
  211743. struct MidiPortAndCallback
  211744. {
  211745. MidiInput* input;
  211746. MidiPortAndEndpoint* portAndEndpoint;
  211747. MidiInputCallback* callback;
  211748. MemoryBlock pendingData;
  211749. int pendingBytes;
  211750. double pendingDataTime;
  211751. bool active;
  211752. void processSysex (const uint8*& d, int& size, const double time)
  211753. {
  211754. if (*d == 0xf0)
  211755. {
  211756. pendingBytes = 0;
  211757. pendingDataTime = time;
  211758. }
  211759. pendingData.ensureSize (pendingBytes + size, false);
  211760. uint8* totalMessage = (uint8*) pendingData.getData();
  211761. uint8* dest = totalMessage + pendingBytes;
  211762. while (size > 0)
  211763. {
  211764. if (pendingBytes > 0 && *d >= 0x80)
  211765. {
  211766. if (*d >= 0xfa || *d == 0xf8)
  211767. {
  211768. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211769. ++d;
  211770. --size;
  211771. }
  211772. else
  211773. {
  211774. if (*d == 0xf7)
  211775. {
  211776. *dest++ = *d++;
  211777. pendingBytes++;
  211778. --size;
  211779. }
  211780. break;
  211781. }
  211782. }
  211783. else
  211784. {
  211785. *dest++ = *d++;
  211786. pendingBytes++;
  211787. --size;
  211788. }
  211789. }
  211790. if (totalMessage [pendingBytes - 1] == 0xf7)
  211791. {
  211792. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211793. pendingBytes = 0;
  211794. }
  211795. else
  211796. {
  211797. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211798. }
  211799. }
  211800. };
  211801. namespace CoreMidiCallbacks
  211802. {
  211803. static CriticalSection callbackLock;
  211804. static VoidArray activeCallbacks;
  211805. }
  211806. static void midiInputProc (const MIDIPacketList* pktlist,
  211807. void* readProcRefCon,
  211808. void* srcConnRefCon)
  211809. {
  211810. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211811. const double originalTime = time;
  211812. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211813. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211814. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211815. {
  211816. const MIDIPacket* packet = &pktlist->packet[0];
  211817. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211818. {
  211819. const uint8* d = (const uint8*) (packet->data);
  211820. int size = packet->length;
  211821. while (size > 0)
  211822. {
  211823. time = originalTime;
  211824. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211825. {
  211826. mpc->processSysex (d, size, time);
  211827. }
  211828. else
  211829. {
  211830. int used = 0;
  211831. const MidiMessage m (d, size, used, 0, time);
  211832. if (used <= 0)
  211833. {
  211834. jassertfalse // malformed midi message
  211835. break;
  211836. }
  211837. else
  211838. {
  211839. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211840. }
  211841. size -= used;
  211842. d += used;
  211843. }
  211844. }
  211845. packet = MIDIPacketNext (packet);
  211846. }
  211847. }
  211848. }
  211849. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211850. {
  211851. MidiInput* mi = 0;
  211852. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211853. {
  211854. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211855. if (endPoint != 0)
  211856. {
  211857. CFStringRef pname;
  211858. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211859. {
  211860. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211861. if (makeSureClientExists())
  211862. {
  211863. MIDIPortRef port;
  211864. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211865. mpc->active = false;
  211866. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211867. {
  211868. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211869. {
  211870. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211871. mpc->callback = callback;
  211872. mpc->pendingBytes = 0;
  211873. mpc->pendingData.ensureSize (128);
  211874. mi = new MidiInput (getDevices() [index]);
  211875. mpc->input = mi;
  211876. mi->internal = mpc;
  211877. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211878. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211879. }
  211880. else
  211881. {
  211882. OK (MIDIPortDispose (port));
  211883. }
  211884. }
  211885. }
  211886. }
  211887. CFRelease (pname);
  211888. }
  211889. }
  211890. return mi;
  211891. }
  211892. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211893. {
  211894. MidiInput* mi = 0;
  211895. if (makeSureClientExists())
  211896. {
  211897. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211898. mpc->active = false;
  211899. MIDIEndpointRef endPoint;
  211900. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211901. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211902. {
  211903. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211904. mpc->callback = callback;
  211905. mpc->pendingBytes = 0;
  211906. mpc->pendingData.ensureSize (128);
  211907. mi = new MidiInput (deviceName);
  211908. mpc->input = mi;
  211909. mi->internal = mpc;
  211910. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211911. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211912. }
  211913. CFRelease (name);
  211914. }
  211915. return mi;
  211916. }
  211917. MidiInput::MidiInput (const String& name_)
  211918. : name (name_)
  211919. {
  211920. }
  211921. MidiInput::~MidiInput()
  211922. {
  211923. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211924. mpc->active = false;
  211925. {
  211926. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211927. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211928. }
  211929. if (mpc->portAndEndpoint->port != 0)
  211930. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211931. delete mpc->portAndEndpoint;
  211932. delete mpc;
  211933. }
  211934. void MidiInput::start()
  211935. {
  211936. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211937. ((MidiPortAndCallback*) internal)->active = true;
  211938. }
  211939. void MidiInput::stop()
  211940. {
  211941. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211942. ((MidiPortAndCallback*) internal)->active = false;
  211943. }
  211944. #undef log
  211945. #else
  211946. MidiOutput::~MidiOutput()
  211947. {
  211948. }
  211949. void MidiOutput::reset()
  211950. {
  211951. }
  211952. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211953. {
  211954. return false;
  211955. }
  211956. void MidiOutput::setVolume (float leftVol, float rightVol)
  211957. {
  211958. }
  211959. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211960. {
  211961. }
  211962. const StringArray MidiOutput::getDevices()
  211963. {
  211964. return StringArray();
  211965. }
  211966. MidiOutput* MidiOutput::openDevice (int index)
  211967. {
  211968. return 0;
  211969. }
  211970. const StringArray MidiInput::getDevices()
  211971. {
  211972. return StringArray();
  211973. }
  211974. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211975. {
  211976. return 0;
  211977. }
  211978. #endif
  211979. #endif
  211980. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211981. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211982. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211983. // compiled on its own).
  211984. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211985. #if ! JUCE_QUICKTIME
  211986. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211987. #endif
  211988. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211989. class QTCameraDeviceInteral;
  211990. END_JUCE_NAMESPACE
  211991. @interface QTCaptureCallbackDelegate : NSObject
  211992. {
  211993. @public
  211994. CameraDevice* owner;
  211995. QTCameraDeviceInteral* internal;
  211996. int64 firstPresentationTime;
  211997. int64 averageTimeOffset;
  211998. }
  211999. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  212000. - (void) dealloc;
  212001. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212002. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212003. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212004. fromConnection: (QTCaptureConnection*) connection;
  212005. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212006. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212007. fromConnection: (QTCaptureConnection*) connection;
  212008. @end
  212009. BEGIN_JUCE_NAMESPACE
  212010. class QTCameraDeviceInteral
  212011. {
  212012. public:
  212013. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212014. {
  212015. const ScopedAutoReleasePool pool;
  212016. session = [[QTCaptureSession alloc] init];
  212017. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212018. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212019. input = 0;
  212020. audioInput = 0;
  212021. audioDevice = 0;
  212022. fileOutput = 0;
  212023. imageOutput = 0;
  212024. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212025. internalDev: this];
  212026. NSError* err = 0;
  212027. [device retain];
  212028. [device open: &err];
  212029. if (err == 0)
  212030. {
  212031. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212032. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212033. [session addInput: input error: &err];
  212034. if (err == 0)
  212035. {
  212036. resetFile();
  212037. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212038. [imageOutput setDelegate: callbackDelegate];
  212039. if (err == 0)
  212040. {
  212041. [session startRunning];
  212042. return;
  212043. }
  212044. }
  212045. }
  212046. openingError = nsStringToJuce ([err description]);
  212047. DBG (openingError);
  212048. }
  212049. ~QTCameraDeviceInteral()
  212050. {
  212051. [session stopRunning];
  212052. [session removeOutput: imageOutput];
  212053. [session release];
  212054. [input release];
  212055. [device release];
  212056. [audioDevice release];
  212057. [audioInput release];
  212058. [fileOutput release];
  212059. [imageOutput release];
  212060. [callbackDelegate release];
  212061. }
  212062. void resetFile()
  212063. {
  212064. [fileOutput recordToOutputFileURL: nil];
  212065. [session removeOutput: fileOutput];
  212066. [fileOutput release];
  212067. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212068. [session removeInput: audioInput];
  212069. [audioInput release];
  212070. audioInput = 0;
  212071. [audioDevice release];
  212072. audioDevice = 0;
  212073. [fileOutput setDelegate: callbackDelegate];
  212074. }
  212075. void addDefaultAudioInput()
  212076. {
  212077. NSError* err = nil;
  212078. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212079. if ([audioDevice open: &err])
  212080. [audioDevice retain];
  212081. else
  212082. audioDevice = nil;
  212083. if (audioDevice != 0)
  212084. {
  212085. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212086. [session addInput: audioInput error: &err];
  212087. }
  212088. }
  212089. void addListener (CameraImageListener* listenerToAdd)
  212090. {
  212091. const ScopedLock sl (listenerLock);
  212092. if (listeners.size() == 0)
  212093. [session addOutput: imageOutput error: nil];
  212094. listeners.addIfNotAlreadyThere (listenerToAdd);
  212095. }
  212096. void removeListener (CameraImageListener* listenerToRemove)
  212097. {
  212098. const ScopedLock sl (listenerLock);
  212099. listeners.removeValue (listenerToRemove);
  212100. if (listeners.size() == 0)
  212101. [session removeOutput: imageOutput];
  212102. }
  212103. void callListeners (CIImage* frame, int w, int h)
  212104. {
  212105. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212106. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212107. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212108. CGContextFlush (image.context);
  212109. const ScopedLock sl (listenerLock);
  212110. for (int i = listeners.size(); --i >= 0;)
  212111. {
  212112. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212113. if (l != 0)
  212114. l->imageReceived (image);
  212115. }
  212116. }
  212117. QTCaptureDevice* device;
  212118. QTCaptureDeviceInput* input;
  212119. QTCaptureDevice* audioDevice;
  212120. QTCaptureDeviceInput* audioInput;
  212121. QTCaptureSession* session;
  212122. QTCaptureMovieFileOutput* fileOutput;
  212123. QTCaptureDecompressedVideoOutput* imageOutput;
  212124. QTCaptureCallbackDelegate* callbackDelegate;
  212125. String openingError;
  212126. VoidArray listeners;
  212127. CriticalSection listenerLock;
  212128. };
  212129. END_JUCE_NAMESPACE
  212130. @implementation QTCaptureCallbackDelegate
  212131. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212132. internalDev: (QTCameraDeviceInteral*) d
  212133. {
  212134. [super init];
  212135. owner = owner_;
  212136. internal = d;
  212137. firstPresentationTime = 0;
  212138. averageTimeOffset = 0;
  212139. return self;
  212140. }
  212141. - (void) dealloc
  212142. {
  212143. [super dealloc];
  212144. }
  212145. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212146. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212147. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212148. fromConnection: (QTCaptureConnection*) connection
  212149. {
  212150. if (internal->listeners.size() > 0)
  212151. {
  212152. const ScopedAutoReleasePool pool;
  212153. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212154. CVPixelBufferGetWidth (videoFrame),
  212155. CVPixelBufferGetHeight (videoFrame));
  212156. }
  212157. }
  212158. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212159. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212160. fromConnection: (QTCaptureConnection*) connection
  212161. {
  212162. const Time now (Time::getCurrentTime());
  212163. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212164. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212165. #else
  212166. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212167. #endif
  212168. int64 presentationTime = (hosttime != nil)
  212169. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212170. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212171. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212172. if (firstPresentationTime == 0)
  212173. {
  212174. firstPresentationTime = presentationTime;
  212175. averageTimeOffset = timeDiff;
  212176. }
  212177. else
  212178. {
  212179. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212180. }
  212181. }
  212182. @end
  212183. BEGIN_JUCE_NAMESPACE
  212184. class QTCaptureViewerComp : public NSViewComponent
  212185. {
  212186. public:
  212187. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212188. {
  212189. const ScopedAutoReleasePool pool;
  212190. captureView = [[QTCaptureView alloc] init];
  212191. [captureView setCaptureSession: internal->session];
  212192. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212193. setView (captureView);
  212194. }
  212195. ~QTCaptureViewerComp()
  212196. {
  212197. setView (0);
  212198. [captureView setCaptureSession: nil];
  212199. [captureView release];
  212200. }
  212201. QTCaptureView* captureView;
  212202. };
  212203. CameraDevice::CameraDevice (const String& name_, int index)
  212204. : name (name_)
  212205. {
  212206. isRecording = false;
  212207. internal = new QTCameraDeviceInteral (this, index);
  212208. }
  212209. CameraDevice::~CameraDevice()
  212210. {
  212211. stopRecording();
  212212. delete static_cast <QTCameraDeviceInteral*> (internal);
  212213. internal = 0;
  212214. }
  212215. Component* CameraDevice::createViewerComponent()
  212216. {
  212217. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212218. }
  212219. const String CameraDevice::getFileExtension()
  212220. {
  212221. return ".mov";
  212222. }
  212223. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212224. {
  212225. stopRecording();
  212226. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212227. d->callbackDelegate->firstPresentationTime = 0;
  212228. file.deleteFile();
  212229. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212230. // out wrong, so we'll put some audio in there too..,
  212231. d->addDefaultAudioInput();
  212232. [d->session addOutput: d->fileOutput error: nil];
  212233. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212234. for (;;)
  212235. {
  212236. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212237. if (connection == 0)
  212238. break;
  212239. QTCompressionOptions* options = 0;
  212240. NSString* mediaType = [connection mediaType];
  212241. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212242. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212243. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212244. : @"QTCompressionOptions240SizeH264Video"];
  212245. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212246. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212247. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212248. }
  212249. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212250. isRecording = true;
  212251. }
  212252. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212253. {
  212254. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212255. if (d->callbackDelegate->firstPresentationTime != 0)
  212256. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212257. return Time();
  212258. }
  212259. void CameraDevice::stopRecording()
  212260. {
  212261. if (isRecording)
  212262. {
  212263. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212264. isRecording = false;
  212265. }
  212266. }
  212267. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212268. {
  212269. if (listenerToAdd != 0)
  212270. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212271. }
  212272. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212273. {
  212274. if (listenerToRemove != 0)
  212275. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212276. }
  212277. const StringArray CameraDevice::getAvailableDevices()
  212278. {
  212279. const ScopedAutoReleasePool pool;
  212280. StringArray results;
  212281. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212282. for (int i = 0; i < (int) [devs count]; ++i)
  212283. {
  212284. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212285. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212286. }
  212287. return results;
  212288. }
  212289. CameraDevice* CameraDevice::openDevice (int index,
  212290. int minWidth, int minHeight,
  212291. int maxWidth, int maxHeight)
  212292. {
  212293. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212294. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212295. return d.release();
  212296. return 0;
  212297. }
  212298. #endif
  212299. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212300. #endif
  212301. #endif
  212302. END_JUCE_NAMESPACE
  212303. #endif
  212304. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212305. #endif
  212306. #endif